Does this guarantee a gold ingot to drop on every pig kill? How would you factor in a fortune weapon to increase drop changes, or Fire Aspect? Like, if normally the big dropped gold ore, but with said enchant it then drops the ingot instead.
Well how was i supposed to know that? I looked up a tut on youtube and apparently yours is wrong and not as efficient. I got like a sword and 2 other items in the game in less than 30 minutes while i was struggling to understand your tut for a few hours
Well how was i supposed to know that? I looked up a tut on youtube and apparently yours is wrong and not as efficient. I got like a sword and 2 other items in the game in less than 30 minutes while i was struggling to understand your tut for a few hours
Alright then if you're too stupid to follow my tutorial it's fine with me for you to go find an easier tutorial for whiny babies like you.
Hey, I just read your tut about making a custom storage block, and (although it was dealing with storage) it got me much closer to understanding how to make blocks with GUIs like that. My problem, though, is that even after copy/pasting your code (and modifying it a bit so that it references that right parts of my code), Minecraft crashes when I open the GUI, telling me that the TileEntity is "missing a mapping." Below (in the spoiler, hopefully) is the crash log.
A TileEntity type io.github.tntftw21.electromag.tileentity.TileEntityEMChamber has throw an exception trying to write state. It will not persist. Report this to the mod author
java.lang.RuntimeException: class io.github.tntftw21.electromag.tileentity.TileEntityEMChamber is missing a mapping! This is a bug!
at net.minecraft.tileentity.TileEntity.writeToNBT(TileEntity.java:96) ~[TileEntity.class:?]
at io.github.tntftw21.electromag.tileentity.TileEntityEMChamber.writeToNBT(TileEntityEMChamber.java:100) ~[TileEntityEMChamber.class:?]
at net.minecraft.world.chunk.storage.AnvilChunkLoader.writeChunkToNBT(AnvilChunkLoader.java:395) [AnvilChunkLoader.class:?]
at net.minecraft.world.chunk.storage.AnvilChunkLoader.saveChunk(AnvilChunkLoader.java:204) [AnvilChunkLoader.class:?]
at net.minecraft.world.gen.ChunkProviderServer.safeSaveChunk(ChunkProviderServer.java:287) [ChunkProviderServer.class:?]
at net.minecraft.world.gen.ChunkProviderServer.saveChunks(ChunkProviderServer.java:340) [ChunkProviderServer.class:?]
at net.minecraft.world.WorldServer.saveAllChunks(WorldServer.java:863) [WorldServer.class:?]
at net.minecraft.server.MinecraftServer.saveAllWorlds(MinecraftServer.java:370) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.stopServer(MinecraftServer.java:405) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.stopServer(IntegratedServer.java:266) [IntegratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:538) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?]
private String frontTexName;
private String sideTexName;
public IIcon sideTex;
public IIcon frontTex;
private static final String name = "Electromagnetic Chamber";
private final Random rand = new Random();
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemStack) {
int l = MathHelper.floor_double((double)(entity.rotationYaw * 4.0f / 360.0f) + 0.5d) & 3;
switch(l) {
case 0:
world.setBlockMetadataWithNotify(x, y, z, 2, 2);
break;
case 1:
world.setBlockMetadataWithNotify(x, y, z, 5, 2);
break;
case 2:
world.setBlockMetadataWithNotify(x, y, z, 3, 2);
break;
case 3:
world.setBlockMetadataWithNotify(x, y, z, 4, 2);
break;
}
}
@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(int side, int meta)
{
return side == 1 ? this.sideTex : (side == 0 ? this.sideTex : (side != meta ? this.sideTex : this.frontTex));
}
@SideOnly(Side.CLIENT)
@Override
public void registerBlockIcons(IIconRegister reg)
{
this.sideTex = reg.registerIcon(this.sideTexName);
this.frontTex = reg.registerIcon(this.frontTexName);
}
@Override
public int damageDropped(int meta) {
return 0;
}
@Override
public TileEntity createNewTileEntity(World world, int meta) {
return new TileEntityEMChamber();
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
if (world.isRemote) {
return true;
}
TileEntity te = world.getTileEntity(x, y, z);
if (te != null && te instanceof TileEntityEMChamber) {
player.openGui(Main.instance, 0, world, x, y, z);
return true;
}
return false;
}
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int par6) {
if (world.isRemote){
return;
}
ArrayList drops = new ArrayList();
TileEntity teRaw = world.getTileEntity(x, y, z);
if (teRaw != null && teRaw instanceof TileEntityEMChamber) {
TileEntityEMChamber te = (TileEntityEMChamber) teRaw;
for (int i = 0; i < te.getSizeInventory(); i++) {
ItemStack stack = te.getStackInSlot(i);
if (stack != null) {
drops.add(stack.copy());
}
}
}
for (int i = 0; i < drops.size(); i++) {
EntityItem item = new EntityItem(world, x + 0.5, y + 0.5, z + 0.5);
item.setVelocity((rand.nextDouble() - 0.5) * 0.25, rand.nextDouble() * 0.5 * 0.25, (rand.nextDouble() - 0.5) * 0.25);
world.spawnEntityInWorld(item);
}
}
}
//TODO Create TileEntityEM and AbilityRegistry
public class TileEntityEMChamber extends TileEntity implements IInventory {
private ItemStack[] items = new ItemStack[15];
@Override
public int getSizeInventory() {
return items.length;
}
@Override
public ItemStack getStackInSlot(int slot) {
return items[slot];
}
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world,
int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
if (te != null) {
if (ID == 0) {
return new ContainerStorage((TileEntityEMChamber)te, player);
}
}
return null;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world,
int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
if (te != null) {
if (ID == 0) {
return new ContainerStorage((TileEntityEMChamber)te, player);
}
}
return null;
}
@Override
public boolean canInteractWith(EntityPlayer player)
{
return te.isUseableByPlayer(player);
}
}
I'm still kind of a noob with modding (even more so with making GUIs and whatnot, since the only tutorials I find are shady at best), so for all I know I could have made a rookie mistake.
Hey, I just read your tut about making a custom storage block, and (although it was dealing with storage) it got me much closer to understanding how to make blocks with GUIs like that. My problem, though, is that even after copy/pasting your code (and modifying it a bit so that it references that right parts of my code), Minecraft crashes when I open the GUI, telling me that the TileEntity is "missing a mapping." Below (in the spoiler, hopefully) is the crash log.
A TileEntity type io.github.tntftw21.electromag.tileentity.TileEntityEMChamber has throw an exception trying to write state. It will not persist. Report this to the mod author
java.lang.RuntimeException: class io.github.tntftw21.electromag.tileentity.TileEntityEMChamber is missing a mapping! This is a bug!
at net.minecraft.tileentity.TileEntity.writeToNBT(TileEntity.java:96) ~[TileEntity.class:?]
at io.github.tntftw21.electromag.tileentity.TileEntityEMChamber.writeToNBT(TileEntityEMChamber.java:100) ~[TileEntityEMChamber.class:?]
at net.minecraft.world.chunk.storage.AnvilChunkLoader.writeChunkToNBT(AnvilChunkLoader.java:395) [AnvilChunkLoader.class:?]
at net.minecraft.world.chunk.storage.AnvilChunkLoader.saveChunk(AnvilChunkLoader.java:204) [AnvilChunkLoader.class:?]
at net.minecraft.world.gen.ChunkProviderServer.safeSaveChunk(ChunkProviderServer.java:287) [ChunkProviderServer.class:?]
at net.minecraft.world.gen.ChunkProviderServer.saveChunks(ChunkProviderServer.java:340) [ChunkProviderServer.class:?]
at net.minecraft.world.WorldServer.saveAllChunks(WorldServer.java:863) [WorldServer.class:?]
at net.minecraft.server.MinecraftServer.saveAllWorlds(MinecraftServer.java:370) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.stopServer(MinecraftServer.java:405) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.stopServer(IntegratedServer.java:266) [IntegratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:538) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?]
private String frontTexName;
private String sideTexName;
public IIcon sideTex;
public IIcon frontTex;
private static final String name = "Electromagnetic Chamber";
private final Random rand = new Random();
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemStack) {
int l = MathHelper.floor_double((double)(entity.rotationYaw * 4.0f / 360.0f) + 0.5d) & 3;
switch(l) {
case 0:
world.setBlockMetadataWithNotify(x, y, z, 2, 2);
break;
case 1:
world.setBlockMetadataWithNotify(x, y, z, 5, 2);
break;
case 2:
world.setBlockMetadataWithNotify(x, y, z, 3, 2);
break;
case 3:
world.setBlockMetadataWithNotify(x, y, z, 4, 2);
break;
}
}
@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(int side, int meta)
{
return side == 1 ? this.sideTex : (side == 0 ? this.sideTex : (side != meta ? this.sideTex : this.frontTex));
}
@SideOnly(Side.CLIENT)
@Override
public void registerBlockIcons(IIconRegister reg)
{
this.sideTex = reg.registerIcon(this.sideTexName);
this.frontTex = reg.registerIcon(this.frontTexName);
}
@Override
public int damageDropped(int meta) {
return 0;
}
@Override
public TileEntity createNewTileEntity(World world, int meta) {
return new TileEntityEMChamber();
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
if (world.isRemote) {
return true;
}
TileEntity te = world.getTileEntity(x, y, z);
if (te != null && te instanceof TileEntityEMChamber) {
player.openGui(Main.instance, 0, world, x, y, z);
return true;
}
return false;
}
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int par6) {
if (world.isRemote){
return;
}
ArrayList drops = new ArrayList();
TileEntity teRaw = world.getTileEntity(x, y, z);
if (teRaw != null && teRaw instanceof TileEntityEMChamber) {
TileEntityEMChamber te = (TileEntityEMChamber) teRaw;
for (int i = 0; i < te.getSizeInventory(); i++) {
ItemStack stack = te.getStackInSlot(i);
if (stack != null) {
drops.add(stack.copy());
}
}
}
for (int i = 0; i < drops.size(); i++) {
EntityItem item = new EntityItem(world, x + 0.5, y + 0.5, z + 0.5);
item.setVelocity((rand.nextDouble() - 0.5) * 0.25, rand.nextDouble() * 0.5 * 0.25, (rand.nextDouble() - 0.5) * 0.25);
world.spawnEntityInWorld(item);
}
}
}
//TODO Create TileEntityEM and AbilityRegistry
public class TileEntityEMChamber extends TileEntity implements IInventory {
private ItemStack[] items = new ItemStack[15];
@Override
public int getSizeInventory() {
return items.length;
}
@Override
public ItemStack getStackInSlot(int slot) {
return items[slot];
}
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world,
int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
if (te != null) {
if (ID == 0) {
return new ContainerStorage((TileEntityEMChamber)te, player);
}
}
return null;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world,
int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
if (te != null) {
if (ID == 0) {
return new ContainerStorage((TileEntityEMChamber)te, player);
}
}
return null;
}
@Override
public boolean canInteractWith(EntityPlayer player)
{
return te.isUseableByPlayer(player);
}
}
I'm still kind of a noob with modding (even more so with making GUIs and whatnot, since the only tutorials I find are shady at best), so for all I know I could have made a rookie mistake.
You need to register the tile entity with GameRegistry.registerTileEntity()
Time: 5/25/15 10:43 AM
Description: Rendering screen
java.lang.ArrayIndexOutOfBoundsException: 15
at blocks.IronCrateTile.getStackInSlot(IronCrateTile.java:22)
at net.minecraft.inventory.Slot.getStack(Slot.java:88)
at net.minecraft.client.gui.inventory.GuiContainer.func_146977_a(GuiContainer.java:219)
at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:114)
at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1137)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1056)
at net.minecraft.client.Minecraft.run(Minecraft.java:951)
at net.minecraft.client.main.Main.main(Main.java:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)
at GradleStart.main(Unknown Source)
A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------
-- Head --
Stacktrace:
at blocks.IronCrateTile.getStackInSlot(IronCrateTile.java:22)
at net.minecraft.inventory.Slot.getStack(Slot.java:88)
at net.minecraft.client.gui.inventory.GuiContainer.func_146977_a(GuiContainer.java:219)
at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:114)
Thanks, I hadn't realized that I had to register that (I had followed another tut on basic tile entities, and I don't remember having to do that). Now, though, Forge keeps telling me that "io.github.tntftw21.electromag.ContainerStorage cannot be cast to net.minecraft.client.gui.GuiScreen." The only part of my code that I changed was the part in ModBlocks.java, which registers the tile entity, too. I also tried switching the object passed by GuiHandler.java to use GuiStorage(te, player) instead of ContainerStorage(te, player), but that led to one heck of a crash log. Here is the error from the above:
[14:31:02] [Client thread/ERROR] [FML]: There was a critical exception handling a packet on channel FML
java.lang.ClassCastException: io.github.tntftw21.electromag.client.gui.ContainerStorage cannot be cast to net.minecraft.client.gui.GuiScreen
at cpw.mods.fml.client.FMLClientHandler.showGuiScreen(FMLClientHandler.java:444) ~[FMLClientHandler.class:?]
at cpw.mods.fml.common.FMLCommonHandler.showGuiScreen(FMLCommonHandler.java:303) ~[FMLCommonHandler.class:?]
at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:94) ~[FMLNetworkHandler.class:?]
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2501) ~[EntityPlayer.class:?]
at cpw.mods.fml.common.network.internal.OpenGuiHandler.channelRead0(OpenGuiHandler.java:16) ~[OpenGuiHandler.class:?]
at cpw.mods.fml.common.network.internal.OpenGuiHandler.channelRead0(OpenGuiHandler.java:11) ~[OpenGuiHandler.class:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[SimpleChannelInboundHandler.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:101) ~[SimpleChannelInboundHandler.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?]
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) ~[MessageToMessageDecoder.class:?]
at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) ~[DefaultChannelPipeline.class:?]
at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) ~[EmbeddedChannel.class:?]
at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?]
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [NetworkManager.class:?]
at net.minecraft.client.multiplayer.PlayerControllerMP.updateController(PlayerControllerMP.java:317) [PlayerControllerMP.class:?]
at net.minecraft.client.Minecraft.runTick(Minecraft.java:1682) [Minecraft.class:?]
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1028) [Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:951) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_40]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_40]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_40]
at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_40]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?]
at GradleStart.main(Unknown Source) [start/:?]
The weird thing is that this error always occurs in triplets (the same one appears three times one after the other, before kicking me from the internal server).
Thanks, I hadn't realized that I had to register that (I had followed another tut on basic tile entities, and I don't remember having to do that). Now, though, Forge keeps telling me that "io.github.tntftw21.electromag.ContainerStorage cannot be cast to net.minecraft.client.gui.GuiScreen." The only part of my code that I changed was the part in ModBlocks.java, which registers the tile entity, too. I also tried switching the object passed by GuiHandler.java to use GuiStorage(te, player) instead of ContainerStorage(te, player), but that led to one heck of a crash log. Here is the error from the above:
[14:31:02] [Client thread/ERROR] [FML]: There was a critical exception handling a packet on channel FML
java.lang.ClassCastException: io.github.tntftw21.electromag.client.gui.ContainerStorage cannot be cast to net.minecraft.client.gui.GuiScreen
at cpw.mods.fml.client.FMLClientHandler.showGuiScreen(FMLClientHandler.java:444) ~[FMLClientHandler.class:?]
at cpw.mods.fml.common.FMLCommonHandler.showGuiScreen(FMLCommonHandler.java:303) ~[FMLCommonHandler.class:?]
at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:94) ~[FMLNetworkHandler.class:?]
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2501) ~[EntityPlayer.class:?]
at cpw.mods.fml.common.network.internal.OpenGuiHandler.channelRead0(OpenGuiHandler.java:16) ~[OpenGuiHandler.class:?]
at cpw.mods.fml.common.network.internal.OpenGuiHandler.channelRead0(OpenGuiHandler.java:11) ~[OpenGuiHandler.class:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[SimpleChannelInboundHandler.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:101) ~[SimpleChannelInboundHandler.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?]
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) ~[MessageToMessageDecoder.class:?]
at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) ~[DefaultChannelPipeline.class:?]
at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) ~[EmbeddedChannel.class:?]
at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?]
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [NetworkManager.class:?]
at net.minecraft.client.multiplayer.PlayerControllerMP.updateController(PlayerControllerMP.java:317) [PlayerControllerMP.class:?]
at net.minecraft.client.Minecraft.runTick(Minecraft.java:1682) [Minecraft.class:?]
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1028) [Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:951) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_40]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_40]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_40]
at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_40]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?]
at GradleStart.main(Unknown Source) [start/:?]
The weird thing is that this error always occurs in triplets (the same one appears three times one after the other, before kicking me from the internal server).
take a look at your GuiScreen. You might have mixed serverside and clientside stuff
I was searching on youtube for a good tutorial about how to mod in minecraft 1.7.10 forge. I came across TheMchewy's tutorial, and I really liked it. But at episode 6, about the textures, here's the link:
, I saw a comment, saying that the episode was outdated, and that the .setBlockTexture command wouldn't exist anymore. It followed a very confusing (at least for me) explanation of what to do (telling something about 3 or 4 .json files and some weird code that I don't know where to put xP).
So, searching for an answer, I found this topic, with very nice tutorials... but in the Adding Items tutorial, you are still using the .setTextureName command.
Would you mind telling me (or making a tutorial about it) if that command is in fact still working, or if not what the heck i should do?
Thank you very much
feflopizer
that command still works, and it does work very well for 1.7.10. If I remember correctly, 1.8 removes this and switched to using .json assets.
how can I make a recipe like that of a sword, that would be "X " "X " "S ", and " X " " X " " S " and " X" " X" " S", so a recipe with more possibilities, but not completely shapeless? Should I just add a line of code for each possibility, or is there another way?
Thanks
feflopizer
I think you can do "X", "X", "S" and it will work perfectly.
public class RainbowStorage extends BlockContainer {
private static final String name = "storage";
private final Random rand = new Random();
public RainbowStorage() {
super(Material.wood);
this.setCreativeTab(Main.tabRainbowMod);
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float lx, float ly, float lz) {
if(world.isRemote)
return true;
TileEntity te = world.getTileEntity(x, y, z);
if (te != null && te instanceof TileEntityRainbowStorage) {
player.openGui(Main.instance, 0, world, x, y, z);
return true;
}
return false;
}
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int par6) {
if(world.isRemote)
return;
ArrayList drops = new ArrayList();
TileEntity teRaw = world.getTileEntity(x, y, z);
if(teRaw != null && teRaw instanceof TileEntityRainbowStorage) {
TileEntityRainbowStorage te = (TileEntityRainbowStorage) teRaw;
for (int i =0; i < te.getSizeInventory(); i++) {
ItemStack stack = te.getStackInSlot(i);
if(stack != null) drops.add(stack.copy());
}
}
for(int i = 0; i < drops.size(); i++) {
EntityItem item = new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, (ItemStack) drops.get(i));
item.setVelocity((rand.nextDouble() - 0.5) * 0.25, rand.nextDouble() * 0.5 * 0.25, (rand.nextDouble() - 0.5) * 0.25);
world.spawnEntityInWorld(item);
}
}
@Override
public TileEntity createNewTileEntity(World world, int par2) {
return new TileEntityRainbowStorage();
}
@Override
public String getInventoryName() {
return "container.rainbowStorage";
}
@Override
public boolean hasCustomInventoryName() {
return false;
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
NBTTagList list = nbt.getTagList("Items", Constants.NBT.TAG_COMPOUND);
items = new ItemStack[getSizeInventory()];
for (int i = 0; i < list.tagCount(); ++i) { NBTTagCompound comp = list.getCompoundTagAt(i); int j = comp.getByte("Slot") & 255; if (j >= 0 && j < items.length) {
items[j] = ItemStack.loadItemStackFromNBT(comp);
}
}
}
@Override
public void writeToNBT(NBTTagCompound nbt){
super.writeToNBT(nbt);
NBTTagList list = new NBTTagList();
for (int i = 0; i < items.length; ++i){
if (items != null){
NBTTagCompound comp = new NBTTagCompound();
comp.setByte("Slot", (byte)i);
items.writeToNBT(comp);
list.appendTag(comp);
}
}
nbt.setTag("Items", list);
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
TileEntity entity = world.getTileEntity(x, y, z);
if(entity != null) {
switch(ID) {
case Main.guiIDDarkFurnace:
if (entity instanceof TileEntityDarkFurnace) {
return new ContainerDarkFurnace(player.inventory, (TileEntityDarkFurnace) entity);
}
return null;
case Main.guiIDRainbowFurnace:
if (entity instanceof TileEntityRainbowFurnace) {
return new ContainerRainbowFurnace(player.inventory, (TileEntityRainbowFurnace) entity);
}
return null;
}
}
if(ID == Main.guiIDRainbowCraftingTable) {
return ID == Main.guiIDRainbowCraftingTable && world.getBlock(x, y, z) == BlocksDecRM.RainbowCraftingTable ? new ContainerRainbowCraftingTable(player.inventory, world, x, y, z) : null;
}
TileEntity te = world.getTileEntity(x, y, z);
if(te != null) {
if(ID == Main.guiIDRainbowStorageBlock) {
return new ContainerRainbowStorage((TileEntityRainbowStorage)te, player);
}
}
return null;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
TileEntity entity = world.getTileEntity(x, y, z);
if (entity != null) {
switch (ID) {
case Main.guiIDDarkFurnace:
if (entity instanceof TileEntityDarkFurnace) {
return new GuiDarkFurnace(player.inventory, (TileEntityDarkFurnace) entity);
}
return null;
case Main.guiIDRainbowFurnace:
if (entity instanceof TileEntityRainbowFurnace) {
return new GuiRainbowFurnace(player.inventory, (TileEntityRainbowFurnace) entity);
}
return null;
}
}
if(ID == Main.guiIDRainbowCraftingTable) {
return ID == Main.guiIDRainbowCraftingTable && world.getBlock(x, y, z) == BlocksDecRM.RainbowCraftingTable ? new GuiRainbowCraftingTable(player.inventory, world, x, y, z) : null;
}
TileEntity te = world.getTileEntity(x, y, z);
if(te != null) {
if(ID == Main.guiIDRainbowStorageBlock) {
return new GuiRainbowStorage((TileEntityRainbowStorage)te, player);
}
}
return null;
}
@Mod(modid = Main.modID, version = Main.version, name = Main.modName)
public class Main {
@SidedProxy(clientSide= "com.rainbow.mod.proxy.ClientProxy" , serverSide= "com.rainbow.mod.proxy.CommonProxy")
public static CommonProxy proxy;
public static final String modID = "rainbowmod";
public static final String version = "alpha 0.1";
public static final String modName = "RainbowMod";
public static CreativeTabs tabRainbowMod = new CreativeTabs("RainbowMod") {
@SideOnly(Side.CLIENT)
public Item getTabIconItem() {
return Item.getItemFromBlock(RainbowOre);
}
};
public static CreativeTabs tabDark = new CreativeTabs("Dark") {
@SideOnly(Side.CLIENT)
public Item getTabIconItem() {
return Item.getItemFromBlock(DarkStone);
}
};
public static CreativeTabs tabRainbowModMaterials = new CreativeTabs("RainbowModMaterials") {
@SideOnly(Side.CLIENT)
public Item getTabIconItem() {
return ItemsDecRM.itemRainbowIngot;
}
};
public static CreativeTabs tabRainbowModFoods = new CreativeTabs("RainbowModFoods") {
@SideOnly(Side.CLIENT)
public Item getTabIconItem() {
return ItemsDecRM.RainbowApple;
}
};
@Instance(modID)
public static Main instance;
public static int entityIndex = 0;
//Entities
public static void registerEntity(Class entityClass, String name) {
int entityID = EntityRegistry.findGlobalUniqueEntityId();
long seed = name.hashCode();
Random rand = new Random(seed);
int primaryColor = rand.nextInt() * 16777215;
int secondaryColor = rand.nextInt() * 16777215;
//Dimensions
public static int RainbowDimension = 5;
//Machines
public static Block DarkFurnaceIdle;
public static Block DarkFurnaceActive;
public static final int guiIDDarkFurnace = 0;
public static Block RainbowFurnaceIdle;
public static Block RainbowFurnaceActive;
public static final int guiIDRainbowFurnace = 1;
public static final int guiIDRainbowCraftingTable = 2;
public static final int guiIDRainbowStorageBlock = 3;
//Armor
public static ItemArmor.ArmorMaterial RainbowArmorMaterial = EnumHelper.addArmorMaterial("RainbowArmor", 25, new int[]{3, 7, 8, 3}, 10);
public static ItemArmor.ArmorMaterial DarkArmorMaterial = EnumHelper.addArmorMaterial("DarkArmor", 25, new int[]{3, 7, 8, 3}, 10);
public static ItemArmor.ArmorMaterial EmeraldArmorMaterial = EnumHelper.addArmorMaterial("EmeraldArmor", 24, new int[]{2, 6, 7, 2}, 9);
public static int armorRainbowHelmID;
public static int armorRainbowChestID;
public static int armorRainbowLegsID;
public static int armorRainbowBootsID;
public static Item armorRainbowHelm;
public static Item armorRainbowChest;
public static Item armorRainbowLegs;
public static Item armorRainbowBoots;
public static int armorDarkHelmID;
public static int armorDarkChestID;
public static int armorDarkLegsID;
public static int armorDarkBootsID;
public static Item armorDarkHelm;
public static Item armorDarkChest;
public static Item armorDarkLegs;
public static Item armorDarkBoots;
public static int armorEmeraldHelmID;
public static int armorEmeraldChestID;
public static int armorEmeraldLegsID;
public static int armorEmeraldBootsID;
public static Item armorEmeraldHelm;
public static Item armorEmeraldChest;
public static Item armorEmeraldLegs;
public static Item armorEmeraldBoots;
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent preEvent) {
ItemsRM.init();
BlocksRM.init();
//Machines
DarkFurnaceIdle = new DarkFurnace(false).setBlockName("DarkFurnaceIdle").setCreativeTab(Main.tabDark).setHardness(3.5F);
DarkFurnaceActive = new DarkFurnace(true).setBlockName("DarkFurnaceActive").setLightLevel(0.625F).setHardness(3.5F);
RainbowFurnaceIdle = new RainbowFurnace(false).setBlockName("RainbowFurnaceIdle").setCreativeTab(Main.tabRainbowMod).setHardness(3.5F);
RainbowFurnaceActive = new RainbowFurnace(true).setBlockName("RainbowFurnaceActive").setLightLevel(0.625F).setHardness(3.5F);
//Armor
armorRainbowHelm = new RainbowArmor(RainbowArmorMaterial, armorRainbowHelmID, 0).setUnlocalizedName("RainbowHelm");
armorRainbowChest = new RainbowArmor(RainbowArmorMaterial, armorRainbowChestID, 1).setUnlocalizedName("RainbowChest");
armorRainbowLegs = new RainbowArmor(RainbowArmorMaterial, armorRainbowLegsID, 2).setUnlocalizedName("RainbowLegs");
armorRainbowBoots = new RainbowArmor(RainbowArmorMaterial, armorRainbowBootsID, 3).setUnlocalizedName("RainbowBoots");
armorDarkHelm = new DarkArmor(DarkArmorMaterial, armorDarkHelmID, 0).setUnlocalizedName("DarkHelm");
armorDarkChest = new DarkArmor(DarkArmorMaterial, armorDarkChestID, 1).setUnlocalizedName("DarkChest");
armorDarkLegs = new DarkArmor(DarkArmorMaterial, armorDarkLegsID, 2).setUnlocalizedName("DarkLegs");
armorDarkBoots = new DarkArmor(DarkArmorMaterial, armorDarkBootsID, 3).setUnlocalizedName("DarkBoots");
armorEmeraldHelm = new EmeraldArmor(EmeraldArmorMaterial, armorEmeraldHelmID, 0).setUnlocalizedName("EmeraldHelm");
armorEmeraldChest = new EmeraldArmor(EmeraldArmorMaterial, armorEmeraldChestID, 1).setUnlocalizedName("EmeraldChest");
armorEmeraldLegs = new EmeraldArmor(EmeraldArmorMaterial, armorEmeraldLegsID, 2).setUnlocalizedName("EmeraldLegs");
armorEmeraldBoots = new EmeraldArmor(EmeraldArmorMaterial, armorEmeraldBootsID, 3).setUnlocalizedName("EmeraldBoots");
//Smelting Recipes
GameRegistry.addSmelting(RainbowOre, new ItemStack(itemRainbowIngot), 4.0F);
GameRegistry.addSmelting(Blocks.stone, new ItemStack(DarkStone), 2.0F);
GameRegistry.addSmelting(DarkOre, new ItemStack(itemDarkIngot), 5.0f);
GameRegistry.addSmelting(RainbowPorkchopRaw, new ItemStack(RainbowPorkchopCooked), 2.0F);
//Shaped Crafting Recipes
GameRegistry.addShapedRecipe(new ItemStack(RainbowPlank, 9), new Object[] {"WWW", "WWW", "WWW", 'W', RainbowLog});
GameRegistry.addShapedRecipe(new ItemStack(RainbowBlock), new Object[]{"III", "III", "III", 'I', itemRainbowIngot});
GameRegistry.addShapedRecipe(new ItemStack(RainbowCraftingTable), new Object[]{"PPP", "PCP", "PPP", 'P', RainbowPlank, 'C', Blocks.crafting_table});
GameRegistry.addShapedRecipe(new ItemStack(itemRainbowShovel), new Object[]{"I", "S", "S", 'I',itemRainbowIngot, 'S', Items.stick });
GameRegistry.addShapedRecipe(new ItemStack(itemRainbowPickaxe), new Object[]{"III", " S ", " S ", 'I',itemRainbowIngot, 'S', Items.stick });
GameRegistry.addShapedRecipe(new ItemStack(itemRainbowAxe), new Object[]{"II", "IS", " S", 'I',itemRainbowIngot, 'S', Items.stick });
GameRegistry.addShapedRecipe(new ItemStack(itemRainbowSword), new Object[]{"I", "I", "S", 'I',itemRainbowIngot, 'S', Items.stick });
GameRegistry.addShapedRecipe(new ItemStack(itemRainbowHoe), new Object[]{"II", " S", " S", 'I',itemRainbowIngot, 'S', Items.stick });
GameRegistry.addShapedRecipe(new ItemStack(itemDarkShovel), new Object[]{"I", "S", "S", 'I',itemDarkIngot, 'S', Items.stick });
GameRegistry.addShapedRecipe(new ItemStack(itemDarkPickaxe), new Object[]{"III", " S ", " S ", 'I',itemDarkIngot, 'S', Items.stick });
GameRegistry.addShapedRecipe(new ItemStack(itemDarkAxe), new Object[]{"II", "IS", " S", 'I',itemDarkIngot, 'S', Items.stick });
GameRegistry.addShapedRecipe(new ItemStack(itemDarkSword), new Object[]{"I", "I", "S", 'I',itemDarkIngot, 'S', Items.stick });
GameRegistry.addShapedRecipe(new ItemStack(itemDarkHoe), new Object[]{"II", " S", " S", 'I',itemDarkIngot, 'S', Items.stick });
GameRegistry.addShapedRecipe(new ItemStack(DarkFurnaceIdle), new Object[] {"DDD", "D D", "DDD", 'D', DarkStone});
GameRegistry.addShapedRecipe(new ItemStack(RainbowFurnaceIdle), new Object[] {"RRR", "R R", "RRR", 'R', RainbowBlock});
GameRegistry.addShapedRecipe(new ItemStack(DarkStoneBrick), new Object[] {"SS", "SS", 'S', DarkStone});
//Shapeless Recipes
GameRegistry.addShapelessRecipe(new ItemStack(itemRainbowIngot, 9), new Object[] {RainbowBlock});
}
@Mod.EventHandler
public void postInit(FMLPostInitializationEvent postEvent) {
cast drops.get(i); into an ItemStack type. Your line will be like so:
EntityItem item = new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, (ItemStack)drops.get(i));
Hope this helps
https://emxtutorials.wordpress.com/adding-custom-drops-to-vanilla-mobs/
Sure thing! When I have time
Does this guarantee a gold ingot to drop on every pig kill? How would you factor in a fortune weapon to increase drop changes, or Fire Aspect? Like, if normally the big dropped gold ore, but with said enchant it then drops the ingot instead.
It will always drop a gold ingot, regardless of any enchantments. I'll cover that when i get to my PC
Another tutorial has been released.. again! This time, making guns!
https://emxtutorials.wordpress.com/creating-a-gun/
As requested by GamingChief1170:
Well how was i supposed to know that? I looked up a tut on youtube and apparently yours is wrong and not as efficient. I got like a sword and 2 other items in the game in less than 30 minutes while i was struggling to understand your tut for a few hours
Alright then if you're too stupid to follow my tutorial it's fine with me for you to go find an easier tutorial for whiny babies like you.
Hey, I just read your tut about making a custom storage block, and (although it was dealing with storage) it got me much closer to understanding how to make blocks with GUIs like that. My problem, though, is that even after copy/pasting your code (and modifying it a bit so that it references that right parts of my code), Minecraft crashes when I open the GUI, telling me that the TileEntity is "missing a mapping." Below (in the spoiler, hopefully) is the crash log.
A TileEntity type io.github.tntftw21.electromag.tileentity.TileEntityEMChamber has throw an exception trying to write state. It will not persist. Report this to the mod author
java.lang.RuntimeException: class io.github.tntftw21.electromag.tileentity.TileEntityEMChamber is missing a mapping! This is a bug!
at net.minecraft.tileentity.TileEntity.writeToNBT(TileEntity.java:96) ~[TileEntity.class:?]
at io.github.tntftw21.electromag.tileentity.TileEntityEMChamber.writeToNBT(TileEntityEMChamber.java:100) ~[TileEntityEMChamber.class:?]
at net.minecraft.world.chunk.storage.AnvilChunkLoader.writeChunkToNBT(AnvilChunkLoader.java:395) [AnvilChunkLoader.class:?]
at net.minecraft.world.chunk.storage.AnvilChunkLoader.saveChunk(AnvilChunkLoader.java:204) [AnvilChunkLoader.class:?]
at net.minecraft.world.gen.ChunkProviderServer.safeSaveChunk(ChunkProviderServer.java:287) [ChunkProviderServer.class:?]
at net.minecraft.world.gen.ChunkProviderServer.saveChunks(ChunkProviderServer.java:340) [ChunkProviderServer.class:?]
at net.minecraft.world.WorldServer.saveAllChunks(WorldServer.java:863) [WorldServer.class:?]
at net.minecraft.server.MinecraftServer.saveAllWorlds(MinecraftServer.java:370) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.stopServer(MinecraftServer.java:405) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.stopServer(IntegratedServer.java:266) [IntegratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:538) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?]
EMChamber.java:
package io.github.tntftw21.electromag.block;
import io.github.tntftw21.electromag.Main;
import io.github.tntftw21.electromag.creativetabs.ModTabs;
import io.github.tntftw21.electromag.tileentity.TileEntityEMChamber;
import java.util.ArrayList;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class EMChamber extends BlockContainer {
private String frontTexName;
private String sideTexName;
public IIcon sideTex;
public IIcon frontTex;
private static final String name = "Electromagnetic Chamber";
private final Random rand = new Random();
public EMChamber(String unlocalizedName) {
super(Material.iron);
this.frontTexName = Main.MODID + ":" + unlocalizedName + "Front";
this.sideTexName = Main.MODID + ":" + unlocalizedName + "Side";
this.setBlockName(unlocalizedName)
.setCreativeTab(ModTabs.tabElectromagItems)
.setHardness(3.5f)
.setResistance(25.0f)
.setHarvestLevel("pickaxe", 1);
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemStack) {
int l = MathHelper.floor_double((double)(entity.rotationYaw * 4.0f / 360.0f) + 0.5d) & 3;
switch(l) {
case 0:
world.setBlockMetadataWithNotify(x, y, z, 2, 2);
break;
case 1:
world.setBlockMetadataWithNotify(x, y, z, 5, 2);
break;
case 2:
world.setBlockMetadataWithNotify(x, y, z, 3, 2);
break;
case 3:
world.setBlockMetadataWithNotify(x, y, z, 4, 2);
break;
}
}
@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(int side, int meta)
{
return side == 1 ? this.sideTex : (side == 0 ? this.sideTex : (side != meta ? this.sideTex : this.frontTex));
}
@SideOnly(Side.CLIENT)
@Override
public void registerBlockIcons(IIconRegister reg)
{
this.sideTex = reg.registerIcon(this.sideTexName);
this.frontTex = reg.registerIcon(this.frontTexName);
}
@Override
public int damageDropped(int meta) {
return 0;
}
@Override
public TileEntity createNewTileEntity(World world, int meta) {
return new TileEntityEMChamber();
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
if (world.isRemote) {
return true;
}
TileEntity te = world.getTileEntity(x, y, z);
if (te != null && te instanceof TileEntityEMChamber) {
player.openGui(Main.instance, 0, world, x, y, z);
return true;
}
return false;
}
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int par6) {
if (world.isRemote){
return;
}
ArrayList drops = new ArrayList();
TileEntity teRaw = world.getTileEntity(x, y, z);
if (teRaw != null && teRaw instanceof TileEntityEMChamber) {
TileEntityEMChamber te = (TileEntityEMChamber) teRaw;
for (int i = 0; i < te.getSizeInventory(); i++) {
ItemStack stack = te.getStackInSlot(i);
if (stack != null) {
drops.add(stack.copy());
}
}
}
for (int i = 0; i < drops.size(); i++) {
EntityItem item = new EntityItem(world, x + 0.5, y + 0.5, z + 0.5);
item.setVelocity((rand.nextDouble() - 0.5) * 0.25, rand.nextDouble() * 0.5 * 0.25, (rand.nextDouble() - 0.5) * 0.25);
world.spawnEntityInWorld(item);
}
}
}
TileEntityEMChamber.java:
package io.github.tntftw21.electromag.tileentity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.Constants;
//TODO Create TileEntityEM and AbilityRegistry
public class TileEntityEMChamber extends TileEntity implements IInventory {
private ItemStack[] items = new ItemStack[15];
@Override
public int getSizeInventory() {
return items.length;
}
@Override
public ItemStack getStackInSlot(int slot) {
return items[slot];
}
@Override
public ItemStack decrStackSize(int slot, int amount) {
if (items[slot] != null) {
ItemStack itemStack;
if (items[slot].stackSize == amount) {
itemStack = items[slot];
items[slot] = null;
markDirty();
return itemStack;
} else {
itemStack = items[slot].splitStack(amount);
if (items[slot].stackSize == 0)
items[slot] = null;
markDirty();
return itemStack;
}
} else {
return null;
}
}
@Override
public ItemStack getStackInSlotOnClosing(int slot) {
if (items[slot] != null) {
ItemStack itemStack = items[slot];
items[slot] = null;
return itemStack;
} else {
return null;
}
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
items[slot] = stack;
if (stack != null && stack.stackSize > getInventoryStackLimit()) {
stack.stackSize = getInventoryStackLimit();
}
markDirty();
}
@Override
public String getInventoryName() {
return "container.storage";
}
@Override
public boolean hasCustomInventoryName() {
return false;
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
NBTTagList list = nbt.getTagList("Items", Constants.NBT.TAG_COMPOUND);
items = new ItemStack[getSizeInventory()];
for (int i = 0; i < list.tagCount(); i++) {
NBTTagCompound comp = list.getCompoundTagAt(i);
int j = comp.getByte("Slot") & 255;
if (j >= 0 && j < items.length) {
items[j] = ItemStack.loadItemStackFromNBT(comp);
}
}
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
NBTTagList list = new NBTTagList();
for (int i = 0; i < items.length; ++i) {
if (items != null) {
NBTTagCompound comp = new NBTTagCompound();
comp.setByte("Slot", (byte)i);
items.writeToNBT(comp);
list.appendTag(comp);
}
}
nbt.setTag("Items", list);
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return worldObj.getTileEntity(xCoord, yCoord, zCoord) != this ? false : player.getDistanceSq((double)xCoord + 0.5d, (double) yCoord + 0.5d, (double) zCoord + 0.5d) <= 64.0d;
}
@Override
public void openInventory() {
//NOOP
}
@Override
public void closeInventory() {
//NOOP
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
return true;
}
}
GuiHandler.java:
package io.github.tntftw21.electromag.handler;
import io.github.tntftw21.electromag.client.gui.ContainerStorage;
import io.github.tntftw21.electromag.tileentity.TileEntityEMChamber;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.IGuiHandler;
public class GuiHandler implements IGuiHandler {
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world,
int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
if (te != null) {
if (ID == 0) {
return new ContainerStorage((TileEntityEMChamber)te, player);
}
}
return null;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world,
int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
if (te != null) {
if (ID == 0) {
return new ContainerStorage((TileEntityEMChamber)te, player);
}
}
return null;
}
}
GuiStorage.java:
package io.github.tntftw21.electromag.client.gui;
import io.github.tntftw21.electromag.Main;
import io.github.tntftw21.electromag.tileentity.TileEntityEMChamber;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
public class GuiStorage extends GuiContainer {
private ResourceLocation texture = new ResourceLocation(Main.MODID, "textures/gui/container/storage.png");
private InventoryPlayer inventory;
private TileEntityEMChamber te;
public GuiStorage(TileEntityEMChamber te, EntityPlayer player) {
super(new ContainerStorage(te, player));
inventory = player.inventory;
this.te = te;
}
@Override
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) {
Minecraft.getMinecraft().renderEngine.bindTexture(texture);
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
int x = (width - xSize) / 2;
int y = (height - ySize) / 2;
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
}
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
fontRendererObj.drawString(I18n.format(te.getInventoryName()), (xSize / 2) - (fontRendererObj.getStringWidth(I18n.format(te.getInventoryName())) / 2), 6, 4210752, false);
fontRendererObj.drawString(I18n.format(inventory.getInventoryName()), 8, ySize - 96 + 2, 4210752);
}
}
ContainerStorage.java:
package io.github.tntftw21.electromag.client.gui;
import io.github.tntftw21.electromag.tileentity.TileEntityEMChamber;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class ContainerStorage extends Container
{
private TileEntityEMChamber te;
private int slotID = 0;
public ContainerStorage(TileEntityEMChamber te, EntityPlayer player)
{
this.te = te;
//Storage
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 5; j++)
{
addSlotToContainer(new Slot(te, slotID++, 44 + j * 18, 17 + i * 18));
}
}
//Inventory
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 9; j++)
{
addSlotToContainer(new Slot(player.inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
// Hotbar
for (int i = 0; i < 9; i++)
{
addSlotToContainer(new Slot(player.inventory, i, 8 + i * 18, 142));
}
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotRaw)
{
ItemStack stack = null;
Slot slot = (Slot)inventorySlots.get(slotRaw);
if (slot != null && slot.getHasStack())
{
ItemStack stackInSlot = slot.getStack();
stack = stackInSlot.copy();
if (slotRaw < 3 * 9)
{
if (!mergeItemStack(stackInSlot, 3 * 9, inventorySlots.size(), true))
{
return null;
}
}
else if (!mergeItemStack(stackInSlot, 0, 3 * 9, false))
{
return null;
}
if (stackInSlot.stackSize == 0)
{
slot.putStack((ItemStack)null);
}
else
{
slot.onSlotChanged();
}
}
return stack;
}
@Override
public boolean canInteractWith(EntityPlayer player)
{
return te.isUseableByPlayer(player);
}
}
I'm still kind of a noob with modding (even more so with making GUIs and whatnot, since the only tutorials I find are shady at best), so for all I know I could have made a rookie mistake.
You need to register the tile entity with GameRegistry.registerTileEntity()
can you show me the crash logs, please?
in your tile entity class, there should be an ItemStack array. You need to change that to 20, since you changed the size to 20.
Thanks, I hadn't realized that I had to register that (I had followed another tut on basic tile entities, and I don't remember having to do that). Now, though, Forge keeps telling me that "io.github.tntftw21.electromag.ContainerStorage cannot be cast to net.minecraft.client.gui.GuiScreen." The only part of my code that I changed was the part in ModBlocks.java, which registers the tile entity, too. I also tried switching the object passed by GuiHandler.java to use GuiStorage(te, player) instead of ContainerStorage(te, player), but that led to one heck of a crash log. Here is the error from the above:
[14:31:02] [Client thread/ERROR] [FML]: There was a critical exception handling a packet on channel FML
java.lang.ClassCastException: io.github.tntftw21.electromag.client.gui.ContainerStorage cannot be cast to net.minecraft.client.gui.GuiScreen
at cpw.mods.fml.client.FMLClientHandler.showGuiScreen(FMLClientHandler.java:444) ~[FMLClientHandler.class:?]
at cpw.mods.fml.common.FMLCommonHandler.showGuiScreen(FMLCommonHandler.java:303) ~[FMLCommonHandler.class:?]
at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:94) ~[FMLNetworkHandler.class:?]
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2501) ~[EntityPlayer.class:?]
at cpw.mods.fml.common.network.internal.OpenGuiHandler.channelRead0(OpenGuiHandler.java:16) ~[OpenGuiHandler.class:?]
at cpw.mods.fml.common.network.internal.OpenGuiHandler.channelRead0(OpenGuiHandler.java:11) ~[OpenGuiHandler.class:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[SimpleChannelInboundHandler.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:101) ~[SimpleChannelInboundHandler.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?]
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) ~[MessageToMessageDecoder.class:?]
at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) ~[DefaultChannelPipeline.class:?]
at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) ~[EmbeddedChannel.class:?]
at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?]
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [NetworkManager.class:?]
at net.minecraft.client.multiplayer.PlayerControllerMP.updateController(PlayerControllerMP.java:317) [PlayerControllerMP.class:?]
at net.minecraft.client.Minecraft.runTick(Minecraft.java:1682) [Minecraft.class:?]
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1028) [Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:951) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_40]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_40]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_40]
at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_40]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?]
at GradleStart.main(Unknown Source) [start/:?]
The weird thing is that this error always occurs in triplets (the same one appears three times one after the other, before kicking me from the internal server).
take a look at your GuiScreen. You might have mixed serverside and clientside stuff
Thanks, that did the trick! I guess I had accidentally read the wrong part of the file when I put it in
that command still works, and it does work very well for 1.7.10. If I remember correctly, 1.8 removes this and switched to using .json assets.
I think you can do "X", "X", "S" and it will work perfectly.
I have a question on the storage block. My block does not open the gui. I followed the tut, but don't know where I went wrong. Here are my files
RainbowStrorage(BLOCK)
package com.rainbow.mod.blocks;
import java.util.ArrayList;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import com.rainbow.mod.Main;
import com.rainbow.mod.tileentity.TileEntityRainbowStorage;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class RainbowStorage extends BlockContainer {
private static final String name = "storage";
private final Random rand = new Random();
public RainbowStorage() {
super(Material.wood);
this.setCreativeTab(Main.tabRainbowMod);
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float lx, float ly, float lz) {
if(world.isRemote)
return true;
TileEntity te = world.getTileEntity(x, y, z);
if (te != null && te instanceof TileEntityRainbowStorage) {
player.openGui(Main.instance, 0, world, x, y, z);
return true;
}
return false;
}
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int par6) {
if(world.isRemote)
return;
ArrayList drops = new ArrayList();
TileEntity teRaw = world.getTileEntity(x, y, z);
if(teRaw != null && teRaw instanceof TileEntityRainbowStorage) {
TileEntityRainbowStorage te = (TileEntityRainbowStorage) teRaw;
for (int i =0; i < te.getSizeInventory(); i++) {
ItemStack stack = te.getStackInSlot(i);
if(stack != null) drops.add(stack.copy());
}
}
for(int i = 0; i < drops.size(); i++) {
EntityItem item = new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, (ItemStack) drops.get(i));
item.setVelocity((rand.nextDouble() - 0.5) * 0.25, rand.nextDouble() * 0.5 * 0.25, (rand.nextDouble() - 0.5) * 0.25);
world.spawnEntityInWorld(item);
}
}
@Override
public TileEntity createNewTileEntity(World world, int par2) {
return new TileEntityRainbowStorage();
}
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
this.blockIcon = iconRegister.registerIcon(Main.modID + ":" + this.getUnlocalizedName().substring(5));
}
}
TileEntityRainbowStorage
package com.rainbow.mod.tileentity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.Constants;
public class TileEntityRainbowStorage extends TileEntity implements IInventory {
private ItemStack[] items = new ItemStack[15];
@Override
public int getSizeInventory() {
return items.length;
}
@Override
public ItemStack getStackInSlot(int slot) {
return items[slot];
}
@Override
public ItemStack decrStackSize(int slot, int amount) {
if (items[slot] != null) {
ItemStack itemstack;
if (items[slot].stackSize == amount) {
itemstack = items[slot];
items[slot] = null;
markDirty();
return itemstack;
}else{
itemstack = items[slot].splitStack(amount);
if (items[slot].stackSize == 0) items[slot] = null;
markDirty();
return itemstack;
}
}else{
return null;
}
}
@Override
public ItemStack getStackInSlotOnClosing(int slot) {
if (items[slot] != null) {
ItemStack itemstack = items[slot];
items[slot] = null;
return itemstack;
}else{
return null;
}
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
items[slot] = stack;
if (stack != null && stack.stackSize > getInventoryStackLimit()) {
stack.stackSize = getInventoryStackLimit();
}
markDirty();
}
@Override
public String getInventoryName() {
return "container.rainbowStorage";
}
@Override
public boolean hasCustomInventoryName() {
return false;
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
NBTTagList list = nbt.getTagList("Items", Constants.NBT.TAG_COMPOUND);
items = new ItemStack[getSizeInventory()];
for (int i = 0; i < list.tagCount(); ++i) { NBTTagCompound comp = list.getCompoundTagAt(i); int j = comp.getByte("Slot") & 255; if (j >= 0 && j < items.length) {
items[j] = ItemStack.loadItemStackFromNBT(comp);
}
}
}
@Override
public void writeToNBT(NBTTagCompound nbt){
super.writeToNBT(nbt);
NBTTagList list = new NBTTagList();
for (int i = 0; i < items.length; ++i){
if (items != null){
NBTTagCompound comp = new NBTTagCompound();
comp.setByte("Slot", (byte)i);
items.writeToNBT(comp);
list.appendTag(comp);
}
}
nbt.setTag("Items", list);
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return worldObj.getTileEntity(xCoord, yCoord, zCoord) != this ? false : player.getDistanceSq((double)xCoord + 0.5D, (double)yCoord + 0.5D, (double)zCoord + 0.5D) <= 64.0D;
}
@Override
public void openInventory() {}
@Override
public void closeInventory() {}
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
return true;
}
}
ContainerRainbowStrorage
package com.rainbow.mod.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import com.rainbow.mod.tileentity.TileEntityRainbowStorage;
public class ContainerRainbowStorage extends Container {
private TileEntityRainbowStorage te;
private int slotID = 0;
public ContainerRainbowStorage(TileEntityRainbowStorage te, EntityPlayer player) {
this.te = te;
//Storage
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 5; j++) {
addSlotToContainer(new Slot(te, slotID++, 44 + j * 18, 17 + i * 18));
}
}
//Inventory
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 9; j++) {
addSlotToContainer(new Slot(player.inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
//Hotbar
for (int i = 0; i < 9; i++) {
addSlotToContainer(new Slot(player.inventory, i, 8 + i * 18, 142));
}
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotRaw) {
ItemStack stack = null;
Slot slot = (Slot)inventorySlots.get(slotRaw);
if(slot != null && slot.getHasStack()) {
ItemStack stackInSlot = slot.getStack();
stack = stackInSlot.copy();
if (slotRaw < 3 * 9) {
if (!mergeItemStack(stackInSlot, 3 * 9, inventorySlots.size(), true)) {
return null;
}
}else if(!mergeItemStack(stackInSlot, 0, 3 * 9, false)) {
return null;
}
if(stackInSlot.stackSize == 0) {
slot.putStack((ItemStack)null);
}else{
slot.onSlotChanged();
}
}
return stack;
}
@Override
public boolean canInteractWith(EntityPlayer player) {
return te.isUseableByPlayer(player);
}
}
Gui Handler
package com.rainbow.mod.handler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import com.rainbow.mod.Main;
import com.rainbow.mod.blocks.BlocksDecRM;
import com.rainbow.mod.container.ContainerDarkFurnace;
import com.rainbow.mod.container.ContainerRainbowCraftingTable;
import com.rainbow.mod.container.ContainerRainbowFurnace;
import com.rainbow.mod.container.ContainerRainbowStorage;
import com.rainbow.mod.gui.GuiDarkFurnace;
import com.rainbow.mod.gui.GuiRainbowCraftingTable;
import com.rainbow.mod.gui.GuiRainbowFurnace;
import com.rainbow.mod.gui.GuiRainbowStorage;
import com.rainbow.mod.tileentity.TileEntityDarkFurnace;
import com.rainbow.mod.tileentity.TileEntityRainbowFurnace;
import com.rainbow.mod.tileentity.TileEntityRainbowStorage;
import cpw.mods.fml.common.network.IGuiHandler;
public class GuiHandler implements IGuiHandler {
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
TileEntity entity = world.getTileEntity(x, y, z);
if(entity != null) {
switch(ID) {
case Main.guiIDDarkFurnace:
if (entity instanceof TileEntityDarkFurnace) {
return new ContainerDarkFurnace(player.inventory, (TileEntityDarkFurnace) entity);
}
return null;
case Main.guiIDRainbowFurnace:
if (entity instanceof TileEntityRainbowFurnace) {
return new ContainerRainbowFurnace(player.inventory, (TileEntityRainbowFurnace) entity);
}
return null;
}
}
if(ID == Main.guiIDRainbowCraftingTable) {
return ID == Main.guiIDRainbowCraftingTable && world.getBlock(x, y, z) == BlocksDecRM.RainbowCraftingTable ? new ContainerRainbowCraftingTable(player.inventory, world, x, y, z) : null;
}
TileEntity te = world.getTileEntity(x, y, z);
if(te != null) {
if(ID == Main.guiIDRainbowStorageBlock) {
return new ContainerRainbowStorage((TileEntityRainbowStorage)te, player);
}
}
return null;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
TileEntity entity = world.getTileEntity(x, y, z);
if (entity != null) {
switch (ID) {
case Main.guiIDDarkFurnace:
if (entity instanceof TileEntityDarkFurnace) {
return new GuiDarkFurnace(player.inventory, (TileEntityDarkFurnace) entity);
}
return null;
case Main.guiIDRainbowFurnace:
if (entity instanceof TileEntityRainbowFurnace) {
return new GuiRainbowFurnace(player.inventory, (TileEntityRainbowFurnace) entity);
}
return null;
}
}
if(ID == Main.guiIDRainbowCraftingTable) {
return ID == Main.guiIDRainbowCraftingTable && world.getBlock(x, y, z) == BlocksDecRM.RainbowCraftingTable ? new GuiRainbowCraftingTable(player.inventory, world, x, y, z) : null;
}
TileEntity te = world.getTileEntity(x, y, z);
if(te != null) {
if(ID == Main.guiIDRainbowStorageBlock) {
return new GuiRainbowStorage((TileEntityRainbowStorage)te, player);
}
}
return null;
}
}
(I have other Furnace Gui's)
Main Class(in case)
package com.rainbow.mod;
import static com.rainbow.mod.items.ItemsDecRM.*;
import static com.rainbow.mod.blocks.BlocksDecRM.*;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.BiomeDictionary;
import net.minecraftforge.common.BiomeDictionary.Type;
import net.minecraftforge.common.BiomeManager;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.EnumHelper;
import com.rainbow.mod.armor.DarkArmor;
import com.rainbow.mod.armor.EmeraldArmor;
import com.rainbow.mod.armor.RainbowArmor;
import com.rainbow.mod.blocks.BlocksRM;
import com.rainbow.mod.blocks.DarkFurnace;
import com.rainbow.mod.blocks.RainbowBlock;
import com.rainbow.mod.blocks.RainbowFurnace;
import com.rainbow.mod.dimension.RMWorldProvider;
import com.rainbow.mod.entities.EntityRainbowArrow;
import com.rainbow.mod.entities.EntityThrowingGold;
import com.rainbow.mod.entities.LeprechanEntityTest;
import com.rainbow.mod.handler.DropHandler;
import com.rainbow.mod.handler.GuiHandler;
import com.rainbow.mod.items.ItemsDecRM;
import com.rainbow.mod.items.ItemsRM;
import com.rainbow.mod.proxy.CommonProxy;
import com.rainbow.mod.tileentity.TileEntityDarkFurnace;
import com.rainbow.mod.tileentity.TileEntityRainbowFurnace;
import com.rainbow.mod.tileentity.TileEntityRainbowStorage;
import com.rainbow.mod.worldgen.RMWorldGen;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@Mod(modid = Main.modID, version = Main.version, name = Main.modName)
public class Main {
@SidedProxy(clientSide= "com.rainbow.mod.proxy.ClientProxy" , serverSide= "com.rainbow.mod.proxy.CommonProxy")
public static CommonProxy proxy;
public static final String modID = "rainbowmod";
public static final String version = "alpha 0.1";
public static final String modName = "RainbowMod";
public static CreativeTabs tabRainbowMod = new CreativeTabs("RainbowMod") {
@SideOnly(Side.CLIENT)
public Item getTabIconItem() {
return Item.getItemFromBlock(RainbowOre);
}
};
public static CreativeTabs tabDark = new CreativeTabs("Dark") {
@SideOnly(Side.CLIENT)
public Item getTabIconItem() {
return Item.getItemFromBlock(DarkStone);
}
};
public static CreativeTabs tabRainbowModMaterials = new CreativeTabs("RainbowModMaterials") {
@SideOnly(Side.CLIENT)
public Item getTabIconItem() {
return ItemsDecRM.itemRainbowIngot;
}
};
public static CreativeTabs tabRainbowModFoods = new CreativeTabs("RainbowModFoods") {
@SideOnly(Side.CLIENT)
public Item getTabIconItem() {
return ItemsDecRM.RainbowApple;
}
};
@Instance(modID)
public static Main instance;
public static int entityIndex = 0;
//Entities
public static void registerEntity(Class entityClass, String name) {
int entityID = EntityRegistry.findGlobalUniqueEntityId();
long seed = name.hashCode();
Random rand = new Random(seed);
int primaryColor = rand.nextInt() * 16777215;
int secondaryColor = rand.nextInt() * 16777215;
EntityRegistry.registerGlobalEntityID(entityClass, name, entityID);
EntityRegistry.registerModEntity(entityClass, name, entityID, Main.instance, 64, 1, true);
EntityList.entityEggs.put(Integer.valueOf(entityID), new EntityList.EntityEggInfo(entityID, primaryColor, secondaryColor));
}
//Dimensions
public static int RainbowDimension = 5;
//Machines
public static Block DarkFurnaceIdle;
public static Block DarkFurnaceActive;
public static final int guiIDDarkFurnace = 0;
public static Block RainbowFurnaceIdle;
public static Block RainbowFurnaceActive;
public static final int guiIDRainbowFurnace = 1;
public static final int guiIDRainbowCraftingTable = 2;
public static final int guiIDRainbowStorageBlock = 3;
//Armor
public static ItemArmor.ArmorMaterial RainbowArmorMaterial = EnumHelper.addArmorMaterial("RainbowArmor", 25, new int[]{3, 7, 8, 3}, 10);
public static ItemArmor.ArmorMaterial DarkArmorMaterial = EnumHelper.addArmorMaterial("DarkArmor", 25, new int[]{3, 7, 8, 3}, 10);
public static ItemArmor.ArmorMaterial EmeraldArmorMaterial = EnumHelper.addArmorMaterial("EmeraldArmor", 24, new int[]{2, 6, 7, 2}, 9);
public static int armorRainbowHelmID;
public static int armorRainbowChestID;
public static int armorRainbowLegsID;
public static int armorRainbowBootsID;
public static Item armorRainbowHelm;
public static Item armorRainbowChest;
public static Item armorRainbowLegs;
public static Item armorRainbowBoots;
public static int armorDarkHelmID;
public static int armorDarkChestID;
public static int armorDarkLegsID;
public static int armorDarkBootsID;
public static Item armorDarkHelm;
public static Item armorDarkChest;
public static Item armorDarkLegs;
public static Item armorDarkBoots;
public static int armorEmeraldHelmID;
public static int armorEmeraldChestID;
public static int armorEmeraldLegsID;
public static int armorEmeraldBootsID;
public static Item armorEmeraldHelm;
public static Item armorEmeraldChest;
public static Item armorEmeraldLegs;
public static Item armorEmeraldBoots;
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent preEvent) {
ItemsRM.init();
BlocksRM.init();
//Entities
registerEntity(LeprechanEntityTest.class, "leprechanEntityTest");
EntityRegistry.registerModEntity(EntityThrowingGold.class, "Throwing Gold", ++entityIndex, this, 64, 10, true);
EntityRegistry.registerModEntity(EntityRainbowArrow.class, "EntityRainbowArrow", ++entityIndex, this, 128, 1, true);
EntityRegistry.registerGlobalEntityID(EntityRainbowArrow.class, "EntityRainbowArrow", ++entityIndex);
//Dimensions
DimensionManager.registerProviderType(RainbowDimension, RMWorldProvider.class, false);
DimensionManager.registerDimension(RainbowDimension, RainbowDimension);
//Machines
DarkFurnaceIdle = new DarkFurnace(false).setBlockName("DarkFurnaceIdle").setCreativeTab(Main.tabDark).setHardness(3.5F);
DarkFurnaceActive = new DarkFurnace(true).setBlockName("DarkFurnaceActive").setLightLevel(0.625F).setHardness(3.5F);
RainbowFurnaceIdle = new RainbowFurnace(false).setBlockName("RainbowFurnaceIdle").setCreativeTab(Main.tabRainbowMod).setHardness(3.5F);
RainbowFurnaceActive = new RainbowFurnace(true).setBlockName("RainbowFurnaceActive").setLightLevel(0.625F).setHardness(3.5F);
//Armor
armorRainbowHelm = new RainbowArmor(RainbowArmorMaterial, armorRainbowHelmID, 0).setUnlocalizedName("RainbowHelm");
armorRainbowChest = new RainbowArmor(RainbowArmorMaterial, armorRainbowChestID, 1).setUnlocalizedName("RainbowChest");
armorRainbowLegs = new RainbowArmor(RainbowArmorMaterial, armorRainbowLegsID, 2).setUnlocalizedName("RainbowLegs");
armorRainbowBoots = new RainbowArmor(RainbowArmorMaterial, armorRainbowBootsID, 3).setUnlocalizedName("RainbowBoots");
armorDarkHelm = new DarkArmor(DarkArmorMaterial, armorDarkHelmID, 0).setUnlocalizedName("DarkHelm");
armorDarkChest = new DarkArmor(DarkArmorMaterial, armorDarkChestID, 1).setUnlocalizedName("DarkChest");
armorDarkLegs = new DarkArmor(DarkArmorMaterial, armorDarkLegsID, 2).setUnlocalizedName("DarkLegs");
armorDarkBoots = new DarkArmor(DarkArmorMaterial, armorDarkBootsID, 3).setUnlocalizedName("DarkBoots");
armorEmeraldHelm = new EmeraldArmor(EmeraldArmorMaterial, armorEmeraldHelmID, 0).setUnlocalizedName("EmeraldHelm");
armorEmeraldChest = new EmeraldArmor(EmeraldArmorMaterial, armorEmeraldChestID, 1).setUnlocalizedName("EmeraldChest");
armorEmeraldLegs = new EmeraldArmor(EmeraldArmorMaterial, armorEmeraldLegsID, 2).setUnlocalizedName("EmeraldLegs");
armorEmeraldBoots = new EmeraldArmor(EmeraldArmorMaterial, armorEmeraldBootsID, 3).setUnlocalizedName("EmeraldBoots");
//Items
GameRegistry.registerItem(itemRainbowSword,"RainbowSword" );
GameRegistry.registerItem(itemRainbowAxe, "RainbowAxe");
GameRegistry.registerItem(itemRainbowPickaxe,"RainbowPickaxe");
GameRegistry.registerItem(itemRainbowShovel,"RainbowShovel" );
GameRegistry.registerItem(itemRainbowHoe, "RainbowHoe");
GameRegistry.registerItem(itemRainbowIngot, "RainbowIngot");
GameRegistry.registerItem(itemDarkIngot, "DarkIngot");
GameRegistry.registerItem(itemDarkSword,"DarkSword" );
GameRegistry.registerItem(itemDarkAxe, "DarkAxe");
GameRegistry.registerItem(itemDarkPickaxe,"DarkPickaxe");
GameRegistry.registerItem(itemDarkShovel,"DarkShovel" );
GameRegistry.registerItem(itemDarkHoe, "DarkHoe");
GameRegistry.registerItem(itemThrowingGold, "ThrowingGold");
GameRegistry.registerItem(RainbowBow, "RainbowBow");
GameRegistry.registerItem(RainbowArrow, "RainbowArrow");
GameRegistry.registerItem(RainbowApple, "RainbowApple");
GameRegistry.registerItem(RainbowStew, "RainbowStew");
GameRegistry.registerItem(RainbowPorkchopRaw, "RainbowPorkchopRaw");
GameRegistry.registerItem(RainbowPorkchopCooked, "RainbowPorkchopCooked");
GameRegistry.registerItem(RainbowGoldenApple, "RainbowGoldenApple");
GameRegistry.registerItem(RainbowWheatSeeds, "RainbowWheatSeeds");
GameRegistry.registerItem(RainbowWheat, "RainbowWheat");
GameRegistry.registerItem(RainbowBread, "RainbowBread");
//Blocks
GameRegistry.registerBlock(RainbowOre, "RainbowOre");
GameRegistry.registerBlock(RainbowBlock, "RainbowBlock");
GameRegistry.registerBlock(DarkFurnaceIdle, "DarkFurnaceIdle");
GameRegistry.registerBlock(DarkFurnaceActive, "DarkFurnaceActive");
GameRegistry.registerBlock(DarkStone, "DarkStone");
GameRegistry.registerBlock(DarkStoneBrick, "DarkStoneBrick");
GameRegistry.registerBlock(DarkOre, "DarkOre");
GameRegistry.registerBlock(RainbowFurnaceIdle, "RainbowFurnaceIdle");
GameRegistry.registerBlock(RainbowFurnaceActive, "RainbowFurnaceActive");
GameRegistry.registerBlock(RainbowCraftingTable, "RainbowCraftingTable");
GameRegistry.registerBlock(RainbowLog, "RainbowLog");
GameRegistry.registerBlock(RainbowPlank, "RainbowPlanks");
GameRegistry.registerBlock(RainbowWheatPlant, "RainbowWheatPlant");
GameRegistry.registerBlock(RainbowPortal, "RainbowPortalBlock");
GameRegistry.registerBlock(RainbowStorageBlock, "RainbowStorage");
//Armor
GameRegistry.registerItem(armorRainbowHelm, "RainbowHelm");
GameRegistry.registerItem(armorRainbowChest, "RainbowChest");
GameRegistry.registerItem(armorRainbowLegs, "RainbowLegs");
GameRegistry.registerItem(armorRainbowBoots, "RainbowBoots");
GameRegistry.registerItem(armorDarkHelm, "DarkHelm");
GameRegistry.registerItem(armorDarkChest, "DarkChest");
GameRegistry.registerItem(armorDarkLegs, "DarkLegs");
GameRegistry.registerItem(armorDarkBoots, "DarkBoots");
GameRegistry.registerItem(armorEmeraldHelm, "EmeraldHelm");
GameRegistry.registerItem(armorEmeraldChest, "EmeraldChest");
GameRegistry.registerItem(armorEmeraldLegs, "EmeraldLegs");
GameRegistry.registerItem(armorEmeraldBoots, "EmeraldBoots");
//World Generating
GameRegistry.registerWorldGenerator(new RMWorldGen(), 1);
proxy.registerRenderers();
}
@Mod.EventHandler
public void Init(FMLInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(new DropHandler());
NetworkRegistry.INSTANCE.registerGuiHandler(this, new GuiHandler());
GameRegistry.registerTileEntity(TileEntityDarkFurnace.class, "DarkFurnace");
GameRegistry.registerTileEntity(TileEntityRainbowFurnace.class, "RainbowFurnace");
GameRegistry.registerTileEntity(TileEntityRainbowStorage.class, "RainbowStorage");
//Smelting Recipes
GameRegistry.addSmelting(RainbowOre, new ItemStack(itemRainbowIngot), 4.0F);
GameRegistry.addSmelting(Blocks.stone, new ItemStack(DarkStone), 2.0F);
GameRegistry.addSmelting(DarkOre, new ItemStack(itemDarkIngot), 5.0f);
GameRegistry.addSmelting(RainbowPorkchopRaw, new ItemStack(RainbowPorkchopCooked), 2.0F);
//Shaped Crafting Recipes
GameRegistry.addShapedRecipe(new ItemStack(RainbowPlank, 9), new Object[] {"WWW", "WWW", "WWW", 'W', RainbowLog});
GameRegistry.addShapedRecipe(new ItemStack(RainbowBlock), new Object[]{"III", "III", "III", 'I', itemRainbowIngot});
GameRegistry.addShapedRecipe(new ItemStack(RainbowCraftingTable), new Object[]{"PPP", "PCP", "PPP", 'P', RainbowPlank, 'C', Blocks.crafting_table});
GameRegistry.addShapedRecipe(new ItemStack(itemRainbowShovel), new Object[]{"I", "S", "S", 'I',itemRainbowIngot, 'S', Items.stick });
GameRegistry.addShapedRecipe(new ItemStack(itemRainbowPickaxe), new Object[]{"III", " S ", " S ", 'I',itemRainbowIngot, 'S', Items.stick });
GameRegistry.addShapedRecipe(new ItemStack(itemRainbowAxe), new Object[]{"II", "IS", " S", 'I',itemRainbowIngot, 'S', Items.stick });
GameRegistry.addShapedRecipe(new ItemStack(itemRainbowSword), new Object[]{"I", "I", "S", 'I',itemRainbowIngot, 'S', Items.stick });
GameRegistry.addShapedRecipe(new ItemStack(itemRainbowHoe), new Object[]{"II", " S", " S", 'I',itemRainbowIngot, 'S', Items.stick });
GameRegistry.addShapedRecipe(new ItemStack(itemDarkShovel), new Object[]{"I", "S", "S", 'I',itemDarkIngot, 'S', Items.stick });
GameRegistry.addShapedRecipe(new ItemStack(itemDarkPickaxe), new Object[]{"III", " S ", " S ", 'I',itemDarkIngot, 'S', Items.stick });
GameRegistry.addShapedRecipe(new ItemStack(itemDarkAxe), new Object[]{"II", "IS", " S", 'I',itemDarkIngot, 'S', Items.stick });
GameRegistry.addShapedRecipe(new ItemStack(itemDarkSword), new Object[]{"I", "I", "S", 'I',itemDarkIngot, 'S', Items.stick });
GameRegistry.addShapedRecipe(new ItemStack(itemDarkHoe), new Object[]{"II", " S", " S", 'I',itemDarkIngot, 'S', Items.stick });
GameRegistry.addShapedRecipe(new ItemStack(DarkFurnaceIdle), new Object[] {"DDD", "D D", "DDD", 'D', DarkStone});
GameRegistry.addShapedRecipe(new ItemStack(RainbowFurnaceIdle), new Object[] {"RRR", "R R", "RRR", 'R', RainbowBlock});
GameRegistry.addShapedRecipe(new ItemStack(DarkStoneBrick), new Object[] {"SS", "SS", 'S', DarkStone});
//Shapeless Recipes
GameRegistry.addShapelessRecipe(new ItemStack(itemRainbowIngot, 9), new Object[] {RainbowBlock});
}
@Mod.EventHandler
public void postInit(FMLPostInitializationEvent postEvent) {
}
}
I love this tutorial but can you tell us how to make textures for items and blocks as I did not catch that.
make the textures as in, apply them to the game as a resource, or make them with an image editing tool?
when i run eclipse it says "Failed to load the JNI shared library "c:\program files (x86)\java\jdk1.8.0_45\bin\...\jre\bin\client\jvm.dll"."
help?
As human beings, we can teach, invent and discover, but if we can't do any of that we can at the very least be honest.