2014-06-04 21:44:48 -08:00
|
|
|
package tconstruct.tools.blocks;
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2014-09-09 18:30:15 +10:00
|
|
|
import cpw.mods.fml.relauncher.*;
|
2013-07-26 21:18:53 -07:00
|
|
|
import java.util.List;
|
2013-12-01 12:19:43 +00:00
|
|
|
import mantle.blocks.abstracts.InventoryBlock;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
2014-08-21 07:12:33 -08:00
|
|
|
import net.minecraft.entity.item.EntityItem;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2014-09-09 18:30:15 +10:00
|
|
|
import net.minecraft.item.*;
|
2014-08-21 07:12:33 -08:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2014-09-09 18:30:15 +10:00
|
|
|
import net.minecraft.util.*;
|
|
|
|
|
import net.minecraft.world.*;
|
2013-12-31 11:26:08 -05:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-02-16 14:23:50 -05:00
|
|
|
import tconstruct.TConstruct;
|
|
|
|
|
import tconstruct.library.TConstructRegistry;
|
2014-06-04 21:44:48 -08:00
|
|
|
import tconstruct.tools.TinkerTools;
|
2014-09-09 18:30:15 +10:00
|
|
|
import tconstruct.tools.logic.*;
|
2014-06-04 21:44:48 -08:00
|
|
|
import tconstruct.tools.model.TableRender;
|
2014-02-16 14:23:50 -05:00
|
|
|
import tconstruct.util.config.PHConstruct;
|
2013-07-26 21:18:53 -07:00
|
|
|
|
|
|
|
|
public class ToolStationBlock extends InventoryBlock
|
|
|
|
|
{
|
2014-01-09 04:08:38 -05:00
|
|
|
public ToolStationBlock(Material material)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2013-12-31 11:26:08 -05:00
|
|
|
super(material);
|
2014-02-05 08:28:53 -05:00
|
|
|
this.setCreativeTab(TConstructRegistry.blockTab);
|
|
|
|
|
this.setHardness(2f);
|
|
|
|
|
this.setStepSound(Block.soundTypeWood);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
2014-02-17 00:31:43 -05:00
|
|
|
//Block.hasComparatorInputOverride and Block.getComparatorInputOverride
|
2013-07-26 21:18:53 -07:00
|
|
|
|
|
|
|
|
/* Rendering */
|
|
|
|
|
@Override
|
|
|
|
|
public String[] getTextureNames ()
|
|
|
|
|
{
|
2014-09-09 18:30:15 +10:00
|
|
|
String[] textureNames = { "toolstation_top", "toolstation_side", "toolstation_bottom", "partbuilder_oak_top", "partbuilder_oak_side", "partbuilder_oak_bottom", "partbuilder_spruce_top", "partbuilder_spruce_side", "partbuilder_spruce_bottom", "partbuilder_birch_top", "partbuilder_birch_side", "partbuilder_birch_bottom", "partbuilder_jungle_top", "partbuilder_jungle_side", "partbuilder_jungle_bottom", "patternchest_top", "patternchest_side", "patternchest_bottom", "stenciltable_oak_top", "stenciltable_oak_side", "stenciltable_oak_bottom", "stenciltable_spruce_top", "stenciltable_spruce_side", "stenciltable_spruce_bottom", "stenciltable_birch_top", "stenciltable_birch_side", "stenciltable_birch_bottom", "stenciltable_jungle_top", "stenciltable_jungle_side", "stenciltable_jungle_bottom" };
|
2013-07-26 21:18:53 -07:00
|
|
|
|
|
|
|
|
return textureNames;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-02-17 15:30:13 -05:00
|
|
|
@SideOnly(Side.CLIENT)
|
2014-02-05 08:28:53 -05:00
|
|
|
public IIcon getIcon (int side, int meta)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
if (meta <= 4)
|
|
|
|
|
{
|
|
|
|
|
return icons[meta * 3 + getTextureIndex(side)];
|
|
|
|
|
}
|
|
|
|
|
else if (meta <= 9)
|
|
|
|
|
{
|
|
|
|
|
return icons[15 + getTextureIndex(side)];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return icons[meta * 3 + getTextureIndex(side) - 12];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getTextureIndex (int side)
|
|
|
|
|
{
|
|
|
|
|
if (side == 0)
|
|
|
|
|
return 2;
|
|
|
|
|
if (side == 1)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-02-05 08:28:53 -05:00
|
|
|
public boolean renderAsNormalBlock ()
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-02-05 08:28:53 -05:00
|
|
|
public boolean isOpaqueCube ()
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2013-08-31 05:13:31 -07:00
|
|
|
|
2013-07-27 21:57:41 +10:00
|
|
|
@Override
|
2014-01-19 19:43:10 +11:00
|
|
|
public boolean isSideSolid (IBlockAccess world, int x, int y, int z, ForgeDirection side)
|
2013-08-31 05:13:31 -07:00
|
|
|
{
|
|
|
|
|
return side == ForgeDirection.UP;
|
2013-07-27 21:57:41 +10:00
|
|
|
}
|
2013-08-31 05:13:31 -07:00
|
|
|
|
2013-07-26 21:18:53 -07:00
|
|
|
@Override
|
2014-02-05 08:28:53 -05:00
|
|
|
public int getRenderType ()
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-06-06 19:46:05 -08:00
|
|
|
return TableRender.model;
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-02-05 08:28:53 -05:00
|
|
|
public boolean shouldSideBeRendered (IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-17 00:31:43 -05:00
|
|
|
@Override
|
2013-07-26 21:18:53 -07:00
|
|
|
public AxisAlignedBB getSelectedBoundingBoxFromPool (World world, int x, int y, int z)
|
|
|
|
|
{
|
|
|
|
|
int metadata = world.getBlockMetadata(x, y, z);
|
|
|
|
|
if (metadata == 5)
|
2014-09-09 18:30:15 +10:00
|
|
|
return AxisAlignedBB.getBoundingBox((double) x + this.minX, (double) y + this.minY, (double) z + this.minZ, (double) x + this.maxX, (double) y + this.maxY - 0.125, (double) z + this.maxZ);
|
2014-06-08 14:37:02 -04:00
|
|
|
return AxisAlignedBB.getBoundingBox((double) x + this.minX, (double) y + this.minY, (double) z + this.minZ, (double) x + this.maxX, (double) y + this.maxY, (double) z + this.maxZ);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-02-15 00:29:24 -05:00
|
|
|
public TileEntity createNewTileEntity (World world, int metadata)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
switch (metadata)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
return new ToolStationLogic();
|
|
|
|
|
case 1:
|
2013-08-16 13:51:33 -07:00
|
|
|
return new PartBuilderLogic();
|
2013-07-26 21:18:53 -07:00
|
|
|
case 2:
|
2013-08-16 13:51:33 -07:00
|
|
|
return new PartBuilderLogic();
|
2013-07-26 21:18:53 -07:00
|
|
|
case 3:
|
2013-08-16 13:51:33 -07:00
|
|
|
return new PartBuilderLogic();
|
2013-07-26 21:18:53 -07:00
|
|
|
case 4:
|
2013-08-16 13:51:33 -07:00
|
|
|
return new PartBuilderLogic();
|
2013-07-26 21:18:53 -07:00
|
|
|
case 5:
|
|
|
|
|
return new PatternChestLogic();
|
|
|
|
|
case 6:
|
|
|
|
|
return new PatternChestLogic();
|
|
|
|
|
case 7:
|
|
|
|
|
return new PatternChestLogic();
|
|
|
|
|
case 8:
|
|
|
|
|
return new PatternChestLogic();
|
|
|
|
|
case 9:
|
|
|
|
|
return new PatternChestLogic();
|
|
|
|
|
case 10:
|
|
|
|
|
return new StencilTableLogic();
|
|
|
|
|
case 11:
|
|
|
|
|
return new StencilTableLogic();
|
|
|
|
|
case 12:
|
|
|
|
|
return new StencilTableLogic();
|
|
|
|
|
case 13:
|
|
|
|
|
return new StencilTableLogic();
|
2014-02-17 00:31:43 -05:00
|
|
|
/*case 14:
|
|
|
|
|
return new CastingTableLogic();*/
|
2013-07-26 21:18:53 -07:00
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Integer getGui (World world, int x, int y, int z, EntityPlayer entityplayer)
|
|
|
|
|
{
|
|
|
|
|
int md = world.getBlockMetadata(x, y, z);
|
|
|
|
|
if (md == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
else if (md < 5)
|
|
|
|
|
return 1;
|
|
|
|
|
else if (md < 10)
|
|
|
|
|
return 2;
|
|
|
|
|
else
|
|
|
|
|
return 3;
|
|
|
|
|
|
2014-02-17 00:31:43 -05:00
|
|
|
//return -1;
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Object getModInstance ()
|
|
|
|
|
{
|
|
|
|
|
return TConstruct.instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-02-15 00:29:24 -05:00
|
|
|
public void getSubBlocks (Item id, CreativeTabs tab, List list)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
for (int iter = 0; iter < 6; iter++)
|
|
|
|
|
{
|
2014-02-15 00:29:24 -05:00
|
|
|
list.add(new ItemStack(id, 1, iter));
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int iter = 10; iter < 14; iter++)
|
|
|
|
|
{
|
2014-02-15 00:29:24 -05:00
|
|
|
list.add(new ItemStack(id, 1, iter));
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-21 07:12:33 -08:00
|
|
|
/*@Override
|
2014-02-05 08:28:53 -05:00
|
|
|
public void onBlockPlacedBy (World world, int x, int y, int z, EntityLivingBase par5EntityLiving, ItemStack par6ItemStack)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
if (PHConstruct.freePatterns)
|
|
|
|
|
{
|
|
|
|
|
int meta = world.getBlockMetadata(x, y, z);
|
|
|
|
|
if (meta == 5)
|
|
|
|
|
{
|
2014-02-05 08:28:53 -05:00
|
|
|
PatternChestLogic logic = (PatternChestLogic) world.getTileEntity(x, y, z);
|
2013-07-26 21:18:53 -07:00
|
|
|
for (int i = 1; i <= 13; i++)
|
|
|
|
|
{
|
2014-06-04 21:44:48 -08:00
|
|
|
logic.setInventorySlotContents(i - 1, new ItemStack(TinkerTools.woodPattern, 1, i));
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
2014-06-04 21:44:48 -08:00
|
|
|
logic.setInventorySlotContents(13, new ItemStack(TinkerTools.woodPattern, 1, 22));
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
2014-02-05 08:28:53 -05:00
|
|
|
super.onBlockPlacedBy(world, x, y, z, par5EntityLiving, par6ItemStack);
|
2014-08-21 07:12:33 -08:00
|
|
|
}*/
|
2014-02-27 15:27:44 -05:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getTextureDomain (int textureNameIndex)
|
|
|
|
|
{
|
|
|
|
|
return "tinker";
|
|
|
|
|
}
|
2014-09-09 18:30:15 +10:00
|
|
|
|
2014-08-21 07:12:33 -08:00
|
|
|
/* Keep pattern chest inventory */
|
|
|
|
|
@Override
|
|
|
|
|
public void breakBlock (World par1World, int x, int y, int z, Block blockID, int meta)
|
|
|
|
|
{
|
|
|
|
|
if (meta < 5 || meta > 9)
|
|
|
|
|
super.breakBlock(par1World, x, y, z, blockID, meta);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
par1World.removeTileEntity(x, y, z);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-09-09 18:30:15 +10:00
|
|
|
|
2014-08-21 07:12:33 -08:00
|
|
|
@Override
|
|
|
|
|
public boolean removedByPlayer (World world, EntityPlayer player, int x, int y, int z, boolean willHarvest)
|
|
|
|
|
{
|
|
|
|
|
player.addExhaustion(0.025F);
|
|
|
|
|
|
|
|
|
|
if (!world.isRemote && world.getGameRules().getGameRuleBooleanValue("doTileDrops"))
|
|
|
|
|
{
|
|
|
|
|
int meta = world.getBlockMetadata(x, y, z);
|
|
|
|
|
if (meta >= 5 && meta <= 9)
|
|
|
|
|
{
|
|
|
|
|
ItemStack chest = new ItemStack(this, 1, 5);
|
|
|
|
|
NBTTagCompound inventory = new NBTTagCompound();
|
|
|
|
|
PatternChestLogic logic = (PatternChestLogic) world.getTileEntity(x, y, z);
|
|
|
|
|
logic.writeInventoryToNBT(inventory);
|
|
|
|
|
NBTTagCompound baseTag = new NBTTagCompound();
|
|
|
|
|
baseTag.setTag("Inventory", inventory);
|
|
|
|
|
chest.setTagCompound(baseTag);
|
|
|
|
|
|
|
|
|
|
//Spawn item
|
|
|
|
|
if (!player.capabilities.isCreativeMode || player.isSneaking())
|
|
|
|
|
{
|
|
|
|
|
float f = 0.7F;
|
|
|
|
|
double d0 = (double) (world.rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
|
|
|
|
|
double d1 = (double) (world.rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
|
|
|
|
|
double d2 = (double) (world.rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
|
|
|
|
|
EntityItem entityitem = new EntityItem(world, (double) x + d0, (double) y + d1, (double) z + d2, chest);
|
|
|
|
|
entityitem.delayBeforeCanPickup = 10;
|
|
|
|
|
world.spawnEntityInWorld(entityitem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return world.setBlockToAir(x, y, z);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void harvestBlock (World world, EntityPlayer player, int x, int y, int z, int meta)
|
|
|
|
|
{
|
|
|
|
|
if (meta < 5 || meta > 9)
|
2014-09-09 18:30:15 +10:00
|
|
|
super.harvestBlock(world, player, x, y, z, meta);
|
2014-08-21 07:12:33 -08:00
|
|
|
//Do nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onBlockPlacedBy (World world, int x, int y, int z, EntityLivingBase living, ItemStack stack)
|
|
|
|
|
{
|
|
|
|
|
boolean keptInventory = false;
|
|
|
|
|
if (stack.hasTagCompound())
|
|
|
|
|
{
|
|
|
|
|
NBTTagCompound inventory = stack.getTagCompound().getCompoundTag("Inventory");
|
|
|
|
|
if (inventory != null)
|
|
|
|
|
{
|
|
|
|
|
PatternChestLogic logic = (PatternChestLogic) world.getTileEntity(x, y, z);
|
|
|
|
|
logic.readInventoryFromNBT(inventory);
|
|
|
|
|
logic.xCoord = x;
|
|
|
|
|
logic.yCoord = y;
|
|
|
|
|
logic.zCoord = z;
|
|
|
|
|
keptInventory = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!keptInventory && PHConstruct.freePatterns)
|
|
|
|
|
{
|
|
|
|
|
int meta = world.getBlockMetadata(x, y, z);
|
|
|
|
|
if (meta == 5)
|
|
|
|
|
{
|
|
|
|
|
PatternChestLogic logic = (PatternChestLogic) world.getTileEntity(x, y, z);
|
|
|
|
|
for (int i = 1; i <= 13; i++)
|
|
|
|
|
{
|
|
|
|
|
logic.setInventorySlotContents(i - 1, new ItemStack(TinkerTools.woodPattern, 1, i));
|
|
|
|
|
}
|
|
|
|
|
logic.setInventorySlotContents(13, new ItemStack(TinkerTools.woodPattern, 1, 22));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
super.onBlockPlacedBy(world, x, y, z, living, stack);
|
|
|
|
|
}
|
2014-02-15 00:29:24 -05:00
|
|
|
}
|