added tools

This commit is contained in:
Jottyfan
2026-01-02 00:16:03 +01:00
parent 4dcd8641dc
commit ec10e5c285
74 changed files with 1664 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ import org.apache.logging.log4j.Logger;
import de.jottyfan.minecraft.block.QuicklyBlocks;
import de.jottyfan.minecraft.blockentity.QuicklyBlockEntity;
import de.jottyfan.minecraft.composter.QuicklyComposter;
import de.jottyfan.minecraft.event.QuicklyEvents;
import de.jottyfan.minecraft.feature.QuicklyFeatures;
import de.jottyfan.minecraft.item.QuicklyItems;
import de.jottyfan.minecraft.loot.QuicklyLootTables;
@@ -32,5 +33,6 @@ public class Quickly implements ModInitializer {
QuicklyFeatures.registerFeatures();
QuicklyComposter.registerComposterItems();
QuicklyLootTables.registerChanges();
QuicklyEvents.registerBlockBreak();
}
}

View File

@@ -0,0 +1,215 @@
package de.jottyfan.minecraft.event;
import java.util.ArrayList;
import java.util.List;
import de.jottyfan.minecraft.Quickly;
import de.jottyfan.minecraft.item.HarvestRange;
import de.jottyfan.minecraft.item.QuicklyItems;
import de.jottyfan.minecraft.item.ToolRangeable;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.ExperienceOrb;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
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 EventBlockBreak {
private enum BlockBreakDirection {
UPWARDS, ALL;
}
/**
* break surrounding block if item is of ToolRangeable
*
* @param level
* @param blockPos
* @param blockState
* @param player
* @param oldBlock
* @return true if this range breaking routine has been used, false otherwise
*/
public boolean doBreakBlock(Level level, BlockPos blockPos, BlockState blockState, Player player, Block oldBlock) {
ItemStack mainHandItemStack = player.getMainHandItem();
if (mainHandItemStack != null) {
Item item = mainHandItemStack.getItem();
if (item instanceof ToolRangeable) {
ToolRangeable tool = (ToolRangeable) item;
// not needed when added to before block break
// if (!world.getBlockState(blockPos).getBlock().equals(oldBlock)) {
// // recreate old block to make it breakable; otherwise, the recursive algorithm stops directly
// // this leads to the BUG that blocks with no neighbour will respawn and drop -> unlimited items.
// world.setBlockState(blockPos, oldBlock.getDefaultState());
// }
int handled = handleRangeableTools(tool, mainHandItemStack, level, oldBlock, blockPos, player);
if (handled >= 255) {
// reward for using rangeable tool very successful
level.addFreshEntity(
new ExperienceOrb(level, blockPos.getX(), blockPos.getY(), blockPos.getZ(), handled / 255));
}
return handled > 0; // this way, a rangeable pickaxe can break a dirt block
} else {
return false;
}
} else {
return false;
}
}
/**
* handle the rangeable tools break event
*
* @param tool the tool that has been used
* @param itemStack the item stack
* @param level the world
* @param block the block to break
* @param pos the position of the current block
* @param player the current player
* @return number of affected blocks
*/
private int handleRangeableTools(ToolRangeable tool, ItemStack itemStack, Level level, Block currentBlock,
BlockPos pos, Player player) {
List<Block> validBlocks = tool.getBlockList(currentBlock);
HarvestRange range = tool.getRange(itemStack);
if (tool instanceof Item) {
Item toolItem = (Item) tool; // a rangeable tool should always be an item
List<String> visitedBlocks = new ArrayList<>();
if (QuicklyItems.TOOL_SPEEDPOWDERAXE.getName().equals(toolItem.getName())) {
return breakBlockRecursive(visitedBlocks, level, validBlocks, pos, tool, range, BlockBreakDirection.UPWARDS,
player, true);
} else if (QuicklyItems.TOOL_SPEEDPOWDERPICKAXE.getName().equals(toolItem.getName())) {
return breakBlockRecursive(visitedBlocks, level, validBlocks, pos, tool, range, BlockBreakDirection.ALL,
player, false);
} else if (QuicklyItems.TOOL_SPEEDPOWDERSHOVEL.getName().equals(toolItem.getName())) {
return breakBlockRecursive(visitedBlocks, level, validBlocks, pos, tool, range, BlockBreakDirection.ALL,
player, false);
} else if (QuicklyItems.TOOL_SPEEDPOWDERHOE.getName().equals(toolItem.getName())) {
return breakBlockRecursive(visitedBlocks, level, validBlocks, pos, tool, range, BlockBreakDirection.ALL,
player, false);
} else if (QuicklyItems.TOOL_QUICKIEPOWDERAXE.getName().equals(toolItem.getName())) {
return breakBlockRecursive(visitedBlocks, level, validBlocks, pos, tool, range, BlockBreakDirection.UPWARDS,
player, true);
} else if (QuicklyItems.TOOL_QUICKIEPOWDERPICKAXE.getName().equals(toolItem.getName())) {
return breakBlockRecursive(visitedBlocks, level, validBlocks, pos, tool, range, BlockBreakDirection.ALL,
player, false);
} else if (QuicklyItems.TOOL_QUICKIEPOWDERSHOVEL.getName().equals(toolItem.getName())) {
return breakBlockRecursive(visitedBlocks, level, validBlocks, pos, tool, range, BlockBreakDirection.ALL,
player, false);
} else if (QuicklyItems.TOOL_QUICKIEPOWDERHOE.getName().equals(toolItem.getName())) {
return breakBlockRecursive(visitedBlocks, level, validBlocks, pos, tool, range, BlockBreakDirection.ALL,
player, false);
} else {
return 0;
}
} else {
Quickly.LOGGER.warn("using a tool that is not an item - no rangeable operations are possible.");
return 0;
}
}
/**
* break block recursively;
*
* @param visitedBlocks the positions of visited blocks
* @param level the world
* @param validBlocks the blocks to break
* @param tool the tool used
* @param range the range left over
* @param pos the position
* @param blockBreakDirection the direction for the recursive call
* @param player the player
* @return number of affected blocks
*/
private int breakBlockRecursive(List<String> visitedBlocks, Level level, List<Block> validBlocks, BlockPos pos,
ToolRangeable tool, HarvestRange range, BlockBreakDirection blockBreakDirection, Player player,
boolean breakLeaves) {
// boolean ignoreSpawn = visitedBlocks.size() < 1; // with this, the already broken block can be omitted to spawn
if (visitedBlocks.contains(pos.toString())) {
return 0;
} else if (validBlocks == null) {
return 0;
} else {
visitedBlocks.add(pos.toString());
}
Integer affected = 0;
BlockState blockState = level.getBlockState(pos);
if (tool.canBreakNeighbors(blockState)) {
Block currentBlock = blockState.getBlock();
if (validBlocks.contains(currentBlock)) {
// if (!ignoreSpawn) {
Block.dropResources(blockState, level, pos); // includes xorbs
// }
affected += 1;
level.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
if (range == null || range.getxRange() > 1 || range.getyRange() > 1 || range.getzRange() > 1) {
HarvestRange nextRadius = range == null ? null : range.addXYZ(-1);
affected += breakBlockRecursive(visitedBlocks, level, validBlocks, pos.north(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, level, validBlocks, pos.north().east(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, level, validBlocks, pos.north().west(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, level, validBlocks, pos.south(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, level, validBlocks, pos.south().east(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, level, validBlocks, pos.south().west(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, level, validBlocks, pos.east(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, level, validBlocks, pos.west(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, level, validBlocks, pos.above(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, level, validBlocks, pos.above().north(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, level, validBlocks, pos.above().north().east(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, level, validBlocks, pos.above().north().west(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, level, validBlocks, pos.above().east(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, level, validBlocks, pos.above().west(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, level, validBlocks, pos.above().south().east(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, level, validBlocks, pos.above().south().west(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, level, validBlocks, pos.above().south(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
if (BlockBreakDirection.ALL.equals(blockBreakDirection)) {
affected += breakBlockRecursive(visitedBlocks, level, validBlocks, pos.below(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, level, validBlocks, pos.below().north(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, level, validBlocks, pos.below().south(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, level, validBlocks, pos.below().east(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, level, validBlocks, pos.below().west(), tool, nextRadius,
blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, level, validBlocks, pos.below().north().east(), tool,
nextRadius, blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, level, validBlocks, pos.below().north().west(), tool,
nextRadius, blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, level, validBlocks, pos.below().south().east(), tool,
nextRadius, blockBreakDirection, player, breakLeaves);
affected += breakBlockRecursive(visitedBlocks, level, validBlocks, pos.below().south().west(), tool,
nextRadius, blockBreakDirection, player, breakLeaves);
}
}
}
}
return affected;
}
}

View File

@@ -0,0 +1,20 @@
package de.jottyfan.minecraft.event;
import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents;
/**
*
* @author jotty
*
*/
public class QuicklyEvents {
public static final void registerBlockBreak() {
PlayerBlockBreakEvents.BEFORE.register((world, player, pos, state, blockEntity) -> {
if (new EventBlockBreak().doBreakBlock(world, pos, state, player, state.getBlock())) {
return false;
} else {
return true;
}
});
}
}

View File

@@ -0,0 +1,110 @@
package de.jottyfan.minecraft.item;
import java.io.Serializable;
/**
*
* @author jotty
*
*/
public class HarvestRange implements Serializable {
private static final long serialVersionUID = 1L;
private int xRange;
private int yRange;
private int zRange;
public HarvestRange(int xyzRange) {
super();
this.xRange = xyzRange;
this.yRange = xyzRange;
this.zRange = xyzRange;
}
public HarvestRange(int[] xyzRange) {
super();
this.xRange = xyzRange[0];
this.yRange = xyzRange[1];
this.zRange = xyzRange[2];
}
public HarvestRange(int xRange, int yRange, int zRange) {
super();
this.xRange = xRange;
this.yRange = yRange;
this.zRange = zRange;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append(xRange).append(":");
buf.append(yRange).append(":");
buf.append(zRange).append(":");
return buf.toString();
}
/**
* add i to x, y and z and return the resulting class as a new one
*
* @param i
* the summand
* @return the new class
*/
public HarvestRange addXYZ(int i) {
return new HarvestRange(xRange + i, yRange + i, zRange + i);
}
/**
* get range as int array
*
* @return the int array
*/
public int[] getRangeAsArray() {
return new int[] {xRange, yRange, zRange};
}
/**
* @return the xRange
*/
public int getxRange() {
return xRange;
}
/**
* @param xRange
* the xRange to set
*/
public void setxRange(int xRange) {
this.xRange = xRange;
}
/**
* @return the yRange
*/
public int getyRange() {
return yRange;
}
/**
* @param yRange
* the yRange to set
*/
public void setyRange(int yRange) {
this.yRange = yRange;
}
/**
* @return the zRange
*/
public int getzRange() {
return zRange;
}
/**
* @param zRange
* the zRange to set
*/
public void setzRange(int zRange) {
this.zRange = zRange;
}
}

View File

@@ -48,7 +48,33 @@ public class QuicklyItems {
public static final Item SULFOR = registerItem("sulfor");
public static final Item CARROTSTACK = registerItem("carrotstack");
// TODO: tools
// TODO: normalize classes and try to summarize tools (such as ToolShovel for both speed and quickie)
// TODO: rename tools to speedaxe and quickaxe instead of the powder version
public static final Item TOOL_SPEEDPOWDERAXE = registerItem("speedpowderaxe",
properties -> new ToolSpeedpowderAxe(properties));
public static final Item TOOL_SPEEDPOWDERHOE = registerItem("speedpowderhoe",
properties -> new ToolSpeedpowderHoe(properties));
public static final Item TOOL_SPEEDPOWDERPICKAXE = registerItem("speedpowderpickaxe",
properties -> new ToolSpeedpowderPickaxe(properties));
public static final Item TOOL_SPEEDPOWDERSHEARS = registerItem("speedpowdershears",
properties -> new ToolSpeedpowderShears(properties));
public static final Item TOOL_SPEEDPOWDERSHOVEL = registerItem("speedpowdershovel",
properties -> new ToolSpeedpowderShovel(properties));
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 ToolQuickiepowderAxe(properties));
public static final Item TOOL_QUICKIEPOWDERHOE = registerItem("quickiepowderhoe",
properties -> new ToolQuickiepowderHoe(properties));
public static final Item TOOL_QUICKIEPOWDERPICKAXE = registerItem("quickiepowderpickaxe",
properties -> new ToolQuickiepowderPickaxe(properties));
public static final Item TOOL_QUICKIEPOWDERSHOVEL = registerItem("quickiepowdershovel",
properties -> new ToolQuickiepowderShovel(properties));
public static final Item TOOL_QUICKIEPOWDERWATERHOE = registerItem("quickiepowderwaterhoe",
properties -> new ToolQuickiepowderWaterHoe(properties, QuicklyItems.TOOL_QUICKIEPOWDERHOE));
public static final Item TOOL_QUICKIEPOWDERSHEARS = registerItem("quickiepowdershears",
properties -> new ToolSpeedpowderShears(properties));
public static final Item ARMOR_TURQUOISE_BOOTS = registerItem("turquoise_boots", ArmorType.BOOTS);
public static final Item ARMOR_TURQUOISE_HELMET = registerItem("turquoise_helmet", ArmorType.HELMET);
@@ -108,6 +134,18 @@ public class QuicklyItems {
item.accept(ARMOR_TURQUOISE_CHESTPLATE);
item.accept(ARMOR_TURQUOISE_LEGGINGS);
item.accept(ARMOR_TURQUOISE_BOOTS);
item.accept(TOOL_QUICKIEPOWDERPICKAXE);
item.accept(TOOL_QUICKIEPOWDERAXE);
item.accept(TOOL_QUICKIEPOWDERSHOVEL);
item.accept(TOOL_QUICKIEPOWDERSHEARS);
item.accept(TOOL_QUICKIEPOWDERHOE);
item.accept(TOOL_QUICKIEPOWDERWATERHOE);
item.accept(TOOL_SPEEDPOWDERPICKAXE);
item.accept(TOOL_SPEEDPOWDERAXE);
item.accept(TOOL_SPEEDPOWDERSHOVEL);
item.accept(TOOL_SPEEDPOWDERSHEARS);
item.accept(TOOL_SPEEDPOWDERHOE);
item.accept(TOOL_SPEEDPOWDERWATERHOE);
});
}
}

View File

@@ -0,0 +1,26 @@
package de.jottyfan.minecraft.item;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ToolMaterial;
/**
*
* @author jotty
*
*/
public class ToolQuickiepowderAxe extends ToolRangeableAxe {
private final static ToolMaterial MATERIAL = new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, 2400, 7f, 1f, 15, ItemTags.DIAMOND_TOOL_MATERIALS);
public ToolQuickiepowderAxe(Properties properties) {
super(MATERIAL, 7F, -3.1F, properties);
}
@Override
public HarvestRange getRange(ItemStack stack) {
// TODO: get the range from the stack
return new HarvestRange(64, 128, 64); // trees bigger than that are too heavy for one small axe...
}
}

View File

@@ -0,0 +1,20 @@
package de.jottyfan.minecraft.item;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.item.ToolMaterial;
/**
*
* @author jotty
*
*/
public class ToolQuickiepowderHoe extends ToolRangeableHoe {
public static final Integer DEFAULT_PLOW_RANGE = 4;
private final static ToolMaterial MATERIAL = new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, 2400, 7f, 1f, 15, ItemTags.DIAMOND_TOOL_MATERIALS);
public ToolQuickiepowderHoe(Properties properties) {
super(MATERIAL, 7F, -3.1f, properties, new HarvestRange(DEFAULT_PLOW_RANGE));
}
}

View File

@@ -0,0 +1,55 @@
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

@@ -0,0 +1,100 @@
package de.jottyfan.minecraft.item;
import java.util.Random;
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.animal.chicken.Chicken;
import net.minecraft.world.entity.animal.cow.Cow;
import net.minecraft.world.entity.animal.equine.Horse;
import net.minecraft.world.entity.animal.sheep.Sheep;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.ShearsItem;
import net.minecraft.world.phys.Vec3;
/**
*
* @author jotty
*
*/
public class ToolQuickiepowderShears extends ShearsItem {
public ToolQuickiepowderShears(Properties properties) {
super(properties.component(DataComponents.TOOL, ShearsItem.createToolProperties()));
}
@Override
public InteractionResult interactLivingEntity(ItemStack stack, Player user, LivingEntity entity,
InteractionHand hand) {
Vec3 pos = entity.position();
Integer amount = 3 + new Random().nextInt(4);
if (entity instanceof Sheep sheep) {
if (!sheep.isSheared()) {
sheep.setSheared(true);
sheep.playAmbientSound();
DyeColor color = sheep.getColor();
Item item = Items.WHITE_WOOL;
if (color.equals(DyeColor.BLACK)) {
item = Items.BLACK_WOOL;
} else if (color.equals(DyeColor.GRAY)) {
item = Items.GRAY_WOOL;
} else if (color.equals(DyeColor.LIGHT_GRAY)) {
item = Items.LIGHT_GRAY_WOOL;
} else if (color.equals(DyeColor.BROWN)) {
item = Items.BROWN_WOOL;
} else if (color.equals(DyeColor.BLUE)) {
item = Items.BLUE_WOOL;
} else if (color.equals(DyeColor.LIGHT_BLUE)) {
item = Items.LIGHT_BLUE_WOOL;
} else if (color.equals(DyeColor.GREEN)) {
item = Items.GREEN_WOOL;
} else if (color.equals(DyeColor.LIME)) {
item = Items.LIME_WOOL;
} else if (color.equals(DyeColor.CYAN)) {
item = Items.CYAN_WOOL;
} else if (color.equals(DyeColor.MAGENTA)) {
item = Items.MAGENTA_WOOL;
} else if (color.equals(DyeColor.ORANGE)) {
item = Items.ORANGE_WOOL;
} else if (color.equals(DyeColor.PINK)) {
item = Items.PINK_WOOL;
} else if (color.equals(DyeColor.PURPLE)) {
item = Items.PURPLE_WOOL;
} else if (color.equals(DyeColor.RED)) {
item = Items.RED_WOOL;
} else if (color.equals(DyeColor.YELLOW)) {
item = Items.YELLOW_WOOL;
}
user.level().addFreshEntity(new ItemEntity(user.level(), pos.x, pos.y, pos.z, new ItemStack(item, amount)));
return InteractionResult.SUCCESS;
}
} else if (entity instanceof Horse horse) {
horse.playAmbientSound();
horse.setBaby(true);
user.level()
.addFreshEntity(new ItemEntity(user.level(), pos.x, pos.y, pos.z, new ItemStack(Items.LEATHER, amount)));
return InteractionResult.SUCCESS;
} else if (entity instanceof Cow cow) {
cow.playAmbientSound();
cow.setBaby(true);
user.level()
.addFreshEntity(new ItemEntity(user.level(), pos.x, pos.y, pos.z, new ItemStack(Items.LEATHER, amount)));
return InteractionResult.SUCCESS;
} else if (entity instanceof Chicken chicken) {
chicken.playAmbientSound();
chicken.setBaby(true);
user.level()
.addFreshEntity(new ItemEntity(user.level(), pos.x, pos.y, pos.z, new ItemStack(Items.FEATHER, amount)));
return InteractionResult.SUCCESS;
}
return InteractionResult.PASS;
}
}

View File

@@ -0,0 +1,97 @@
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

@@ -0,0 +1,47 @@
package de.jottyfan.minecraft.item;
import net.minecraft.core.BlockPos;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
/**
*
* @author jotty
*
*/
public class ToolQuickiepowderWaterHoe extends ToolQuickiepowderHoe {
private Item fallbackHoe;
public ToolQuickiepowderWaterHoe(Properties properties, Item fallbackHoe) {
super(properties);
this.fallbackHoe = fallbackHoe;
}
@Override
public InteractionResult useOn(UseOnContext context) {
InteractionResult res = super.useOn(context);
if (!InteractionResult.PASS.equals(res)) {
BlockPos pos = context.getClickedPos();
Level level = context.getLevel();
BlockState oldBlockState = level.getBlockState(pos);
level.setBlockAndUpdate(pos, Blocks.WATER.defaultBlockState());
InteractionHand hand = context.getHand();
Player player = context.getPlayer();
ItemStack oldTool = player.getItemInHand(hand);
ItemStack newTool = new ItemStack(fallbackHoe);
newTool.setDamageValue(oldTool.getDamageValue());
level.addFreshEntity(
new ItemEntity(level, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(oldBlockState.getBlock())));
player.setItemInHand(hand, newTool);
}
return res;
}
}

View File

@@ -0,0 +1,39 @@
package de.jottyfan.minecraft.item;
import java.util.List;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
/**
*
* @author jotty
*
*/
public interface ToolRangeable {
/**
* @param stack the item stack that keeps the range
* @return range of blocks to be harvested
*/
public HarvestRange getRange(ItemStack stack);
/**
* check if this block state is one that affects the neighbor blocks to break
* also if they are from the same type
*
* @param blockState the block state of the current block
* @return true or false
*/
public boolean canBreakNeighbors(BlockState blockState);
/**
* get list of blocks that belong together (could be useful for stripped logs)
*
* @param block of the set
* @return the list of blocks or null if not found
*/
public List<Block> getBlockList(Block block);
}

View File

@@ -0,0 +1,63 @@
package de.jottyfan.minecraft.item;
import java.util.List;
import com.google.common.collect.Lists;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.item.AxeItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ToolMaterial;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.LeavesBlock;
import net.minecraft.world.level.block.state.BlockState;
/**
*
* @author jotty
*
*/
public abstract class ToolRangeableAxe extends AxeItem implements ToolRangeable {
protected ToolRangeableAxe(ToolMaterial material, float attackDamage, float attackSpeed, Properties properties) {
super(material, attackDamage, attackSpeed, properties);
}
@Override
public HarvestRange getRange(ItemStack stack) {
// TODO: get the range from the stack
return new HarvestRange(16, 32, 16);
}
/**
* check if the block is a leaves block
*
* @param blockIn the block
* @return true or false
*/
private boolean isLeavesBlock(BlockState blockIn) {
boolean vanillaLeaves = blockIn.getBlock() instanceof LeavesBlock;
boolean terrestriaLeaves = false;
try {
Class<?> extendedLeavesBlock = Class.forName("com.terraformersmc.terraform.leaves.block.ExtendedLeavesBlock");
terrestriaLeaves = extendedLeavesBlock.isInstance(blockIn.getBlock());
} catch (ClassNotFoundException e) {
// no terrestria mod available, so ignore this
// using this approach instead of the instanceof functionality, we don't need to refer to terrestria
// and omit a crash on installations that do not have or want terrestria available
}
boolean blockTagLeaves = blockIn.is(BlockTags.LEAVES);
return vanillaLeaves || terrestriaLeaves || blockTagLeaves;
}
@Override
public boolean canBreakNeighbors(BlockState blockIn) {
return new ItemStack((ItemLike) this).isCorrectToolForDrops(blockIn) || isLeavesBlock(blockIn) || blockIn.is(BlockTags.LOGS);
}
@Override
public List<Block> getBlockList(Block block) {
return Lists.newArrayList(block);
}
}

View File

@@ -0,0 +1,96 @@
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.world.InteractionResult;
import net.minecraft.world.item.HoeItem;
import net.minecraft.world.item.ItemStack;
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.CropBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
/**
*
* @author jotty
*
*/
public abstract class ToolRangeableHoe extends HoeItem implements ToolRangeable {
public HarvestRange range;
public ToolRangeableHoe(ToolMaterial material, float attackDamage, float attackSpeed, Properties properties, HarvestRange range) {
super(material, attackDamage, attackSpeed, properties);
this.range = range;
}
@Override
public InteractionResult useOn(UseOnContext context) {
InteractionResult res = super.useOn(context);
boolean isCrop = context.getLevel().getBlockState(context.getClickedPos()).getBlock() instanceof CropBlock;
if (!InteractionResult.PASS.equals(res) || isCrop) {
for (int x = -this.range.getxRange(); x <= this.range.getxRange(); x++) {
for (int y = -this.range.getyRange(); y <= this.range.getyRange(); y++) {
for (int z = -this.range.getzRange(); z <= this.range.getzRange(); z++) {
if (!isCrop) {
removePossibleGrass(context.getLevel(), new BlockPos(x, y, z));
BlockHitResult bhr = new BlockHitResult(context.getClickedPos().getCenter(), Direction.UP,
context.getClickedPos().offset(x, y, z), false);
UseOnContext ctx = new UseOnContext(context.getPlayer(), context.getHand(), bhr);
super.useOn(ctx);
} else {
harvestIfPossible(context.getClickedPos().offset(x, y, z), context.getLevel());
}
}
}
}
}
return res;
}
private void removePossibleGrass(Level level, BlockPos pos) {
Block block = level.getBlockState(pos).getBlock();
Boolean grassFound = Blocks.FERN.equals(block) || Blocks.LARGE_FERN.equals(block)
|| Blocks.SHORT_GRASS.equals(block) || Blocks.TALL_GRASS.equals(block);
if (grassFound) {
level.destroyBlock(pos, true);
}
}
private void harvestIfPossible(BlockPos pos, Level level) {
BlockState blockState = level.getBlockState(pos);
Block block = blockState.getBlock();
if (block instanceof CropBlock) {
CropBlock cBlock = (CropBlock) block;
if (cBlock.isMaxAge(blockState)) {
Block.dropResources(blockState, level, pos);
level.setBlockAndUpdate(pos, cBlock.defaultBlockState().setValue(CropBlock.AGE, 0));
}
}
}
@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) || Blocks.TALL_GRASS.equals(blockState.getBlock())
|| Blocks.FERN.equals(blockState.getBlock()) || Blocks.LARGE_FERN.equals(blockState.getBlock());
}
@Override
public List<Block> getBlockList(Block block) {
return Lists.newArrayList(block);
}
}

View File

@@ -0,0 +1,26 @@
package de.jottyfan.minecraft.item;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ToolMaterial;
/**
*
* @author jotty
*
*/
public class ToolSpeedpowderAxe extends ToolRangeableAxe {
private final static ToolMaterial MATERIAL = new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, 800, 7f, 1f, 15, ItemTags.DIAMOND_TOOL_MATERIALS);
public ToolSpeedpowderAxe(Properties properties) {
super(MATERIAL, 7f, -3.1f, properties);
}
@Override
public HarvestRange getRange(ItemStack stack) {
// TODO: get the range from the stack
return new HarvestRange(32, 64, 32);
}
}

View File

@@ -0,0 +1,20 @@
package de.jottyfan.minecraft.item;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.item.ToolMaterial;
/**
*
* @author jotty
*
*/
public class ToolSpeedpowderHoe extends ToolRangeableHoe {
public static final Integer DEFAULT_PLOW_RANGE = 2;
private final static ToolMaterial MATERIAL = new ToolMaterial(BlockTags.INCORRECT_FOR_DIAMOND_TOOL, 800, 7f, 1f, 15, ItemTags.DIAMOND_TOOL_MATERIALS);
public ToolSpeedpowderHoe(Properties properties) {
super(MATERIAL, 7F, -3.1F, properties, new HarvestRange(DEFAULT_PLOW_RANGE));
}
}

View File

@@ -0,0 +1,55 @@
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 ToolSpeedpowderPickaxe extends Item implements ToolRangeable {
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));
}
@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

@@ -0,0 +1,105 @@
package de.jottyfan.minecraft.item;
import java.util.Random;
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.animal.chicken.Chicken;
import net.minecraft.world.entity.animal.cow.Cow;
import net.minecraft.world.entity.animal.equine.Horse;
import net.minecraft.world.entity.animal.sheep.Sheep;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.ShearsItem;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.phys.Vec3;
/**
*
* @author jotty
*
*/
public class ToolSpeedpowderShears extends ShearsItem {
public ToolSpeedpowderShears(Properties properties) {
super(properties.component(DataComponents.TOOL, ShearsItem.createToolProperties()));
}
@Override
public InteractionResult useOn(UseOnContext context) {
return super.useOn(context);
}
@Override
public InteractionResult interactLivingEntity(ItemStack stack, Player user, LivingEntity entity,
InteractionHand hand) {
Vec3 pos = entity.position();
Integer amount = 1 + new Random().nextInt(4);
if (entity instanceof Sheep sheep) {
if (!sheep.isSheared()) {
sheep.setSheared(true);
sheep.playAmbientSound();
DyeColor color = sheep.getColor();
Item item = Items.WHITE_WOOL;
if (color.equals(DyeColor.BLACK)) {
item = Items.BLACK_WOOL;
} else if (color.equals(DyeColor.GRAY)) {
item = Items.GRAY_WOOL;
} else if (color.equals(DyeColor.LIGHT_GRAY)) {
item = Items.LIGHT_GRAY_WOOL;
} else if (color.equals(DyeColor.BROWN)) {
item = Items.BROWN_WOOL;
} else if (color.equals(DyeColor.BLUE)) {
item = Items.BLUE_WOOL;
} else if (color.equals(DyeColor.LIGHT_BLUE)) {
item = Items.LIGHT_BLUE_WOOL;
} else if (color.equals(DyeColor.GREEN)) {
item = Items.GREEN_WOOL;
} else if (color.equals(DyeColor.LIME)) {
item = Items.LIME_WOOL;
} else if (color.equals(DyeColor.CYAN)) {
item = Items.CYAN_WOOL;
} else if (color.equals(DyeColor.MAGENTA)) {
item = Items.MAGENTA_WOOL;
} else if (color.equals(DyeColor.ORANGE)) {
item = Items.ORANGE_WOOL;
} else if (color.equals(DyeColor.PINK)) {
item = Items.PINK_WOOL;
} else if (color.equals(DyeColor.PURPLE)) {
item = Items.PURPLE_WOOL;
} else if (color.equals(DyeColor.RED)) {
item = Items.RED_WOOL;
} else if (color.equals(DyeColor.YELLOW)) {
item = Items.YELLOW_WOOL;
}
user.level().addFreshEntity(new ItemEntity(user.level(), pos.x, pos.y, pos.z, new ItemStack(item, amount)));
return InteractionResult.SUCCESS;
}
} else if (entity instanceof Horse horse) {
horse.playAmbientSound();
horse.setBaby(true);
user.level()
.addFreshEntity(new ItemEntity(user.level(), pos.x, pos.y, pos.z, new ItemStack(Items.LEATHER, amount)));
return InteractionResult.SUCCESS;
} else if (entity instanceof Cow cow) {
cow.playAmbientSound();
cow.setBaby(true);
user.level()
.addFreshEntity(new ItemEntity(user.level(), pos.x, pos.y, pos.z, new ItemStack(Items.LEATHER, amount)));
return InteractionResult.SUCCESS;
} else if (entity instanceof Chicken chicken) {
chicken.playAmbientSound();
chicken.setBaby(true);
user.level()
.addFreshEntity(new ItemEntity(user.level(), pos.x, pos.y, pos.z, new ItemStack(Items.FEATHER, amount)));
return InteractionResult.SUCCESS;
}
return InteractionResult.PASS;
}
}

View File

@@ -0,0 +1,96 @@
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 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 ToolSpeedpowderShovel(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();
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);
}
@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

@@ -0,0 +1,47 @@
package de.jottyfan.minecraft.item;
import net.minecraft.core.BlockPos;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
/**
*
* @author jotty
*
*/
public class ToolSpeedpowderWaterHoe extends ToolSpeedpowderHoe {
private Item fallbackHoe;
public ToolSpeedpowderWaterHoe(Properties properties, Item fallbackHoe) {
super(properties);
this.fallbackHoe = fallbackHoe;
}
@Override
public InteractionResult useOn(UseOnContext context) {
InteractionResult res = super.useOn(context);
if (!InteractionResult.PASS.equals(res)) {
BlockPos pos = context.getClickedPos();
Level level = context.getLevel();
BlockState oldBlockState = level.getBlockState(pos);
level.setBlockAndUpdate(pos, Blocks.WATER.defaultBlockState());
InteractionHand hand = context.getHand();
Player player = context.getPlayer();
ItemStack oldTool = player.getItemInHand(hand);
ItemStack newTool = new ItemStack(fallbackHoe);
newTool.setDamageValue(oldTool.getDamageValue());
level.addFreshEntity(
new ItemEntity(level, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(oldBlockState.getBlock())));
player.setItemInHand(hand, newTool);
}
return res;
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "quickly:item/quickiepowderaxe"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "quickly:item/quickiepowderhoe"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "quickly:item/quickiepowderpickaxe"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "quickly:item/quickiepowdershears"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "quickly:item/quickiepowdershovel"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "quickly:item/quickiepowderwaterhoe"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "quickly:item/speedpowderaxe"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "quickly:item/speedpowderhoe"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "quickly:item/speedpowderpickaxe"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "quickly:item/speedpowdershears"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "quickly:item/speedpowdershovel"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "quickly:item/speedpowderwaterhoe"
}
}

View File

@@ -1,4 +1,17 @@
{
"item.quickly.speedpowderaxe": "Fluchtpulveraxt",
"item.quickly.speedpowderpickaxe": "Fluchtpulverspitzhacke",
"item.quickly.speedpowdershovel": "Fluchtpulverschaufel",
"item.quickly.speedpowderhoe": "Fluchtpulverfeldhacke",
"item.quickly.speedpowderwaterhoe": "bewässerte Fluchtpulverfeldhacke",
"item.quickly.speedpowdershears": "Fluchtpulverschere",
"item.quickly.quickiepowderaxe": "Eilpulveraxt",
"item.quickly.quickiepowderpickaxe": "Eilpulverspitzhacke",
"item.quickly.quickiepowdershovel": "Eilpulverschaufel",
"item.quickly.quickiepowderhoe": "Eilpulverfeldhacke",
"item.quickly.quickiepowderwaterhoe": "bewässerte Eilpulverfeldhacke",
"item.quickly.quickiepowdershears": "Eilpulverschere",
"info.block.drillfuel": "Ladung: %s Bohrungen",
"info.block.itemhoarder": "enthält: %s",
"info.block.monsterhoarder": "Radius: %s, Brenndauer: %s Ticks",

View File

@@ -1,4 +1,17 @@
{
"item.quickly.speedpowderaxe": "speedpowder axe",
"item.quickly.speedpowderpickaxe": "speedpowder pickaxe",
"item.quickly.speedpowdershovel": "speedpowder shovel",
"item.quickly.speedpowderhoe": "speedpowder hoe",
"item.quickly.speedpowderwaterhoe": "watered speedpowder hoe",
"item.quickly.speedpowdershears": "speedpowder shears",
"item.quickly.quickiepowderaxe": "hurrypowder axe",
"item.quickly.quickiepowderpickaxe": "hurrypowder pickaxe",
"item.quickly.quickiepowdershovel": "hurrypowder shovel",
"item.quickly.quickiepowderhoe": "hurrypowder hoe",
"item.quickly.quickiepowderwaterhoe": "watered hurrypowder hoe",
"item.quickly.quickiepowdershears": "hurrypowder shears",
"info.block.drillfuel": "Load: %s drills",
"info.block.itemhoarder": "contains: %s",
"info.block.monsterhoarder": "radius: %s, burn ticks: %s",

View File

@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "quickly:item/quickiepowderaxe"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "quickly:item/quickiepowderhoe"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "quickly:item/quickiepowderpickaxe"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "quickly:item/quickiepowdershears"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "quickly:item/quickiepowdershovel"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "quickly:item/quickiepowderwaterhoe"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "quickly:item/speedpowderaxe"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "quickly:item/speedpowderhoe"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "quickly:item/speedpowderpickaxe"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "quickly:item/speedpowdershears"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "quickly:item/speedpowdershovel"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "quickly:item/speedpowderwaterhoe"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

View File

@@ -0,0 +1,7 @@
{
"replace": false,
"values": [
"quickly:speedpowderaxe",
"quickly:quickiepowderaxe"
]
}

View File

@@ -0,0 +1,9 @@
{
"replace": false,
"values": [
"quickly:speedpowderhoe",
"quickly:speedpowderwaterhoe",
"quickly:quickiepowderhoe",
"quickly:quickiepowderwaterhoe"
]
}

View File

@@ -0,0 +1,7 @@
{
"replace": false,
"values": [
"quickly:speedpowderpickaxe",
"quickly:quickiepowderpickaxe"
]
}

View File

@@ -0,0 +1,7 @@
{
"replace": false,
"values": [
"quickly:speedpowdershovel",
"quickly:quickiepowdershovel"
]
}

View File

@@ -0,0 +1,14 @@
{
"type": "minecraft:crafting_shaped",
"category": "tools",
"pattern": [
" #",
"# "
],
"key": {
"#": "quickly:quickieingot"
},
"result": {
"id": "quickly:quickiepowdershears"
}
}

View File

@@ -0,0 +1,17 @@
{
"type": "minecraft:crafting_shaped",
"category": "tools",
"pattern": [
"ss",
"s|",
" |"
],
"key": {
"s": "quickly:quickieingot",
"|": "quickly:copperstick"
},
"result": {
"id": "quickly:quickiepowderaxe",
"count": 1
}
}

View File

@@ -0,0 +1,17 @@
{
"type": "minecraft:crafting_shaped",
"category": "tools",
"pattern": [
"ss",
" |",
" |"
],
"key": {
"s": "quickly:quickieingot",
"|": "quickly:copperstick"
},
"result": {
"id": "quickly:quickiepowderhoe",
"count": 1
}
}

View File

@@ -0,0 +1,17 @@
{
"type": "minecraft:crafting_shaped",
"category": "tools",
"pattern": [
"sss",
" | ",
" | "
],
"key": {
"s": "quickly:quickieingot",
"|": "quickly:copperstick"
},
"result": {
"id": "quickly:quickiepowderpickaxe",
"count": 1
}
}

View File

@@ -0,0 +1,17 @@
{
"type": "minecraft:crafting_shaped",
"category": "tools",
"pattern": [
"s",
"|",
"|"
],
"key": {
"s": "quickly:quickieingot",
"|": "quickly:copperstick"
},
"result": {
"id": "quickly:quickiepowdershovel",
"count": 1
}
}

View File

@@ -0,0 +1,14 @@
{
"type": "minecraft:crafting_shaped",
"category": "tools",
"pattern": [
" #",
"# "
],
"key": {
"#": "quickly:speedingot"
},
"result": {
"id": "quickly:speedpowdershears"
}
}

View File

@@ -0,0 +1,17 @@
{
"type": "minecraft:crafting_shaped",
"category": "tools",
"pattern": [
"ss",
"s|",
" |"
],
"key": {
"s": "quickly:speedingot",
"|": "minecraft:stick"
},
"result": {
"id": "quickly:speedpowderaxe",
"count": 1
}
}

View File

@@ -0,0 +1,17 @@
{
"type": "minecraft:crafting_shaped",
"category": "tools",
"pattern": [
"ss",
" |",
" |"
],
"key": {
"s": "quickly:speedingot",
"|": "minecraft:stick"
},
"result": {
"id": "quickly:speedpowderhoe",
"count": 1
}
}

View File

@@ -0,0 +1,17 @@
{
"type": "minecraft:crafting_shaped",
"category": "tools",
"pattern": [
"sss",
" | ",
" | "
],
"key": {
"s": "quickly:speedingot",
"|": "minecraft:stick"
},
"result": {
"id": "quickly:speedpowderpickaxe",
"count": 1
}
}

View File

@@ -0,0 +1,17 @@
{
"type": "minecraft:crafting_shaped",
"category": "tools",
"pattern": [
"s",
"|",
"|"
],
"key": {
"s": "quickly:speedingot",
"|": "minecraft:stick"
},
"result": {
"id": "quickly:speedpowdershovel",
"count": 1
}
}

View File

@@ -0,0 +1,11 @@
{
"type": "minecraft:crafting_shapeless",
"ingredients": [
"minecraft:water_bucket",
"quickly:quickiepowderhoe"
],
"result": {
"id": "quickly:quickiepowderwaterhoe",
"count": 1
}
}

View File

@@ -0,0 +1,11 @@
{
"type": "minecraft:crafting_shapeless",
"ingredients": [
"minecraft:water_bucket",
"quickly:speedpowderhoe"
],
"result": {
"id": "quickly:speedpowderwaterhoe",
"count": 1
}
}