Jump to content

Zipree

Members
  • Posts

    3
  • Joined

  • Last visited

Posts posted by Zipree

  1. On server side, how to reduce players item from inventory?

     

    I used below codes.

     

    It doesn't work. Nothing changed.

    @Override
    	public IMessage onMessage(CostMessage message, MessageContext ctx) {
    		EntityPlayerMP player = ctx.getServerHandler().player;
    		if (message != null) {
    			ItemStack stack = message.getItemStack();
    			if (stack == null)
    				return null;
    			InventoryPlayer inv = player.inventory;
    			inv.deleteStack(stack);
    		}
    		return null;
    	}

     

    It caused NoSuchMethodException with func_184429_b

    @Override
    	public IMessage onMessage(CostMessage message, MessageContext ctx) {
    		EntityPlayerMP player = ctx.getServerHandler().player;
    		if (message != null) {
    			ItemStack stack = message.getItemStack();
    			if (stack == null)
    				return null;
    			InventoryPlayer inv = player.inventory;
    			int amount = stack.getCount();
    			int p = 0, cnt = stack.getCount();
    			while (cnt > 0) {
    				int slot = inv.getSlotFor(stack);
    				int cntFrom = inv.getStackInSlot(slot).getCount();
    				cnt -= cntFrom;
    				if (cnt > 0) {
    					inv.setInventorySlotContents(slot, null);
    				} else if (cnt != 0) {
    					stack.setCount(-cnt);
    					inv.setInventorySlotContents(slot, stack);
    				}
    			}
    		}
    		return null;
    	}

     

    Is there any method or way to reduce items from player's inventory by item name & count?

  2. 3 hours ago, Animefan8888 said:

    No don't ever trust the client. Instead when the button or whatever action is causing this to occur happens send a packet to the server to perform the logic and change the information there.

    then, how to send a packet to server from guiscreen?

     

    is there any network object for guiscreen or from forge?

     

    or should i make custom network IO connection?

  3. I have a class which extends GuiScreen

     

    I want to change player's inventory in it and sync with server

     

    I used below code

     

    if(ItemStack.areItemsEqual(iStack, new ItemStack(ModItems.whiteCoin))){
    	player.inventory.mainInventory.set(slotNum, new ItemStack(ModItems.whiteCoin, itemAmount));
    }

     

    but it doesn't sync with client and server both.

     

    How can i change EntityPlayerSP's inventory and sync data with server?

×
×
  • Create New...

Important Information

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