Я сделал свой сундук в своем моде, но проблем немного.Текстура предмета не работает, сундук всегда направлен на юг, и на нем не отображаются ярлыки предметов, когда я наводю на них предметы.Как решить эти проблемы?Спасибо за помощь!
Вот код: 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;
import 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.IBlockAccess;
import net.minecraft.world.World;
public class MoneyChest extends BlockContainer {
public MoneyChest(String name) {
super(Material.IRON);
setSoundType(SoundType.STONE);
setCreativeTab(Main.RM_TAB1);
setUnlocalizedName(name);
setRegistryName(name);
ModBlocks.BLOCKS.add(this);
ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
}
@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, 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 pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
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 state) {
return EnumBlockRenderType.ENTITYBLOCK_ANIMATED;
}
@Override
public boolean isFullBlock(IBlockState state) {
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 state) {
return false;
}
@Override
public boolean isOpaqueCube(IBlockState state) {
return false;
}
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
return MONEY_CHEST_AABB;
}
}
TileEntityMoneyChest
package com.rinventor.rinventedmod.blocks.advanced.tileentity;
import 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;
public class TileEntityMoneyChest extends TileEntityLockableLoot implements ITickable {
private NonNullList<ItemStack> chestContents = NonNullList.<ItemStack>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() {
for(ItemStack stack : 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 compound) {
super.readFromNBT(compound);
this.chestContents = NonNullList.<ItemStack>withSize(this.getSizeInventory(), ItemStack.EMPTY);
if(!checkLootAndRead(compound)) ItemStackHelper.loadAllItems(compound, chestContents);
if(compound.hasKey("CustomName", 8)) this.customName = compound.getString("CustomName");
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
super.writeToNBT(compound);
if(!this.checkLootAndWrite(compound)) ItemStackHelper.saveAllItems(compound, chestContents);
if(compound.hasKey("CustomName", 8)) compound.setString("CustomName", this.customName);
return compound;
}
@Override
public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn) {
return new ContainerMoneyChest(playerInventory, this, playerIn);
}
@Override
public String getGuiID() {
return Main.MODID + ":money_chest";
}
@Override
protected NonNullList<ItemStack> 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;
float f = 5.0F;
for (EntityPlayer entityplayer : this.world.getEntitiesWithinAABB(EntityPlayer.class, new 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) {
++this.numPlayersUsing;
}
}
}
}
this.prevLidAngle = this.lidAngle;
float f1 = 0.1F;
if (this.numPlayersUsing > 0 && this.lidAngle == 0.0F) {
double d1 = (double)pos.getX() + 0.5D;
double d2 = (double)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 < 1.0F) {
float f2 = this.lidAngle;
if (this.numPlayersUsing > 0) {
this.lidAngle += 0.1F;
}
else {
this.lidAngle -= 0.1F;
}
if (this.lidAngle > 1.0F) {
this.lidAngle = 1.0F;
}
float f3 = 0.5F;
if (this.lidAngle < 0.5F && f2 >= 0.5F) {
double d3 = (double)pos.getX() + 0.5D;
double d0 = (double)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);
}
if (this.lidAngle < 0.0F) {
this.lidAngle = 0.0F;
}
}
}
@Override
public void openInventory(EntityPlayer player) {
++this.numPlayersUsing;
this.world.addBlockEvent(pos, this.getBlockType(), 1, this.numPlayersUsing);
this.world.notifyNeighborsOfStateChange(pos, this.getBlockType(), false);
}
@Override
public void closeInventory(EntityPlayer player) {
--this.numPlayersUsing;
this.world.addBlockEvent(pos, this.getBlockType(), 1, this.numPlayersUsing);
this.world.notifyNeighborsOfStateChange(pos, this.getBlockType(), false);
}
}
ContainerMoneyChest
package com.rinventor.rinventedmod.blocks.advanced.container;
import 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;
public class ContainerMoneyChest extends Container {
private final int numRows;
private final TileEntityMoneyChest chestInventory;
public ContainerMoneyChest(InventoryPlayer playerInv, TileEntityMoneyChest chestInventory, EntityPlayer player) {
this.chestInventory = chestInventory;
this.numRows = 2; //chest rows
chestInventory.openInventory(player);
for(int i = 0; i < this.numRows; i++) {
for(int j = 0; j < 8; j++) {
this.addSlotToContainer(new Slot(chestInventory, j + i*9, 17 + j*18, 15 + i*18));//17 - XposFromLeft; tagum15s - YposFromTop
}
}
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, 72 + y*18)); //72 - YposFromTopTex(Inventory)
}
}
for(int x = 0; x < 9; x++) {
this.addSlotToContainer(new Slot(playerInv, x, 8 + x*18, 130)); //130 - YposFromTopTex(hotbar)
}
}
@Override
public boolean canInteractWith(EntityPlayer playerIn) {
return this.chestInventory.isUsableByPlayer(playerIn);
}
@Override
public void onContainerClosed(EntityPlayer playerIn) {
super.onContainerClosed(playerIn);
chestInventory.closeInventory(playerIn);
}
@Override
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 < this.numRows * 8) {
if (!this.mergeItemStack(itemstack1, this.numRows * 8, this.inventorySlots.size(), true)) {
return ItemStack.EMPTY;
}
}
else if (!this.mergeItemStack(itemstack1, 0, this.numRows * 8, false)) {
return ItemStack.EMPTY;
}
if (itemstack1.isEmpty()) {
slot.putStack(ItemStack.EMPTY);
}
else { slot.onSlotChanged(); }
}
return itemstack;
}
public TileEntityMoneyChest getChestInventory() {
return this.chestInventory;
}
}
GuiMoneyChest
package com.rinventor.rinventedmod.blocks.advanced.gui;
import com.rinventor.rinventedmod.Main;
import com.rinventor.rinventedmod.blocks.advanced.container.ContainerMoneyChest;
import com.rinventor.rinventedmod.blocks.advanced.tileentity.TileEntityMoneyChest;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
public class GuiMoneyChest extends GuiContainer {
private static final ResourceLocation GUI_CHEST = new ResourceLocation(Main.MODID + ":textures/gui/money_chest.png");
private final InventoryPlayer playerInventory;
private final TileEntityMoneyChest temc;
public GuiMoneyChest(InventoryPlayer playerInventory, TileEntityMoneyChest chestInventory, EntityPlayer player) {
super(new ContainerMoneyChest(playerInventory, chestInventory, player));
this.playerInventory = playerInventory;
this.temc = chestInventory;
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-green
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, но это не причина проблем, с которыми я столкнулся.