use of net.minecraft.world.item.ItemStack in project MyPet by xXKeyleXx.
the class CustomInventory method save.
@Override
public TagCompound save(TagCompound compound) {
List<TagCompound> itemList = new ArrayList<>();
for (int i = 0; i < this.items.size(); i++) {
ItemStack itemStack = this.items.get(i);
if (itemStack != ItemStack.EMPTY) {
TagCompound item = ItemStackNBTConverter.itemStackToCompound(itemStack);
item.getCompoundData().put("Slot", new TagByte((byte) i));
itemList.add(item);
}
}
compound.getCompoundData().put("Items", new TagList(itemList));
return compound;
}
use of net.minecraft.world.item.ItemStack in project MyPet by xXKeyleXx.
the class CustomInventory method removeItem.
@Override
public ItemStack removeItem(int slot, int subtract) {
if (slot < size && items.get(slot) != ItemStack.EMPTY) {
if (items.get(slot).getCount() <= subtract) {
ItemStack itemStack = items.get(slot);
items.set(slot, ItemStack.EMPTY);
return itemStack;
} else {
ItemStack splittedStack = items.get(slot).split(subtract);
if (items.get(slot).getCount() == 0) {
items.set(slot, ItemStack.EMPTY);
}
return splittedStack;
}
}
return ItemStack.EMPTY;
}
use of net.minecraft.world.item.ItemStack in project MyPet by xXKeyleXx.
the class IconMenuInventory method open.
@Override
public void open(IconMenu menu, HumanEntity player) {
size = menu.getSize();
minecraftInventory = new CustomInventory(size, menu.getTitle());
for (int slot = 0; slot < size; slot++) {
IconMenuItem menuItem = menu.getOption(slot);
if (menuItem != null) {
ItemStack item = createItemStack(menuItem);
minecraftInventory.setItem(slot, item);
}
}
minecraftInventory.open((Player) player);
}
use of net.minecraft.world.item.ItemStack in project MyPet by xXKeyleXx.
the class IconMenuInventory method update.
@Override
public void update(IconMenu menu) {
if (minecraftInventory != null) {
for (int slot = 0; slot < size; slot++) {
IconMenuItem menuItem = menu.getOption(slot);
if (menuItem != null) {
ItemStack item = createItemStack(menuItem);
minecraftInventory.setItem(slot, item);
} else {
minecraftInventory.setItem(slot, ItemStack.EMPTY);
}
}
}
}
use of net.minecraft.world.item.ItemStack in project MyPet by xXKeyleXx.
the class EntityMyEnderman method handlePlayerInteraction.
@Override
public InteractionResult handlePlayerInteraction(Player entityhuman, InteractionHand enumhand, ItemStack itemStack) {
if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack).consumesAction()) {
return InteractionResult.CONSUME;
}
if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) {
if (itemStack.getItem() == Items.SHEARS && getMyPet().hasBlock() && getOwner().getPlayer().isSneaking()) {
ItemEntity entityitem = new ItemEntity(this.level, this.getX(), this.getY() + 1, this.getZ(), CraftItemStack.asNMSCopy(getMyPet().getBlock()));
entityitem.pickupDelay = 10;
entityitem.setDeltaMovement(entityitem.getDeltaMovement().add(0, this.random.nextFloat() * 0.05F, 0));
makeSound("entity.sheep.shear", 1.0F, 1.0F);
getMyPet().setBlock(null);
if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
try {
itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> entityhuman1.broadcastBreakEvent(enumhand));
} catch (Error e) {
// TODO REMOVE
itemStack.hurtAndBreak(1, entityhuman, (entityhuman1) -> {
try {
CompatManager.ENTITY_LIVING_broadcastItemBreak.invoke(entityhuman1, enumhand);
} catch (IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace();
}
});
}
}
return InteractionResult.CONSUME;
} else if (getMyPet().getBlock() == null && Util.isBetween(1, 255, Item.getId(itemStack.getItem())) && getOwner().getPlayer().isSneaking()) {
getMyPet().setBlock(CraftItemStack.asBukkitCopy(itemStack));
if (itemStack != ItemStack.EMPTY && !entityhuman.getAbilities().instabuild) {
itemStack.shrink(1);
if (itemStack.getCount() <= 0) {
entityhuman.getInventory().setItem(entityhuman.getInventory().selected, ItemStack.EMPTY);
}
}
return InteractionResult.CONSUME;
}
}
return InteractionResult.PASS;
}
Aggregations