mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-15 22:33:42 +01:00
parent
d4a4e245bd
commit
4801c6f73b
5 changed files with 25 additions and 86 deletions
|
@ -1,14 +1,7 @@
|
||||||
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;
|
||||||
|
@ -18,16 +11,10 @@ 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) {
|
||||||
|
@ -78,39 +65,4 @@ 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +0,0 @@
|
||||||
package com.simibubi.create.content.curiosities.armor;
|
|
||||||
|
|
||||||
public interface IBackTankRechargeable {
|
|
||||||
|
|
||||||
int maxUses();
|
|
||||||
|
|
||||||
}
|
|
|
@ -6,7 +6,6 @@ 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;
|
||||||
|
@ -27,6 +26,7 @@ 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 implements IBackTankRechargeable {
|
public class ExtendoGripItem extends Item {
|
||||||
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 implements IBackTankRechargeable {
|
||||||
PlayerEntity player = (PlayerEntity) event.getEntityLiving();
|
PlayerEntity player = (PlayerEntity) event.getEntityLiving();
|
||||||
|
|
||||||
CompoundNBT persistentData = player.getPersistentData();
|
CompoundNBT persistentData = player.getPersistentData();
|
||||||
boolean inOff = isActiveExtendoGrip(player.getHeldItemOffhand());
|
boolean inOff = AllItems.EXTENDO_GRIP.isIn(player.getHeldItemOffhand());
|
||||||
boolean inMain = isActiveExtendoGrip(player.getHeldItemMainhand());
|
boolean inMain = AllItems.EXTENDO_GRIP.isIn(player.getHeldItemMainhand());
|
||||||
boolean holdingDualExtendo = inOff && inMain;
|
boolean holdingDualExtendo = inOff && inMain;
|
||||||
boolean holdingExtendo = inOff ^ inMain;
|
boolean holdingExtendo = inOff ^ inMain;
|
||||||
holdingExtendo &= !holdingDualExtendo;
|
holdingExtendo &= !holdingDualExtendo;
|
||||||
|
@ -198,14 +198,17 @@ public class ExtendoGripItem extends Item implements IBackTankRechargeable {
|
||||||
return;
|
return;
|
||||||
if (player.world.isRemote)
|
if (player.world.isRemote)
|
||||||
return;
|
return;
|
||||||
ItemStack main = player.getHeldItemMainhand();
|
Hand hand = Hand.MAIN_HAND;
|
||||||
ItemStack off = player.getHeldItemOffhand();
|
ItemStack extendo = player.getHeldItemMainhand();
|
||||||
for (ItemStack stack : new ItemStack[]{main, off}) {
|
if (!AllItems.EXTENDO_GRIP.isIn(extendo)) {
|
||||||
if (isActiveExtendoGrip(stack)) {
|
extendo = player.getHeldItemOffhand();
|
||||||
if (!BackTankUtil.canAbsorbDamage(player, ((IBackTankRechargeable) stack.getItem()).maxUses()))
|
hand = Hand.OFF_HAND;
|
||||||
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
|
||||||
|
@ -223,8 +226,7 @@ public class ExtendoGripItem extends Item implements IBackTankRechargeable {
|
||||||
return BackTankUtil.showDurabilityBar(stack, maxUses());
|
return BackTankUtil.showDurabilityBar(stack, maxUses());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private static int maxUses() {
|
||||||
public int maxUses() {
|
|
||||||
return AllConfigs.SERVER.curiosities.maxExtendoGripActions.get();
|
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()));
|
.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 = isActiveExtendoGrip(player.getHeldItemOffhand());
|
boolean inOff = AllItems.EXTENDO_GRIP.isIn(player.getHeldItemOffhand());
|
||||||
boolean inMain = isActiveExtendoGrip(player.getHeldItemMainhand());
|
boolean inMain = AllItems.EXTENDO_GRIP.isIn(player.getHeldItemMainhand());
|
||||||
boolean holdingGrip = inOff || inMain;
|
boolean holdingGrip = inOff || inMain;
|
||||||
return holdingGrip;
|
return holdingGrip;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 = !ExtendoGripItem.isActiveExtendoGrip(offhandItem);
|
boolean notInOffhand = !AllItems.EXTENDO_GRIP.isIn(offhandItem);
|
||||||
if (notInOffhand && !ExtendoGripItem.isActiveExtendoGrip(heldItem))
|
if (notInOffhand && !AllItems.EXTENDO_GRIP.isIn(heldItem))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MatrixStack ms = event.getMatrixStack();
|
MatrixStack ms = event.getMatrixStack();
|
||||||
|
|
|
@ -8,7 +8,6 @@ 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;
|
||||||
|
@ -38,7 +37,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 implements IBackTankRechargeable {
|
public class PotatoCannonItem extends ShootableItem {
|
||||||
|
|
||||||
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;
|
||||||
|
@ -78,8 +77,7 @@ public class PotatoCannonItem extends ShootableItem implements IBackTankRecharge
|
||||||
return BackTankUtil.showDurabilityBar(stack, maxUses());
|
return BackTankUtil.showDurabilityBar(stack, maxUses());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private int maxUses() {
|
||||||
public int maxUses() {
|
|
||||||
return AllConfigs.SERVER.curiosities.maxPotatoCannonShots.get();
|
return AllConfigs.SERVER.curiosities.maxPotatoCannonShots.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,9 +98,6 @@ public class PotatoCannonItem extends ShootableItem implements IBackTankRecharge
|
||||||
@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))
|
||||||
|
@ -155,7 +150,8 @@ public class PotatoCannonItem extends ShootableItem implements IBackTankRecharge
|
||||||
player.inventory.deleteStack(itemStack);
|
player.inventory.deleteStack(itemStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
stack.damageItem(1, player, p -> {});
|
if (!BackTankUtil.canAbsorbDamage(player, maxUses()))
|
||||||
|
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)
|
||||||
|
|
Loading…
Reference in a new issue