Jump to content

vilu

Forge Modder
  • Posts

    84
  • Joined

  • Last visited

Converted

  • Gender
    Male
  • Personal Text
    Modder

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

vilu's Achievements

Stone Miner

Stone Miner (3/8)

12

Reputation

  1. Try changing your model name in your blockstate file. You are now referencing to minecraft's chest model, so "normal": { "model": "yourmodel_id_lowercased:block_model_file_name" }
  2. You could try IInventory#setInventorySlotContents(int, ItemStack) and then IInventory#markDirty Not sure if that would do the trick and I cannot check from my own sources how I did that syncing right now, but I can check next time when I'm back. But anyway, let me know if it doesn't work.
  3. You should pass it into the constructor of your Container, not GuiContainer(which is on the client-side). So in IGuiHandler#getServerGuiElement when you return new Container for server, you'll pass InventoryPlayer (I think you can get it from EntityPlayer#inventory) to your Container constructor.
  4. -> Server gets packet (that has pressed button ID for example) -> Packet has MessageContext ctx, so ctx.getServerHandler().playerEntity gives you server-side player (EntityPlayerMP) -> playerEntity.openContainer gives you container you have defined in your IGuiHandler (getClientGuiElement you returned GuiContainer for client-side and getServerGuiElement Container for server-side) -> You can set ItemStack to player inventory by getting player's inventory either from Container (if you have passed InventoryPlayer as an argument when constructing Container for server in IGuiHandler, that would be easiest because InventoryPlayer has good methods for handling player's inventory) or from EntityPlayerMP#getInventory() (which returns inventory as ItemStack array).
  5. Check EntityPlayerSP#onLivingUpdate and EntityPlayerSP#sendHorseJump I think horse jumping is done by checking somewhere that ridden entity is instance of EntityHorse and otherwise Minecraft just ignores space pressing when trying to jump while riding. I had same kind of problem when I tried to set specific state for entity when space was pressed and I solved it by subscribe of KeyInputEvent and checking there if Minecraft.getMinecraft().gameSettings.keyBindJump.isPressed() and if so, client sends packet to server. Packet is received by server side packet handler and it gets EntityPlayerMP from MessageContext and if EntityPlayerMP#ridingEntity is not null and its instanceof my entity that uses space to set state, it sets the state and updates ridingEntity datawatcher. Or you could try to extend EntityHorse instead of EntityAnimal.
  6. Double check that there is no abstract methods. It seems like there is problem to construct new instance of mercenarymod.mensajeMercenario
  7. Just like you would do it on client side. You can set itemstacks and check player inventory on server-side same way as on client side, you just need to use server-side player (EntityPlayerMP). The first thing you need to do is to let server know which button was pressed and this is where the packet is needed. So you need packet and handlers. There is great tutorial at http://www.minecraftforge.net/forum/index.php/topic,20135.0.html When the packet is received by server, you can get EntityPlayerMP from MessageContext#getServerHandler().playerEntity and server-side container from player EntityPlayerMP#openContainer which is the container you have returned in your IGuiHandler#getServerGuiElement when player opened the gui.
  8. You are approaching this from wrong direction. Gui is on client side and remember that client can let the gui know exactly what it wants (hacking). So you really need to do that on server side and I would do this like this way: - Player presses gui button -> onActionPerformed() get called. It sends request to server (can be your own packet or same way as item enchant is done so look for that. That request contains the name of requested item/block to craft. - Server gets this requests and gets player from server side container (EntityPlayerMP#opencontainer) - Server "scans" player inventory with for-loop and checks every slot of players inventory looking for items/blocks needed for requested crafting. Server knows needed items by getting it's recipe from GameRegistry (or was it somewhere else). It can find recipe by getting correct item for recipe with Item.getItemByName(requested item name) - If the correct items have been found, server subtracts itemstacks on player inventory as needed. - Now server sets requested item to slot, it can be slot in gui or in player inventory. If its in player inventory server finds first free slot with for-loop and is trying to find slot that is null. When its found then it can be set, and for cases that there is no free space left in player inventory, server can spawn item next to your block so player can pick it up.
  9. Hey check this out http://www.minecraftforge.net/forum/index.php/topic,20135.0.html it works on 1.8 as well.
  10. That worked! Thank you so much So it was, just like you said, the logger messing up sides. Packet were handled in server-side just like it should be. It just looked like it is the client that receives server-side packet because tileentity did reset everytime when its metadata (blockstate) changed. I added console debug print to onBlockActivated and checked what it prints after sending packet and it did show same nbt tag compound for both sides. Then I changed current blockstate with one Boolean property and checked nbt tags again so then it reset tileentity.
  11. Well, no specific reason why =D Actually its much efficient and easier way to do all those things I do.. just never thought it. I think that there were some case that I had problems with containers or something and therefore I made sure that Container would never return null value for getTileEntity() or something. And I just left it like that so, that's the background story behind. But back to the problem. I did more digging and I've noticed that every time I set blockstate (aka. metadata) tileentity resets. Something like this: worldIn.setBlockState(pos, previousState.withProperty(POWERED, Boolean.valueOf(powered)), 3); worldIn.notifyNeighborsOfStateChange(pos, worldIn.getBlockState(pos).getBlock());
  12. Sorry it was typo. Just quickly renamed some parts of code. It doesn't extend BlockContainer, the tileentity of block instead does. I didn't remember that BlockContainer actually exists. I'll edit my posts.
  13. I was thinking the same, but it's weird because there are lot of cases that logger recognizes server as it should. After I did some debugging I see that tileentity losts given data after changing associated block metadata...
  14. BlockPacket.ServerHandler: public static class HandlerServer extends BlockPacket implements IMessageHandler<BlockPacket, IMessage> { @Override public IMessage onMessage(BlockPacket message, MessageContext ctx) { int receivedInt = message.someInteger; System.out.printf("BlockPacket.HandlerServer.onMessage: Received integer was %s", receivedInt); EntityPlayer player = ctx.getServerHandler().playerEntity; if(player != null) { Container container = player.openContainer; if (container != null && container instanceof SomeContainer) { //Note: IGuiHandler returns SomeContainer that extends Container for server. BlockPos pos = ((SomeContainer)container).getTileEntity().getPos(); TileEntity te = player.worldObj.getTileEntity(pos); if(te != null && te instanceof BlockTileEntity) { ((BlockTileEntity)te).setDataFromPacket(receivedInt); } else { System.out.printf("BlockPacket.HandlerServer.onMessage: No tileentity found at %s", pos.toString); } } } return null; } } and console says: [modname-CLIENT] BlockPacket.HandlerServer.onMessage: Received integer was 1234 [modname-CLIENT] BlockTileEntity.setDataFromPacket: Got data 1234 but if I run exactly the same code (except blockPos, it were x y z coordinates) in 1.7.10 console says: [modname-SERVER] BlockPacket.HandlerServer.onMessage: Received integer was 1234 [modname-SERVER] BlockTileEntity.setDataFromPacket: Got data 1234
  15. I'm using SimpleNetworkWrapper to send packets that implements IMessage. Everything worked fine on 1.7.10 but now if I send packet from client side to server, I can see from console that it's the client that handles packet when its handler is registered to be on server-side. So here is some code. @EventHandler public void preInit(FMLPreInitializationEvent event) { network = NetworkRegistry.INSTANCE.newSimpleChannel(Info.modChannel); network.registerMessage(BlockPacket.HandlerServer.class, BlockPacket.class, 1, Side.SERVER); network.registerMessage(BlockPacket.HandlerClient.class, BlockPacket.class, 2, Side.CLIENT); } BlockPacket.ServerHandler: public static class HandlerServer extends BlockPacket implements IMessageHandler<BlockPacket, IMessage> { @Override public IMessage onMessage(BlockPacket message, MessageContext ctx) { int receivedInt = message.someInteger; System.out.printf("BlockPacket.HandlerServer.onMessage: Received integer was %s", receivedInt); return null; } } I'm trying to send packet from GUI: modname.network.sendToServer(new BlockPacket(1234)); and then I can see from console that it's send and received but: [modname-CLIENT] BlockPacket.HandlerServer.onMessage: Received integer was 1234 Let's say I want to send packet from a gui to the server, and there are values I want to set to the tileentity. If I set those values by using received packet it will update only client side tileentity, not server side as it should. So any ideas how to fix this? And this same thing happens for all packets sent to server handler.
×
×
  • Create New...

Important Information

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