From 801429d27ff969bee86cafad57c89219c864f038 Mon Sep 17 00:00:00 2001 From: Wynd Date: Sun, 7 Jan 2024 02:30:52 +0200 Subject: [PATCH] Shift for unmounting vehicles, drop entire stacks and multiple ways to handle boat breaking --- .../xyz/pixelatedw/finalbeta/ModConfig.java | 10 ++-- .../xyz/pixelatedw/finalbeta/WyHelper.java | 22 ++++++--- .../pixelatedw/finalbeta/mixin/BoatMixin.java | 49 +++++++++++++++++++ .../finalbeta/mixin/BookshelfTileMixin.java | 4 +- .../finalbeta/mixin/ClientPlayerMixin.java | 36 ++++++++++---- .../finalbeta/mixin/LivingEntityMixin.java | 15 +++++- src/main/resources/finalbeta.mixins.json | 3 +- 7 files changed, 114 insertions(+), 25 deletions(-) create mode 100644 src/main/java/xyz/pixelatedw/finalbeta/mixin/BoatMixin.java diff --git a/src/main/java/xyz/pixelatedw/finalbeta/ModConfig.java b/src/main/java/xyz/pixelatedw/finalbeta/ModConfig.java index ceefd91..4c4b01d 100644 --- a/src/main/java/xyz/pixelatedw/finalbeta/ModConfig.java +++ b/src/main/java/xyz/pixelatedw/finalbeta/ModConfig.java @@ -20,14 +20,16 @@ public class ModConfig { public static final Option ENABLE_CLOUDS = make("Enable Clouds", true, "Enables the rendering of clouds"); public static final Option DISABLE_ID_TAGS = make("Disable ID Tags", true, "Disables id tags showing above entities in F3 mode"); - public static final Option BOOKSHELVES_DROP = make("Bookshelves Drops", true, - "Drops 3 books when breaking a bookshelf"); public static final Option FENCE_SLIM_HITBOX = make("Slim Hitbox for Fences", true, "Uses slim hitbox for fences on the X and Z axies (the height of the fence is not changed)"); public static final Option REMOVE_NIGHTMARES = make("Remove Nightmares", false, "Removes nightmares completely"); public static final Option DISABLE_BEDS = make("Disable Beds", false, "Disables bed mechanics such as setting spawn points and skipping the night, does NOT delete already placed blocks nor does it disable the crafting or placing of beds as decorative blocks"); + public static final Option BOAT_BREAKING_LOGIC = make("Boat Breaking Logic", 2, + "0 - Vanilla behavior\n1 - Boats will never break regardless of their speed\n2 - Boats will only break when crashing with almost max speed"); + public static final Option STACK_DROP = make("Drop Held Stack", true, + "Allows the player to drop the entire stack they're holding using Shift + Q (or whatever drop key they have set)"); public static final Option FIX_BOW_MODEL = make("Fix bow model", true, "Makes the box model held by players and skeletons bigger and facing forward"); @@ -47,7 +49,9 @@ public class ModConfig { "Fixes saddles not dropping when killing saddled pigs"); public static final Option FIX_FURNACE_LAVA_BUCKET = make("Fix furnace lava bucket", true, "Fixes furnaces consuming the bucket when using lava buckets as fuel"); - + public static final Option FIX_BOOKSHELVES_DROP = make("Fix Bookshelves Drops", true, + "Drops 3 books when breaking a bookshelf"); + private static ModConfig instance = new ModConfig(); public static final ModConfig instance() { return instance; diff --git a/src/main/java/xyz/pixelatedw/finalbeta/WyHelper.java b/src/main/java/xyz/pixelatedw/finalbeta/WyHelper.java index af6b5a2..ff81906 100644 --- a/src/main/java/xyz/pixelatedw/finalbeta/WyHelper.java +++ b/src/main/java/xyz/pixelatedw/finalbeta/WyHelper.java @@ -6,6 +6,8 @@ import java.time.Duration; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.Player; +import net.minecraft.item.ItemInstance; +import net.minecraft.item.ItemType; import net.minecraft.stat.Stats; public class WyHelper { @@ -53,7 +55,9 @@ public class WyHelper { } public static void cheatCommand(Player player) { - + + player.dropItem(new ItemInstance(ItemType.boat, 1)); + // int x = MathsHelper.floor(player.x); // int y = MathsHelper.floor(player.boundingBox.minY); // int z = MathsHelper.floor(player.z); @@ -88,14 +92,16 @@ public class WyHelper { // player.dropItem(new ItemInstance(Tile.RAIL, 64), false); // player.dropItem(new ItemInstance(Tile.GOLDEN_RAIL, 64), false); -// Zombie enemy = new Zombie(player.level); -// enemy.setPositionAndAngles(player.x + 2, player.y, player.z, 0.0f, 0.0f); -// player.level.spawnEntity(enemy); +// player.dropItem(new ItemInstance(ItemType.saddle, 1)); +// +// Pig animal = new Pig(player.level); +// animal.setPositionAndAngles(player.x + 2, player.y, player.z, 0.0f, 0.0f); +// player.level.spawnEntity(animal); player.level.setLevelTime(0); -// player.level.getProperties().setRaining(false); -// player.level.getProperties().setRainTime(0); -// player.level.getProperties().setThundering(false); -// player.level.getProperties().setThunderTime(0); + player.level.getProperties().setRaining(false); + player.level.getProperties().setRainTime(0); + player.level.getProperties().setThundering(false); + player.level.getProperties().setThunderTime(0); } } diff --git a/src/main/java/xyz/pixelatedw/finalbeta/mixin/BoatMixin.java b/src/main/java/xyz/pixelatedw/finalbeta/mixin/BoatMixin.java new file mode 100644 index 0000000..818c802 --- /dev/null +++ b/src/main/java/xyz/pixelatedw/finalbeta/mixin/BoatMixin.java @@ -0,0 +1,49 @@ +package xyz.pixelatedw.finalbeta.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.At.Shift; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.entity.Boat; +import xyz.pixelatedw.finalbeta.ModConfig; + +@Mixin(Boat.class) +public class BoatMixin { + + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Ljava/lang/Math;sqrt(D)D", shift = Shift.AFTER)) + public void boatVelocityCheck(CallbackInfo ci) { + Boat boat = ((Boat) (Object) this); + + /* + * This randomly named field_1624 is actually the horizontal collision + * check, which we're setting to false before the vanilla check happens + * if the boat is set to survive the impact from our checks. + * + * Do note that they way the boat collision check happens is that the + * boat gets slowed down first, and then the velocity check is + * performed, by default a velocity check is 0.15, we're raising that + * limit to 0.22. + */ + if (this.isCollidingHorizontally(boat) && this.canSurvive(boat)) { + ((Boat) (Object) this).field_1624 = false; + } + } + + private boolean canSurvive(Boat boat) { + double velocity = Math.sqrt(boat.velocityX * boat.velocityX + boat.velocityZ * boat.velocityZ); + boolean survives = false; + if (ModConfig.BOAT_BREAKING_LOGIC.get() == 1) { + survives = true; + } else if (ModConfig.BOAT_BREAKING_LOGIC.get() == 2 && velocity < 0.22) { + survives = true; + } + + return survives; + } + + private boolean isCollidingHorizontally(Boat boat) { + return ((Boat) (Object) this).field_1624; + } +} diff --git a/src/main/java/xyz/pixelatedw/finalbeta/mixin/BookshelfTileMixin.java b/src/main/java/xyz/pixelatedw/finalbeta/mixin/BookshelfTileMixin.java index 57d9599..3c609fd 100644 --- a/src/main/java/xyz/pixelatedw/finalbeta/mixin/BookshelfTileMixin.java +++ b/src/main/java/xyz/pixelatedw/finalbeta/mixin/BookshelfTileMixin.java @@ -22,14 +22,14 @@ public class BookshelfTileMixin extends Tile { @Inject(method = "getDropCount", at = @At("HEAD"), cancellable = true) public void getDropCount(Random random, CallbackInfoReturnable cir) { - if (ModConfig.BOOKSHELVES_DROP.get()) { + if (ModConfig.FIX_BOOKSHELVES_DROP.get()) { cir.setReturnValue(3); } } @Override public int getDropId(int i, Random random) { - if (ModConfig.BOOKSHELVES_DROP.get()) { + if (ModConfig.FIX_BOOKSHELVES_DROP.get()) { return ItemType.book.id; } diff --git a/src/main/java/xyz/pixelatedw/finalbeta/mixin/ClientPlayerMixin.java b/src/main/java/xyz/pixelatedw/finalbeta/mixin/ClientPlayerMixin.java index 6181ca2..bf14f46 100644 --- a/src/main/java/xyz/pixelatedw/finalbeta/mixin/ClientPlayerMixin.java +++ b/src/main/java/xyz/pixelatedw/finalbeta/mixin/ClientPlayerMixin.java @@ -8,39 +8,57 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import net.minecraft.client.Minecraft; import net.minecraft.container.ChestContainer; import net.minecraft.entity.player.ClientPlayer; import net.minecraft.entity.player.Player; import net.minecraft.inventory.Inventory; +import net.minecraft.item.ItemInstance; import xyz.pixelatedw.finalbeta.ModConfig; import xyz.pixelatedw.finalbeta.WyHelper; @Mixin(ClientPlayer.class) public class ClientPlayerMixin { - + private Random rand = new Random(); - + @Inject(method = "method_136", at = @At("TAIL")) public void onKeyPressed(int key, boolean state, CallbackInfo ci) { + Minecraft mc = WyHelper.getInstance(); + Player player = (Player) (Object) this; + + if (player.vehicle != null && key == Keyboard.KEY_LSHIFT) { + player.startRiding(null); + return; + } + + if (ModConfig.STACK_DROP.get() && key == mc.options.dropKey.key && Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) { + ItemInstance heldItem = player.inventory.getHeldItem(); + if (heldItem != null && heldItem.count > 0) { + player.dropItem(player.inventory.takeInvItem(player.inventory.selectedHotbarSlot, heldItem.count), false); + return; + } + } + if (WyHelper.isDebug() && key == Keyboard.KEY_Z && state) { - Player player = (Player) (Object) this; WyHelper.cheatCommand(player); + return; } } - + @Inject(method = "openChestScreen", at = @At("TAIL")) public void openChestScreen(Inventory arg, CallbackInfo ci) { - if(ModConfig.ADD_MORE_SOUNDS.get()) { + if (ModConfig.ADD_MORE_SOUNDS.get()) { Player player = (Player) (Object) this; - player.level.playSound(player, "random.chestopen", 0.3f, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F); + player.level.playSound(player, "random.chestopen", 0.3f, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F); } } - + @Inject(method = "closeContainer", at = @At("HEAD")) public void closeContainer(CallbackInfo ci) { - if(ModConfig.ADD_MORE_SOUNDS.get()) { + if (ModConfig.ADD_MORE_SOUNDS.get()) { Player player = (Player) (Object) this; - if(player.container instanceof ChestContainer) { + if (player.container instanceof ChestContainer) { player.level.playSound(player, "random.chestclosed", 0.3f, (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F + 1.0F); } } diff --git a/src/main/java/xyz/pixelatedw/finalbeta/mixin/LivingEntityMixin.java b/src/main/java/xyz/pixelatedw/finalbeta/mixin/LivingEntityMixin.java index 8fc2aa7..232f4ed 100644 --- a/src/main/java/xyz/pixelatedw/finalbeta/mixin/LivingEntityMixin.java +++ b/src/main/java/xyz/pixelatedw/finalbeta/mixin/LivingEntityMixin.java @@ -6,6 +6,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.animal.Chicken; import net.minecraft.entity.animal.Pig; import net.minecraft.item.ItemType; import xyz.pixelatedw.finalbeta.ModConfig; @@ -13,13 +14,23 @@ import xyz.pixelatedw.finalbeta.ModConfig; @Mixin(LivingEntity.class) public class LivingEntityMixin { + @Inject(method = "setSize", at = @At("HEAD"), cancellable = true) + public void setSize(float f, float f1, CallbackInfo ci) { + LivingEntity entity = (LivingEntity) (Object) this; + if (entity instanceof Chicken) { + entity.width = 0.3F; + entity.height = 0.7F; + ci.cancel(); + } + } + @Inject(method = "dropLoot", at = @At("TAIL")) public void dropLoot(CallbackInfo ci) { - if(ModConfig.FIX_SADDLES_NOT_DROPPING.get()) { + if (ModConfig.FIX_SADDLES_NOT_DROPPING.get()) { LivingEntity entity = (LivingEntity) (Object) this; if (entity instanceof Pig && ((Pig) entity).isSaddled()) { entity.dropItem(ItemType.saddle.id, 1); - } + } } } } diff --git a/src/main/resources/finalbeta.mixins.json b/src/main/resources/finalbeta.mixins.json index e260aca..4ed389c 100644 --- a/src/main/resources/finalbeta.mixins.json +++ b/src/main/resources/finalbeta.mixins.json @@ -32,7 +32,8 @@ "BookshelfTileMixin", "FenceTileMixin", "LevelMonsterSpawnerMixin", - "BedTileMixin" + "BedTileMixin", + "BoatMixin" ], "injectors": { "defaultRequire": -1