Сделал я пару блок-контейнеров, в итоге у них всех общие слоты, причём не важно, ставить одинаковые блоки или разные, слоты в них всё равно будут общими ( примерно как в эндер-сундуке). Как это исправить?
Так же при попытке поставить
Потом пробовал ещё делать через этот слот, опять же просто зависает.
Блок 1:
public class OakBox extends BlockContainer implements IHasModel {
public static final PropertyDirection FACING = BlockHorizontal.FACING;
private static boolean keepInventory;
public OakBox(String name) {
super(Material.WOOD);
setUnlocalizedName(name);
setRegistryName(name);
setHardness(5.0F);
setHarvestLevel("axe", 0);
setResistance(4.0F);
setSoundType(SoundType.WOOD);
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
BlockInit.BLOCKS.add(this);
ItemInit.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
}
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
return Item.getItemFromBlock(BlockInit.OAK_BOX);
}
@Override
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) {
return new ItemStack(BlockInit.OAK_BOX);
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if(!worldIn.isRemote) {
playerIn.openGui(Main.instance, Reference.GUI_OAK_BOX , worldIn, pos.getX(), pos.getY(), pos.getZ());
}
return true;
}
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
{
this.setDefaultFacing(worldIn, pos, state);
}
private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state)
{
if (!worldIn.isRemote)
{
IBlockState iblockstate = worldIn.getBlockState(pos.north());
IBlockState iblockstate1 = worldIn.getBlockState(pos.south());
IBlockState iblockstate2 = worldIn.getBlockState(pos.west());
IBlockState iblockstate3 = worldIn.getBlockState(pos.east());
EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
if (enumfacing == EnumFacing.NORTH && iblockstate.isFullBlock() && !iblockstate1.isFullBlock())
{
enumfacing = EnumFacing.SOUTH;
}
else if (enumfacing == EnumFacing.SOUTH && iblockstate1.isFullBlock() && !iblockstate.isFullBlock())
{
enumfacing = EnumFacing.NORTH;
}
else if (enumfacing == EnumFacing.WEST && iblockstate2.isFullBlock() && !iblockstate3.isFullBlock())
{
enumfacing = EnumFacing.EAST;
}
else if (enumfacing == EnumFacing.EAST && iblockstate3.isFullBlock() && !iblockstate2.isFullBlock())
{
enumfacing = EnumFacing.WEST;
}
worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);
}
}
public static void setState(boolean active, World worldIn, BlockPos pos) {
IBlockState state = worldIn.getBlockState(pos);
TileEntity tileentity = worldIn.getTileEntity(pos);
keepInventory = true;
if(active) {
worldIn.setBlockState(pos, BlockInit.OAK_BOX.getDefaultState().withProperty(FACING, state.getValue(FACING)), 3);
worldIn.setBlockState(pos, BlockInit.OAK_BOX.getDefaultState().withProperty(FACING, state.getValue(FACING)), 3);
}
else {
worldIn.setBlockState(pos, BlockInit.OAK_BOX.getDefaultState().withProperty(FACING, state.getValue(FACING)), 3);
worldIn.setBlockState(pos, BlockInit.OAK_BOX.getDefaultState().withProperty(FACING, state.getValue(FACING)), 3);
}
keepInventory = false;
if(tileentity != null) {
tileentity.validate();
worldIn.setTileEntity(pos, tileentity);
}
}
@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {
return new TileEntityOakBox();
}
@Override
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
}
@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
worldIn.setBlockState(pos, this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
}
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
if (!keepInventory)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityOakBox)
{
InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityOakBox)tileentity);
}
}
super.breakBlock(worldIn, pos, state);
}
@Override
public EnumBlockRenderType getRenderType(IBlockState state) {
return EnumBlockRenderType.MODEL;
}
@Override
public IBlockState withRotation(IBlockState state, Rotation rot) {
return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}
@Override
public IBlockState withMirror(IBlockState state, Mirror mirrorIn) {
return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, new IProperty[] {FACING});
}
@Override
public IBlockState getStateFromMeta(int meta) {
EnumFacing facing = EnumFacing.getFront(meta);
if(facing.getAxis() == EnumFacing.Axis.Y) facing = EnumFacing.NORTH;
return this.getDefaultState().withProperty(FACING, facing);
}
@Override
public int getMetaFromState(IBlockState state) {
return ((EnumFacing)state.getValue(FACING)).getIndex();
}
@Override
public void registerModels() {
Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");
}
}
Контейнер 1:
public class ContainerOakBox extends Container {
private final TileEntityOakBox tileentity;
public ContainerOakBox(InventoryPlayer player, TileEntityOakBox tileentity) {
this.tileentity = tileentity;
for(int y = 0; y < 3; y++) {
for(int x = 0; x < 9; x++) {
this.addSlotToContainer(new Slot(player, x + y*9 + 9, 8 + x*18, 64 + y*18));
}
}
for(int x = 0; x <9; x++) {
this.addSlotToContainer(new Slot(player, x, 8 + x*18, 122));
}
this.addSlotToContainer(new Slot(player, 36, 71, 18));
this.addSlotToContainer(new Slot(player, 37, 89, 18));
this.addSlotToContainer(new Slot(player, 38, 71, 36));
this.addSlotToContainer(new Slot(player, 39, 89, 36));
}
@Override
public void addListener(IContainerListener listener) {
super.addListener(listener);
listener.sendAllWindowProperties(this, this.tileentity);
}
@Override
public boolean canInteractWith(EntityPlayer playerIn) {
return this.tileentity.isUsableByPlayer(playerIn);
}
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.inventorySlots.get(index);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (index >= 0 && index < 36)
{
if (!this.mergeItemStack(itemstack1, 36, 40, false))
{
return ItemStack.EMPTY;
}
}
else if (index >= 36 && index < 40)
{
if (!this.mergeItemStack(itemstack1, 0, 36, false))
{
return ItemStack.EMPTY;
}
}
else if (!this.mergeItemStack(itemstack1, 9, 45, false))
{
return ItemStack.EMPTY;
}
if (itemstack1.isEmpty())
{
slot.putStack(ItemStack.EMPTY);
}
else
{
slot.onSlotChanged();
}
if (itemstack1.getCount() == itemstack.getCount())
{
return ItemStack.EMPTY;
}
ItemStack itemstack2 = slot.onTake(playerIn, itemstack1);
if (index == 0)
{
playerIn.dropItem(itemstack2, false);
}
}
return itemstack;
}
}
Гуи 1:
public class GuiOakBox extends GuiContainer {
private static final ResourceLocation TEXTURES = new ResourceLocation(Reference.MODID + ":textures/gui/gui_wooden_box.png");
private final InventoryPlayer player;
private final TileEntityOakBox tileentity;
public GuiOakBox(InventoryPlayer player, TileEntityOakBox tileentity) {
super(new ContainerOakBox(player, tileentity));
this.player = player;
this.tileentity = tileentity;
this.xSize = 176;
this.ySize = 146;
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
String tileName = this.tileentity.getDisplayName().getUnformattedText();
this.fontRenderer.drawString(tileName, this.xSize / 2 - this.fontRenderer.getStringWidth(tileName) / 2, 6, 0);
this.fontRenderer.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 0);
}
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
super.drawScreen(mouseX, mouseY, partialTicks);
this.renderHoveredToolTip(mouseX, mouseY);
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
this.mc.getTextureManager().bindTexture(TEXTURES);
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
}
}
ТайлЭнтити 1:
public class TileEntityOakBox extends TileEntity implements IInventory {
private NonNullList<ItemStack> inventory = NonNullList.<ItemStack>withSize(4, ItemStack.EMPTY);
private String customName;
@Override
public String getName() {
return this.hasCustomName() ? this.customName : "container.oak_box";
}
@Override
public boolean hasCustomName() {
return this.customName != null && !this.customName.isEmpty();
}
public void setCustomName(String customName) {
this.customName = customName;
}
@Override
public ITextComponent getDisplayName() {
return this.hasCustomName() ? new TextComponentString(this.getName()) : new TextComponentTranslation(this.getName());
}
@Override
public int getSizeInventory() {
return this.inventory.size();
}
@Override
public boolean isEmpty() {
for(ItemStack stack : this.inventory) {
if(!stack.isEmpty()) return false;
}
return true;
}
@Override
public ItemStack getStackInSlot(int index) {
return (ItemStack)this.inventory.get(index);
}
@Override
public ItemStack decrStackSize(int index, int count) {
return ItemStackHelper.getAndSplit(this.inventory, index, count);
}
@Override
public ItemStack removeStackFromSlot(int index) {
return ItemStackHelper.getAndRemove(this.inventory, index);
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public boolean isUsableByPlayer(EntityPlayer player) {
return this.world.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64;
}
@Override
public void readFromNBT(NBTTagCompound compound) {
super.readFromNBT(compound);
ItemStackHelper.loadAllItems(compound, this.inventory);
if(compound.hasKey("CustomName", 8)) this.setCustomName(compound.getString("CustomName"));
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
super.writeToNBT(compound);
ItemStackHelper.saveAllItems(compound, this.inventory);
if(this.hasCustomName()) compound.setString("CustomName", this.customName);
return compound;
}
@Override
public void openInventory(EntityPlayer player) { }
@Override
public void closeInventory(EntityPlayer player) {}
public String getGuiID() {
return "me:oak_box";
}
@Override
public void clear() {
this.inventory.clear();
}
@Override
public void setInventorySlotContents(int index, ItemStack stack) {
this.inventory.set(index, stack);
if (!stack.isEmpty() && stack.getCount() > this.getInventoryStackLimit()) {
stack.setCount(this.getInventoryStackLimit());
}
this.markDirty();
}
@Override
public boolean isItemValidForSlot(int index, ItemStack stack) {
return false;
}
@Override
public int getField(int id) {
return 0;
}
@Override
public void setField(int id, int value) {
}
@Override
public int getFieldCount() {
return 0;
}
}
Блок 2:
public class BirchBox extends BlockContainer implements IHasModel {
public static final PropertyDirection FACING = BlockHorizontal.FACING;
private static boolean keepInventory;
public BirchBox(String name) {
super(Material.WOOD);
setUnlocalizedName(name);
setRegistryName(name);
setHardness(5.0F);
setHarvestLevel("axe", 0);
setResistance(4.0F);
setSoundType(SoundType.WOOD);
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
BlockInit.BLOCKS.add(this);
ItemInit.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
}
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
return Item.getItemFromBlock(BlockInit.BIRCH_BOX);
}
@Override
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) {
return new ItemStack(BlockInit.BIRCH_BOX);
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if(!worldIn.isRemote) {
playerIn.openGui(Main.instance, Reference.GUI_BIRCH_BOX , worldIn, pos.getX(), pos.getY(), pos.getZ());
}
return true;
}
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
{
this.setDefaultFacing(worldIn, pos, state);
}
private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state)
{
if (!worldIn.isRemote)
{
IBlockState iblockstate = worldIn.getBlockState(pos.north());
IBlockState iblockstate1 = worldIn.getBlockState(pos.south());
IBlockState iblockstate2 = worldIn.getBlockState(pos.west());
IBlockState iblockstate3 = worldIn.getBlockState(pos.east());
EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
if (enumfacing == EnumFacing.NORTH && iblockstate.isFullBlock() && !iblockstate1.isFullBlock())
{
enumfacing = EnumFacing.SOUTH;
}
else if (enumfacing == EnumFacing.SOUTH && iblockstate1.isFullBlock() && !iblockstate.isFullBlock())
{
enumfacing = EnumFacing.NORTH;
}
else if (enumfacing == EnumFacing.WEST && iblockstate2.isFullBlock() && !iblockstate3.isFullBlock())
{
enumfacing = EnumFacing.EAST;
}
else if (enumfacing == EnumFacing.EAST && iblockstate3.isFullBlock() && !iblockstate2.isFullBlock())
{
enumfacing = EnumFacing.WEST;
}
worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);
}
}
public static void setState(boolean active, World worldIn, BlockPos pos) {
IBlockState state = worldIn.getBlockState(pos);
TileEntity tileentity = worldIn.getTileEntity(pos);
keepInventory = true;
if(active) {
worldIn.setBlockState(pos, BlockInit.BIRCH_BOX.getDefaultState().withProperty(FACING, state.getValue(FACING)), 3);
worldIn.setBlockState(pos, BlockInit.BIRCH_BOX.getDefaultState().withProperty(FACING, state.getValue(FACING)), 3);
}
else {
worldIn.setBlockState(pos, BlockInit.BIRCH_BOX.getDefaultState().withProperty(FACING, state.getValue(FACING)), 3);
worldIn.setBlockState(pos, BlockInit.BIRCH_BOX.getDefaultState().withProperty(FACING, state.getValue(FACING)), 3);
}
keepInventory = false;
if(tileentity != null) {
tileentity.validate();
worldIn.setTileEntity(pos, tileentity);
}
}
@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {
return new TileEntityBirchBox();
}
@Override
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
}
@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
worldIn.setBlockState(pos, this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
}
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
if (!keepInventory)
{
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityBirchBox)
{
InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityBirchBox)tileentity);
}
}
super.breakBlock(worldIn, pos, state);
}
@Override
public EnumBlockRenderType getRenderType(IBlockState state) {
return EnumBlockRenderType.MODEL;
}
@Override
public IBlockState withRotation(IBlockState state, Rotation rot) {
return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}
@Override
public IBlockState withMirror(IBlockState state, Mirror mirrorIn) {
return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, new IProperty[] {FACING});
}
@Override
public IBlockState getStateFromMeta(int meta) {
EnumFacing facing = EnumFacing.getFront(meta);
if(facing.getAxis() == EnumFacing.Axis.Y) facing = EnumFacing.NORTH;
return this.getDefaultState().withProperty(FACING, facing);
}
@Override
public int getMetaFromState(IBlockState state) {
return ((EnumFacing)state.getValue(FACING)).getIndex();
}
@Override
public void registerModels() {
Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");
}
}
Контейнер 2:
public class ContainerBirchBox extends Container {
private final TileEntityBirchBox tileentity;
public ContainerBirchBox(InventoryPlayer player, TileEntityBirchBox tileentity) {
this.tileentity = tileentity;
for(int y = 0; y < 3; y++) {
for(int x = 0; x < 9; x++) {
this.addSlotToContainer(new Slot(player, x + y*9 + 9, 8 + x*18, 64 + y*18));
}
}
for(int x = 0; x <9; x++) {
this.addSlotToContainer(new Slot(player, x, 8 + x*18, 122));
}
this.addSlotToContainer(new Slot(player, 36, 71, 18));
this.addSlotToContainer(new Slot(player, 37, 89, 18));
this.addSlotToContainer(new Slot(player, 38, 71, 36));
this.addSlotToContainer(new Slot(player, 39, 89, 36));
}
@Override
public void addListener(IContainerListener listener) {
super.addListener(listener);
listener.sendAllWindowProperties(this, this.tileentity);
}
@Override
public boolean canInteractWith(EntityPlayer playerIn) {
return this.tileentity.isUsableByPlayer(playerIn);
}
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.inventorySlots.get(index);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (index >= 0 && index < 36)
{
if (!this.mergeItemStack(itemstack1, 36, 40, false))
{
return ItemStack.EMPTY;
}
}
else if (index >= 36 && index < 40)
{
if (!this.mergeItemStack(itemstack1, 0, 36, false))
{
return ItemStack.EMPTY;
}
}
else if (!this.mergeItemStack(itemstack1, 9, 45, false))
{
return ItemStack.EMPTY;
}
if (itemstack1.isEmpty())
{
slot.putStack(ItemStack.EMPTY);
}
else
{
slot.onSlotChanged();
}
if (itemstack1.getCount() == itemstack.getCount())
{
return ItemStack.EMPTY;
}
ItemStack itemstack2 = slot.onTake(playerIn, itemstack1);
if (index == 0)
{
playerIn.dropItem(itemstack2, false);
}
}
return itemstack;
}
}
Гуи 2:
public class GuiBirchBox extends GuiContainer {
private static final ResourceLocation TEXTURES = new ResourceLocation(Reference.MODID + ":textures/gui/gui_wooden_box.png");
private final InventoryPlayer player;
private final TileEntityBirchBox tileentity;
public GuiBirchBox(InventoryPlayer player, TileEntityBirchBox tileentity) {
super(new ContainerBirchBox(player, tileentity));
this.player = player;
this.tileentity = tileentity;
this.xSize = 176;
this.ySize = 146;
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
String tileName = this.tileentity.getDisplayName().getUnformattedText();
this.fontRenderer.drawString(tileName, this.xSize / 2 - this.fontRenderer.getStringWidth(tileName) / 2, 6, 0);
this.fontRenderer.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 0);
}
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
super.drawScreen(mouseX, mouseY, partialTicks);
this.renderHoveredToolTip(mouseX, mouseY);
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
this.mc.getTextureManager().bindTexture(TEXTURES);
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
}
}
ТайлЭнтити 2:
public class TileEntityBirchBox extends TileEntity implements IInventory {
private NonNullList<ItemStack> inventory = NonNullList.<ItemStack>withSize(4, ItemStack.EMPTY);
private String customName;
@Override
public String getName() {
return this.hasCustomName() ? this.customName : "container.birch_box";
}
@Override
public boolean hasCustomName() {
return this.customName != null && !this.customName.isEmpty();
}
public void setCustomName(String customName) {
this.customName = customName;
}
@Override
public ITextComponent getDisplayName() {
return this.hasCustomName() ? new TextComponentString(this.getName()) : new TextComponentTranslation(this.getName());
}
@Override
public int getSizeInventory() {
return this.inventory.size();
}
@Override
public boolean isEmpty() {
for(ItemStack stack : this.inventory) {
if(!stack.isEmpty()) return false;
}
return true;
}
@Override
public ItemStack getStackInSlot(int index) {
return (ItemStack)this.inventory.get(index);
}
@Override
public ItemStack decrStackSize(int index, int count) {
return ItemStackHelper.getAndSplit(this.inventory, index, count);
}
@Override
public ItemStack removeStackFromSlot(int index) {
return ItemStackHelper.getAndRemove(this.inventory, index);
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public boolean isUsableByPlayer(EntityPlayer player) {
return this.world.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64;
}
@Override
public void readFromNBT(NBTTagCompound compound) {
super.readFromNBT(compound);
ItemStackHelper.loadAllItems(compound, this.inventory);
if(compound.hasKey("CustomName", 8)) this.setCustomName(compound.getString("CustomName"));
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
super.writeToNBT(compound);
ItemStackHelper.saveAllItems(compound, this.inventory);
if(this.hasCustomName()) compound.setString("CustomName", this.customName);
return compound;
}
@Override
public void openInventory(EntityPlayer player) { }
@Override
public void closeInventory(EntityPlayer player) {}
public String getGuiID() {
return "me:birch_box";
}
@Override
public void clear() {
this.inventory.clear();
}
@Override
public void setInventorySlotContents(int index, ItemStack stack) {
this.inventory.set(index, stack);
if (!stack.isEmpty() && stack.getCount() > this.getInventoryStackLimit()) {
stack.setCount(this.getInventoryStackLimit());
}
this.markDirty();
}
@Override
public boolean isItemValidForSlot(int index, ItemStack stack) {
return false;
}
@Override
public int getField(int id) {
return 0;
}
@Override
public void setField(int id, int value) {
}
@Override
public int getFieldCount() {
return 0;
}
}
Так же при попытке поставить
tileentity
вместо player
при добавлении слотов в контейнере, игра зависает при попытке открытия инвентаря.
Слот:
public class WoodenSlot extends Slot {
private final EntityPlayer thePlayer;
private int removeCount;
public WoodenSlot(EntityPlayer player, IInventory inventoryIn, int slotIndex, int xPosition, int yPosition){
super(inventoryIn, slotIndex, xPosition, yPosition);
this.thePlayer = player;
}
public boolean isItemValid(@Nullable ItemStack stack){
return true;
}
public ItemStack decrStackSize(int amount){
if (this.getHasStack()){
this.removeCount += Math.min(amount, this.getStack().getCount());
}
return super.decrStackSize(amount);
}
public ItemStack onTake(EntityPlayer player, ItemStack stack){
this.onCrafting(stack);
super.onTake(player, stack);
return stack;
}
protected void onCrafting(ItemStack stack, int amount){
this.removeCount += amount;
this.onCrafting(stack);
}
protected void onCrafting(ItemStack stack){
stack.onCrafting(this.thePlayer.world, this.thePlayer, this.removeCount);
this.removeCount = 0;
}
}
Потом пробовал ещё делать через этот слот, опять же просто зависает.