From 5513704a0ba9c976bc7fa2cb953552283ed8fb79 Mon Sep 17 00:00:00 2001 From: khj xiaogu <54445543+khjxiaogu@users.noreply.github.com> Date: Sat, 23 Oct 2021 21:57:32 +0800 Subject: [PATCH] disable ca? --- .../com/teammoeg/steampowered/SPConfig.java | 18 +++++++ .../teammoeg/steampowered/SteamPowered.java | 1 + .../server/MixinAbstractContraption.java | 48 +++++++++++++++++ .../server/MixinCartAssemblerTileEntity.java | 51 +++++++++++++++++++ src/main/resources/steampowered.mixins.json | 4 +- 5 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/teammoeg/steampowered/mixin/server/MixinAbstractContraption.java create mode 100644 src/main/java/com/teammoeg/steampowered/mixin/server/MixinCartAssemblerTileEntity.java diff --git a/src/main/java/com/teammoeg/steampowered/SPConfig.java b/src/main/java/com/teammoeg/steampowered/SPConfig.java index 9972448..e27fffd 100644 --- a/src/main/java/com/teammoeg/steampowered/SPConfig.java +++ b/src/main/java/com/teammoeg/steampowered/SPConfig.java @@ -67,13 +67,31 @@ public class SPConfig { builder.pop(); } } + public static class Server { + public final ForgeConfigSpec.BooleanValue allowUnverifiedContraption; + public final ForgeConfigSpec.BooleanValue allowCartAssembler; + + Server(ForgeConfigSpec.Builder builder) { + builder.push("createmodify"); + { + allowUnverifiedContraption=builder.comment("Set to False to automatically disassemble contraptions formed before this mod installed").define("allowUnverifiedContraption",false); + allowCartAssembler=builder.comment("Cart Assembler is not very \"Realistic\",So You can choose to disable its use").define("allowCartAssembler",false); + } + builder.pop(); + } + } public static final ForgeConfigSpec COMMON_CONFIG; + public static final ForgeConfigSpec SERVER_CONFIG; public static final Common COMMON; + public static final Server SERVER; static { ForgeConfigSpec.Builder COMMON_BUILDER = new ForgeConfigSpec.Builder(); + ForgeConfigSpec.Builder SERVER_BUILDER = new ForgeConfigSpec.Builder(); COMMON = new Common(COMMON_BUILDER); + SERVER=new Server(SERVER_BUILDER); + SERVER_CONFIG=SERVER_BUILDER.build(); COMMON_CONFIG = COMMON_BUILDER.build(); } diff --git a/src/main/java/com/teammoeg/steampowered/SteamPowered.java b/src/main/java/com/teammoeg/steampowered/SteamPowered.java index 85adfa0..ade3bcd 100644 --- a/src/main/java/com/teammoeg/steampowered/SteamPowered.java +++ b/src/main/java/com/teammoeg/steampowered/SteamPowered.java @@ -64,6 +64,7 @@ public class SteamPowered { SPItems.register(); ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, SPConfig.COMMON_CONFIG); + ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, SPConfig.SERVER_CONFIG); PacketHandler.register(); } diff --git a/src/main/java/com/teammoeg/steampowered/mixin/server/MixinAbstractContraption.java b/src/main/java/com/teammoeg/steampowered/mixin/server/MixinAbstractContraption.java new file mode 100644 index 0000000..bf379ec --- /dev/null +++ b/src/main/java/com/teammoeg/steampowered/mixin/server/MixinAbstractContraption.java @@ -0,0 +1,48 @@ +package com.teammoeg.steampowered.mixin.server; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; +import com.teammoeg.steampowered.SPConfig; + +import net.minecraft.nbt.CompoundNBT; + +@Mixin(AbstractContraptionEntity.class) +public abstract class MixinAbstractContraption { + boolean shoulddisb=false; + /** + * @author khjxiaogu + * @reason force reset contraptions for mod propose + * */ + @Inject(at = @At("TAIL"), method = "writeAdditional",remap=false) + protected void writeAdditional(CompoundNBT compound, boolean spawnPacket,CallbackInfo cbi) { + if(!SPConfig.SERVER.allowUnverifiedContraption.get()) + compound.putInt("spinst",2); + } + @Shadow(remap=false) + public abstract void disassemble(); + /** + * @author khjxiaogu + * @reason force reset contraptions for mod propose + * */ + @Inject(at = @At("TAIL"), method = "readAdditional",remap=false) + protected void readAdditional(CompoundNBT compound, boolean spawnPacket,CallbackInfo cbi) { + if(!SPConfig.SERVER.allowUnverifiedContraption.get()) + if(compound.getInt("spinst")!=2) { + shoulddisb=true; + } + } + /** + * @author khjxiaogu + * @reason force reset contraptions for mod propose + * */ + @Inject(at = @At("TAIL"), method = "tick",remap=true) + protected void tick(CallbackInfo cbi) { + if(shoulddisb) + this.disassemble(); + } +} diff --git a/src/main/java/com/teammoeg/steampowered/mixin/server/MixinCartAssemblerTileEntity.java b/src/main/java/com/teammoeg/steampowered/mixin/server/MixinCartAssemblerTileEntity.java new file mode 100644 index 0000000..7bbbb07 --- /dev/null +++ b/src/main/java/com/teammoeg/steampowered/mixin/server/MixinCartAssemblerTileEntity.java @@ -0,0 +1,51 @@ +package com.teammoeg.steampowered.mixin.server; + +import java.util.List; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import com.simibubi.create.content.contraptions.components.structureMovement.mounted.CartAssemblerTileEntity; +import com.simibubi.create.foundation.tileEntity.SmartTileEntity; +import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; +import com.teammoeg.steampowered.SPConfig; + +import net.minecraft.entity.item.minecart.AbstractMinecartEntity; +import net.minecraft.tileentity.TileEntityType; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +@Mixin(CartAssemblerTileEntity.class) +public abstract class MixinCartAssemblerTileEntity extends SmartTileEntity{ + public MixinCartAssemblerTileEntity(TileEntityType tileEntityTypeIn) { + super(tileEntityTypeIn); + } + /** + * @author khjxiaogu + * @reason config disable cart assembly + * */ + @Inject(at = @At("HEAD"), method = "tryAssemble",remap=false,cancellable=true) + public void tryAssemble(AbstractMinecartEntity cart,CallbackInfo cbi) { + if(!SPConfig.SERVER.allowCartAssembler.get()) { + if (cart == null) + return; + + if (!isMinecartUpdateValid()) + return; + resetTicksSinceMinecartUpdate(); + disassemble(level, worldPosition, cart); + cbi.cancel(); + + } + + } + @Shadow(remap=false) + protected abstract void disassemble(World world, BlockPos pos, AbstractMinecartEntity cart) ; + @Shadow(remap=false) + public abstract void resetTicksSinceMinecartUpdate(); + @Shadow(remap=false) + public abstract boolean isMinecartUpdateValid(); +} diff --git a/src/main/resources/steampowered.mixins.json b/src/main/resources/steampowered.mixins.json index f137f3b..b4c3ab9 100644 --- a/src/main/resources/steampowered.mixins.json +++ b/src/main/resources/steampowered.mixins.json @@ -6,7 +6,9 @@ "refmap": "steampowered.refmap.json", "mixins": [ "FlywheelTileEntityAccess", - "HandCrankBlockMixin" + "HandCrankBlockMixin", + "server.MixinAbstractContraption", + "server.MixinCartAssemblerTileEntity" ], "client": [ "client.MixinClientEvents"