Jump to content

Recommended Posts

Posted

Hey guys, I generally dislike coming here to forums, but I have been struggling to get this to work for hours.

 

My problem is I want to make it so I cannot take out of the 2nd slot (number 1 in the index)

 

BlockExtractinator: (the block)

 

public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
{
	 if (par1World.isRemote){
         return true;
     } else {
         TileEntityExtractinator entity = (TileEntityExtractinator)par1World.getTileEntity(x, y, z);
        if (entity != null){
        	par5EntityPlayer.openGui(Main.instance, Main.instance.guiIdExtractinator, par1World, x, y, z);
        }
         return true;
     }
}

 @Override
     public void breakBlock(World world, int x, int y, int z, Block par5, int par6) {
             dropItems(world, x, y, z);
             super.breakBlock(world, x, y, z, par5, par6);
     }

     private void dropItems(World world, int x, int y, int z){
             Random rand = new Random();

             TileEntity tileEntity = world.getTileEntity(x, y, z);
             if (!(tileEntity instanceof IInventory)) {
                     return;
             }
             IInventory inventory = (IInventory) tileEntity;

             for (int i = 0; i < inventory.getSizeInventory(); i++) {
                     ItemStack item = inventory.getStackInSlot(i);

                     if (item != null && item.stackSize > 0) {
                             float rx = rand.nextFloat() * 0.8F + 0.1F;
                             float ry = rand.nextFloat() * 0.8F + 0.1F;
                             float rz = rand.nextFloat() * 0.8F + 0.1F;

                             EntityItem entityItem = new EntityItem(world,
                                             x + rx, y + ry, z + rz,
                                             new ItemStack(item.getItem(), item.stackSize, item.getItemDamage()));

                             if (item.hasTagCompound()) {
                                     entityItem.getEntityItem().setTagCompound((NBTTagCompound) item.getTagCompound().copy());
                             }

                             float factor = 0.05F;
                             entityItem.motionX = rand.nextGaussian() * factor;
                             entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
                             entityItem.motionZ = rand.nextGaussian() * factor;
                             world.spawnEntityInWorld(entityItem);
                             item.stackSize = 0;
                     }
             }
     }

@Override
public void onBlockExploded(World world, int x, int y, int z, Explosion explosion) {

}

@Override
public TileEntity createNewTileEntity(World var1, int var2) {
	return new TileEntityExtractinator();
}

 

GUI

 

private TileEntityExtractinator extractinator;

public static final ResourceLocation texture = new ResourceLocation(Main.MODID.toLowerCase(), "textures/gui/extractinator.png");

public GuiExtractinator(InventoryPlayer inventoryPlayer, TileEntityExtractinator entity) {
	super(new ContainerExtractinator(inventoryPlayer, entity));

	this.extractinator = entity;

	this.xSize = 176;
	this.ySize = 166;
}

@Override
protected void drawGuiContainerBackgroundLayer(float var1, int var2,
		int var3) {
	GL11.glColor4f(1F, 1F, 1F, 1F);

	Minecraft.getMinecraft().getTextureManager().bindTexture(texture);

	drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
}

@Override
protected void drawGuiContainerForegroundLayer(int var1, int var2) {
	String name = "Extractinator";
	this.fontRendererObj.drawString(name, this.xSize/2 - this.fontRendererObj.getStringWidth(name) /2, 6, 4210752);
	this.fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory").trim(), 8, this.ySize - 96, 4210752);

}

 

TileEntityExtractinator

 

package com.revereor.tileentity;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;

public class TileEntityExtractinator extends TileEntity implements ISidedInventory{

private ItemStack[] slots = new ItemStack[2];

private int extractTime;

private static final int[] slots_top = new int[]{0};
private static final int[] slots_bottom = new int[]{1};
private static final int[] slots_sides = new int[]{};

public int getSizeInventory(){
	return this.slots.length;
}

@Override
public ItemStack getStackInSlot(int var1) {
	return slots[var1];
}

@Override
public ItemStack decrStackSize(int var1, int var2) {
	// TODO Auto-generated method stub
	return null;
}

@Override
public ItemStack getStackInSlotOnClosing(int var1) {
	// TODO Auto-generated method stub
	return null;
}

@Override
public void setInventorySlotContents(int var1, ItemStack var2) {
	slots[var1] = var2;
}

@Override
public String getInventoryName() {
	return "Extractinator";
}

@Override
public boolean hasCustomInventoryName() {
	return true;
}

@Override
public int getInventoryStackLimit() {
	return 64;
}

@Override
public boolean isUseableByPlayer(EntityPlayer var1) {
	// 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

}

public void updateEntity(){
	if(slots[0] != null){

	} else {
		extractTime = 0;
	}
}

@Override
public boolean isItemValidForSlot(int var1, ItemStack var2) {
	return var1 != 1;
}

@Override
public int[] getAccessibleSlotsFromSide(int var1) {
	return var1 == 0 ? slots_bottom : (var1 == 1 ? slots_top : slots_sides);
}

@Override
public boolean canInsertItem(int var1, ItemStack var2, int var3) {
	return this.isItemValidForSlot(var1, var2);
}

@Override
public boolean canExtractItem(int var1, ItemStack var2, int var3) {
	return var3 != 0 || var1 != 1;
}
}

 

Container

 

package com.revereor.container;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;

import com.revereor.tileentity.TileEntityExtractinator;

public class ContainerExtractinator extends Container {

private TileEntityExtractinator extractinator;

public ContainerExtractinator(InventoryPlayer inventory,
		TileEntityExtractinator entity) {
	this.extractinator = entity;

	this.addSlotToContainer(new Slot(entity, 0, 52,35));
	this.addSlotToContainer(new Slot(entity, 1, 116,35));

	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 9; j++){
			this.addSlotToContainer(new Slot(inventory, j + i*9 + 9, j*18+8, i*18+84));
		}
	}
	for(int i = 0; i < 9; i++){
		for(int j = 0; j < 1; j++){
			this.addSlotToContainer(new Slot(inventory, i, 8+i*18, 142));
		}
	}
}

@Override
public boolean canInteractWith(EntityPlayer var1) {
	return true;
}

}

 

Sorry if thats a lot!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.