Я сделал нестандартный сундук в своем моде, но есть несколько проблем. Текстура предметов не работает, сундук всегда обращен на юг, и при наведении курсора на них на них не отображаются надписи. Как решить эти проблемы? Спасибо за помощь!
Вот код: MoneyChest
package com.rinventor.rinventedmod.blocks.advanced; import com.rinventor.rinventedmod .Main; import com.rinventor.rinventedmod.blocks.advanced.tileentity.TileEntityMoneyChest; import com.rinventor.rinventedmod.init.ModBlocks; import com.rinventor.rinventedmod.init.ModItems; import net.minecraft.block.BlockContainer; net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.InventoryHelper; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumBlockRenderType; import net.minecraft. util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlock Доступ; импорт net.minecraft.world.World; открытый класс MoneyChest расширяет BlockContainer {public MoneyChest (имя строки) {super (Material.IRON); setSoundType (SoundType.STONE); setCreativeTab (Main.RM_TAB1); setUnlocalizedName (имя); setRegistryName (имя); ModBlocks.BLOCKS.add (это); ModItems.ITEMS.add (новый ItemBlock (this) .setRegistryName (this.getRegistryName ())); } @Override public boolean onBlockActivated (World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing face, float hitX, float hitY, float hitZ) {if (! WorldIn.isRemote) {playerIn.openGui (Main.instance , Main.GUI_MONEY_CHEST, worldIn, pos.getX (), pos.getY (), pos.getZ ()); } return true; } @Override public void breakBlock (World worldIn, BlockPos pos, IBlockState state) {TileEntityMoneyChest tilemoneychest = (TileEntityMoneyChest) worldIn.getTileEntity (pos); InventoryHelper.dropInventoryItems (worldIn, pos, tilemoneychest); super.breakBlock (worldIn, pos, state); } @Override public void onBlockPlacedBy (World worldIn, позиция BlockPos, состояние IBlockState, объект EntityLivingBase, стек ItemStack) {if (stack.hasDisplayName ()) {TileEntity tilemoneychest = worldIn.getTileEntity (pos); if (tilemoneychest instanceof TileEntityMoneyChest) {((TileEntityMoneyChest) tilemoneychest) .setCustomName (stack.getDisplayName ()); }}} @Override public TileEntity createNewTileEntity (World worldIn, int meta) {return new TileEntityMoneyChest (); } @Override public EnumBlockRenderType getRenderType (состояние IBlockState) {return EnumBlockRenderType.ENTITYBLOCK_ANIMATED; } @Override public boolean isFullBlock (состояние IBlockState) {return false; } public static final AxisAlignedBB MONEY_CHEST_AABB = new AxisAlignedBB (0,0625D, 0, 0,0625D, 0,9375D, 0,875D, 0. 9375D); @Override public boolean isFullCube (состояние IBlockState) {return false; } @Override public boolean isOpaqueCube (состояние IBlockState) {return false; } @Override public AxisAlignedBB getBoundingBox (состояние IBlockState, источник IBlockAccess, позиция BlockPos) {return MONEY_CHEST_AABB; }}
TileEntityMoneyChest
пакет com.rinventor.rinventedmod.blocks.advanced.tileentity; импорт com.rinventor.rinventedmod. Main; import com.rinventor.rinventedmod.blocks.advanced.container.ContainerMoneyChest; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.init.SoundEvents; import net .minecraft.inventory.Container; import net.minecraft.inventory.ItemStackHelper; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntityLockableLoot; import net.minecraft.util. ITickable; import net.minecraft.util.NonNullList; import net.minecraft.util.SoundCategory; import net.minecraft.util.math.AxisAlignedBB; открытый класс TileEntityMoneyChest расширяет TileEntityLockableLoot реализует ITickable {private NonNullLockableLockableLoot private NonNullList > withSize (72, ItemStack.EMPTY); public int numPlayersUsing, ticksSinceSync; public float lidAngle, prevLidAngle; @Override public int getSizeInventory () {return 72; } @Override public int getInventoryStackLimit () {return 50; } @Override public boolean isEmpty () {для (стек ItemStack: this.chestContents) {if (! Stack .isEmpty ()) return false; } return true; } @Override public String getName () {return this.hasCustomName ()? this.customName: "container.money_chest"; } @Override public void readFromNBT (соединение NBTTagCompound) {super.readFromNBT (соединение); this.chestContents = NonNullList. withSize (this.getSizeInventory (), ItemStack.EMPTY); если (! checkLootAndRead (составной)) ItemStackHelper.loadAllItems (составной, ChessContents); если (соединение.hasKey ("CustomName", 8)) this.customName = соединение.getString ("CustomName"); } @Override public NBTTagCompound writeToNBT (составной NBTTagCompound) {super.writeToNBT (составной); если (! this.checkLootAndWrite (составной)) ItemStackHelper.saveAllItems (составной, сундук); if (complex.hasKey ("CustomName", 8)) complex.setString ("CustomName", this.customName); возвратное соединение; } @Override публичный контейнер createContainer (InventoryPlayer playerInventory, EntityPlayer playerIn) {return new ContainerMoneyChest (playerInventory, this, playerIn); } @Override public String getGuiID () {return Main.MODID + ": money_chest"; } @Override protected NonNullList getItems () {return this.chestContents; } @Override public void update () {if (! This.world.isRemote && this.numPlayersUsing! = 0 && (this.ticksSinceSync + pos.getX () + pos.getY () + pos.getZ ())% 200 == 0) {this.numPlayersUsing = 0; поплавок f = 5.0F; для (EntityPlayer entityplayer: this.world. getEntitiesWithinAABB (EntityPlayer.class, новый AxisAlignedBB ((double) ((float) pos.getX () - 5.0F), (double) ((float) pos.getY () - 5.0F), (double) ((float) pos.getZ () - 5.0F), (double) ((float) (pos.getX () + 1) + 5.0F), (double) ((float) (pos.getY () + 1) + 5.0F ), (double) ((float) (pos.getZ () + 1) + 5.0F)))) {if (entityplayer.openContainer instanceof ContainerMoneyChest) {if (((ContainerMoneyChest) entityplayer.openContainer) .getChestInventory () = = это) {++ this.numPlayersUsing; }}}} this.prevLidAngle = this.lidAngle; поплавок f1 = 0,1F; if (this.numPlayersUsing> 0 && this.lidAngle == 0.0F) {двойной d1 = (двойной) pos.getX () + 0.5D; двойной d2 = (двойной) pos.getZ () + 0.5D; this.world.playSound ((EntityPlayer) null, d1, (double) pos.getY () + 0.5D, d2, SoundEvents.BLOCK_IRON_TRAPDOOR_OPEN, SoundCategory.BLOCKS, 0.5F, this.world.rand.nextFloat () * 0.1F + 0.9F); } if (this.numPlayersUsing == 0 && this.lidAngle> 0.0F || this.numPlayersUsing> 0 && this.lidAngle 0) {this.lidAngle + = 0,1F; } else {this.lidAngle - = 0.1F; } если (this.lidAngle> 1.0F) {this.lidAngle = 1.0F; } float f3 = 0,5F; если (this.lidAngle = 0,5F) {двойной d3 = (двойной) pos.getX () + 0,5D; двойной d0 = (двойной) pos.getZ () + 0.5D; this.world.playSound ((EntityPlayer) null, d3, (double) pos.getY () + 0.5D, d0, SoundEvents.BLOCK_IRON_TRAPDOOR_CLOSE, SoundCategory.BLOCKS, 0.5F, this.world.rand.nextFloat () * 0.1F + 0.9F); } если (this.lidAngle
ContainerMoneyChest
пакет com.rinventor.rinventedmod.blocks.advanced.container; импорт com.rinventor.rinventedmod. blocks.advanced.tileentity.TileEntityMoneyChest; 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; открытый класс ContainerMoneyChest расширяет контейнер {private final int numRows; закрытый финал TileEntityMoneyChest ChessInventory; общедоступный ContainerMoneyChest (InventoryPlayer playerInv, TileEntityMoneyChest ChestInventory, EntityPlayer player) {this.chestInventory = ChestInventory; this.numRows = 2; //ряды сундуков ChestInventory.openInventory (player); for (int i = 0; i
GuiMoneyChest
пакет com.rinventor.rinventedmod.blocks.advanced.gui; импортировать com.rinventor.rinventedmod. Main; импорт com.rinventor.rinventedmod.blocks.advanced.container.ContainerMoneyChest; импорт com.rinventor.rinventedmod.blocks.advanced.tileentity.TileEntityMoneyChest; импорт net.minecraft.client.gui.inventory.GuiContainer; импорт net.minecraft. client.renderer.GlStateManager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.util.ResourceLocation; открытый класс GuiMoneyChest расширяет GuiContainer {private static final ResourceLocation = new GUI_CHI_CHI_CH ResourceLocation (Main.MODID + ": textures/gui/money_chest.png"); закрытый финальный InventoryPlayer playerInventory; закрытый финальный TileEntityMoneyChest temc; общедоступный GuiMoneyChest (InventoryPlayer playerInventory, TileEntityMoneyChest ChestInventory, EntityPlayer player) {super (новый ContainerMoneyChest (playerInventory, ChessInventory, player)); this.playerInventory = playerInventory; this.temc = ChessInventory; this.xSize = 176; this.ySize = 154; } @Override protected void drawGuiContainerForegroundLayer (int mouseX, int mouseY) {this.fontRenderer.drawString (this.temc.getDisplayName (). GetUnformattedText (), 14, 4, 0);//3120942-зеленый this.fontRenderer.drawString ( this.playerInventory.getDisplayName (). getUnformattedText (), 8, this.ySize-93, 0); } @Override protected void drawGuiContainerBackgroundLayer (float partialTicks, int mouseX, int mouseY) {GlStateManager.color (1.0f, 1.0f, 1.0f, 1). 0f); this.mc.getTextureManager (). bindTexture (GUI_CHEST); this.drawTexturedModalRect (this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize); }}
У меня также есть файлы ModelMoneyChest и RenderMoneyChest, но это не причина моих проблем.