@Override public IItemHandlerModifiable getBaublesInventoryWrapped(EntityPlayer player) { return BaublesApi.getBaublesHandler(player); }
@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); } }
public static ItemStack getOdinRing(EntityPlayer player) { IItemHandler baubles = BaublesApi.getBaublesHandler(player); ItemStack stack1 = baubles.getStackInSlot(1); ItemStack stack2 = baubles.getStackInSlot(2); return isOdinRing(stack1) ? stack1 : isOdinRing(stack2) ? stack2 : null; }
public static ItemStack getThorRing(EntityPlayer player) { IItemHandler baubles = BaublesApi.getBaublesHandler(player); ItemStack stack1 = baubles.getStackInSlot(1); ItemStack stack2 = baubles.getStackInSlot(2); return isThorRing(stack1) ? stack1 : isThorRing(stack2) ? stack2 : null; }
private static ItemStack getLokiRing(EntityPlayer player) { IItemHandler baubles = BaublesApi.getBaublesHandler(player); ItemStack stack1 = baubles.getStackInSlot(1); ItemStack stack2 = baubles.getStackInSlot(2); return isLokiRing(stack1) ? stack1 : isLokiRing(stack2) ? stack2 : ItemStack.EMPTY; }
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); }
public static boolean hasMonocle(EntityPlayer player) { for(int i = 0; i < 7; i++) { ItemStack stack = BaublesApi.getBaublesHandler(player).getStackInSlot(i); if(!stack.isEmpty()) { Item item = stack.getItem(); if(item instanceof IBurstViewerBauble) return true; if(item instanceof ICosmeticAttachable) { ICosmeticAttachable attach = (ICosmeticAttachable) item; ItemStack cosmetic = attach.getCosmeticItem(stack); if(cosmetic != null && cosmetic.getItem() instanceof IBurstViewerBauble) return true; } } } return false; }
@Override public IMessage onMessage(PacketJump message, MessageContext ctx) { EntityPlayerMP player = ctx.getServerHandler().player; player.server.addScheduledTask(() -> { IItemHandler baublesInv = BaublesApi.getBaublesHandler(player); ItemStack amuletStack = baublesInv.getStackInSlot(0); if(!amuletStack.isEmpty() && amuletStack.getItem() instanceof CloudPendantShim) { player.addExhaustion(0.3F); player.fallDistance = 0; ItemStack belt = BaublesApi.getBaublesHandler(player).getStackInSlot(3); if(!belt.isEmpty() && belt.getItem() instanceof ItemTravelBelt) player.fallDistance = -((ItemTravelBelt) belt.getItem()).fallBuffer * ((CloudPendantShim) amuletStack.getItem()).getMaxAllowedJumps(); } }); return null; } }
@SubscribeEvent public static void onExplosion(ExplosionEvent.Detonate event) { Explosion e = event.getExplosion(); Vec3d vec = e.getPosition(); List<EntityPlayer> players = event.getWorld().getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(vec.x, vec.y, vec.z, vec.x, vec.y, vec.z).grow(8)); for(EntityPlayer player : players) { ItemStack charm = BaublesApi.getBaublesHandler(player).getStackInSlot(6); if(!charm.isEmpty() && charm.getItem() instanceof ItemGoddessCharm && ManaItemHandler.requestManaExact(charm, player, COST, true)) { event.getAffectedBlocks().clear(); return; } } }
@SubscribeEvent public void onPlayerJump(LivingJumpEvent event) { if(event.getEntityLiving() instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) event.getEntityLiving(); ItemStack belt = BaublesApi.getBaublesHandler(player).getStackInSlot(3); if(!belt.isEmpty() && belt.getItem() instanceof ItemTravelBelt && ManaItemHandler.requestManaExact(belt, player, COST, false)) { player.motionY += ((ItemTravelBelt) belt.getItem()).jump; player.fallDistance = -((ItemTravelBelt) belt.getItem()).fallBuffer; } } }
private boolean shouldPlayerHaveFlight(EntityPlayer player) { ItemStack armor = BaublesApi.getBaublesHandler(player).getStackInSlot(4); if(!armor.isEmpty() && armor.getItem() == this) { int left = ItemNBTHelper.getInt(armor, TAG_TIME_LEFT, MAX_FLY_TIME); boolean flying = ItemNBTHelper.getBoolean(armor, TAG_FLYING, false); return (left > (flying ? 0 : MAX_FLY_TIME / 10) || player.inventory.hasItemStack(new ItemStack(ModItems.flugelEye))) && ManaItemHandler.requestManaExact(armor, player, getCost(armor, left), false); } return false; }
@SubscribeEvent public void onTossItem(ItemTossEvent event) { IItemHandler inv = BaublesApi.getBaublesHandler(event.getPlayer()); for(int i = 0; i < inv.getSlots(); i++) { ItemStack stack = inv.getStackInSlot(i); if(!stack.isEmpty() && stack.getItem() instanceof ItemMagnetRing) { setCooldown(stack, 100); BotaniaAPI.internalHandler.sendBaubleUpdatePacket(event.getPlayer(), i); } } }
@Override public void doRenderLayer(@Nonnull EntityPlayer player, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch, float scale) { if(!ConfigHandler.renderBaubles || player.getActivePotionEffect(MobEffects.INVISIBILITY) != null) return; IItemHandler inv = BaublesApi.getBaublesHandler(player); dispatchRenders(inv, player, RenderType.BODY, partialTicks); if(!inv.getStackInSlot(3).isEmpty()) renderManaTablet(player); float yaw = player.prevRotationYawHead + (player.rotationYawHead - player.prevRotationYawHead) * partialTicks; float yawOffset = player.prevRenderYawOffset + (player.renderYawOffset - player.prevRenderYawOffset) * partialTicks; float pitch = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * partialTicks; GlStateManager.pushMatrix(); GlStateManager.rotate(yawOffset, 0, -1, 0); GlStateManager.rotate(yaw - 270, 0, 1, 0); GlStateManager.rotate(pitch, 0, 0, 1); dispatchRenders(inv, player, RenderType.HEAD, partialTicks); ItemStack helm = player.inventory.armorItemInSlot(3); if(!helm.isEmpty() && helm.getItem() instanceof ItemTerrasteelHelm) ItemTerrasteelHelm.renderOnPlayer(helm, player); GlStateManager.popMatrix(); }
@SubscribeEvent public static void onDeath(LivingDeathEvent evt) { if(!evt.getEntityLiving().world.isRemote && evt.getEntityLiving() instanceof EntityPlayer && !evt.getEntityLiving().world.getGameRules().getBoolean("keepInventory") && !((EntityPlayer) evt.getEntityLiving()).isSpectator()) { IItemHandler inv = BaublesApi.getBaublesHandler((EntityPlayer) evt.getEntityLiving()); for(int i = 0; i < inv.getSlots(); i++) { ItemStack stack = inv.getStackInSlot(i); if (!stack.isEmpty() && stack.getItem().getRegistryName().getNamespace().equals(LibMisc.MOD_ID)) { ((ItemBauble) stack.getItem()).onUnequipped(stack, evt.getEntityLiving()); } } } }
@SubscribeEvent public void onPlayerDamage(LivingHurtEvent event) { if(event.getEntityLiving() instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) event.getEntityLiving(); ItemStack belt = BaublesApi.getBaublesHandler(player).getStackInSlot(5); if(!belt.isEmpty() && belt.getItem() instanceof ItemHolyCloak && !isInEffect(belt)) { ItemHolyCloak cloak = (ItemHolyCloak) belt.getItem(); int cooldown = getCooldown(belt); // Used to prevent StackOverflows with mobs that deal damage when damaged setInEffect(belt, true); if(cooldown == 0 && cloak.effectOnDamage(event, player, belt)) setCooldown(belt, cloak.getCooldownTime(belt)); setInEffect(belt, false); } } }
@Override public IMessage onMessage(PacketDodge message, MessageContext ctx) { EntityPlayerMP player = ctx.getServerHandler().player; player.server.addScheduledTask(() -> { player.world.playSound(null, player.posX, player.posY, player.posZ, ModSounds.dash, SoundCategory.PLAYERS, 1F, 1F); IItemHandler baublesInv = BaublesApi.getBaublesHandler(player); ItemStack ringStack = baublesInv.getStackInSlot(1); if(ringStack.isEmpty() || !(ringStack.getItem() instanceof ItemDodgeRing)) { ringStack = baublesInv.getStackInSlot(2); if(ringStack.isEmpty() || !(ringStack.getItem() instanceof ItemDodgeRing)) ctx.getServerHandler().disconnect(new TextComponentTranslation("botaniamisc.invalidDodge")); return; } player.addExhaustion(0.3F); ItemNBTHelper.setInt(ringStack, ItemDodgeRing.TAG_DODGE_COOLDOWN, ItemDodgeRing.MAX_CD); }); return null; } }
@SubscribeEvent public static void onDamageTaken(LivingHurtEvent event) { if(!event.getEntityLiving().world.isRemote && event.getEntityLiving() instanceof EntityPlayer && event.getSource().getTrueSource() instanceof EntityLivingBase) { EntityPlayer player = (EntityPlayer) event.getEntityLiving(); ItemStack stack = PlayerHelper.getFirstHeldItemClass(player, IPixieSpawner.class); float chance = getChance(stack); for (ItemStack element : player.inventory.armorInventory) chance += getChance(element); IItemHandler baubles = BaublesApi.getBaublesHandler(player); for(int i = 0; i < baubles.getSlots(); i++) chance += getChance(baubles.getStackInSlot(i)); if(Math.random() < chance) { EntityPixie pixie = new EntityPixie(player.world); pixie.setPosition(player.posX, player.posY + 2, player.posZ); if(((ItemElementiumHelm) ModItems.elementiumHelm).hasArmorSet(player)) { pixie.setApplyPotionEffect(new PotionEffect(potions[event.getEntityLiving().world.rand.nextInt(potions.length)], 40, 0)); } float dmg = 4; if(!stack.isEmpty() && stack.getItem() == ModItems.elementiumSword) dmg += 2; pixie.setProps((EntityLivingBase) event.getSource().getTrueSource(), player, 0, dmg); pixie.onInitialSpawn(player.world.getDifficultyForLocation(new BlockPos(pixie)), null); player.world.spawnEntity(pixie); } } }
@SubscribeEvent @SideOnly(Side.CLIENT) public static void onKeyDown(KeyInputEvent event) { Minecraft mc = Minecraft.getMinecraft(); IItemHandler baublesInv = BaublesApi.getBaublesHandler(mc.player); ItemStack ringStack = baublesInv.getStackInSlot(1); if(ringStack.isEmpty() || !(ringStack.getItem() instanceof ItemDodgeRing)) { ringStack = baublesInv.getStackInSlot(2); if(ringStack.isEmpty() || !(ringStack.getItem() instanceof ItemDodgeRing)) return; } if(ItemNBTHelper.getInt(ringStack, TAG_DODGE_COOLDOWN, 0) > 0) return; int threshold = 4; if(mc.gameSettings.keyBindLeft.isKeyDown() && !oldLeftDown) { int oldLeft = leftDown; leftDown = ClientTickHandler.ticksInGame; if(leftDown - oldLeft < threshold) dodge(mc.player, true); } else if(mc.gameSettings.keyBindRight.isKeyDown() && !oldRightDown) { int oldRight = rightDown; rightDown = ClientTickHandler.ticksInGame; if(rightDown - oldRight < threshold) dodge(mc.player, false); } oldLeftDown = mc.gameSettings.keyBindLeft.isKeyDown(); oldRightDown = mc.gameSettings.keyBindRight.isKeyDown(); }
public ContainerBaubleBox(EntityPlayer player, InventoryBaubleBox boxInv) { int i; int j; IInventory playerInv = player.inventory; baubleBoxInv = boxInv; baubles = BaublesApi.getBaublesHandler(player); addSlotToContainer(new SlotBauble(player, baubles, 0, 8, 8 + 0 * 18)); addSlotToContainer(new SlotBauble(player, baubles, 1, 8, 8 + 1 * 18)); addSlotToContainer(new SlotBauble(player, baubles, 2, 8, 8 + 2 * 18)); addSlotToContainer(new SlotBauble(player, baubles, 3, 8, 8 + 3 * 18)); addSlotToContainer(new SlotBauble(player, baubles, 4, 27, 8 + 0 * 18)); addSlotToContainer(new SlotBauble(player, baubles, 5, 27, 8 + 1 * 18)); addSlotToContainer(new SlotBauble(player, baubles, 6, 27, 8 + 2 * 18)); for(i = 0; i < 4; ++i) for(j = 0; j < 6; ++j) { int k = j + i * 6; addSlotToContainer(new SlotItemHandler(baubleBoxInv, k, 62 + j * 18, 8 + i * 18)); } for(i = 0; i < 3; ++i) for(j = 0; j < 9; ++j) addSlotToContainer(new Slot(playerInv, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); for(i = 0; i < 9; ++i) { if(playerInv.getStackInSlot(i) == baubleBoxInv.box) addSlotToContainer(new SlotLocked(playerInv, i, 8 + i * 18, 142)); else addSlotToContainer(new Slot(playerInv, i, 8 + i * 18, 142)); } }
@SubscribeEvent(priority = EventPriority.HIGHEST) public static void onDrawScreenPre(RenderGameOverlayEvent.Pre event) { Minecraft mc = Minecraft.getMinecraft(); Profiler profiler = mc.profiler; if(event.getType() == ElementType.HEALTH) { profiler.startSection("botania-hud"); IItemHandler baublesInv = BaublesApi.getBaublesHandler(mc.player); ItemStack headpiece = baublesInv.getStackInSlot(4); if(!headpiece.isEmpty() && headpiece.getItem() == ModItems.flightTiara) { profiler.startSection("flugelTiara"); ItemFlightTiara.renderHUD(event.getResolution(), mc.player, headpiece); profiler.endSection(); } dodgeRing: { ItemStack ring = baublesInv.getStackInSlot(1); if(ring.isEmpty() || !(ring.getItem() instanceof ItemDodgeRing)) { ring = baublesInv.getStackInSlot(2); if(ring.isEmpty() || !(ring.getItem() instanceof ItemDodgeRing)) break dodgeRing; } profiler.startSection("dodgeRing"); ItemDodgeRing.renderHUD(event.getResolution(), mc.player, ring, event.getPartialTicks()); profiler.endSection(); } profiler.endSection(); } }