Skip to content

Commit

Permalink
fix mob yoinker with increased stack size
Browse files Browse the repository at this point in the history
closes #45
  • Loading branch information
MelanX committed Aug 4, 2023
1 parent ccb00f7 commit d641980
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions mod.properties
Expand Up @@ -4,8 +4,8 @@ group=de.melanx
base_version=0.8

# dependencies
forge_version=1.20.1-47.0.19
#mappings=sugarcane_2022.12.12-1.19.2
forge_version=1.20.1-47.1.28
mappings=sugarcane_2023.07.30-1.20.1

# Upload properties
upload_versions=1.20.1
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/de/melanx/utilitix/util/MobUtil.java
Expand Up @@ -28,7 +28,7 @@ public class MobUtil {
public static boolean storeEntityData(Player player, InteractionHand hand, LivingEntity entity, ResourceList denylist, boolean typeKeyOnly) {
String entityKey = entity.getEncodeId();
ItemStack stack = player.getItemInHand(hand);
CompoundTag nbt = stack.getOrCreateTag();
CompoundTag nbt = stack.getOrCreateTag().copy();
if (entityKey == null || entityKey.equals(nbt.getString(MobUtil.ENTITY_TYPE_TAG))) {
return false;
}
Expand All @@ -42,7 +42,18 @@ public static boolean storeEntityData(Player player, InteractionHand hand, Livin
if (!typeKeyOnly) {
nbt.put(MobUtil.ENTITY_DATA_TAG, entity.saveWithoutId(new CompoundTag()));
}
player.setItemInHand(hand, stack);

if (stack.getCount() > 1) {
stack.shrink(1);
ItemStack copyStack = stack.copy();
copyStack.setCount(1);
copyStack.setTag(nbt);
player.addItem(copyStack);
} else {
stack.setTag(nbt);
player.setItemInHand(hand, stack);
}

player.displayClientMessage(MobUtil.getCurrentMob(entity.getType()), true);
return true;
}
Expand Down

0 comments on commit d641980

Please sign in to comment.