Skip to content

Commit

Permalink
allow anvil dropping with items in other hand
Browse files Browse the repository at this point in the history
  • Loading branch information
nad2040 committed May 31, 2024
1 parent 65caef6 commit b423817
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
9 changes: 0 additions & 9 deletions src/main/java/com/nad2040/elytrabombing/ElytraBombingMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
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;
Expand All @@ -27,17 +26,9 @@ public class ElytraBombingMod implements ModInitializer {

@Override
public void onInitialize() {
// This code runs as soon as Minecraft is in a mod-load-ready state.
// However, some things (like resources) may still be uninitialized.
// Proceed with mild caution.

LOGGER.info("Elytra Bombing Mod initialized!");
}

public static BlockPos VEC_3D_TO_POS(Vec3d vec3d) {
return new BlockPos((int)Math.round(vec3d.x), (int)Math.round(vec3d.y), (int)Math.round(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"));
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/nad2040/elytrabombing/mixin/ItemMixin.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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.EquipmentSlot;
Expand All @@ -14,7 +13,6 @@
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;
Expand All @@ -38,24 +36,26 @@ public void use(World world, PlayerEntity user, Hand hand, CallbackInfoReturnabl
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);
// changed methods signatures to ones that are also supported in 1.18*
world.playSound(tntEntity.getX(), tntEntity.getY(), tntEntity.getZ(), SoundEvents.ENTITY_TNT_PRIMED, SoundCategory.BLOCKS, 1.0f, 1.0f, false);
user.emitGameEvent(GameEvent.PRIME_FUSE, tntEntity);
if (!user.getAbilities().creativeMode) {
usedItemStack.damage(1, user, EquipmentSlot.MAINHAND);
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()) {
} else if (usedItemStack.isOf(Items.ANVIL) || usedItemStack.isOf(Items.CHIPPED_ANVIL) || usedItemStack.isOf(Items.DAMAGED_ANVIL)) {
FallingBlockEntity anvilEntity = new FallingBlockEntity(EntityType.FALLING_BLOCK, world);
anvilEntity.timeFalling = 1; // allows anvils to work on 1.18* by avoiding `(this.timeFalling++ == 0)`
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);
world.playSound(anvilEntity.getX(), anvilEntity.getY(), anvilEntity.getZ(), SoundEvents.BLOCK_ANVIL_FALL, SoundCategory.BLOCKS, 1.0f, 1.0f, false);
if (!user.getAbilities().creativeMode) {
usedItemStack.decrement(1);
}
Expand Down

0 comments on commit b423817

Please sign in to comment.