Skip to content

Commit 34a11c9

Browse files
committed
port wip
1 parent 23d5509 commit 34a11c9

File tree

19 files changed

+271
-372
lines changed

19 files changed

+271
-372
lines changed

src/main/java/com/mrh0/createaddition/blocks/alternator/AlternatorBlockEntity.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,14 @@ protected Block getStressConfigKey() {
129129
return CABlocks.ALTERNATOR.get();
130130
}
131131

132-
@Override
133-
public void remove() {
134-
lazyEnergy.invalidate();
135-
super.remove();
136-
}
137-
138132
public void firstTick() {
139133
updateCache();
140134
};
141135

142136
public void updateCache() {
143-
if(level.isClientSide()) return;
144-
for(Direction side : Direction.values()) {
137+
if (level == null) return;
138+
if (level.isClientSide()) return;
139+
for (Direction side : Direction.values()) {
145140
BlockEntity te = level.getBlockEntity(worldPosition.relative(side));
146141
if(te == null) {
147142
setCache(side, LazyOptional.empty());

src/main/java/com/mrh0/createaddition/blocks/connector/SmallLightConnectorBlockEntity.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.mrh0.createaddition.energy.network.EnergyNetwork;
77
import com.simibubi.create.foundation.blockEntity.behaviour.BlockEntityBehaviour;
88
import net.minecraft.core.BlockPos;
9+
import net.minecraft.core.HolderLookup;
910
import net.minecraft.nbt.CompoundTag;
1011
import net.minecraft.world.level.block.entity.BlockEntityType;
1112
import net.minecraft.world.level.block.state.BlockState;
@@ -32,15 +33,15 @@ public SmallLightConnectorBlockEntity(BlockEntityType<?> blockEntityTypeIn, Bloc
3233
}
3334

3435
@Override
35-
public void read(CompoundTag nbt, boolean clientPacket) {
36+
public void read(CompoundTag nbt, HolderLookup.Provider registries, boolean clientPacket) {
3637
tickToggleTimer = nbt.getInt("tick_toggle_timer");
37-
super.read(nbt, clientPacket);
38+
super.read(nbt, registries, clientPacket);
3839
}
3940

4041
@Override
41-
public void write(CompoundTag nbt, boolean clientPacket) {
42+
public void writeSafe(CompoundTag nbt, HolderLookup.Provider registries) {
4243
nbt.putInt("tick_toggle_timer", tickToggleTimer);
43-
super.write(nbt, clientPacket);
44+
super.writeSafe(nbt, registries);
4445
}
4546

4647
@Override

src/main/java/com/mrh0/createaddition/blocks/connector/base/AbstractConnectorBlockEntity.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,10 @@ public void updateExternalEnergyStorage() {
373373
if (level == null) return;
374374
if (!(level instanceof ServerLevel)) return;
375375
if (!level.isLoaded(getBlockPos())) return;
376-
externalStorageInvalid = false;
377376
var side = getBlockState().getValue(AbstractConnectorBlock.FACING);
377+
if (!level.isLoaded(getBlockPos().relative(side))) return;
378+
externalStorageInvalid = false;
379+
378380
//if (!level.isLoaded(worldPosition.relative(side))) {
379381
// external = LazyOptional.empty();
380382
// return;
@@ -394,8 +396,8 @@ public void updateExternalEnergyStorage() {
394396
external = BlockCapabilityCache.create(
395397
Capabilities.EnergyStorage.BLOCK, // capability to cache
396398
(ServerLevel) level, // level
397-
getPos(),
398-
side,
399+
getPos().relative(side),
400+
side.getOpposite(),
399401
() -> !this.isRemoved(), // validity check (because the cache might outlive the object it belongs to)
400402
() -> { externalStorageInvalid = true; } // invalidation listener
401403
);

src/main/java/com/mrh0/createaddition/blocks/connector/base/ConnectorMode.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
import net.minecraft.util.StringRepresentable;
88
import net.minecraft.world.level.Level;
99
import net.minecraft.world.level.block.entity.BlockEntity;
10-
import net.minecraftforge.common.capabilities.ForgeCapabilities;
11-
import net.minecraftforge.common.util.LazyOptional;
12-
import net.minecraftforge.energy.IEnergyStorage;
10+
import net.neoforged.neoforge.capabilities.Capabilities;
11+
import net.neoforged.neoforge.energy.IEnergyStorage;
1312

1413
public enum ConnectorMode implements StringRepresentable {
1514
Push("push"),
@@ -63,16 +62,13 @@ public boolean isActive() {
6362
public static ConnectorMode test(Level level, BlockPos pos, Direction face) {
6463
BlockEntity be = level.getBlockEntity(pos);
6564
if(be == null) return None;
66-
LazyOptional<IEnergyStorage> optional = be.getCapability(ForgeCapabilities.ENERGY, face);
67-
if(!optional.isPresent()) optional = be.getCapability(ForgeCapabilities.ENERGY);
68-
if(!optional.isPresent()) return None;
69-
if(optional.orElse(null) == null) return None;
70-
71-
IEnergyStorage e = optional.orElse(null);
65+
IEnergyStorage energy = level.getCapability(Capabilities.EnergyStorage.BLOCK, pos, face);
66+
if (energy == null) energy = level.getCapability(Capabilities.EnergyStorage.BLOCK, pos, null);
67+
if (energy == null) return None;
7268

7369
// if(e.canExtract() && e.canReceive()) return Passive;
74-
if(e.canExtract()) return Pull;
75-
if(e.canReceive()) return Push;
70+
if(energy.canExtract()) return Pull;
71+
if(energy.canReceive()) return Push;
7672

7773
return None;
7874
}

src/main/java/com/mrh0/createaddition/blocks/creative_energy/CreativeEnergyBlockEntity.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,15 @@
88
import net.minecraft.world.level.block.entity.BlockEntity;
99
import net.minecraft.world.level.block.entity.BlockEntityType;
1010
import net.minecraft.world.level.block.state.BlockState;
11-
import net.minecraftforge.common.capabilities.Capability;
12-
import net.minecraftforge.common.capabilities.ForgeCapabilities;
13-
import net.minecraftforge.common.util.LazyOptional;
14-
import net.minecraftforge.energy.IEnergyStorage;
11+
import net.neoforged.neoforge.energy.IEnergyStorage;
1512

1613
public class CreativeEnergyBlockEntity extends CrateBlockEntity {
1714

1815
protected final CreativeEnergyStorage energy;
19-
private LazyOptional<IEnergyStorage> lazyEnergy;
2016

2117
public CreativeEnergyBlockEntity(BlockEntityType<?> tileEntityTypeIn, BlockPos pos, BlockState state) {
2218
super(tileEntityTypeIn, pos, state);
2319
energy = new CreativeEnergyStorage();
24-
lazyEnergy = LazyOptional.of(() -> energy);
25-
}
26-
27-
@Override
28-
public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
29-
if(cap == ForgeCapabilities.ENERGY)// && !level.isClientSide
30-
return lazyEnergy.cast();
31-
return super.getCapability(cap, side);
3220
}
3321

3422
private boolean firstTickState = true;
@@ -50,11 +38,6 @@ public void tick() {
5038
}
5139
}
5240

53-
@Override
54-
public void remove() {
55-
lazyEnergy.invalidate();
56-
}
57-
5841
public void firstTick() {
5942
updateCache();
6043
};

src/main/java/com/mrh0/createaddition/blocks/digital_adapter/DigitalAdapterBlockEntity.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
import net.minecraft.world.level.block.entity.BlockEntity;
1919
import net.minecraft.world.level.block.entity.BlockEntityType;
2020
import net.minecraft.world.level.block.state.BlockState;
21-
import net.minecraftforge.common.capabilities.Capability;
22-
import net.minecraftforge.common.util.LazyOptional;
2321

2422
import javax.annotation.Nonnull;
2523
import java.util.ArrayList;
@@ -30,15 +28,15 @@ public class DigitalAdapterBlockEntity extends BlockEntity {
3028
public static final int MAX_LINES = 16;
3129
public static final MutableComponent EMPTY_LINE = Component.literal("");
3230

33-
protected LazyOptional<DigitalAdapterPeripheral> peripheral;
31+
//protected LazyOptional<DigitalAdapterPeripheral> peripheral;
3432

3533
public DigitalAdapterBlockEntity(BlockEntityType<?> tileEntityTypeIn, BlockPos pos, BlockState state) {
3634
super(tileEntityTypeIn, pos, state);
3735
textLines = new ArrayList<>();
3836
for(int i = 0; i < MAX_LINES; i++) textLines.add(EMPTY_LINE);
3937

40-
if (CreateAddition.CC_ACTIVE)
41-
this.peripheral = LazyOptional.of(() -> Peripherals.createDigitalAdapterPeripheral(this));
38+
//if (CreateAddition.CC_ACTIVE)
39+
// this.peripheral = LazyOptional.of(() -> Peripherals.createDigitalAdapterPeripheral(this));
4240
}
4341

4442
private int line = 1;
@@ -78,12 +76,12 @@ public int setLine(int ln) {
7876
return line = ln < 1 || ln > DigitalAdapterBlockEntity.MAX_LINES ? line : ln;
7977
}
8078

81-
@Nonnull
82-
@Override
83-
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @javax.annotation.Nullable Direction side) {
84-
if (CreateAddition.CC_ACTIVE && Peripherals.isPeripheral(cap)) return this.peripheral.cast();
85-
return super.getCapability(cap, side);
86-
}
79+
//@Nonnull
80+
//@Override
81+
//public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @javax.annotation.Nullable Direction side) {
82+
// if (CreateAddition.CC_ACTIVE && Peripherals.isPeripheral(cap)) return this.peripheral.cast();
83+
// return super.getCapability(cap, side);
84+
//}
8785

8886
public SpeedControllerBlockEntity getSpeedController(Direction dir) {
8987
BlockEntity be = this.level.getBlockEntity(getBlockPos().relative(dir));

src/main/java/com/mrh0/createaddition/blocks/liquid_blaze_burner/LiquidBlazeBurnerBlock.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
import javax.annotation.Nullable;
66

7+
import com.mojang.serialization.MapCodec;
78
import com.mrh0.createaddition.index.CABlockEntities;
89
import com.simibubi.create.AllBlocks;
910
import com.simibubi.create.AllItems;
1011
import com.simibubi.create.AllShapes;
1112
import com.simibubi.create.content.equipment.wrench.IWrenchable;
1213
import com.simibubi.create.content.processing.basin.BasinBlockEntity;
1314
import com.simibubi.create.content.processing.burner.BlazeBurnerBlock;
14-
import com.simibubi.create.content.processing.burner.BlazeBurnerBlock.HeatLevel;
1515
import com.simibubi.create.foundation.block.IBE;
1616

1717
import net.minecraft.core.BlockPos;
@@ -21,6 +21,7 @@
2121
import net.minecraft.world.InteractionHand;
2222
import net.minecraft.world.InteractionResult;
2323
import net.minecraft.world.InteractionResultHolder;
24+
import net.minecraft.world.ItemInteractionResult;
2425
import net.minecraft.world.entity.player.Player;
2526
import net.minecraft.world.item.CreativeModeTab;
2627
import net.minecraft.world.item.Item;
@@ -38,9 +39,9 @@
3839
import net.minecraft.world.phys.BlockHitResult;
3940
import net.minecraft.world.phys.shapes.CollisionContext;
4041
import net.minecraft.world.phys.shapes.VoxelShape;
41-
import net.minecraftforge.api.distmarker.Dist;
42-
import net.minecraftforge.api.distmarker.OnlyIn;
43-
import net.minecraftforge.common.util.FakePlayer;
42+
import net.neoforged.api.distmarker.Dist;
43+
import net.neoforged.api.distmarker.OnlyIn;
44+
import net.neoforged.neoforge.common.util.FakePlayer;
4445

4546
public class LiquidBlazeBurnerBlock extends HorizontalDirectionalBlock implements IBE<LiquidBlazeBurnerBlockEntity>, IWrenchable {
4647

@@ -51,6 +52,13 @@ public LiquidBlazeBurnerBlock(Properties properties) {
5152
registerDefaultState(defaultBlockState().setValue(HEAT_LEVEL, BlazeBurnerBlock.HeatLevel.NONE));
5253
}
5354

55+
public static final MapCodec<BlazeBurnerBlock> CODEC = simpleCodec(BlazeBurnerBlock::new);
56+
57+
@Override
58+
protected MapCodec<? extends HorizontalDirectionalBlock> codec() {
59+
return CODEC;
60+
}
61+
5462
@Override
5563
protected void createBlockStateDefinition(Builder<Block, BlockState> builder) {
5664
super.createBlockStateDefinition(builder);
@@ -90,28 +98,26 @@ public Item asItem() {
9098
}
9199

92100
@Override
93-
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand,
94-
BlockHitResult hit) {
95-
101+
protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult) {
96102
ItemStack heldItem = player.getItemInHand(hand);
97103
BlazeBurnerBlock.HeatLevel heat = state.getValue(HEAT_LEVEL);
98104

99105
if (AllItems.GOGGLES.isIn(heldItem) && heat != BlazeBurnerBlock.HeatLevel.NONE)
100-
return onBlockEntityUse(level, pos, be -> {
106+
return onBlockEntityUseItemOn(level, pos, be -> {
101107
if (be.goggles)
102-
return InteractionResult.PASS;
108+
return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
103109
be.goggles = true;
104110
be.notifyUpdate();
105-
return InteractionResult.SUCCESS;
111+
return ItemInteractionResult.SUCCESS;
106112
});
107113

108114
if (heldItem.isEmpty() && heat != BlazeBurnerBlock.HeatLevel.NONE)
109-
return onBlockEntityUse(level, pos, be -> {
115+
return onBlockEntityUseItemOn(level, pos, be -> {
110116
if (!be.goggles)
111-
return InteractionResult.PASS;
117+
return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
112118
be.goggles = false;
113119
be.notifyUpdate();
114-
return InteractionResult.SUCCESS;
120+
return ItemInteractionResult.SUCCESS;
115121
});
116122

117123
boolean doNotConsume = player.isCreative();
@@ -129,7 +135,7 @@ public InteractionResult use(BlockState state, Level level, BlockPos pos, Player
129135
}
130136
}
131137

132-
return res.getResult() == InteractionResult.SUCCESS ? InteractionResult.SUCCESS : InteractionResult.PASS;
138+
return res.getResult() == InteractionResult.SUCCESS ? ItemInteractionResult.SUCCESS : ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
133139
}
134140

135141
public static InteractionResultHolder<ItemStack> tryInsert(BlockState state, Level level, BlockPos pos,
@@ -185,12 +191,10 @@ public int getAnalogOutputSignal(BlockState state, Level level, BlockPos pos) {
185191
}
186192

187193
@Override
188-
public boolean isPathfindable(BlockState state, BlockGetter getter, BlockPos pos, PathComputationType type) {
194+
protected boolean isPathfindable(BlockState state, PathComputationType pathComputationType) {
189195
return false;
190196
}
191197

192-
193-
194198
@OnlyIn(Dist.CLIENT)
195199
public void animateTick(BlockState state, Level world, BlockPos pos, Random random) {
196200
if (random.nextInt(10) != 0)

0 commit comments

Comments
 (0)