Jump to content

IvanTune

Members
  • Posts

    29
  • Joined

  • Last visited

Converted

  • Gender
    Undisclosed
  • Personal Text
    I am new!

IvanTune's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Oooooooohhhhhh! Now it works perfectly, thanks ernio <3
  2. Hi there! So I want to save NBT to my solar panel when its broken and placed again. What the code below does is it works when I break and place the solarpanel in the same place, but if I place the solar panel somewhere else it places a solar panel with no Gui or data. Any help is much appriciated. BlockSolarPanel @Override public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) { TileEntitySolarPanel te = (TileEntitySolarPanel) world.getTileEntity(x, y, z); if (te instanceof TileEntitySolarPanel && stack.getTagCompound() != null) { te.readFromNBT(stack.getTagCompound()); } } @Override public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) { ArrayList<ItemStack> ret = new ArrayList<ItemStack>(); ItemStack stack = new ItemStack(world.getBlock(x, y, z), 1, metadata); TileEntitySolarPanel te = (TileEntitySolarPanel) world.getTileEntity(x, y, z); if (te instanceof TileEntitySolarPanel) { NBTTagCompound tag = new NBTTagCompound(); ((TileEntitySolarPanel)te).writeToNBT(tag); if (!stack.hasTagCompound()) { stack.setTagCompound(tag); } ret.add(stack); } return ret; } @Override public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest) { if (willHarvest) { return true; // If it will harvest, delay deletion of the block // until after getDrops } return super.removedByPlayer(world, player, x, y, z, willHarvest); } @Override public void harvestBlock(World world, EntityPlayer player, int x, int y, int z, int meta) { super.harvestBlock(world, player, x, y, z, meta); world.setBlockToAir(x, y, z); }
  3. Hello there! 1. So been having a lot of trouble with tileentity syncing and packets. The first thing i I am trying to do is send the RF storage from the server to the client so that the player can see in the GUI what the storage is at. It works fine on a SP world, but when I tried on a server the RF would go up to 32k, then reset itself and stay at 0, then go up to 32k and reset itself again in the gui. TileEntitySolarPanel public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); storage.writeToNBT(nbt); } public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); storage.readFromNBT(nbt); } public void updateEntity() { if (!worldObj.isRemote) { if(storage.getEnergyStored() < storage.getMaxEnergyStored()) { int i = storage.getEnergyStored() + currentRfgeneration; storage.setEnergyStored(i); } } } ContainerSolarPanel private TileEntitySolarPanel solarPanel; int lastEnergyStored; @Override public void addCraftingToCrafters(ICrafting icrafting) { super.addCraftingToCrafters(icrafting); icrafting.sendProgressBarUpdate(this, 0, this.solarPanel.getEnergyStored()); } public void detectAndSendChanges() { super.detectAndSendChanges(); for (int i = 0; i < this.crafters.size(); i++) { ICrafting icrafting = (ICrafting) this.crafters.get(i); if (this.lastEnergyStored != this.solarPanel.getEnergyStored()) { icrafting.sendProgressBarUpdate(this, 0, this.solarPanel.getEnergyStored()); } } this.lastEnergyStored = this.solarPanel.getEnergyStored(); } @SideOnly(Side.CLIENT) @Override public void updateProgressBar(int slot, int newValue) { if (slot == 0) { this.solarPanel.setEnergyStored(newValue); } } 2. Also when a player does changes to stuff in GUI (ints), i want these to be sent to the server. I'm not quite sure if I am doing packets right and I am not sure what to put in the OnMessage so that the int is sent right. I also want the int to be sent back to the client so that other people can see it, is it ok to just do it through the container? MessageGuiSolarTab1Height package com.EvanTune.futuregate.network; import com.EvanTune.futuregate.block.machine.solar_panel.tab.TestTab; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; import io.netty.buffer.ByteBuf; public class MessageGuiSolarTab1Height implements IMessage, IMessageHandler<MessageGuiSolarTab1Height, IMessage> { private int tabHeight; public MessageGuiSolarTab1Height() {} public MessageGuiSolarTab1Height(int value) { this.tabHeight = value; } @Override public void toBytes(ByteBuf buffer) { buffer.writeInt(tabHeight); } @Override public void fromBytes(ByteBuf buffer) { this.tabHeight = buffer.readInt(); } @Override public IMessage onMessage(MessageGuiSolarTab1Height message, MessageContext ctx) { TestTab heighty = new TestTab(tabHeight); heighty.tempHeightSetting = message.tabHeight; return null; } } NetworkHandler package com.EvanTune.futuregate.network; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper; import cpw.mods.fml.relauncher.Side; public class NetworkHandler { public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(Reference.CHANNEL); private static int id = 0; public static void init() { INSTANCE.registerMessage(MessageGuiSolarTab1Height.class, MessageGuiSolarTab1Height.class, id++, Side.SERVER); } } TestTab @Override public void mouseReleased(GuiSolarPanel gui, int x, int y, int button) { NetworkHandler.INSTANCE.sendToServer(new MessageGuiSolarTab1Height(tempHeightSetting)); isDragging = false; } Thanks in advance for any help or tips!
  4. Thanks for replies! So I am using GuiContainer for the gui and forge version 1517 for 1.7.10. Also a bit confused because I don't see MouseInputEvent in the GuiScreenEvent. Any idea what I could do for GuiContainer? Just need it to detect that someone is scrolling then fire some code and work in gui.
  5. Hello folks! So I am making scrollable windows in my gui and I want to use the scrollwheel on mouse to move them up and down. Everything works fine when gui is not open, but with gui open the MouseEvent does not fire for some reason. Any help on how to solve it is much appriciated. Thanks!
  6. Hello! So I added tooltips to my gui so when a player hovers over a bar it displays sun intesity on solar panel. This all works fine, but what if I also want the texture to change on that area when player hovers mouse there. What I did below works when mouse is hovered over, but if I pick up 1 of an item then the texture goes white. If I pick up 64 or 12 of an item then everything works, but this only happens when 1 item is picked up. Here is what happens: Any help is appriciated. public void drawScreen(int x, int y, float f) { super.drawScreen(x, y, f); this.drawToolTipsSunIntensity(x, y); } public void drawToolTipsSunIntensity(int mouseX, int mouseY) { int boxX = (this.width - this.xSize) / 2 + 28; int boxY = (this.height - this.ySize) / 2 + 6; int defaultX = 19; int defaultY = 48; if(mouseX > boxX && mouseX < boxX + defaultX && mouseY > boxY && mouseY < boxY + defaultY) { List list = new ArrayList(); int currentPower = solarPanel.getSunIntensityPercent(); int rf = solarPanel.getCurrentRfgeneration(); list.add("\u00a7eSun Intensity:"); list.add(currentPower + "%"); Minecraft.getMinecraft().getTextureManager().bindTexture(texture); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glDisable(2896); drawTexturedModalRect(guiLeft + 29, guiTop + 7, 194, 62, 18, 47); GuiScreen.drawRect(20, 22, 22, 22, 22); this.drawHoveringText(list, mouseX, mouseY, fontRendererObj); } else{ Minecraft.getMinecraft().getTextureManager().bindTexture(texture); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glDisable(2896); drawTexturedModalRect(guiLeft + 29, guiTop + 7, 176, 62, 18, 47); } }
  7. Hello! So I made a solar panel that is supposed to send RF out of its storage and into blocks that wants to receive. I made the panel start generating energy if sun is up, but why is it it not sending the storage into other blocks like a Leadstone Energy Cell etc? I saved storage to NBT and tile is implementing IEnergyProvider. Any help and/or tips are very much appriciated! TileSolarPanel: // RF Stuff public EnergyStorage storage; public static int CAPACITY = 100000; public static int MAX_RECEIVE = 0; public static int MAX_EXTRACT = 512; public TileEntitySolarPanel(){ storage = new EnergyStorage(CAPACITY, MAX_RECEIVE, MAX_EXTRACT); } @Override public boolean canConnectEnergy(ForgeDirection from) { return true; } @Override public int getEnergyStored(ForgeDirection from){ return storage.getEnergyStored(); } public int getEnergyStored(){ return storage.getEnergyStored(); } @Override public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) { return storage.extractEnergy(maxExtract, simulate); } public int getMaxEnergyStored(){ return storage.getMaxEnergyStored(); } @Override public int getMaxEnergyStored(ForgeDirection from){ return storage.getMaxEnergyStored(); }
  8. Really appricate the answers diesieben07. You mean something like this? @Override public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) { ArrayList<ItemStack> ret = new ArrayList<ItemStack>(); ItemStack stack = new ItemStack(world.getBlock(x, y, z), 1, metadata); TileEntityRedstoneMacerator te = (TileEntityRedstoneMacerator)world.getTileEntity(x, y, z); int i = te.cookTime; if (te instanceof TileEntityRedstoneMacerator){ if (!stack.hasTagCompound()) { stack.setTagCompound(new NBTTagCompound()); } stack.getTagCompound().setInteger("CookTime", i); ret.add(stack); } return ret; }
  9. I am probably missing something, but I thought the ret.add was adding my block to the itemstack, then adding the data to the block and returning the itemstack as a drop with the data. @Override public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) { ArrayList<ItemStack> ret = new ArrayList<ItemStack>(); TileEntityRedstoneMacerator te = (TileEntityRedstoneMacerator)world.getTileEntity(x, y, z); if (te instanceof TileEntityRedstoneMacerator) ret.add(new ItemStack(ModBlocks.blockRedstoneMaceratorIdle, 1, te.getEnergyStored())); return ret; }
  10. Do you mean changing it to ArrayList<ItemStack> ret = new ArrayList<ItemStack>();? I tried that also but when I break the block and pick it back up again it goes back into the same stack it was in. I also tried adding other data into it but it didn't go into its own stack when picked up. Like when I try to add te.cookTime() same thing happens. Does the data need to be done in a special way in the tileentity in order to be stored? For cooktime all I did was make the int, store it in NBT, then change its value depending on what machine was doing. nbt.setShort("CookTime", (short) this.cookTime); this.cookTime = (int) nbt.getShort("CookTime");
  11. Since I was getting 2 items I set the getItemDropped to null, and this is code so far, is it now storing the data in the block that gets dropped? The te.getEnergyStored() is returning the internal storage the tileentity has. @Override public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) { ArrayList<ItemStack> ret = super.getDrops(world, x, y, z, metadata, fortune); TileEntityRedstoneMacerator te = (TileEntityRedstoneMacerator)world.getTileEntity(x, y, z); if (te != null && te instanceof TileEntityRedstoneMacerator) ret.add(new ItemStack(ModBlocks.blockRedstoneMaceratorIdle, 1, te.getEnergyStored())); return ret; } @Override public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest) { if (willHarvest){ return true; //If it will harvest, delay deletion of the block until after getDrops } return super.removedByPlayer(world, player, x, y, z, willHarvest); } @Override public void harvestBlock(World world, EntityPlayer player, int x, int y, int z, int meta) { super.harvestBlock(world, player, x, y, z, meta); world.setBlockToAir(x, y, z); }
  12. Thanks for the reply, and yes the data is stored in a tileentity. I had a look at the getDrops method (which I assume is the only one I need from the BlockFlowerPot class?), and this is what I got from it. It does drop an extra block when broken, but did it apply the data to the dropped block like this? @Override public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) { ArrayList<ItemStack> ret = super.getDrops(world, x, y, z, metadata, fortune); TileEntityRedstoneMacerator te = (TileEntityRedstoneMacerator)world.getTileEntity(x, y, z); if (te != null && te instanceof TileEntityRedstoneMacerator) ret.add(new ItemStack(ModBlocks.blockRedstoneMaceratorIdle, 1, te.getEnergyStored())); return ret; }
  13. Hello! I was wondering how you would go about allowing an int value to be saved to a specific block, so when a player breaks the block and places it again the block contains the storage (rf) it had before (and this block can now not be stacked any more with the same blocks). I have saved the rf storage to NBT, and logging out and in again works fine, but I am not sure how to save the storage to an instanced block. Thanks.
  14. That is precisely what's happening. It's called z-fighting. Most mods avoid this problem by not using vanilla blocks in their structures. Your best bet is to create an invisible (but solid) block that replaces the redstone (or whatever) so that the original block doesn't render. But when broken, it drops the original and kills the multiblock. Thanks for the help to all of you, appriciate it. So the code below is what I got so far, it's a complete mess. I want to have a multiblock that I can set to any size with different blocks everywhere, but checking that will require thousands of if statements. So how I understand it is if isMultiBlock is true set the blocks to their invisible state. But then it has to know which of the blocks the player breaks and set the invisible blocks back to the solid textured ones. Also if the player breaks the main block, how do you then set the blocks from invisible to solid textured? BreakEvents? I just started school learning java so that and some tips here will hopefully get me where I want. Edit: A friend told me about an api called beefcore for making multiblocks, might try it: https://github.com/erogenousbeef/BeefCore public boolean isMultiBlockStructure(World world, int x, int y, int z) { if (checkMulti(world, x, y, z)){ world.setBlock(x + 1, y + 0, z + 0, ModBlocks.blockInvBedrock); world.setBlock(x + 2, y + 0, z + 0, ModBlocks.blockInvCoal); world.setBlock(x + 3, y + 0, z + 0, ModBlocks.blockInvDiamond); world.setBlock(x + 4, y + 0, z + 0, ModBlocks.blockInvGravel); world.setBlock(x + 5, y + 0, z + 0, ModBlocks.blockInvMelon); /* North */ return true; } if (checkIfMelonIsAir(world, x, y, z)){ world.setBlock(x + 1, y + 0, z + 0, Blocks.bedrock); world.setBlock(x + 2, y + 0, z + 0, Blocks.coal_block); world.setBlock(x + 3, y + 0, z + 0, Blocks.diamond_block); world.setBlock(x + 4, y + 0, z + 0, Blocks.gravel); // world.setBlock(x + 5, y + 0, z + 0, Blocks.melon_block); /* North */ return true; } if (checkIfGravelIsAir(world, x, y, z)){ world.setBlock(x + 1, y + 0, z + 0, Blocks.bedrock); world.setBlock(x + 2, y + 0, z + 0, Blocks.coal_block); world.setBlock(x + 3, y + 0, z + 0, Blocks.diamond_block); // world.setBlock(x + 4, y + 0, z + 0, Blocks.gravel); world.setBlock(x + 5, y + 0, z + 0, Blocks.melon_block); /* North */ return true; } if (checkIfDiamondIsAir(world, x, y, z)){ world.setBlock(x + 1, y + 0, z + 0, Blocks.bedrock); world.setBlock(x + 2, y + 0, z + 0, Blocks.coal_block); // world.setBlock(x + 3, y + 0, z + 0, Blocks.diamond_block); world.setBlock(x + 4, y + 0, z + 0, Blocks.gravel); world.setBlock(x + 5, y + 0, z + 0, Blocks.melon_block); /* North */ return true; } if (checkIfCoalIsAir(world, x, y, z)){ world.setBlock(x + 1, y + 0, z + 0, Blocks.bedrock); // world.setBlock(x + 2, y + 0, z + 0, Blocks.coal_block); world.setBlock(x + 3, y + 0, z + 0, Blocks.diamond_block); world.setBlock(x + 4, y + 0, z + 0, Blocks.gravel); world.setBlock(x + 5, y + 0, z + 0, Blocks.melon_block); /* North */ return true; } if (checkIfBedrockIsAir(world, x, y, z)){ // world.setBlock(x + 1, y + 0, z + 0, Blocks.bedrock); world.setBlock(x + 2, y + 0, z + 0, Blocks.coal_block); world.setBlock(x + 3, y + 0, z + 0, Blocks.diamond_block); world.setBlock(x + 4, y + 0, z + 0, Blocks.gravel); world.setBlock(x + 5, y + 0, z + 0, Blocks.melon_block); /* North */ return true; } return false; } private static boolean checkMulti(World world, int x, int y, int z) { if (world.getBlock(x + 1, y + 0, z + 0) == Blocks.bedrock || world.getBlock(x + 1, y + 0, z + 0) == ModBlocks.blockInvBedrock){ if (world.getBlock(x + 2, y + 0, z + 0) == Blocks.coal_block || world.getBlock(x + 2, y + 0, z + 0) == ModBlocks.blockInvCoal) { if (world.getBlock(x + 3, y + 0, z + 0) == Blocks.diamond_block || world.getBlock(x + 3, y + 0, z + 0) == ModBlocks.blockInvDiamond) { if (world.getBlock(x + 4, y + 0, z + 0) == Blocks.gravel || world.getBlock(x + 4, y + 0, z + 0) == ModBlocks.blockInvGravel) { if (world.getBlock(x + 5, y + 0, z + 0) == Blocks.melon_block || world.getBlock(x + 5, y + 0, z + 0) == ModBlocks.blockInvMelon) { return true; } } } } } return false; } private static boolean checkIfMelonIsAir(World world, int x, int y, int z) { if (world.getBlock(x + 1, y + 0, z + 0) == ModBlocks.blockInvBedock){ if (world.getBlock(x + 2, y + 0, z + 0) == ModBlocks.blockInvCoal) { if (world.getBlock(x + 3, y + 0, z + 0) == ModBlocks.blockInvDiamond) { if (world.getBlock(x + 4, y + 0, z + 0) == ModBlocks.blockInvGravel) { if (world.getBlock(x + 5, y + 0, z + 0) == Blocks.air) { return true; } } } } } return false; } private static boolean checkIfGravelIsAir(World world, int x, int y, int z) { if (world.getBlock(x + 1, y + 0, z + 0) == ModBlocks.blockInvBedrock){ if (world.getBlock(x + 2, y + 0, z + 0) == ModBlocks.blockInvCoal) { if (world.getBlock(x + 3, y + 0, z + 0) == ModBlocks.blockInvDiamond) { if (world.getBlock(x + 4, y + 0, z + 0) == Blocks.air) { if (world.getBlock(x + 5, y + 0, z + 0) == ModBlocks.blockInvMelon) { return true; } } } } } return false; } private static boolean checkIfDiamondIsAir(World world, int x, int y, int z) { if (world.getBlock(x + 1, y + 0, z + 0) == ModBlocks.blockInvbedrock){ if (world.getBlock(x + 2, y + 0, z + 0) == ModBlocks.blockInvCoal) { if (world.getBlock(x + 3, y + 0, z + 0) == Blocks.air) { if (world.getBlock(x + 4, y + 0, z + 0) == ModBlocks.blockInvGravel) { if (world.getBlock(x + 5, y + 0, z + 0) == ModBlocks.blockInvMelon) { return true; } } } } } return false; } private static boolean checkIfCoalIsAir(World world, int x, int y, int z) { if (world.getBlock(x + 1, y + 0, z + 0) == ModBlocks.blockInvbedrock){ if (world.getBlock(x + 2, y + 0, z + 0) == Blocks.air) { if (world.getBlock(x + 3, y + 0, z + 0) == ModBlocks.blockInvDiamond) { if (world.getBlock(x + 4, y + 0, z + 0) == ModBlocks.blockInvGravel) { if (world.getBlock(x + 5, y + 0, z + 0) == ModBlocks.blockInvMelon) { return true; } } } } } return false; } private static boolean checkIfBedrockIsAir(World world, int x, int y, int z) { if (world.getBlock(x + 1, y + 0, z + 0) == Blocks.air){ if (world.getBlock(x + 2, y + 0, z + 0) == ModBlocks.blockInvCoal) { if (world.getBlock(x + 3, y + 0, z + 0) == ModBlocks.blockInvDiamond) { if (world.getBlock(x + 4, y + 0, z + 0) == ModBlocks.blockInvGravel) { if (world.getBlock(x + 5, y + 0, z + 0) == ModBlocks.blockInvMelon) { return true; } } } } } return false; }
×
×
  • Create New...

Important Information

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