Skip to content

Commit

Permalink
Allow items to be picked up that give into your basket
Browse files Browse the repository at this point in the history
  • Loading branch information
Gegy committed Oct 29, 2023
1 parent 2d40371 commit d85a3df
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;

Expand Down Expand Up @@ -64,7 +64,7 @@ public static boolean isCollectible(final ItemStack stack) {
return tag != null && tag.contains(KEY_ITEM_STACK_MARKER);
}

public static boolean isIllegalCollectible(final ItemStack stack, final ServerPlayer player) {
public static boolean isIllegalCollectible(final ItemStack stack, final Player player) {
if (stack.isEmpty()) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,22 @@ public static boolean onItemToss(final Player player, final ItemEntity item) {
@SubscribeEvent
public static void onItemPickup(final EntityItemPickupEvent event) {
final ItemStack stack = event.getItem().getItem();
if (Collectible.isCollectible(stack)) {
final Collectible collectible = Collectible.byItem(stack);
if (collectible == null) {
return;
}

final Player player = event.getEntity();
if (Collectible.isIllegalCollectible(stack, player)) {
stack.setCount(0);
event.getItem().discard();
event.setCanceled(true);
} else {
final CollectibleStore store = CollectibleStore.getNullable(player);
if (store != null) {
store.give(collectible);
Collectible.addMarkerTo(player.getUUID(), stack);
}
}
}

Expand Down

0 comments on commit d85a3df

Please sign in to comment.