Jump to content

DonKresenko

Members
  • Posts

    63
  • Joined

  • Last visited

Everything posted by DonKresenko

  1. I'm having a problem with opening GUI with Packets. Don't know what to do. I have some code, but it ain't working
  2. I have the same problem. Can anyone post the final code please?
  3. This is actually my problem http://www.minecraftforge.net/forum/index.php/topic,20398.msg102954.html#msg102954 ... I still can't fix it or know what the problem is
  4. I'm opening GUI on the block. Can any of you guys lead me to some source or examples?
  5. I got suggested that I should use a PacketHandler to open my GUI. Now I have no idea on how to open the gui in the PacketHandler, so I would require some help. I searched for some tutorials and explanations, but I can't realize what should I do. The GUI has 1 button and 1 text input field. When you input a number in the field and click on the button, it will take the number and set the strength of the explosion. Here's the action method for the button:
  6. Alright. Thank you for leading me on what is causing the problem
  7. How can I do that? I never mess around with packets before, I heard, but don't know what it is.
  8. I created a block with it's own GUI. What the GUI dose is that creates an explosion based on number you input in the text box. Everything works on singleplayer, but on multiplayer, the server crashes when i click on the button Here's the method protected void actionPerformed(GuiButton button) { World world = null; WorldServer[] list = MinecraftServer.getServer().worldServers; // in console it says this line crashes for (WorldServer ins : list) { if (ins.provider.dimensionId == entity.worldObj.provider.dimensionId) world = ins; } if (world == null) world = list[0]; if (button.id == 0) { if (true) { if (power.getText().isEmpty()) power.setText(""); else if (power.getText().matches("[a-zA-Z]+")) power.setText(""); else if (power.getText().matches("[0-9]+")) { this.mc.displayGuiScreen((GuiScreen) null); world.createExplosion((Entity) null, i, j - 10, k, Integer.parseInt(power.getText().trim()), true); } else power.setText(""); } } }
  9. TileEntity package com.nuclearbanana.piecraft.saltex; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityFurnace; import org.lwjgl.opengl.GL11; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class TileEntitySaltExtractor extends TileEntity implements ISidedInventory { private static final int[] slotsTop = new int[] { 0 }; private static final int[] slotsBottom = new int[] { 2, 1 }; private static final int[] slotsSides = new int[] { 1 }; private ItemStack[] furnaceItemStacks = new ItemStack[3]; public int furnaceBurnTime; public int currentBurnTime; public int furnaceCookTime; private String furnaceName; public void furnaceName(String string){ this.furnaceName = string; } @Override public int getSizeInventory() { return this.furnaceItemStacks.length; } @Override public ItemStack getStackInSlot(int slot) { return this.furnaceItemStacks[slot]; } @Override public ItemStack decrStackSize(int par1, int par2) { if (this.furnaceItemStacks[par1] != null) { ItemStack itemstack; if (this.furnaceItemStacks[par1].stackSize <= par2) { itemstack = this.furnaceItemStacks[par1]; this.furnaceItemStacks[par1] = null; return itemstack; } else { itemstack = this.furnaceItemStacks[par1].splitStack(par2); if (this.furnaceItemStacks[par1].stackSize == 0) { this.furnaceItemStacks[par1] = null; } return itemstack; } } else { return null; } } @Override public ItemStack getStackInSlotOnClosing(int slot) { if (this.furnaceItemStacks[slot] != null) { ItemStack itemstack = this.furnaceItemStacks[slot]; this.furnaceItemStacks[slot] = null; return itemstack; } else { return null; } } @Override public void setInventorySlotContents(int slot, ItemStack itemstack) { this.furnaceItemStacks[slot] = itemstack; if (itemstack != null && itemstack.stackSize > this.getInventoryStackLimit()) { itemstack.stackSize = this.getInventoryStackLimit(); } } @Override public String getInventoryName() { return this.hasCustomInventoryName() ? this.furnaceName : "Salt Extractor"; } @Override public boolean hasCustomInventoryName() { return this.furnaceName != null && this.furnaceName.length() > 0; } @Override public int getInventoryStackLimit() { return 64; } public void readFromNBT(NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); NBTTagList tagList = tagCompound.getTagList("Items", 10); this.furnaceItemStacks = new ItemStack[this.getSizeInventory()]; for (int i = 0; i < tagList.tagCount(); ++i) { NBTTagCompound tabCompound1 = tagList.getCompoundTagAt(i); byte byte0 = tabCompound1.getByte("Slot"); if (byte0 >= 0 && byte0 < this.furnaceItemStacks.length) { this.furnaceItemStacks[byte0] = ItemStack.loadItemStackFromNBT(tabCompound1); } } this.furnaceBurnTime = tagCompound.getShort("BurnTime"); this.furnaceCookTime = tagCompound.getShort("CookTime"); this.currentBurnTime = getItemBurnTime(this.furnaceItemStacks[1]); if (tagCompound.hasKey("CustomName", ) { this.furnaceName = tagCompound.getString("CustomName"); } } public void writeToNBT(NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); tagCompound.setShort("BurnTime", (short) this.furnaceBurnTime); tagCompound.setShort("CookTime", (short) this.furnaceBurnTime); NBTTagList tagList = new NBTTagList(); for (int i = 0; i < this.furnaceItemStacks.length; ++i) { if (this.furnaceItemStacks[i] != null) { NBTTagCompound tagCompound1 = new NBTTagCompound(); tagCompound1.setByte("Slot", (byte) i); this.furnaceItemStacks[i].writeToNBT(tagCompound1); tagList.appendTag(tagCompound1); } } tagCompound.setTag("Items", tagList); if (this.hasCustomInventoryName()) { tagCompound.setString("CustomName", this.furnaceName); } } @SideOnly(Side.CLIENT) public int getCookProgressScaled(int par1) { return this.furnaceCookTime * par1 / 200; // How long will be infusing } @SideOnly(Side.CLIENT) public int getBurnTimeRemainingScaled(int par1) { if (this.currentBurnTime == 0) { this.currentBurnTime = 200; } return this.furnaceBurnTime * par1 / this.currentBurnTime; } public boolean isBurning() { return this.furnaceBurnTime > 0; } public void updateEntity() { boolean flag = this.furnaceBurnTime > 0; boolean flag1 = false; if (this.furnaceBurnTime > 0) { --this.furnaceBurnTime; } if (!this.worldObj.isRemote) { if (this.furnaceBurnTime == 0 && this.canSmelt()) { this.currentBurnTime = this.furnaceBurnTime = getItemBurnTime(this.furnaceItemStacks[1]); if (this.furnaceBurnTime > 0) { flag1 = true; if (this.furnaceItemStacks[1] != null) { --this.furnaceItemStacks[1].stackSize; if (this.furnaceItemStacks[1].stackSize == 0) { this.furnaceItemStacks[1] = furnaceItemStacks[1].getItem().getContainerItem(this.furnaceItemStacks[1]); } } } } if (this.isBurning() && this.canSmelt()) { ++this.furnaceCookTime; if (this.furnaceCookTime == 200) { // menjaj i ovaj broj! this.furnaceCookTime = 0; this.smeltItem(); flag1 = true; } } else { this.furnaceCookTime = 0; } } if (flag != this.furnaceBurnTime > 0) { flag1 = true; SaltExtractor.updateBlockState(this.furnaceBurnTime > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord); } if (flag1) { this.markDirty(); } } private boolean canSmelt() { if (this.furnaceItemStacks[0] == null) { return false; } else { ItemStack itemstack = SaltExtractorRecipes.make().getSmeltingResult(this.furnaceItemStacks[0]); if (itemstack == null) return false; if (this.furnaceItemStacks[2] == null) return true; if (!this.furnaceItemStacks[2].isItemEqual(itemstack)) return false; int result = furnaceItemStacks[2].stackSize + itemstack.stackSize; return result <= getInventoryStackLimit() && result <= this.furnaceItemStacks[2].getMaxStackSize(); } } public void smeltItem() { if (this.canSmelt()) { ItemStack itemstack = SaltExtractorRecipes.make().getSmeltingResult(this.furnaceItemStacks[0]); if (this.furnaceItemStacks[2] == null) { this.furnaceItemStacks[2] = itemstack.copy(); } else if (this.furnaceItemStacks[2].getItem() == itemstack.getItem()) { this.furnaceItemStacks[2].stackSize += itemstack.stackSize; } --this.furnaceItemStacks[0].stackSize; if(this.furnaceItemStacks[0].stackSize <= 0){ this.furnaceItemStacks[0] = null; } } } public static int getItemBurnTime(ItemStack itemstack){ if(itemstack == null){ return 0; }else{ Item item = itemstack.getItem(); /*if(item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.air){ Block block = Block.getBlockFromItem(item); if(block == Blocks.anvil) return 200; if(block.getMaterial() == Material.rock) return 300; }*/ if(item == Items.redstone) return 2000; /*if(item instanceof ItemTool && ((ItemTool) item).getToolMaterialName().equals("EMERALD")) return 300; */ return GameRegistry.getFuelValue(itemstack); } } public static boolean isItemFuel(ItemStack itemstack){ return getItemBurnTime(itemstack) > 0; } @Override public boolean isUseableByPlayer(EntityPlayer player) { return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : player.getDistanceSq((double) this.xCoord + 0.5D, (double) this.yCoord + 0.5D, (double) this.zCoord + 0.5D) <= 64.0D; } @Override public void openInventory() { } @Override public void closeInventory() { } @Override public boolean isItemValidForSlot(int par1, ItemStack itemstack) { return par1 == 2 ? false : (par1 == 1 ? isItemFuel(itemstack) : true); } @Override public int[] getAccessibleSlotsFromSide(int par1) { return par1 == 0 ? slotsBottom : (par1 == 1 ? slotsTop : slotsSides); } @Override public boolean canInsertItem(int par1, ItemStack itemstack, int par3) { return this.isItemValidForSlot(par1, itemstack); } @Override public boolean canExtractItem(int par1, ItemStack itemstack, int par3) { return par3 != 0 || par1 != 1 || itemstack.getItem() == Items.bucket; } //@Override /*public void renderTileEntityAt(TileEntity entity, double x, double y, double z, float f) { GL11.glPushMatrix(); ItemStack stack = new ItemStack(Items.iron_ingot, 1, 0); EntityItem entItem = new EntityItem(Minecraft.getMinecraft().thePlayer.getEntityWorld(), 0D, 0D, 0D, stack); //Without the below line, the item will spazz out entItem.hoverStart = 0.0F; RenderItem.renderInFrame = true; //Add the below line (without //'s) to make the item lie flat on the block GL11.glRotatef(180, 0, 1, 1); //Change the 0D's to different values to move it around RenderManager.instance.renderEntityWithPosYaw(entItem, 1.0D, 1.0D, 1.0D, 1.0F, 1.0F); RenderItem.renderInFrame = false; GL11.glPopMatrix(); }*/ } RecipeHandler package com.nuclearbanana.piecraft.saltex; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import com.nuclearbanana.piecraft.PieCraft; import net.minecraft.block.Block; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemFishFood; import net.minecraft.item.ItemStack; public class SaltExtractorRecipes { private static final SaltExtractorRecipes smeltingBase = new SaltExtractorRecipes(); /** * The list of smelting results. */ private Map smeltingList = new HashMap(); private Map experienceList = new HashMap(); /** * Used to call methods addSmelting and getSmeltingResult. */ public static SaltExtractorRecipes make() { return smeltingBase; } private SaltExtractorRecipes() { this.infuseItem(Items.water_bucket, new ItemStack(PieCraft.Salt), 0.7F); } public void infuseBlock(Block block, ItemStack is, float xp) { this.infuseItem(Item.getItemFromBlock(block), is, xp); } public void infuseItem(Item p_151396_1_, ItemStack p_151396_2_, float p_151396_3_) { this.InfuseItemStack(new ItemStack(p_151396_1_, 1, 32767), p_151396_2_, p_151396_3_); } public void InfuseItemStack(ItemStack p_151394_1_, ItemStack p_151394_2_, float p_151394_3_) { this.smeltingList.put(p_151394_1_, p_151394_2_); this.experienceList.put(p_151394_2_, Float.valueOf(p_151394_3_)); } /** * Returns the smelting result of an item. */ public ItemStack getSmeltingResult(ItemStack p_151395_1_) { Iterator iterator = this.smeltingList.entrySet().iterator(); Entry entry; do { if (!iterator.hasNext()) { return null; } entry = (Entry)iterator.next(); } while (!this.func_151397_a(p_151395_1_, (ItemStack)entry.getKey())); return (ItemStack)entry.getValue(); } private boolean func_151397_a(ItemStack p_151397_1_, ItemStack p_151397_2_) { return p_151397_2_.getItem() == p_151397_1_.getItem() && (p_151397_2_.getItemDamage() == 32767 || p_151397_2_.getItemDamage() == p_151397_1_.getItemDamage()); } public Map getSmeltingList() { return this.smeltingList; } public float func_151398_b(ItemStack p_151398_1_) { float ret = p_151398_1_.getItem().getSmeltingExperience(p_151398_1_); if (ret != -1) return ret; Iterator iterator = this.experienceList.entrySet().iterator(); Entry entry; do { if (!iterator.hasNext()) { return 0.0F; } entry = (Entry)iterator.next(); } while (!this.func_151397_a(p_151398_1_, (ItemStack)entry.getKey())); return ((Float)entry.getValue()).floatValue(); } } GuiHandler package com.nuclearbanana.piecraft.saltex; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; import cpw.mods.fml.common.network.IGuiHandler; public class PieGuiHandler implements IGuiHandler { public PieGuiHandler (){ } @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if(ID == 0){ TileEntitySaltExtractor tileEntityFurnace = (TileEntitySaltExtractor) world.getTileEntity(x, y, z); return new ContainerSaltExtractor(player.inventory, tileEntityFurnace); } return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if(ID == 0){ TileEntitySaltExtractor tileEntityTestContainer = (TileEntitySaltExtractor) world.getTileEntity(x, y, z); return new GuiSaltExtractor(player.inventory, tileEntityTestContainer); } return null; } } Hope anyone can help
  10. First (assuming you created your item) you need to make the ItemStack of your item. Do this code start registerItem(yourItem, "Your item"); //<--- normal thing ItemStack yourItemStack= new ItemStack(YourMainClass.yourItem); //making an ItemStack yourItemStack.addEnchantment(Enchantment.protection, 3); // adding enchantments. Do what ever you like yourItemStack.addEnchantment(Enchantment.unbreaking, 2); GameRegistry.addRecipe(yourItemStack, new Object[] { "###", '#', Blocks.dirt}); //adding a recipe. So when your item is crafted, it will have enchantments on it code end I hope this helps
  11. Hello all! I made a new furnace recently. That's all working fine, everything. I added the custom smelt recipe, the fuel is gold chunk. If you place a water bucket and 'smelt' it, it will take out the bucket as well. It should take the water bucket and give back the bucket. Any solutions? Please respond
×
×
  • Create New...

Important Information

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