Jump to content

oneofthem999

Members
  • Posts

    51
  • Joined

  • Last visited

Converted

  • Gender
    Undisclosed
  • Personal Text
    I am new!

oneofthem999's Achievements

Stone Miner

Stone Miner (3/8)

1

Reputation

  1. The blocks work as expected now. Thank you very much everyone!
  2. So I was trying to test out the idea of using blocks that checks whether or not a custom potion effect is active on the player when the player steps on the block. The KillBlock in this scenario should kill the player when the player steps on the block, if the player does not have a custom potion effect. The NeutralizationBlock should remove all potion effects the player has when stepped on. The Aura Potion is a generic potion that just add a speed 2 potion effect. Really, its just filler, since the idea was to learn how to create a custom potion. I wanted to be able to access the potion in one of the creative mode tabs, so I created a food item that grants the potion effect. However, the KillBlock and NeutralizationBlock does not work as expected. When stepped on, no effect takes place. A session of debugging determined that the onEntityCollidedWithBlock method didn't trigger at all, leading me to think that the method does not do what I originally thought it did. How do I improve the code such that the KillBlock and NeutralizationBlock will trigger when stepped on? Here's the NeutralizationBlock code: http://pastebin.com/6Jk0zJCQ And the KillBlock code: http://pastebin.com/5cJBD4UG The AuraPotionItemFood code: http://pastebin.com/EZDUyTY8 The AuraPotionEventHook code: http://pastebin.com/yDbPd2vg The AuraPotion code: http://pastebin.com/dxQugajB And finally, the Main code: http://pastebin.com/ZDrWZah3 Thank you in advance.
  3. Fixed it. I used drawModalRectWithCustomSizedTexture. Thank you everyone for all of your help!
  4. I figured out what was the problem. IntelliJ was registering the modID, "chestsmod", as a typo, and was therefore not compiling it. Once I changed the modID to chest-mod, a gui starting appearing, based on the PNG image in the assets/chest-mod/textures/gui/ file. There's is still one last problem: the gui is not scaling properly. That is, the PNG image is 256 x 256 pixels, but I want the gui to be 176 x 166 in size, and the code so far does not resize the image down to 176 X 166 for the gui. How do I properly scale the image down to size? I tried using a PNG image of 176 x 166 pixels, but the problem still occurred... Here's the code for the GuiChestTileEntity class: public class GuiChestTileEntity extends GuiContainer { private IInventory playerInv; private TileEntityRedChest te; private static ResourceLocation location = new ResourceLocation("chest-mod","textures/gui/chest-slots.png"); public GuiChestTileEntity(IInventory playerInv, TileEntityRedChest te) { super(new ContainerChestTileEntity(playerInv, te)); this.playerInv = playerInv; this.te = te; this.xSize = 176; this.ySize = 166; } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f); this.mc.getTextureManager().bindTexture(location); this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize); } @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { } }
  5. That's where I'm confused, because I thought I did...
  6. Thanks for the tip. I'll be doing that from now on. Unfortunately, the gui still has a black and purple background... Here's the code for the GuiChestTileEntity class: http://pastebin.com/6VtTwmUW And here's the code for the Chest (Main) class: http://pastebin.com/BgSudHca
  7. I tried it, but it doesn't seem to work. Instead, it gives me a black and purple background for the gui. Here's the code for the GuiChestTileEntity class: public class GuiChestTileEntity extends GuiContainer { private IInventory playerInv; private TileEntityRedChest te; private static ResourceLocation location = new ResourceLocation("chestsmod", "textures/gui/chestSlots.png"); public GuiChestTileEntity(IInventory playerInv, TileEntityRedChest te) { super(new ContainerChestTileEntity(playerInv, te)); this.playerInv = playerInv; this.te = te; this.xSize = 176; this.ySize = 166; this.width = 1920; this.height = 1080; } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f); this.mc.getTextureManager().bindTexture(location); this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize); } @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { String s = "Chest"; this.fontRendererObj.drawString(s, 88 - this.fontRendererObj.getStringWidth(s) / 2, 6, 4210752); //#404040 this.fontRendererObj.drawString(this.playerInv.getDisplayName().getUnformattedText(), 8, 72, 4210752); //#404040 } } And here's the code for the Chests (Main) class: @Mod(modid = Chest.MODID, version = Chest.VERSION) public class Chest { public static final String MODID = "chestsmod"; public static final String VERSION = "1.0"; public static Block redChest; @Mod.Instance("chestsmod") public static Chest instance = new Chest(); @Mod.EventHandler public static void init(FMLInitializationEvent event) { redChest = new BlockRedChest(); GameRegistry.registerBlock(redChest, "redChest"); GameRegistry.registerTileEntity(TileEntityRedChest.class, "redChestTileEntity"); //Register GUI NetworkRegistry.INSTANCE.registerGuiHandler(instance, new ChestGuiHandler()); } }
  8. I've taken your advise, but unfortunately, the Gui is still transparent for me, expect for the foreground text. Here's the code: public class GuiChestTileEntity extends GuiContainer { private IInventory playerInv; private TileEntityRedChest te; public GuiChestTileEntity(IInventory playerInv, TileEntityRedChest te) { super(new ContainerChestTileEntity(playerInv, te)); this.playerInv = playerInv; this.te = te; this.xSize = 176; this.ySize = 166; } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f); this.drawRect(this.guiLeft, this.guiTop, this.guiLeft + 256, this.guiTop + 256 , 0xFFFFFF); //this.mc.getTextureManager().bindTexture(new ResourceLocation("chestsmod:textures/gui/chestSlots.png")); //this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.guiLeft + this.xSize, this.guiTop + this.ySize); } @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { String s = "Chest"; this.fontRendererObj.drawString(s, 88 - this.fontRendererObj.getStringWidth(s) / 2, 6, 4210752); //#404040 this.fontRendererObj.drawString(this.playerInv.getDisplayName().getUnformattedText(), 8, 72, 4210752); //#404040 } } I tried putting the drawRect method in the foreground, to see what would happen, but nothing occurred; the gui was still transparent. On another note, I'm trying a different approach of using a PNG image as a backdrop, but I have a question for that. Assuming that the PNG has the following location: assets/ChestsMod/textures/gui/chestSlots.png How would I set up the new ResourceLocation? I've tried it myself, but it seems I'm not fully understanding something...
  9. Actually, I was wondering if I could get some help on that. I updated my code in my GuiChestTileEntity class, so as to draw the background layer of the gui. However, it doesn't seem to work. Here's the code for that class: public class GuiChestTileEntity extends GuiContainer { private IInventory playerInv; private TileEntityRedChest te; public GuiChestTileEntity(IInventory playerInv, TileEntityRedChest te) { super(new ContainerChestTileEntity(playerInv, te)); this.playerInv = playerInv; this.te = te; this.xSize = 176; this.ySize = 166; } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f); this.drawRect(this.guiLeft, this.guiTop, 256, 256, 16777215); //this.mc.getTextureManager().bindTexture(new ResourceLocation("ChestsMod:textures/gui/chestSlots.png")); //this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize); } @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { String s = "Chest"; this.fontRendererObj.drawString(s, 88 - this.fontRendererObj.getStringWidth(s) / 2, 6, 4210752); //#404040 this.fontRendererObj.drawString(this.playerInv.getDisplayName().getUnformattedText(), 8, 72, 4210752); //#404040 } } Note that the foreground works just fine.
  10. Thanks for the tip! The code works now; it produces a transparent GUI. Here's the code, in this order. Please note that the code still has system.out.println statements that print out "checkpoints," a result of my debugging attempt, and I'm sorry if they make the code difficult to follow. The BlockRedChest class, the ChestGuiHandler class, the ContainerChestTileEntity class, the GuiChestTileEntity class, the TileEntityRedChest class, and the Chest (Main) class: http://pastebin.com/cXUjshQ6 http://pastebin.com/EJuFSpi1 http://pastebin.com/vsh882mx http://pastebin.com/6VtTwmUW http://pastebin.com/WucCAgcy http://pastebin.com/BgSudHca
  11. I'm not quite I see the error. Here's the code tutorial for what the onBlockActivated method should be @Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ) { if (!world.isRemote) { player.openGui(Main.instance, ModGuiHandler.MOD_TILE_ENTITY_GUI, world, pos.getX(), pos.getY(), pos.getZ()); } return true; } Now, in my code, the onBlockActivated method has two additional parameters: hand, which is of type EnumHand, and heldItem, which is of type ItemStack. These additions were added in the 1.9 edition of Forge, and I am currently using 1.9.4. The "Main" file is called Chest, the "ModGuiHandler" file is instead called "ChestGuiHandler", and the variable in the ModGuiHandler class, MOD_TILE_ENTITY_GUI is renamed CHEST_TILE_ENTITY_GUI, and comes from the "ChestGuiHandler" class. Bearing these changes in mind (as well as removing the unnessary system.out.println statements, which again, were there from debugging), we get the following code. @Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { if (!world.isRemote) { player.openGui(Chest.instance, ChestGuiHandler.CHEST_TILE_ENTITY_GUI, world, pos.getX(), pos.getY(), pos.getZ()); } return true; } } ...which is what is in my code currently.
  12. So I took your advice on it, and decided to look into some online gui tutorials that were not completely up-to-date, but still relatively recent. However I ran into some trouble spots. No gui is shown when the block in question is right-clicked, and I tried to debug the code, but unfortunately, I'm still lost. One aspect that particularly confused me what this tutorials instance on using IInventory, in spite of the use of capabilities. It was my understanding that the use of capabilities, specifically the ItemStackHandler capability, made the implementation of IInventory outdated, though again, I really do have a superficial understanding, so I'm not quite certain. Here's the code, in this order. Please note that the code still has system.out.println statements that print out "checkpoints," a result of my debugging attempt, and I'm sorry if they make the code difficult to follow. The BlockRedChest class, the ChestGuiHandler class, the ContainerChestTileEntity class, the GuiChestTileEntity class, the TileEntityRedChest class, and the Chest (Main) class: http://pastebin.com/cXUjshQ6 http://pastebin.com/EJuFSpi1 http://pastebin.com/vsh882mx http://pastebin.com/6VtTwmUW http://pastebin.com/WucCAgcy http://pastebin.com/BgSudHca Also, for those interested, here's the tutorial I was looking at, though I'm not sure if it will help: http://bedrockminer.jimdo.com/modding-tutorials/advanced-modding/tile-entity-with-inventory/ http://bedrockminer.jimdo.com/modding-tutorials/advanced-modding/gui-handler/ http://bedrockminer.jimdo.com/modding-tutorials/advanced-modding/gui-container/
  13. I'm not entirely sure where to put this post, so I'll do it here. I've been trying to search for a good tutorial on how to create GUI's for my custom blocks, but the tutorials I keep finding, either out of my own incompetence or just the sheer lack of tutorials online, are out of date. Since I cannot find them by searching myself, I've come here. Does anyone know where I could find some GUI tutorials for 1.9.4?
  14. I solved it! I kept destroying the block with my fists in creative mode, which is why nothing dropped. However, when I harvested it using an axe, then the items stored in the block were dropped as expected.
  15. I solved it! I kept destroying the block with my fists in creative mode, which is why nothing dropped. However, when I harvested it using an axe, then the items stored in the block were dropped as expected.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.