Skip to content

Commit 2be8efa

Browse files
fixed engineer table crash
1 parent 24c0e51 commit 2be8efa

File tree

8 files changed

+34
-24
lines changed

8 files changed

+34
-24
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,13 @@ public CreatingSpace(IEventBus modEventBus, ModContainer modContainer) {
5454
IEventBus forgeEventBus = NeoForge.EVENT_BUS;
5555
ModLoadingContext modLoadingContext = ModLoadingContext.get();
5656
modEventBus.addListener((DataPackRegistryEvent.NewRegistry event) -> {
57-
event.dataPackRegistry(RocketAccessibleDimension.REGISTRY_KEY,RocketAccessibleDimension.CODEC, RocketAccessibleDimension.CODEC);
57+
event.dataPackRegistry(RocketAccessibleDimension.REGISTRY_KEY,RocketAccessibleDimension.CODEC, RocketAccessibleDimension.CODEC,
58+
(builder) -> builder.sync(true)
59+
);
5860
event.dataPackRegistry(MiscInit.Keys.POWER_PACK_TYPE,PowerPackType.DIRECT_CODEC, PowerPackType.DIRECT_CODEC);
5961
event.dataPackRegistry(MiscInit.Keys.EXHAUST_PACK_TYPE,ExhaustPackType.DIRECT_CODEC, ExhaustPackType.DIRECT_CODEC);
60-
event.dataPackRegistry(PropellantTypeInit.Keys.PROPELLANT_TYPE,PropellantType.DIRECT_CODEC, PropellantType.DIRECT_CODEC);
62+
event.dataPackRegistry(PropellantTypeInit.Keys.PROPELLANT_TYPE,PropellantType.DIRECT_CODEC, PropellantType.DIRECT_CODEC,
63+
(builder) -> builder.sync(true));
6164
LOGGER.debug("added reload for CS registries");
6265
});
6366
/*modEventBus.addListener((NewRegistryEvent event) -> {

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,23 @@
77
import com.rae.creatingspace.api.IMass;
88
import com.rae.creatingspace.content.rocket.engine.design.PropellantType;
99
import com.rae.creatingspace.configs.CSConfigs;
10+
import com.rae.creatingspace.init.TagsInit;
1011
import com.rae.creatingspace.init.ingameobject.PropellantTypeInit;
1112
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity;
1213
import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour;
1314
import net.minecraft.core.BlockPos;
15+
import net.minecraft.core.Holder;
1416
import net.minecraft.core.HolderLookup;
1517
import net.minecraft.nbt.CompoundTag;
1618
import net.minecraft.nbt.NbtOps;
19+
import net.minecraft.resources.ResourceKey;
1720
import net.minecraft.resources.ResourceLocation;
1821
import net.minecraft.world.level.block.entity.BlockEntityType;
1922
import net.minecraft.world.level.block.state.BlockState;
2023

2124
import java.util.List;
25+
import java.util.Map;
26+
import java.util.Objects;
2227

2328
public abstract class RocketEngineBlockEntity extends SmartBlockEntity {
2429

@@ -39,7 +44,7 @@ public RocketEngineBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState
3944

4045
public static class NbtDependent extends RocketEngineBlockEntity implements IMass {
4146
int thrust = 1000;
42-
PropellantType propellantType = PropellantTypeInit.METHALOX.get();
47+
Holder<PropellantType> propellantType = null;//= PropellantTypeInit.METHALOX.get();
4348
Float efficiency = 1f;
4449
int mass = 0;
4550

@@ -64,7 +69,7 @@ public int getThrust() {
6469

6570
@Override
6671
public PropellantType getPropellantType() {
67-
return propellantType;
72+
return propellantType.value();
6873
}
6974

7075
public void setThrust(int thrust) {
@@ -78,7 +83,7 @@ protected void write(CompoundTag nbt, HolderLookup.Provider registries, boolean
7883
nbt.putFloat("efficiency", efficiency);
7984
try {
8085
nbt.put("propellantType", ResourceLocation.CODEC.encodeStart(NbtOps.INSTANCE,
81-
PropellantTypeInit.getSyncedPropellantRegistry().getKey(propellantType)).getOrThrow());
86+
Objects.requireNonNull(propellantType.getKey()).location()).getOrThrow());
8287
} catch (Throwable error){
8388
CreatingSpace.LOGGER.warn("catch exception will saving engine : "+propellantType);
8489
CreatingSpace.LOGGER.warn("exeption : "+error.getMessage());
@@ -90,21 +95,25 @@ protected void write(CompoundTag nbt, HolderLookup.Provider registries, boolean
9095
@Override
9196
public void read(CompoundTag nbt, HolderLookup.Provider registries, boolean clientPacket) {
9297
super.read(nbt,registries,clientPacket);
93-
setFromNbt(nbt);
98+
setFromNbt(nbt, registries);
9499
}
95100

96-
public void setFromNbt(CompoundTag nbt) {
101+
public void setFromNbt(CompoundTag nbt, HolderLookup.Provider registries) {
97102

98103
thrust = nbt.getInt("thrust");
99104
efficiency = nbt.getFloat("efficiency");
100105
mass = nbt.getInt("mass");
101106
try {
102-
propellantType = PropellantTypeInit.getSyncedPropellantRegistry().getOptional(ResourceLocation.CODEC.parse(NbtOps.INSTANCE, nbt.get("propellantType")).getOrThrow())
103-
.orElse(PropellantTypeInit.METHALOX.get());
107+
propellantType = registries.holderOrThrow(ResourceKey.create(
108+
PropellantTypeInit.Keys.PROPELLANT_TYPE,
109+
ResourceLocation.CODEC.parse(NbtOps.INSTANCE, nbt.get("propellantType")).getOrThrow()));
110+
/*propellantType = PropellantTypeInit.getSyncedPropellantRegistry().getOptional().getOrThrow())
111+
.orElse(PropellantTypeInit.METHALOX.get());*/
104112
} catch (Throwable error){
105-
propellantType = PropellantTypeInit.METHALOX.get();
106-
CreatingSpace.LOGGER.warn("catch exception will loading engine : "+propellantType);
113+
//propellantType = PropellantTypeInit.METHALOX.get();
114+
CreatingSpace.LOGGER.warn("catch exception will loading engine : "+nbt);
107115
CreatingSpace.LOGGER.warn("exeption : "+ error.getMessage());
116+
propellantType = null;
108117
}
109118
}
110119

