Active\Inactive switch moved to RC.

This commit is contained in:
drcrazy 2019-12-24 11:00:21 +03:00
parent ecb63b5a6b
commit 562d333be9
4 changed files with 46 additions and 122 deletions

View file

@ -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<ItemStack> 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<BlockPos> 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<BlockPos> wood, List<BlockPos> 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<BlockPos> 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<ItemStack> itemList) {
if (!isIn(par2ItemGroup)) {
return;
}
InitUtils.initPoweredItems(TRContent.INDUSTRIAL_CHAINSAW, itemList);
}
@Override
public TypedActionResult<ItemStack> 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);
}
}
}

View file

@ -172,30 +172,7 @@ public class IndustrialDrillItem extends DrillItem {
public TypedActionResult<ItemStack> 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);

View file

@ -106,30 +106,7 @@ public class NanosaberItem extends SwordItem implements EnergyHolder, ItemDurabi
public TypedActionResult<ItemStack> 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);

View file

@ -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",