Skip to content

Commit 24c0e51

Browse files
fixed engineer table crash
1 parent 74a83aa commit 24c0e51

File tree

11 files changed

+1767
-15
lines changed

11 files changed

+1767
-15
lines changed

diagram.uml

Lines changed: 1737 additions & 0 deletions
Large diffs are not rendered by default.

src/main/java/com/rae/creatingspace/CreatingSpace.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import net.neoforged.neoforge.common.NeoForge;
3434
import net.neoforged.neoforge.event.AddReloadListenerEvent;
3535
import net.neoforged.neoforge.registries.DataPackRegistryEvent;
36+
import net.neoforged.neoforge.registries.NewRegistryEvent;
37+
import net.neoforged.neoforge.registries.RegistryBuilder;
3638
import org.slf4j.Logger;
3739

3840
@Mod(CreatingSpace.MODID)
@@ -58,6 +60,12 @@ public CreatingSpace(IEventBus modEventBus, ModContainer modContainer) {
5860
event.dataPackRegistry(PropellantTypeInit.Keys.PROPELLANT_TYPE,PropellantType.DIRECT_CODEC, PropellantType.DIRECT_CODEC);
5961
LOGGER.debug("added reload for CS registries");
6062
});
63+
/*modEventBus.addListener((NewRegistryEvent event) -> {
64+
//event.create(new RegistryBuilder<>(RocketAccessibleDimension.REGISTRY_KEY).sync(true));
65+
//event.create(new RegistryBuilder<>(MiscInit.Keys.POWER_PACK_TYPE));
66+
//event.create(new RegistryBuilder<>(MiscInit.Keys.EXHAUST_PACK_TYPE));
67+
event.create(new RegistryBuilder<>(PropellantTypeInit.Keys.PROPELLANT_TYPE));
68+
});*/
6169
REGISTRATE.registerEventListeners(modEventBus);
6270

6371
TagsInit.init();

src/main/java/com/rae/creatingspace/content/rocket/RocketContraptionEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ private void stopRocket() {
859859
}
860860

