Topic category: Help with Minecraft modding (Java Edition)
Hi, everyone! I'm trying to add to my modification block with inventory, that is cabinet with drawers. My problem is that, in every MCreators for 1.7.10, the ability to add inventory to a block doesn't work and end with compilation error.
This is an error:
F:\MCreator173\forge\build\sources\java\mod\mcreator\mcreator_drawerTable.java:179: error: method createNewTileEntity(World,int) is already defined in class BlockDrawerTable
public TileEntity createNewTileEntity(World var1, int var2) {
^
F:\MCreator173\forge\build\sources\java\mod\mcreator\mcreator_drawerTable.java:346: error: class TileEntityCustom is already defined in class mcreator_drawerTable
public static class TileEntityCustom extends TileEntity implements IInventory {
^
F:\MCreator173\forge\build\sources\java\mod\mcreator\mcreator_drawerTable.java:113: error: cannot find symbol
for (int i1 = 0; i1 < tilecustom.getSizeInventory(); ++i1) {
^
symbol: method getSizeInventory()
location: variable tilecustom of type TileEntityCustom
F:\MCreator173\forge\build\sources\java\mod\mcreator\mcreator_drawerTable.java:114: error: cannot find symbol
ItemStack itemstack = tilecustom.getStackInSlot(i1);
^
symbol: method getStackInSlot(int)
location: variable tilecustom of type TileEntityCustom
F:\MCreator173\forge\build\sources\java\mod\mcreator\mcreator_drawerTable.java:158: error: incompatible types: TileEntityCustom cannot be converted to IInventory
return Container.calcRedstoneFromInventory((TileEntityCustom) tileentity);
^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
5 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
If anyone know how to fix it, please help me :(
Oh, and sorry for my English, because I'm from Poland.
Can you show your code?
Ok, here is my code:
package mod.mcreator;
import org.lwjgl.opengl.GL11;
import net.minecraft.world.World;
import net.minecraft.world.IBlockAccess;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.MathHelper;
import net.minecraft.util.IIcon;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.item.ItemStack;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Container;
import net.minecraft.init.Items;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.Entity;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.Minecraft;
import net.minecraft.block.material.Material;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.Block;
import java.util.Random;
import cpw.mods.fml.relauncher.SideOnly;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.client.registry.ClientRegistry;
public class mcreator_drawerTable {
public mcreator_drawerTable() {
}
public static BlockDrawerTable block;
public static Object instance;
public int addFuel(ItemStack fuel) {
return 0;
}
public void serverLoad(FMLServerStartingEvent event) {
}
public void preInit(FMLPreInitializationEvent event) {
GameRegistry.registerBlock(block, "DrawerTable");
}
public void registerRenderers() {
ClientRegistry
.bindTileEntitySpecialRenderer(mcreator_drawerTable.TileEntityCustom.class, new mcreator_drawerTable.TileEntityCustomRenderer());
}
public void load() {
GameRegistry.registerTileEntity(mcreator_drawerTable.TileEntityCustom.class, "TileEntitydrawerTable");
GameRegistry.registerTileEntity(mcreator_drawerTable.TileEntityCustom.class, "tileEntityDrawerTable");
GameRegistry.addRecipe(new ItemStack(block, 1), new Object[]{"X1X", "X4X", "X7X", Character.valueOf('1'), new ItemStack(Items.iron_ingot, 1),
Character.valueOf('4'), new ItemStack(Items.iron_ingot, 1), Character.valueOf('7'), new ItemStack(mcreator_ironTable.block, 1),});
}
static {
block = (BlockDrawerTable) (new BlockDrawerTable().setHardness(2.1500000000000004F).setResistance(9.5F).setLightLevel(0.0F)
.setBlockName("DrawerTable").setBlockTextureName("drawer_tabe_item").setLightOpacity(0).setStepSound(Block.soundTypeMetal)
.setCreativeTab(mcreator_spongebobMod.tab));
block.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
Block.blockRegistry.addObject(214, "DrawerTable", block);
block.setHarvestLevel("pickaxe", 0);
}
public void generateSurface(World world, Random random, int chunkX, int chunkZ) {
}
public void generateNether(World world, Random random, int chunkX, int chunkZ) {
}
static class BlockDrawerTable extends BlockContainer implements ITileEntityProvider {
int a1 = 0, a2 = 0, a3 = 0, a4 = 0, a5 = 0, a6 = 0;
Random field_149942_b = new Random();
IIcon gor = null, dol = null, st1 = null, st2 = null, st3 = null, st4 = null;
boolean red = false;
protected BlockDrawerTable() {
super(Material.iron);
}
@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {
return new TileEntityCustom();
}
@Override
public void breakBlock(World p_149749_1_, int p_149749_2_, int p_149749_3_, int p_149749_4_, Block p_149749_5_, int p_149749_6_) {
TileEntityCustom tilecustom = (TileEntityCustom) p_149749_1_.getTileEntity(p_149749_2_, p_149749_3_, p_149749_4_);
if (tilecustom != null) {
for (int i1 = 0; i1 < tilecustom.getSizeInventory(); ++i1) {
ItemStack itemstack = tilecustom.getStackInSlot(i1);
if (itemstack != null) {
float f = this.field_149942_b.nextFloat() * 0.8F + 0.1F;
float f1 = this.field_149942_b.nextFloat() * 0.8F + 0.1F;
float f2 = this.field_149942_b.nextFloat() * 0.8F + 0.1F;
while (itemstack.stackSize > 0) {
int j1 = this.field_149942_b.nextInt(21) + 10;
if (j1 > itemstack.stackSize)
j1 = itemstack.stackSize;
itemstack.stackSize -= j1;
EntityItem entityitem = new EntityItem(p_149749_1_, (double) ((float) p_149749_2_ + f),
(double) ((float) p_149749_3_ + f1), (double) ((float) p_149749_4_ + f2), new ItemStack(itemstack.getItem(), j1,
itemstack.getItemDamage()));
if (itemstack.hasTagCompound())
entityitem.getEntityItem().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy());
float f3 = 0.05F;
entityitem.motionX = (double) ((float) this.field_149942_b.nextGaussian() * f3);
entityitem.motionY = (double) ((float) this.field_149942_b.nextGaussian() * f3 + 0.2F);
entityitem.motionZ = (double) ((float) this.field_149942_b.nextGaussian() * f3);
p_149749_1_.spawnEntityInWorld(entityitem);
}
}
}
p_149749_1_.func_147453_f(p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_);
}
super.breakBlock(p_149749_1_, p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_, p_149749_6_);
}
@Override
public boolean onBlockEventReceived(World worldIn, int i, int j, int k, int eventID, int eventParam) {
super.onBlockEventReceived(worldIn, i, j, k, eventID, eventParam);
TileEntity tileentity = worldIn.getTileEntity(i, j, k);
return tileentity == null ? false : tileentity.receiveClientEvent(eventID, eventParam);
}
@Override
public boolean hasComparatorInputOverride() {
return true;
}
@Override
public int getComparatorInputOverride(World worldIn, int i, int j, int k, int l) {
TileEntity tileentity = worldIn.getTileEntity(i, j, k);
if (tileentity instanceof mcreator_drawerTable.TileEntityCustom)
return Container.calcRedstoneFromInventory((TileEntityCustom) tileentity);
else
return 0;
}
public void onBlockAdded(World world, int i, int j, int k) {
EntityPlayer entity = Minecraft.getMinecraft().thePlayer;
if (entity != null && world != null) {
int le = MathHelper.floor_double((double) (entity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
world.setBlockMetadataWithNotify(i, j, k, le, 2);
}
world.scheduleBlockUpdate(i, j, k, this, this.tickRate(world));
}
public int isProvidingStrongPower(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) {
return red ? 1 : 0;
}
@Override
public TileEntity createNewTileEntity(World var1, int var2) {
return new TileEntityCustom();
}
@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(int i, int par2) {
if (i == 0)
return gor;
else if (i == 1)
return dol;
else if (i == 2)
return st1;
else if (i == 3)
return st2;
else if (i == 4)
return st4;
else if (i == 5)
return st3;
else
return gor;
}
@SideOnly(Side.CLIENT)
@Override
public void registerBlockIcons(IIconRegister reg) {
this.gor = reg.registerIcon("drawer_tabe_item");
this.dol = reg.registerIcon("drawer_tabe_item");
this.st1 = reg.registerIcon("drawer_tabe_item");
this.st2 = reg.registerIcon("drawer_tabe_item");
this.st3 = reg.registerIcon("drawer_tabe_item");
this.st4 = reg.registerIcon("drawer_tabe_item");
}
public boolean isOpaqueCube() {
return false;
}
public boolean renderAsNormalBlock() {
return false;
}
public int getRenderType() {
return -1;
}
@Override
public int tickRate(World world) {
return 10;
}
public int quantityDropped(Random par1Random) {
return 1;
}
}
public static class TileEntityCustom extends TileEntity {
}
public static class TileEntityCustomRenderer extends TileEntitySpecialRenderer {
private final ModelTableMetal model;
public TileEntityCustomRenderer() {
this.model = new ModelTableMetal();
}
@Override
public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) {
GL11.glPushMatrix();
GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
ResourceLocation textures = (new ResourceLocation("TableDrawer.png"));
Minecraft.getMinecraft().renderEngine.bindTexture(textures);
GL11.glPushMatrix();
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
GL11.glPushMatrix();
GL11.glRotatef(te.getBlockMetadata() * 90, 0.0F, 1.0F, 0.0F);
this.model.render((Entity) null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
GL11.glPopMatrix();
GL11.glPopMatrix();
GL11.glPopMatrix();
}
}
// Date: 2016-11-07 21:01:01
// Template version 1.1
// Java generated by Techne
// Keep in mind that you still need to fill in some blanks
// - ZeuX
public static class ModelTableMetal extends ModelBase {
// fields
ModelRenderer Shape1;
ModelRenderer Shape2;
ModelRenderer Shape3;
ModelRenderer Shape4;
ModelRenderer Shape5;
public ModelTableMetal() {
textureWidth = 64;
textureHeight = 32;
Shape1 = new ModelRenderer(this, 0, 0);
Shape1.addBox(0F, 0F, 0F, 2, 10, 2);
Shape1.setRotationPoint(6F, 14F, 6F);
Shape1.setTextureSize(64, 32);
Shape1.mirror = true;
setRotation(Shape1, 0F, 0F, 0F);
Shape2 = new ModelRenderer(this, 0, 0);
Shape2.addBox(0F, 0F, 0F, 2, 10, 2);
Shape2.setRotationPoint(-8F, 14F, -8F);
Shape2.setTextureSize(64, 32);
Shape2.mirror = true;
setRotation(Shape2, 0F, 0F, 0F);
Shape3 = new ModelRenderer(this, 0, 0);
Shape3.addBox(0F, 0F, 0F, 2, 10, 2);
Shape3.setRotationPoint(6F, 14F, -8F);
Shape3.setTextureSize(64, 32);
Shape3.mirror = true;
setRotation(Shape3, 0F, 0F, 0F);
Shape4 = new ModelRenderer(this, 0, 0);
Shape4.addBox(0F, 0F, 0F, 2, 10, 2);
Shape4.setRotationPoint(-8F, 14F, 6F);
Shape4.setTextureSize(64, 32);
Shape4.mirror = true;
setRotation(Shape4, 0F, 0F, 0F);
Shape5 = new ModelRenderer(this, 0, 10);
Shape5.addBox(0F, 0F, 0F, 16, 6, 16);
Shape5.setRotationPoint(-8F, 8F, -8F);
Shape5.setTextureSize(64, 32);
Shape5.mirror = true;
setRotation(Shape5, 0F, 0F, 0F);
}
public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) {
super.render(entity, f, f1, f2, f3, f4, f5);
setRotationAngles(f, f1, f2, f3, f4, f5, entity);
Shape1.render(f5);
Shape2.render(f5);
Shape3.render(f5);
Shape4.render(f5);
Shape5.render(f5);
}
private void setRotation(ModelRenderer model, float x, float y, float z) {
model.rotateAngleX = x;
model.rotateAngleY = y;
model.rotateAngleZ = z;
}
public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity e)
{
super.setRotationAngles(f, f1, f2, f3, f4, f5, e);
}
}
public static class TileEntityCustom extends TileEntity implements IInventory {
private static final Random RNG = new Random();
private ItemStack[] stacks = new ItemStack[9];
protected String customName;
public ItemStack getStackInSlotOnClosing(int p_70304_1_) {
if (this.stacks[p_70304_1_] != null) {
ItemStack itemstack = this.stacks[p_70304_1_];
this.stacks[p_70304_1_] = null;
return itemstack;
} else {
return null;
}
}
public int getSizeInventory() {
return 9;
}
public ItemStack getStackInSlot(int index) {
return this.stacks[index];
}
public ItemStack decrStackSize(int index, int count) {
if (this.stacks[index] != null) {
if (this.stacks[index].stackSize <= count) {
ItemStack itemstack1 = this.stacks[index];
this.stacks[index] = null;
this.markDirty();
return itemstack1;
} else {
ItemStack itemstack = this.stacks[index].splitStack(count);
if (this.stacks[index].stackSize == 0) {
this.stacks[index] = null;
}
this.markDirty();
return itemstack;
}
} else {
return null;
}
}
/**
* Removes a stack from the given slot and returns it.
*/
public ItemStack removeStackFromSlot(int index) {
if (this.stacks[index] != null) {
ItemStack itemstack = this.stacks[index];
this.stacks[index] = null;
return itemstack;
} else {
return null;
}
}
public void setInventorySlotContents(int index, ItemStack stack) {
this.stacks[index] = stack;
if (stack != null && stack.stackSize > this.getInventoryStackLimit()) {
stack.stackSize = this.getInventoryStackLimit();
}
this.markDirty();
}
public int addItemStack(ItemStack stack) {
for (int i = 0; i < this.stacks.length; ++i) {
if (this.stacks[i] == null || this.stacks[i].getItem() == null) {
this.setInventorySlotContents(i, stack);
return i;
}
}
return -1;
}
public String getName() {
return this.hasCustomName() ? this.customName : "container.dispenser";
}
public void setCustomName(String customName) {
this.customName = customName;
}
public boolean hasCustomName() {
return this.customName != null;
}
@Override
public void readFromNBT(NBTTagCompound compound) {
super.readFromNBT(compound);
NBTTagList nbttaglist = compound.getTagList("Items", 10);
this.stacks = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < nbttaglist.tagCount(); ++i) {
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
int j = nbttagcompound.getByte("Slot") & 255;
if (j >= 0 && j < this.stacks.length) {
this.stacks[j] = ItemStack.loadItemStackFromNBT(nbttagcompound);
}
}
}
@Override
public void writeToNBT(NBTTagCompound compound) {
super.writeToNBT(compound);
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < this.stacks.length; ++i) {
if (this.stacks[i] != null) {
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setByte("Slot", (byte) i);
this.stacks[i].writeToNBT(nbttagcompound);
nbttaglist.appendTag(nbttagcompound);
}
}
compound.setTag("Items", nbttaglist);
}
public int getInventoryStackLimit() {
return 64;
}
public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {
return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : p_70300_1_.getDistanceSq(
(double) this.xCoord + 0.5D, (double) this.yCoord + 0.5D, (double) this.zCoord + 0.5D) <= 64.0D;
}
public void openInventory(EntityPlayer player) {
}
public void closeInventory(EntityPlayer player) {
}
/**
* Returns true if automation is allowed to insert the given stack
* (ignoring stack size) into the given slot.
*/
public boolean isItemValidForSlot(int index, ItemStack stack) {
return true;
}
public String getGuiID() {
return "minecraft:drawerTable";
}
public int getField(int id) {
return 0;
}
public void setField(int id, int value) {
}
public int getFieldCount() {
return 0;
}
public void clear() {
for (int i = 0; i < this.stacks.length; ++i) {
this.stacks[i] = null;
}
}
public void openInventory() {
}
public void closeInventory() {
}
public String getInventoryName() {
return "minecraft:drawerTable";
}
/**
* Returns if the inventory is named
*/
public boolean hasCustomInventoryName() {
return false;
}
}
}
There is link to download code file: https://www.dropbox.com/s/catyuhfx6g1d6br/mcreator_drawerTable.java?dl=0
with me it doesn't give recompile errors it just doesn't work in game