disable ca?

This commit is contained in:
khj xiaogu 2021-10-23 21:57:32 +08:00
parent b60a5bfecf
commit 5513704a0b
No known key found for this signature in database
GPG key ID: DEA172814EAFF426
5 changed files with 121 additions and 1 deletions

View file

@ -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();
}

View file

@ -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();
}

View file

@ -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();
}
}

View file

@ -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();
}

View file

@ -6,7 +6,9 @@
"refmap": "steampowered.refmap.json",
"mixins": [
"FlywheelTileEntityAccess",
"HandCrankBlockMixin"
"HandCrankBlockMixin",
"server.MixinAbstractContraption",
"server.MixinCartAssemblerTileEntity"
],
"client": [
"client.MixinClientEvents"