Fix JABBA-related issues with crafting station slots (#54)

* Fix shift-merging tools voiding items

fixes <https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues/11392>

* Change 0-sized ItemStacks into null stacks in crafting station attached slots

Fixes <https://github.com/GTNewHorizons/GT-New-Horizons-Modpack/issues/10425>

* Update buildscript

* spotlessApply
This commit is contained in:
Raven Szewczyk authored and GitHub committed 2022-09-22 20:51:23 +02:00
1 parent 18bfeaff32
commit 39be06c23b
571 files changed
+25959 -28223

No files matched your search

@@ -2,22 +2,16 @@ package tconstruct.library.weaponry;
import cpw.mods.fml.common.Optional;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.util.StatCollector;
import tconstruct.library.TConstructRegistry;
import tconstruct.weaponry.TinkerWeaponry;
import tconstruct.util.Reference;
import mods.battlegear2.api.PlayerEventChild;
import mods.battlegear2.api.weapons.IBattlegearWeapon;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.tools.ToolCore;
import tconstruct.tools.TinkerTools;
import mods.battlegear2.api.PlayerEventChild;
import mods.battlegear2.api.weapons.IBattlegearWeapon;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import java.util.List;
@Optional.InterfaceList({
@Optional.Interface(modid = "battlegear2", iface = "mods.battlegear2.api.weapons.IBattlegearWeapon")
@@ -30,14 +24,14 @@ public abstract class AmmoItem extends ToolCore implements IBattlegearWeapon, IA
@Override
public int getAmmoCount(ItemStack stack) {
if(!stack.hasTagCompound()) return 0;
if (!stack.hasTagCompound()) return 0;
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
return tags.getInteger("Ammo");
}
@Override
public int getMaxAmmo(ItemStack stack) {
if(!stack.hasTagCompound()) return 0;
if (!stack.hasTagCompound()) return 0;
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
return getMaxAmmo(tags);
}
@@ -50,7 +44,7 @@ public abstract class AmmoItem extends ToolCore implements IBattlegearWeapon, IA
@Override
public int addAmmo(int toAdd, ItemStack stack) {
if(!stack.hasTagCompound()) return toAdd;
if (!stack.hasTagCompound()) return toAdd;
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
int oldCount = tags.getInteger("Ammo");
int newCount = Math.min(oldCount + toAdd, getMaxAmmo(stack));
@@ -60,7 +54,7 @@ public abstract class AmmoItem extends ToolCore implements IBattlegearWeapon, IA
@Override
public int consumeAmmo(int toUse, ItemStack stack) {
if(!stack.hasTagCompound()) return toUse;
if (!stack.hasTagCompound()) return toUse;
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
int oldCount = tags.getInteger("Ammo");
int newCount = Math.max(oldCount - toUse, 0);
@@ -70,42 +64,39 @@ public abstract class AmmoItem extends ToolCore implements IBattlegearWeapon, IA
@Override
public void setAmmo(int count, ItemStack stack) {
if(!stack.hasTagCompound()) return;
if (!stack.hasTagCompound()) return;
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
tags.setInteger("Ammo", count);
}
public float getAmmoModifier() { return 0.1f; }
public float getAmmoModifier() {
return 0.1f;
}
public boolean pickupAmmo(ItemStack stack, ItemStack candidate, EntityPlayer player)
{
if(stack.getItem() == null || !stack.hasTagCompound() || !(stack.getItem() instanceof IAmmo))
return false;
public boolean pickupAmmo(ItemStack stack, ItemStack candidate, EntityPlayer player) {
if (stack.getItem() == null || !stack.hasTagCompound() || !(stack.getItem() instanceof IAmmo)) return false;
// check if our candidate fits
if(candidate != null)
{
if (candidate != null) {
// same item
if(testIfAmmoMatches(stack, candidate)) {
if (testIfAmmoMatches(stack, candidate)) {
IAmmo pickedup = ((IAmmo) stack.getItem());
IAmmo ininventory = ((IAmmo) candidate.getItem());
// we can be sure that it's ammo, since stack is ammo and they're equal
int count = pickedup.getAmmoCount(stack);
if(count != ininventory.addAmmo(count, candidate))
return true;
if (count != ininventory.addAmmo(count, candidate)) return true;
}
}
// search the players inventory
for(ItemStack invItem : player.inventory.mainInventory) {
for (ItemStack invItem : player.inventory.mainInventory) {
if (testIfAmmoMatches(stack, invItem)) {
IAmmo pickedup = ((IAmmo) stack.getItem());
IAmmo ininventory = ((IAmmo) invItem.getItem());
// we can be sure that it's ammo, since stack is ammo and they're equal
int count = pickedup.getAmmoCount(stack);
if(count != ininventory.addAmmo(count, invItem))
return true;
if (count != ininventory.addAmmo(count, invItem)) return true;
}
}
@@ -113,15 +104,11 @@ public abstract class AmmoItem extends ToolCore implements IBattlegearWeapon, IA
return false;
}
private boolean testIfAmmoMatches(ItemStack reference, ItemStack candidate)
{
if(candidate == null)
return false;
if(!candidate.hasTagCompound() || !candidate.getTagCompound().hasKey("InfiTool"))
return false;
private boolean testIfAmmoMatches(ItemStack reference, ItemStack candidate) {
if (candidate == null) return false;
if (!candidate.hasTagCompound() || !candidate.getTagCompound().hasKey("InfiTool")) return false;
if(reference.getItem() != candidate.getItem())
return false;
if (reference.getItem() != candidate.getItem()) return false;
NBTTagCompound referenceTags = getComparisonTags(reference);
NBTTagCompound testTags = getComparisonTags(candidate);
@@ -151,22 +138,18 @@ public abstract class AmmoItem extends ToolCore implements IBattlegearWeapon, IA
}
private void copyTag(NBTTagCompound out, NBTTagCompound in, String tag) {
if(in.hasKey(tag))
out.setInteger(tag, in.getInteger(tag));
if (in.hasKey(tag)) out.setInteger(tag, in.getInteger(tag));
}
@Override
public boolean onLeftClickEntity (ItemStack stack, EntityPlayer player, Entity entity)
{
public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) {
// ammo doesn't hurt on smacking stuff with it
return false;
}
@Override
@Optional.Method(modid = "battlegear2")
public boolean sheatheOnBack(ItemStack item)
{
public boolean sheatheOnBack(ItemStack item) {
return true;
}
@@ -178,7 +161,8 @@ public abstract class AmmoItem extends ToolCore implements IBattlegearWeapon, IA
@Override
@Optional.Method(modid = "battlegear2")
public boolean offhandAttackEntity(PlayerEventChild.OffhandAttackEvent event, ItemStack mainhandItem, ItemStack offhandItem) {
public boolean offhandAttackEntity(
PlayerEventChild.OffhandAttackEvent event, ItemStack mainhandItem, ItemStack offhandItem) {
event.cancelParent = false;
event.swingOffhand = false;
event.shouldAttack = false;
@@ -195,7 +179,7 @@ public abstract class AmmoItem extends ToolCore implements IBattlegearWeapon, IA
@Override
@Optional.Method(modid = "battlegear2")
public boolean offhandClickBlock(PlayerInteractEvent event, ItemStack mainhandItem, ItemStack offhandItem) {
event.setCanceled(false);
event.setCanceled(false);
return false;
}
@@ -208,9 +192,10 @@ public abstract class AmmoItem extends ToolCore implements IBattlegearWeapon, IA
@Override
@Optional.Method(modid = "battlegear2")
public boolean allowOffhand(ItemStack mainhand, ItemStack offhand) {
if(offhand == null)
return true;
return (mainhand != null && mainhand.getItem() != TinkerTools.cleaver && mainhand.getItem() != TinkerTools.battleaxe)
if (offhand == null) return true;
return (mainhand != null
&& mainhand.getItem() != TinkerTools.cleaver
&& mainhand.getItem() != TinkerTools.battleaxe)
&& (offhand.getItem() != TinkerTools.cleaver && offhand.getItem() != TinkerTools.battleaxe);
}
}