normalized rangeable pickaxe

This commit is contained in:
Jottyfan
2026-01-03 11:39:37 +01:00
parent 1b7336e866
commit 312c7370cf
7 changed files with 60 additions and 206 deletions

View File

@@ -1,6 +1,10 @@
package de.jottyfan.minecraft.item; package de.jottyfan.minecraft.item;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.core.BlockPos;
/** /**
* *
@@ -46,8 +50,7 @@ public class HarvestRange implements Serializable {
/** /**
* add i to x, y and z and return the resulting class as a new one * add i to x, y and z and return the resulting class as a new one
* *
* @param i * @param i the summand
* the summand
* @return the new class * @return the new class
*/ */
public HarvestRange addXYZ(int i) { public HarvestRange addXYZ(int i) {
@@ -63,6 +66,32 @@ public class HarvestRange implements Serializable {
return new int[] { xRange, yRange, zRange }; return new int[] { xRange, yRange, zRange };
} }
/**
* get range as blockpos array; find all the block positions for the distance of
* xRange, yRange and zRange
*
* @param pos the reference position
* @param ignoreY if true, ignore the height
* @param reduce values to reduce range
* @return the list of block positions; an empty list at least
*/
public List<BlockPos> getRangeAsBlockPosArray(BlockPos pos, boolean ignoreY, BlockPos reduce) {
List<BlockPos> blockPositions = new ArrayList<>();
int xBorder = xRange - reduce.getX();
int yBorder = ignoreY ? 0 : yRange - reduce.getY();
int zBorder = zRange - reduce.getZ();
for (int x = -xBorder; x <= xBorder; x++) {
for (int z = -zBorder; z <= zBorder; z++) {
for (int y = -yBorder; y <= yBorder; y++) {
if (ignoreY || Math.abs(x) + Math.abs(y) + Math.abs(z) <= Math.max(Math.max(xBorder, yBorder), zBorder)) {
blockPositions.add(pos.offset(x, y, z));
}
}
}
}
return blockPositions;
}
/** /**
* @return the xRange * @return the xRange
*/ */
@@ -71,8 +100,7 @@ public class HarvestRange implements Serializable {
} }
/** /**
* @param xRange * @param xRange the xRange to set
* the xRange to set
*/ */
public void setxRange(int xRange) { public void setxRange(int xRange) {
this.xRange = xRange; this.xRange = xRange;
@@ -86,8 +114,7 @@ public class HarvestRange implements Serializable {
} }
/** /**
* @param yRange * @param yRange the yRange to set
* the yRange to set
*/ */
public void setyRange(int yRange) { public void setyRange(int yRange) {
this.yRange = yRange; this.yRange = yRange;
@@ -101,8 +128,7 @@ public class HarvestRange implements Serializable {
} }
/** /**
* @param zRange * @param zRange the zRange to set
* the zRange to set
*/ */
public void setzRange(int zRange) { public void setzRange(int zRange) {
this.zRange = zRange; this.zRange = zRange;

View File

@@ -10,10 +10,7 @@ import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
import net.minecraft.resources.Identifier; import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.item.ToolMaterial;
import net.minecraft.world.item.Item.Properties; import net.minecraft.world.item.Item.Properties;
import net.minecraft.world.item.equipment.ArmorType; import net.minecraft.world.item.equipment.ArmorType;
@@ -55,29 +52,25 @@ public class QuicklyItems {
// TODO: rename tools to speedaxe and quickaxe instead of the powder version // TODO: rename tools to speedaxe and quickaxe instead of the powder version
public static final Item TOOL_SPEEDPOWDERAXE = registerItem("speedpowderaxe", public static final Item TOOL_SPEEDPOWDERAXE = registerItem("speedpowderaxe",
properties -> new ToolRangeableAxe( properties -> new ToolRangeableAxe(800, 7f, -3.1f, properties, new HarvestRange(32, 64, 32)));
new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, 800, 7f, 1f, 15, ItemTags.DIAMOND_TOOL_MATERIALS), 7f,
-3.1f, properties, new HarvestRange(32, 64, 32)));
public static final Item TOOL_SPEEDPOWDERHOE = registerItem("speedpowderhoe", public static final Item TOOL_SPEEDPOWDERHOE = registerItem("speedpowderhoe",
properties -> new ToolSpeedpowderHoe(properties)); properties -> new ToolSpeedpowderHoe(properties));
public static final Item TOOL_SPEEDPOWDERPICKAXE = registerItem("speedpowderpickaxe", public static final Item TOOL_SPEEDPOWDERPICKAXE = registerItem("speedpowderpickaxe",
properties -> new ToolSpeedpowderPickaxe(properties)); properties -> new ToolRangeablePickaxe(properties, 800, new HarvestRange(3)));
public static final Item TOOL_SPEEDPOWDERSHEARS = registerItem("speedpowdershears", public static final Item TOOL_SPEEDPOWDERSHEARS = registerItem("speedpowdershears",
properties -> new ToolSpeedpowderShears(properties)); properties -> new ToolSpeedpowderShears(properties));
public static final Item TOOL_SPEEDPOWDERSHOVEL = registerItem("speedpowdershovel", public static final Item TOOL_SPEEDPOWDERSHOVEL = registerItem("speedpowdershovel",
properties -> new ToolSpeedpowderShovel(properties)); properties -> new ToolRangeableShovel(properties, 800, new HarvestRange(3)));
public static final Item TOOL_SPEEDPOWDERWATERHOE = registerItem("speedpowderwaterhoe", public static final Item TOOL_SPEEDPOWDERWATERHOE = registerItem("speedpowderwaterhoe",
properties -> new ToolSpeedpowderWaterHoe(properties, QuicklyItems.TOOL_SPEEDPOWDERHOE)); properties -> new ToolSpeedpowderWaterHoe(properties, QuicklyItems.TOOL_SPEEDPOWDERHOE));
public static final Item TOOL_QUICKIEPOWDERAXE = registerItem("quickiepowderaxe", public static final Item TOOL_QUICKIEPOWDERAXE = registerItem("quickiepowderaxe",
properties -> new ToolRangeableAxe( properties -> new ToolRangeableAxe(2400, 7F, -3.1F, properties, new HarvestRange(64, 128, 64)));
new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, 2400, 7f, 1f, 15, ItemTags.DIAMOND_TOOL_MATERIALS), 7F,
-3.1F, properties, new HarvestRange(64, 128, 64)));
public static final Item TOOL_QUICKIEPOWDERHOE = registerItem("quickiepowderhoe", public static final Item TOOL_QUICKIEPOWDERHOE = registerItem("quickiepowderhoe",
properties -> new ToolQuickiepowderHoe(properties)); properties -> new ToolQuickiepowderHoe(properties));
public static final Item TOOL_QUICKIEPOWDERPICKAXE = registerItem("quickiepowderpickaxe", public static final Item TOOL_QUICKIEPOWDERPICKAXE = registerItem("quickiepowderpickaxe",
properties -> new ToolQuickiepowderPickaxe(properties)); properties -> new ToolRangeablePickaxe(properties, 2400, new HarvestRange(6)));
public static final Item TOOL_QUICKIEPOWDERSHOVEL = registerItem("quickiepowdershovel", public static final Item TOOL_QUICKIEPOWDERSHOVEL = registerItem("quickiepowdershovel",
properties -> new ToolQuickiepowderShovel(properties)); properties -> new ToolRangeableShovel(properties, 2400, new HarvestRange(6)));
public static final Item TOOL_QUICKIEPOWDERWATERHOE = registerItem("quickiepowderwaterhoe", public static final Item TOOL_QUICKIEPOWDERWATERHOE = registerItem("quickiepowderwaterhoe",
properties -> new ToolQuickiepowderWaterHoe(properties, QuicklyItems.TOOL_QUICKIEPOWDERHOE)); properties -> new ToolQuickiepowderWaterHoe(properties, QuicklyItems.TOOL_QUICKIEPOWDERHOE));
public static final Item TOOL_QUICKIEPOWDERSHEARS = registerItem("quickiepowdershears", public static final Item TOOL_QUICKIEPOWDERSHEARS = registerItem("quickiepowdershears",

View File

@@ -1,55 +0,0 @@
package de.jottyfan.minecraft.item;
import java.util.List;
import com.google.common.collect.Lists;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ToolMaterial;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
/**
*
* @author jotty
*
*/
public class ToolQuickiepowderPickaxe extends Item implements ToolRangeable {
public static final int[] DEFAULT_HARVEST_RANGE = new int[] { 6, 6, 6 };
private final static ToolMaterial MATERIAL = new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, 2400, 7f, 1f, 15, ItemTags.DIAMOND_TOOL_MATERIALS);
public ToolQuickiepowderPickaxe(Properties properties) {
super(properties.pickaxe(MATERIAL, 7F, -3.1F));
}
@Override
public HarvestRange getRange(ItemStack stack) {
return new HarvestRange(DEFAULT_HARVEST_RANGE);
}
@Override
public boolean canBreakNeighbors(BlockState blockIn) {
return new ItemStack(this).isCorrectToolForDrops(blockIn);
}
@Override
public List<Block> getBlockList(Block block) {
return Lists.newArrayList(block);
}
// @Override
// public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
// CommonToolCode.onItemRightClick(worldIn, playerIn, handIn);
// return super.onItemRightClick(worldIn, playerIn, handIn);
// }
//
// @Override
// public void addInformation(ItemStack stack, World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
// CommonToolCode.addInformation(stack, worldIn, tooltip, flagIn);
// super.addInformation(stack, worldIn, tooltip, flagIn);
// }
}

View File

@@ -1,97 +0,0 @@
package de.jottyfan.minecraft.item;
import java.util.List;
import com.google.common.collect.Lists;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ShovelItem;
import net.minecraft.world.item.ToolMaterial;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
/**
*
* @author jotty
*
*/
public class ToolQuickiepowderShovel extends ShovelItem implements ToolRangeable {
public static final Integer DEFAULT_HARVEST_RANGE = 6;
private final static ToolMaterial MATERIAL = new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, 2400, 7f, 1f, 15, ItemTags.DIAMOND_TOOL_MATERIALS);
public HarvestRange range;
public ToolQuickiepowderShovel(Properties properties) {
super(MATERIAL, 7F, -3.1F, properties);
this.range = new HarvestRange(DEFAULT_HARVEST_RANGE);
}
private void createPathOnGrass(Level level, BlockPos pos, Direction side) {
BlockState blockState = level.getBlockState(pos);
if (blockState.isAir()) {
// try to find one underneath
pos = pos.below();
blockState = level.getBlockState(pos);
} else if (!level.getBlockState(pos.above()).isAir()) {
pos = pos.above();
blockState = level.getBlockState(pos);
}
if (side != Direction.DOWN) {
if (blockState != null && level.getBlockState(pos.above()).isAir()) {
if (!level.isClientSide()) {
level.setBlock(pos, blockState, 11);
}
}
}
}
@Override
public InteractionResult useOn(UseOnContext context) {
Level level = context.getLevel();
BlockPos pos = context.getClickedPos();
BlockPos[] positions = new BlockPos[] { pos.north().north().west().west(), pos.north().north().west(),
pos.north().north(), pos.north().north().east(), pos.north().north().east().east(), pos.north().west().west(),
pos.north().west(), pos.north(), pos.north().east(), pos.north().east().east(), pos.west().west(), pos.west(),
pos, pos.east(), pos.east().east(), pos.south().west().west(), pos.south().west(), pos.south(),
pos.south().east(), pos.south().east().east(), pos.south().south().west().west(), pos.south().south().west(),
pos.south().south(), pos.south().south().east(), pos.south().south().east().east() };
for (BlockPos p : positions) {
createPathOnGrass(level, p, context.getClickedFace());
}
return super.useOn(context);
}
@Override
public HarvestRange getRange(ItemStack stack) {
// TODO: get range from stack
return range;
}
@Override
public boolean canBreakNeighbors(BlockState blockState) {
return new ItemStack(this).isCorrectToolForDrops(blockState);
}
@Override
public List<Block> getBlockList(Block block) {
return Lists.newArrayList(block);
}
// @Override
// public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
// CommonToolCode.onItemRightClick(worldIn, playerIn, handIn);
// return super.onItemRightClick(worldIn, playerIn, handIn);
// }
//
// @Override
// public void addInformation(ItemStack stack, World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
// CommonToolCode.addInformation(stack, worldIn, tooltip, flagIn);
// super.addInformation(stack, worldIn, tooltip, flagIn);
// }
}

View File

@@ -5,6 +5,7 @@ import java.util.List;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import net.minecraft.tags.BlockTags; import net.minecraft.tags.BlockTags;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.item.AxeItem; import net.minecraft.world.item.AxeItem;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ToolMaterial; import net.minecraft.world.item.ToolMaterial;
@@ -22,8 +23,8 @@ public class ToolRangeableAxe extends AxeItem implements ToolRangeable {
private final HarvestRange range; private final HarvestRange range;
public ToolRangeableAxe(ToolMaterial material, float attackDamage, float attackSpeed, Properties properties, HarvestRange range) { public ToolRangeableAxe(int duration, float attackDamage, float attackSpeed, Properties properties, HarvestRange range) {
super(material, attackDamage, attackSpeed, properties); super(new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, duration, 7f, 1f, 15, ItemTags.DIAMOND_TOOL_MATERIALS), attackDamage, attackSpeed, properties);
this.range = range; this.range = range;
} }

View File

@@ -17,18 +17,17 @@ import net.minecraft.world.level.block.state.BlockState;
* @author jotty * @author jotty
* *
*/ */
public class ToolSpeedpowderPickaxe extends Item implements ToolRangeable { public class ToolRangeablePickaxe extends Item implements ToolRangeable {
private HarvestRange range;
public static final int[] DEFAULT_HARVEST_RANGE = new int[] { 3, 3, 3 }; public ToolRangeablePickaxe(Properties properties, Integer duration, HarvestRange range) {
private final static ToolMaterial MATERIAL = new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, 800, 7.0F, 1.0F, 15, ItemTags.DIAMOND_TOOL_MATERIALS); super(properties.pickaxe(new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, duration, 7.0F, 1.0F, 15, ItemTags.DIAMOND_TOOL_MATERIALS), 7F, -3.1F));
this.range = range;
public ToolSpeedpowderPickaxe(Properties properties) {
super(properties.pickaxe(MATERIAL, 7F, -3.1F));
} }
@Override @Override
public HarvestRange getRange(ItemStack stack) { public HarvestRange getRange(ItemStack stack) {
return new HarvestRange(DEFAULT_HARVEST_RANGE); return range;
} }
@Override @Override

View File

@@ -15,21 +15,15 @@ import net.minecraft.world.item.ToolMaterial;
import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
/** public class ToolRangeableShovel extends ShovelItem implements ToolRangeable {
*
* @author jotty
*
*/
public class ToolSpeedpowderShovel extends ShovelItem implements ToolRangeable {
public static final Integer DEFAULT_HARVEST_RANGE = 3;
private final static ToolMaterial MATERIAL = new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, 800, 7f, 1f, 15, ItemTags.DIAMOND_TOOL_MATERIALS);
public HarvestRange range; public HarvestRange range;
public ToolSpeedpowderShovel(Properties properties) { public ToolRangeableShovel(Properties properties, Integer durability, HarvestRange range) {
super(MATERIAL, 7F, -3.1F, properties); super(new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, durability, 7f, 1f, 15, ItemTags.DIAMOND_TOOL_MATERIALS), 7F, -3.1F, properties);
this.range = new HarvestRange(DEFAULT_HARVEST_RANGE); this.range = range;
} }
private void createPathOnGrass(Level level, BlockPos pos, Direction side) { private void createPathOnGrass(Level level, BlockPos pos, Direction side) {
@@ -45,7 +39,7 @@ public class ToolSpeedpowderShovel extends ShovelItem implements ToolRangeable {
if (side != Direction.DOWN) { if (side != Direction.DOWN) {
if (blockState != null && level.getBlockState(pos.above()).isAir()) { if (blockState != null && level.getBlockState(pos.above()).isAir()) {
if (!level.isClientSide()) { if (!level.isClientSide()) {
level.setBlock(pos, blockState, 11); level.setBlockAndUpdate(pos, Blocks.DIRT_PATH.defaultBlockState());
} }
} }
} }
@@ -53,22 +47,14 @@ public class ToolSpeedpowderShovel extends ShovelItem implements ToolRangeable {
@Override @Override
public InteractionResult useOn(UseOnContext context) { public InteractionResult useOn(UseOnContext context) {
Level level = context.getLevel(); for (BlockPos pos : range.getRangeAsBlockPosArray(context.getClickedPos(), true, new BlockPos(1, 1, 1))) {
BlockPos pos = context.getClickedPos(); createPathOnGrass(context.getLevel(), pos, context.getClickedFace());
createPathOnGrass(level, pos.north(), context.getClickedFace()); }
createPathOnGrass(level, pos.north().east(), context.getClickedFace());
createPathOnGrass(level, pos.north().west(), context.getClickedFace());
createPathOnGrass(level, pos.east(), context.getClickedFace());
createPathOnGrass(level, pos.west(), context.getClickedFace());
createPathOnGrass(level, pos.south(), context.getClickedFace());
createPathOnGrass(level, pos.south().east(), context.getClickedFace());
createPathOnGrass(level, pos.south().west(), context.getClickedFace());
return super.useOn(context); return super.useOn(context);
} }
@Override @Override
public HarvestRange getRange(ItemStack stack) { public HarvestRange getRange(ItemStack stack) {
// TODO: get range from stack
return range; return range;
} }
@@ -93,4 +79,5 @@ public class ToolSpeedpowderShovel extends ShovelItem implements ToolRangeable {
// CommonToolCode.addInformation(stack, worldIn, tooltip, flagIn); // CommonToolCode.addInformation(stack, worldIn, tooltip, flagIn);
// super.addInformation(stack, worldIn, tooltip, flagIn); // super.addInformation(stack, worldIn, tooltip, flagIn);
// } // }
} }