diff --git a/src/main/java/tconstruct/armor/player/ArmorExtended.java b/src/main/java/tconstruct/armor/player/ArmorExtended.java index a817bfaf..ac935dc8 100644 --- a/src/main/java/tconstruct/armor/player/ArmorExtended.java +++ b/src/main/java/tconstruct/armor/player/ArmorExtended.java @@ -1,21 +1,22 @@ package tconstruct.armor.player; +import java.io.IOException; +import java.lang.ref.WeakReference; +import java.util.UUID; + import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.network.ByteBufUtils; import cpw.mods.fml.relauncher.Side; import io.netty.buffer.ByteBuf; -import java.io.IOException; -import java.lang.ref.WeakReference; -import java.util.*; - import net.minecraft.enchantment.Enchantment; import net.minecraft.entity.SharedMonsterAttributes; -import net.minecraft.entity.ai.attributes.*; -import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.ai.attributes.AttributeModifier; +import net.minecraft.entity.ai.attributes.IAttributeInstance; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.*; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; import tconstruct.library.accessory.IHealthAccessory; public class ArmorExtended implements IInventory @@ -278,13 +279,15 @@ public class ArmorExtended implements IInventory public void dropItems () { EntityPlayer player = parent.get(); - - for (int i = 0; i < 4; ++i) + if (player != null) { - if (this.inventory[i] != null && !isSoulBounded(this.inventory[i])) + for (int i = 0; i < 4; ++i) { - player.func_146097_a(this.inventory[i], true, false); - this.inventory[i] = null; + if (this.inventory[i] != null && !isSoulBounded(this.inventory[i])) + { + player.func_146097_a(this.inventory[i], true, false); + this.inventory[i] = null; + } } } } diff --git a/src/main/java/tconstruct/armor/player/KnapsackInventory.java b/src/main/java/tconstruct/armor/player/KnapsackInventory.java index 3e825136..a2bf5d62 100644 --- a/src/main/java/tconstruct/armor/player/KnapsackInventory.java +++ b/src/main/java/tconstruct/armor/player/KnapsackInventory.java @@ -1,16 +1,17 @@ package tconstruct.armor.player; +import java.io.IOException; +import java.lang.ref.WeakReference; + import cpw.mods.fml.common.network.ByteBufUtils; import io.netty.buffer.ByteBuf; -import java.io.IOException; -import java.lang.ref.WeakReference; -import java.util.ArrayList; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.*; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; public class KnapsackInventory implements IInventory { @@ -166,12 +167,15 @@ public class KnapsackInventory implements IInventory { EntityPlayer player = parent.get(); - for (int i = 0; i < inventory.length; ++i) + if (player != null) { - if (this.inventory[i] != null) + for (int i = 0; i < inventory.length; ++i) { - player.func_146097_a(this.inventory[i], true, false); - this.inventory[i] = null; + if (this.inventory[i] != null) + { + player.func_146097_a(this.inventory[i], true, false); + this.inventory[i] = null; + } } } } @@ -179,12 +183,16 @@ public class KnapsackInventory implements IInventory public void unequipItems () { EntityPlayer player = parent.get(); - for (int i = 0; i < inventory.length; ++i) + + if (player != null) { - if (this.inventory[i] != null) + for (int i = 0; i < inventory.length; ++i) { - dropItemEntity(player, inventory[i]); - this.inventory[i] = null; + if (this.inventory[i] != null) + { + dropItemEntity(player, inventory[i]); + this.inventory[i] = null; + } } } } diff --git a/src/main/java/tconstruct/armor/player/TPlayerStats.java b/src/main/java/tconstruct/armor/player/TPlayerStats.java index 66fdec21..c24d6433 100644 --- a/src/main/java/tconstruct/armor/player/TPlayerStats.java +++ b/src/main/java/tconstruct/armor/player/TPlayerStats.java @@ -1,6 +1,7 @@ package tconstruct.armor.player; import java.lang.ref.WeakReference; + import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; @@ -73,15 +74,17 @@ public class TPlayerStats implements IExtendedEntityProperties, IPlayerExtendedI public void loadNBTData (NBTTagCompound compound) { NBTTagCompound properties = (NBTTagCompound) compound.getTag(PROP_NAME); - - this.armor.readFromNBT(properties); - this.knapsack.readFromNBT(properties); - this.beginnerManual = properties.getBoolean("beginnerManual"); - this.materialManual = properties.getBoolean("materialManual"); - this.smelteryManual = properties.getBoolean("smelteryManual"); - this.weaponryManual = properties.getBoolean("weaponryManual"); - this.battlesignBonus = properties.getBoolean("battlesignBonus"); - this.derpLevel = properties.getInteger("derpLevel"); + if (properties != null) + { + this.armor.readFromNBT(properties); + this.knapsack.readFromNBT(properties); + this.beginnerManual = properties.getBoolean("beginnerManual"); + this.materialManual = properties.getBoolean("materialManual"); + this.smelteryManual = properties.getBoolean("smelteryManual"); + this.weaponryManual = properties.getBoolean("weaponryManual"); + this.battlesignBonus = properties.getBoolean("battlesignBonus"); + this.derpLevel = properties.getInteger("derpLevel"); + } } @Override diff --git a/src/main/java/tconstruct/library/tools/AbilityHelper.java b/src/main/java/tconstruct/library/tools/AbilityHelper.java index f28a48d7..1dbed5e3 100644 --- a/src/main/java/tconstruct/library/tools/AbilityHelper.java +++ b/src/main/java/tconstruct/library/tools/AbilityHelper.java @@ -1,29 +1,37 @@ package tconstruct.library.tools; +import java.util.Iterator; +import java.util.List; +import java.util.Random; + import cofh.api.energy.IEnergyContainerItem; -import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.eventhandler.Event.Result; -import java.util.*; import net.minecraft.block.Block; import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.entity.*; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; -import net.minecraft.entity.monster.*; +import net.minecraft.entity.monster.EntityCreeper; +import net.minecraft.entity.monster.EntityGhast; +import net.minecraft.entity.monster.IMob; import net.minecraft.entity.passive.EntityWolf; -import net.minecraft.entity.player.*; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.potion.Potion; -import net.minecraft.stats.*; +import net.minecraft.stats.AchievementList; +import net.minecraft.stats.StatList; import net.minecraft.util.*; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.event.entity.player.UseHoeEvent; import tconstruct.TConstruct; -import tconstruct.library.*; +import tconstruct.library.ActiveToolMod; +import tconstruct.library.TConstructRegistry; import tconstruct.library.util.PiercingEntityDamage; public class AbilityHelper @@ -58,7 +66,7 @@ public class AbilityHelper public static boolean onLeftClickEntity (ItemStack stack, EntityLivingBase player, Entity entity, ToolCore tool, int baseDamage) { - if (entity.canAttackWithItem() && stack.hasTagCompound()) + if (entity != null && player != null && entity.canAttackWithItem() && stack.hasTagCompound()) { if (!entity.hitByEntity(player)) // can't attack this entity { diff --git a/src/main/java/tconstruct/mechworks/blocks/BlockLandmine.java b/src/main/java/tconstruct/mechworks/blocks/BlockLandmine.java index 7b36bebf..ae1e7fdc 100644 --- a/src/main/java/tconstruct/mechworks/blocks/BlockLandmine.java +++ b/src/main/java/tconstruct/mechworks/blocks/BlockLandmine.java @@ -1,31 +1,45 @@ package tconstruct.mechworks.blocks; -import cpw.mods.fml.relauncher.*; -import java.util.*; +import static net.minecraftforge.common.util.ForgeDirection.*; + +import java.util.Iterator; +import java.util.List; +import java.util.Random; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import mantle.blocks.BlockUtils; import mantle.world.WorldHelper; -import net.minecraft.block.*; +import net.minecraft.block.Block; +import net.minecraft.block.BlockContainer; import net.minecraft.block.BlockPressurePlate.Sensitivity; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.entity.*; -import net.minecraft.entity.item.*; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.item.EntityTNTPrimed; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.*; +import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.*; -import net.minecraft.world.*; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.IIcon; +import net.minecraft.util.MathHelper; +import net.minecraft.world.Explosion; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import tconstruct.TConstruct; import tconstruct.mechworks.MechworksProxyCommon; import tconstruct.mechworks.landmine.Helper; -import tconstruct.mechworks.logic.*; +import tconstruct.mechworks.logic.LandmineExplodeLogic; +import tconstruct.mechworks.logic.TileEntityLandmine; import tconstruct.world.model.RenderLandmine; -import static net.minecraftforge.common.util.ForgeDirection.*; - /** * * @author fuj1n @@ -442,16 +456,17 @@ public class BlockLandmine extends BlockContainer protected int getMineState (World par1World, int par2, int par3, int par4) { - TileEntityLandmine te = (TileEntityLandmine) par1World.getTileEntity(par2, par3, par4); - - Sensitivity triggerType; - + TileEntity tileEntity = par1World.getTileEntity(par2, par3, par4); // Change to return 1 if you want the landmine to blow up when the block // holding it is broken - if (te == null) + if (!(tileEntity instanceof TileEntityLandmine)) { return 0; } + + TileEntityLandmine te = (TileEntityLandmine)tileEntity; + Sensitivity triggerType; + switch (te.triggerType) { case 0: diff --git a/src/main/java/tconstruct/smeltery/logic/SmelteryLogic.java b/src/main/java/tconstruct/smeltery/logic/SmelteryLogic.java index ffb2d643..63364fef 100644 --- a/src/main/java/tconstruct/smeltery/logic/SmelteryLogic.java +++ b/src/main/java/tconstruct/smeltery/logic/SmelteryLogic.java @@ -1,30 +1,47 @@ package tconstruct.smeltery.logic; -import cpw.mods.fml.relauncher.*; -import java.util.*; -import mantle.blocks.abstracts.*; -import mantle.blocks.iface.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import mantle.blocks.abstracts.InventoryLogic; +import mantle.blocks.abstracts.MultiServantLogic; +import mantle.blocks.iface.IActiveLogic; +import mantle.blocks.iface.IFacingLogic; +import mantle.blocks.iface.IMasterLogic; +import mantle.blocks.iface.IServantLogic; import mantle.world.CoordTuple; import net.minecraft.block.Block; -import net.minecraft.entity.*; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; -import net.minecraft.entity.monster.*; -import net.minecraft.entity.passive.*; -import net.minecraft.entity.player.*; -import net.minecraft.init.Blocks; +import net.minecraft.entity.monster.EntityEnderman; +import net.minecraft.entity.monster.EntityIronGolem; +import net.minecraft.entity.passive.EntityHorse; +import net.minecraft.entity.passive.EntityVillager; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.*; -import net.minecraft.network.*; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.*; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.DamageSource; +import net.minecraft.util.MathHelper; import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.*; import tconstruct.TConstruct; import tconstruct.library.crafting.Smeltery; -import tconstruct.smeltery.*; +import tconstruct.smeltery.SmelteryDamageSource; +import tconstruct.smeltery.TinkerSmeltery; import tconstruct.smeltery.inventory.SmelteryContainer; import tconstruct.util.config.PHConstruct; @@ -328,67 +345,74 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci AxisAlignedBB box = AxisAlignedBB.getBoundingBox(minPos.x, minPos.y, minPos.z, maxPos.x + 1, minPos.y + layers, maxPos.z + 1); - List list = worldObj.getEntitiesWithinAABB(Entity.class, box); - for (Object o : list) + List list = worldObj.getEntitiesWithinAABB(Entity.class, box); + for (Entity o : list) { + if (o.isDead) + return; + if (moltenMetal.size() >= 1) { + Fluid fluid = null; + int amount = 0; + float damage = 5; + if (o instanceof EntityVillager && PHConstruct.meltableVillagers) { EntityVillager villager = (EntityVillager) o; - if (villager.attackEntityFrom(new SmelteryDamageSource(), 5)) - { - if (currentLiquid + 40 < maxLiquid) - { - int amount = villager.isChild() ? 5 : 40; - this.fill(new FluidStack(TinkerSmeltery.moltenEmeraldFluid, amount), true); - } - } + fluid = TinkerSmeltery.moltenEmeraldFluid; + amount = villager.isChild() ? 5 : 40; } else if (o instanceof EntityEnderman) { - EntityEnderman villager = (EntityEnderman) o; - if (villager.attackEntityFrom(new SmelteryDamageSource(), 5)) - { - if (currentLiquid + 125 < maxLiquid) - { - this.fill(new FluidStack(TinkerSmeltery.moltenEnderFluid, 125), true); - } - } + fluid = TinkerSmeltery.moltenEnderFluid; + amount = 125; } else if (o instanceof EntityIronGolem) { - EntityIronGolem golem = (EntityIronGolem) o; - if (golem.attackEntityFrom(new SmelteryDamageSource(), 5)) - { - if (currentLiquid + 40 < maxLiquid) - { - this.fill(new FluidStack(TinkerSmeltery.moltenIronFluid, 40), true); - } - } + fluid = TinkerSmeltery.moltenIronFluid; + amount = 40; } else if (o instanceof EntityHorse && PHConstruct.meltableHorses) { - EntityHorse horse = (EntityHorse) o; - if (horse.attackEntityFrom(new SmelteryDamageSource(), 5)) - { - if (currentLiquid + 108 < maxLiquid) - { - this.fill(new FluidStack(TinkerSmeltery.glueFluid, 108), true); - } - } + fluid = TinkerSmeltery.glueFluid; + amount = 108; } else if (o instanceof EntityLivingBase) { EntityLivingBase living = (EntityLivingBase) o; - if (!living.isDead && living.attackEntityFrom(new SmelteryDamageSource(), 5)) + fluid = TinkerSmeltery.bloodFluid; + amount = living.isChild() || living instanceof EntityPlayer ? 5 : 40; + } + + if (fluid != null && amount > 0 && damage > 0) + { + boolean canFill = false; + + if (o instanceof EntityLivingBase) { - if (currentLiquid + 40 < maxLiquid) + int freeLiquid = Math.max(0, this.maxLiquid - this.currentLiquid - 1); + if (freeLiquid > 0) { - int amount = (living.isChild() || living instanceof EntityPlayer) ? 5 : 40; - this.fill(new FluidStack(TinkerSmeltery.bloodFluid, amount), true); + int freeQuants = MathHelper.floor_float((float) freeLiquid / amount); + if (freeQuants > 0) + { + float health = ((EntityLivingBase) o).getHealth(); + int quantsAmount = MathHelper.ceiling_float_int(health / damage); + if (quantsAmount > 0) + { + int quantsToBeAdded = Math.min(freeQuants, quantsAmount); + amount = quantsToBeAdded * amount; + canFill = o.attackEntityFrom(DamageSource.outOfWorld, 9999); + } + } } } + else + canFill = o.attackEntityFrom(new SmelteryDamageSource(), damage); + + if (canFill && amount > 0) + this.fill(new FluidStack(fluid, amount), true); } } else if (PHConstruct.throwableSmeltery && o instanceof EntityItem) @@ -753,9 +777,9 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci int xd1 = 1, xd2 = 1; // x-difference for (int i = 1; i < MAX_SMELTERY_SIZE; i++) // don't check farther than needed { - if (worldObj.getBlock(x - xd1, y, z) == null || worldObj.isAirBlock(x - xd1, y, z)) + if (this.worldObj.isAirBlock(x - xd1, y, z)) xd1++; - else if (worldObj.getBlock(x + xd2, y, z) == null || worldObj.isAirBlock(x + xd2, y, z)) + else if (this.worldObj.isAirBlock(x + xd2, y, z)) xd2++; // if one side hit a wall and the other didn't we might have to center our x-position again @@ -778,9 +802,9 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci int zd1 = 1, zd2 = 1; for (int i = 1; i < MAX_SMELTERY_SIZE; i++) // don't check farther than needed { - if (worldObj.getBlock(x, y, z - zd1) == null || worldObj.isAirBlock(x, y, z - zd1)) + if (this.worldObj.isAirBlock(x, y, z - zd1)) zd1++; - else if (worldObj.getBlock(x, y, z + zd2) == null || worldObj.isAirBlock(x, y, z + zd2)) + else if (this.worldObj.isAirBlock(x, y, z + zd2)) zd2++; // if one side hit a wall and the other didn't we might have to center our x-position again @@ -885,9 +909,10 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci { for (int zPos = zMin + 1; zPos <= zMax - 1; zPos++) { - block = worldObj.getBlock(xPos, y, zPos); - if (block != null && !worldObj.isAirBlock(xPos, y, zPos)) + if (!this.worldObj.isAirBlock(xPos, y, zPos)) + { return false; + } } } @@ -940,7 +965,7 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci { // regular check failed, maybe it's the bottom? Block block = worldObj.getBlock(x, y, z); - if (block != null && !worldObj.isAirBlock(x, y, z)) + if (!block.isAir(this.worldObj, x, y, z)) if (validBlockID(block)) return validateBottom(x, y, z, sides, count); @@ -960,21 +985,29 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci int zMax = z + sides[3] - 1; // Check inside - for (int xPos = xMin; xPos <= xMax; xPos++) - { - for (int zPos = zMin; zPos <= zMax; zPos++) + if (y >= 0 && y < 256) { + for (int xPos = xMin; xPos <= xMax; xPos++) { - if (validBlockID(worldObj.getBlock(xPos, y, zPos)) && (worldObj.getBlockMetadata(xPos, y, zPos) >= 2)) { - TileEntity te = worldObj.getTileEntity(xPos, y, zPos); + for (int zPos = zMin; zPos <= zMax; zPos++) + { + Chunk chunk = this.worldObj.getChunkFromBlockCoords(xPos, zPos); + if (chunk == null) + continue; - if (te instanceof MultiServantLogic) { - MultiServantLogic servant = (MultiServantLogic) te; - if (servant.hasValidMaster()) { - if (servant.verifyMaster(this, worldObj, this.xCoord, this.yCoord, this.zCoord)) + int xx = xPos & 15; + int zz = zPos & 15; + if (this.validBlockID(chunk.getBlock(xx, y, zz)) && chunk.getBlockMetadata(xx, y, zz) >= 2) { + TileEntity te = worldObj.getTileEntity(xPos, y, zPos); + + if (te instanceof MultiServantLogic) { + MultiServantLogic servant = (MultiServantLogic) te; + if (servant.hasValidMaster()) { + if (servant.verifyMaster(this, worldObj, this.xCoord, this.yCoord, this.zCoord)) + bottomBricks++; + } else { + servant.overrideMaster(this.xCoord, this.yCoord, this.zCoord); bottomBricks++; - } else { - servant.overrideMaster(this.xCoord, this.yCoord, this.zCoord); - bottomBricks++; + } } } } diff --git a/src/main/java/tconstruct/tools/TinkerToolEvents.java b/src/main/java/tconstruct/tools/TinkerToolEvents.java index 0990e735..96df7a69 100644 --- a/src/main/java/tconstruct/tools/TinkerToolEvents.java +++ b/src/main/java/tconstruct/tools/TinkerToolEvents.java @@ -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) { diff --git a/src/main/java/tconstruct/tools/inventory/CraftingStationContainer.java b/src/main/java/tconstruct/tools/inventory/CraftingStationContainer.java index 2ee71567..5f72eafe 100644 --- a/src/main/java/tconstruct/tools/inventory/CraftingStationContainer.java +++ b/src/main/java/tconstruct/tools/inventory/CraftingStationContainer.java @@ -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; } diff --git a/src/main/java/tconstruct/tools/inventory/PartCrafterChestContainer.java b/src/main/java/tconstruct/tools/inventory/PartCrafterChestContainer.java index 3aec9393..990ba5c4 100644 --- a/src/main/java/tconstruct/tools/inventory/PartCrafterChestContainer.java +++ b/src/main/java/tconstruct/tools/inventory/PartCrafterChestContainer.java @@ -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(); diff --git a/src/main/java/tconstruct/tools/logic/CraftingStationLogic.java b/src/main/java/tconstruct/tools/logic/CraftingStationLogic.java index 02e2e7e0..f4469507 100644 --- a/src/main/java/tconstruct/tools/logic/CraftingStationLogic.java +++ b/src/main/java/tconstruct/tools/logic/CraftingStationLogic.java @@ -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 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 () { diff --git a/src/main/java/tconstruct/tools/logic/StencilTableLogic.java b/src/main/java/tconstruct/tools/logic/StencilTableLogic.java index 65c74a33..4530d7f0 100644 --- a/src/main/java/tconstruct/tools/logic/StencilTableLogic.java +++ b/src/main/java/tconstruct/tools/logic/StencilTableLogic.java @@ -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); + } } } diff --git a/src/main/java/tconstruct/tools/logic/ToolStationLogic.java b/src/main/java/tconstruct/tools/logic/ToolStationLogic.java index fe815e88..5ea0571d 100644 --- a/src/main/java/tconstruct/tools/logic/ToolStationLogic.java +++ b/src/main/java/tconstruct/tools/logic/ToolStationLogic.java @@ -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