@@ -159,6 +168,7 @@ public float getEfficiency() {
159168

160169
@Override
161170
public PropellantType getPropellantType() {
171+
//need testing.
162172
return PropellantTypeInit.METHALOX.get();
163173
}
164174

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static void appendEngineDependentText(List<Component> components, Compoun
4646
PropellantType propellantType = beTag.contains("propellantType")? PropellantTypeInit.getSyncedPropellantRegistry().getOptional(
4747
ResourceLocation.CODEC.parse(NbtOps.INSTANCE, beTag.get("propellantType"))
4848
.resultOrPartial(s -> {
49-
}).orElse(PropellantTypeInit.METHALOX.getId())).orElseThrow():null;
49+
}).orElseThrow()).orElseThrow():null;
5050
appendEngineTextDirect(components,propellantType,
5151
beTag.contains("efficiency")&&propellantType!=null?(int) (propellantType.getMaxISP() * beTag.getFloat("efficiency")):null,
5252
beTag.contains("mass")?beTag.getInt("mass"):null,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void setPlacedBy(Level worldIn, BlockPos pos, BlockState state, @Nullable
7878
if (worldIn.isClientSide)
7979
return;
8080
withBlockEntityDo(worldIn, pos, be -> {
81-
be.setFromNbt(Objects.requireNonNull(stack.get(DataComponents.CUSTOM_DATA)).copyTag().getCompound("blockEntity"));
81+
be.setFromNbt(Objects.requireNonNull(stack.get(DataComponents.CUSTOM_DATA)).copyTag().getCompound("blockEntity"), worldIn.registryAccess());
8282
});
8383
}
8484

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.rae.creatingspace.content.rocket.engine.design.PropellantType;
66
import com.rae.creatingspace.init.MiscInit;
77
import com.rae.creatingspace.init.ingameobject.PropellantTypeInit;
8+
import net.minecraft.core.HolderLookup;
89
import net.minecraft.core.component.DataComponents;
910
import net.minecraft.nbt.CompoundTag;
1011
import net.minecraft.nbt.NbtOps;
@@ -61,8 +62,8 @@ public void appendHoverText(ItemStack itemStack, @Nullable TooltipContext contex
6162

6263
public ItemStack getBlueprintForEngine(int throatArea, int expansionRatio, int materialLevel, int thrust, float efficiency, ResourceLocation propellantTypeLocation, ResourceLocation exhaustPackTypeLocation, ResourceLocation powerPackTypeLocation) {
6364

64-
PropellantType propellantType = PropellantTypeInit.getSyncedPropellantRegistry().getOptional(
65-
propellantTypeLocation).orElse(PropellantTypeInit.METHALOX.get());
65+
PropellantType propellantType = PropellantTypeInit.getSyncedPropellantRegistry().get(
66+
propellantTypeLocation);
6667
ExhaustPackType exhaustPackType = MiscInit.getSyncedExhaustPackRegistry()
6768
.get(exhaustPackTypeLocation);
6869
PowerPackType powerPackType = MiscInit.getSyncedPowerPackRegistry().get(powerPackTypeLocation);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import java.util.ArrayList;
3535
import java.util.List;
36+
import java.util.Objects;
3637
import java.util.Optional;
3738

3839
import static com.rae.creatingspace.init.MiscInit.getSyncedExhaustPackRegistry;
@@ -305,7 +306,7 @@ else if (exhaustPackTypes.isEmpty() || powerPackTypes.isEmpty()){
305306

306307
private void craftEngine(BlockPos blockEntityPos, ResourceLocation propellantType, ResourceLocation exhaustType, ResourceLocation powerPackType, float isp, float mass, float thrust) {
307308
//send a packet to the BE
308-
float efficiency = isp / getSyncedPropellantRegistry().get(propellantType).getMaxISP();
309+
float efficiency = isp / Objects.requireNonNull(getSyncedPropellantRegistry().get(propellantType)).getMaxISP();
309310
ItemStack engineBlueprint = ((EngineFabricationBlueprint) ItemInit.ENGINE_BLUEPRINT.get().asItem())
310311
.getBlueprintForEngine(engineSizeInput.getState(), expansionRatioSlider.getValueInt(), materialLevel, (int) thrust, efficiency, propellantType, exhaustType, powerPackType);
311312
CatnipServices.NETWORK

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ 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-
27-
//.dataPackRegistry(PropellantType.DIRECT_CODEC, PropellantType.DIRECT_CODEC));
2823
public static final DeferredHolder<PropellantType,PropellantType> METHALOX = DEFERRED_PROPELLANT_TYPE
2924
.register("methalox", () -> new PropellantType(
3025
Map.of(

src/main/java/com/rae/creatingspace/legacy/server/items/BigEngineItem.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public BigEngineItem(Block p_40565_, Properties p_40566_) {
2626
super(p_40565_, p_40566_);
2727
}
2828
@Override
29-
protected boolean canPlace(BlockPlaceContext pContext, BlockState pState) {
29+
protected boolean canPlace(BlockPlaceContext pContext, @NotNull BlockState pState) {
3030
RocketEngineBlock part = (RocketEngineBlock) getBlock();
3131
Level level = pContext.getLevel();
3232
Direction facing = pContext.getClickedFace();
@@ -50,7 +50,7 @@ protected boolean canPlace(BlockPlaceContext pContext, BlockState pState) {
5050
}
5151

5252
@Override
53-
protected boolean placeBlock(BlockPlaceContext pContext, BlockState pState) {
53+
protected boolean placeBlock(BlockPlaceContext pContext, @NotNull BlockState pState) {
5454
RocketEngineBlock part = (RocketEngineBlock) getBlock();
5555
Level lvl = pContext.getLevel();
5656
Direction facing = pContext.getClickedFace();
@@ -103,7 +103,7 @@ private static Direction getGhostDirection(int x, int z, int y) {
103103

104104

105105
@Override
106-
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> components, TooltipFlag flag) {
106+
public void appendHoverText(@NotNull ItemStack stack, @NotNull TooltipContext context, @NotNull List<Component> components, @NotNull TooltipFlag flag) {
107107
//This can be called before registries are bounded to the deferredHolder so check for binding first
108108
if (PropellantTypeInit.METHALOX.isBound())
109109
appendEngineTextDirect(components,PropellantTypeInit.METHALOX.get(), (int) (PropellantTypeInit.METHALOX.get().getMaxISP() * 0.79f),10000,

0 commit comments

Comments
 (0)