@Override public void sendBaubleUpdatePacket(EntityPlayer player, int slot) { if(player instanceof EntityPlayerMP) { PacketHandler.INSTANCE.sendTo(new PacketSync(player, slot, BaublesApi.getBaublesHandler(player).getStackInSlot(slot)), (EntityPlayerMP) player); } }
for(int i = 0; i < baubles.getSlots(); i++) { if(baubles.isItemValidForSlot(i, toEquip, player)) { ItemStack stackInSlot = baubles.getStackInSlot(i); if(stackInSlot.isEmpty() || ((IBauble) stackInSlot.getItem()).canUnequip(stackInSlot, player)) { baubles.setStackInSlot(i, ItemStack.EMPTY); baubles.setStackInSlot(i, toEquip); ((IBauble) toEquip.getItem()).onEquipped(toEquip, player);
@Override public void markDirty() { handler.setChanged(slot, true); } }
private void syncSlots(EntityPlayer player, Collection<? extends EntityPlayer> receivers) { IBaublesItemHandler baubles = BaublesApi.getBaublesHandler(player); for (int i = 0; i < baubles.getSlots(); i++) { syncSlot(player, i, baubles.getStackInSlot(i), receivers); } }
public void dropItemsAt(EntityPlayer player, List<EntityItem> drops, Entity e) { IBaublesItemHandler baubles = BaublesApi.getBaublesHandler(player); for (int i = 0; i < baubles.getSlots(); ++i) { if (baubles.getStackInSlot(i) != null && !baubles.getStackInSlot(i).isEmpty()) { EntityItem ei = new EntityItem(e.world, e.posX, e.posY + e.getEyeHeight(), e.posZ, baubles.getStackInSlot(i).copy()); ei.setPickupDelay(40); float f1 = e.world.rand.nextFloat() * 0.5F; float f2 = e.world.rand.nextFloat() * (float) Math.PI * 2.0F; ei.motionX = (double) (-MathHelper.sin(f2) * f1); ei.motionZ = (double) (MathHelper.cos(f2) * f1); ei.motionY = 0.20000000298023224D; drops.add(ei); baubles.setStackInSlot(i, ItemStack.EMPTY); } } } }
private void syncBaubles(EntityPlayer player, IBaublesItemHandler baubles) { ItemStack[] items = baublesSync.get(player.getUniqueID()); if (items == null) { items = new ItemStack[baubles.getSlots()]; Arrays.fill(items, ItemStack.EMPTY); baublesSync.put(player.getUniqueID(), items); } if (items.length != baubles.getSlots()) { ItemStack[] old = items; items = new ItemStack[baubles.getSlots()]; System.arraycopy(old, 0, items, 0, Math.min(old.length, items.length)); baublesSync.put(player.getUniqueID(), items); } Set<EntityPlayer> receivers = null; for (int i = 0; i < baubles.getSlots(); i++) { ItemStack stack = baubles.getStackInSlot(i); IBauble bauble = stack.getCapability(BaublesCapabilities.CAPABILITY_ITEM_BAUBLE, null); if (baubles.isChanged(i) || bauble != null && bauble.willAutoSync(stack, player) && !ItemStack.areItemStacksEqual(stack, items[i])) { if (receivers == null) { receivers = new HashSet<>(((WorldServer) player.world).getEntityTracker().getTrackingPlayers(player)); receivers.add(player); } syncSlot(player, i, stack, receivers); baubles.setChanged(i,false); items[i] = stack == null ? ItemStack.EMPTY : stack.copy(); } } }
@Override @Nonnull public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) { // Check if the entity we've just hit has a stack in the first slot. If so, use that instead. ItemStack stack = player.getHeldItem(hand); RayTraceResult hit = PlayerHelpers.findHitGuess(player); Entity entity = hit.entityHit; if (hit.typeOfHit == RayTraceResult.Type.ENTITY && !(entity instanceof EntityPlayer) && entity instanceof EntityLivingBase) { if (((EntityLivingBase) entity).getItemStackFromSlot(NeuralHelpers.ARMOR_SLOT).isEmpty() && stack.getCount() == 1) { return ActionResult.newResult(EnumActionResult.SUCCESS, stack); } } if (LoadedCache.hasBaubles()) { IBaublesItemHandler handler = BaublesApi.getBaublesHandler(player); for (int slot : NeuralHelpers.getBaubleType().getValidSlots()) { if (handler.getStackInSlot(slot).isEmpty()) { if (!world.isRemote) { handler.setStackInSlot(slot, stack.copy()); if (!player.capabilities.isCreativeMode) stack.grow(-1); } return ActionResult.newResult(EnumActionResult.SUCCESS, stack); } } } return super.onItemRightClick(world, player, hand); }
@Override public int getSizeInventory() { return handler.getSlots(); }
@Override public void setInventorySlotContents(int index, ItemStack stack) { handler.setStackInSlot(index, stack); }
int slotShift = baubles.getSlots(); if (itemstack1.isEmpty() && !baubles.isEventBlocked() && slot instanceof SlotBauble && itemstack.hasCapability(BaublesCapabilities.CAPABILITY_ITEM_BAUBLE, null)) { itemstack.getCapability(BaublesCapabilities.CAPABILITY_ITEM_BAUBLE, null).onUnequipped(itemstack, playerIn);
@SideOnly(Side.CLIENT) @Override public void setAll(List<ItemStack> l) { baubles.setEventBlock(true); super.setAll(l); }
@Override public boolean isItemValidForSlot(int index, ItemStack stack) { return handler.isItemValidForSlot(index, stack, player); }
/** * Returns if the passed in item is equipped in a bauble slot. Will return the first slot found * @return -1 if not found and slot number if it is found */ public static int isBaubleEquipped(EntityPlayer player, Item bauble) { IBaublesItemHandler handler = getBaublesHandler(player); for (int a=0;a<handler.getSlots();a++) { if (!handler.getStackInSlot(a).isEmpty() && handler.getStackInSlot(a).getItem()==bauble) return a; } return -1; } }
for (int a = 0; a<baubles.getSlots();a++) { ItemStack st = baubles.getStackInSlot(a); if (!st.isEmpty() && st.hasCapability(BaublesCapabilities.CAPABILITY_ITEM_BAUBLE, null)) { IBauble bauble = st.getCapability(BaublesCapabilities.CAPABILITY_ITEM_BAUBLE, null); int slot = -1; try { slot = Integer.parseInt(args[2]); } catch (Exception e) {} if (slot<0 || slot >= baubles.getSlots()) { sender.sendMessage(new TextComponentTranslation("\u00a7cInvalid arguments")); sender.sendMessage(new TextComponentTranslation("\u00a7cUse /baubles help to get help")); } else { baubles.setStackInSlot(slot, ItemStack.EMPTY); sender.sendMessage(new TextComponentTranslation("\u00a73Cleared baubles slot "+slot+" for "+entityplayermp.getName())); entityplayermp.sendMessage(new TextComponentTranslation("\u00a74Your baubles slot "+slot+" has been cleared by admin "+sender.getName())); for (int a = 0; a<baubles.getSlots();a++) { baubles.setStackInSlot(a, ItemStack.EMPTY);
public static Iterable<ItemStack> getBaubles(Entity entity) { if (CAPABILITY_BAUBLES == null) { return Collections.emptyList(); } IBaublesItemHandler handler = entity.getCapability(CAPABILITY_BAUBLES, null); if (handler == null) { return Collections.emptyList(); } return IntStream.range(0, handler.getSlots()).mapToObj(handler::getStackInSlot).filter(stack -> !stack.isEmpty()).collect(Collectors.toList()); }
@Override public ItemStack removeStackFromSlot(int index) { ItemStack out = this.getStackInSlot(index); handler.setStackInSlot(index, ItemStack.EMPTY); return out; }
/** * Called from the main game loop to update the screen. */ @Override public void updateScreen() { ((ContainerPlayerExpanded)inventorySlots).baubles.setEventBlock(false); updateActivePotionEffects(); resetGuiLeft(); }
/** * Check if the stack is a valid item for this slot. */ @Override public boolean isItemValid(ItemStack stack) { return ((IBaublesItemHandler)getItemHandler()).isItemValidForSlot(baubleSlot, stack, player); }
private boolean shouldPlayerHaveStepup(EntityPlayer player) { ItemStack armor = BaublesApi.getBaublesHandler(player).getStackInSlot(3); return !armor.isEmpty() && armor.getItem() instanceof ItemTravelBelt && ManaItemHandler.requestManaExact(armor, player, COST, false); }
/** Baubles **/ private ItemStack getHeadgear(EntityPlayer entity) { IBaublesItemHandler baubles = BaublesApi.getBaublesHandler(entity); for (int i = 0; i < baubles.getSlots(); i++) { ItemStack bauble = baubles.getStackInSlot(i); if (bauble.isEmpty() || bauble.getItem() != GaiaItems.ACCESSORY_HEADGEAR) continue; return bauble; } return ItemStack.EMPTY; } }