From 562d333be967ad47cb00b0fdfa973486b4dd2659 Mon Sep 17 00:00:00 2001 From: drcrazy Date: Tue, 24 Dec 2019 11:00:21 +0300 Subject: [PATCH] Active\Inactive switch moved to RC. --- .../industrial/IndustrialChainsawItem.java | 112 +++++++----------- .../tool/industrial/IndustrialDrillItem.java | 25 +--- .../items/tool/industrial/NanosaberItem.java | 25 +--- .../assets/techreborn/lang/en_us.json | 6 - 4 files changed, 46 insertions(+), 122 deletions(-) diff --git a/src/main/java/techreborn/items/tool/industrial/IndustrialChainsawItem.java b/src/main/java/techreborn/items/tool/industrial/IndustrialChainsawItem.java index 379d495ec..ccedce331 100644 --- a/src/main/java/techreborn/items/tool/industrial/IndustrialChainsawItem.java +++ b/src/main/java/techreborn/items/tool/industrial/IndustrialChainsawItem.java @@ -62,7 +62,6 @@ public class IndustrialChainsawItem extends ChainsawItem { private static final Direction[] SEARCH_ORDER = new Direction[]{Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST, Direction.UP}; - // 4M FE max charge with 1k charge rate public IndustrialChainsawItem() { super(ToolMaterials.DIAMOND, TechRebornConfig.industrialChainsawCharge, 1.0F); @@ -70,27 +69,6 @@ public class IndustrialChainsawItem extends ChainsawItem { this.transferLimit = 1000; } - @Environment(EnvType.CLIENT) - @Override - public void appendStacks(ItemGroup par2ItemGroup, DefaultedList itemList) { - if (!isIn(par2ItemGroup)) { - return; - } - InitUtils.initPoweredItems(TRContent.INDUSTRIAL_CHAINSAW, itemList); - } - - @Override - public boolean postMine(ItemStack stack, World worldIn, BlockState blockIn, BlockPos pos, LivingEntity entityLiving) { - List wood = new ArrayList<>(); - if (ItemUtils.isActive(stack)) { - findWood(worldIn, pos, wood, new ArrayList<>()); - wood.stream() - .filter(p -> Energy.of(stack).use(cost)) - .forEach(pos1 -> breakBlock(pos1, stack, worldIn, entityLiving, pos)); - } - return super.postMine(stack, worldIn, blockIn, pos, entityLiving); - } - private void findWood(World world, BlockPos pos, List wood, List leaves){ //Limit the amount of wood to be broken to 64 blocks. if(wood.size() >= 64){ @@ -112,38 +90,57 @@ public class IndustrialChainsawItem extends ChainsawItem { findWood(world, checkPos, wood, leaves); } } - } } + 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 wood = new ArrayList<>(); + if (ItemUtils.isActive(stack)) { + findWood(worldIn, pos, wood, new ArrayList<>()); + wood.stream() + .filter(p -> Energy.of(stack).use(cost)) + .forEach(pos1 -> breakBlock(pos1, stack, worldIn, entityLiving, pos)); + } + return super.postMine(stack, worldIn, blockIn, pos, entityLiving); + } + + // Item + @Environment(EnvType.CLIENT) + @Override + public void appendStacks(ItemGroup par2ItemGroup, DefaultedList itemList) { + if (!isIn(par2ItemGroup)) { + return; + } + InitUtils.initPoweredItems(TRContent.INDUSTRIAL_CHAINSAW, itemList); + } + @Override public TypedActionResult use(final World world, final PlayerEntity player, final Hand hand) { final ItemStack stack = player.getStackInHand(hand); if (player.isSneaking()) { - if (Energy.of(stack).getEnergy() < cost) { - ChatUtils.sendNoSpamMessages(MessageIDs.poweredToolID, new LiteralText( - Formatting.GRAY + StringUtils.t("techreborn.message.nanosaberEnergyErrorTo") + " " - + Formatting.GOLD + StringUtils.t("techreborn.message.nanosaberActivate"))); - } else { - if (!ItemUtils.isActive(stack)) { - if (stack.getTag() == null) { - stack.setTag(new CompoundTag()); - } - stack.getTag().putBoolean("isActive", true); - if (world.isClient) { - ChatUtils.sendNoSpamMessages(MessageIDs.poweredToolID, new LiteralText( - Formatting.GRAY + StringUtils.t("techreborn.message.setTo") + " " - + Formatting.GOLD + StringUtils.t("techreborn.message.nanosaberActive"))); - } - } else { - stack.getOrCreateTag().putBoolean("isActive", false); - if (world.isClient) { - ChatUtils.sendNoSpamMessages(MessageIDs.poweredToolID, new LiteralText( - Formatting.GRAY + StringUtils.t("techreborn.message.setTo") + " " - + Formatting.GOLD + StringUtils.t("techreborn.message.nanosaberInactive"))); - } - } - } + ItemUtils.switchActive(stack, cost, world.isClient, MessageIDs.poweredToolID); return new TypedActionResult<>(ActionResult.SUCCESS, stack); } return new TypedActionResult<>(ActionResult.PASS, stack); @@ -164,25 +161,4 @@ public class IndustrialChainsawItem extends ChainsawItem { public boolean isEffectiveOn(BlockState blockIn) { return Items.DIAMOND_AXE.isEffectiveOn(blockIn); } - - public 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); - } - - } } diff --git a/src/main/java/techreborn/items/tool/industrial/IndustrialDrillItem.java b/src/main/java/techreborn/items/tool/industrial/IndustrialDrillItem.java index 42bd12689..d0e0c883c 100644 --- a/src/main/java/techreborn/items/tool/industrial/IndustrialDrillItem.java +++ b/src/main/java/techreborn/items/tool/industrial/IndustrialDrillItem.java @@ -172,30 +172,7 @@ public class IndustrialDrillItem extends DrillItem { public TypedActionResult use(final World world, final PlayerEntity player, final Hand hand) { final ItemStack stack = player.getStackInHand(hand); if (player.isSneaking()) { - if (Energy.of(stack).getEnergy() < cost) { - ChatUtils.sendNoSpamMessages(MessageIDs.poweredToolID, new LiteralText( - Formatting.GRAY + StringUtils.t("techreborn.message.nanosaberEnergyErrorTo") + " " - + Formatting.GOLD + StringUtils.t("techreborn.message.nanosaberActivate"))); - } else { - if (!ItemUtils.isActive(stack)) { - if (stack.getTag() == null) { - stack.setTag(new CompoundTag()); - } - stack.getOrCreateTag().putBoolean("isActive", true); - if (world.isClient) { - ChatUtils.sendNoSpamMessages(MessageIDs.poweredToolID, new LiteralText( - Formatting.GRAY + StringUtils.t("techreborn.message.setTo") + " " - + Formatting.GOLD + StringUtils.t("techreborn.message.nanosaberActive"))); - } - } else { - stack.getOrCreateTag().putBoolean("isActive", false); - if (world.isClient) { - ChatUtils.sendNoSpamMessages(MessageIDs.poweredToolID, new LiteralText( - Formatting.GRAY + StringUtils.t("techreborn.message.setTo") + " " - + Formatting.GOLD + StringUtils.t("techreborn.message.nanosaberInactive"))); - } - } - } + ItemUtils.switchActive(stack, cost, world.isClient, MessageIDs.poweredToolID); return new TypedActionResult<>(ActionResult.SUCCESS, stack); } return new TypedActionResult<>(ActionResult.PASS, stack); diff --git a/src/main/java/techreborn/items/tool/industrial/NanosaberItem.java b/src/main/java/techreborn/items/tool/industrial/NanosaberItem.java index b188605c8..67d228dec 100644 --- a/src/main/java/techreborn/items/tool/industrial/NanosaberItem.java +++ b/src/main/java/techreborn/items/tool/industrial/NanosaberItem.java @@ -106,30 +106,7 @@ public class NanosaberItem extends SwordItem implements EnergyHolder, ItemDurabi public TypedActionResult use(final World world, final PlayerEntity player, final Hand hand) { final ItemStack stack = player.getStackInHand(hand); if (player.isSneaking()) { - if (Energy.of(stack).getEnergy() < cost) { - ChatUtils.sendNoSpamMessages(MessageIDs.poweredToolID, new LiteralText( - Formatting.GRAY + StringUtils.t("techreborn.message.nanosaberEnergyErrorTo") + " " - + Formatting.GOLD + StringUtils.t("techreborn.message.nanosaberActivate"))); - } else { - if (!ItemUtils.isActive(stack)) { - if (stack.getTag() == null) { - stack.setTag(new CompoundTag()); - } - stack.getTag().putBoolean("isActive", true); - if (world.isClient) { - ChatUtils.sendNoSpamMessages(MessageIDs.poweredToolID, new LiteralText( - Formatting.GRAY + StringUtils.t("techreborn.message.setTo") + " " - + Formatting.GOLD + StringUtils.t("techreborn.message.nanosaberActive"))); - } - } else { - stack.getOrCreateTag().putBoolean("isActive", false); - if (world.isClient) { - ChatUtils.sendNoSpamMessages(MessageIDs.poweredToolID, new LiteralText( - Formatting.GRAY + StringUtils.t("techreborn.message.setTo") + " " - + Formatting.GOLD + StringUtils.t("techreborn.message.nanosaberInactive"))); - } - } - } + ItemUtils.switchActive(stack, cost, world.isClient, MessageIDs.poweredToolID); return new TypedActionResult<>(ActionResult.SUCCESS, stack); } return new TypedActionResult<>(ActionResult.PASS, stack); diff --git a/src/main/resources/assets/techreborn/lang/en_us.json b/src/main/resources/assets/techreborn/lang/en_us.json index 71fcc8973..4fca80604 100644 --- a/src/main/resources/assets/techreborn/lang/en_us.json +++ b/src/main/resources/assets/techreborn/lang/en_us.json @@ -594,15 +594,10 @@ "techreborn.message.allPlayers": "All Players", "techreborn.message.onlyOtherPlayers": "Only Other Players", "techreborn.message.onlyYou": "Only You", - "techreborn.message.nanosaberActive": "Active", - "techreborn.message.nanosaberActivate": "Activate", - "techreborn.message.nanosaberInactive": "Inactive", - "techreborn.message.nanosaberEnergyErrorTo": "Not Enough Energy to", "techreborn.message.daygen": "Panel in direct sunlight", "techreborn.message.nightgen": "Panel in reduced sunlight", "techreborn.message.zerogen": "Panel obstructed from sky", - "techreborn.message.info.item.techreborn.overclocker_upgrade": "Increases speed at the cost of more energy", "techreborn.message.info.item.techreborn.transformer_upgrade": "Increase energy tier", "techreborn.message.info.item.techreborn.energy_storage_upgrade": "Increase energy store", @@ -671,7 +666,6 @@ "techreborn.message.info.block.techreborn.charge_o_mat": "Charges up to 6 items simultaneously", "techreborn.message.info.block.techreborn.chunk_loader": "Keeps chunks loaded, allows machines to run when you're not nearby", - "keys.techreborn.category": "TechReborn Category", "keys.techreborn.config": "Config",