Jump to content

Recommended Posts

Posted (edited)

Hi all,

 

I want to make a very simple mod, that just adds a "hammer" (similar to something like Tinkerer's Construct) to the game but only so it mines a 3 wide X 3 high x 1 deep chunk. I have already added the item to the game as a PickaxeItem:

 

	@Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
	public static class RegistryEvents
	{
		@SubscribeEvent
		public static void registerItems(final RegistryEvent.Register<Item> event) 
		{
			event.getRegistry().registerAll(
			ItemList.hammer = new PickaxeItem(ToolMaterialList.hammer,-6, -2.8f, new Item.Properties().group(ItemGroup.TOOLS)).setRegistryName(location("hammer"))
			);
			logger.info("Items registered.");
		}
		
		private static ResourceLocation location(String name) {
			return new ResourceLocation(modid, name);
		}
	}

 with hammer being in a seperate enum, defined in the following way: 

 

public enum ToolMaterialList implements IItemTier
{
	hammer(5.0f,9.0f,1561,3,25,Items.DIAMOND);
	
	private float attackDamage, efficiency;
	private int durability, harvestLevel, enchantability;
	private Item repairMaterial;
	
	private ToolMaterialList(float attackDamage, float efficiency, int durability, int harvestLevel, int enchantability, Item repairMaterial) 
	{
		this.attackDamage=attackDamage;
		this.efficiency=efficiency;
		this.durability=durability;
		this.harvestLevel=harvestLevel;
		this.enchantability=enchantability;
		this.repairMaterial=repairMaterial;
		
	}
	@Override
	public float getAttackDamage() {
		return this.attackDamage;
	}
	@Override
	public float getEfficiency() {
		return this.efficiency;
	}
	@Override
	public int getEnchantability() {
		return this.enchantability;
	}
	@Override
	public int getHarvestLevel() {
		return this.harvestLevel;
	}
	@Override
	public int getMaxUses() {
		return this.durability;
	}
	@Override
	public Ingredient getRepairMaterial() {
		return Ingredient.fromItems(this.repairMaterial);
	}
}

 

So the item loads into game with the texture I want but right now if functions pretty much identically to a diamond pickaxe. How can I go about changing the mining radius? Sorry if this is an involved question I just really don't know where to start.

Edited by norquisd
included MC version
Posted

The way I am thinking about doing this is adding some sort of listener to detect when a player uses the hammer to break a block, to then just execute a command as that player using their coordinates and rotation to calculate what 9 blocks should break. 

Posted

Override onBlockDestroyed(ItemStack, World, BlockState, BlockPos, LivingEntity) in your hammer's class. You will need a custom class that extends PickaxeItem to do this. In that method figure out which Direction the player is looking and break all the blocks perpendicular to that vector.

  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

In PickaxeItem.class:

 

public class PickaxeItem extends ToolItem {
   private static final Set<Block> EFFECTIVE_ON = ImmutableSet.of(Blocks.ACTIVATOR_RAIL, Blocks.COAL_ORE, Blocks.COBBLESTONE, Blocks.DETECTOR_RAIL, Blocks.DIAMOND_BLOCK, Blocks.DIAMOND_ORE, Blocks.POWERED_RAIL, Blocks.GOLD_BLOCK, Blocks.GOLD_ORE, Blocks.ICE, Blocks.IRON_BLOCK, Blocks.IRON_ORE, Blocks.LAPIS_BLOCK, Blocks.LAPIS_ORE, Blocks.MOSSY_COBBLESTONE, Blocks.NETHERRACK, Blocks.PACKED_ICE, Blocks.BLUE_ICE, Blocks.RAIL, Blocks.REDSTONE_ORE, Blocks.SANDSTONE, Blocks.CHISELED_SANDSTONE, Blocks.CUT_SANDSTONE, Blocks.CHISELED_RED_SANDSTONE, Blocks.CUT_RED_SANDSTONE, Blocks.RED_SANDSTONE, Blocks.STONE, Blocks.GRANITE, Blocks.POLISHED_GRANITE, Blocks.DIORITE, Blocks.POLISHED_DIORITE, Blocks.ANDESITE, Blocks.POLISHED_ANDESITE, Blocks.STONE_SLAB, Blocks.SMOOTH_STONE_SLAB, Blocks.SANDSTONE_SLAB, Blocks.PETRIFIED_OAK_SLAB, Blocks.COBBLESTONE_SLAB, Blocks.BRICK_SLAB, Blocks.STONE_BRICK_SLAB, Blocks.NETHER_BRICK_SLAB, Blocks.QUARTZ_SLAB, Blocks.RED_SANDSTONE_SLAB, Blocks.PURPUR_SLAB, Blocks.SMOOTH_QUARTZ, Blocks.SMOOTH_RED_SANDSTONE, Blocks.SMOOTH_SANDSTONE, Blocks.SMOOTH_STONE, Blocks.STONE_BUTTON, Blocks.STONE_PRESSURE_PLATE, Blocks.POLISHED_GRANITE_SLAB, Blocks.SMOOTH_RED_SANDSTONE_SLAB, Blocks.MOSSY_STONE_BRICK_SLAB, Blocks.POLISHED_DIORITE_SLAB, Blocks.MOSSY_COBBLESTONE_SLAB, Blocks.END_STONE_BRICK_SLAB, Blocks.SMOOTH_SANDSTONE_SLAB, Blocks.SMOOTH_QUARTZ_SLAB, Blocks.GRANITE_SLAB, Blocks.ANDESITE_SLAB, Blocks.RED_NETHER_BRICK_SLAB, Blocks.POLISHED_ANDESITE_SLAB, Blocks.DIORITE_SLAB, Blocks.SHULKER_BOX, Blocks.BLACK_SHULKER_BOX, Blocks.BLUE_SHULKER_BOX, Blocks.BROWN_SHULKER_BOX, Blocks.CYAN_SHULKER_BOX, Blocks.GRAY_SHULKER_BOX, Blocks.GREEN_SHULKER_BOX, Blocks.LIGHT_BLUE_SHULKER_BOX, Blocks.LIGHT_GRAY_SHULKER_BOX, Blocks.LIME_SHULKER_BOX, Blocks.MAGENTA_SHULKER_BOX, Blocks.ORANGE_SHULKER_BOX, Blocks.PINK_SHULKER_BOX, Blocks.PURPLE_SHULKER_BOX, Blocks.RED_SHULKER_BOX, Blocks.WHITE_SHULKER_BOX, Blocks.YELLOW_SHULKER_BOX);

   public PickaxeItem(IItemTier tier, int attackDamageIn, float attackSpeedIn, Item.Properties builder) {
      super((float)attackDamageIn, attackSpeedIn, tier, EFFECTIVE_ON, builder.addToolType(net.minecraftforge.common.ToolType.PICKAXE, tier.getHarvestLevel()));
   }

   /**
    * Check whether this Item can harvest the given Block
    */
   public boolean canHarvestBlock(BlockState blockIn) {
      Block block = blockIn.getBlock();
      int i = this.getTier().getHarvestLevel();
      if (blockIn.getHarvestTool() == net.minecraftforge.common.ToolType.PICKAXE) {
         return i >= blockIn.getHarvestLevel();
      }
      Material material = blockIn.getMaterial();
      return material == Material.ROCK || material == Material.IRON || material == Material.ANVIL;
   }

   public float getDestroySpeed(ItemStack stack, BlockState state) {
      Material material = state.getMaterial();
      return material != Material.IRON && material != Material.ANVIL && material != Material.ROCK ? super.getDestroySpeed(stack, state) : this.efficiency;
   }
}

 I don't see the method you suggested in this class.

Posted

Ok sorry if I am stupid but I am kind of unfamiliar with the Vec3d() object. I put the following method into my hammer class:

 

	public boolean onBlockDestroyed(ItemStack stack, World worldIn, BlockState state, BlockPos pos, LivingEntity entityLiving) {
	     if (!worldIn.isRemote && state.getBlockHardness(worldIn, pos) != 0.0F) {
	         stack.damageItem(1, entityLiving, (p_220038_0_) -> {
	            p_220038_0_.sendBreakAnimation(EquipmentSlotType.MAINHAND);
	         });
	         Vec3d facing = entityLiving.getLookVec();
	         PlayerEntity player = (PlayerEntity) entityLiving;
	         BreakEvent b = new BreakEvent(worldIn, pos, state, player);
	         MinecraftForge.EVENT_BUS.register(b);
	      }

	      return true;
	   }

 

Obviously this wouldn't work as is. But as I understand, I just need to pass a BreakEvent for each block perpendicular to the source block. So it amounts to passing b to the Event Bus 8 times, probably in some sort of loop. How do I update the pos so that I get the perpendicular blocks? More specifically, what does my variable facing actually hold? 

Posted
5 minutes ago, norquisd said:

BreakEvent b = new BreakEvent(worldIn, pos, state, player); MinecraftForge.EVENT_BUS.register(b);

Don't do this. Do World#destroyBlock.

16 minutes ago, norquisd said:

Ok sorry if I am stupid but I am kind of unfamiliar with the Vec3d() object. I put the following method into my hammer class:

Take a look at Entity#func_213324_a it shows you how to ray trace. Then you just check the RayTraceResult to see if the type is BLOCK and if it is then cast to BlockRayTraceResult. Once it is casted use the "face" field to know the direction the block is being hit from. You can then use that to break the correct blocks.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (edited)
6 minutes ago, Animefan8888 said:

Take a look at Entity#func_213324_a it shows you how to ray trace. Then you just check the RayTraceResult to see if the type is BLOCK and if it is then cast to BlockRayTraceResult. Once it is casted use the "face" field to know the direction the block is being hit from. You can then use that to break the correct blocks.

Im confused about what this return type is, or what I even pass to it. Sorry this is literally Day 1 modding for me. Thanks for the block destroy tip also.

Edited by norquisd
Posted
13 minutes ago, norquisd said:

Im confused about what this return type is

It returns a RayTraceResult. A Ray Trace is when you create a vector from one point to another and see what it collides with. The RayTraceResult tells you what it collides with.

 

14 minutes ago, norquisd said:

or what I even pass to it.

Don't call the method look at it's code to see how a ray trace is done in Minecraft.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
3 minutes ago, Animefan8888 said:

Don't call the method look at it's code to see how a ray trace is done in Minecraft.

   @OnlyIn(Dist.CLIENT)
   public RayTraceResult func_213324_a(double p_213324_1_, float p_213324_3_, boolean p_213324_4_) {
      Vec3d vec3d = this.getEyePosition(p_213324_3_);
      Vec3d vec3d1 = this.getLook(p_213324_3_);
      Vec3d vec3d2 = vec3d.add(vec3d1.x * p_213324_1_, vec3d1.y * p_213324_1_, vec3d1.z * p_213324_1_);
      return this.world.rayTraceBlocks(new RayTraceContext(vec3d, vec3d2, RayTraceContext.BlockMode.OUTLINE, p_213324_4_ ? RayTraceContext.FluidMode.ANY : RayTraceContext.FluidMode.NONE, this));
   }

I'm having a hard time deciphering what is going on though, since the variables names are not helpful.

Posted
Just now, norquisd said:

I'm having a hard time deciphering what is going on though, since the variables names are not helpful.

Take a deeper look.

 

getEyePosition and getLook both take in a float called partialTicks. This variable is client side only. Of no use to use we are not a client. Use 0F.

 

p_213324_4_ is a boolean. And if it used to determine if the FluidMode is ANY or NONE. You don't need this you can hardcode it to NONE.

To figure out what p_213324_1_ is lets look at the call hierarchy of the func_213324_a. Upon looking at the first thing that comes up this is the block reach distance which you can get from the REACH_DISTANCE attribute. Like so PlayerEntity#getAttribute(PlayerEntity.REACH_DISTANCE).getValue()

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

By the way, absolutely fire those forge events for each block you break. Other mods might have permission restrictions (think land claims that block modification except by the owner) and suchlike. You may also want to check that the block is either the same as the center block or that its harvest level (and tool) is acceptable for your tool.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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