- Copper Backtank now recharges the durability of pneumatic tools in the wearer's inventory rather than being used as a separate durability source
- Potato Cannon and Extendo Grip now become inactive instead of breaking when running out of durability
This commit is contained in:
reidbhuntley 2021-07-04 21:56:18 -04:00
parent 202f81aa7c
commit 1a273753eb
5 changed files with 86 additions and 25 deletions

View file

@ -1,7 +1,14 @@
package com.simibubi.create.content.curiosities.armor; package com.simibubi.create.content.curiosities.armor;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.google.common.collect.Streams;
import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.config.AllConfigs;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.EquipmentSlotType; import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.BlockItem; import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemGroup;
@ -11,10 +18,16 @@ import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.ActionResultType; import net.minecraft.util.ActionResultType;
import net.minecraft.util.NonNullList; import net.minecraft.util.NonNullList;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
@EventBusSubscriber
public class CopperBacktankItem extends CopperArmorItem { public class CopperBacktankItem extends CopperArmorItem {
public static final int DURABILITY_BAR = 0xefefef; public static final int DURABILITY_BAR = 0xefefef;
public static final int RECHARGES_PER_TICK = 4;
private BlockItem blockItem; private BlockItem blockItem;
public CopperBacktankItem(Properties p_i48534_3_, BlockItem blockItem) { public CopperBacktankItem(Properties p_i48534_3_, BlockItem blockItem) {
@ -41,7 +54,7 @@ public class CopperBacktankItem extends CopperArmorItem {
public void fillItemGroup(ItemGroup p_150895_1_, NonNullList<ItemStack> p_150895_2_) { public void fillItemGroup(ItemGroup p_150895_1_, NonNullList<ItemStack> p_150895_2_) {
if (!isInGroup(p_150895_1_)) if (!isInGroup(p_150895_1_))
return; return;
ItemStack stack = new ItemStack(this); ItemStack stack = new ItemStack(this);
CompoundNBT nbt = new CompoundNBT(); CompoundNBT nbt = new CompoundNBT();
nbt.putInt("Air", AllConfigs.SERVER.curiosities.maxAirInBacktank.get()); nbt.putInt("Air", AllConfigs.SERVER.curiosities.maxAirInBacktank.get());
@ -65,4 +78,39 @@ public class CopperBacktankItem extends CopperArmorItem {
return orCreateTag.getInt("Air"); return orCreateTag.getInt("Air");
} }
@SubscribeEvent
public static void rechargePneumaticTools(TickEvent.PlayerTickEvent event) {
PlayerEntity player = event.player;
if (event.phase != TickEvent.Phase.START)
return;
if (event.side != LogicalSide.SERVER)
return;
if (player.isSpectator())
return;
ItemStack tankStack = BackTankUtil.get(player);
if (tankStack.isEmpty())
return;
PlayerInventory inv = player.inventory;
List<ItemStack> toCharge = Streams.concat(Stream.of(player.getHeldItemMainhand()), inv.offHandInventory.stream(),
inv.armorInventory.stream(), inv.mainInventory.stream())
.filter(s -> s.getItem() instanceof IBackTankRechargeable && s.isDamaged())
.collect(Collectors.toList());
int charges = RECHARGES_PER_TICK;
for (ItemStack stack : toCharge) {
while (stack.isDamaged()) {
if (BackTankUtil.canAbsorbDamage(event.player, ((IBackTankRechargeable) stack.getItem()).maxUses())) {
stack.setDamage(stack.getDamage() - 1);
charges--;
if (charges <= 0)
return;
} else {
return;
}
}
}
}
} }

View file

@ -0,0 +1,7 @@
package com.simibubi.create.content.curiosities.armor;
public interface IBackTankRechargeable {
int maxUses();
}

View file

@ -6,6 +6,7 @@ import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.simibubi.create.AllItems; import com.simibubi.create.AllItems;
import com.simibubi.create.content.curiosities.armor.BackTankUtil; import com.simibubi.create.content.curiosities.armor.BackTankUtil;
import com.simibubi.create.content.curiosities.armor.IBackTankRechargeable;
import com.simibubi.create.foundation.advancement.AllTriggers; import com.simibubi.create.foundation.advancement.AllTriggers;
import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.config.AllConfigs;
import com.simibubi.create.foundation.networking.AllPackets; import com.simibubi.create.foundation.networking.AllPackets;
@ -26,7 +27,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.Rarity; import net.minecraft.item.Rarity;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.DamageSource; import net.minecraft.util.DamageSource;
import net.minecraft.util.Hand;
import net.minecraft.util.LazyValue; import net.minecraft.util.LazyValue;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.BlockRayTraceResult;
@ -50,7 +50,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
@EventBusSubscriber @EventBusSubscriber
public class ExtendoGripItem extends Item { public class ExtendoGripItem extends Item implements IBackTankRechargeable {
private static DamageSource lastActiveDamageSource; private static DamageSource lastActiveDamageSource;
public static final int MAX_DAMAGE = 200; public static final int MAX_DAMAGE = 200;
@ -86,8 +86,8 @@ public class ExtendoGripItem extends Item {
PlayerEntity player = (PlayerEntity) event.getEntityLiving(); PlayerEntity player = (PlayerEntity) event.getEntityLiving();
CompoundNBT persistentData = player.getPersistentData(); CompoundNBT persistentData = player.getPersistentData();
boolean inOff = AllItems.EXTENDO_GRIP.isIn(player.getHeldItemOffhand()); boolean inOff = isActiveExtendoGrip(player.getHeldItemOffhand());
boolean inMain = AllItems.EXTENDO_GRIP.isIn(player.getHeldItemMainhand()); boolean inMain = isActiveExtendoGrip(player.getHeldItemMainhand());
boolean holdingDualExtendo = inOff && inMain; boolean holdingDualExtendo = inOff && inMain;
boolean holdingExtendo = inOff ^ inMain; boolean holdingExtendo = inOff ^ inMain;
holdingExtendo &= !holdingDualExtendo; holdingExtendo &= !holdingDualExtendo;
@ -198,17 +198,14 @@ public class ExtendoGripItem extends Item {
return; return;
if (player.world.isRemote) if (player.world.isRemote)
return; return;
Hand hand = Hand.MAIN_HAND; ItemStack main = player.getHeldItemMainhand();
ItemStack extendo = player.getHeldItemMainhand(); ItemStack off = player.getHeldItemOffhand();
if (!AllItems.EXTENDO_GRIP.isIn(extendo)) { for (ItemStack stack : new ItemStack[]{main, off}) {
extendo = player.getHeldItemOffhand(); if (isActiveExtendoGrip(stack)) {
hand = Hand.OFF_HAND; if (!BackTankUtil.canAbsorbDamage(player, ((IBackTankRechargeable) stack.getItem()).maxUses()))
stack.damageItem(1, player, p -> {});
}
} }
if (!AllItems.EXTENDO_GRIP.isIn(extendo))
return;
final Hand h = hand;
if (!BackTankUtil.canAbsorbDamage(player, maxUses()))
extendo.damageItem(1, player, p -> p.sendBreakAnimation(h));
} }
@Override @Override
@ -226,7 +223,8 @@ public class ExtendoGripItem extends Item {
return BackTankUtil.showDurabilityBar(stack, maxUses()); return BackTankUtil.showDurabilityBar(stack, maxUses());
} }
private static int maxUses() { @Override
public int maxUses() {
return AllConfigs.SERVER.curiosities.maxExtendoGripActions.get(); return AllConfigs.SERVER.curiosities.maxExtendoGripActions.get();
} }
@ -244,7 +242,7 @@ public class ExtendoGripItem extends Item {
public static void bufferLivingAttackEvent(LivingAttackEvent event) { public static void bufferLivingAttackEvent(LivingAttackEvent event) {
// Workaround for removed patch to get the attacking entity. // Workaround for removed patch to get the attacking entity.
lastActiveDamageSource = event.getSource(); lastActiveDamageSource = event.getSource();
DamageSource source = event.getSource(); DamageSource source = event.getSource();
if (source == null) if (source == null)
return; return;
@ -314,9 +312,13 @@ public class ExtendoGripItem extends Item {
.sendToServer(new ExtendoGripInteractionPacket(target, event.getHand(), event.getLocalPos())); .sendToServer(new ExtendoGripInteractionPacket(target, event.getHand(), event.getLocalPos()));
} }
public static boolean isActiveExtendoGrip(ItemStack stack) {
return AllItems.EXTENDO_GRIP.isIn(stack) && stack.getDamage() != stack.getMaxDamage() - 1;
}
public static boolean isHoldingExtendoGrip(PlayerEntity player) { public static boolean isHoldingExtendoGrip(PlayerEntity player) {
boolean inOff = AllItems.EXTENDO_GRIP.isIn(player.getHeldItemOffhand()); boolean inOff = isActiveExtendoGrip(player.getHeldItemOffhand());
boolean inMain = AllItems.EXTENDO_GRIP.isIn(player.getHeldItemMainhand()); boolean inMain = isActiveExtendoGrip(player.getHeldItemMainhand());
boolean holdingGrip = inOff || inMain; boolean holdingGrip = inOff || inMain;
return holdingGrip; return holdingGrip;
} }

View file

@ -59,8 +59,8 @@ public class ExtendoGripRenderHandler {
boolean rightHand = event.getHand() == Hand.MAIN_HAND ^ player.getPrimaryHand() == HandSide.LEFT; boolean rightHand = event.getHand() == Hand.MAIN_HAND ^ player.getPrimaryHand() == HandSide.LEFT;
ItemStack offhandItem = getRenderedOffHandStack(); ItemStack offhandItem = getRenderedOffHandStack();
boolean notInOffhand = !AllItems.EXTENDO_GRIP.isIn(offhandItem); boolean notInOffhand = !ExtendoGripItem.isActiveExtendoGrip(offhandItem);
if (notInOffhand && !AllItems.EXTENDO_GRIP.isIn(heldItem)) if (notInOffhand && !ExtendoGripItem.isActiveExtendoGrip(heldItem))
return; return;
MatrixStack ms = event.getMatrixStack(); MatrixStack ms = event.getMatrixStack();

View file

@ -8,6 +8,7 @@ import com.simibubi.create.AllEntityTypes;
import com.simibubi.create.Create; import com.simibubi.create.Create;
import com.simibubi.create.CreateClient; import com.simibubi.create.CreateClient;
import com.simibubi.create.content.curiosities.armor.BackTankUtil; import com.simibubi.create.content.curiosities.armor.BackTankUtil;
import com.simibubi.create.content.curiosities.armor.IBackTankRechargeable;
import com.simibubi.create.content.curiosities.zapper.ShootableGadgetItemMethods; import com.simibubi.create.content.curiosities.zapper.ShootableGadgetItemMethods;
import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.config.AllConfigs;
import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.AnimationTickHolder;
@ -37,7 +38,7 @@ import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
public class PotatoCannonItem extends ShootableItem { public class PotatoCannonItem extends ShootableItem implements IBackTankRechargeable {
public static ItemStack CLIENT_CURRENT_AMMO = ItemStack.EMPTY; public static ItemStack CLIENT_CURRENT_AMMO = ItemStack.EMPTY;
public static final int MAX_DAMAGE = 100; public static final int MAX_DAMAGE = 100;
@ -77,7 +78,8 @@ public class PotatoCannonItem extends ShootableItem {
return BackTankUtil.showDurabilityBar(stack, maxUses()); return BackTankUtil.showDurabilityBar(stack, maxUses());
} }
private int maxUses() { @Override
public int maxUses() {
return AllConfigs.SERVER.curiosities.maxPotatoCannonShots.get(); return AllConfigs.SERVER.curiosities.maxPotatoCannonShots.get();
} }
@ -98,6 +100,9 @@ public class PotatoCannonItem extends ShootableItem {
@Override @Override
public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand) { public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand) {
ItemStack stack = player.getHeldItem(hand); ItemStack stack = player.getHeldItem(hand);
if (stack.getDamage() == getMaxDamage(stack) - 1)
return ActionResult.pass(stack);
return findAmmoInInventory(world, player, stack).map(itemStack -> { return findAmmoInInventory(world, player, stack).map(itemStack -> {
if (ShootableGadgetItemMethods.shouldSwap(player, stack, hand, this::isCannon)) if (ShootableGadgetItemMethods.shouldSwap(player, stack, hand, this::isCannon))
@ -150,8 +155,7 @@ public class PotatoCannonItem extends ShootableItem {
player.inventory.deleteStack(itemStack); player.inventory.deleteStack(itemStack);
} }
if (!BackTankUtil.canAbsorbDamage(player, maxUses())) stack.damageItem(1, player, p -> {});
stack.damageItem(1, player, p -> p.sendBreakAnimation(hand));
Integer cooldown = Integer cooldown =
findAmmoInInventory(world, player, stack).flatMap(PotatoCannonProjectileTypes::getProjectileTypeOf) findAmmoInInventory(world, player, stack).flatMap(PotatoCannonProjectileTypes::getProjectileTypeOf)