normalized rangeable pickaxe
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package de.jottyfan.minecraft.item;
|
||||
|
||||
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
|
||||
*
|
||||
* @param i
|
||||
* the summand
|
||||
* @param i the summand
|
||||
* @return the new class
|
||||
*/
|
||||
public HarvestRange addXYZ(int i) {
|
||||
@@ -60,7 +63,33 @@ public class HarvestRange implements Serializable {
|
||||
* @return the int array
|
||||
*/
|
||||
public int[] getRangeAsArray() {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,8 +100,7 @@ public class HarvestRange implements Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param xRange
|
||||
* the xRange to set
|
||||
* @param xRange the xRange to set
|
||||
*/
|
||||
public void setxRange(int xRange) {
|
||||
this.xRange = xRange;
|
||||
@@ -86,8 +114,7 @@ public class HarvestRange implements Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param yRange
|
||||
* the yRange to set
|
||||
* @param yRange the yRange to set
|
||||
*/
|
||||
public void setyRange(int yRange) {
|
||||
this.yRange = yRange;
|
||||
@@ -101,8 +128,7 @@ public class HarvestRange implements Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param zRange
|
||||
* the zRange to set
|
||||
* @param zRange the zRange to set
|
||||
*/
|
||||
public void setzRange(int zRange) {
|
||||
this.zRange = zRange;
|
||||
|
||||
@@ -10,10 +10,7 @@ import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.Identifier;
|
||||
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.ToolMaterial;
|
||||
import net.minecraft.world.item.Item.Properties;
|
||||
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
|
||||
|
||||
public static final Item TOOL_SPEEDPOWDERAXE = registerItem("speedpowderaxe",
|
||||
properties -> new ToolRangeableAxe(
|
||||
new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, 800, 7f, 1f, 15, ItemTags.DIAMOND_TOOL_MATERIALS), 7f,
|
||||
-3.1f, properties, new HarvestRange(32, 64, 32)));
|
||||
properties -> new ToolRangeableAxe(800, 7f, -3.1f, properties, new HarvestRange(32, 64, 32)));
|
||||
public static final Item TOOL_SPEEDPOWDERHOE = registerItem("speedpowderhoe",
|
||||
properties -> new ToolSpeedpowderHoe(properties));
|
||||
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",
|
||||
properties -> new ToolSpeedpowderShears(properties));
|
||||
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",
|
||||
properties -> new ToolSpeedpowderWaterHoe(properties, QuicklyItems.TOOL_SPEEDPOWDERHOE));
|
||||
public static final Item TOOL_QUICKIEPOWDERAXE = registerItem("quickiepowderaxe",
|
||||
properties -> new ToolRangeableAxe(
|
||||
new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, 2400, 7f, 1f, 15, ItemTags.DIAMOND_TOOL_MATERIALS), 7F,
|
||||
-3.1F, properties, new HarvestRange(64, 128, 64)));
|
||||
properties -> new ToolRangeableAxe(2400, 7F, -3.1F, properties, new HarvestRange(64, 128, 64)));
|
||||
public static final Item TOOL_QUICKIEPOWDERHOE = registerItem("quickiepowderhoe",
|
||||
properties -> new ToolQuickiepowderHoe(properties));
|
||||
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",
|
||||
properties -> new ToolQuickiepowderShovel(properties));
|
||||
properties -> new ToolRangeableShovel(properties, 2400, new HarvestRange(6)));
|
||||
public static final Item TOOL_QUICKIEPOWDERWATERHOE = registerItem("quickiepowderwaterhoe",
|
||||
properties -> new ToolQuickiepowderWaterHoe(properties, QuicklyItems.TOOL_QUICKIEPOWDERHOE));
|
||||
public static final Item TOOL_QUICKIEPOWDERSHEARS = registerItem("quickiepowdershears",
|
||||
|
||||
@@ -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);
|
||||
// }
|
||||
}
|
||||
@@ -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);
|
||||
// }
|
||||
}
|
||||
@@ -5,6 +5,7 @@ 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.AxeItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.ToolMaterial;
|
||||
@@ -22,8 +23,8 @@ public class ToolRangeableAxe extends AxeItem implements ToolRangeable {
|
||||
|
||||
private final HarvestRange range;
|
||||
|
||||
public ToolRangeableAxe(ToolMaterial material, float attackDamage, float attackSpeed, Properties properties, HarvestRange range) {
|
||||
super(material, attackDamage, attackSpeed, properties);
|
||||
public ToolRangeableAxe(int duration, float attackDamage, float attackSpeed, Properties properties, HarvestRange range) {
|
||||
super(new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, duration, 7f, 1f, 15, ItemTags.DIAMOND_TOOL_MATERIALS), attackDamage, attackSpeed, properties);
|
||||
this.range = range;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,18 +17,17 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||
* @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 };
|
||||
private final static ToolMaterial MATERIAL = new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, 800, 7.0F, 1.0F, 15, ItemTags.DIAMOND_TOOL_MATERIALS);
|
||||
|
||||
public ToolSpeedpowderPickaxe(Properties properties) {
|
||||
super(properties.pickaxe(MATERIAL, 7F, -3.1F));
|
||||
public ToolRangeablePickaxe(Properties properties, Integer duration, HarvestRange range) {
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HarvestRange getRange(ItemStack stack) {
|
||||
return new HarvestRange(DEFAULT_HARVEST_RANGE);
|
||||
return range;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -15,21 +15,15 @@ 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.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
/**
|
||||
*
|
||||
* @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 class ToolRangeableShovel extends ShovelItem implements ToolRangeable {
|
||||
public HarvestRange range;
|
||||
|
||||
public ToolSpeedpowderShovel(Properties properties) {
|
||||
super(MATERIAL, 7F, -3.1F, properties);
|
||||
this.range = new HarvestRange(DEFAULT_HARVEST_RANGE);
|
||||
public ToolRangeableShovel(Properties properties, Integer durability, HarvestRange range) {
|
||||
super(new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, durability, 7f, 1f, 15, ItemTags.DIAMOND_TOOL_MATERIALS), 7F, -3.1F, properties);
|
||||
this.range = range;
|
||||
}
|
||||
|
||||
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 (blockState != null && level.getBlockState(pos.above()).isAir()) {
|
||||
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
|
||||
public InteractionResult useOn(UseOnContext context) {
|
||||
Level level = context.getLevel();
|
||||
BlockPos pos = context.getClickedPos();
|
||||
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());
|
||||
for (BlockPos pos : range.getRangeAsBlockPosArray(context.getClickedPos(), true, new BlockPos(1, 1, 1))) {
|
||||
createPathOnGrass(context.getLevel(), pos, context.getClickedFace());
|
||||
}
|
||||
return super.useOn(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HarvestRange getRange(ItemStack stack) {
|
||||
// TODO: get range from stack
|
||||
return range;
|
||||
}
|
||||
|
||||
@@ -93,4 +79,5 @@ public class ToolSpeedpowderShovel extends ShovelItem implements ToolRangeable {
|
||||
// CommonToolCode.addInformation(stack, worldIn, tooltip, flagIn);
|
||||
// super.addInformation(stack, worldIn, tooltip, flagIn);
|
||||
// }
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user