861861
@Override
862-
public @Nullable AbstractContainerMenu createMenu(int i, Inventory inventory, Player player) {
862+
public @Nullable AbstractContainerMenu createMenu(int i, @NotNull Inventory inventory, @NotNull Player player) {
863863
return ScheduleMakingMenu.create(i,inventory,this);
864864
}
865865

src/main/java/com/rae/creatingspace/content/rocket/ScheduleMakingMenu.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public static ScheduleMakingMenu create(int id, Inventory inv, RocketContraption
2727

2828
@Override
2929
protected RocketContraptionEntity createOnClient(RegistryFriendlyByteBuf extraData) {
30-
//System.out.println("create on client");
3130
int entityID = extraData.readVarInt();
3231
Entity entityByID = Minecraft.getInstance().level.getEntity(entityID);
3332
if (!(entityByID instanceof RocketContraptionEntity rocketEntity))

src/main/java/com/rae/creatingspace/content/rocket/engine/RocketEngineBlockEntity.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ protected void write(CompoundTag nbt, HolderLookup.Provider registries, boolean
7979
try {
8080
nbt.put("propellantType", ResourceLocation.CODEC.encodeStart(NbtOps.INSTANCE,
8181
PropellantTypeInit.getSyncedPropellantRegistry().getKey(propellantType)).getOrThrow());
82-
} catch (Throwable ignored){
83-
nbt.put("propellantType", ResourceLocation.CODEC.encodeStart(NbtOps.INSTANCE,PropellantTypeInit.METHALOX.getId() ).getOrThrow());
84-
CreatingSpace.LOGGER.warn("catch exeption will saving engine : "+propellantType);
85-
CreatingSpace.LOGGER.warn("exeption : "+ignored.getMessage());
82+
} catch (Throwable error){
83+
CreatingSpace.LOGGER.warn("catch exception will saving engine : "+propellantType);
84+
CreatingSpace.LOGGER.warn("exeption : "+error.getMessage());
85+
nbt.put("propellantType", ResourceLocation.CODEC.encodeStart(NbtOps.INSTANCE,CreatingSpace.resource("methalox")).getOrThrow());//PropellantTypeInit.METHALOX.getId()));
8686
}
8787
super.write(nbt,registries, clientPacket);
8888
}
@@ -101,10 +101,10 @@ public void setFromNbt(CompoundTag nbt) {
101101
try {
102102
propellantType = PropellantTypeInit.getSyncedPropellantRegistry().getOptional(ResourceLocation.CODEC.parse(NbtOps.INSTANCE, nbt.get("propellantType")).getOrThrow())
103103
.orElse(PropellantTypeInit.METHALOX.get());
104-
} catch (Throwable ignored){
104+
} catch (Throwable error){
105105
propellantType = PropellantTypeInit.METHALOX.get();
106-
CreatingSpace.LOGGER.warn("catch exeption will loading engine : "+propellantType);
107-
CreatingSpace.LOGGER.warn("exeption : "+ignored.getMessage());
106+
CreatingSpace.LOGGER.warn("catch exception will loading engine : "+propellantType);
107+
CreatingSpace.LOGGER.warn("exeption : "+ error.getMessage());
108108
}
109109
}
110110

src/main/java/com/rae/creatingspace/content/rocket/engine/table/EngineerTableMenu.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,13 @@ public static EngineerTableMenu create(int id, Inventory inv, RocketEngineerTabl
4949

5050
@Override
5151
protected RocketEngineerTableBlockEntity createOnClient(RegistryFriendlyByteBuf extraData) {
52-
//System.out.println("create on client");
5352
ClientLevel world = Minecraft.getInstance().level;
5453
assert world != null;
5554
BlockEntity blockEntity = world.getBlockEntity(extraData.readBlockPos());
5655
if (blockEntity instanceof RocketEngineerTableBlockEntity engineerTable) {
5756
engineerTable.readClient(Objects.requireNonNull(extraData.readNbt()), world.registryAccess());
5857
return engineerTable;
5958
}
60-
//System.out.println("fail");
6159
return null;
6260
}
6361

src/main/java/com/rae/creatingspace/content/rocket/engine/table/RocketEngineerTableBlock.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public BlockState getStateForPlacement(@NotNull BlockPlaceContext context) {
4848
if (level.isClientSide)
4949
return InteractionResult.SUCCESS;
5050
BlockEntity blockentity = level.getBlockEntity(pos);
51-
if (blockentity instanceof RocketEngineerTableBlockEntity) {
52-
player.openMenu((MenuProvider)blockentity);
51+
if (blockentity instanceof RocketEngineerTableBlockEntity be) {
52+
player.openMenu(be, be::sendToMenu);
5353
}
5454
return super.useWithoutItem(state, level, pos, player, hitResult);
5555
}

src/main/java/com/rae/creatingspace/content/rocket/engine/table/RocketEngineerTableBlockEntity.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import net.minecraft.core.HolderLookup;
1515
import net.minecraft.nbt.CompoundTag;
1616
import net.minecraft.nbt.NbtOps;
17+
import net.minecraft.network.RegistryFriendlyByteBuf;
1718
import net.minecraft.network.chat.Component;
1819
import net.minecraft.resources.ResourceLocation;
1920
import net.minecraft.tags.TagKey;
@@ -75,7 +76,7 @@ public RocketEngineerTableBlockEntity(BlockEntityType<?> p_155228_, BlockPos p_1
7576
}
7677

7778
@Override
78-
public AbstractContainerMenu createMenu(int id, Inventory inv, Player player) {
79+
public AbstractContainerMenu createMenu(int id, @NotNull Inventory inv, @NotNull Player player) {
7980
return EngineerTableMenu.create(id, inv, this);
8081
}
8182

@@ -144,6 +145,10 @@ public void readScreenData(SyncData screenInfo) {
144145
propellantType = screenInfo.propellantType;
145146
}
146147

148+
@Override
149+
public void sendToMenu(RegistryFriendlyByteBuf buffer) {
150+
super.sendToMenu(buffer);
151+
}
147152

148153
@Override
149154
public void write(CompoundTag tag, HolderLookup.Provider registries, boolean clientPacket) {

src/main/java/com/rae/creatingspace/content/rocket/network/RocketEngineerTableSync.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import net.minecraft.server.level.ServerPlayer;
1212

1313
public class RocketEngineerTableSync extends BlockEntityConfigurationPacket<RocketEngineerTableBlockEntity> {
14-
private CompoundTag syncData;
14+
private final CompoundTag syncData;
1515
public static final StreamCodec<RegistryFriendlyByteBuf, RocketEngineerTableSync> STREAM_CODEC = StreamCodec.composite(
1616
BlockPos.STREAM_CODEC, packet -> packet.pos,
1717
ByteBufCodecs.COMPOUND_TAG, packet -> packet.syncData,

src/main/java/com/rae/creatingspace/init/ingameobject/PropellantTypeInit.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public class PropellantTypeInit {
2020
public static final DeferredRegister<PropellantType> DEFERRED_PROPELLANT_TYPE =
2121
DeferredRegister.create(Keys.PROPELLANT_TYPE, CreatingSpace.MODID);
2222

23+
static {
24+
//DEFERRED_PROPELLANT_TYPE.makeRegistry((builder) -> builder.sync(true));
25+
}
26+
2327
//.dataPackRegistry(PropellantType.DIRECT_CODEC, PropellantType.DIRECT_CODEC));
2428
public static final DeferredHolder<PropellantType,PropellantType> METHALOX = DEFERRED_PROPELLANT_TYPE
2529
.register("methalox", () -> new PropellantType(
@@ -45,6 +49,7 @@ public class PropellantTypeInit {
4549
public static Registry<PropellantType> getSyncedPropellantRegistry() {
4650
return getSideAwareRegistry(Keys.PROPELLANT_TYPE);
4751
}
52+
4853
public static void register(IEventBus modEventBus) {
4954
DEFERRED_PROPELLANT_TYPE.register(modEventBus);
5055
}

0 commit comments

Comments
 (0)