Disable TNT using callback injectors
This commit is contained in:
parent
73f76ecc6f
commit
c833b625f2
@ -9,12 +9,15 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.state.property.BooleanProperty;
|
||||
import net.minecraft.state.property.Properties;
|
||||
import net.minecraft.world.World;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import party._2a03.mc.server.Config;
|
||||
|
||||
@Mixin(TntBlock.class)
|
||||
public class MixinTntBlock extends Block {
|
||||
public abstract class MixinTntBlock extends Block {
|
||||
@Shadow
|
||||
public static final BooleanProperty UNSTABLE = Properties.UNSTABLE;
|
||||
|
||||
@ -23,11 +26,9 @@ public class MixinTntBlock extends Block {
|
||||
this.setDefaultState(this.getDefaultState().with(UNSTABLE, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @reason Disable TNT block explosions.
|
||||
* @author flewkey
|
||||
*/
|
||||
@Overwrite
|
||||
private static void primeTnt(World world, BlockPos pos, @Nullable LivingEntity igniter) {
|
||||
@Inject(method = "primeTnt", at = @At("HEAD"), cancellable = true)
|
||||
private static void OnPrimeTnt(CallbackInfo ci) {
|
||||
if (Config.getBool("disableTntExplosions") == true)
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,12 @@ import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.TntEntity;
|
||||
import net.minecraft.world.World;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import party._2a03.mc.server.Config;
|
||||
|
||||
@Mixin(TntEntity.class)
|
||||
public abstract class MixinTntEntity extends Entity {
|
||||
@ -19,11 +22,9 @@ public abstract class MixinTntEntity extends Entity {
|
||||
this.inanimate = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @reason Disable TNT entity explosions.
|
||||
* @author flewkey
|
||||
*/
|
||||
@Overwrite
|
||||
private void explode() {
|
||||
@Inject(method = "explode", at = @At("HEAD"), cancellable = true)
|
||||
private void OnTntExplode(CallbackInfo ci) {
|
||||
if (Config.getBool("disableTntExplosions") == true)
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
@ -77,6 +77,10 @@ public class Config {
|
||||
return json.getJSONArray(key);
|
||||
}
|
||||
|
||||
public static boolean getBool(String key) {
|
||||
return json.getBoolean(key);
|
||||
}
|
||||
|
||||
public static void setData(String key, JSONArray data) {
|
||||
json.put(key, data);
|
||||
saveConfig();
|
||||
|
Loading…
x
Reference in New Issue
Block a user