Lathe Container

This commit is contained in:
KitsuShadow
2015-08-21 22:49:51 -04:00
parent 4832b33b0c
commit a42607aab4
9 changed files with 283 additions and 98 deletions

View File

@@ -3,9 +3,7 @@ package nmd.primal.energy.block.lathe;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import nmd.primal.energy.render.RenderID;
import nmd.primal.energy.tileents.TileEntCrank;
import nmd.primal.energy.tileents.TileEntFlintLathe;
import nmd.primal.energy.tileents.TileEntLatheBase;
public class FlintLathe extends LatheBase{
@@ -16,7 +14,7 @@ public class FlintLathe extends LatheBase{
@Override
public TileEntity createNewTileEntity(World world, int i) {
return new TileEntFlintLathe("TileEntFlintLathe");
return new TileEntLatheBase("TileEntFlintLathe");
}

View File

@@ -3,8 +3,13 @@ package nmd.primal.energy.block.lathe;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import nmd.primal.energy.common.ModInfo;
import nmd.primal.energy.render.RenderID;
import nmd.primal.energy.tileents.TileEntLatheBase;
import nmd.primal.energy.util.CustomTab;
public abstract class LatheBase extends BlockContainer implements ITileEntityProvider{
@@ -21,6 +26,55 @@ public abstract class LatheBase extends BlockContainer implements ITileEntityPro
0.9F, 0.75F, 0.9F);
}
public boolean onBlockActivated (World world, int x, int y, int z, EntityPlayer player, int q, float a, float b, float c) {
TileEntLatheBase tileEnt = (TileEntLatheBase) world.getTileEntity(x, y, z);
if(!world.isRemote){
if(player.inventory.getCurrentItem()!=null){
if (tileEnt.getStackInSlot(0)==null){
tileEnt.setInventorySlotContents(0, player.inventory.getCurrentItem());
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
}
if (tileEnt.getStackInSlot(0)!=null){
if(player.inventory.getCurrentItem()!=null){
ItemStack pStack = player.inventory.getCurrentItem().copy();
ItemStack sStack = tileEnt.getStackInSlot(0).copy();
ItemStack sStackTemp = tileEnt.getStackInSlot(0).copy();
if(tileEnt.getStackInSlot(0).stackSize < 64){
sStackTemp.stackSize++;
if ((sStack.getItem().equals(pStack.getItem())) && (sStack.getItemDamage() == pStack.getItemDamage()) ){
tileEnt.setInventorySlotContents(0, sStackTemp);
player.inventory.decrStackSize(player.inventory.currentItem, 1);
}
}
}
}
return true;
}
if (player.isSneaking() && player.inventory.getCurrentItem()==null) {
if(tileEnt.getStackInSlot(0)!=null){
player.inventory.setInventorySlotContents(player.inventory.currentItem, tileEnt.getStackInSlot(0));
tileEnt.setInventorySlotContents(0, null);
}
return true;
}
if (!player.isSneaking()) {
if((player.inventory.getCurrentItem()==null)){
if(tileEnt.getStackInSlot(0)!=null){
ItemStack pStack = tileEnt.getStackInSlot(0).copy();
pStack.stackSize = 1;
world.spawnEntityInWorld(new EntityItem(world, player.posX, player.posY, player.posZ, pStack));
tileEnt.decrStackSize(0, 1);
}
}
return true;
}
}
tileEnt.markForUpdate();
tileEnt.markDirty();
return true;
}
@Override
public int getRenderType() {
return RenderID.latheID;

View File

@@ -0,0 +1,62 @@
package nmd.primal.energy.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import nmd.primal.energy.tileents.TileEntLatheBase;
public class ContainerLathe extends Container{
protected TileEntLatheBase tile;
public boolean canInteractWith(EntityPlayer player) {
return tile.isUseableByPlayer(player);
}
public ContainerLathe (InventoryPlayer inventoryPlayer, TileEntLatheBase te){
tile = te;
addSlotToContainer(new Slot(tile, 0, 80, 34));
addSlotToContainer(new Slot(tile, 1, 80, 34));
bindPlayerInventory(inventoryPlayer);
}
protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 9; j++) {
addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9,
8 + j * 18, 84 + i * 18));
}
}
for (int i = 0; i < 9; i++) {
addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142));
}
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
ItemStack stack = null;
Slot slotObject = (Slot) inventorySlots.get(slot);
if (slotObject != null && slotObject.getHasStack()) {
ItemStack stackInSlot = slotObject.getStack();
stack = stackInSlot.copy();
if (slot < 9) {
if (!this.mergeItemStack(stackInSlot, 9, this.inventorySlots.size(), true)) {
return null;
}
}
else if (!this.mergeItemStack(stackInSlot, 0, 9, false)) {
return null;
}
if (stackInSlot.stackSize == 0) {
slotObject.putStack((ItemStack)null);
} else {
slotObject.onSlotChanged();
}
}
return stack;
}
}

