use of dev.rosewood.rosestacker.stack.StackedItem in project RoseStacker by Rosewood-Development.
the class ItemListener method onItemPickup.
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onItemPickup(EntityPickupItemEvent event) {
if (this.stackManager.isWorldDisabled(event.getEntity().getWorld()))
return;
if (!this.stackManager.isItemStackingEnabled())
return;
StackedItem stackedItem = this.stackManager.getStackedItem(event.getItem());
if (stackedItem == null)
return;
Inventory inventory;
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
inventory = player.getInventory();
} else if (event.getEntity() instanceof Villager) {
Villager villager = (Villager) event.getEntity();
inventory = villager.getInventory();
} else if (event.getEntityType() == EntityType.DOLPHIN) {
// Only stop the dolphin from picking up the item if it's larger than a normal item would be, otherwise
// cancel the event, give the dolphin an item of max normal stack size, and reduce the stacked item size
int maxStack = event.getItem().getItemStack().getType().getMaxStackSize();
if (stackedItem.getStackSize() > maxStack) {
ItemStack clone = event.getItem().getItemStack().clone();
clone.setAmount(maxStack);
stackedItem.setStackSize(stackedItem.getStackSize() - maxStack);
EntityEquipment equipment = event.getEntity().getEquipment();
if (equipment != null)
equipment.setItemInMainHand(clone);
// Stun the item temporarily to avoid it getting instantly stacked back into
stackedItem.getItem().setPickupDelay(50);
event.setCancelled(true);
}
return;
} else {
// Only pick up one item
if (stackedItem.getStackSize() > 1) {
this.stackManager.splitItemStack(stackedItem, 1);
event.setCancelled(true);
}
return;
}
if (this.applyInventoryItemPickup(inventory, stackedItem, event.getEntity()))
event.setCancelled(true);
}
use of dev.rosewood.rosestacker.stack.StackedItem in project RoseStacker by Rosewood-Development.
the class ItemConversionHandler method handleConversion.
@Override
public Set<Stack<?>> handleConversion(Set<ConversionData> conversionData) {
Set<Stack<?>> stacks = new HashSet<>();
for (ConversionData data : conversionData) {
StackedItem stackedItem = new StackedItem(data.getStackSize(), data.getItem());
this.stackManager.addItemStack(stackedItem);
stacks.add(stackedItem);
}
return stacks;
}
use of dev.rosewood.rosestacker.stack.StackedItem in project RoseStacker by Rosewood-Development.
the class WildStackerItemConversionHandler method handleConversion.
@Override
public Set<Stack<?>> handleConversion(Set<ConversionData> conversionData) {
Set<Item> items = conversionData.stream().map(ConversionData::getItem).filter(Objects::nonNull).collect(Collectors.toSet());
Set<Stack<?>> stacks = new HashSet<>();
for (Item item : items) {
PersistentDataContainer dataContainer = item.getPersistentDataContainer();
if (dataContainer.has(PersistentDataUtils.CONVERTED_KEY, PersistentDataType.INTEGER))
continue;
int stackSize = dataContainer.getOrDefault(STACK_KEY, PersistentDataType.INTEGER, -1);
if (stackSize == -1)
continue;
dataContainer.set(PersistentDataUtils.CONVERTED_KEY, PersistentDataType.INTEGER, 1);
StackedItem stackedItem = new StackedItem(stackSize, item);
this.stackManager.addItemStack(stackedItem);
stacks.add(stackedItem);
}
return stacks;
}
Aggregations