Jump to content

NindyBun

Members
  • Posts

    88
  • Joined

  • Last visited

Everything posted by NindyBun

  1. So I am at a loss on how to get the item drops of a block into the players inventory. Say I mined a coal ore block with fortune, I want the drops to appear in my inventory rather than in the world. How do I get that to work?
  2. Actually, nvm I fixed the problem.
  3. @Override public ActionResultType onItemUse(ItemUseContext context) { refuel(context.getItem(), context.getPlayer()); int fuelValue = 0; if (context.getItem().hasTag() && context.getItem().getTag().contains("FuelValue")) { fuelValue = context.getItem().getTag().getInt("FuelValue"); } World world = context.getWorld(); ItemStack stack = context.getItem(); BlockPos pos = context.getPos(); BlockState state = context.getWorld().getBlockState(pos); PlayerEntity player = context.getPlayer(); Block block = world.getBlockState(pos).getBlock(); if (fuelValue >= use){ //context.getWorld().destroyBlock(context.getPos(), false); if (block.removedByPlayer(state, world, pos, player, true, state.getFluidState())){ BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, state, player); block.dropXpOnBlockBreak(world, pos, event.getExpToDrop()); block.harvestBlock(world, player, pos, state, world.getTileEntity(pos), stack); event.getWorld().destroyBlock(pos, false); //event.getWorld().playSound(context.getPlayer(), event.getPos(), event.getState().getSoundType().getBreakSound(), SoundCategory.BLOCKS, event.getState().getSoundType().getVolume(), event.getState().getSoundType().getPitch()); //context.getWorld().setBlockState(context.getPos(), Blocks.AIR.getDefaultState()); } fuelValue -= use; context.getItem().getTag().putInt("FuelValue", context.getItem().getTag().getInt("FuelValue")-use); } return super.onItemUse(context); } So i made an item that harvests a block on right click, but when I do it under a piece of grass, the grass doesn't break. How do I fix this issue?
  4. I call the extract every time my fuelValue is below 0. When it extracts the first time it makes the fuelValue = 1600 but doesn't remove the item, then it extracts again when the fuelValue is at 0 again, this time the item is actually removed from it's inventory. Is there a tutorial that you can recommend for capabilities? I've been looking all over the place but I don't think I understand the concept.
  5. Uh, so I've ran into a problem. I can insert items fine and my item will store them, but when I try to extract an item it still stays there unless I call the extract function twice. Does it have to do with my ItemHandler? package com.nindybun.miningtool.test_item; import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.ITickableTileEntity; import net.minecraftforge.items.ItemStackHandler; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import javax.annotation.Nonnull; public class ItemStackHandlerTestItem extends ItemStackHandler { public static final int MIN_SLOTS = 1; public static final int MAX_SLOTS = 1; public ItemStackHandlerTestItem(int numberOfSlots){ super(numberOfSlots); } public static boolean isFuel(ItemStack stack) { return net.minecraftforge.common.ForgeHooks.getBurnTime(stack) > 0; } public boolean isItemValid(int slot, @Nonnull ItemStack stack) { if (slot < 0 || slot >= MAX_SLOTS) { throw new IllegalArgumentException("Invalid slot number: " + slot); } if (stack.isEmpty()) { return false; } if (isFuel(stack)) { return true; } return false; } public boolean isDirty() { boolean currentState = isDirty; isDirty = false; return currentState; } protected void onContentsChanged(int slot) { super.onContentsChanged(slot); isDirty = true; } private boolean isDirty = true; private final Logger LOGGER = LogManager.getLogger(); } My item class: package com.nindybun.miningtool.test_item; import com.google.common.collect.Sets; import com.nindybun.miningtool.MiningTool; import com.nindybun.miningtool.init.ItemInit; import com.nindybun.miningtool.util.WorldUtil; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.material.Material; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.ITickable; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.INamedContainerProvider; import net.minecraft.item.*; import net.minecraft.item.crafting.Ingredient; import net.minecraft.nbt.CompoundNBT; import net.minecraft.tags.BlockTags; import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.LazyValue; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.StringTextComponent; import net.minecraft.world.World; import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.ToolType; import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.fml.network.NetworkHooks; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemStackHandler; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.List; import java.util.Set; import java.util.function.Supplier; public class ItemTestItem extends ToolItem{ private static final int MAX_ITEM_STACK = 1; private static final Set<Block> EFFECTIVE_ON = Sets.newHashSet(); private static int fuelValue; private static int use = 100; public ItemTestItem(Properties properties) { super(15, 15, ModItemTier.TESTITEM, EFFECTIVE_ON, properties .addToolType(ToolType.get("pickaxe"), 4) .addToolType(ToolType.get("axe"), 4) .addToolType(ToolType.get("shovel"), 4) ); } @Override public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) { tooltip.add(new StringTextComponent("IDK")); super.addInformation(stack, worldIn, tooltip, flagIn); } /*@Override public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, PlayerEntity player) { IItemHandler item = getItemStackHandlerTestItem(stack); RayTraceResult ray = WorldUtil.getMovingObjectPosWithReachDistance(player.world, player, pos, player.world.getBlockState(pos)); if (ray != null){ if (fuelValue >= use){ LOGGER.info("Fuel Value Before >> " + fuelValue); //BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(player.world, pos, player.world.getBlockState(pos), player); //event.getState().getBlock().harvestBlock(player.world, player, pos, player.world.getBlockState(pos), player.world.getTileEntity(pos), stack); //player.world.destroyBlock(pos, false); fuelValue -= use; LOGGER.info("Fuel Value After >> " + fuelValue); }else { player.world.destroyBlock(pos, false); } } return true; }*/ @Override public boolean onBlockDestroyed(ItemStack stack, World worldIn, BlockState state, BlockPos pos, LivingEntity entityLiving) { IItemHandler item = getItemStackHandlerTestItem(stack); if (fuelValue >= use) { LOGGER.info("Fuel Value Before >> " + fuelValue); fuelValue -= use; LOGGER.info("Fuel Value After >> " + fuelValue); //entityLiving.world.destroyBlock(pos, true); state.getBlock().harvestBlock(worldIn, (PlayerEntity) entityLiving, pos, state, worldIn.getTileEntity(pos), stack); }else{ entityLiving.world.destroyBlock(pos, false); } return super.onBlockDestroyed(stack, worldIn, state, pos, entityLiving); } /*public void refuel(ItemStack stack){ IItemHandler item = getItemStackHandlerTestItem(stack); }*/ public float getDestroySpeed(ItemStack stack, BlockState state) { IItemHandler item = getItemStackHandlerTestItem(stack); if (!EFFECTIVE_ON.contains(state.getBlock())){ EFFECTIVE_ON.add(state.getBlock()); } if (fuelValue >= use){ return super.getDestroySpeed(stack, state); }else{ if (item.getStackInSlot(0).getCount() > 0){ fuelValue = net.minecraftforge.common.ForgeHooks.getBurnTime(item.getStackInSlot(0)); LOGGER.info("Fuel Value >> " + fuelValue); item.extractItem(0, 1, false); return super.getDestroySpeed(stack, state); } return 0.2f; } } public enum ModItemTier implements IItemTier { TESTITEM(4, 0, 20.0f, 7.0f, 250, null); public final int harvestlevel; private final int maxUses; private final float efficiency; private final float attackDamage; private final int enchantability; private final LazyValue<Ingredient> repairMaterial; ModItemTier(int harvestLevel, int maxUses, float efficiency, float attackDamage, int enchantability, Supplier<Ingredient> repairMaterial) { this.maxUses = maxUses; this.efficiency = efficiency; this.attackDamage = attackDamage; this.enchantability = enchantability; this.repairMaterial = new LazyValue<>(repairMaterial); this.harvestlevel = harvestLevel; } @Override public int getMaxUses() { return this.maxUses; } @Override public float getEfficiency() { return this.efficiency; } @Override public float getAttackDamage() { return this.attackDamage; } @Override public int getHarvestLevel() { return this.harvestlevel; } @Override public int getEnchantability() { return this.enchantability; } @Override public Ingredient getRepairMaterial() { return this.repairMaterial.getValue(); } } @Nonnull @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) { ItemStack stack = playerIn.getHeldItem(handIn); IItemHandler item = getItemStackHandlerTestItem(stack); if (!worldIn.isRemote){ if (playerIn.isSneaking()){ item.insertItem(0, new ItemStack(Items.COAL, 1), false); }else{ INamedContainerProvider containerProviderTestItem = new ContainerProviderTestItem(this, stack); final int NUMBER_OF_SLOTS = 1; NetworkHooks.openGui((ServerPlayerEntity) playerIn, containerProviderTestItem, (packetBuffer)->{packetBuffer.writeInt(NUMBER_OF_SLOTS); }); } } return ActionResult.resultSuccess(stack); } private static class ContainerProviderTestItem implements INamedContainerProvider{ public ContainerProviderTestItem(ItemTestItem itemTestItem, ItemStack itemStackTestItem){ this.itemStackTestItem = itemStackTestItem; this.itemTestItem = itemTestItem; } @Override public ITextComponent getDisplayName() { return itemStackTestItem.getDisplayName(); } @Nullable @Override public ContainerTestItem createMenu(int windowID_, PlayerInventory playerInventory, PlayerEntity playerEntity) { ContainerTestItem newContainerServerSide = ContainerTestItem.createContainerServerSide(windowID_, playerInventory, itemTestItem.getItemStackHandlerTestItem(itemStackTestItem), itemStackTestItem); return newContainerServerSide; } private ItemTestItem itemTestItem; private ItemStack itemStackTestItem; } @Nonnull @Override public ICapabilityProvider initCapabilities(ItemStack stack, CompoundNBT oldCapNbt) { return new CapabilityProviderTestItem(); } private static ItemStackHandlerTestItem getItemStackHandlerTestItem(ItemStack itemStack) { IItemHandler testItem = itemStack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElse(null); if (testItem == null || !(testItem instanceof ItemStackHandlerTestItem)) { LOGGER.error("ItemTestItem did not have the expected ITEM_HANDLER_CAPABILITY"); return new ItemStackHandlerTestItem(1); } return (ItemStackHandlerTestItem) testItem; } private final String BASE_NBT_TAG = "base"; private final String CAPABILITY_NBT_TAG = "cap"; @Nullable @Override public CompoundNBT getShareTag(ItemStack stack) { CompoundNBT baseTag = stack.getTag(); ItemStackHandlerTestItem itemStackHandlerTestItem = getItemStackHandlerTestItem(stack); CompoundNBT capabilityTag = itemStackHandlerTestItem.serializeNBT(); CompoundNBT combinedTag = new CompoundNBT(); if (baseTag != null) { combinedTag.put(BASE_NBT_TAG, baseTag); } if (capabilityTag != null) { combinedTag.put(CAPABILITY_NBT_TAG, capabilityTag); } return combinedTag; } @Override public void readShareTag(ItemStack stack, @Nullable CompoundNBT nbt) { if (nbt == null) { stack.setTag(null); return; } CompoundNBT baseTag = nbt.getCompound(BASE_NBT_TAG); CompoundNBT capabilityTag = nbt.getCompound(CAPABILITY_NBT_TAG); stack.setTag(baseTag); ItemStackHandlerTestItem itemStackHandlerTestItem = getItemStackHandlerTestItem(stack); itemStackHandlerTestItem.deserializeNBT(capabilityTag); } private static final Logger LOGGER = LogManager.getLogger(); }
  6. package com.nindybun.miningtool.test_item; import com.nindybun.miningtool.MiningTool; import net.minecraft.client.renderer.texture.ITickable; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.INamedContainerProvider; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.text.ITextComponent; import net.minecraft.world.World; import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.fml.network.NetworkHooks; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import javax.annotation.Nonnull; import javax.annotation.Nullable; public class ItemTestItem extends Item { private static final int MAX_ITEM_STACK = 1; public ItemTestItem(Properties properties) { super(properties); } @Nonnull @Override public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) { ItemStack stack = playerIn.getHeldItem(handIn); if (!worldIn.isRemote){ if (playerIn.isSneaking()){ //Add a piece of coal to this items inventory }else{ INamedContainerProvider containerProviderTestItem = new ContainerProviderTestItem(this, stack); final int NUMBER_OF_SLOTS = 1; NetworkHooks.openGui((ServerPlayerEntity) playerIn, containerProviderTestItem, (packetBuffer)->{packetBuffer.writeInt(NUMBER_OF_SLOTS); }); } } return ActionResult.resultSuccess(stack); } private static class ContainerProviderTestItem implements INamedContainerProvider{ public ContainerProviderTestItem(ItemTestItem itemTestItem, ItemStack itemStackTestItem){ this.itemStackTestItem = itemStackTestItem; this.itemTestItem = itemTestItem; } @Override public ITextComponent getDisplayName() { return itemStackTestItem.getDisplayName(); } @Nullable @Override public ContainerTestItem createMenu(int windowID_, PlayerInventory playerInventory, PlayerEntity playerEntity) { ContainerTestItem newContainerServerSide = ContainerTestItem.createContainerServerSide(windowID_, playerInventory, itemTestItem.getItemStackHandlerTestItem(itemStackTestItem), itemStackTestItem); return newContainerServerSide; } private ItemTestItem itemTestItem; private ItemStack itemStackTestItem; } @Nonnull @Override public ICapabilityProvider initCapabilities(ItemStack stack, CompoundNBT oldCapNbt) { return new CapabilityProviderTestItem(); } private static ItemStackHandlerTestItem getItemStackHandlerTestItem(ItemStack itemStack) { IItemHandler testItem = itemStack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElse(null); if (testItem == null || !(testItem instanceof ItemStackHandlerTestItem)) { LOGGER.error("ItemTestItem did not have the expected ITEM_HANDLER_CAPABILITY"); return new ItemStackHandlerTestItem(1); } return (ItemStackHandlerTestItem) testItem; } private final String BASE_NBT_TAG = "base"; private final String CAPABILITY_NBT_TAG = "cap"; @Nullable @Override public CompoundNBT getShareTag(ItemStack stack) { CompoundNBT baseTag = stack.getTag(); ItemStackHandlerTestItem itemStackHandlerTestItem = getItemStackHandlerTestItem(stack); CompoundNBT capabilityTag = itemStackHandlerTestItem.serializeNBT(); CompoundNBT combinedTag = new CompoundNBT(); if (baseTag != null) { combinedTag.put(BASE_NBT_TAG, baseTag); } if (capabilityTag != null) { combinedTag.put(CAPABILITY_NBT_TAG, capabilityTag); } return combinedTag; } @Override public void readShareTag(ItemStack stack, @Nullable CompoundNBT nbt) { if (nbt == null) { stack.setTag(null); return; } CompoundNBT baseTag = nbt.getCompound(BASE_NBT_TAG); // empty if not found CompoundNBT capabilityTag = nbt.getCompound(CAPABILITY_NBT_TAG); // empty if not found stack.setTag(baseTag); ItemStackHandlerTestItem itemStackHandlerTestItem = getItemStackHandlerTestItem(stack); itemStackHandlerTestItem.deserializeNBT(capabilityTag); } public static float getFullnessPropertyOverride(ItemStack itemStack, @Nullable World world, @Nullable LivingEntity livingEntity) { ItemStackHandlerTestItem testItem = getItemStackHandlerTestItem(itemStack); float fractionEmpty = testItem.getNumberOfEmptySlots() / (float)testItem.getSlots(); return 1.0F - fractionEmpty; } private static final Logger LOGGER = LogManager.getLogger(); } Basically I have an Item GUI that acts as a storage bag right now, and I want to be able to remove/add items to it whenever I shift-right clicked. Problem is I don't know how to make it so it can add or remove an item from the items inventory.
  7. @Mod.EventBusSubscriber(modid = MiningTool.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) With this?
  8. I tried using this but it's not being used. @SubscribeEvent(priority = EventPriority.HIGHEST) public void onBlockStartBreak(PlayerEvent.BreakSpeed event){ LOGGER.info(event.getOriginalSpeed()); }
  9. I have a tool that mines a 3x3 area with worldIn.destroyBlock() but the problem I have is how do I make the tool's mining speed equal to the average mining speed of the total surrounding blocks? I'm currently using public boolean onBlockDestroyed() package com.nindybun.miningtool.objects.items; import net.minecraft.block.BlockState; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.LivingEntity; import net.minecraft.item.IItemTier; import net.minecraft.item.ItemStack; import net.minecraft.item.PickaxeItem; import net.minecraft.util.math.*; import net.minecraft.util.math.shapes.VoxelShapes; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.StringTextComponent; import net.minecraft.world.World; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import javax.annotation.Nullable; import java.util.List; public class TestDrill extends PickaxeItem { private static final Logger LOGGER = LogManager.getLogger(); public TestDrill(IItemTier tier, int attackDamageIn, float attackSpeedIn, Properties builder) { super(tier, attackDamageIn, attackSpeedIn, builder); } @Override public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) { tooltip.add(new StringTextComponent("This is a test drill.")); super.addInformation(stack, worldIn, tooltip, flagIn); } @Override public boolean onBlockDestroyed(ItemStack stack, World worldIn, BlockState state, BlockPos pos, LivingEntity entityLiving) { double a = entityLiving.getPosX(); double b = entityLiving.getPosY() + (double) entityLiving.getEyeHeight(); double c = entityLiving.getPosZ(); Vec3d vec3start = new Vec3d(a, b, c); float f = entityLiving.rotationPitch; float f1 = entityLiving.rotationYaw; float f2 = MathHelper.cos(-f1 * 0.017453292F - (float) Math.PI); float f3 = MathHelper.sin(-f1 * 0.017453292F - (float) Math.PI); float f4 = -MathHelper.cos(-f * 0.017453292F); float f5 = MathHelper.sin(-f * 0.017453292F); float f6 = f3 * f4; float f7 = f2 * f4; double d3 = 5.0D; Vec3d vec3end = vec3start.add((double) f6 * d3, (double) f5 * d3, (double) f7 * d3); RayTraceResult face = worldIn.rayTraceBlocks(vec3start, vec3end, pos, VoxelShapes.fullCube(), state); if (!entityLiving.isSneaking()) { if (face.getHitVec().getY() == pos.getY() + 1 || face.getHitVec().getY() == pos.getY()) { //Top Face or Bottom Face for (int x = -1; x < 2; x++) { for (int z = -1; z < 2; z++) { if (worldIn.getBlockState(pos.add(x, 0, z)).getBlockHardness(worldIn, pos.add(x, 0, z)) <= 0 || pos.add(x, 0, z) == pos) { } else { worldIn.destroyBlock(pos.add(x, 0, z), true); stack.setDamage(stack.getDamage() + 1); } } } } if (face.getHitVec().getZ() == pos.getZ() || face.getHitVec().getZ() == pos.getZ() + 1) { //North Face or South Face for (int x = -1; x < 2; x++) { for (int y = -1; y < 2; y++) { if (worldIn.getBlockState(pos.add(x, y, 0)).getBlockHardness(worldIn, pos.add(x, y, 0)) <= 0 || pos.add(x, y, 0) == pos) { } else { worldIn.destroyBlock(pos.add(x, y, 0), true); stack.setDamage(stack.getDamage() + 1); } } } } if (face.getHitVec().getX() == pos.getX() || face.getHitVec().getX() == pos.getX() + 1) { //West Face or east Face for (int y = -1; y < 2; y++) { for (int z = -1; z < 2; z++) { if (worldIn.getBlockState(pos.add(0, y, z)).getBlockHardness(worldIn, pos.add(0, y, z)) <= 0 || pos.add(0, y, z) == pos) { } else { worldIn.destroyBlock(pos.add(0, y, z), true); stack.setDamage(stack.getDamage() + 1); } } } } } return super.onBlockDestroyed(stack, worldIn, state, pos, entityLiving); } }
  10. For me, the world.rayTraceBlocks(vec3start, vec3end) does not work. instead it needed to be world.rayTraceBlocks(vec3start, vec3end, pos, VoxelShapes.fullCube(), state); And in order for me to get the face of the block, I needed to do face.getHitVec().getY() == pos.getY() and face.getHitVec().getY() == pos.getY()+1 to mine a 3x3 area for the top and bottom face. The same idea goes with the horizontal directions
  11. What did you do do make it work up and down?
  12. I'm trying to make a tool that mines a 3x3 area based on the side of the block the player broke. For example if I broke a block while having my cursor on one of the faces, then it would mine blocks around it on the same plane. So far I'm using the direction of the entity and pitch. package com.nindybun.miningtool.objects.items; import com.sun.org.apache.xerces.internal.xs.XSIDCDefinition; import net.minecraft.block.BlockState; import net.minecraft.block.DirectionalBlock; import net.minecraft.client.Minecraft; import net.minecraft.client.MinecraftGame; import net.minecraft.client.renderer.FaceDirection; import net.minecraft.client.renderer.Vector3d; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.IItemTier; import net.minecraft.item.ItemStack; import net.minecraft.item.PickaxeItem; import net.minecraft.util.Direction; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.StringTextComponent; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; import net.minecraftforge.client.event.ClientChatEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import javax.annotation.Nullable; import java.util.List; public class TestDrill extends PickaxeItem { private static final Logger LOGGER = LogManager.getLogger(); public TestDrill(IItemTier tier, int attackDamageIn, float attackSpeedIn, Properties builder) { super(tier, attackDamageIn, attackSpeedIn, builder); } @Override public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) { tooltip.add(new StringTextComponent("This is a test drill.")); super.addInformation(stack, worldIn, tooltip, flagIn); } @Override public boolean onBlockDestroyed(ItemStack stack, World worldIn, BlockState state, BlockPos pos, LivingEntity entityLiving) { float pitch = entityLiving.getPitch(0); //Vertical if (pitch < 0){ pitch = -pitch; } if ((entityLiving.getHorizontalFacing() == Direction.NORTH || entityLiving.getHorizontalFacing() == Direction.SOUTH) & (pitch != 90)) { //mines North/South worldIn.destroyBlock(pos.add(0, 1, 0), true); worldIn.destroyBlock(pos.add(0, -1, 0), true); worldIn.destroyBlock(pos.add(1, 0, 0), true); worldIn.destroyBlock(pos.add(-1, 0, 0), true); worldIn.destroyBlock(pos.add(1, 1, 0), true); worldIn.destroyBlock(pos.add(-1, -1, 0), true); worldIn.destroyBlock(pos.add(1, -1, 0), true); worldIn.destroyBlock(pos.add(-1, 1, 0), true); } else if ((entityLiving.getHorizontalFacing() == Direction.WEST || entityLiving.getHorizontalFacing() == Direction.EAST) & (pitch != 90)){ //Mines West/east worldIn.destroyBlock(pos.add(0, 1, 0), true); worldIn.destroyBlock(pos.add(0, -1, 0), true); worldIn.destroyBlock(pos.add(0, 0, 1), true); worldIn.destroyBlock(pos.add(0, 0, -1), true); worldIn.destroyBlock(pos.add(0, 1, 1), true); worldIn.destroyBlock(pos.add(0, -1, -1), true); worldIn.destroyBlock(pos.add(0, -1, 1), true); worldIn.destroyBlock(pos.add(0, 1, -1), true); } else if (pitch == 90){ //Mines Up/Down worldIn.destroyBlock(pos.add(1, 0, 0), true); worldIn.destroyBlock(pos.add(-1, 0, 0), true); worldIn.destroyBlock(pos.add(0, 0, 1), true); worldIn.destroyBlock(pos.add(0, 0, -1), true); worldIn.destroyBlock(pos.add(1, 0, 1), true); worldIn.destroyBlock(pos.add(-1, 0, -1), true); worldIn.destroyBlock(pos.add(-1, 0, 1), true); worldIn.destroyBlock(pos.add(1, 0, -1), true); } return super.onBlockDestroyed(stack, worldIn, state, pos, entityLiving); } }
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.