Everything posted by TheScaryParrot
-
Difficulties with custom Entity Packets
I'm using forge-1.19.2-43.1.57 and my SoulEntity extends 'net.minecraft.world.entity.Entity'
-
Difficulties with custom Entity Packets
As 'getAddEntityPacket()' is an abstract method of the Entity class it gives me an error if it isn't implemented. Anyways I just used the same code which is used in the LivingEntity class, which seems to work fine. @Override public Packet<?> getAddEntityPacket() { return new ClientboundAddEntityPacket(this); } Still thank you very much for the answer! The docs will most certainly get useful in the future.
-
Difficulties with custom Entity Packets
I'm working on a mod which should allow the player to capture the souls of dead LivingEntities. When LivingEntity dies a SoulEntity should be created that flies towards the player, similar to how experience orbs work. So I created a SoulEntity class which extends Entity. But I'm having problems with the Packet required for the 'getAddEntityPacket()' method. I created my custom Packet class simliar to the ClientboundAddExperienceOrbPacket. But I'm having trouble with the 'handle(ClientGamePacketListener p_131523_)' method. In the ClientboundAddExperienceOrbPacket the handling is done by the ClientGamePacketListener argument: public void handle(ClientGamePacketListener p_131523_) { p_131523_.handleAddExperienceOrb(this); } But as ClientGamePacketListener is a vanilla interface I'm not certain how I can add my own handle method to it. I'm having trouble finding documentation on this subject as most tutorials only explain the creation of LivingEntities, which don't require a custom 'getAddEntityPacket()' method. As I'm rather new to modding I'm not really sure what to do.
-
Changing ItemStack but player inventory not updating
OMG I found the problem. I was testing in creative and not survival mode. Obviously items aren't consumed in creative.
-
Changing ItemStack but player inventory not updating
You're understanding absolutly fine. Seems like a me problem then. I also tried building the mod and I still get the same result (item not disappearing from inventory). I'll take a look at it the following days maybe my MC is broken? In the meantime thank you very much for your help!
-
Changing ItemStack but player inventory not updating
Here you go: https://github.com/TheScaryParrot/mc-forge-modding-itemstack-problem/tree/main/src/main The code can be found at: src/main/java/io/github/thescaryparrot/darkcenturies/newstuff/items/RessurectionAmulet.java & TestItem.java
-
Changing ItemStack but player inventory not updating
I took a look at it and adjusted my code accordingly. But it still doesn't work correctly. Now I the 3rd print gives me the inventory without the item (as it should be) but the player's GUI doesn't update. Additionaly when I use another ressurection amulet it's 3rd print shows the item again: use of amulet in 1st slot: "[0 air, 1 amulet_of_ressurection, 1 air, 1 air, 1 air, 1 air, 1 amulet_of_ressurection, 1 netherite_sword, 1 wolf_spawn_egg]" use of amulet in 2nd slot: "[1 amulet_of_ressurection, 0 air, 1 air, 1 air, 1 air, 1 air, 1 amulet_of_ressurection, 1 netherite_sword, 1 wolf_spawn_egg]" @Override public InteractionResult useOn(UseOnContext context) { Level level = context.getLevel(); if (level instanceof ServerLevel && !level.isClientSide) { System.out.println(context.getItemInHand()); // 1 context.getItemInHand().shrink(1); System.out.println(context.getItemInHand()); // 2 System.out.println(context.getPlayer().getInventory().items); // 3 } return InteractionResult.sidedSuccess(level.isClientSide); }
-
Changing ItemStack but player inventory not updating
I'm currently working on an item(called ressurection amulet) that the player can apply onto tamable animals. When these animals die they drop that item which then allows the player to ressurect them. But when I try to shrink the ItemStack the player's inventory doesn't update accordingly. The following lines are printed to the console when running the code below: 1: "1 ressurection_amulet" 2: "0 air" 3: player inventory that still contains the ressurection amulet @Override public InteractionResult useOn(UseOnContext context) { System.out.println("use"); if (ressurectEntity(context.getLevel(), context.getClickLocation().add(new Vec3(0, 1, 0)), context.getItemInHand())) { System.out.println("ressurect"); System.out.println(context.getItemInHand()); // 1 context.getItemInHand().shrink(1); System.out.println(context.getItemInHand()); // 2 System.out.println(context.getPlayer().getInventory().items); // 3 return InteractionResult.CONSUME; } else { return InteractionResult.FAIL; } } @Override public InteractionResult interactLivingEntity(ItemStack itemStack, Player player, LivingEntity entity, InteractionHand hand) { System.out.println("entity interact"); if (!(entity instanceof TamableAnimal)) return InteractionResult.FAIL; //change entity.addTag("ressurection_amulet_applied"); System.out.println(itemStack); // 1 itemStack.shrink(1); System.out.println(itemStack); // 2 System.out.println(player.getInventory().items); // 3 return InteractionResult.CONSUME; }
IPS spam blocked by CleanTalk.