mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-10 03:53:12 +01:00
Top-up
- 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:
parent
202f81aa7c
commit
1a273753eb
5 changed files with 86 additions and 25 deletions
|
@ -1,7 +1,14 @@
|
|||
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 net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.EquipmentSlotType;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
|
@ -11,10 +18,16 @@ import net.minecraft.nbt.CompoundNBT;
|
|||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.NonNullList;
|
||||
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 static final int DURABILITY_BAR = 0xefefef;
|
||||
public static final int RECHARGES_PER_TICK = 4;
|
||||
private 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_) {
|
||||
if (!isInGroup(p_150895_1_))
|
||||
return;
|
||||
|
||||
|
||||
ItemStack stack = new ItemStack(this);
|
||||
CompoundNBT nbt = new CompoundNBT();
|
||||
nbt.putInt("Air", AllConfigs.SERVER.curiosities.maxAirInBacktank.get());
|
||||
|
@ -65,4 +78,39 @@ public class CopperBacktankItem extends CopperArmorItem {
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package com.simibubi.create.content.curiosities.armor;
|
||||
|
||||
public interface IBackTankRechargeable {
|
||||
|
||||
int maxUses();
|
||||
|
||||
}
|
|
@ -6,6 +6,7 @@ import com.google.common.collect.ImmutableMultimap;
|
|||
import com.google.common.collect.Multimap;
|
||||
import com.simibubi.create.AllItems;
|
||||
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.config.AllConfigs;
|
||||
import com.simibubi.create.foundation.networking.AllPackets;
|
||||
|
@ -26,7 +27,6 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.item.Rarity;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.LazyValue;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
|
@ -50,7 +50,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
|
||||
@EventBusSubscriber
|
||||
public class ExtendoGripItem extends Item {
|
||||
public class ExtendoGripItem extends Item implements IBackTankRechargeable {
|
||||
private static DamageSource lastActiveDamageSource;
|
||||
|
||||
public static final int MAX_DAMAGE = 200;
|
||||
|
@ -86,8 +86,8 @@ public class ExtendoGripItem extends Item {
|
|||
PlayerEntity player = (PlayerEntity) event.getEntityLiving();
|
||||
|
||||
CompoundNBT persistentData = player.getPersistentData();
|
||||
boolean inOff = AllItems.EXTENDO_GRIP.isIn(player.getHeldItemOffhand());
|
||||
boolean inMain = AllItems.EXTENDO_GRIP.isIn(player.getHeldItemMainhand());
|
||||
boolean inOff = isActiveExtendoGrip(player.getHeldItemOffhand());
|
||||
boolean inMain = isActiveExtendoGrip(player.getHeldItemMainhand());
|
||||
boolean holdingDualExtendo = inOff && inMain;
|
||||
boolean holdingExtendo = inOff ^ inMain;
|
||||
holdingExtendo &= !holdingDualExtendo;
|
||||
|
@ -198,17 +198,14 @@ public class ExtendoGripItem extends Item {
|
|||
return;
|
||||
if (player.world.isRemote)
|
||||
return;
|
||||
Hand hand = Hand.MAIN_HAND;
|
||||
ItemStack extendo = player.getHeldItemMainhand();
|
||||
if (!AllItems.EXTENDO_GRIP.isIn(extendo)) {
|
||||
extendo = player.getHeldItemOffhand();
|
||||
hand = Hand.OFF_HAND;
|
||||
ItemStack main = player.getHeldItemMainhand();
|
||||
ItemStack off = player.getHeldItemOffhand();
|
||||
for (ItemStack stack : new ItemStack[]{main, off}) {
|
||||
if (isActiveExtendoGrip(stack)) {
|
||||
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
|
||||
|
@ -226,7 +223,8 @@ public class ExtendoGripItem extends Item {
|
|||
return BackTankUtil.showDurabilityBar(stack, maxUses());
|
||||
}
|
||||
|
||||
private static int maxUses() {
|
||||
@Override
|
||||
public int maxUses() {
|
||||
return AllConfigs.SERVER.curiosities.maxExtendoGripActions.get();
|
||||
}
|
||||
|
||||
|
@ -244,7 +242,7 @@ public class ExtendoGripItem extends Item {
|
|||
public static void bufferLivingAttackEvent(LivingAttackEvent event) {
|
||||
// Workaround for removed patch to get the attacking entity.
|
||||
lastActiveDamageSource = event.getSource();
|
||||
|
||||
|
||||
DamageSource source = event.getSource();
|
||||
if (source == null)
|
||||
return;
|
||||
|
@ -314,9 +312,13 @@ public class ExtendoGripItem extends Item {
|
|||
.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) {
|
||||
boolean inOff = AllItems.EXTENDO_GRIP.isIn(player.getHeldItemOffhand());
|
||||
boolean inMain = AllItems.EXTENDO_GRIP.isIn(player.getHeldItemMainhand());
|
||||
boolean inOff = isActiveExtendoGrip(player.getHeldItemOffhand());
|
||||
boolean inMain = isActiveExtendoGrip(player.getHeldItemMainhand());
|
||||
boolean holdingGrip = inOff || inMain;
|
||||
return holdingGrip;
|
||||
}
|
||||
|
|
|
@ -59,8 +59,8 @@ public class ExtendoGripRenderHandler {
|
|||
boolean rightHand = event.getHand() == Hand.MAIN_HAND ^ player.getPrimaryHand() == HandSide.LEFT;
|
||||
|
||||
ItemStack offhandItem = getRenderedOffHandStack();
|
||||
boolean notInOffhand = !AllItems.EXTENDO_GRIP.isIn(offhandItem);
|
||||
if (notInOffhand && !AllItems.EXTENDO_GRIP.isIn(heldItem))
|
||||
boolean notInOffhand = !ExtendoGripItem.isActiveExtendoGrip(offhandItem);
|
||||
if (notInOffhand && !ExtendoGripItem.isActiveExtendoGrip(heldItem))
|
||||
return;
|
||||
|
||||
MatrixStack ms = event.getMatrixStack();
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.simibubi.create.AllEntityTypes;
|
|||
import com.simibubi.create.Create;
|
||||
import com.simibubi.create.CreateClient;
|
||||
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.foundation.config.AllConfigs;
|
||||
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.OnlyIn;
|
||||
|
||||
public class PotatoCannonItem extends ShootableItem {
|
||||
public class PotatoCannonItem extends ShootableItem implements IBackTankRechargeable {
|
||||
|
||||
public static ItemStack CLIENT_CURRENT_AMMO = ItemStack.EMPTY;
|
||||
public static final int MAX_DAMAGE = 100;
|
||||
|
@ -77,7 +78,8 @@ public class PotatoCannonItem extends ShootableItem {
|
|||
return BackTankUtil.showDurabilityBar(stack, maxUses());
|
||||
}
|
||||
|
||||
private int maxUses() {
|
||||
@Override
|
||||
public int maxUses() {
|
||||
return AllConfigs.SERVER.curiosities.maxPotatoCannonShots.get();
|
||||
}
|
||||
|
||||
|
@ -98,6 +100,9 @@ public class PotatoCannonItem extends ShootableItem {
|
|||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand) {
|
||||
ItemStack stack = player.getHeldItem(hand);
|
||||
if (stack.getDamage() == getMaxDamage(stack) - 1)
|
||||
return ActionResult.pass(stack);
|
||||
|
||||
return findAmmoInInventory(world, player, stack).map(itemStack -> {
|
||||
|
||||
if (ShootableGadgetItemMethods.shouldSwap(player, stack, hand, this::isCannon))
|
||||
|
@ -150,8 +155,7 @@ public class PotatoCannonItem extends ShootableItem {
|
|||
player.inventory.deleteStack(itemStack);
|
||||
}
|
||||
|
||||
if (!BackTankUtil.canAbsorbDamage(player, maxUses()))
|
||||
stack.damageItem(1, player, p -> p.sendBreakAnimation(hand));
|
||||
stack.damageItem(1, player, p -> {});
|
||||
|
||||
Integer cooldown =
|
||||
findAmmoInInventory(world, player, stack).flatMap(PotatoCannonProjectileTypes::getProjectileTypeOf)
|
||||
|
|
Loading…
Reference in a new issue