Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

HappyKiller1O1

Members
  • Joined

  • Last visited

Everything posted by HappyKiller1O1

  1. Well, if he was going to make his own Achievement type system, he would need to use IEEP.
  2. Alright, I researched interfaces a tad bit, and made one for my base class. And, after all of that, THE SAME ERROR PERSISTS. Like I said, I have three Backpacks that extend the base of ItemBackpack (ItemSmallBackpack, ItemMediumBackpack, and ItemLargeBackpack). Now, I would think, considering these are three separate classes, it wouldn't be too difficult to actually get the right item, I would be wrong. Here are the item classes, the base, the interface, and the new #setInventorySlotContents. Thank you for any help you can provide. ItemSmallBackpack: package com.happykiller.weightlimit.items; public class ItemSmallBackpack extends ItemBackpack { public ItemSmallBackpack() { this.setMaxCarryWeight(200); } } ItemMediumBackpack: package com.happykiller.weightlimit.items; public class ItemMediumBackpack extends ItemBackpack { public ItemMediumBackpack() { this.setMaxCarryWeight(280); } } ItemLargeBackpack: package com.happykiller.weightlimit.items; public class ItemLargeBackpack extends ItemBackpack { public ItemLargeBackpack() { this.setMaxCarryWeight(380); } } ItemBackpack: package com.happykiller.weightlimit.items; import java.util.List; import com.happykiller.weightlimit.main.interfaces.ICarryWeightModifier; import com.happykiller.weightlimit.player.ExtendedPlayer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class ItemBackpack extends Item implements ICarryWeightModifier { protected int maxWeightModifier = 150; public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { if(!world.isRemote) { ExtendedPlayer props = ExtendedPlayer.get(player); if(!player.isSneaking()) { props.addWeight(1); System.out.println("Current Weight: " + props.getCurrentWeight()); }else { props.removeAllWeight(); System.out.println("Current Weight: " + props.getCurrentWeight()); } } return stack; } @SideOnly(Side.CLIENT) public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean advanced) { } public int setMaxCarryWeight(int newMaxWeight) { if(newMaxWeight > 0) { this.maxWeightModifier = newMaxWeight; }else { this.maxWeightModifier = 150; } return this.maxWeightModifier; } public int getMaxCarryWeight() { return this.maxWeightModifier; } public int getMaxCarryWeightForStack(ItemStack stack) { int stackModifier = 150; if(stack.getItem() instanceof ItemBackpack) { stackModifier = ((ItemBackpack)stack.getItem()).getMaxCarryWeight(); }else { System.out.println("ERROR: Stack was not an extension of ItemBackpack in SLOT_BACKPACK!"); } return stackModifier; } } ICarryWeightModifier: package com.happykiller.weightlimit.main.interfaces; import net.minecraft.item.ItemStack; public interface ICarryWeightModifier { public int setMaxCarryWeight(int newMaxWeight); public int getMaxCarryWeightForStack(ItemStack stack); public int getMaxCarryWeight(); } New #setInventorySlotContents: public void setInventorySlotContents(int slot, ItemStack stack) { this.inventory[slot] = stack; if(stack != null && stack.stackSize > this.getInventoryStackLimit()) { stack.stackSize = this.getInventoryStackLimit(); } if(slot == SLOT_BACKPACK) { if(!player.worldObj.isRemote) { ExtendedPlayer props = ExtendedPlayer.get(player); if(props.get(player) != null) { if(stack == null || !(stack.getItem() instanceof ItemBackpack)) { props.setMaxWeight(150); }else { int newMaxWeight = ((ItemBackpack)stack.getItem()).getMaxCarryWeightForStack(stack); System.out.println("Stack in use: " + stack.getItem()); System.out.println("Max weight from interface is: " + newMaxWeight); props.setMaxWeight(newMaxWeight); } } } } this.markDirty(); }
  3. I was working on this at 4am, so no wonder I forgot about the parameters. I honestly have never understood how Interfaces truly work. I know they can help me greatly, but all I know is they are abstract, and used to implement methods I am guessing you call in other classes?
  4. And, as Ernio said, it is very important you learn how to read stacktrace. It is quite simple, you can even click the stacktrace directing to the class with the error in eclipse. Although, I am curious on why you have most likely over 1000 lines in your main mod. Seems a bit messy.
  5. The error says it's on line 971 of the "HelpFulMod" class. That should be where the problem is. I do suggest however, creating your mod in 1.8, rather than 1.7.10. This is because 1.8 is far different from 1.7.10, and it becomes more difficult to update your mod the more you add to it while using a previous version. One of the changes in 1.8, is the removal of having to register Item IDs. Thus, you would never run into this specific problem if you were using 1.8, instead of 1.7.10.
  6. Please show your preInit in your main mod. You seem to be registering a block or item with an ID (214) which is taking by a vanilla minecraft Block.
  7. So, in my Inventory class for my custom inventory, I am using #setInventorySlotContents to detect an item in the slot, and perform an action accordingly. Problem is, it is only detecting one item. here is what my method looks like: public void setInventorySlotContents(int slot, ItemStack stack) { this.inventory[slot] = stack; if(stack != null && stack.stackSize > this.getInventoryStackLimit()) { stack.stackSize = this.getInventoryStackLimit(); } if(getStackInSlot(SLOT_BACKPACK) != null && getStackInSlot(SLOT_BACKPACK).getItem() instanceof ItemBackpack) { if(!player.worldObj.isRemote) { System.out.println("World is not remote"); ExtendedPlayer props = ExtendedPlayer.get(player); if(props.get(player) != null) { System.out.println("Player props are not null"); if(getStackInSlot(SLOT_BACKPACK).getItem() instanceof ItemSmallBackpack) { System.out.println("Small Backpack detected!"); props.setMaxWeight(200); } if(getStackInSlot(SLOT_BACKPACK).getItem() instanceof ItemMediumBackpack) { System.out.println("Medium Backpack detected!"); props.setMaxWeight(250); } if(getStackInSlot(SLOT_BACKPACK).getItem() instanceof ItemLargeBackpack) { System.out.println("Large Backpack detected!"); props.setMaxWeight(300); } } } System.out.println("BACKPACK IN SLOT!"); }else { if(!player.worldObj.isRemote) { ExtendedPlayer props = ExtendedPlayer.get(player); if(props.get(player) != null) { props.setMaxWeight(150); } } } this.markDirty(); } The problem is where I am checking for an item in "SLOT_BACKPACK" (it is 0. I just use a constant for organization). The items I check for all extend a base called "ItemBackpack", and I would think using "instanceof" to check for it would be enough. But no matter what of the three items I put, it will always seem to return as the ItemSmallBackpack being in the slot. Am I checking for the items wrong? Would using a switch fix the problem?
  8. So, I went to go and shift-click my custom item into my custom slot, and I get this error: Caused by: java.lang.IndexOutOfBoundsException: Index: 40, Size: 37 at java.util.ArrayList.rangeCheck(Unknown Source) ~[?:1.8.0_65] at java.util.ArrayList.get(Unknown Source) ~[?:1.8.0_65] at net.minecraft.inventory.Container.mergeItemStack(Container.java:638) ~[Container.class:?] at com.happykiller.weightlimit.player.inventory.container.ContainerWeightedPlayer.transferStackInSlot(ContainerWeightedPlayer.java:81) ~[ContainerWeightedPlayer.class:?] at net.minecraft.inventory.Container.slotClick(Container.java:291) ~[Container.class:?] at net.minecraft.client.multiplayer.PlayerControllerMP.windowClick(PlayerControllerMP.java:540) ~[PlayerControllerMP.class:?] at net.minecraft.client.gui.inventory.GuiContainer.handleMouseClick(GuiContainer.java:690) ~[GuiContainer.class:?] at net.minecraft.client.gui.inventory.GuiContainer.mouseClicked(GuiContainer.java:422) ~[GuiContainer.class:?] at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:606) ~[GuiScreen.class:?] at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:572) ~[GuiScreen.class:?] at net.minecraft.client.Minecraft.runTick(Minecraft.java:1760) ~[Minecraft.class:?] ... 15 more Here is the line that gives the error: if(!this.mergeItemStack(stack1, INV_START, HOTBAR_END + 1, true)) { return null; } Here are those variables (NOTE: I do not have armor slots in my Inventory. This might be causing the problem, but I am not sure): private static final int ARMOR_START = InventoryWeightLimit.INV_SIZE, ARMOR_END = ARMOR_START + 3, INV_START = ARMOR_END + 1, INV_END = INV_START + 26, HOTBAR_START = INV_END + 1, HOTBAR_END = HOTBAR_START + 8; Any ideas?
  9. I changed it and it seems to be working. Here's my new #readFromNBT (just so you can see if there is something that may cause problems in the future): public void readFromNBT(NBTTagCompound tag) { NBTTagList items = tag.getTagList(tagName, tag.getId()); for(int i = 0; i < items.tagCount(); i++) { NBTTagCompound item = items.getCompoundTagAt(i); int j = item.getByte("Slot"); ItemStack stack = ItemStack.loadItemStackFromNBT(item); if(stack != null) { if(j >= 0 && j < this.inventory.length) { this.inventory[j] = stack; } } } } Thank you again for helping me coolAlias! Like I am completely honest, most of my knowledge has come from your tutorials, and your generous help on both this, and the MinecraftForum. Thanks for always helping in a kind manner.
  10. Ohhhh, alright so I should manually loop through the slots and fill them with a for() loop?
  11. I'm really sorry to act so ignorant, but are you talking about how I am using #setInventorySlotContents in the #loadFromNBT method in my inventory class?
  12. Alright, that worked fine. Except for this persistent error that happens when I log in, or open the custom inventory after putting the item in and logging off and on. Error: [21:07:20] [Netty Server IO #1/ERROR] [FML]: There was a critical exception handling a packet on channel WeightLimit java.lang.NullPointerException at net.minecraftforge.fml.common.network.FMLOutboundHandler$OutboundTarget$4.selectNetworks(FMLOutboundHandler.java:112) ~[FMLOutboundHandler$OutboundTarget$4.class:?] at net.minecraftforge.fml.common.network.FMLOutboundHandler.write(FMLOutboundHandler.java:276) ~[FMLOutboundHandler.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeWrite(DefaultChannelHandlerContext.java:645) ~[DefaultChannelHandlerContext.class:4.0.15.Final] at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:699) ~[DefaultChannelHandlerContext.class:4.0.15.Final] at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:638) ~[DefaultChannelHandlerContext.class:4.0.15.Final] at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:115) ~[MessageToMessageEncoder.class:4.0.15.Final] at io.netty.handler.codec.MessageToMessageCodec.write(MessageToMessageCodec.java:116) ~[MessageToMessageCodec.class:4.0.15.Final] at io.netty.channel.DefaultChannelHandlerContext.invokeWrite(DefaultChannelHandlerContext.java:645) ~[DefaultChannelHandlerContext.class:4.0.15.Final] at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:699) ~[DefaultChannelHandlerContext.class:4.0.15.Final] at io.netty.channel.DefaultChannelHandlerContext.writeAndFlush(DefaultChannelHandlerContext.java:689) ~[DefaultChannelHandlerContext.class:4.0.15.Final] at io.netty.channel.DefaultChannelHandlerContext.writeAndFlush(DefaultChannelHandlerContext.java:718) ~[DefaultChannelHandlerContext.class:4.0.15.Final] at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:893) ~[DefaultChannelPipeline.class:4.0.15.Final] at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:240) ~[AbstractChannel.class:4.0.15.Final] at net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.sendTo(SimpleNetworkWrapper.java:196) ~[simpleNetworkWrapper.class:?] at com.happykiller.weightlimit.player.ExtendedPlayer.sync(ExtendedPlayer.java:118) ~[ExtendedPlayer.class:?] at com.happykiller.weightlimit.player.ExtendedPlayer.setMaxWeight(ExtendedPlayer.java:111) ~[ExtendedPlayer.class:?] at com.happykiller.weightlimit.player.inventory.InventoryWeightLimit.setInventorySlotContents(InventoryWeightLimit.java:110) ~[inventoryWeightLimit.class:?] at com.happykiller.weightlimit.player.inventory.InventoryWeightLimit.readFromNBT(InventoryWeightLimit.java:180) ~[inventoryWeightLimit.class:?] at com.happykiller.weightlimit.player.ExtendedPlayer.loadNBTData(ExtendedPlayer.java:58) ~[ExtendedPlayer.class:?] at net.minecraft.entity.Entity.readFromNBT(Entity.java:1710) ~[Entity.class:?] at net.minecraft.server.management.ServerConfigurationManager.readPlayerDataFromFile(ServerConfigurationManager.java:300) ~[serverConfigurationManager.class:?] at net.minecraft.server.management.ServerConfigurationManager.initializeConnectionToPlayer(ServerConfigurationManager.java:123) ~[serverConfigurationManager.class:?] at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.completeServerSideConnection(NetworkDispatcher.java:239) ~[NetworkDispatcher.class:?] at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher.access$100(NetworkDispatcher.java:51) ~[NetworkDispatcher.class:?] at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher$1.update(NetworkDispatcher.java:190) ~[NetworkDispatcher$1.class:?] at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:270) ~[NetworkManager.class:?] at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:208) ~[NetworkSystem.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:798) ~[MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:669) ~[MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:171) ~[integratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:540) ~[MinecraftServer.class:?] at java.lang.Thread.run(Unknown Source) [?:1.8.0_65] It leads to my sync method in the ExtendedPlayer. Which simply sends the client update packet. Here's the setInventorySlotContents: public void setInventorySlotContents(int slot, ItemStack stack) { this.inventory[slot] = stack; if(stack != null && stack.stackSize > this.getInventoryStackLimit()) { stack.stackSize = this.getInventoryStackLimit(); } this.markDirty(); if(getStackInSlot(SLOT_BACKPACK) != null && getStackInSlot(SLOT_BACKPACK).getItem() instanceof ItemBackpack) { if(!player.worldObj.isRemote) { System.out.println("World is not remote"); ExtendedPlayer props = ExtendedPlayer.get(player); if(props.get(player) != null) { System.out.println("Player props are not null"); if(getStackInSlot(SLOT_BACKPACK).getItem() instanceof ItemSmallBackpack) { System.out.println("Small Backpack detected!"); props.setMaxWeight(200); } } } System.out.println("BACKPACK IN SLOT!"); }else { if(!player.worldObj.isRemote) { ExtendedPlayer props = ExtendedPlayer.get(player); if(props.get(player) != null) { props.setMaxWeight(150); } } } } Any idea?
  13. Alright, it works with the detection and such. But, I need to get the server side player in order to use my ExtendedPlayer. How would I be able to set that?
  14. I believe the second is best in my case. When the item is added, I would like to increase my maxWeight variable in the ExtendedPlayer by a certain amount. And when removed, decrease it by the same amount. So, using a tick handler would be useless I believe.
  15. Because it's my own inventory, I have my own inventory class. How exactly would I go about checking though? I know I can use "getStackInSlot" and use my slot ID, then check for the item. But, where would I be checking for that?
  16. So, I made a custom inventory for the player, that houses a custom slot. I would like to know how I would check if my custom slot contains a certain item. I would normally do this in a onUpdate method (like in a TileEntity), but there is no update method that I've found within the Container class. Where would I look to accomplish this?
  17. He could use a date to give the player the block, but when they log in and out, they will receive it again. Plus, considering Minecraft runs off of the computer date, a player could abuse this and change his date back between January 1st to get the items again. Honestly, the only concrete way of making sure the player will only get the block once, would be to use IEEP. You could however, go through the TinkersConstruct Github to find out how they did it.
  18. I haven't looked through their code, but I would guess they use some form of IEEP to accomplish that. Here's a tutorial by one of the greats here (coolAlias) about IExtendedEntityProperties: http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/1571567-forge-1-6-4-1-8-eventhandler-and Set yours up, and just do a boolean instead of the int's he sets. Then, it should work as you would like.
  19. Well, considering a TileEntity is apart of a block and not the player, it would be impossible for the game to know if the player got it or not. I would use IExtendedEntityProperties to save a boolean to the player, and check the boolean when the player joins the world. If it is false, give the player the block. If it is true, do not. Again, a TileEntity can't do what you're trying to accomplish.
  20. Why not just drop the items when the block is broken? It would save a lot of time.
  21. Is your mod attempting to add anything to the Item generation in chests?
  22. Alright, so I have created a way of syncing between client and server with packets. It works just fine in game, but when running this code in my event handler: @SubscribeEvent public void onEntityJoinWorld(EntityJoinWorldEvent event) { if(!event.entity.worldObj.isRemote && event.entity instanceof EntityPlayer && ExtendedPlayer.get((EntityPlayer)event.entity) != null) { ExtendedPlayer.get((EntityPlayer)event.entity).sync(); } } I get this error during me joining: [01:18:21] [Client thread/FATAL] [FML]: Exception caught executing FutureTask: java.util.concurrent.ExecutionException: java.lang.NullPointerException java.util.concurrent.ExecutionException: java.lang.NullPointerException at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_65] at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_65] at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:715) [FMLCommonHandler.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1077) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:376) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:117) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_65] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_65] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_65] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_65] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_65] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_65] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_65] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_65] at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?] at GradleStart.main(Unknown Source) [start/:?] Caused by: java.lang.NullPointerException at com.happykiller.weightlimit.player.ExtendedPlayer.get(ExtendedPlayer.java:35) ~[ExtendedPlayer.class:?] at com.happykiller.weightlimit.server.packet.packets.PacketSyncPlayerProps$Handler$1.run(PacketSyncPlayerProps.java:47) ~[PacketSyncPlayerProps$Handler$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_65] at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_65] at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:714) ~[FMLCommonHandler.class:?] ... 15 more Here is line 35 of ExtendedPlayer: public static final ExtendedPlayer get(EntityPlayer player) { return (ExtendedPlayer)player.getExtendedProperties(EXT_PROP_NAME); } And here is the packet being sent to update the client: package com.happykiller.weightlimit.server.packet.packets; import com.happykiller.weightlimit.player.ExtendedPlayer; import io.netty.buffer.ByteBuf; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.server.MinecraftServer; import net.minecraft.util.IThreadListener; import net.minecraftforge.fml.common.network.ByteBufUtils; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; public class PacketSyncPlayerProps implements IMessage { private NBTTagCompound data; public PacketSyncPlayerProps() {} public PacketSyncPlayerProps(EntityPlayer player) { data = new NBTTagCompound(); ExtendedPlayer.get(player).saveNBTData(data); } public void fromBytes(ByteBuf buf) { data = ByteBufUtils.readTag(buf); } public void toBytes(ByteBuf buf) { ByteBufUtils.writeTag(buf, data); } public static class Handler implements IMessageHandler<PacketSyncPlayerProps, IMessage> { public IMessage onMessage(final PacketSyncPlayerProps message, MessageContext ctx) { IThreadListener mainThread = Minecraft.getMinecraft(); final EntityPlayer player = Minecraft.getMinecraft().thePlayer; mainThread.addScheduledTask(new Runnable() { public void run() { System.out.println("Loading client player data..."); ExtendedPlayer.get(player).loadNBTData(message.data); } }); return null; } } } This might just be me missing something obvious, but I am really flustered on why this is happening. Any thoughts?
  23. Oh wait, think I got it! Will using MinecraftServer#getServer() cause any problems?

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.