old-bugs

Minecraft: Better than Adventure! mod that brings back bugs from older versions
git clone git://memoryshards.xyz/old-bugs.git
Log | Files | Refs | README | LICENSE

commit ed8fd787b1b89459e0f2f5461278ffd2cd6baa68
parent 49171f5389f4547cf2afacdfea5a6dfcce420a4f
Author: Amb0s <ambos@disroot.org>
Date:   Wed, 24 Jan 2024 20:34:17 +0100

Added configuration file support

Diffstat:
Msrc/main/java/ambos/oldbugs/OldBugs.java | 29+++++++++++++++++++++++++++++
Msrc/main/java/ambos/oldbugs/mixin/BlockFireMixin.java | 21+++++++++++++++------
Msrc/main/java/ambos/oldbugs/mixin/EntityBoatMixin.java | 8+++++++-
Msrc/main/java/ambos/oldbugs/mixin/EntityLivingMixin.java | 5+++++
Msrc/main/java/ambos/oldbugs/mixin/EntityMinecartMixin.java | 8+++++++-
Msrc/main/java/ambos/oldbugs/mixin/EntityMixin.java | 20++++++++++++++++++--
6 files changed, 81 insertions(+), 10 deletions(-)

diff --git a/src/main/java/ambos/oldbugs/OldBugs.java b/src/main/java/ambos/oldbugs/OldBugs.java @@ -1,12 +1,41 @@ package ambos.oldbugs; import net.fabricmc.api.ModInitializer; +import turniplabs.halplibe.util.TomlConfigHandler; +import turniplabs.halplibe.util.toml.Toml; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class OldBugs implements ModInitializer { public static final String MOD_ID = "oldbugs"; public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); + public static final TomlConfigHandler TOML_CONFIG_HANDLER; + public static final boolean OLD_FIRE_SPREAD; + public static final boolean BOAT_WATER_LIFT; + public static final boolean LADDER_GAP; + public static final boolean MINECART_BOOSTER; + public static final boolean SOUTH_EAST_RULE_LIQUIDS; + public static final int FIRE_TICK_RATE; + static { + Toml configToml = new Toml(); + configToml.addCategory("Bugs"); + configToml.addEntry("old_fire_spread", true); + configToml.addEntry("boat_water_lift", true); + configToml.addEntry("ladder_gap", true); + configToml.addEntry("minecart_booster", true); + configToml.addEntry("south_east_rule_liquids", true); + configToml.addCategory("Settings"); + configToml.addEntry("fire_tick_rate", 10); + + TOML_CONFIG_HANDLER = new TomlConfigHandler(MOD_ID, configToml); + OLD_FIRE_SPREAD = TOML_CONFIG_HANDLER.getBoolean("Bugs.old_fire_spread"); + BOAT_WATER_LIFT = TOML_CONFIG_HANDLER.getBoolean("Bugs.boat_water_lift"); + LADDER_GAP = TOML_CONFIG_HANDLER.getBoolean("Bugs.ladder_gap"); + MINECART_BOOSTER = TOML_CONFIG_HANDLER.getBoolean("Bugs.minecart_booster"); + SOUTH_EAST_RULE_LIQUIDS = TOML_CONFIG_HANDLER.getBoolean("Bugs.south_east_rule_liquids"); + FIRE_TICK_RATE = TOML_CONFIG_HANDLER.getInt("Settings.fire_tick_rate"); + } @Override public void onInitialize() { diff --git a/src/main/java/ambos/oldbugs/mixin/BlockFireMixin.java b/src/main/java/ambos/oldbugs/mixin/BlockFireMixin.java @@ -6,25 +6,34 @@ import net.minecraft.core.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.*; +import ambos.oldbugs.OldBugs; + @Mixin(value = BlockFire.class, remap = false) final class BlockFireMixin { @ModifyConstant(method = "tickRate", constant = @Constant(intValue = 40)) private int changeTickRate(int a) { - return 10; + if (OldBugs.OLD_FIRE_SPREAD) { + return OldBugs.FIRE_TICK_RATE; + } else { + return a; + } } - @Redirect(method = "tryToCatchBlockOnFire", at = @At(value = "INVOKE", target = "Lnet/minecraft/core/world/World;setBlockAndMetadataWithNotify(IIIII)Z")) - private boolean infiniteSpreading(World world, int x, int y, int z, int id, int meta) { + private boolean infiniteSpreading(World world, int x, int y, int z, int id, int meta) { + if (OldBugs.OLD_FIRE_SPREAD) { world.setBlockAndMetadataWithNotify(x, y, z, Block.fire.id, 0); + } - return false; + return false; } @Redirect(method = "tryToCatchBlockOnFire", at = @At(value = "INVOKE", target = "Lnet/minecraft/core/block/BlockFire;setBurnResult(Lnet/minecraft/core/world/World;III)V")) - private void cancelSetBurnResult(BlockFire instance, World world, int x, int y, int z) { - + private void cancelSetBurnResult(BlockFire instance, World world, int x, int y, int z) { + if (!OldBugs.OLD_FIRE_SPREAD) { + instance.setBurnResult(world, x, y, z); } + } } diff --git a/src/main/java/ambos/oldbugs/mixin/EntityBoatMixin.java b/src/main/java/ambos/oldbugs/mixin/EntityBoatMixin.java @@ -5,10 +5,16 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.Constant; import org.spongepowered.asm.mixin.injection.ModifyConstant; +import ambos.oldbugs.OldBugs; + @Mixin(value = EntityBoat.class, remap = false) final class EntityBoatMixin { @ModifyConstant(method = "tick", constant = @Constant(doubleValue = 1.0, ordinal = 1)) private double change(double d) { - return Double.MAX_VALUE; + if (OldBugs.BOAT_WATER_LIFT) { + return Double.MAX_VALUE; + } else { + return d; + } } } diff --git a/src/main/java/ambos/oldbugs/mixin/EntityLivingMixin.java b/src/main/java/ambos/oldbugs/mixin/EntityLivingMixin.java @@ -8,11 +8,16 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import ambos.oldbugs.OldBugs; @Mixin(value = EntityLiving.class, remap = false) final class EntityLivingMixin { @Inject(method = "canClimb", at = @At("HEAD"), cancellable = true) public void increaseLadderCoverage(CallbackInfoReturnable<Boolean> cir) { + if (!OldBugs.LADDER_GAP) { + return; + } + EntityLiving self = ((EntityLiving) ((Object) this)); int x = MathHelper.floor_double(self.x); diff --git a/src/main/java/ambos/oldbugs/mixin/EntityMinecartMixin.java b/src/main/java/ambos/oldbugs/mixin/EntityMinecartMixin.java @@ -5,10 +5,16 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyVariable; +import ambos.oldbugs.OldBugs; + @Mixin(value = EntityMinecart.class, remap = false) final class EntityMinecartMixin { @ModifyVariable(method = "push", at = @At(value = "STORE"), ordinal = 6) private double change(double d6) { - return 0; + if (OldBugs.MINECART_BOOSTER) { + return 0; + } else { + return d6; + } } } diff --git a/src/main/java/ambos/oldbugs/mixin/EntityMixin.java b/src/main/java/ambos/oldbugs/mixin/EntityMixin.java @@ -2,21 +2,37 @@ package ambos.oldbugs.mixin; import net.minecraft.core.block.material.Material; import net.minecraft.core.entity.Entity; +import net.minecraft.core.util.phys.AABB; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import net.minecraft.core.util.phys.AABB; + +import ambos.oldbugs.OldBugs; @Mixin(value = Entity.class, remap = false) final class EntityMixin { @Inject(method = "checkAndHandleWater", at = @At("HEAD"), cancellable = true) private void onCheckAndHandleWater(CallbackInfoReturnable<Boolean> cir) { - Entity self = ((Entity) ((Object) this)); + if (!OldBugs.SOUTH_EAST_RULE_LIQUIDS) { + return; + } + Entity self = ((Entity) ((Object) this)); AABB aabb = self.bb.expand(0.0, -0.4000000059604645, 0.0); boolean res = self.world.handleMaterialAcceleration(aabb, Material.water, self); + cir.setReturnValue(res); + } + + @Inject(method = "isInLava", at = @At("HEAD"), cancellable = true) + private void lavaInject(CallbackInfoReturnable<Boolean> cir){ + if (!OldBugs.SOUTH_EAST_RULE_LIQUIDS) { + return; + } + Entity self = ((Entity) ((Object) this)); + AABB aabb = self.bb.expand(0.0, -0.4000000059604645, 0.0); + boolean res = self.world.isMaterialInBB(aabb, Material.lava); cir.setReturnValue(res); } }