Follow along with the video below to see how to install our site as a web app on your home screen.
Примечание: This feature may not be available in some browsers.
Уйди, умник.IvanTur написал(а):НУ как бы в ванильном майне нет у нас контейнера, так что код кидай)
package com.minebot.statics.gui;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class ContainerMagnet extends Container
{
private static List<ItemStack> slots = null;
private TileEntityMagnet te;
public ContainerMagnet(IInventory playerInv, TileEntityMagnet te) {
this.te = te;
// Tile Entity, Slot 0-4, Slot IDs 0-4
for(int i = 0; i <= 4; i++)
{
int x = 44 + i * 18;
int y = 20;
addSlotToContainer(new Slot((IInventory) te, i, x, y));
}
// Player Inventory, Slot 9-35, Slot IDs 9-35
for (int y = 0; y < 3; ++y) {
for (int x = 0; x < 9; ++x) {
this.addSlotToContainer(new Slot(playerInv, x + y * 9 + 9, 8 + x * 18, 51 + y * 18));
}
}
// Player Inventory, Slot 0-8, Slot IDs 36-44
for (int x = 0; x < 9; ++x) {
this.addSlotToContainer(new Slot(playerInv, x, 8 + x * 18, 109));
}
}
@Override
public boolean canInteractWith(EntityPlayer playerIn) {
return te.isUseableByPlayer(playerIn);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer playerIn, int fromSlot)
{
ItemStack previous = null;
Slot slot = (Slot) this.inventorySlots.get(fromSlot);
if (slot != null && slot.getHasStack()) {
ItemStack current = slot.getStack();
previous = current.copy();
if (fromSlot < 6) {
if (!this.mergeItemStack(current, 5, 45, true))
return null;
} else {
if (!this.mergeItemStack(current, 0, 5, false))
return null;
}
if (current.stackSize == 0)
slot.putStack((ItemStack) null);
else
slot.onSlotChanged();
if (current.stackSize == previous.stackSize)
return null;
slot.onPickupFromSlot(playerIn, current);
}
return previous;
}
}
@Override
public void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
NBTTagList nbttaglist = compound.getTagList("Items", 10);
this.inv = new ItemStack[this.getSizeInventory()];
if (compound.hasKey("CustomName", 8))
{
this.customName = compound.getString("CustomName");
}
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
int j = nbttagcompound.getByte("Slot") & 255;
if (j >= 0 && j < this.inv.length)
{
this.inv[j] = ItemStack.loadItemStackFromNBT(nbttagcompound);
}
}
}
@Override
public void writeToNBT(NBTTagCompound compound)
{
super.writeToNBT(compound);
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < this.inv.length; ++i)
{
if (this.inv[i] != null)
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setByte("Slot", (byte)i);
this.inv[i].writeToNBT(nbttagcompound);
nbttaglist.appendTag(nbttagcompound);
}
}
compound.setTag("Items", nbttaglist);
if (this.hasCustomName())
{
compound.setString("CustomName", this.customName);
}
}
Не заметил, идиот я.Minebot написал(а):Ниже пролистни :/
Тайл?КонечноMinebot написал(а):Угу. А его надо регистрировать?
GameRegistry.registerTileEntity(TEBlockDecorMonitor.class, "TEBlockDecorMonitor");
ClientRegistry.bindTileEntitySpecialRenderer(TEBlockDecorMonitor.class, new TEMonitorRenderer());
Да эт код тимахи, он у нас гений методов.Minebot написал(а):А что за specialRenderer. Я такого не делал :/
package com.minebot.statics.gui;
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;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IChatComponent;
public class TileEntityMagnet extends TileEntity implements IInventory
{
private String customName;
private ItemStack[] inv;
public TileEntityMagnet(){ inv = new ItemStack[5]; }
@Override
public String getName() {
return "gui.tileentitymagnet";
}
@Override
public boolean hasCustomName() {
return true;
}
@Override
public IChatComponent getDisplayName() {
// TODO Auto-generated method stub
return null;
}
@Override
public int getSizeInventory() {
return inv.length;
}
@Override
public ItemStack getStackInSlot(int index) {
return inv[index];
}
@Override
public ItemStack decrStackSize(int slot, int amt) {
ItemStack stack = getStackInSlot(slot);
if (stack != null) {
if (stack.stackSize <= amt) {
setInventorySlotContents(slot, null);
} else {
stack = stack.splitStack(amt);
if (stack.stackSize == 0) {
setInventorySlotContents(slot, null);
}
}
}
return stack;
}
@Override
public ItemStack removeStackFromSlot(int index) {
if (this.inv[index] != null)
{
ItemStack itemstack = this.inv[index];
this.inv[index] = null;
return itemstack;
}
else
{
return null;
}
}
@Override
public void setInventorySlotContents(int index, ItemStack stack) {
inv[index] = stack;
if (stack != null && stack.stackSize > getInventoryStackLimit()) {
stack.stackSize = getInventoryStackLimit();
}
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return true;
}
@Override
public void openInventory(EntityPlayer player) {
}
@Override
public void closeInventory(EntityPlayer player) {
}
@Override
public void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
NBTTagList nbttaglist = compound.getTagList("Items", 10);
this.inv = new ItemStack[this.getSizeInventory()];
if (compound.hasKey("CustomName", 8))
{
this.customName = compound.getString("CustomName");
}
for (int i = 0; i < nbttaglist.tagCount(); ++i)
{
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
int j = nbttagcompound.getByte("Slot") & 255;
if (j >= 0 && j < this.inv.length)
{
this.inv[j] = ItemStack.loadItemStackFromNBT(nbttagcompound);
}
}
}
@Override
public void writeToNBT(NBTTagCompound compound)
{
super.writeToNBT(compound);
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < this.inv.length; ++i)
{
if (this.inv[i] != null)
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setByte("Slot", (byte)i);
this.inv[i].writeToNBT(nbttagcompound);
nbttaglist.appendTag(nbttagcompound);
}
}
compound.setTag("Items", nbttaglist);
if (this.hasCustomName())
{
compound.setString("CustomName", this.customName);
}
}
@Override
public boolean isItemValidForSlot(int index, ItemStack stack) {
return true;
}
@Override
public int getField(int id) {
// TODO Auto-generated method stub
return 0;
}
@Override
public void setField(int id, int value) {
// TODO Auto-generated method stub
}
@Override
public int getFieldCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void clear() {
for (int i = 0; i < this.inv.length; ++i)
{
this.inv[i] = null;
}
}
}