View File

@@ -4,7 +4,7 @@ import cpw.mods.fml.client.registry.ClientRegistry;
import nmd.primal.energy.render.block.RenderCrank;
import nmd.primal.energy.render.block.RenderLathe;
import nmd.primal.energy.tileents.TileEntCrank;
import nmd.primal.energy.tileents.TileEntFlintLathe;
import nmd.primal.energy.tileents.TileEntLatheBase;
public class RenderRegistry {
@@ -12,7 +12,7 @@ public class RenderRegistry {
//MinecraftForgeClient.registerItemRenderer(ModItems.woodenShield, new ItemRenderWoodenShield());
//MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(ModBlocks.emptySoftCrucible), new ItemRendererSECrucible());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntCrank.class, new RenderCrank());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntFlintLathe.class, new RenderLathe());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntLatheBase.class, new RenderLathe());
}
}

View File

@@ -11,8 +11,7 @@ import net.minecraft.world.World;
import net.minecraftforge.client.model.AdvancedModelLoader;
import net.minecraftforge.client.model.IModelCustom;
import nmd.primal.energy.block.ModBlocks;
import nmd.primal.energy.tileents.TileEntCrank;
import nmd.primal.energy.tileents.TileEntFlintLathe;
import nmd.primal.energy.tileents.TileEntLatheBase;
public class RenderLathe extends TileEntitySpecialRenderer {
@@ -28,13 +27,13 @@ public class RenderLathe extends TileEntitySpecialRenderer {
GL11.glPushMatrix();
GL11.glTranslatef((float) x, (float) y, (float) z);
TileEntFlintLathe tile = (TileEntFlintLathe) tileEnt;
TileEntLatheBase tile = (TileEntLatheBase) tileEnt;
renderBlock(tile, tileEnt.getWorldObj(), tileEnt.xCoord,tileEnt.yCoord, tileEnt.zCoord, ModBlocks.flintLathe);
GL11.glPopMatrix();
}
public void renderBlock(TileEntFlintLathe tl, World world, int x, int y,int z, Block block) {
public void renderBlock(TileEntLatheBase tl, World world, int x, int y,int z, Block block) {
GL11.glPushMatrix();

View File

@@ -10,7 +10,7 @@ import net.minecraft.world.World;
public class TileBase extends TileEntity{
private String specName;
protected String specName;
public boolean isPowered;
public TileBase(String name){

View File

@@ -1,86 +0,0 @@
package nmd.primal.energy.tileents;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
public class TileEntFlintLathe extends TileBase implements IInventory {
public TileEntFlintLathe(String name) {
super(name);
// TODO Auto-generated constructor stub
}
@Override
public int getSizeInventory() {
// TODO Auto-generated method stub
return 0;
}
@Override
public ItemStack getStackInSlot(int slot) {
// TODO Auto-generated method stub
return null;
}
@Override
public ItemStack decrStackSize(int slot, int amount) {
// TODO Auto-generated method stub
return null;
}
@Override
public ItemStack getStackInSlotOnClosing(int p_70304_1_) {
// TODO Auto-generated method stub
return null;
}
@Override
public void setInventorySlotContents(int p_70299_1_, ItemStack p_70299_2_) {
// TODO Auto-generated method stub
}
@Override
public String getInventoryName() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean hasCustomInventoryName() {
// TODO Auto-generated method stub
return false;
}
@Override
public int getInventoryStackLimit() {
// TODO Auto-generated method stub
return 0;
}
@Override
public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {
// TODO Auto-generated method stub
return false;
}
@Override
public void openInventory() {
// TODO Auto-generated method stub
}
@Override
public void closeInventory() {
// TODO Auto-generated method stub
}
@Override
public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) {
// TODO Auto-generated method stub
return false;
}
}

View File

@@ -0,0 +1,158 @@
package nmd.primal.energy.tileents;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
public class TileEntLatheBase extends TileBase implements IInventory {
private ItemStack[] inv;
public TileEntLatheBase(String name) {
super(name);
this.inv = new ItemStack[2];
}
@Override
public int getSizeInventory() {
return this.inv.length;
}
@Override
public ItemStack getStackInSlot(int slot) {
return this.inv[slot];
}
@Override
public ItemStack decrStackSize(int slot, int amount) {
if (this.inv[slot] != null)
{
ItemStack itemstack;
if (this.inv[slot].stackSize <= amount)
{
itemstack = this.inv[slot];
this.inv[slot] = null;
this.markForUpdate();
this.markDirty();
return itemstack;
}
itemstack = this.inv[slot].splitStack(amount);
if (this.inv[slot].stackSize == 0)
{
this.inv[slot] = null;
}
this.markForUpdate();
this.markDirty();
return itemstack;
}
this.markForUpdate();
this.markDirty();
return null;
}
@Override
public ItemStack getStackInSlotOnClosing(int slot) {
if (this.inv[slot] != null)
{
ItemStack itemstack = this.inv[slot];
this.inv[slot] = null;
this.markForUpdate();
this.markDirty();
return itemstack;
}
else
{
this.markForUpdate();
this.markDirty();
return null;
}
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
this.inv[slot] = stack;
if (stack != null && stack.stackSize > this.getInventoryStackLimit())
{
stack.stackSize = this.getInventoryStackLimit();
}
this.markForUpdate();
this.markDirty();
}
@Override
public String getInventoryName() {
return this.hasCustomInventoryName() ? this.specName : this.specName;
}
@Override
public boolean hasCustomInventoryName() {
return this.specName != null && this.specName.length() > 0;
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq(this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D) <= 64.0D;
}
@Override
public void openInventory() {}
@Override
public void closeInventory() {}
/*NEEDS TO CHECK AGAINST A SET OF DATA HOLDING LATHE TOOLS AND LATHE INPUTS
* */
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
// TODO Auto-generated method stub
return false;
}
@Override
public void readFromNBT(NBTTagCompound tagCompound)
{
super.readFromNBT(tagCompound);
NBTTagList tagList = tagCompound.getTagList("Inventory", 10);
this.inv = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < tagList.tagCount(); i++) {
NBTTagCompound tag = tagList.getCompoundTagAt(i);
byte slot = tag.getByte("Slot");
if (slot >= 0 && slot < this.inv.length) {
this.inv[slot] = ItemStack.loadItemStackFromNBT(tag);
}
}
if (tagCompound.hasKey("CustomName", 8)) {
this.specName = tagCompound.getString("CustomName");
}
this.isPowered = tagCompound.getBoolean("ISPOWERED");
}
@Override
public void writeToNBT(NBTTagCompound tagCompound)
{
super.writeToNBT(tagCompound);
NBTTagList itemList = new NBTTagList();
for (int i = 0; i < inv.length; i++) {
if (inv[i] != null) {
NBTTagCompound tag = new NBTTagCompound();
tag.setByte("Slot", (byte) i);
this.inv[i].writeToNBT(tag);
itemList.appendTag(tag);
}
}
tagCompound.setTag("Inventory", itemList);
tagCompound.setBoolean("ISPOWERED", this.isPowered);
}
}

View File

@@ -7,6 +7,6 @@ public class TileRegistry {
public static final void init() {
GameRegistry.registerTileEntity(TileEntCrank.class, "TileEntCrank");
GameRegistry.registerTileEntity(TileEntFlintLathe.class, "TileEntFlintLathe");
GameRegistry.registerTileEntity(TileEntLatheBase.class, "TileEntLatheBase");
}
}