Closed zenmogwai closed 8 years ago
um, that doesn't happen for me. Is this if you try to compile the modtut from the 1.10.2 branch?
I just now saw the branch. Let me retry.
Still get the same error. I'm just copying the code with a minor tweak to the package location.
Well I need to see your code as the original modtut code doesn't have that problem
I was following the tutorial for the custom container. Here are the main, the proxy, the ModBlock and the block classes. I also have the GUI, TileEntity, GUIProxy and Container class but it seems like the conflict is between the ModBlock and the Block.
The Main Class
package modtut;
import org.apache.logging.log4j.Logger;
import net.minecraft.block.Block;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
@Mod(modid = ModTut.MODID, name = ModTut.MODNAME, version = ModTut.MODVERSION,
useMetadata = true)
public class ModTut {
public static final String MODID = "modtut";
public static final String MODNAME = "Mod tutorials";
public static final String MODVERSION = "0.0.1";
TestContainerBlock newBlock = new TestContainerBlock();
@SidedProxy (clientSide = "modtut.ClientProxy", serverSide = "modtut.ServerProxy")
public static CommonProxy proxy;
@Mod.Instance
public static ModTut instance;
public static Logger logger;
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
logger = event.getModLog();
proxy.preInit(event);
}
@Mod.EventHandler
public void init(FMLInitializationEvent event) {
proxy.init(event);
}
@Mod.EventHandler
public void postInit(FMLPostInitializationEvent event) {
proxy.postInit(event);
}
}
The proxy class
package modtut;
import net.minecraft.block.Block;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
public class CommonProxy {
public void preInit(FMLPreInitializationEvent event) {
ModBlocks.init();
}
public void init(FMLInitializationEvent event) {
NetworkRegistry.INSTANCE.registerGuiHandler(ModTut.instance, new GuiProxy());
}
public void postInit(FMLPostInitializationEvent event) {
}
}
The ModBlocks class
package modtut;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ModBlocks {
public static TestContainerBlock testContainerBlock;
public static void init() {
testContainerBlock = new TestContainerBlock();
}
@SideOnly(Side.CLIENT)
public static void initModels() {
testContainerBlock.initModel();
}
@SideOnly(Side.CLIENT)
public static void initItemModels() {
}
}
and the block class
package modtut;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class TestContainerBlock extends Block implements ITileEntityProvider {
public static final int GUI_ID = 1;
public TestContainerBlock() {
super(Material.ROCK);
setUnlocalizedName(ModTut.MODID + ".testcontainerblock");
setRegistryName("testcontainerblock");
GameRegistry.register(this);
GameRegistry.register(new ItemBlock(this), getRegistryName());
GameRegistry.registerTileEntity(TestContainerTileEntity.class, ModTut.MODID + "_testcontainerblock");
setCreativeTab(CreativeTabs.MISC);
}
@SideOnly(Side.CLIENT)
public void initModel() {
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(), "inventory"));
}
@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {
return new TestContainerTileEntity();
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side,
float hitX, float hitY, float hitZ) {
// Only execute on the server
if (world.isRemote) {
return true;
}
TileEntity te = world.getTileEntity(pos);
if (!(te instanceof TestContainerTileEntity)) {
return false;
}
player.openGui(ModTut.instance, GUI_ID, world, pos.getX(), pos.getY(), pos.getZ());
return true;
}
}
You do new TestContainerBlock() twice. Once in ModTut and one in ModBlocks. That's wrong. Every block should only exist once. Remove the one in ModTut
Following the code for blocks results in attempt to register the same block twice.
The name tutmod:testcontainerblock has been registered twice, for Block{tutmod:testcontainerblock} and Block{null}.