Remove block moved to utils
This commit is contained in:
parent
06b4af59bc
commit
c4ecef5dcb
4 changed files with 82 additions and 57 deletions
src/main/java/techreborn/items/tool/industrial
|
@ -27,24 +27,22 @@ package techreborn.items.tool.industrial;
|
|||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.client.item.TooltipContext;
|
||||
import reborncore.common.util.StringUtils;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.item.ToolMaterials;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.tag.BlockTags;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.DefaultedList;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.TypedActionResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import reborncore.common.util.ChatUtils;
|
||||
import reborncore.common.util.ItemUtils;
|
||||
import team.reborn.energy.Energy;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
|
@ -53,6 +51,7 @@ import techreborn.items.tool.ChainsawItem;
|
|||
import techreborn.utils.InitUtils;
|
||||
import techreborn.utils.MessageIDs;
|
||||
import techreborn.utils.TagUtils;
|
||||
import techreborn.utils.ToolsUtil;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
|
@ -93,35 +92,19 @@ public class IndustrialChainsawItem extends ChainsawItem {
|
|||
}
|
||||
}
|
||||
|
||||
private void breakBlock(BlockPos pos, ItemStack stack, World world, LivingEntity entityLiving, BlockPos oldPos) {
|
||||
if (oldPos == pos) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(Energy.of(stack).use(cost)){
|
||||
BlockState blockState = world.getBlockState(pos);
|
||||
if (blockState.getHardness(world, pos) == -1.0F) {
|
||||
return;
|
||||
}
|
||||
if(!(entityLiving instanceof PlayerEntity)){
|
||||
return;
|
||||
}
|
||||
|
||||
blockState.getBlock().afterBreak(world, (PlayerEntity) entityLiving, pos, blockState, world.getBlockEntity(pos), stack);
|
||||
world.setBlockState(pos, Blocks.AIR.getDefaultState());
|
||||
world.removeBlockEntity(pos);
|
||||
}
|
||||
}
|
||||
|
||||
//ChainsawItem
|
||||
@Override
|
||||
public boolean postMine(ItemStack stack, World worldIn, BlockState blockIn, BlockPos pos, LivingEntity entityLiving) {
|
||||
List<BlockPos> wood = new ArrayList<>();
|
||||
List<BlockPos> leaves = new ArrayList<>();
|
||||
if (ItemUtils.isActive(stack)) {
|
||||
findWood(worldIn, pos, wood, new ArrayList<>());
|
||||
findWood(worldIn, pos, wood, leaves);
|
||||
wood.remove(pos);
|
||||
wood.stream()
|
||||
.filter(p -> Energy.of(stack).use(cost))
|
||||
.forEach(pos1 -> breakBlock(pos1, stack, worldIn, entityLiving, pos));
|
||||
.filter(p -> Energy.of(stack).simulate().use(cost))
|
||||
.forEach(pos1 -> ToolsUtil.breakBlock(stack, worldIn, pos1, entityLiving, cost));
|
||||
leaves.remove(pos);
|
||||
leaves.forEach(pos1 -> ToolsUtil.breakBlock(stack, worldIn, pos1, entityLiving, 0));
|
||||
}
|
||||
return super.postMine(stack, worldIn, blockIn, pos, entityLiving);
|
||||
}
|
||||
|
|
|
@ -30,24 +30,23 @@ import net.minecraft.block.BlockState;
|
|||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.client.item.TooltipContext;
|
||||
import reborncore.common.util.StringUtils;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.item.ToolMaterials;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.DefaultedList;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.TypedActionResult;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.RayTraceContext;
|
||||
import net.minecraft.world.World;
|
||||
import reborncore.common.util.ChatUtils;
|
||||
import reborncore.common.util.ItemUtils;
|
||||
import team.reborn.energy.Energy;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
|
@ -55,6 +54,7 @@ import techreborn.init.TRContent;
|
|||
import techreborn.items.tool.DrillItem;
|
||||
import techreborn.utils.InitUtils;
|
||||
import techreborn.utils.MessageIDs;
|
||||
import techreborn.utils.ToolsUtil;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
|
@ -71,11 +71,12 @@ public class IndustrialDrillItem extends DrillItem {
|
|||
this.transferLimit = 1000;
|
||||
}
|
||||
|
||||
private Set<BlockPos> getTargetBlocks(World worldIn, BlockPos pos, @Nullable PlayerEntity playerIn) {
|
||||
private Set<BlockPos> getTargetBlocks(World worldIn, BlockPos pos, @Nullable LivingEntity entityLiving) {
|
||||
Set<BlockPos> targetBlocks = new HashSet<>();
|
||||
if (playerIn == null) {
|
||||
if (!(entityLiving instanceof PlayerEntity) || entityLiving == null) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
PlayerEntity playerIn = (PlayerEntity) entityLiving;
|
||||
|
||||
//Put a dirt block down to raytrace with to stop it raytracing past the intended block
|
||||
worldIn.setBlockState(pos, Blocks.DIRT.getDefaultState());
|
||||
|
@ -117,16 +118,6 @@ public class IndustrialDrillItem extends DrillItem {
|
|||
return targetBlocks;
|
||||
}
|
||||
|
||||
private void breakBlock(BlockPos pos, World world, PlayerEntity playerIn, ItemStack drill) {
|
||||
BlockState blockState = world.getBlockState(pos);
|
||||
|
||||
if(Energy.of(drill).use(cost)){
|
||||
blockState.getBlock().onBlockRemoved(blockState, world, pos, blockState, true);
|
||||
blockState.getBlock().afterBreak(world, playerIn, pos, blockState, world.getBlockEntity(pos), drill);
|
||||
world.setBlockState(pos, Blocks.AIR.getDefaultState());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean shouldBreak(PlayerEntity playerIn, World worldIn, BlockPos originalPos, BlockPos pos) {
|
||||
if (originalPos.equals(pos)) {
|
||||
return false;
|
||||
|
@ -148,17 +139,13 @@ public class IndustrialDrillItem extends DrillItem {
|
|||
|
||||
// DrillItem
|
||||
@Override
|
||||
public boolean postMine(ItemStack stack, World worldIn, BlockState blockIn, BlockPos pos, LivingEntity entityLiving) {
|
||||
PlayerEntity playerIn = null;
|
||||
if ((entityLiving instanceof PlayerEntity)) {
|
||||
playerIn = (PlayerEntity) entityLiving;
|
||||
}
|
||||
public boolean postMine(ItemStack stack, World worldIn, BlockState stateIn, BlockPos pos, LivingEntity entityLiving) {
|
||||
if(ItemUtils.isActive(stack)){
|
||||
for (BlockPos additionalPos : getTargetBlocks(worldIn, pos, playerIn)) {
|
||||
breakBlock(additionalPos, worldIn, playerIn, stack);
|
||||
for (BlockPos additionalPos : getTargetBlocks(worldIn, pos, entityLiving)) {
|
||||
ToolsUtil.breakBlock(stack, worldIn, additionalPos, entityLiving, cost);
|
||||
}
|
||||
}
|
||||
return super.postMine(stack, worldIn, blockIn, pos, entityLiving);
|
||||
return super.postMine(stack, worldIn, stateIn, pos, entityLiving);
|
||||
}
|
||||
|
||||
// PickaxeItem
|
||||
|
|
|
@ -36,16 +36,13 @@ import net.minecraft.entity.attribute.EntityAttributes;
|
|||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.*;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.world.World;
|
||||
import reborncore.api.items.ItemStackModifiers;
|
||||
import reborncore.common.powerSystem.PowerSystem;
|
||||
import reborncore.common.util.ChatUtils;
|
||||
import reborncore.common.util.ItemDurabilityExtensions;
|
||||
import reborncore.common.util.ItemUtils;
|
||||
import reborncore.common.util.StringUtils;
|
||||
import team.reborn.energy.Energy;
|
||||
import team.reborn.energy.EnergyHolder;
|
||||
import team.reborn.energy.EnergySide;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue