Jump to content

Scaleios

Members
  • Posts

    3
  • Joined

  • Last visited

Scaleios's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. I am attempting to remove items from a player's inventory, organize them, and replace them. Questions at the bottom. My old system was done completely client side as follows: GuiKeyPress event -> Remove items on client using the invwrapper -> sort the array, and place it back one by one into inventory That worked fine for a while, but then I noticed an issue where there would seem to be some sort of desync. The inventory would appear sorted, but trying to click on any item in it would result in the inventory reverting to the state it was before I executed my code. That is what I assumed was the desync. In response to that, I switched to sending a network packet with the inventory instead to the server, and handle everything there. That solved the desync issue I had, but now I am having problems with the inventory being completely cleared if the items are already in a sorted order. I tried a mix of clearing the inventory on client, then repopulating it on server, handling everything on server, handling everything on client, and just replacing without removing but there was always some sort of desync. To confirm, the packets reach the handler properly and all the data is as expected on the other end. The second desync issue essentially arises from trying to set an itemstack into the same index it was/already is in. The replacement was done by using ServerPlayerEntity/ClientPlayerEntity -> "inventory.removeStackFromSlot" & "replaceItemInInventory", along with using InvWrapper on each, along with the extract/insert methods. Additionally I used "PlayerEntity.addItemStackToInventory", which interestingly when called on one item would shift its index by one each successive call. I am using a simple simplempl implementation if that matters. Questions: Why is this desync happening, and is it avoidable? Is there a better way to sync the client and server up without requiring packets, and if there isn't, what is the best method of approaching this?
  2. That was it, thank you. There isn't a crash, and nothing of note shows up in the logs. Thank you anyways. Noted, thank you.
  3. I've been digging around for a while, looking for a way to spawn items in the world. In essence, I have the player, I want to take an ItemStack from their inventory (so far so good), and drop it. Now I know that my question is about entity spawning, but this says dropping, but I couldn't get either to work. The first thing I did was try to use ClientPlayerEntity.dropItem, which did nothing, so I assumed that was because I used InvWrapper.extractItem beforehand. That is when I transitioned to spawning. I tried to create a new ItemEntity and use World.addEntity on it. I know I have a valid ItemEntity, and I saw some form of this idea used in other projects & minecraft code. When executing however, nothing happens. I also tried to add the ItemStack back to the inventory and drop it, but that did nothing either. I am not sure where to go from here. Here is my code (Really starts at Functions.java): Mod.java @Mod("Mod") public class Mod { MinecraftForge.EVENT_BUS.register(clientEventHandlers); } ClientEventHandlers.java class ClientEventHandlers { @SubscribeEvent public void onKeyRelease(GuiScreenEvent.KeyboardKeyReleasedEvent.Post event) { if (true) { // Ignore what this says, this is just used for simplicity Functions.myFunction(); } } } Functions.java class Functions { static void myFunction(){ ClientPlayerEntity player = Minecraft.getInstance().player; InvWrapper invWrapper = new InvWrapper(player.inventory); ArrayList<ItemStack> removed; removed.add(invWrapper.extractItems(my, logic, false); // Removing item from inventory, works as expected // Important Bit Starts here BlockPos pos = player.getPosition(); for (ItemStack itemStack: removed){ // Each of the following comment blocks is something I tried, all to the same end /* ItemEntity itemEntity = new ItemEntity(player.world, pos.getX(), pos.getY(), pos.getZ(), itemStack.getStack()); player.world.addEntity(itemEntity); */ /* ItemEntity itemEntity = new ItemEntity(player.world, pos.getX(), pos.getY(), pos.getZ(), itemStack.getStack()); itemEntity.world.addEntity(itemEntity); */ /* invWrapper.setStackInSlot(someSlot, itemStack); player.dropItem(itemStack, true, true); // I tried every combination of bools here */ } } } (Player has to be correct because all other logic works as expected) An example value of itemEntity: "ItemEntity['Spruce Wood'/4, l='MpServer', x=4.00, y=56.00, z=-7.00]"
×
×
  • Create New...

Important Information

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