fixed recipes, working tools
@ -21,6 +21,7 @@ public class QuickieMod implements ModInitializer {
|
||||
LOGGER.info("loading {}", MODID);
|
||||
RegistryManager.registerBlockEntityTypes();
|
||||
RegistryManager.registerItems();
|
||||
RegistryManager.registerEvents();
|
||||
RegistryManager.registerBlocks();
|
||||
RegistryManager.registerFeatures();
|
||||
RegistryManager.registerItemGroup();
|
||||
|
84
src/main/java/de/jottyfan/quickiemod/api/Neighborhood.java
Normal file
@ -0,0 +1,84 @@
|
||||
package de.jottyfan.quickiemod.api;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class Neighborhood {
|
||||
|
||||
/**
|
||||
* find the same blocks that is next to the current position pos
|
||||
*
|
||||
* @param world the world to look for the blocks
|
||||
* @param pos the starting position
|
||||
* @param seekLimit the limit of seek operations
|
||||
* @param checkLambda check functionality
|
||||
* @return a set of found block positions
|
||||
*/
|
||||
public static final Set<BlockPos> findEqualBlock(World world, BlockPos pos, int seekLimit,
|
||||
BiFunction<World, BlockPos, Boolean> checkLambda) {
|
||||
Set<NeighborhoodBean> found = new HashSet<>();
|
||||
found.add(new NeighborhoodBean(pos, true));
|
||||
|
||||
while (pos != null && found.size() < seekLimit) {
|
||||
findNewNeihgbor(world, pos.east(), found, checkLambda);
|
||||
findNewNeihgbor(world, pos.south(), found, checkLambda);
|
||||
findNewNeihgbor(world, pos.west(), found, checkLambda);
|
||||
findNewNeihgbor(world, pos.north(), found, checkLambda);
|
||||
pos = findNextUncheckedField(found);
|
||||
}
|
||||
|
||||
Set<BlockPos> finals = new HashSet<>();
|
||||
for (NeighborhoodBean bean : found) {
|
||||
finals.add(bean.getPos());
|
||||
}
|
||||
return finals;
|
||||
}
|
||||
|
||||
private static final BlockPos findNextUncheckedField(Set<NeighborhoodBean> found) {
|
||||
Iterator<NeighborhoodBean> i = found.iterator();
|
||||
while (i.hasNext()) {
|
||||
NeighborhoodBean bean = i.next();
|
||||
if (!bean.isChecked()) {
|
||||
bean.setChecked(true);
|
||||
return bean.getPos();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* find new neighbor at pos
|
||||
*
|
||||
* @param world the world
|
||||
* @param pos the position
|
||||
* @param found the set with all already found positions
|
||||
* @return true or false
|
||||
*/
|
||||
private static final boolean findNewNeihgbor(World world, BlockPos pos, Set<NeighborhoodBean> found,
|
||||
BiFunction<World, BlockPos, Boolean> checkLambda) {
|
||||
NeighborhoodBean bean = new NeighborhoodBean(pos);
|
||||
if (found.contains(bean) || found.contains(bean.over()) || found.contains(bean.below())) {
|
||||
return false;
|
||||
} else if (checkLambda.apply(world, pos).booleanValue()) {
|
||||
found.add(bean);
|
||||
return true;
|
||||
} else if (checkLambda.apply(world, pos.up()).booleanValue()) {
|
||||
found.add(new NeighborhoodBean(pos.up()));
|
||||
return true;
|
||||
} else if (checkLambda.apply(world, pos.down()).booleanValue()) {
|
||||
found.add(new NeighborhoodBean(pos.down()));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package de.jottyfan.quickiemod.api;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class NeighborhoodBean {
|
||||
private final BlockPos pos;
|
||||
private boolean checked;
|
||||
|
||||
public NeighborhoodBean(BlockPos pos, boolean checked) {
|
||||
super();
|
||||
this.pos = pos;
|
||||
this.checked = checked;
|
||||
}
|
||||
|
||||
public NeighborhoodBean(BlockPos pos) {
|
||||
super();
|
||||
this.pos = pos;
|
||||
this.checked = false;
|
||||
}
|
||||
|
||||
public NeighborhoodBean over() {
|
||||
return new NeighborhoodBean(pos.up(), checked);
|
||||
}
|
||||
|
||||
public NeighborhoodBean below() {
|
||||
return new NeighborhoodBean(pos.down(), checked);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
Boolean result = null;
|
||||
if (this == obj) {
|
||||
result = true;
|
||||
} else if (obj == null) {
|
||||
result = false;
|
||||
} else if (getClass() != obj.getClass()) {
|
||||
result = false;
|
||||
} else {
|
||||
NeighborhoodBean other = (NeighborhoodBean) obj;
|
||||
result = Objects.equals(pos, other.pos);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the checked
|
||||
*/
|
||||
public boolean isChecked() {
|
||||
return checked;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param checked the checked to set
|
||||
*/
|
||||
public void setChecked(boolean checked) {
|
||||
this.checked = checked;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the pos
|
||||
*/
|
||||
public BlockPos getPos() {
|
||||
return pos;
|
||||
}
|
||||
}
|
@ -5,11 +5,11 @@ import java.util.List;
|
||||
|
||||
import de.jottyfan.quickiemod.blocks.help.IntProviderHelper;
|
||||
import de.jottyfan.quickiemod.items.QuickieItems;
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.ExperienceDroppingBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.loot.context.LootContextParameterSet.Builder;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
|
||||
|
||||
/**
|
||||
@ -20,7 +20,7 @@ import net.minecraft.loot.context.LootContextParameterSet.Builder;
|
||||
public class BlockOreDeepslateSulphor extends ExperienceDroppingBlock {
|
||||
|
||||
public BlockOreDeepslateSulphor() {
|
||||
super(IntProviderHelper.of(0, 2), AbstractBlock.Settings.create().hardness(1.9f).requiresTool());
|
||||
super(IntProviderHelper.of(0, 2), Settings.create().strength(2.5f).hardness(1.9f).sounds(BlockSoundGroup.SOUL_SAND).requiresTool());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,11 +5,11 @@ import java.util.List;
|
||||
|
||||
import de.jottyfan.quickiemod.blocks.help.IntProviderHelper;
|
||||
import de.jottyfan.quickiemod.items.QuickieItems;
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.ExperienceDroppingBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.loot.context.LootContextParameterSet.Builder;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -19,7 +19,7 @@ import net.minecraft.loot.context.LootContextParameterSet.Builder;
|
||||
public class BlockOreNetherSulphor extends ExperienceDroppingBlock {
|
||||
|
||||
public BlockOreNetherSulphor() {
|
||||
super(IntProviderHelper.of(0, 2), AbstractBlock.Settings.create().hardness(2.1f).requiresTool());
|
||||
super(IntProviderHelper.of(0, 2), Settings.create().strength(2.5f).hardness(2.1f).sounds(BlockSoundGroup.SOUL_SAND).requiresTool());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,11 +5,11 @@ import java.util.List;
|
||||
|
||||
import de.jottyfan.quickiemod.blocks.help.IntProviderHelper;
|
||||
import de.jottyfan.quickiemod.items.QuickieItems;
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.ExperienceDroppingBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.loot.context.LootContextParameterSet.Builder;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
import net.minecraft.util.math.random.Random;
|
||||
|
||||
/**
|
||||
@ -20,7 +20,7 @@ import net.minecraft.util.math.random.Random;
|
||||
public class BlockOreSalpeter extends ExperienceDroppingBlock {
|
||||
|
||||
public BlockOreSalpeter() {
|
||||
super(IntProviderHelper.of(0, 2), AbstractBlock.Settings.create().hardness(3.1f).requiresTool());
|
||||
super(IntProviderHelper.of(0, 2), Settings.create().strength(2.5f).hardness(3.1f).sounds(BlockSoundGroup.SOUL_SAND).requiresTool());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,12 +5,12 @@ import java.util.List;
|
||||
|
||||
import de.jottyfan.quickiemod.blocks.help.IntProviderHelper;
|
||||
import de.jottyfan.quickiemod.items.QuickieItems;
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.ExperienceDroppingBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.loot.context.LootContextParameterSet.Builder;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
import net.minecraft.util.math.random.Random;
|
||||
|
||||
/**
|
||||
@ -21,7 +21,7 @@ import net.minecraft.util.math.random.Random;
|
||||
public class BlockOreSandSalpeter extends ExperienceDroppingBlock {
|
||||
|
||||
public BlockOreSandSalpeter() {
|
||||
super(IntProviderHelper.of(0, 2), AbstractBlock.Settings.create().hardness(2.9f).requiresTool());
|
||||
super(IntProviderHelper.of(0, 2), Settings.create().strength(2.5f).hardness(2.9f).sounds(BlockSoundGroup.SOUL_SAND).requiresTool());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,11 +5,11 @@ import java.util.List;
|
||||
|
||||
import de.jottyfan.quickiemod.blocks.help.IntProviderHelper;
|
||||
import de.jottyfan.quickiemod.items.QuickieItems;
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.ExperienceDroppingBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.loot.context.LootContextParameterSet.Builder;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
|
||||
|
||||
/**
|
||||
@ -20,7 +20,7 @@ import net.minecraft.loot.context.LootContextParameterSet.Builder;
|
||||
public class BlockOreSulphor extends ExperienceDroppingBlock {
|
||||
|
||||
public BlockOreSulphor() {
|
||||
super(IntProviderHelper.of(0, 2), AbstractBlock.Settings.create().hardness(1.9f).requiresTool());
|
||||
super(IntProviderHelper.of(0, 2), Settings.create().strength(2.5f).hardness(1.9f).sounds(BlockSoundGroup.SOUL_SAND).requiresTool());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,11 +5,11 @@ import java.util.List;
|
||||
|
||||
import de.jottyfan.quickiemod.blocks.help.IntProviderHelper;
|
||||
import de.jottyfan.quickiemod.items.QuickieItems;
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.ExperienceDroppingBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.loot.context.LootContextParameterSet.Builder;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -19,7 +19,7 @@ import net.minecraft.loot.context.LootContextParameterSet.Builder;
|
||||
public class BlockSalpeter extends ExperienceDroppingBlock {
|
||||
|
||||
public BlockSalpeter() {
|
||||
super(IntProviderHelper.of(0, 2), AbstractBlock.Settings.create().hardness(0.5f));
|
||||
super(IntProviderHelper.of(0, 2), Settings.create().strength(2.5f).hardness(0.5f).sounds(BlockSoundGroup.SOUL_SAND).requiresTool());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -6,12 +6,12 @@ import java.util.List;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
|
||||
import de.jottyfan.quickiemod.items.QuickieItems;
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.FallingBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.loot.context.LootContextParameterSet.Builder;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
import net.minecraft.util.math.random.Random;
|
||||
|
||||
/**
|
||||
@ -22,7 +22,7 @@ import net.minecraft.util.math.random.Random;
|
||||
public class BlockSandSalpeter extends FallingBlock {
|
||||
|
||||
public BlockSandSalpeter() {
|
||||
super(AbstractBlock.Settings.create().hardness(3.1f).requiresTool());
|
||||
super(Settings.create().strength(2.5f).hardness(3.1f).sounds(BlockSoundGroup.SOUL_SAND).requiresTool());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,11 +5,11 @@ import java.util.List;
|
||||
|
||||
import de.jottyfan.quickiemod.blocks.help.IntProviderHelper;
|
||||
import de.jottyfan.quickiemod.items.QuickieItems;
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.ExperienceDroppingBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.loot.context.LootContextParameterSet.Builder;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -19,7 +19,7 @@ import net.minecraft.loot.context.LootContextParameterSet.Builder;
|
||||
public class BlockSulphor extends ExperienceDroppingBlock {
|
||||
|
||||
public BlockSulphor() {
|
||||
super(IntProviderHelper.of(0, 2), AbstractBlock.Settings.create().hardness(0.5f));
|
||||
super(IntProviderHelper.of(0, 2), Settings.create().strength(2.5f).hardness(0.5f).sounds(BlockSoundGroup.SOUL_SAND).requiresTool());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,29 @@
|
||||
package de.jottyfan.quickiemod.event;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public interface BreakBlockCallback {
|
||||
Event<BreakBlockCallback> EVENT = EventFactory.createArrayBacked(BreakBlockCallback.class,
|
||||
(listeners) -> (world, blockPos, blockState, playerEntity) -> {
|
||||
for (BreakBlockCallback listener : listeners) {
|
||||
ActionResult result = listener.injectBlockBreakCallback(world, blockPos, blockState, playerEntity);
|
||||
if (result != ActionResult.PASS) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
});
|
||||
|
||||
ActionResult injectBlockBreakCallback(World world, BlockPos blockPos, BlockState blockState, PlayerEntity playerEntity);
|
||||
}
|
193
src/main/java/de/jottyfan/quickiemod/event/EventBlockBreak.java
Normal file
@ -0,0 +1,193 @@
|
||||
package de.jottyfan.quickiemod.event;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import de.jottyfan.quickiemod.QuickieMod;
|
||||
import de.jottyfan.quickiemod.items.HarvestRange;
|
||||
import de.jottyfan.quickiemod.items.QuickieItems;
|
||||
import de.jottyfan.quickiemod.items.ToolRangeable;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.entity.ExperienceOrbEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class EventBlockBreak {
|
||||
private static final Logger LOGGER = LogManager.getLogger(QuickieMod.MODID);
|
||||
|
||||
private enum BlockBreakDirection {
|
||||
UPWARDS, ALL;
|
||||
}
|
||||
|
||||
public void doBreakBlock(World world, BlockPos blockPos, BlockState blockState, PlayerEntity playerEntity) {
|
||||
ItemStack mainHandItemStack = playerEntity.getEquippedStack(EquipmentSlot.MAINHAND);
|
||||
if (mainHandItemStack != null) {
|
||||
Item item = mainHandItemStack.getItem();
|
||||
if (item instanceof ToolRangeable) {
|
||||
ToolRangeable tool = (ToolRangeable) item;
|
||||
Block block = blockState.getBlock();
|
||||
int handled = handleRangeableTools(tool, mainHandItemStack, world, block, blockPos, playerEntity);
|
||||
if (handled >= 255) {
|
||||
// reward for using rangeable tool very successful
|
||||
world.spawnEntity(
|
||||
new ExperienceOrbEntity(world, blockPos.getX(), blockPos.getY(), blockPos.getZ(), handled / 255));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* handle the rangeable tools break event
|
||||
*
|
||||
* @param tool the tool that has been used
|
||||
* @param itemStack the item stack
|
||||
* @param world 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, World world, Block currentBlock,
|
||||
BlockPos pos, PlayerEntity player) {
|
||||
List<Block> validBlocks = tool.getBlockList(currentBlock);
|
||||
HarvestRange range = tool.getRange(itemStack);
|
||||
|
||||
LOGGER.info("current tool: {}", tool);
|
||||
|
||||
if (QuickieItems.SPEEDPOWDERAXE.getItem().equals(tool)) {
|
||||
return breakBlockRecursive(new ArrayList<>(), world, validBlocks, pos, tool, range, BlockBreakDirection.UPWARDS,
|
||||
player, true);
|
||||
} else if (QuickieItems.SPEEDPOWDERPICKAXE.getItem().equals(tool)) {
|
||||
return breakBlockRecursive(new ArrayList<>(), world, validBlocks, pos, tool, range, BlockBreakDirection.ALL,
|
||||
player, false);
|
||||
} else if (QuickieItems.SPEEDPOWDERSHOVEL.getItem().equals(tool)) {
|
||||
return breakBlockRecursive(new ArrayList<>(), world, validBlocks, pos, tool, range, BlockBreakDirection.ALL,
|
||||
player, false);
|
||||
} else if (QuickieItems.SPEEDPOWDERHOE.getItem().equals(tool)) {
|
||||
return breakBlockRecursive(new ArrayList<>(), world, validBlocks, pos, tool, range, BlockBreakDirection.ALL,
|
||||
player, false);
|
||||
} else if (QuickieItems.QUICKIEPOWDERAXE.getItem().equals(tool)) {
|
||||
return breakBlockRecursive(new ArrayList<>(), world, validBlocks, pos, tool, range, BlockBreakDirection.UPWARDS,
|
||||
player, true);
|
||||
} else if (QuickieItems.QUICKIEPOWDERPICKAXE.getItem().equals(tool)) {
|
||||
return breakBlockRecursive(new ArrayList<>(), world, validBlocks, pos, tool, range, BlockBreakDirection.ALL,
|
||||
player, false);
|
||||
} else if (QuickieItems.QUICKIEPOWDERSHOVEL.getItem().equals(tool)) {
|
||||
return breakBlockRecursive(new ArrayList<>(), world, validBlocks, pos, tool, range, BlockBreakDirection.ALL,
|
||||
player, false);
|
||||
} else if (QuickieItems.QUICKIEPOWDERHOE.getItem().equals(tool)) {
|
||||
return breakBlockRecursive(new ArrayList<>(), world, validBlocks, pos, tool, range, BlockBreakDirection.ALL,
|
||||
player, false);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* break block recursively;
|
||||
*
|
||||
* @param visitedBlocks the positions of visited blocks
|
||||
* @param world 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, World world, List<Block> validBlocks, BlockPos pos,
|
||||
ToolRangeable tool, HarvestRange range, BlockBreakDirection blockBreakDirection, PlayerEntity player,
|
||||
boolean breakLeaves) {
|
||||
if (visitedBlocks.contains(pos.toString())) {
|
||||
return 0;
|
||||
} else if (validBlocks == null) {
|
||||
return 0;
|
||||
} else {
|
||||
visitedBlocks.add(pos.toString());
|
||||
}
|
||||
Integer affected = 0;
|
||||
BlockState blockState = world.getBlockState(pos);
|
||||
if (tool.canBreakNeighbors(blockState)) {
|
||||
Block currentBlock = blockState.getBlock();
|
||||
if (validBlocks.contains(currentBlock)) {
|
||||
Block.dropStacks(blockState, world, pos); // includes xorbs
|
||||
affected += 1;
|
||||
world.setBlockState(pos, Blocks.AIR.getDefaultState());
|
||||
if (range == null || range.getxRange() > 1 || range.getyRange() > 1 || range.getzRange() > 1) {
|
||||
HarvestRange nextRadius = range == null ? null : range.addXYZ(-1);
|
||||
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.north(), tool, nextRadius,
|
||||
blockBreakDirection, player, breakLeaves);
|
||||
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.north().east(), tool, nextRadius,
|
||||
blockBreakDirection, player, breakLeaves);
|
||||
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.north().west(), tool, nextRadius,
|
||||
blockBreakDirection, player, breakLeaves);
|
||||
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.south(), tool, nextRadius,
|
||||
blockBreakDirection, player, breakLeaves);
|
||||
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.south().east(), tool, nextRadius,
|
||||
blockBreakDirection, player, breakLeaves);
|
||||
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.south().west(), tool, nextRadius,
|
||||
blockBreakDirection, player, breakLeaves);
|
||||
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.east(), tool, nextRadius,
|
||||
blockBreakDirection, player, breakLeaves);
|
||||
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.west(), tool, nextRadius,
|
||||
blockBreakDirection, player, breakLeaves);
|
||||
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.up(), tool, nextRadius,
|
||||
blockBreakDirection, player, breakLeaves);
|
||||
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.up().north(), tool, nextRadius,
|
||||
blockBreakDirection, player, breakLeaves);
|
||||
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.up().north().east(), tool, nextRadius,
|
||||
blockBreakDirection, player, breakLeaves);
|
||||
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.up().north().west(), tool, nextRadius,
|
||||
blockBreakDirection, player, breakLeaves);
|
||||
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.up().east(), tool, nextRadius,
|
||||
blockBreakDirection, player, breakLeaves);
|
||||
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.up().west(), tool, nextRadius,
|
||||
blockBreakDirection, player, breakLeaves);
|
||||
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.up().south().east(), tool, nextRadius,
|
||||
blockBreakDirection, player, breakLeaves);
|
||||
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.up().south().west(), tool, nextRadius,
|
||||
blockBreakDirection, player, breakLeaves);
|
||||
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.up().south(), tool, nextRadius,
|
||||
blockBreakDirection, player, breakLeaves);
|
||||
|
||||
if (BlockBreakDirection.ALL.equals(blockBreakDirection)) {
|
||||
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.down(), tool, nextRadius,
|
||||
blockBreakDirection, player, breakLeaves);
|
||||
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.down().north(), tool, nextRadius,
|
||||
blockBreakDirection, player, breakLeaves);
|
||||
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.down().south(), tool, nextRadius,
|
||||
blockBreakDirection, player, breakLeaves);
|
||||
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.down().east(), tool, nextRadius,
|
||||
blockBreakDirection, player, breakLeaves);
|
||||
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.down().west(), tool, nextRadius,
|
||||
blockBreakDirection, player, breakLeaves);
|
||||
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.down().north().east(), tool,
|
||||
nextRadius, blockBreakDirection, player, breakLeaves);
|
||||
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.down().north().west(), tool,
|
||||
nextRadius, blockBreakDirection, player, breakLeaves);
|
||||
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.down().south().east(), tool,
|
||||
nextRadius, blockBreakDirection, player, breakLeaves);
|
||||
affected += breakBlockRecursive(visitedBlocks, world, validBlocks, pos.down().south().west(), tool,
|
||||
nextRadius, blockBreakDirection, player, breakLeaves);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return affected;
|
||||
}
|
||||
}
|
@ -6,6 +6,8 @@ import org.slf4j.LoggerFactory;
|
||||
import de.jottyfan.quickiemod.QuickieMod;
|
||||
import de.jottyfan.quickiemod.blockentity.BlockEntityTypes;
|
||||
import de.jottyfan.quickiemod.blocks.QuickieBlocks;
|
||||
import de.jottyfan.quickiemod.event.BreakBlockCallback;
|
||||
import de.jottyfan.quickiemod.event.EventBlockBreak;
|
||||
import de.jottyfan.quickiemod.items.QuickieItems;
|
||||
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
|
||||
import net.fabricmc.fabric.api.biome.v1.BiomeSelectors;
|
||||
@ -21,6 +23,7 @@ import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
/**
|
||||
@ -47,7 +50,7 @@ public class RegistryManager {
|
||||
}
|
||||
|
||||
public static final void registerItems() {
|
||||
LOGGER.debug("registering items");
|
||||
LOGGER.info("registering items");
|
||||
for (QuickieItems i : QuickieItems.values()) {
|
||||
Registry.register(Registries.ITEM, Identifier.of(QuickieMod.MODID, i.getName()), i.getItem());
|
||||
}
|
||||
@ -60,7 +63,7 @@ public class RegistryManager {
|
||||
}
|
||||
|
||||
public static final void registerBlocks() {
|
||||
LOGGER.debug("registering blocks");
|
||||
LOGGER.info("registering blocks");
|
||||
for (QuickieBlocks b : QuickieBlocks.values()) {
|
||||
Registry.register(Registries.BLOCK, Identifier.of(QuickieMod.MODID, b.getName()), b.getBlock());
|
||||
Registry.register(Registries.ITEM, Identifier.of(QuickieMod.MODID, b.getName()), new BlockItem(b.getBlock(), new Settings()));
|
||||
@ -77,6 +80,14 @@ public class RegistryManager {
|
||||
FeaturesManager.netherOres());
|
||||
}
|
||||
|
||||
public static final void registerEvents() {
|
||||
LOGGER.info("registering events");
|
||||
BreakBlockCallback.EVENT.register((world, blockPos, blockState, playerEntity) -> {
|
||||
new EventBlockBreak().doBreakBlock(world, blockPos, blockState, playerEntity);
|
||||
return ActionResult.SUCCESS;
|
||||
});
|
||||
}
|
||||
|
||||
public static final void registerBlockEntityTypes() {
|
||||
new BlockEntityTypes();
|
||||
}
|
||||
|
101
src/main/java/de/jottyfan/quickiemod/items/HarvestRange.java
Normal file
@ -0,0 +1,101 @@
|
||||
package de.jottyfan.quickiemod.items;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
@ -9,7 +9,22 @@ import net.minecraft.item.Item;
|
||||
*/
|
||||
public enum QuickieItems {
|
||||
// @formatter:off
|
||||
SPEEDPOWDERSHEARS(new ItemSpeedpowdershears(), "speedpowdershears"),
|
||||
SPEEDPOWDER(new ItemSpeedpowder(), "speedpowder"),
|
||||
QUICKIEPOWDER(new ItemQuickiepowder(), "quickiepowder"),
|
||||
OXIDIZEDCOPPERPOWDER(new ItemOxidizedcopperpowder(), "oxidizedcopperpowder"),
|
||||
SPEEDINGOT(new ItemSpeedingot(), "speedingot"),
|
||||
QUICKIEINGOT(new ItemQuickieingot(), "quickieingot"),
|
||||
SPEEDPOWDERAXE(new ToolSpeedpowderAxe(), "speedpowderaxe"),
|
||||
SPEEDPOWDERPICKAXE(new ToolSpeedpowderPickaxe(), "speedpowderpickaxe"),
|
||||
SPEEDPOWDERSHOVEL(new ToolSpeedpowderShovel(), "speedpowdershovel"),
|
||||
SPEEDPOWDERHOE(new ToolSpeedpowderHoe(), "speedpowderhoe"),
|
||||
SPEEDPOWDERWATERHOE(new ToolSpeedpowderWaterHoe(), "speedpowderwaterhoe"),
|
||||
SPEEDPOWDERSHEARS(new ToolSpeedpowderShears(), "speedpowdershears"),
|
||||
QUICKIEPOWDERAXE(new ToolQuickiepowderAxe(), "quickiepowderaxe"),
|
||||
QUICKIEPOWDERPICKAXE(new ToolQuickiepowderPickaxe(), "quickiepowderpickaxe"),
|
||||
QUICKIEPOWDERSHOVEL(new ToolQuickiepowderShovel(), "quickiepowdershovel"),
|
||||
QUICKIEPOWDERHOE(new ToolQuickiepowderHoe(), "quickiepowderhoe"),
|
||||
QUICKIEPOWDERWATERHOE(new ToolQuickiepowderWaterHoe(), "quickiepowderwaterhoe"),
|
||||
ROTTEN_FLESH_STRIPES(new ItemRottenFleshStripes(), "rotten_flesh_stripes"),
|
||||
CARROTSTACK(new ItemCarrotstack(), "carrotstack"),
|
||||
COTTON(new ItemCotton(), "cotton"),
|
||||
@ -20,12 +35,7 @@ public enum QuickieItems {
|
||||
CANOLABOTTLESTACK(new ItemCanolabottlestack(), "canolabottlestack"),
|
||||
STUB(new ItemStub(), "stub"),
|
||||
SALPETER(new ItemSalpeter(), "salpeter"),
|
||||
SULPHOR(new ItemSulphor(), "sulphor"),
|
||||
SPEEDPOWDER(new ItemSpeedpowder(), "speedpowder"),
|
||||
QUICKIEPOWDER(new ItemQuickiepowder(), "quickiepowder"),
|
||||
OXIDIZEDCOPPERPOWDER(new ItemOxidizedcopperpowder(), "oxidizedcopperpowder"),
|
||||
SPEEDINGOT(new ItemSpeedingot(), "speedingot"),
|
||||
QUICKIEINGOT(new ItemQuickieingot(), "quickieingot");
|
||||
SULPHOR(new ItemSulphor(), "sulphor");
|
||||
// @formatter:on
|
||||
|
||||
private final Item item;
|
||||
|
@ -0,0 +1,26 @@
|
||||
package de.jottyfan.quickiemod.items;
|
||||
|
||||
import de.jottyfan.quickiemod.items.mat.QuickieToolMaterial;
|
||||
import net.minecraft.item.AxeItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class ToolQuickiepowderAxe extends ToolRangeableAxe {
|
||||
|
||||
private final static QuickieToolMaterial MATERIAL = QuickieToolMaterial.of(7f, 2400, 15, 1f, QuickieItems.SPEEDINGOT.getItem());
|
||||
|
||||
public ToolQuickiepowderAxe() {
|
||||
super(MATERIAL, new Item.Settings().attributeModifiers(AxeItem.createAttributeModifiers(MATERIAL, 7F, -3.1F)));
|
||||
}
|
||||
|
||||
@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...
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package de.jottyfan.quickiemod.items;
|
||||
|
||||
import de.jottyfan.quickiemod.items.mat.QuickieToolMaterial;
|
||||
import net.minecraft.item.HoeItem;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class ToolQuickiepowderHoe extends ToolRangeableHoe {
|
||||
|
||||
public static final Integer DEFAULT_PLOW_RANGE = 4;
|
||||
private final static QuickieToolMaterial MATERIAL = QuickieToolMaterial.of(7f, 2400, 15, 1f, QuickieItems.SPEEDINGOT.getItem());
|
||||
|
||||
public ToolQuickiepowderHoe() {
|
||||
super(MATERIAL, new Item.Settings().attributeModifiers(HoeItem.createAttributeModifiers(MATERIAL, 7F, -3.1F)), new HarvestRange(DEFAULT_PLOW_RANGE));
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package de.jottyfan.quickiemod.items;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import de.jottyfan.quickiemod.items.mat.QuickieToolMaterial;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.PickaxeItem;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class ToolQuickiepowderPickaxe extends PickaxeItem implements ToolRangeable {
|
||||
|
||||
public static final int[] DEFAULT_HARVEST_RANGE = new int[] { 6, 6, 6 };
|
||||
private final static QuickieToolMaterial MATERIAL = QuickieToolMaterial.of(7f, 2400, 15, 1f, QuickieItems.SPEEDINGOT.getItem());
|
||||
|
||||
public ToolQuickiepowderPickaxe() {
|
||||
super(MATERIAL, new Item.Settings().attributeModifiers(PickaxeItem.createAttributeModifiers(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).isSuitableFor(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);
|
||||
// }
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package de.jottyfan.quickiemod.items;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import de.jottyfan.quickiemod.items.mat.QuickieToolMaterial;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.item.ShovelItem;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class ToolQuickiepowderShovel extends ShovelItem implements ToolRangeable {
|
||||
public static final Integer DEFAULT_HARVEST_RANGE = 6;
|
||||
private final static QuickieToolMaterial MATERIAL = QuickieToolMaterial.of(7f, 2400, 15, 1f, QuickieItems.SPEEDINGOT.getItem());
|
||||
public HarvestRange range;
|
||||
|
||||
public ToolQuickiepowderShovel() {
|
||||
super(MATERIAL, new Item.Settings().attributeModifiers(ShovelItem.createAttributeModifiers(MATERIAL, 7F, -3.1F)));
|
||||
this.range = new HarvestRange(DEFAULT_HARVEST_RANGE);
|
||||
}
|
||||
|
||||
private void createPathOnGrass(World world, BlockPos pos, Direction side) {
|
||||
BlockState blockState = world.getBlockState(pos);
|
||||
if (blockState.isAir()) {
|
||||
// try to find one underneath
|
||||
pos = pos.down();
|
||||
blockState = world.getBlockState(pos);
|
||||
} else if (!world.getBlockState(pos.up()).isAir()) {
|
||||
pos = pos.up();
|
||||
blockState = world.getBlockState(pos);
|
||||
}
|
||||
if (side != Direction.DOWN) {
|
||||
BlockState blockState2 = (BlockState) PATH_STATES.get(blockState.getBlock());
|
||||
if (blockState2 != null && world.getBlockState(pos.up()).isAir()) {
|
||||
if (!world.isClient) {
|
||||
world.setBlockState(pos, blockState2, 11);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult useOnBlock(ItemUsageContext context) {
|
||||
World world = context.getWorld();
|
||||
BlockPos pos = context.getBlockPos();
|
||||
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(world, p, context.getSide());
|
||||
}
|
||||
return super.useOnBlock(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HarvestRange getRange(ItemStack stack) {
|
||||
// TODO: get range from stack
|
||||
return range;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreakNeighbors(BlockState blockState) {
|
||||
return new ItemStack(this).isSuitableFor(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);
|
||||
// }
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package de.jottyfan.quickiemod.items;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class ToolQuickiepowderWaterHoe extends ToolQuickiepowderHoe {
|
||||
@Override
|
||||
public ActionResult useOnBlock(ItemUsageContext context) {
|
||||
ActionResult res = super.useOnBlock(context);
|
||||
if (!ActionResult.PASS.equals(res)) {
|
||||
BlockPos pos = context.getBlockPos();
|
||||
World world = context.getWorld();
|
||||
BlockState oldBlockState = world.getBlockState(pos);
|
||||
world.setBlockState(pos, Blocks.WATER.getDefaultState());
|
||||
Hand hand = context.getHand();
|
||||
PlayerEntity player = context.getPlayer();
|
||||
ItemStack oldTool = player.getStackInHand(hand);
|
||||
ItemStack newTool = new ItemStack(QuickieItems.QUICKIEPOWDERHOE.getItem());
|
||||
newTool.setDamage(oldTool.getDamage());
|
||||
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(oldBlockState.getBlock())));
|
||||
player.setStackInHand(hand, newTool);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package de.jottyfan.quickiemod.items;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
*
|
||||
* @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);
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package de.jottyfan.quickiemod.items;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.LeavesBlock;
|
||||
import net.minecraft.item.AxeItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ToolMaterial;
|
||||
import net.minecraft.registry.tag.BlockTags;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public abstract class ToolRangeableAxe extends AxeItem implements ToolRangeable {
|
||||
|
||||
protected ToolRangeableAxe(ToolMaterial material, Item.Settings settings) {
|
||||
super(material, settings);
|
||||
}
|
||||
|
||||
@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.isIn(BlockTags.LEAVES);
|
||||
return vanillaLeaves || terrestriaLeaves || blockTagLeaves;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreakNeighbors(BlockState blockIn) {
|
||||
return new ItemStack(this).isSuitableFor(blockIn) || isLeavesBlock(blockIn) || blockIn.isIn(BlockTags.LOGS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Block> getBlockList(Block block) {
|
||||
return Lists.newArrayList(block);
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package de.jottyfan.quickiemod.items;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.CropBlock;
|
||||
import net.minecraft.item.HoeItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.item.ToolMaterial;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public abstract class ToolRangeableHoe extends HoeItem implements ToolRangeable {
|
||||
|
||||
public HarvestRange range;
|
||||
|
||||
public ToolRangeableHoe(ToolMaterial material, Settings settings, HarvestRange range) {
|
||||
super(material, settings);
|
||||
this.range = range;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult useOnBlock(ItemUsageContext context) {
|
||||
ActionResult res = super.useOnBlock(context);
|
||||
boolean isCrop = context.getWorld().getBlockState(context.getBlockPos()).getBlock() instanceof CropBlock;
|
||||
if (!ActionResult.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.getWorld(), new BlockPos(x, y, z));
|
||||
BlockHitResult bhr = new BlockHitResult(context.getHitPos(), Direction.UP,
|
||||
context.getBlockPos().add(new Vec3i(x, y, z)), false);
|
||||
ItemUsageContext ctx = new ItemUsageContext(context.getPlayer(), context.getHand(), bhr);
|
||||
super.useOnBlock(ctx);
|
||||
} else {
|
||||
harvestIfPossible(context.getBlockPos().add(x, y, z), context.getWorld());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private void removePossibleGrass(World world, BlockPos pos) {
|
||||
Block block = world.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) {
|
||||
world.breakBlock(pos, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void harvestIfPossible(BlockPos pos, World world) {
|
||||
BlockState blockState = world.getBlockState(pos);
|
||||
Block block = blockState.getBlock();
|
||||
if (block instanceof CropBlock) {
|
||||
CropBlock cBlock = (CropBlock) block;
|
||||
if (cBlock.isMature(blockState)) {
|
||||
Block.dropStacks(blockState, world, pos);
|
||||
world.setBlockState(pos, cBlock.withAge(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public HarvestRange getRange(ItemStack stack) {
|
||||
// TODO: get range from stack
|
||||
return range;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreakNeighbors(BlockState blockState) {
|
||||
return new ItemStack(this).isSuitableFor(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);
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package de.jottyfan.quickiemod.items;
|
||||
|
||||
import de.jottyfan.quickiemod.items.mat.QuickieToolMaterial;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.PickaxeItem;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class ToolSpeedpowderAxe extends ToolRangeableAxe {
|
||||
|
||||
private final static QuickieToolMaterial MATERIAL = QuickieToolMaterial.of(7f, 800, 15, 1f, QuickieItems.SPEEDINGOT.getItem());
|
||||
|
||||
public ToolSpeedpowderAxe() {
|
||||
super(MATERIAL, new Item.Settings().attributeModifiers(PickaxeItem.createAttributeModifiers(MATERIAL, 7f, -3.1f)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public HarvestRange getRange(ItemStack stack) {
|
||||
// TODO: get the range from the stack
|
||||
return new HarvestRange(32, 64, 32);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package de.jottyfan.quickiemod.items;
|
||||
|
||||
import de.jottyfan.quickiemod.items.mat.QuickieToolMaterial;
|
||||
import net.minecraft.item.HoeItem;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class ToolSpeedpowderHoe extends ToolRangeableHoe {
|
||||
|
||||
public static final Integer DEFAULT_PLOW_RANGE = 2;
|
||||
private final static QuickieToolMaterial MATERIAL = QuickieToolMaterial.of(7f, 800, 15, 1f, QuickieItems.SPEEDINGOT.getItem());
|
||||
|
||||
public ToolSpeedpowderHoe() {
|
||||
super(MATERIAL, new Item.Settings().attributeModifiers(HoeItem.createAttributeModifiers(MATERIAL, 7F, -3.1F)), new HarvestRange(DEFAULT_PLOW_RANGE));
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package de.jottyfan.quickiemod.items;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import de.jottyfan.quickiemod.items.mat.QuickieToolMaterial;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.AxeItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.PickaxeItem;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class ToolSpeedpowderPickaxe extends PickaxeItem implements ToolRangeable {
|
||||
|
||||
public static final int[] DEFAULT_HARVEST_RANGE = new int[] { 3, 3, 3 };
|
||||
private final static QuickieToolMaterial MATERIAL = QuickieToolMaterial.of(7f, 800, 15, 1f, QuickieItems.SPEEDINGOT.getItem());
|
||||
|
||||
public ToolSpeedpowderPickaxe() {
|
||||
super(MATERIAL, new Item.Settings().attributeModifiers(AxeItem.createAttributeModifiers(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).isSuitableFor(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);
|
||||
// }
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package de.jottyfan.quickiemod.items;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.component.DataComponentTypes;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.passive.ChickenEntity;
|
||||
import net.minecraft.entity.passive.CowEntity;
|
||||
import net.minecraft.entity.passive.HorseEntity;
|
||||
import net.minecraft.entity.passive.SheepEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.item.ShearsItem;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.DyeColor;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class ToolSpeedpowderShears extends ShearsItem {
|
||||
|
||||
public ToolSpeedpowderShears() {
|
||||
super(new Item.Settings().component(DataComponentTypes.TOOL, ShearsItem.createToolComponent()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity entity, Hand hand) {
|
||||
Vec3d pos = entity.getPos();
|
||||
Integer amount = 3 + new Random().nextInt(4);
|
||||
if (entity instanceof SheepEntity) {
|
||||
SheepEntity sheep = (SheepEntity) entity;
|
||||
if (sheep.isShearable()) {
|
||||
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.getWorld().spawnEntity(new ItemEntity(user.getWorld(), pos.getX(), pos.getY(), pos.getZ(), new ItemStack(item, amount)));
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
} else if (entity instanceof HorseEntity) {
|
||||
HorseEntity horse = (HorseEntity) entity;
|
||||
horse.playAmbientSound();
|
||||
user.getWorld().spawnEntity(new ItemEntity(user.getWorld(), pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.LEATHER, amount)));
|
||||
return ActionResult.SUCCESS;
|
||||
} else if (entity instanceof CowEntity) {
|
||||
CowEntity cow = (CowEntity) entity;
|
||||
cow.playAmbientSound();
|
||||
user.getWorld().spawnEntity(new ItemEntity(user.getWorld(), pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.LEATHER, amount)));
|
||||
return ActionResult.SUCCESS;
|
||||
} else if (entity instanceof ChickenEntity) {
|
||||
ChickenEntity cow = (ChickenEntity) entity;
|
||||
cow.playAmbientSound();
|
||||
user.getWorld().spawnEntity(new ItemEntity(user.getWorld(), pos.getX(), pos.getY(), pos.getZ(), new ItemStack(Items.FEATHER, amount)));
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package de.jottyfan.quickiemod.items;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import de.jottyfan.quickiemod.items.mat.QuickieToolMaterial;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.item.ShovelItem;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class ToolSpeedpowderShovel extends ShovelItem implements ToolRangeable {
|
||||
public static final Integer DEFAULT_HARVEST_RANGE = 3;
|
||||
private final static QuickieToolMaterial MATERIAL = QuickieToolMaterial.of(7f, 800, 15, 1f, QuickieItems.SPEEDINGOT.getItem());
|
||||
public HarvestRange range;
|
||||
|
||||
public ToolSpeedpowderShovel() {
|
||||
super(MATERIAL, new Item.Settings().attributeModifiers(ShovelItem.createAttributeModifiers(MATERIAL, 7F, -3.1F)));
|
||||
this.range = new HarvestRange(DEFAULT_HARVEST_RANGE);
|
||||
}
|
||||
|
||||
private void createPathOnGrass(World world, BlockPos pos, Direction side) {
|
||||
BlockState blockState = world.getBlockState(pos);
|
||||
if (blockState.isAir()) {
|
||||
// try to find one underneath
|
||||
pos = pos.down();
|
||||
blockState = world.getBlockState(pos);
|
||||
} else if (!world.getBlockState(pos.up()).isAir()) {
|
||||
pos = pos.up();
|
||||
blockState = world.getBlockState(pos);
|
||||
}
|
||||
if (side != Direction.DOWN) {
|
||||
BlockState blockState2 = (BlockState) PATH_STATES.get(blockState.getBlock());
|
||||
if (blockState2 != null && world.getBlockState(pos.up()).isAir()) {
|
||||
if (!world.isClient) {
|
||||
world.setBlockState(pos, blockState2, 11);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult useOnBlock(ItemUsageContext context) {
|
||||
World world = context.getWorld();
|
||||
BlockPos pos = context.getBlockPos();
|
||||
createPathOnGrass(world, pos.north(), context.getSide());
|
||||
createPathOnGrass(world, pos.north().east(), context.getSide());
|
||||
createPathOnGrass(world, pos.north().west(), context.getSide());
|
||||
createPathOnGrass(world, pos.east(), context.getSide());
|
||||
createPathOnGrass(world, pos.west(), context.getSide());
|
||||
createPathOnGrass(world, pos.south(), context.getSide());
|
||||
createPathOnGrass(world, pos.south().east(), context.getSide());
|
||||
createPathOnGrass(world, pos.south().west(), context.getSide());
|
||||
return super.useOnBlock(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HarvestRange getRange(ItemStack stack) {
|
||||
// TODO: get range from stack
|
||||
return range;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreakNeighbors(BlockState blockState) {
|
||||
return new ItemStack(this).isSuitableFor(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);
|
||||
// }
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package de.jottyfan.quickiemod.items;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class ToolSpeedpowderWaterHoe extends ToolSpeedpowderHoe {
|
||||
@Override
|
||||
public ActionResult useOnBlock(ItemUsageContext context) {
|
||||
ActionResult res = super.useOnBlock(context);
|
||||
if (!ActionResult.PASS.equals(res)) {
|
||||
BlockPos pos = context.getBlockPos();
|
||||
World world = context.getWorld();
|
||||
BlockState oldBlockState = world.getBlockState(pos);
|
||||
world.setBlockState(pos, Blocks.WATER.getDefaultState());
|
||||
Hand hand = context.getHand();
|
||||
PlayerEntity player = context.getPlayer();
|
||||
ItemStack oldTool = player.getStackInHand(hand);
|
||||
ItemStack newTool = new ItemStack(QuickieItems.SPEEDPOWDERHOE.getItem());
|
||||
newTool.setDamage(oldTool.getDamage());
|
||||
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(oldBlockState.getBlock())));
|
||||
player.setStackInHand(hand, newTool);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package de.jottyfan.quickiemod.items.mat;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ToolMaterial;
|
||||
import net.minecraft.recipe.Ingredient;
|
||||
import net.minecraft.registry.tag.BlockTags;
|
||||
import net.minecraft.registry.tag.TagKey;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class QuickieToolMaterial implements ToolMaterial {
|
||||
|
||||
private final float attackDamage;
|
||||
private final int durability;
|
||||
private final int enchantability;
|
||||
private final float miningSpeedMuliplier;
|
||||
private final Item item;
|
||||
|
||||
private QuickieToolMaterial(float attackDamage, int durability, int enchantability, float miningSpeedMultiplier, Item item) {
|
||||
this.attackDamage = attackDamage;
|
||||
this.durability = durability;
|
||||
this.enchantability = enchantability;
|
||||
this.miningSpeedMuliplier = miningSpeedMultiplier;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public static final QuickieToolMaterial of(float attackDamage, int durability, int enchantability, float miningSpeedMultiplier, Item item) {
|
||||
return new QuickieToolMaterial(attackDamage, durability, enchantability, miningSpeedMultiplier, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAttackDamage() {
|
||||
return attackDamage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDurability() {
|
||||
return durability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnchantability() {
|
||||
return enchantability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TagKey<Block> getInverseTag() {
|
||||
return BlockTags.INCORRECT_FOR_IRON_TOOL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMiningSpeedMultiplier() {
|
||||
return miningSpeedMuliplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Ingredient getRepairIngredient() {
|
||||
return Ingredient.ofItems(item);
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package de.jottyfan.quickiemod.mixin;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import de.jottyfan.quickiemod.event.BreakBlockCallback;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
@Mixin(Block.class)
|
||||
public class BlockBreakMixin {
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "onBreak(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/entity/player/PlayerEntity;)Lnet/minecraft/block/BlockState;")
|
||||
private void onBreak(final World world, final BlockPos blockPos, final BlockState blockState,
|
||||
final PlayerEntity playerEntity, final CallbackInfoReturnable<BlockBreakMixin> info) {
|
||||
ActionResult result = BreakBlockCallback.EVENT.invoker().injectBlockBreakCallback(world, blockPos, blockState,
|
||||
playerEntity);
|
||||
if (result == ActionResult.FAIL) {
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "minecraft:item/handheld",
|
||||
"textures": {
|
||||
"layer0": "quickiemod:item/quickiepowderaxe"
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "quickiemod:item/quickiepowderhoe"
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "quickiemod:item/quickiepowderpickaxe"
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "quickiemod:item/quickiepowdershovel"
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "quickiemod:item/quickiepowderwaterhoe"
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "quickiemod:item/speedpowderaxe"
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "quickiemod:item/speedpowderhoe"
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "quickiemod:item/speedpowderpickaxe"
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "quickiemod:item/speedpowdershovel"
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "quickiemod:item/speedpowderwaterhoe"
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 5.9 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 6.0 KiB |
7
src/main/resources/data/c/tags/item/axes.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"quickiemod:speedpowderaxe",
|
||||
"quickiemod:quickiepowderaxe"
|
||||
]
|
||||
}
|
9
src/main/resources/data/c/tags/item/hoes.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"quickiemod:speedpowderhoe",
|
||||
"quickiemod:speedpowderwaterhoe",
|
||||
"quickiemod:quickiepowderhoe",
|
||||
"quickiemod:quickiepowderwaterhoe"
|
||||
]
|
||||
}
|
7
src/main/resources/data/c/tags/item/pickaxes.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"quickiemod:speedpowderpickaxe",
|
||||
"quickiemod:quickiepowderpickaxe"
|
||||
]
|
||||
}
|
7
src/main/resources/data/c/tags/item/shovels.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"quickiemod:speedpowdershovel",
|
||||
"quickiemod:quickiepowdershovel"
|
||||
]
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
{
|
||||
"type": "minecraft:crafting_shaped",
|
||||
"category": "tools",
|
||||
"pattern": [
|
||||
"ss",
|
||||
"s|",
|
||||
" |"
|
||||
],
|
||||
"key": {
|
||||
"s": {
|
||||
"item": "quickiemod:quickieingot"
|
||||
},
|
||||
"|": {
|
||||
"item": "minecraft:stick"
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
"id": "quickiemod:quickiepowderaxe",
|
||||
"count": 1
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
{
|
||||
"type": "minecraft:crafting_shaped",
|
||||
"category": "tools",
|
||||
"pattern": [
|
||||
"ss",
|
||||
" |",
|
||||
" |"
|
||||
],
|
||||
"key": {
|
||||
"s": {
|
||||
"item": "quickiemod:quickieingot"
|
||||
},
|
||||
"|": {
|
||||
"item": "minecraft:stick"
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
"id": "quickiemod:quickiepowderhoe",
|
||||
"count": 1
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
{
|
||||
"type": "minecraft:crafting_shaped",
|
||||
"category": "tools",
|
||||
"pattern": [
|
||||
"sss",
|
||||
" | ",
|
||||
" | "
|
||||
],
|
||||
"key": {
|
||||
"s": {
|
||||
"item": "quickiemod:quickieingot"
|
||||
},
|
||||
"|": {
|
||||
"item": "minecraft:stick"
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
"id": "quickiemod:quickiepowderpickaxe",
|
||||
"count": 1
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
{
|
||||
"type": "minecraft:crafting_shaped",
|
||||
"category": "tools",
|
||||
"pattern": [
|
||||
"s",
|
||||
"|",
|
||||
"|"
|
||||
],
|
||||
"key": {
|
||||
"s": {
|
||||
"item": "quickiemod:quickieingot"
|
||||
},
|
||||
"|": {
|
||||
"item": "minecraft:stick"
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
"id": "quickiemod:quickiepowdershovel",
|
||||
"count": 1
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
{
|
||||
"type": "minecraft:crafting_shaped",
|
||||
"category": "tools",
|
||||
"pattern": [
|
||||
"ss",
|
||||
"s|",
|
||||
" |"
|
||||
],
|
||||
"key": {
|
||||
"s": {
|
||||
"item": "quickiemod:speedingot"
|
||||
},
|
||||
"|": {
|
||||
"item": "minecraft:stick"
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
"id": "quickiemod:speedpowderaxe",
|
||||
"count": 1
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
{
|
||||
"type": "minecraft:crafting_shaped",
|
||||
"category": "tools",
|
||||
"pattern": [
|
||||
"ss",
|
||||
" |",
|
||||
" |"
|
||||
],
|
||||
"key": {
|
||||
"s": {
|
||||
"item": "quickiemod:speedingot"
|
||||
},
|
||||
"|": {
|
||||
"item": "minecraft:stick"
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
"id": "quickiemod:speedpowderhoe",
|
||||
"count": 1
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
{
|
||||
"type": "minecraft:crafting_shaped",
|
||||
"category": "tools",
|
||||
"pattern": [
|
||||
"sss",
|
||||
" | ",
|
||||
" | "
|
||||
],
|
||||
"key": {
|
||||
"s": {
|
||||
"item": "quickiemod:speedingot"
|
||||
},
|
||||
"|": {
|
||||
"item": "minecraft:stick"
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
"id": "quickiemod:speedpowderpickaxe",
|
||||
"count": 1
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
{
|
||||
"type": "minecraft:crafting_shaped",
|
||||
"category": "tools",
|
||||
"pattern": [
|
||||
"s",
|
||||
"|",
|
||||
"|"
|
||||
],
|
||||
"key": {
|
||||
"s": {
|
||||
"item": "quickiemod:speedingot"
|
||||
},
|
||||
"|": {
|
||||
"item": "minecraft:stick"
|
||||
}
|
||||
},
|
||||
"result": {
|
||||
"id": "quickiemod:speedpowdershovel",
|
||||
"count": 1
|
||||
}
|
||||
}
|