-
Posts
28 -
Joined
-
Last visited
Everything posted by Jimmynator
-
[SOLVED] Importing a schematic into the world
Jimmynator replied to Jimmynator's topic in Modder Support
Hey, that's great, your mod is awesome too. I currently need to import schematics to make a very big update to classcraft. Is your generator an importer or an editor? I'd love to talk with you but I don't have mic. Do you have a google talk account? Also, I'd obviously credit you and help you if you want. -
So I'm currently making a mod and I need some help in how to import a schematic file and place it in the world. I'd appreciate any response you could give me about how to do this. Thanks in advance.
-
[Solved in a strange way][1.3.2] Sync issues in inventories
Jimmynator replied to Jimmynator's topic in Modder Support
Great! Thanks for the code, but it is a crafting inventory, so the server doesn't have to know the items in each slot. Mine, however, needs to sync with the server. -
[Solved in a strange way][1.3.2] Sync issues in inventories
Jimmynator replied to Jimmynator's topic in Modder Support
No, it is extending the base GuiContainer. This might be a problem with inventories that aren't using tile entities. It's great that you solved it, how's your mod going? -
[Solved in a strange way][1.3.2] Sync issues in inventories
Jimmynator replied to Jimmynator's topic in Modder Support
That's some strange things happening. My code kind of works when it is fired 4 times. At least it does for my container -
[Solved in a strange way][1.3.2] Sync issues in inventories
Jimmynator replied to Jimmynator's topic in Modder Support
Yeah, I'm sure this shouldn't be the code to make things work, but the only packets I send are those sync packets I've put here, and it works this way. If someone comes up with the actual code we should be using, it'd be much appreciated. About your container isues, as you're using tile entities you should take a look at cpw's code in it's ironchests github. I remember the packets you used had some kind of sync issues back in 1.2.5. -
[Solved in a strange way][1.3.2] Sync issues in inventories
Jimmynator replied to Jimmynator's topic in Modder Support
Finally, I fixed it, I had to sync the slot clicking in the container for it to work. This was synced automatically in 1.2.5, I don't know why has this changed. Code: ContainerX: @Override public ItemStack slotClick (int slot, int button, boolean flag, EntityPlayer player) { ItemStack stack = super.slotClick(slot, button, flag, player); if (Minecraft.getMinecraft() != null && slot > 35) { PacketHandlerX.syncStack(stack, slot); } return stack; } PacketHandlerX: public void onPacketData(NetworkManager manager, Packet250CustomPayload packet, Player player) { if (packet.channel.equals("channelX")) { DataInputStream dataStream = new DataInputStream(new ByteArrayInputStream(packet.data)); EntityPlayer entityplayer = (EntityPlayer) player; int id = -1; try { id = dataStream.readInt(); switch (id) { case -1: break; case 0: ItemStack stack; int slot = dataStream.readInt(); int itemID = dataStream.readInt(); if (itemID < 0) { stack = null; } else { int stacksize = dataStream.readInt(); int damage = dataStream.readInt(); boolean bool = dataStream.readBoolean(); stack = new ItemStack(itemID, stacksize, damage); if (!bool) { NBTTagCompound tags = (NBTTagCompound) NBTTagCompound.readNamedTag(dataStream); stack.setTagCompound(tags); } } ((((inventoryYouWantToUpdate)))).setInventorySlotContents(slot, stack); break; } } catch(IOException e) { e.printStackTrace(); } } } public static void syncStack(ItemStack stack, int slot) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); DataOutputStream data = new DataOutputStream(bytes); try { data.writeInt(0); data.writeInt(slot); if (stack == null) { data.writeInt(-1); } else { data.writeInt(stack.itemID); data.writeInt(stack.stackSize); data.writeInt(stack.getItemDamage()); data.writeBoolean(stack.getTagCompound() == null); if (stack.getTagCompound() != null) { stack.getTagCompound().writeNamedTag(stack.getTagCompound(), data); } } } catch(IOException e) { e.printStackTrace(); } Packet250CustomPayload packet = new Packet250CustomPayload(); packet.channel = "channelX"; packet.data = bytes.toByteArray(); packet.length = packet.data.length; PacketDispatcher.sendPacketToServer(packet); } I don't know if this is what it is supposed to be like, but it works. -
[Solved in a strange way][1.3.2] Sync issues in inventories
Jimmynator replied to Jimmynator's topic in Modder Support
No. Still searching for an answer... -
[Solved in a strange way][1.3.2] Sync issues in inventories
Jimmynator replied to Jimmynator's topic in Modder Support
This is very strange... Actually, when I use a stack of 64 items, it creates a "ghost" stack in the inventory and a real one in my hand. This is obvioulsy a sync issue, but I can't find where the problem is! -
So I'm trying to update my mods to 1.3.2. I have everything working but one single bug: whenever I try to put a stack of items inside a custom inventory, the stack is duplicated, and whenever I try to remove it, it totally disappears. Example: I have a stack of 2, I try to place it in a slot in my custom inventory and the stack size is now 4, I remove it and it disappears. This is very strange as the same code worked in 1.2.5. This is my code: InventoryResearch: package jimmynator.researchcraft; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Random; import cpw.mods.fml.client.FMLClientHandler; import net.minecraft.client.Minecraft; import net.minecraft.src.Block; import net.minecraft.src.CraftingManager; import net.minecraft.src.EntityPlayer; import net.minecraft.src.IInvBasic; import net.minecraft.src.IInventory; import net.minecraft.src.IRecipe; import net.minecraft.src.InventoryBasic; import net.minecraft.src.InventoryPlayer; import net.minecraft.src.ItemStack; import net.minecraft.src.NBTTagCompound; import net.minecraft.src.NBTTagList; import net.minecraft.src.StringTranslate; public class InventoryResearch implements IInventory { public ItemStack[] itemStacks = new ItemStack[9]; public InventoryPlayer inventoryPlayer; public GuiResearchButton researchButton; public int researchProgress = 0; public boolean isResearching = false; public String recipeToShow = ""; public InventoryResearch(InventoryPlayer inventoryplayer) { this.inventoryPlayer = inventoryplayer; } public void setIsResearching(GuiResearchButton guibutton, boolean flag) { if (flag) { researchProgress = 0; recipeToShow = ""; } if (guibutton != null) { researchButton = guibutton; } isResearching = !isResearching; researchButton.enabled = !isResearching; } public void updateInventory() { if (isResearching) { if (researchProgress < 12000) { if (inventoryPlayer.player.getFoodStats().getFoodLevel() - 10 > 0) { researchProgress += (inventoryPlayer.player.getFoodStats().getFoodLevel() - 10)*10; inventoryPlayer.player.addExhaustion(0.0025F); } } else { Random rand = inventoryPlayer.player.worldObj.rand; researchProgress = 12000; List recipelist = new ArrayList(); recipelist.add(10); List recipes = CraftingManager.getInstance().getRecipeList(); for (int index = 0; index < recipes.size(); index++) { String recipe = ResearchCraft.dataHandler.getRecipeString((IRecipe)recipes.get(index)); if (recipe == null) { continue; } ItemStack[] stacks = ResearchCraft.dataHandler.getStacksFromString(recipe); int itemok = 0; int size = 0; for (int i = 1; i < stacks.length; i++) { if (stacks[i] != null) { size++; for (int j = 36; j < 36 + getSizeInventory(); j++) { if (getStackInSlot(j) != null && stacks[i].itemID == getStackInSlot(j).itemID) { if (stacks[i].itemID < Block.blocksList.length || !(stacks[i].isItemStackDamageable())) { if (stacks[i].getItemDamage() != -1) { if (stacks[i].getItemDamage() == getStackInSlot(j).getItemDamage()) { itemok++; break; } } else { itemok++; break; } } else { itemok++; break; } } } } else { itemok++; } } if (itemok == stacks.length - 1) { if (!ResearchCraft.dataHandler.getIsResearched(recipe, inventoryPlayer.player)) { if (recipe.contains("#@58:0") || (recipe.contains("#@54:0") && ResearchCraft.dataHandler.getIsResearched("#@58:0", inventoryPlayer.player)) || (recipe.contains("#@61:0") && ResearchCraft.dataHandler.getIsResearched("#@58:0", inventoryPlayer.player)) || (recipe.contains("#@355:0") && ResearchCraft.dataHandler.getIsResearched("#@58:0", inventoryPlayer.player))) { recipelist = new ArrayList(); recipelist.add(size); recipelist.add(recipe); break; } else if (size < (Integer) recipelist.get(0)) { recipelist = new ArrayList(); recipelist.add(size); recipelist.add(recipe); } else if (size == (Integer) recipelist.get(0)) { recipelist.add(recipe); } } } } if (recipelist.size() > 1) { if (rand.nextBoolean()) { if (!ResearchCraft.dataHandler.getPlayerString(inventoryPlayer.player).contains("#")) { inventoryPlayer.player.addStat(ResearchCraft.instance.achievements[0], 1); } recipeToShow = (String) recipelist.get(rand.nextInt(recipelist.size() - 1) + 1); if (!ResearchCraft.dataHandler.getPlayerString(inventoryPlayer.player).contains(recipeToShow)) { ResearchCraft.dataHandler.setPlayerString(inventoryPlayer.player, ResearchCraft.dataHandler.getPlayerString(inventoryPlayer.player).concat(recipeToShow)); PacketHandler.sendRecipeResearch(recipeToShow); } setIsResearching(researchButton, false); ItemStack stack = ResearchCraft.dataHandler.getStacksFromString(recipeToShow)[0]; Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(stack.getItem().getItemDisplayName(stack) + ". " + StringTranslate.getInstance().translateKey("gui.yes") + "!"); } else { for (int i = 36; i < 36 + getSizeInventory(); i++) { if (getStackInSlot(i) != null) { if (rand.nextBoolean()) { if (getStackInSlot(i).stackSize > 1) { getStackInSlot(i).stackSize -= 1; setInventorySlotContents(i, getStackInSlot(i)); } else { setInventorySlotContents(i, null); } PacketHandler.sendReduceResearch(i); } } } if (isResearching) { setIsResearching(researchButton, false); setIsResearching(researchButton, true); } else { setIsResearching(researchButton, true); } } } else { for (int i = 36; i < 36 + getSizeInventory(); i++) { if (getStackInSlot(i) != null) { if (rand.nextBoolean()) { if (getStackInSlot(i).stackSize > 1) { getStackInSlot(i).stackSize -= 1; setInventorySlotContents(i, getStackInSlot(i)); } else { setInventorySlotContents(i, null); } PacketHandler.sendReduceResearch(i); } } } if (isResearching) { setIsResearching(researchButton, true); Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(StringTranslate.getInstance().translateKey("potion.prefix.uninteresting") + "..."); } } } } } public int getResearchProgressScaled(int par1) { return (int) (par1 * (researchProgress / 12000F)); } @Override public int getSizeInventory() { return 9; } @Override public ItemStack getStackInSlot(int var1) { return itemStacks[var1 - 36]; } @Override public ItemStack decrStackSize(int var1, int var2) { System.out.println("lol2? " + var1 + " " + var2); if (this.itemStacks[var1 - 36] != null) { ItemStack var3; if (this.itemStacks[var1 - 36].stackSize <= var2) { var3 = this.itemStacks[var1 - 36]; this.itemStacks[var1 - 36] = null; this.onInventoryChanged(); return var3; } else { var3 = this.itemStacks[var1 - 36].splitStack(var2); if (this.itemStacks[var1 - 36].stackSize == 0) { this.itemStacks[var1 - 36] = null; } this.onInventoryChanged(); return var3; } } else { return null; } } @Override public ItemStack getStackInSlotOnClosing(int var1) { return null; } @Override public void setInventorySlotContents(int var1, ItemStack var2) { System.out.println("lol? " + var1 + " " + var2); this.itemStacks[var1 - 36] = var2; this.onInventoryChanged(); } @Override public String getInvName() { return "Research Inventory"; } @Override public int getInventoryStackLimit() { return 64; } @Override public void onInventoryChanged() {} @Override public boolean isUseableByPlayer(EntityPlayer var1) { return this.inventoryPlayer.player.isDead ? false : var1.getDistanceSqToEntity(this.inventoryPlayer.player) <= 64.0D; } @Override public void openChest() {} @Override public void closeChest() {} } ContainerResearch: package jimmynator.researchcraft; import net.minecraft.src.Container; import net.minecraft.src.EntityPlayer; import net.minecraft.src.IInventory; import net.minecraft.src.InventoryPlayer; import net.minecraft.src.ItemStack; import net.minecraft.src.Slot; public class ContainerResearch extends Container { public IInventory researchInventory; public ContainerResearch(InventoryPlayer inventoryplayer, InventoryResearch inventoryresearch) { researchInventory = inventoryresearch; int var3; int var4; this.addSlotToContainer(new Slot(inventoryresearch, 36, 6, 16)); this.addSlotToContainer(new Slot(inventoryresearch, 37, 27, 6)); this.addSlotToContainer(new Slot(inventoryresearch, 38, 50, ); this.addSlotToContainer(new Slot(inventoryresearch, 39, 11, 38)); this.addSlotToContainer(new Slot(inventoryresearch, 40, 34, 30)); this.addSlotToContainer(new Slot(inventoryresearch, 41, 59, 35)); this.addSlotToContainer(new Slot(inventoryresearch, 42, 13, 60)); this.addSlotToContainer(new Slot(inventoryresearch, 43, 32, 53)); this.addSlotToContainer(new Slot(inventoryresearch, 44, 53, 61)); for (var3 = 0; var3 < 3; ++var3) { for (var4 = 0; var4 < 9; ++var4) { this.addSlotToContainer(new Slot(inventoryplayer, var4 + (var3 + 1) * 9, 8 + var4 * 18, 84 + var3 * 18)); } } for (var3 = 0; var3 < 9; ++var3) { this.addSlotToContainer(new Slot(inventoryplayer, var3, 8 + var3 * 18, 142)); } } @Override public boolean canInteractWith(EntityPlayer var1) { return true; } @Override public ItemStack transferStackInSlot(int par1) { ItemStack var2 = null; Slot var3 = (Slot)this.inventorySlots.get(par1); if (var3 != null && var3.getHasStack()) { ItemStack var4 = var3.getStack(); var2 = var4.copy(); if (par1 == 0) { if (!this.mergeItemStack(var4, 9, 45, true)) { return null; } var3.onSlotChange(var4, var2); } else if (par1 >= 9 && par1 < 36) { if (!this.mergeItemStack(var4, 36, 45, false)) { return null; } } else if (par1 >= 36 && par1 < 45) { if (!this.mergeItemStack(var4, 9, 36, false)) { return null; } } else if (!this.mergeItemStack(var4, 9, 45, false)) { return null; } if (var4.stackSize == 0) { var3.putStack((ItemStack)null); } else { var3.onSlotChanged(); } if (var4.stackSize == var2.stackSize) { return null; } var3.onPickupFromSlot(var4); } return var2; } } GuiResearch (only client side): package jimmynator.researchcraft; import net.minecraft.src.EntityPlayer; import net.minecraft.src.GuiButton; import net.minecraft.src.GuiContainer; import net.minecraft.src.InventoryPlayer; import net.minecraft.src.ItemStack; import net.minecraft.src.OpenGlHelper; import net.minecraft.src.RenderHelper; import net.minecraft.src.ScaledResolution; import net.minecraft.src.Slot; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; public class GuiResearch extends GuiContainer { private static ContainerResearch container = null; public GuiResearchButton startResearch; public InventoryPlayer inventoryPlayer; public InventoryResearch inventoryResearch; public GuiResearch(EntityPlayer par1EntityPlayer) { super(new ContainerResearch(par1EntityPlayer.inventory, ResearchCraft.dataHandler.getInventoryResearch(par1EntityPlayer))); inventoryPlayer = par1EntityPlayer.inventory; inventoryResearch = ResearchCraft.dataHandler.getInventoryResearch(par1EntityPlayer); } @Override public void initGui() { super.initGui(); guiLeft = (width - xSize) / 2; guiTop = (height - ySize) / 2; controlList.clear(); startResearch = new GuiResearchButton(0, guiLeft + 87, guiTop + 61, 18, 18, ""); inventoryResearch.setIsResearching(startResearch, false); inventoryResearch.setIsResearching(startResearch, false); controlList.add(startResearch); } @Override protected void actionPerformed(GuiButton guibutton) { if (guibutton.id == 0) { inventoryResearch.setIsResearching((GuiResearchButton) guibutton, true); } } @Override protected void drawGuiContainerForegroundLayer() { this.fontRenderer.drawString("Research", 118, 68, 4210752); } @Override protected void drawGuiContainerBackgroundLayer(float f, int i, int j) { int r = mc.renderEngine.getTexture("/textures/researchcraft_research.png"); GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.5F); mc.renderEngine.bindTexture(r); int w = (width - xSize) / 2; int h = (height - ySize) / 2; //GUI drawTexturedModalRect(w, h, 0, 0, xSize, ySize); //Bulb int scaledProgress = inventoryResearch.getResearchProgressScaled(31); drawTexturedModalRect(w + 86, h + 27 + (31 - scaledProgress), 176, 0 + (31 - scaledProgress), 20, scaledProgress); //Button if (startResearch.drawButton) { ScaledResolution var13 = new ScaledResolution(mc.gameSettings, mc.displayWidth, mc.displayHeight); int var14 = var13.getScaledWidth(); int var15 = var13.getScaledHeight(); int var16 = Mouse.getX() * var14 / mc.displayWidth; int var17 = var15 - Mouse.getY() * var15 / mc.displayHeight - 1; boolean var5 = var16 >= startResearch.xPosition && var17 >= startResearch.yPosition && var16 < startResearch.xPosition + startResearch.width && var17 < startResearch.yPosition + startResearch.height; int var6 = startResearch.getHoverState(var5); drawTexturedModalRect(w + 87, h + 61, 176, 32 + var6 * 18, startResearch.width, startResearch.height); startResearch.mouseDragged(mc, var16, var17); } //Research recipe if (inventoryResearch.researchProgress >= 12000 && inventoryResearch.recipeToShow != "") { ItemStack[] stacks = ResearchCraft.dataHandler.getStacksFromString(inventoryResearch.recipeToShow); drawStackInventory(stacks[0], 88, ; drawStackInventory(stacks[1], 116, ; drawStackInventory(stacks[2], 134, ; drawStackInventory(stacks[3], 152, ; drawStackInventory(stacks[4], 116, 26); drawStackInventory(stacks[5], 134, 26); drawStackInventory(stacks[6], 152, 26); drawStackInventory(stacks[7], 116, 44); drawStackInventory(stacks[8], 134, 44); drawStackInventory(stacks[9], 152, 44); } } private void drawStackInventory(ItemStack itemstack, int x, int y) { ItemStack newitem = null; if (itemstack != null) { newitem = itemstack.copy(); if (itemstack.getItemDamage() == -1) { newitem.setItemDamage(0); } } RenderHelper.enableGUIStandardItemLighting(); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glEnable(GL12.GL_RESCALE_NORMAL); GL11.glEnable(GL11.GL_LIGHTING); GL11.glEnable(GL11.GL_DEPTH_TEST); Slot var6 = null; short var7 = 240; short var8 = 240; OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)var7 / 1.0F, (float)var8 / 1.0F); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); zLevel = 100.0F; itemRenderer.zLevel = 100.0F; if (itemstack != null) { itemRenderer.renderItemIntoGUI(fontRenderer, mc.renderEngine, newitem, guiLeft + x, guiTop + y); itemRenderer.renderItemOverlayIntoGUI(fontRenderer, mc.renderEngine, newitem, guiLeft + x, guiTop + y); } itemRenderer.zLevel = 0.0F; zLevel = 0.0F; GL11.glDisable(GL12.GL_RESCALE_NORMAL); RenderHelper.disableStandardItemLighting(); GL11.glDisable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_DEPTH_TEST); } @Override protected void keyTyped(char par1, int par2) { if (par2 == 1 || par2 == this.mc.gameSettings.keyBindInventory.keyCode || par2 == ClientKeyHandler.Research.keyCode) { this.mc.thePlayer.closeScreen(); } } }
-
I am the developer of the ResearchCraft mod, and while making the mod I found that I needed a small hook to check the position before the crafting happens. This would help me to finish the mod and might help others who want some recipe to be used only under certain circumstances, like for example a recipe to make ice from a water bucket. That recipe would be disabled unless the crafting occurs in a snow biome. Ok, so I have the hook here, this is what I want it to be like. Look at it and say if you like it or the coding is awful and must be replaced by some better code: ICraftingHandler.java: with onTakenFromCrafting. ForgeHooks.java: after or before onTakenFromCrafting. CraftingManager: note that there is some code in the deprecated one. Now there are two base edits that aren't edited right now by forge. You'll not like this. ContainerPlayer: ContainerWorkbench:
-
Strange NullPointerException With Most Forge Mods.
Jimmynator replied to Icet44's topic in Support & Bug Reports
Try using forge 3.3.7.135. -
Yes, but I want other mod's crafting tables to work too (such as RedPower's or BuildCraft's), and that wouldn't work.
-
LoL . Well, I haven't found the hook yet. I have discovered how to remove all base edits but the one which enables or disables recipes for each person. I need some help here.
-
There should be a forge hook list, just to keep it simple to search hooks. About the hook. Still can't find it. I have been searching in ForgeHooks, MinecraftForge, CraftingManager, ContainerWorkbench and InventoryCrafting with no luck. Even then, having to handle the recipes in my mod would have serious compatibility issues, and I'd have to make it compatible with every conflicting mod by hand.
-
OK, so I have been searching the hook you stated, but after looking into all forge hooks, I can say there is NOT such hook (or it is very VERY difficult to find). There is a hook to handle when an item is taken from crafting (which actually is repeated in FML), but it doesn't allow you to block crafting such item. The solution for this isn't going to be easy, as it would only affect the basic crafting GUI. The only way to retrieve the player is with SlotCrafting, which hasn't got a generic way of retrieving it, so I have to deal with Container.getSlot(number), and that number may differ between crafting containers. To sum up, there is actually no generic way to check who is crafting something, and I can't find a solution.
-
Still can't find it... Do you know the name of the hook?
-
My SSP method is the same I use for SMP, which edits base classes.
-
Yes, it can be found here: http://www.minecraftforum.net/topic/1012026-125smp-jimmynators-mods-classcraft-v231-researchcraft-v08-june-26/ About the hook, I can't see it. The only crafting hook I see is the onTakenFromCrafting() hook. Where is it? BTW, is there any way to add a new variable to EntityPlayer without editing it?
-
Thanks for trying it! Yes, that's the problem I have. I might need some help to make a hook if that's what you are proposing, as I have no idea about how to do them. I'm not an expert programmer. I have some code to do that, but it only works with my mod.
-
Hi, I'm the developer of the ResearchCraft mod here, and I have to edit some base classes for it to work. As I don't like editing base classes, I've tried removing all those edits and doing it with reflection. It works in SSP by removing and adding them again, but I have a problem in SMP, where I need the recipes to be enabled for some users and disabled for some others. The problem is that it isn't possible to remove a recipe from a client while not removing it from the other clients. What happens is that if you remove the recipe from the client, you can't see the recipe being craftable, but you can still craft it as it is in the server recipe list, and removing them from the server, removes them from all clients. So what I need is a small hook to enable or disable recipes for each player instead of the full server.