Fixed a lot of NPE's and few duplication glitches

(cherry-pick from other fork)
This commit is contained in:
Arseny Spiridonov committed 2020-09-22 23:52:53 +07:00
1 parent cae72b2db6
commit 6bd68f13b1
12 files changed
+292 -162

No files matched your search

@@ -1,30 +1,36 @@
package tconstruct.tools;
import cpw.mods.fml.common.eventhandler.Event.Result;
import cpw.mods.fml.common.eventhandler.*;
import cpw.mods.fml.common.gameevent.PlayerEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent.ItemCraftedEvent;
import java.util.List;
import net.minecraft.entity.*;
import cpw.mods.fml.common.eventhandler.Event.Result;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent.ItemCraftedEvent;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.monster.*;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.item.*;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.play.server.S14PacketEntity;
import net.minecraft.util.*;
import net.minecraft.util.DamageSource;
import net.minecraft.util.Vec3;
import net.minecraft.world.EnumDifficulty;
import net.minecraftforge.event.entity.living.*;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.event.entity.player.PlayerDropsEvent;
import net.minecraftforge.oredict.*;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.OreDictionary.OreRegisterEvent;
import tconstruct.TConstruct;
import tconstruct.armor.player.TPlayerStats;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.entity.ProjectileBase;
import tconstruct.library.event.*;
import tconstruct.library.event.PartBuilderEvent;
import tconstruct.library.event.ToolBuildEvent;
import tconstruct.library.event.ToolCraftEvent;
import tconstruct.library.tools.*;
import tconstruct.util.ItemHelper;
import tconstruct.util.config.PHConstruct;
@@ -35,6 +41,9 @@ public class TinkerToolEvents
@SubscribeEvent
public void onCrafting (ItemCraftedEvent event)
{
if (event.crafting == null || event.player == null || event.player.worldObj == null || event.craftMatrix == null)
return;
Item item = event.crafting.getItem();
if (!event.player.worldObj.isRemote)
{
@@ -1,17 +1,20 @@
package tconstruct.tools.inventory;
import java.lang.ref.WeakReference;
import net.minecraft.block.Block;
import net.minecraft.entity.player.*;
import net.minecraft.inventory.*;
import net.minecraft.item.*;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import tconstruct.library.crafting.ModifyBuilder;
import tconstruct.library.event.ToolCraftedEvent;
import tconstruct.library.modifier.IModifyable;
import tconstruct.library.tools.AbilityHelper;
import tconstruct.tools.TinkerTools;
import tconstruct.tools.logic.CraftingStationLogic;
@@ -26,6 +29,7 @@ public class CraftingStationContainer extends Container
private int posX;
private int posY;
private int posZ;
private WeakReference[] inventories;
public CraftingStationContainer(InventoryPlayer inventorplayer, CraftingStationLogic logic, int x, int y, int z)
{
@@ -37,6 +41,7 @@ public class CraftingStationContainer extends Container
this.logic = logic;
craftMatrix = new InventoryCraftingStation(this, 3, 3, logic);
craftResult = new InventoryCraftingStationResult(logic);
this.inventories = logic.getInventories();
int row;
int column;
@@ -162,6 +167,10 @@ public class CraftingStationContainer extends Container
Block block = worldObj.getBlock(this.posX, this.posY, this.posZ);
if (block != TinkerTools.craftingStationWood && block != TinkerTools.craftingSlabWood)
return false;
if (!this.logic.isUseableByPlayer(player) || !CraftingStationLogic.isUseableByPlayer(player, this.inventories))
return false;
return player.getDistanceSq((double) this.posX + 0.5D, (double) this.posY + 0.5D, (double) this.posZ + 0.5D) <= 64.0D;
}
@@ -1,14 +1,16 @@
package tconstruct.tools.inventory;
import net.minecraft.block.Block;
import net.minecraft.entity.player.*;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import tconstruct.armor.inventory.SlotOnlyTake;
import tconstruct.library.util.IPattern;
import tconstruct.smeltery.inventory.ActiveContainer;
import tconstruct.tools.TinkerTools;
import tconstruct.tools.logic.*;
import tconstruct.tools.logic.PartBuilderLogic;
import tconstruct.tools.logic.PatternChestLogic;
public class PartCrafterChestContainer extends ActiveContainer
{
@@ -74,9 +76,10 @@ public class PartCrafterChestContainer extends ActiveContainer
ItemStack slotStack = slot.getStack();
stack = slotStack.copy();
if (slotID < logic.getSizeInventory())
int inventorySize = this.inventory.length + this.patternLogic.getSizeInventory();
if (slotID < inventorySize)
{
if (!this.mergeItemStack(slotStack, logic.getSizeInventory() + patternLogic.getSizeInventory(), this.inventorySlots.size(), true))
if (!this.mergeItemStack(slotStack, inventorySize, this.inventorySlots.size(), true))
{
return null;
}
@@ -94,7 +97,7 @@ public class PartCrafterChestContainer extends ActiveContainer
if (slotStack.stackSize == 0)
{
slot.putStack((ItemStack) null);
slot.putStack(null);
logic.tryBuildPart(slotID);
}
slot.onSlotChanged();
@@ -1,11 +1,17 @@
package tconstruct.tools.logic;
import java.lang.ref.WeakReference;
import mantle.blocks.abstracts.InventoryLogic;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.*;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.*;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.world.World;
import tconstruct.tools.inventory.CraftingStationContainer;
@@ -93,6 +99,26 @@ public class CraftingStationLogic extends InventoryLogic implements ISidedInvent
return new int[] {};
}
@Override
public boolean isUseableByPlayer(EntityPlayer player)
{
return isUseableByPlayer(player, this.getInventories()) && super.isUseableByPlayer(player);
}
public static boolean isUseableByPlayer(EntityPlayer player, WeakReference[] inventories) {
for (WeakReference<IInventory> ref : inventories)
{
if (ref != null)
{
IInventory inv = ref.get();
if (inv != null && !inv.isUseableByPlayer(player))
return false;
}
}
return true;
}
@Override
public boolean canInsertItem (int i, ItemStack itemstack, int j)
{
@@ -142,6 +168,11 @@ public class CraftingStationLogic extends InventoryLogic implements ISidedInvent
}
public WeakReference[] getInventories()
{
return new WeakReference[] { this.chest, this.doubleChest, this.patternChest, this.furnace };
}
@Override
public boolean canUpdate ()
{
@@ -2,7 +2,8 @@ package tconstruct.tools.logic;
import mantle.blocks.abstracts.InventoryLogic;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.*;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
@@ -55,13 +56,20 @@ public class StencilTableLogic extends InventoryLogic implements ISidedInventory
{
super.setInventorySlotContents(slot, itemstack);
if (slot == 0) {
if(itemstack != null && StencilBuilder.isBlank(itemstack)) {
if (itemstack != null && StencilBuilder.isBlank(itemstack))
{
super.setInventorySlotContents(1, selectedStack);
} else if(itemstack!=null) {
}
else if (itemstack!=null)
{
ItemStack cpy=itemstack.copy();
cpy.stackSize=1;
super.setInventorySlotContents(1, cpy);
}else super.setInventorySlotContents(1,null);
}
else
{
super.setInventorySlotContents(1,null);
}
}
}
@@ -3,14 +3,14 @@ package tconstruct.tools.logic;
import mantle.blocks.abstracts.InventoryLogic;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.*;
import net.minecraft.item.Item;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import tconstruct.library.crafting.*;
import tconstruct.library.crafting.ModifyBuilder;
import tconstruct.library.crafting.ToolBuilder;
import tconstruct.library.modifier.IModifyable;
import tconstruct.library.tools.ToolCore;
import tconstruct.tools.inventory.ToolStationContainer;
/* Simple class for storing items in the block
@@ -193,7 +193,7 @@ public class ToolStationLogic extends InventoryLogic implements ISidedInventory
@Override
public String getInventoryName ()
{
return null;
return "null";
}
@Override