Jump to content

brandon3055

Forge Modder
  • Posts

    444
  • Joined

  • Last visited

Everything posted by brandon3055

  1. just had to use the event to get the player instead of Minecraft.getMinecraft().theWorld turns out the the packet handler was working all along i just wasnt using it properly lol
  2. IT WORKED!!! You guys are Awesome Thank you!
  3. ok i will give that a try i assume i can send along the event to the processPacketOnServerSide method?
  4. If you look closer i have the test block set up to send both ways if the player right clicks it it sends a packet from the server to the client but if the player shift-right clicks it it sends a packet from the client to the server.
  5. Ok so maby it is actually working properly but im just not using it properly. The following is my code for receiving a gui button packet. World theWorld = Minecraft.getMinecraft().theWorld; switch (packetTypeID) { case packetTypeIDButton: { byte buttonId = bbis.readByte(); int playerId = bbis.readInt(); EntityPlayer player = (EntityPlayer) theWorld.getEntityByID(playerId); Container container = player.openContainer; if (container != null && container instanceof ContainerWeatherController){ TileWeatherController tileWC = ((ContainerWeatherController) container).getTileWC(); tileWC.reciveButtonEvent(buttonId); } break; } } (the complete code is in my original post) so if "theWorld" only exists on the client side then the tile i eventially get from it must also only be on the client side. So how can i get the tile on the server side? Edit: you just beat me! I am currently sending the entityId of the player and using theWorld.getEntityById() which obviously isnt working so how else can i do it?
  6. ok but i still know the packet isnt getting to the server because i was originally trying to use it to send a button packet from a gui to a tile but the tile was only reviving the packet on the client side. Edit: Oh i am also using Minecraft.getMinecraft().theWorld my processPacketOnServerSide method to get the player which i use to get the container which i use to get the tile...
  7. Thanks but i am already very familiar with the system i have set up now so i will wait for jabelar to reply. Buy if i cant get my current system working i will definitely look into yours. Edit: I am now more confused then ever... I noticed it seemed like two packets were being received by the server packet handler (on the client side) so i disabled the server packet handler (by not registering it) but the onServerPacket method in the server packet handler is still being called its as if i have registered a second server packet handler somewhere.
  8. use Item.getItemFromBlock(Blocks.cobblestone);
  9. you have to override quantityDropped e.g. @Override public int quantityDropped(final Random random) { return 4; }
  10. Remove the "TileEntityKeyPad." that if im not mistaken is setting the default value fore the TileEntityKeyPad class.
  11. I setup my packet handling using a setup suggested to me by jabelar in this thread http://www.minecraftforge.net/forum/index.php/topic,18804.0.html I really like this setup because its simple and easy to use but I have a problem that I just cant figure out. It works perfectly when sending packets from the server to the client but I cant get it to work the other way (sending packets from the client to the server) This is my setup. Server Packet handler: Client Packet handler: Packet: Common Proxy: (this is where the Server packet handler is registered (removed unrelated code)) Client Proxy: (this is where the Client packet handler is registered (removed unrelated code)) Test code: (I made a basic block and used its "onBlockActivated" method to test the packet handler) After a lot of debugging I think i have tracked down where things go wrong. From what i understand the "onServerPacker" method is suposed to be called on the server side when the server receives a a packet. But unless "World world = Minecraft.getMinecraft().theWorld;" dosnt work properly in this method "onServerPacket" is being called Client side instead of server side So the packet is being sent from, received and processed all on the client side and never actually reaches the server. @jabelar From what I could tell from your posts in the other thread you havent started using this system to send data to the server yet. So have you tested it it works both ways?
  12. I am such a noob. Take a look at this method @Override public ItemStack decrStackSize(int i, int count) { ItemStack itemstack = getStackInSlot(i); if (itemstack != null) { if (itemstack.stackSize <= count) { setInventorySlotContents(i, null); } else { itemstack.splitStack(count); if (itemstack.stackSize == 0) { setInventorySlotContents(i, null); } } } return itemstack; } Notice anything? itemstack.splitStack(count); should be itemstack = itemstack.splitStack(count); I must have checked that code half a dozen times before i made this post lol But thanks for letting me know about ISidedInventory i that will come in handy in the future but unless i am mistaken it isn't required for this application.
  13. You can simply put the markBlockForUpdate() method at the end of the onDataPacket() method that way it will run after the client receives and processes the packet. @Override public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { readFromNBT(pkt.func_148857_g()); worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); }
  14. I made my inventory based on a 1.6.4 tutorial but im guessing something changed in 1.7.2. The problem i am having is hopper interaction. it works fine when putting items in but when i try to remove items with a hopper it acts very weird. If there is a full stack in the inventory ()the inventory only holds one stack) it will take 5 items from the inventory and will the hopper. It seems like it is each stack the hopper pulls out is the size of the stack in the inventory so if there is 50 items in the inventory and i place a hopper under it the hopper will pull 5 items and each slot in the hopper will receive 50 of the item in the inventory it will then pull 5 more items to fill each slot to 64. This is my tile and all related classes i would really appreciate some help with this because i'm completely lost. tile class Container class Gui class Custome slot Block class Edit: Its a bit hard to explain exactly what its doing so i recorded what is happening. [embed=425,349]http://youtu.be/96MH1Luw0NU[/embed]
  15. @diesieben07 i would have tryed that after my first attempt failed
  16. I still have a lot to learn so i am sure there is an easier way but with what i know now this is how i would do it. create two identical blocks one that emits light and one that dosn't. in the randomDisplayTick() use world.getWorldTime(); in the block that dosnt emmit light if it is night use world.setBlock("light emitting version") in the block that dose emit light if it is day use world.setBlock("non light emitting version") This should work but im sure there is a better way out there Note to get the "actual time" use double days = world.getWorldTime() / 24000; int time = (int)(world.getWorldTime() - days * 24000);
  17. IIcons is how you register textures in 1.7.2 (there may be other ways) you first need to register your icons (textures) using registerBlockIcons() to register an icon use icon = iconRegister.registerIcon("modid:/texture name"); // this will look for "texture name" in modid:/textures/blocks then you override getIcon(int side, int meta) to add the icon to the block this allows you to do things like set different textures for different sides or meta data. in this case i am also using getIcon(IBlockAccess block, int x, int y, int z, int side) this is basically the same thing except it gives more data to work with but it cant texture a block item Note: some of this info may not be correct/compleat because i am only just learning to modd myself. Edit: Thank you diesieben07! there is still so much i have to learn ok so you dont need getIcon(IBlockAccess block, int x, int y, int z, int side) you can just use @Override @SideOnly(Side.CLIENT) public IIcon getIcon(int side, int meta) { int dim = Minecraft.getMinecraft().theWorld.provider.dimensionId; if (dim == -1) return iconNether; else if (dim == 0) return iconOverworld; } let me know if you still need help.
  18. I used separate blocks for different dimentions but now that i think about it it would make sense to just use one block and re texture it depending on dimension. So I played around with my ore and unfortunately i wasn't able to figure out how to get the dimention id when getting the icon BUT i was able to figure out how to set the texture depending on the biome. so with your ore you could just set it up so that if biome == "Hell" it uses the nether texture else it uses the overworld texture. Keep in mind this method isnt ideal because if another mod e.g. Natura adds new biomes to the nether you will get the overworld texture in those biomes. Edit: and before you ask it is still necessary to use getIcon(int side, int meta) because getIcon(IBlockAccess block, int x, int y, int z, int side) adds the texture to the block in world but it cant add a texture to the item (the block in your inventory).
  19. Ok im calling this one solved! I ended up going with larsgerrits suggestion because it was simple and its designed for this exact application although it did take a bit to figure out because it seems to have changed a little in 1.7.2 For anyone else having the same problem. @Override public Packet getDescriptionPacket() { //Debug System.out.println("[DEBUG]:Server sent tile sync packet"); NBTTagCompound tagCompound = new NBTTagCompound(); this.writeToNBT(tagCompound); return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, tagCompound); } @Override public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { //Debug System.out.println("[DEBUG]:Client recived tile sync packet"); readFromNBT(pkt.func_148857_g()); worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); } @jabelar I will still be using your packet handler because the next thing on my list is adding buttons to the gui which requires a packet handler. If i have any more problems figuring it out i will pm you (if that's ok with you?) but i think i have it figured out.
  20. ok now i understand. If you look at my earlier post that is how ALL of the tutorials i have seen so far have set up the proxys. I have never seen anyone add the FMLPreInit/Init/PostInit events to their proxys. After i get some sleep i will try setting up my proxys like yours and will let you know how i go. I will also have to look into what larsgerrits said and see if i can figure that out.
  21. You can do this by overriding the onBlockStartBreak() method in your pick class this is called just before the block breaks. There is a bit involved in getting it to work properly but instead of trying to explain it and completely confusing you (im not good at explaining things) i have put together an example pick class that will dig a 3x3x3 area around the block you mine. Hopefully you will be able to figure out how it works and modify it to suit your needs. You shouldnt have any trouble getting this class to work all you have to do is rename the package and add it in your main class preinit method (or wherever you add your items) using testPick = new TestPick(); It will be in the creative tools tab and it will have the diamond pick texture. package tolkienaddon.items.tools; import java.util.ArrayList; import java.util.List; import org.lwjgl.input.Keyboard; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.EnumRarity; import net.minecraft.item.Item; import net.minecraft.item.ItemPickaxe; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IIcon; import net.minecraft.world.World; import net.minecraft.world.WorldSettings.GameType; import tolkienaddon.Tolkienaddon; import tolkienaddon.items.ModItems; import tolkienaddon.lib.References; import tolkienaddon.lib.Strings; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class TestPick extends ItemPickaxe { public static Material[] materialsPick = { Material.anvil, Material.circuits, Material.coral, Material.glass, Material.ice, Material.iron, Material.rock }; public TestPick() { super(ToolMaterial.EMERALD); this.setUnlocalizedName("testPick"); this.setCreativeTab(CreativeTabs.tabTools); GameRegistry.registerItem(this, "testPick"); } @Override @SideOnly(Side.CLIENT) public void registerIcons(final IIconRegister iconRegister) { this.itemIcon = iconRegister.registerIcon("minecraft:diamond_pickaxe"); } @Override @SideOnly(Side.CLIENT) public IIcon getIconFromDamage(int par1) { return itemIcon; } @Override public boolean onBlockStartBreak(final ItemStack stack, final int x, final int y, final int z, final EntityPlayer player) { World world = player.worldObj; int fortune = EnchantmentHelper.getFortuneModifier(player); boolean silk = EnchantmentHelper.getSilkTouchModifier(player); disSquare(x, y, z, player, world, silk, fortune, stack); return true; } public static void disSquare(int x, int y, int z, final EntityPlayer player, final World world, final boolean silk, final int fortune, ItemStack stack) { int sizeX = 1; int sizeY = 1; int sizeZ = 1; for (int x1 = x - sizeX; x1 <= x + sizeX; x1++) { for (int y1 = y - sizeY; y1 <= y + sizeY; y1++) { for (int z1 = z - sizeZ; z1 <= z + sizeZ; z1++) { mineBlock(x1, y1, z1, player, world, silk, fortune, stack); } } } } @SuppressWarnings({ "rawtypes", "unchecked" }) public static void mineBlock(int x, int y, int z, EntityPlayer player, World world, boolean silk, int fortune, ItemStack stack) { Block block = world.getBlock(x, y, z); int meta = world.getBlockMetadata(x, y, z); Material mat = block.getMaterial(); if ((block != null) && (!block.isAir(world, x, y, z)) && (block.getPlayerRelativeBlockHardness(player, world, x, y, z) != 0.0F)) { List<ItemStack> items = new ArrayList(); if ((!block.canHarvestBlock(player, meta)) || (!isRightMaterial(mat, materialsPick))) { return; } if ((silk) && (block.canSilkHarvest(world, player, x, y, z, meta))) { if (block == Blocks.lit_redstone_ore) items.add(new ItemStack(Item.getItemFromBlock(Blocks.redstone_ore))); else items.add(new ItemStack(block.getItem(world, x, y, z), 1, meta)); } else { items.addAll(block.getDrops(world, x, y, z, meta, fortune)); block.dropXpOnBlockBreak(world, x, y, z, block.getExpDrop(world, meta, fortune)); } world.setBlockToAir(x, y, z); if (!world.isRemote) { for (final ItemStack item : items) { world.spawnEntityInWorld(new EntityItem(world, player.posX, player.posY, player.posZ, item)); } } } } public static boolean isRightMaterial(final Material material, final Material[] materialsListing) { for (final Material mat : materialsListing) { if (material == mat) { return true; } } return false; } } If you need me to explain anything just ask. Oh and i will just point out that i am also very new to modding so there may be better ways to do some of this. Edit: Also note this tool wont loose durability because i copied most of the code from one of my tool classes and my tools have infinite durability. If you cant figure out how to make the tool loose durability when you use it let me know.
  22. so would you be able to help me out with my proxys? im not sure how you set up your init() methods. When you start your tutorials i would very much like to take a look the way you explained this was awesome.
  23. YOU ARE AWESOME! Thats the first tutorial I have been able to understand all the other tutorials i looked at were insanely complex and impossible for me to figure out but i think i understand how this works now. I just have one thing i cant figure out and that is the "Create and Register Your Packet Handler Classes" part can you please explain in more detail. i dont use init() methods in my proxys and im not sure how to set them up. My proxys: common client And my main mod class: Thank you for your help!
  24. Thanks i will look over your code and see if i can figure it out. I looked at a few of the 1.7.2 tutorials using the netty system but i couldn't figure out how to use it. I will let you know how i go.
  25. I am having some trouble with a tile entity. I am using nbt to store a data value but it seems nbt is only read on the server and i need this data on the client aswell can someone tell me how to synchronize the client with the server when the nbt is read? this is my tile entity class the field i am trying to save is "charges"
×
×
  • Create New...

Important Information

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