preparations for level up functionality

This commit is contained in:
Jörg Henke 2020-10-28 19:02:31 +01:00
parent 281129212d
commit 8b3e4da9c2
7 changed files with 61 additions and 29 deletions

View File

@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.9.3+build.207 loader_version=0.9.3+build.207
# Mod Properties # Mod Properties
mod_version = 1.16.3.6 mod_version = 1.16.3.7
maven_group = de.jottyfan.minecraft maven_group = de.jottyfan.minecraft
archives_base_name = quickiefabric archives_base_name = quickiefabric

View File

@ -14,7 +14,6 @@ import net.minecraft.entity.ExperienceOrbEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -34,14 +33,13 @@ public class EventBlockBreak {
if (mainHandItemStack != null) { if (mainHandItemStack != null) {
Item item = mainHandItemStack.getItem(); Item item = mainHandItemStack.getItem();
if (item instanceof ToolRangeable) { if (item instanceof ToolRangeable) {
CompoundTag nbt = mainHandItemStack.getTag();
Integer level = nbt != null ? nbt.getInt("level") : 0;
ToolRangeable tool = (ToolRangeable) item; ToolRangeable tool = (ToolRangeable) item;
Block block = blockState.getBlock(); Block block = blockState.getBlock();
int handled = handleRangeableTools(tool, level, world, block, blockPos, playerEntity); int handled = handleRangeableTools(tool, mainHandItemStack, world, block, blockPos, playerEntity);
if (handled >= 255) { if (handled >= 255) {
// reward for using rangeable tool very successful // reward for using rangeable tool very successful
world.spawnEntity(new ExperienceOrbEntity(world, blockPos.getX(), blockPos.getY(), blockPos.getZ(), handled / 255)); world.spawnEntity(
new ExperienceOrbEntity(world, blockPos.getX(), blockPos.getY(), blockPos.getZ(), handled / 255));
} }
} }
} }
@ -51,19 +49,17 @@ public class EventBlockBreak {
* handle the rangeable tools break event * handle the rangeable tools break event
* *
* @param tool the tool that has been used * @param tool the tool that has been used
* @param itemStack the item stack
* @param world the world * @param world the world
* @param block the block to break * @param block the block to break
* @param pos the position of the current block * @param pos the position of the current block
* @param player the current player * @param player the current player
* @return number of affected blocks * @return number of affected blocks
*/ */
private int handleRangeableTools(ToolRangeable tool, Integer level, World world, Block currentBlock, BlockPos pos, private int handleRangeableTools(ToolRangeable tool, ItemStack itemStack, World world, Block currentBlock,
PlayerEntity player) { BlockPos pos, PlayerEntity player) {
List<Block> validBlocks = tool.getBlockList(currentBlock); List<Block> validBlocks = tool.getBlockList(currentBlock);
HarvestRange range = tool.getRange(); HarvestRange range = tool.getRange(itemStack);
if (range != null) {
range = range.addXYZ(level);
}
if (QuickieTools.SPEEDPOWDERAXE.equals(tool)) { if (QuickieTools.SPEEDPOWDERAXE.equals(tool)) {
return breakBlockRecursive(new ArrayList<>(), world, validBlocks, pos, tool, range, BlockBreakDirection.UPWARDS, return breakBlockRecursive(new ArrayList<>(), world, validBlocks, pos, tool, range, BlockBreakDirection.UPWARDS,
player, true); player, true);

View File

@ -20,6 +20,13 @@ public class HarvestRange implements Serializable {
this.zRange = 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) { public HarvestRange(int xRange, int yRange, int zRange) {
super(); super();
this.xRange = xRange; this.xRange = xRange;
@ -38,6 +45,15 @@ public class HarvestRange implements Serializable {
return new HarvestRange(xRange + i, yRange + i, zRange + 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 * @return the xRange
*/ */

View File

@ -15,6 +15,7 @@ import de.jottyfan.minecraft.quickiefabric.tools.externalmods.Terrestria;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
/** /**
@ -57,7 +58,8 @@ public interface ToolRangeable {
"fir", "green_enchanted", "holly", "jacaranda", "mahogany", "mangrove", "pine", "rainbow_eucalyptus", "fir", "green_enchanted", "holly", "jacaranda", "mahogany", "mangrove", "pine", "rainbow_eucalyptus",
"redwood", "skyris", "willow", "witch_hazel", "zelkova").getGroups("log", "wood")), "redwood", "skyris", "willow", "witch_hazel", "zelkova").getGroups("log", "wood")),
Byg.createFromSet( Byg.createFromSet(
new IdentifierGroups("blue_glowshroom", "purple_glowshroom", "red_glowshroom", "yellow_glowshroom").getGroups("block", "stem"))); new IdentifierGroups("blue_glowshroom", "purple_glowshroom", "red_glowshroom", "yellow_glowshroom")
.getGroups("block", "stem")));
public static final Set<Block> PICKAXE_EFFECTIVE_ON = Sets.newHashSet(new Block[] { Blocks.GLOWSTONE }); public static final Set<Block> PICKAXE_EFFECTIVE_ON = Sets.newHashSet(new Block[] { Blocks.GLOWSTONE });
@ -92,9 +94,10 @@ public interface ToolRangeable {
} }
/** /**
* @param stack the item stack that keeps the range
* @return range of blocks to be harvested * @return range of blocks to be harvested
*/ */
public HarvestRange getRange(); public HarvestRange getRange(ItemStack stack);
/** /**
* check if this block state is one that affects the neighbor blocks to break * check if this block state is one that affects the neighbor blocks to break

View File

@ -26,7 +26,8 @@ public class ToolRangeableAxe extends AxeItem implements ToolRangeable {
} }
@Override @Override
public HarvestRange getRange() { 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... return new HarvestRange(64, 128, 64); // trees bigger than that are too heavy for one small axe...
} }

View File

@ -8,8 +8,10 @@ import de.jottyfan.minecraft.quickiefabric.init.RegistryManager;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.PickaxeItem; import net.minecraft.item.PickaxeItem;
import net.minecraft.item.ToolMaterials; import net.minecraft.item.ToolMaterials;
import net.minecraft.nbt.CompoundTag;
/** /**
* *
@ -18,17 +20,22 @@ import net.minecraft.item.ToolMaterials;
*/ */
public class ToolSpeedpowderPickaxe extends PickaxeItem implements ToolRangeable { public class ToolSpeedpowderPickaxe extends PickaxeItem implements ToolRangeable {
public static final Integer DEFAULT_HARVEST_RANGE = 3; public static final int[] DEFAULT_HARVEST_RANGE = new int[] {3, 3, 3};
private HarvestRange range;
public ToolSpeedpowderPickaxe() { public ToolSpeedpowderPickaxe() {
super(ToolMaterials.DIAMOND, 4, 2.0f, new Item.Settings().group(RegistryManager.QUICKIEFABRIC_GROUP)); super(ToolMaterials.DIAMOND, 4, 2.0f, new Item.Settings().group(RegistryManager.QUICKIEFABRIC_GROUP));
this.range = new HarvestRange(DEFAULT_HARVEST_RANGE);
} }
@Override @Override
public HarvestRange getRange() { public HarvestRange getRange(ItemStack stack) {
return range; CompoundTag tag = stack.getTag();
int[] range = tag.getIntArray("range");
if (range.length < 3) {
range = DEFAULT_HARVEST_RANGE;
tag.putIntArray("range", range);
}
return new HarvestRange(range);
} }
@Override @Override
@ -41,8 +48,15 @@ public class ToolSpeedpowderPickaxe extends PickaxeItem implements ToolRangeable
return Lists.newArrayList(block); return Lists.newArrayList(block);
} }
public void setPlusRange(Integer plusRange) { public void setPlusRange(ItemStack stack, Integer plusRange) {
range.addXYZ(plusRange); CompoundTag tag = stack.getTag();
int[] range = tag.getIntArray("range");
if (range.length < 3) {
range = DEFAULT_HARVEST_RANGE;
}
HarvestRange harvestRange = new HarvestRange(range);
harvestRange.addXYZ(plusRange);
tag.putIntArray("range", harvestRange.getRangeAsArray());
} }
// @Override // @Override

View File

@ -11,6 +11,7 @@ import de.jottyfan.minecraft.quickiefabric.init.RegistryManager;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ShovelItem; import net.minecraft.item.ShovelItem;
import net.minecraft.item.ToolMaterials; import net.minecraft.item.ToolMaterials;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
@ -32,7 +33,8 @@ public class ToolSpeedpowderShovel extends ShovelItem implements ToolRangeable {
} }
@Override @Override
public HarvestRange getRange() { public HarvestRange getRange(ItemStack stack) {
// TODO: get range from stack
return range; return range;
} }