- 91
- 1
- 5
Решил создать печь, вписал всё что надо и мне пишет в консоли:
[04:10:48] [Server thread/FATAL] [minecraft/MinecraftServer]: Error executing task
java.util.concurrent.ExecutionException: java.lang.RuntimeException: class com.enginners.production.tileentity.TileEntityClayFurnace is missing a mapping! This is a bug!
[04:10:48] [Server thread/FATAL] [minecraft/MinecraftServer]: Error executing task
java.util.concurrent.ExecutionException: java.lang.RuntimeException: class com.enginners.production.tileentity.TileEntityClayFurnace is missing a mapping! This is a bug!
Код:
public class BlockClayFurnace extends BlockBase implements ITileEntityProvider, IHasModel{
public static final PropertyDirection FACING = BlockHorizontal.FACING;
public static final PropertyBool BURNING = PropertyBool.create("burning");
private final boolean isBurning;
private static boolean keepInventory;
public BlockClayFurnace(String name, Material material, boolean isBurning){
super(name, material);
this.setSoundType(SoundType.GROUND);
this.setHardness(2.0F);
this.setResistance(5.0F);
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(BURNING, false));
this.isBurning = isBurning;
}
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune){
return Item.getItemFromBlock(MBlocks.CLAY_FURNACE);
}
@Override
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 north = worldIn.getBlockState(pos.north());
IBlockState south = worldIn.getBlockState(pos.south());
IBlockState west = worldIn.getBlockState(pos.west());
IBlockState east = worldIn.getBlockState(pos.east());
EnumFacing face = (EnumFacing)state.getValue(FACING);
if (face == EnumFacing.NORTH && north.isFullBlock() && !south.isFullBlock()) face = EnumFacing.SOUTH;
else if (face == EnumFacing.SOUTH && south.isFullBlock() && !north.isFullBlock()) face = EnumFacing.NORTH;
else if (face == EnumFacing.WEST && west.isFullBlock() && !east.isFullBlock()) face = EnumFacing.EAST;
else if (face == EnumFacing.EAST && east.isFullBlock() && !west.isFullBlock()) face = EnumFacing.WEST;
worldIn.setBlockState(pos, state.withProperty(FACING, face), 2);
}
}
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand){
if (isBurning){
EnumFacing enumfacing = (EnumFacing)stateIn.getValue(FACING);
double d0 = (double)pos.getX() + 0.5D;
double d1 = (double)pos.getY() + rand.nextDouble() * 6.0D / 16.0D;
double d2 = (double)pos.getZ() + 0.5D;
double d3 = 0.52D;
double d4 = rand.nextDouble() * 0.6D - 0.3D;
if (rand.nextDouble() < 0.1D){
worldIn.playSound((double)pos.getX() + 0.5D, (double)pos.getY(), (double)pos.getZ() + 0.5D, SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, SoundCategory.BLOCKS, 1.0F, 1.0F, false);
}switch (enumfacing){
case WEST:
worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 - d3 - 0.52D, d1, d2 + d4, 0.0D, 0.0D, 0.0D);
worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 - 0.52D, d1, d2 + d4, 0.0D, 0.0D, 0.0D);
break;
case EAST:
worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + 0.52D, d1, d2 + d4, 0.0D, 0.0D, 0.0D);
worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 + 0.52D, d1, d2 + d4, 0.0D, 0.0D, 0.0D);
break;
case NORTH:
worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d4, d1, d2 - 0.52D, 0.0D, 0.0D, 0.0D);
worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 + d4, d1, d2 - 0.52D, 0.0D, 0.0D, 0.0D);
break;
case SOUTH:
worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d4, d1, d2 + 0.52D, 0.0D, 0.0D, 0.0D);
worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 + d4, d1, d2 + 0.52D, 0.0D, 0.0D, 0.0D);
case DOWN:
break;
case UP:
break;
default:
break;
}
}
}
@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){
return true;
}
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityClayFurnace){
return false;
}
playerIn.openGui(Mymod.instance, GuiHandler.GUI_CLAY_FURNACE, worldIn, pos.getX(), pos.getY(), pos.getZ());
return true;
}
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, MBlocks.CLAY_FURNACE.getDefaultState().withProperty(FACING, state.getValue(FACING)).withProperty(BURNING, true), 3);
else worldIn.setBlockState(pos, MBlocks.CLAY_FURNACE.getDefaultState().withProperty(FACING, state.getValue(FACING)).withProperty(BURNING, false), 3);
if(tileentity != null){
tileentity.validate();
worldIn.setTileEntity(pos, tileentity);
}
}
@Override
public TileEntity createNewTileEntity(World worldIn, int meta){
return new TileEntityClayFurnace();
}
@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, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
if (stack.hasDisplayName()){
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityClayFurnace){
((TileEntityClayFurnace)tileentity).setCustomName(stack.getDisplayName());
}
}
}
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state){
if (keepInventory){
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityClayFurnace){
InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityClayFurnace)tileentity);
worldIn.updateComparatorOutputLevel(pos, this);
}
}
super.breakBlock(worldIn, pos, state);
}
@Override
public boolean hasComparatorInputOverride(IBlockState state){
return true;
}
public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos){
return Container.calcRedstone(worldIn.getTileEntity(pos));
}
@Override
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state){
return new ItemStack(MBlocks.CLAY_FURNACE);
}
@Override
public EnumBlockRenderType getRenderType(IBlockState state){
return EnumBlockRenderType.MODEL;
}
@Override
public IBlockState getStateFromMeta(int meta){
boolean blockIsActive = false;
if(meta >= 0){
blockIsActive = true;
meta = meta - 0;
}
EnumFacing enumfacing = EnumFacing.getFront(meta);
if(enumfacing.getAxis() == EnumFacing.Axis.Y) {enumfacing = EnumFacing.NORTH;}
return this.getDefaultState().withProperty(FACING, enumfacing).withProperty(BURNING, blockIsActive);
}
@Override
public int getMetaFromState(IBlockState state){
int a = state.getValue(BURNING) ? 1 : 0;
return ((EnumFacing)state.getValue(FACING)).getIndex() + 0*a;
}
@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
public boolean hasTileEntity(IBlockState state){
return true;
}
@Override
protected BlockStateContainer createBlockState(){
return new BlockStateContainer(this, new IProperty[] {BURNING, FACING});
}
}
Код:
public class TileEntityClayFurnace extends TileEntity implements IInventory, ITickable{
private NonNullList<ItemStack> inventory = NonNullList.<ItemStack>withSize(4, ItemStack.EMPTY);
private String customName;
public static boolean keepInventory;
private int burnTime;
private int currentBurnTime;
private int cookTime;
private int totalCookTime;
@Override
public String getName(){
return this.hasCustomName() ? this.customName : "container.clay_furnace";
}
@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;
}
@Nullable
@Override
public SPacketUpdateTileEntity getUpdatePacket(){
final NBTTagCompound tag = new NBTTagCompound();
writeToNBT(tag);
return new SPacketUpdateTileEntity(getPos(), 1, tag);
}
@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt){
readFromNBT(pkt.getNbtCompound());
}
public boolean canInteractWith(EntityPlayer playerIn){
return !isInvalid() && playerIn.getDistanceSq(pos.add(0.5D, 0.5D, 0.5D)) <= 64D;
}
@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 void setInventorySlotContents(int index, ItemStack stack){
ItemStack itemstack = (ItemStack)this.inventory.get(index);
boolean flag = !stack.isEmpty() && stack.isItemEqual(itemstack) && ItemStack.areItemStackTagsEqual(stack, itemstack);
this.inventory.set(index, stack);
if(stack.getCount() > this.getInventoryStackLimit()) stack.setCount(this.getInventoryStackLimit());
if(index == 0 && index + 1 == 1 && !flag){
ItemStack stack1 = (ItemStack)this.inventory.get(index + 1);
this.totalCookTime = this.getCookTime(stack, stack1);
this.cookTime = 0;
this.markDirty();
}
}
@Override
public void readFromNBT(NBTTagCompound compound){
super.readFromNBT(compound);
this.inventory = NonNullList.<ItemStack>withSize(this.getSizeInventory(), ItemStack.EMPTY);
ItemStackHelper.loadAllItems(compound, this.inventory);
this.burnTime = compound.getInteger("BurnTime");
this.cookTime = compound.getInteger("CookTime");
this.totalCookTime = compound.getInteger("CookTimeTotal");
this.currentBurnTime = getItemBurnTime((ItemStack)this.inventory.get(2));
if(compound.hasKey("CustomName", 8)) this.setCustomName(compound.getString("CustomName"));
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound){
super.writeToNBT(compound);
compound.setInteger("BurnTime", (short)this.burnTime);
compound.setInteger("CookTime", (short)this.cookTime);
compound.setInteger("CookTimeTotal", (short)this.totalCookTime);
ItemStackHelper.saveAllItems(compound, this.inventory);
if(this.hasCustomName()) compound.setString("CustomName", this.customName);
return compound;
}
@Override
public int getInventoryStackLimit(){
return 64;
}
public boolean isBurning(){
return this.burnTime > 0;
}
@SideOnly(Side.CLIENT)
public static boolean isBurning(IInventory inventory){
return inventory.getField(0) > 0;
}
public void update(){
boolean flag = this.isBurning();
boolean flag1 = false;
if(this.isBurning()) --this.burnTime;
if(!this.world.isRemote){
ItemStack stack = (ItemStack)this.inventory.get(2);
if(this.isBurning() || !stack.isEmpty() && !((((ItemStack)this.inventory.get(0)).isEmpty()) || ((ItemStack)this.inventory.get(1)).isEmpty())){
if(!this.isBurning() && this.canSmelt()){
this.burnTime = getItemBurnTime(stack);
this.currentBurnTime = this.burnTime;
if(this.isBurning()){
flag1 = true;
if(!stack.isEmpty()){
Item item = stack.getItem();
stack.shrink(1);
if(stack.isEmpty()){
ItemStack item1 = item.getContainerItem(stack);
this.inventory.set(2, item1);
}
}
}
}if(this.isBurning() && this.canSmelt()){
++this.cookTime;
if(this.cookTime == this.totalCookTime){
this.cookTime = 0;
this.totalCookTime = this.getCookTime((ItemStack)this.inventory.get(0), (ItemStack)this.inventory.get(1));
this.smeltItem();
flag1 = true;
}
}else this.cookTime = 0;
}else if(!this.isBurning() && this.cookTime > 0){
this.cookTime = MathHelper.clamp(this.cookTime - 2, 0, this.totalCookTime);
}if(flag != this.isBurning()){
flag1 = true;
BlockClayFurnace.setState(this.isBurning(), this.world, this.pos);
}
}if(flag1) this.markDirty();
}
public int getCookTime(ItemStack input1, ItemStack input2){
return 200;
}
private boolean canSmelt(){
if(((ItemStack)this.inventory.get(0)).isEmpty() || ((ItemStack)this.inventory.get(1)).isEmpty()) return false;
else{
ItemStack result = ClayFurnaceRecipes.getInstance().getClayResult((ItemStack)this.inventory.get(0), (ItemStack)this.inventory.get(1));
if(result.isEmpty()) return false;
else{
ItemStack output = (ItemStack)this.inventory.get(3);
if(output.isEmpty()) return true;
if(!output.isItemEqual(result)) return false;
int res = output.getCount() + result.getCount();
return res <= getInventoryStackLimit() && res <= output.getMaxStackSize();
}
}
}
public void smeltItem(){
if(this.canSmelt()){
ItemStack input1 = (ItemStack)this.inventory.get(0);
ItemStack input2 = (ItemStack)this.inventory.get(1);
ItemStack result = ClayFurnaceRecipes.getInstance().getClayResult(input1, input2);
ItemStack output = (ItemStack)this.inventory.get(3);
if(output.isEmpty()) this.inventory.set(3, result.copy());
else if(output.getItem() == result.getItem()) output.grow(result.getCount());
input1.shrink(1);
input2.shrink(1);
}
}
@SuppressWarnings("deprecation")
public static int getItemBurnTime(ItemStack fuel){
if(fuel.isEmpty()) {
return 0;
}else{
int burnTime = net.minecraftforge.event.ForgeEventFactory.getItemBurnTime(fuel);
if (burnTime >= 0) return burnTime;
Item item = fuel.getItem();
if (item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.AIR){
Block block = Block.getBlockFromItem(item);
if (block == Blocks.WOODEN_SLAB)
return 150;
if (block.getDefaultState().getMaterial() == Material.WOOD)
return 300;
if (block == Blocks.COAL_BLOCK)
return 16000;
}if (item instanceof ItemTool && "WOOD".equals(((ItemTool)item).getToolMaterialName()))
return 200;
if (item instanceof ItemSword && "WOOD".equals(((ItemSword)item).getToolMaterialName()))
return 200;
if (item instanceof ItemHoe && "WOOD".equals(((ItemHoe)item).getMaterialName()))
return 200;
if (item == Items.STICK)
return 100;
if (item == Items.COAL)
return 1600;
if (item == Items.LAVA_BUCKET)
return 20000;
if (item == Item.getItemFromBlock(Blocks.SAPLING))
return 100;
if (item == Items.BLAZE_ROD)
return 2400;
return GameRegistry.getFuelValue(fuel);
}
}
public static boolean isItemFuel(ItemStack fuel){
return getItemBurnTime(fuel) > 0;
}
@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.0D;
}
@Override
public void openInventory(EntityPlayer player) {}
@Override
public void closeInventory(EntityPlayer player) {}
@Override
public boolean isItemValidForSlot(int index, ItemStack stack){
if(index == 3) return false;
else if(index != 2) return true;
else {
return isItemFuel(stack);
}
}
public String getGuiID(){
return "mymod:clay_furnace";
}
@Override
public int getField(int id){
switch(id){
case 0:
return this.burnTime;
case 1:
return this.currentBurnTime;
case 2:
return this.cookTime;
case 3:
return this.totalCookTime;
default:
return 0;
}
}
@Override
public void setField(int id, int value){
switch(id){
case 0:
this.burnTime = value;
break;
case 1:
this.currentBurnTime = value;
break;
case 2:
this.cookTime = value;
break;
case 3:
this.totalCookTime = value;
}
}
@Override
public int getFieldCount(){
return 4;
}
@Override
public void clear(){
this.inventory.clear();
}
}
Код:
public class GuiClayFurnace extends GuiContainer{
private static final ResourceLocation BACKGROUND = new ResourceLocation(GuiHandler.GUI_CLAY_FURNACE + ":textures/gui/machine/clay_furnace.png");
private final InventoryPlayer player;
private final TileEntityClayFurnace tileentity;
public GuiClayFurnace(InventoryPlayer player, TileEntityClayFurnace tileentity){
super(new ContainerClayFurnace(player, tileentity));
this.player = player;
this.tileentity = tileentity;
}
@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) + 3, 8, 4210752);
this.fontRenderer.drawString(this.player.getDisplayName().getUnformattedText(), 122, this.ySize - 96 + 2, 4210752);
}
@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY){
GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
this.mc.getTextureManager().bindTexture(BACKGROUND);
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
if(TileEntityClayFurnace.isBurning(tileentity)){
int k = this.getBurnLeftScaled(13);
this.drawTexturedModalRect(this.guiLeft + 8, this.guiTop + 54 + 12 - k, 176, 12 - k, 14, k + 1);
}
int l = this.getCookProgressScaled(24);
this.drawTexturedModalRect(this.guiLeft + 44, this.guiTop + 36, 176, 14, l + 1, 16);
}
private int getBurnLeftScaled(int pixels){
int i = this.tileentity.getField(1);
if(i == 0) i = 200;
return this.tileentity.getField(0) * pixels / i;
}
private int getCookProgressScaled(int pixels){
int i = this.tileentity.getField(2);
int j = this.tileentity.getField(3);
return j != 0 && i != 0 ? i * pixels / j : 0;
}
}
Код:
public class GuiHandler implements IGuiHandler{
public static final int GUI_CLAY_FURNACE = 0;
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z){
if(ID == GUI_CLAY_FURNACE)
return new ContainerClayFurnace(player.inventory, (TileEntityClayFurnace)world.getTileEntity(new BlockPos(x,y,z)));
return null;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z){
if(ID == GUI_CLAY_FURNACE)
return new GuiClayFurnace(player.inventory, (TileEntityClayFurnace)world.getTileEntity(new BlockPos(x,y,z)));
return null;
}
}