From 06b85c85c4eb63b0fabc6611042469b4b80bcc50 Mon Sep 17 00:00:00 2001 From: nad <58147198+nad2040@users.noreply.github.com> Date: Sat, 7 Oct 2023 12:55:58 -0400 Subject: [PATCH] works for both 1.19 and 1.20 --- gradle.properties | 6 +-- .../elytrabombing/ElytraBombingMod.java | 5 ++ .../elytrabombing/mixin/ItemMixin.java | 47 +++++++++---------- src/main/resources/fabric.mod.json | 2 +- 4 files changed, 32 insertions(+), 28 deletions(-) diff --git a/gradle.properties b/gradle.properties index cc92009..3eba1af 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,9 +4,9 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop - minecraft_version=1.20 - yarn_mappings=1.20+build.1 - loader_version=0.14.21 + minecraft_version=1.19 + yarn_mappings=1.19+build.4 + loader_version=0.14.22 # Mod Properties mod_version = 1.1.0 diff --git a/src/main/java/com/nad2040/elytrabombing/ElytraBombingMod.java b/src/main/java/com/nad2040/elytrabombing/ElytraBombingMod.java index b265b27..13503ce 100644 --- a/src/main/java/com/nad2040/elytrabombing/ElytraBombingMod.java +++ b/src/main/java/com/nad2040/elytrabombing/ElytraBombingMod.java @@ -8,6 +8,7 @@ import net.minecraft.block.BlockState; import net.minecraft.item.ItemStack; import net.minecraft.util.Hand; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,6 +34,10 @@ public void onInitialize() { LOGGER.info("Elytra Bombing Mod initialized!"); } + public static BlockPos VEC_3D_TO_POS(Vec3d vec3d) { + return new BlockPos(vec3d.x, vec3d.y, vec3d.z); + } + public static void log(Hand hand, Hand other_hand, ItemStack usedItemStack, ItemStack otherItemStack, Vec3d position, Vec3d velocity) { LOGGER.info("right click action detected"); LOGGER.info("hand is " + ((hand == Hand.MAIN_HAND) ? "main hand" : "off hand")); diff --git a/src/main/java/com/nad2040/elytrabombing/mixin/ItemMixin.java b/src/main/java/com/nad2040/elytrabombing/mixin/ItemMixin.java index 496905c..48c0ea1 100644 --- a/src/main/java/com/nad2040/elytrabombing/mixin/ItemMixin.java +++ b/src/main/java/com/nad2040/elytrabombing/mixin/ItemMixin.java @@ -1,6 +1,7 @@ package com.nad2040.elytrabombing.mixin; import com.nad2040.elytrabombing.ElytraBombingMod; +import net.minecraft.block.AnvilBlock; import net.minecraft.block.Blocks; import net.minecraft.entity.EntityType; import net.minecraft.entity.FallingBlockEntity; @@ -12,6 +13,7 @@ import net.minecraft.stat.Stats; import net.minecraft.util.Hand; import net.minecraft.util.TypedActionResult; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraft.world.event.GameEvent; @@ -28,36 +30,33 @@ public void use(World world, PlayerEntity user, Hand hand, CallbackInfoReturnabl Hand other_hand = (hand == Hand.MAIN_HAND) ? Hand.OFF_HAND : Hand.MAIN_HAND; ItemStack usedItemStack = user.getStackInHand(hand), otherItemStack = user.getStackInHand(other_hand); Vec3d position = user.getPos(), velocity = user.getVelocity(); - if (ElytraBombingMod.SHOULD_LOG && world.isClient) { + if (ElytraBombingMod.SHOULD_LOG && !world.isClient) { ElytraBombingMod.log(hand,other_hand,usedItemStack,otherItemStack,position,velocity); } if (usedItemStack.isOf(Items.FLINT_AND_STEEL) && otherItemStack.isOf(Items.TNT)) { - if (!world.isClient) { - TntEntity tntEntity = new TntEntity(world, position.x, position.y, position.z, user); - tntEntity.setVelocity(velocity.multiply(1.2)); - world.spawnEntity(tntEntity); - world.playSound(null, tntEntity.getX(), tntEntity.getY(), tntEntity.getZ(), SoundEvents.ENTITY_TNT_PRIMED, SoundCategory.BLOCKS, 1.0f, 1.0f); - world.emitGameEvent(user, GameEvent.PRIME_FUSE, position); - if (!user.getAbilities().creativeMode) { - usedItemStack.damage(1, user, p -> p.sendToolBreakStatus(hand)); - otherItemStack.decrement(1); - } - user.incrementStat(Stats.USED.getOrCreateStat((FlintAndSteelItem) (Object) this)); + TntEntity tntEntity = new TntEntity(world, position.x, position.y, position.z, user); + tntEntity.setVelocity(velocity.multiply(1.2)); + world.spawnEntity(tntEntity); + world.playSound(null, tntEntity.getX(), tntEntity.getY(), tntEntity.getZ(), SoundEvents.ENTITY_TNT_PRIMED, SoundCategory.BLOCKS, 1.0f, 1.0f); + world.emitGameEvent(user, GameEvent.PRIME_FUSE, position); + if (!user.getAbilities().creativeMode) { + usedItemStack.damage(1, user, p -> p.sendToolBreakStatus(hand)); + otherItemStack.decrement(1); } + user.incrementStat(Stats.USED.getOrCreateStat((FlintAndSteelItem) (Object) this)); cir.setReturnValue(TypedActionResult.success(user.getStackInHand(hand), world.isClient())); } else if ((usedItemStack.isOf(Items.ANVIL) || usedItemStack.isOf(Items.CHIPPED_ANVIL) || usedItemStack.isOf(Items.DAMAGED_ANVIL)) && otherItemStack.isEmpty()) { - if (!world.isClient) { - FallingBlockEntity anvilEntity = new FallingBlockEntity(EntityType.FALLING_BLOCK, world); - anvilEntity.setPosition(position); - anvilEntity.setVelocity(velocity.multiply(1.2)); - if (usedItemStack.isOf(Items.ANVIL)) ((ElytraBombingMod.FBEInterface) anvilEntity).setBlock(Blocks.ANVIL.getDefaultState()); - if (usedItemStack.isOf(Items.CHIPPED_ANVIL)) ((ElytraBombingMod.FBEInterface) anvilEntity).setBlock(Blocks.CHIPPED_ANVIL.getDefaultState()); - if (usedItemStack.isOf(Items.DAMAGED_ANVIL)) ((ElytraBombingMod.FBEInterface) anvilEntity).setBlock(Blocks.DAMAGED_ANVIL.getDefaultState()); - world.spawnEntity(anvilEntity); - world.playSound(null, anvilEntity.getX(), anvilEntity.getY(), anvilEntity.getZ(), SoundEvents.BLOCK_ANVIL_FALL, SoundCategory.BLOCKS, 1.0f, 1.0f); - if (!user.getAbilities().creativeMode) { - usedItemStack.decrement(1); - } + FallingBlockEntity anvilEntity = new FallingBlockEntity(EntityType.FALLING_BLOCK, world); + anvilEntity.setPosition(position); + anvilEntity.setVelocity(velocity.multiply(1.2)); + if (usedItemStack.isOf(Items.ANVIL)) ((ElytraBombingMod.FBEInterface) anvilEntity).setBlock(Blocks.ANVIL.getDefaultState()); + if (usedItemStack.isOf(Items.CHIPPED_ANVIL)) ((ElytraBombingMod.FBEInterface) anvilEntity).setBlock(Blocks.CHIPPED_ANVIL.getDefaultState()); + if (usedItemStack.isOf(Items.DAMAGED_ANVIL)) ((ElytraBombingMod.FBEInterface) anvilEntity).setBlock(Blocks.DAMAGED_ANVIL.getDefaultState()); + anvilEntity.setFallingBlockPos(anvilEntity.getBlockPos()); + world.spawnEntity(anvilEntity); + world.playSound(null, anvilEntity.getX(), anvilEntity.getY(), anvilEntity.getZ(), SoundEvents.BLOCK_ANVIL_FALL, SoundCategory.BLOCKS, 1.0f, 1.0f); + if (!user.getAbilities().creativeMode) { + usedItemStack.decrement(1); } cir.setReturnValue(TypedActionResult.success(user.getStackInHand(hand), world.isClient())); } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 5c303c7..ad6782c 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -28,7 +28,7 @@ "depends": { "fabricloader": ">=0.7", - "minecraft": ">=1.20", + "minecraft": ">=1.19", "java": ">=17" }, "suggests": {