我在我的mod中做了一个定制的箱子,但是问题很少。物品纹理不起作用,胸部始终朝南,当我将鼠标悬停在物品上时,它不显示物品标签。如何解决这些问题?感谢您的帮助!
这是代码: MoneyChest
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] words = {"monkey","donkey","konkey","funkey","bonkey"};
Scanner input = new Scanner(System.in);
//random string from string array
String str = randomString(words);
//change string array to char array
char[] word = str.toCharArray();
System.out.println("Picked " + str);
int size = 0;
boolean k = true;
//Create the char array
char[] array = new char[str.length()];
//fill it with *
for(int i = 0 ; i < str.length() ; i++) {
array[i] ='*';
}
//check if given char is in the string
do {
System.out.print("enter the char: ");
char given = input.next().charAt(0);
for(int i = 0 ; i < word.length ; i++) {
if(word[i] == given) {
char g = given;
//Check if the array[i] has been already replaced
//If not increase the size
if(array[i] == '*') size++;
array[i] = g;
}
if(size == str.length()){
k = false;
}
}
for(char e:array) {
System.out.print(e);
}
System.out.println();
}while(k);
}
public static String randomString(String[] str) {
int k = (int) (Math.random() * str.length);
String strk = str[k];
return strk;
}
TileEntityMoneyChest
enter the char: k
***k**
enter the char: d
***k**
enter the char: o
*o*k**
enter the char: n
*onk**
enter the char: k
*onk**
enter the char: e
*onke*
enter the char: y
*onkey
enter the char: m
monkey
ContainerMoneyChest
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;
}
}
GuiMoneyChest
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);
}
}
我也有ModelMoneyChest和RenderMoneyChest文件,但这不是我遇到问题的原因。