Revert "Top-up"

This reverts commit 1a273753
This commit is contained in:
reidbhuntley 2021-07-05 11:32:57 -04:00
parent d4a4e245bd
commit 4801c6f73b
5 changed files with 25 additions and 86 deletions

View file

@ -1,14 +1,7 @@
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;
@ -18,16 +11,10 @@ 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) {
@ -78,39 +65,4 @@ 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;
}
}
}
}
}

View file

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

View file

@ -6,7 +6,6 @@ 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;
@ -27,6 +26,7 @@ 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 implements IBackTankRechargeable {
public class ExtendoGripItem extends Item {
private static DamageSource lastActiveDamageSource;
public static final int MAX_DAMAGE = 200;
@ -86,8 +86,8 @@ public class ExtendoGripItem extends Item implements IBackTankRechargeable {
PlayerEntity player = (PlayerEntity) event.getEntityLiving();
CompoundNBT persistentData = player.getPersistentData();
boolean inOff = isActiveExtendoGrip(player.getHeldItemOffhand());
boolean inMain = isActiveExtendoGrip(player.getHeldItemMainhand());
boolean inOff = AllItems.EXTENDO_GRIP.isIn(player.getHeldItemOffhand());
boolean inMain = AllItems.EXTENDO_GRIP.isIn(player.getHeldItemMainhand());
boolean holdingDualExtendo = inOff && inMain;
boolean holdingExtendo = inOff ^ inMain;
holdingExtendo &= !holdingDualExtendo;
@ -198,14 +198,17 @@ public class ExtendoGripItem extends Item implements IBackTankRechargeable {
return;
if (player.world.isRemote)
return;
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 -> {});
}
Hand hand = Hand.MAIN_HAND;
ItemStack extendo = player.getHeldItemMainhand();
if (!AllItems.EXTENDO_GRIP.isIn(extendo)) {
extendo = player.getHeldItemOffhand();
hand = Hand.OFF_HAND;
}
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
@ -223,8 +226,7 @@ public class ExtendoGripItem extends Item implements IBackTankRechargeable {
return BackTankUtil.showDurabilityBar(stack, maxUses());
}
@Override
public int maxUses() {
private static int maxUses() {
return AllConfigs.SERVER.curiosities.maxExtendoGripActions.get();
}
@ -312,13 +314,9 @@ public class ExtendoGripItem extends Item implements IBackTankRechargeable {
.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 = isActiveExtendoGrip(player.getHeldItemOffhand());
boolean inMain = isActiveExtendoGrip(player.getHeldItemMainhand());
boolean inOff = AllItems.EXTENDO_GRIP.isIn(player.getHeldItemOffhand());
boolean inMain = AllItems.EXTENDO_GRIP.isIn(player.getHeldItemMainhand());
boolean holdingGrip = inOff || inMain;
return holdingGrip;
}

View file

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

View file

@ -8,7 +8,6 @@ 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;
@ -38,7 +37,7 @@ import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
public class PotatoCannonItem extends ShootableItem implements IBackTankRechargeable {
public class PotatoCannonItem extends ShootableItem {
public static ItemStack CLIENT_CURRENT_AMMO = ItemStack.EMPTY;
public static final int MAX_DAMAGE = 100;
@ -78,8 +77,7 @@ public class PotatoCannonItem extends ShootableItem implements IBackTankRecharge
return BackTankUtil.showDurabilityBar(stack, maxUses());
}
@Override
public int maxUses() {
private int maxUses() {
return AllConfigs.SERVER.curiosities.maxPotatoCannonShots.get();
}
@ -100,9 +98,6 @@ public class PotatoCannonItem extends ShootableItem implements IBackTankRecharge
@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))
@ -155,7 +150,8 @@ public class PotatoCannonItem extends ShootableItem implements IBackTankRecharge
player.inventory.deleteStack(itemStack);
}
stack.damageItem(1, player, p -> {});
if (!BackTankUtil.canAbsorbDamage(player, maxUses()))
stack.damageItem(1, player, p -> p.sendBreakAnimation(hand));
Integer cooldown =
findAmmoInInventory(world, player, stack).flatMap(PotatoCannonProjectileTypes::getProjectileTypeOf)