Skip to content

Commit 4d6766f

Browse files
committed
bug: Fixed cannon contraption breaking in place of existing cannon resulting in new cannon disconnecting
1 parent 0ce0791 commit 4d6766f

4 files changed

Lines changed: 14 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Fixed:
1212
- Fixed NO_DAMAGE munition damage setting not applying to shrapnel (including flak and grapeshot)
1313
- Fixed Create Pulleys and Gantries pushing more blocks than in vanilla Create
1414
- Fixed display of upside down Cannon Mount and manual Autocannon when solid blocks are above player
15+
- Fixed cannon contraption breaking in place of existing cannon resulting in new cannon disconnecting
1516

1617
## [5.11.2] - 2026-02-27
1718

src/main/java/rbasamoyai/createbigcannons/cannons/CannonBehavior.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public abstract class CannonBehavior extends BlockEntityBehaviour {
2121
protected final Set<Direction> connectedTowards = EnumSet.noneOf(Direction.class);
2222
protected final Set<Direction> weldedTowards = EnumSet.noneOf(Direction.class);
2323
protected Direction currentFacing;
24+
protected boolean protectedFromSurroundingRemovals = false;
2425

2526
protected CannonBehavior(SmartBlockEntity te) {
2627
super(te);
@@ -29,6 +30,7 @@ protected CannonBehavior(SmartBlockEntity te) {
2930
@Override
3031
public void tick() {
3132
super.tick();
33+
this.protectedFromSurroundingRemovals = false;
3234

3335
BlockState state = this.blockEntity.getBlockState();
3436
if (state.hasProperty(BlockStateProperties.FACING)) {
@@ -111,6 +113,7 @@ public void write(CompoundTag nbt, boolean spawnPacket) {
111113

112114
@Override
113115
public void read(CompoundTag nbt, boolean clientPacket) {
116+
this.protectedFromSurroundingRemovals = true;
114117
this.currentFacing = nbt.contains("Facing") ? Direction.byName(nbt.getString("Facing")) : null;
115118

116119
boolean updateFlag = false;
@@ -162,4 +165,6 @@ public boolean canConnectToSide(Direction face) {
162165
return state.getBlock() instanceof CannonContraptionProviderBlock cBlock && cBlock.canConnectToSide(state, face);
163166
}
164167

168+
public boolean isProtectedFromSurroundingRemovals() { return this.protectedFromSurroundingRemovals; }
169+
165170
}

src/main/java/rbasamoyai/createbigcannons/cannons/autocannon/AutocannonBlock.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ default void onRemoveCannon(BlockState state, Level level, BlockPos pos, BlockSt
5252
if (state1.getBlock() instanceof AutocannonBlock cBlock1
5353
&& cBlock1.getAutocannonMaterialInLevel(level, state1, pos1) == material
5454
&& cBlock1.canConnectToSide(state1, opposite)
55-
&& be1 instanceof IAutocannonBlockEntity cbe1) {
55+
&& be1 instanceof IAutocannonBlockEntity cbe1
56+
&& !cbe1.cannonBehavior().isProtectedFromSurroundingRemovals()) {
5657
cbe1.cannonBehavior().setConnectedFace(opposite, false);
5758
cbe1.cannonBehavior().setWelded(opposite, false);
5859
cbe1.cannonBehavior().blockEntity.setChanged();
@@ -67,7 +68,8 @@ default void onRemoveCannon(BlockState state, Level level, BlockPos pos, BlockSt
6768
if (state2.getBlock() instanceof AutocannonBlock cBlock2
6869
&& cBlock2.getAutocannonMaterialInLevel(level, state2, pos2) == material
6970
&& cBlock2.canConnectToSide(state2, facing)
70-
&& be2 instanceof IAutocannonBlockEntity cbe2) {
71+
&& be2 instanceof IAutocannonBlockEntity cbe2
72+
&& !cbe2.cannonBehavior().isProtectedFromSurroundingRemovals()) {
7173
cbe2.cannonBehavior().setConnectedFace(facing, false);
7274
cbe2.cannonBehavior().setWelded(facing, false);
7375
cbe2.cannonBehavior().blockEntity.setChanged();

src/main/java/rbasamoyai/createbigcannons/cannons/big_cannons/BigCannonBlock.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ default void onRemoveCannon(BlockState state, Level level, BlockPos pos, BlockSt
8181
if (this.canConnectToSide(state, facing)
8282
&& state1.getBlock() instanceof BigCannonBlock cBlock1
8383
&& cBlock1.getCannonMaterialInLevel(level, state1, pos1) == material
84+
&& cBlock1.canConnectToSide(state1, opposite)
8485
&& be1 instanceof IBigCannonBlockEntity cbe1
85-
&& cBlock1.canConnectToSide(state1, opposite)) {
86+
&& !cbe1.cannonBehavior().isProtectedFromSurroundingRemovals()) {
8687
cbe1.cannonBehavior().setConnectedFace(opposite, false);
8788
cbe1.cannonBehavior().setWelded(opposite, false);
8889
if (cbe1 instanceof LayeredBigCannonBlockEntity layered) {
@@ -99,8 +100,9 @@ default void onRemoveCannon(BlockState state, Level level, BlockPos pos, BlockSt
99100
if (this.canConnectToSide(state, opposite)
100101
&& state2.getBlock() instanceof BigCannonBlock cBlock2
101102
&& cBlock2.getCannonMaterialInLevel(level, state2, pos2) == material
103+
&& cBlock2.canConnectToSide(state2, facing)
102104
&& be2 instanceof IBigCannonBlockEntity cbe2
103-
&& cBlock2.canConnectToSide(state2, facing)) {
105+
&& !cbe2.cannonBehavior().isProtectedFromSurroundingRemovals()) {
104106
cbe2.cannonBehavior().setConnectedFace(facing, false);
105107
cbe2.cannonBehavior().setWelded(facing, false);
106108
if (cbe2 instanceof LayeredBigCannonBlockEntity layered) {
@@ -151,7 +153,6 @@ static void onPlace(Level level, BlockPos pos) {
151153
if (be instanceof IBigCannonBlockEntity cbe) {
152154
BlockPos pos1 = pos.relative(facing);
153155
BlockState state1 = level.getBlockState(pos1);
154-
BlockEntity be1 = level.getBlockEntity(pos1);
155156

156157
if (cBlock.canConnectToSide(state, facing)
157158
&& state1.getBlock() instanceof BigCannonBlock cBlock1
@@ -188,7 +189,6 @@ static void onPlace(Level level, BlockPos pos) {
188189

189190
BlockPos pos2 = pos.relative(opposite);
190191
BlockState state2 = level.getBlockState(pos2);
191-
BlockEntity be2 = level.getBlockEntity(pos2);
192192

193193
if (cBlock.canConnectToSide(state, opposite)
194194
&& state2.getBlock() instanceof BigCannonBlock cBlock2

0 commit comments

Comments
 (0)