fixed block breaking bug
This commit is contained in:
parent
4ae1e998b0
commit
46a21b03c0
@ -9,7 +9,7 @@ yarn_mappings=1.21.4+build.1
|
||||
loader_version=0.16.9
|
||||
|
||||
# Mod Properties
|
||||
mod_version=1.21.4.1
|
||||
mod_version=1.21.4.2
|
||||
maven_group=de.jottyfan.quickiemod
|
||||
archives_base_name=quickiemod
|
||||
|
||||
|
@ -12,7 +12,6 @@ import de.jottyfan.quickiemod.feature.ModFeatures;
|
||||
import de.jottyfan.quickiemod.item.ModItems;
|
||||
import de.jottyfan.quickiemod.itemgroup.ModItemGroup;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.event.player.AttackBlockCallback;
|
||||
import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents;
|
||||
import net.fabricmc.fabric.api.loot.v3.LootTableEvents;
|
||||
import net.fabricmc.fabric.api.registry.CompostingChanceRegistry;
|
||||
@ -22,8 +21,6 @@ import net.minecraft.item.Items;
|
||||
import net.minecraft.loot.LootPool;
|
||||
import net.minecraft.loot.condition.SurvivesExplosionLootCondition;
|
||||
import net.minecraft.loot.entry.ItemEntry;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -70,12 +67,11 @@ public class Quickiemod implements ModInitializer {
|
||||
ModItemGroup.registerItemGroup(items, blocks);
|
||||
PlayerBlockBreakEvents.BEFORE.register((world, player, pos, state, blockEntity) -> {
|
||||
Block oldBlock = state.getBlock();
|
||||
new EventBlockBreak().doBreakBlock(world, pos, state, player, oldBlock);
|
||||
if (new EventBlockBreak().doBreakBlock(world, pos, state, player, oldBlock)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
// PlayerBlockBreakEvents.AFTER.register((world, player, pos, state, blockEntity) -> {
|
||||
// Block oldBlock = state.getBlock();
|
||||
// new EventBlockBreak().doBreakBlock(world, pos, state, player, oldBlock);
|
||||
// });
|
||||
}
|
||||
}
|
@ -7,7 +7,6 @@ import de.jottyfan.quickiemod.Quickiemod;
|
||||
import de.jottyfan.quickiemod.item.HarvestRange;
|
||||
import de.jottyfan.quickiemod.item.ModItems;
|
||||
import de.jottyfan.quickiemod.item.ToolRangeable;
|
||||
import de.jottyfan.quickiemod.item.ToolSpeedpowderAxe;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
@ -29,7 +28,17 @@ public class EventBlockBreak {
|
||||
UPWARDS, ALL;
|
||||
}
|
||||
|
||||
public void doBreakBlock(World world, BlockPos blockPos, BlockState blockState, PlayerEntity playerEntity, Block oldBlock) {
|
||||
/**
|
||||
* break surrounding block if item is of ToolRangeable
|
||||
*
|
||||
* @param world
|
||||
* @param blockPos
|
||||
* @param blockState
|
||||
* @param playerEntity
|
||||
* @param oldBlock
|
||||
* @return true if this range breaking routine has been used, false otherwise
|
||||
*/
|
||||
public boolean doBreakBlock(World world, BlockPos blockPos, BlockState blockState, PlayerEntity playerEntity, Block oldBlock) {
|
||||
ItemStack mainHandItemStack = playerEntity.getEquippedStack(EquipmentSlot.MAINHAND);
|
||||
if (mainHandItemStack != null) {
|
||||
Item item = mainHandItemStack.getItem();
|
||||
@ -47,7 +56,12 @@ public class EventBlockBreak {
|
||||
world.spawnEntity(
|
||||
new ExperienceOrbEntity(world, 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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,7 +83,7 @@ public class EventBlockBreak {
|
||||
if (tool instanceof Item) {
|
||||
Item toolItem = (Item) tool; // a rangeable tool should always be an item
|
||||
List<String> visitedBlocks = new ArrayList<>();
|
||||
if (tool instanceof ToolSpeedpowderAxe) {
|
||||
if (ModItems.TOOL_SPEEDPOWDERAXE.getName().equals(toolItem.getName())) {
|
||||
return breakBlockRecursive(visitedBlocks, world, validBlocks, pos, tool, range, BlockBreakDirection.UPWARDS,
|
||||
player, true);
|
||||
} else if (ModItems.TOOL_SPEEDPOWDERPICKAXE.getName().equals(toolItem.getName())) {
|
||||
@ -118,7 +132,7 @@ public class EventBlockBreak {
|
||||
private int breakBlockRecursive(List<String> visitedBlocks, World world, List<Block> validBlocks, BlockPos pos,
|
||||
ToolRangeable tool, HarvestRange range, BlockBreakDirection blockBreakDirection, PlayerEntity player,
|
||||
boolean breakLeaves) {
|
||||
boolean ignoreSpawn = visitedBlocks.size() < 1; // with this, the already broken block can be omitted to spawn
|
||||
// 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) {
|
||||
@ -131,9 +145,9 @@ public class EventBlockBreak {
|
||||
if (tool.canBreakNeighbors(blockState)) {
|
||||
Block currentBlock = blockState.getBlock();
|
||||
if (validBlocks.contains(currentBlock)) {
|
||||
if (!ignoreSpawn) {
|
||||
// if (!ignoreSpawn) {
|
||||
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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user