Skip to content

Commit

Permalink
works for both 1.19 and 1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
nad2040 committed Oct 7, 2023
1 parent e1b13ad commit 06b85c8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 28 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/nad2040/elytrabombing/ElytraBombingMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"));
Expand Down
47 changes: 23 additions & 24 deletions src/main/java/com/nad2040/elytrabombing/mixin/ItemMixin.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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()));
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

"depends": {
"fabricloader": ">=0.7",
"minecraft": ">=1.20",
"minecraft": ">=1.19",
"java": ">=17"
},
"suggests": {
Expand Down

0 comments on commit 06b85c8

Please sign in to comment.