Skip to content

Commit

Permalink
bug, refactor: Fixed elevator assembly issue
Browse files Browse the repository at this point in the history
  • Loading branch information
rbasamoyai committed Dec 8, 2024
1 parent 94ea051 commit f33182a
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 22 deletions.
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Fixed:
- Fixed autocannon round duplication glitch
- Fixed projectile ground tracking
- Fixed strength attributes for incomplete and unbored sliding breeches to be consistent with complete sliding breeches
- Fixed elevator assembly issue


5.6.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import rbasamoyai.createbigcannons.CBCClientCommon;
import rbasamoyai.createbigcannons.CreateBigCannons;
import rbasamoyai.createbigcannons.compat.trinkets.CBCTrinketsClient;
import rbasamoyai.createbigcannons.fabric.mixin.client.KeyMappingAccessor;
import rbasamoyai.createbigcannons.fabric.network.CBCNetworkFabric;
Expand Down Expand Up @@ -84,6 +85,7 @@ private static void wrapOverlay(String id, CBCClientCommon.CBCGuiOverlay overlay
}

public static void onModsLoaded(EnvType envType) {
CreateBigCannons.onCommonSetup();
if (envType != EnvType.CLIENT)
return;
CBCModsFabric.TRINKETS.executeIfInstalled(() -> () -> CBCTrinketsClient.initClient());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private void onCommonSetup(FMLCommonSetupEvent event) {
DefaultFluidCompat.registerMinecraftBlobEffects();
DefaultFluidCompat.registerCreateBlobEffects();

CreateBigCannons.onCommonSetup();
DefaultCreateCompat.init();
DefaultCannonMountPropertiesSerializers.init();
CBCModsForge.COPYCATS.executeIfInstalled(() -> () -> CopycatsCompat.init());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.world.level.Level;
import rbasamoyai.createbigcannons.base.PartialBlockDamageManager;
import rbasamoyai.createbigcannons.cannon_control.cannon_types.CBCCannonContraptionTypes;
import rbasamoyai.createbigcannons.cannon_loading.CBCModifiedContraptionRegistry;
import rbasamoyai.createbigcannons.index.CBCArmInteractionPointTypes;
import rbasamoyai.createbigcannons.index.CBCBlockEntities;
import rbasamoyai.createbigcannons.index.CBCBlocks;
Expand Down Expand Up @@ -92,4 +93,8 @@ public static <T extends Explosion & CustomExplosion> void handleCustomExplosion
explosion.sendExplosionToClient(player);
}

public static void onCommonSetup() {
CBCModifiedContraptionRegistry.registerDefaults();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package rbasamoyai.createbigcannons.cannon_loading;

import com.simibubi.create.content.contraptions.Contraption;
import com.simibubi.create.content.contraptions.ContraptionType;

import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet;
import rbasamoyai.createbigcannons.index.CBCContraptionTypes;
import rbasamoyai.createbigcannons.remix.HasFragileContraption;

public class CBCModifiedContraptionRegistry {

private static final ReferenceOpenHashSet<ContraptionType> CANNON_LOADER_TYPES = new ReferenceOpenHashSet<>();
private static final ReferenceOpenHashSet<ContraptionType> FRAGILE_TYPES = new ReferenceOpenHashSet<>();

public static void registerCannonLoaderType(ContraptionType type) {
if (CANNON_LOADER_TYPES.contains(type))
throw new IllegalStateException("Already registered big cannon loader contraption type");
CANNON_LOADER_TYPES.add(type);
}

public static void registerFragileType(ContraptionType type) {
if (FRAGILE_TYPES.contains(type))
throw new IllegalStateException("Already registered fragile contraption type");
FRAGILE_TYPES.add(type);
}

public static boolean canLoadBigCannon(Contraption contraption) {
return CANNON_LOADER_TYPES.contains(contraption.getType()) && contraption instanceof CanLoadBigCannon;
}

public static boolean isFragileContraption(Contraption contraption) {
return FRAGILE_TYPES.contains(contraption.getType()) && contraption instanceof HasFragileContraption;
}

public static void registerDefaults() {
registerCannonLoaderType(CBCContraptionTypes.CANNON_LOADER);
registerCannonLoaderType(ContraptionType.PISTON);
registerCannonLoaderType(ContraptionType.GANTRY);
registerCannonLoaderType(ContraptionType.PULLEY);
registerFragileType(CBCContraptionTypes.CANNON_LOADER);
registerFragileType(ContraptionType.PISTON);
registerFragileType(ContraptionType.GANTRY);
registerFragileType(ContraptionType.PULLEY);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
import com.simibubi.create.content.contraptions.AssemblyException;
import com.simibubi.create.content.contraptions.Contraption;
import com.simibubi.create.content.contraptions.ContraptionType;
import com.simibubi.create.content.contraptions.StructureTransform;
import com.simibubi.create.content.contraptions.chassis.ChassisBlockEntity;
import com.simibubi.create.content.contraptions.glue.SuperGlueEntity;
Expand All @@ -34,6 +35,7 @@
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo;
import rbasamoyai.createbigcannons.cannon_loading.CBCModifiedContraptionRegistry;
import rbasamoyai.createbigcannons.cannon_loading.CanLoadBigCannon;
import rbasamoyai.createbigcannons.cannons.big_cannons.BigCannonBlock;
import rbasamoyai.createbigcannons.cannons.big_cannons.IBigCannonBlockEntity;
Expand All @@ -58,23 +60,25 @@ public abstract class ContraptionMixin {
private void createbigcannons$searchMovedStructure$setForcedDirection(Level level, BlockPos pos, Direction forcedDirection,
CallbackInfoReturnable<Boolean> cir,
@Local(argsOnly = true) LocalRef<Direction> forcedDirectionRef) {
if (!(this.createbigcannons$self instanceof CanLoadBigCannon loader)) return;
if (forcedDirectionRef.get() == null) forcedDirectionRef.set(loader.createbigcannons$getAssemblyMovementDirection(level));
if (!(CBCModifiedContraptionRegistry.canLoadBigCannon(this.createbigcannons$self))) return;
if (forcedDirectionRef.get() == null)
forcedDirectionRef.set(((CanLoadBigCannon) this.createbigcannons$self).createbigcannons$getAssemblyMovementDirection(level));
}

@Inject(method = "searchMovedStructure",
at = @At(value = "INVOKE", target = "Ljava/util/Queue;add(Ljava/lang/Object;)Z", shift = At.Shift.AFTER),
remap = false)
private void createbigcannons$searchMovedStructure$removePulley(Level level, BlockPos pos, Direction forcedDirection,
CallbackInfoReturnable<Boolean> cir, @Local Queue<BlockPos> frontier) {
if (this.createbigcannons$self instanceof PulleyContraption pulley)
ContraptionRemix.pulleyChecks(pulley, level, pos, forcedDirection, frontier);
if (this.createbigcannons$self.getType() == ContraptionType.PULLEY)
ContraptionRemix.pulleyChecks((PulleyContraption) this.createbigcannons$self, level, pos, forcedDirection, frontier);
}

@Inject(method = "addBlocksToWorld", at = @At("HEAD"))
private void createbigcannons$addBlocksToWorld(Level world, StructureTransform transform, CallbackInfo ci) {
if (this.disassembled || !(this.createbigcannons$self instanceof HasFragileContraption fragile))
if (this.disassembled || !(CBCModifiedContraptionRegistry.isFragileContraption(this.createbigcannons$self)))
return;
HasFragileContraption fragile = (HasFragileContraption) this.createbigcannons$self;
if (!fragile.createbigcannons$isBrokenDisassembly())
fragile.createbigcannons$setBrokenDisassembly(HasFragileContraption.checkForIntersectingBlocks(this.createbigcannons$self.entity.level(), this.createbigcannons$self.entity, fragile));
}
Expand Down Expand Up @@ -105,34 +109,34 @@ public abstract class ContraptionMixin {
private void createbigcannons$moveBlock$stickerMarking(Level level, Direction forcedDirection, Queue<BlockPos> frontier,
Set<BlockPos> visited, CallbackInfoReturnable<Boolean> cir,
@Local(ordinal = 1) Direction offset, @Local(ordinal = 1) BlockPos attached) {
if (this.createbigcannons$self instanceof CanLoadBigCannon)
if (CBCModifiedContraptionRegistry.canLoadBigCannon(this.createbigcannons$self))
ContraptionRemix.stickerMarking((Contraption & CanLoadBigCannon) this.createbigcannons$self, level, attached, offset, forcedDirection);
}

@Inject(method = "moveChassis", at = @At(value = "TAIL", shift = At.Shift.BEFORE), remap = false)
private void createbigcannons$moveChassis(Level level, BlockPos pos, Direction movementDirection, Queue<BlockPos> frontier,
Set<BlockPos> visited, CallbackInfoReturnable<Boolean> cir,
@Local ChassisBlockEntity chassis, @Local List<BlockPos> includedBlockPositions) {
if (this.createbigcannons$self instanceof CanLoadBigCannon)
if (CBCModifiedContraptionRegistry.canLoadBigCannon(this.createbigcannons$self))
ContraptionRemix.chassisMarking((Contraption & CanLoadBigCannon) this.createbigcannons$self, level, includedBlockPositions, frontier, visited, movementDirection, chassis);
}

@Inject(method = "moveMechanicalPiston", at = @At("TAIL"), remap = false)
private void createbigcannons$moveMechanicalPiston(Level level, BlockPos pos, Queue<BlockPos> frontier, Set<BlockPos> visited,
BlockState state, CallbackInfoReturnable<Boolean> cir) {
if (this.createbigcannons$self instanceof CanLoadBigCannon)
if (CBCModifiedContraptionRegistry.canLoadBigCannon(this.createbigcannons$self))
ContraptionRemix.pistonMarking((Contraption & CanLoadBigCannon) this.createbigcannons$self, level, pos, state);
}

@Inject(method = "movePistonHead", at = @At("TAIL"), remap = false)
private void createbigcannons$movePistonHead(Level level, BlockPos pos, Queue<BlockPos> frontier, Set<BlockPos> visited, BlockState state, CallbackInfo ci) {
if (this.createbigcannons$self instanceof CanLoadBigCannon)
if (CBCModifiedContraptionRegistry.canLoadBigCannon(this.createbigcannons$self))
ContraptionRemix.pistonHeadMarking((Contraption & CanLoadBigCannon) this.createbigcannons$self, level, pos, state);
}

@Inject(method = "moveGantryPinion", at = @At("HEAD"), remap = false)
private void createbigcannons$moveGantryPinion(Level level, BlockPos pos, Queue<BlockPos> frontier, Set<BlockPos> visited, BlockState state, CallbackInfo ci) {
if (this.createbigcannons$self instanceof CanLoadBigCannon)
if (CBCModifiedContraptionRegistry.canLoadBigCannon(this.createbigcannons$self))
ContraptionRemix.gantryCarriageMarking((Contraption & CanLoadBigCannon) this.createbigcannons$self, level, pos, state);
}

Expand All @@ -141,7 +145,7 @@ public abstract class ContraptionMixin {
private void createbigcannons$moveBlock$loaderBlocks(Level level, Direction forcedDirection, Queue<BlockPos> frontier,
Set<BlockPos> visited, CallbackInfoReturnable<Boolean> cir,
@Local BlockPos pos, @Local BlockState state) {
if (this.createbigcannons$self instanceof CanLoadBigCannon)
if (CBCModifiedContraptionRegistry.canLoadBigCannon(this.createbigcannons$self))
ContraptionRemix.moveLoaderBlocks((Contraption & CanLoadBigCannon) this.createbigcannons$self, level, forcedDirection, frontier, visited, pos, state);
}

Expand All @@ -158,7 +162,7 @@ public abstract class ContraptionMixin {
@Local(ordinal = 2) boolean blockAttachedTowardsFace,
@Share("removeFlag") LocalBooleanRef removeFlag) {
removeFlag.set(false);
if (!(this.createbigcannons$self instanceof CanLoadBigCannon) || frontier.contains(offsetPos)) return;
if (!(CBCModifiedContraptionRegistry.canLoadBigCannon(this.createbigcannons$self)) || frontier.contains(offsetPos)) return;
boolean stickFlag = ContraptionRemix.getStickFlag((Contraption & CanLoadBigCannon) this.createbigcannons$self, level, pos, offsetPos,
state, blockState, offset, forcedDirection, faceHasGlue | blockAttachedTowardsFace);
removeFlag.set(ContraptionRemix.handleCannonFrontier((Contraption & CanLoadBigCannon) this.createbigcannons$self, level, pos, offsetPos,
Expand All @@ -172,7 +176,7 @@ public abstract class ContraptionMixin {
Set<BlockPos> visited, CallbackInfoReturnable<Boolean> cir,
@Local(ordinal = 2) BlockPos offsetPos,
@Share("removeFlag") LocalBooleanRef removeFlag) {
if (this.createbigcannons$self instanceof CanLoadBigCannon && removeFlag.get())
if (CBCModifiedContraptionRegistry.canLoadBigCannon(this.createbigcannons$self) && removeFlag.get())
frontier.remove(offsetPos);
}

Expand All @@ -181,7 +185,7 @@ public abstract class ContraptionMixin {
private Pair<StructureBlockInfo, BlockEntity> createbigcannons$moveBlock$preCannonBlockCapture(Pair<StructureBlockInfo, BlockEntity> original,
Level level, @Nullable Direction forcedDirection, Queue<BlockPos> frontier, Set<BlockPos> visited,
@Local(ordinal = 0) BlockPos pos) {
if (this.createbigcannons$self instanceof CanLoadBigCannon) {
if (CBCModifiedContraptionRegistry.canLoadBigCannon(this.createbigcannons$self)) {
Pair<StructureBlockInfo, BlockEntity> pair = ContraptionRemix.handleCapture((Contraption & CanLoadBigCannon) this.createbigcannons$self,
level, pos, frontier, visited, forcedDirection, this.glueToRemove);
return pair == null ? original : pair;
Expand All @@ -192,7 +196,7 @@ public abstract class ContraptionMixin {
@Inject(method = "movePulley", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;getBlock()Lnet/minecraft/world/level/block/Block;", shift = At.Shift.BEFORE))
private void createbigcannons$movePulley$0(Level level, BlockPos pos, Queue<BlockPos> frontier, Set<BlockPos> visited, CallbackInfo ci,
@Local(ordinal = 1) BlockPos ropePos, @Local LocalRef<BlockState> ropeState) {
if (this.createbigcannons$self instanceof CanLoadBigCannon)
if (CBCModifiedContraptionRegistry.canLoadBigCannon(this.createbigcannons$self))
ropeState.set(ContraptionRemix.getInnerCannonState(level, ropeState.get(), ropePos, Direction.DOWN));
}

Expand Down Expand Up @@ -221,8 +225,8 @@ public abstract class ContraptionMixin {
Level level, BlockPos pos,
@Local(ordinal = 1) BlockPos ropePos) {
Direction forcedDirection = null;
if (this.createbigcannons$self instanceof CanLoadBigCannon loader)
forcedDirection = loader.createbigcannons$getAssemblyMovementDirection(level);
if (CBCModifiedContraptionRegistry.canLoadBigCannon(this.createbigcannons$self))
forcedDirection = ((CanLoadBigCannon) this.createbigcannons$self).createbigcannons$getAssemblyMovementDirection(level);
BlockState state = level.getBlockState(ropePos);
BlockPos local = this.toLocalPos(ropePos);

Expand All @@ -242,23 +246,23 @@ public abstract class ContraptionMixin {
@Inject(method = "searchMovedStructure", at = @At(value = "RETURN", ordinal = 1), remap = false)
private void createbigcannons$searchMovedStructure(Level level, BlockPos pos, Direction forcedDirection, CallbackInfoReturnable<Boolean> cir) throws AssemblyException {
ContraptionRemix.validateCannonRope(this.createbigcannons$self, level, forcedDirection, this::toLocalPos);
if (this.createbigcannons$self instanceof HasFragileContraption)
if (CBCModifiedContraptionRegistry.isFragileContraption(this.createbigcannons$self))
ContraptionRemix.markFragileBlocks((Contraption & HasFragileContraption) this.createbigcannons$self);
}

@Inject(method = "readNBT", at = @At("TAIL"), remap = false)
private void createbigcannons$readNBT(Level level, CompoundTag nbt, boolean spawnData, CallbackInfo ci) {
if (this.createbigcannons$self instanceof CanLoadBigCannon)
if (CBCModifiedContraptionRegistry.canLoadBigCannon(this.createbigcannons$self))
ContraptionRemix.readCannonLoaderData((Contraption & CanLoadBigCannon) this.createbigcannons$self, nbt);
if (this.createbigcannons$self instanceof HasFragileContraption)
if (CBCModifiedContraptionRegistry.isFragileContraption(this.createbigcannons$self))
ContraptionRemix.readFragileBlocks((Contraption & HasFragileContraption) this.createbigcannons$self, nbt);
}

@Inject(method = "writeNBT", at = @At("TAIL"), remap = false)
private void createbigcannons$writeNBT(boolean spawnPacket, CallbackInfoReturnable<CompoundTag> cir, @Local(ordinal = 0) CompoundTag nbt) {
if (this.createbigcannons$self instanceof CanLoadBigCannon)
if (CBCModifiedContraptionRegistry.canLoadBigCannon(this.createbigcannons$self))
ContraptionRemix.writeCannonLoaderData((Contraption & CanLoadBigCannon) this.createbigcannons$self, nbt);
if (this.createbigcannons$self instanceof HasFragileContraption)
if (CBCModifiedContraptionRegistry.isFragileContraption(this.createbigcannons$self))
ContraptionRemix.writeFragileBlocks((Contraption & HasFragileContraption) this.createbigcannons$self, nbt);
}

Expand Down

0 comments on commit f33182a

Please sign in to comment.