Jump to content

Recommended Posts

Posted (edited)

I have a little problem with my Inventory. I want to make it upgradeble so you can have more Slots in it. So I addet an Integer in the TileEntiy for the number of Slots and changed the size of the LazyOptional<ItemStackHandler> inventory and it seems to work, but the screen is a bit buggy. The bigger inventory occupies slots from the playerinventory and does not extend its own one, althouge I adjust the number of slots via the Integer in the tileEntity. Any idea what I am doing wrong? 

 

My Function to increase size in the TileEntity:

	public void setItemSlots(int itemSlots) {
		this.itemSlots = itemSlots;
		LazyOptional<ItemStackHandler> itemHandler = LazyOptional.of(() -> new ItemStackHandler(itemSlots));
		inventory.ifPresent(consumer -> {
			for (int i = 0; i < consumer.getSlots(); i++) {
				int slot = i;
				itemHandler.ifPresent(consumer1 -> consumer1.setStackInSlot(slot, consumer.getStackInSlot(slot)));
			}		
			
		});
		inventory = itemHandler;	
	}

 

 

The init of the Container. Maybe I need to re-init it, but I dont know how

	@Override
	public void init() {
		tileEntity.getInventory().ifPresent(handler -> addSlots(handler, 0 , 8, 25, tileEntity.getItemSlots()));
		addPlayerInventory(8, 113);	

	}

The addSlots Functions:

public int addHorizontalSlots(IItemHandler handler, int index, int x, int y, int amount) {
		for (int i = 0; i < amount; i++) {
			addSlot(new SlotItemHandler(handler, index, x, y));
			x+=18;
			index++;
		}
		return index;
	}
	

	
	public int addSlots(IItemHandler handler, int index, int x, int y, int amount) {
		int verticalAmount = (int) Math.ceil(amount/9);
		for (int i = 0; i < verticalAmount; i++) {			
			index = addHorizontalSlots(handler,index,x,y,9);
			y+=18;
		}
		index = addHorizontalSlots(handler, index, x, y, amount%9);
		return index;
		
	}

 

My render in screen:

	@Override
	public void render(int mouseX, int mouseY, float partialTicks) {
		// TODO Auto-generated method stub
		renderBackground();		
		super.render(mouseX, mouseY, partialTicks);
		renderHoveredToolTip(mouseX, mouseY);
		getHoverdVillager(mouseX, mouseY);
		
		renderVillagerTooltip(mouseX,mouseY,this.font);
	}

 

 

 

 

 

 

 

 

 

 

 

Edited by Anubis
Couldn't find insert code last time
Posted

Maybe thats an stupid question, but how do i synchronize that?

That's my NetworkHooks for the tileentity:

NetworkHooks.openGui((ServerPlayerEntity) playerEntity, village_Center_Tile_Entity, blockPos);

What do I need to add, so it will synchronize?

  • 2 weeks later...
Posted

I don't know if anyone is interested, but I found my mistake. After long searching I found the problem, just a stupid one. Before the upgrading procedure I had a isRemote check, witch cases the unsync between client and server side.

 

Thanks for help everyone

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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