Search in sources :

Example 1 with SlotNotation

use of convenientadditions.api.inventory.SlotNotation in project ConvenientAdditions by Necr0.

the class PlayerInventoryTickHandler method onPlayerInventoryTick.

@SubscribeEvent
public void onPlayerInventoryTick(TickEvent.PlayerTickEvent e) {
    EntityPlayer player = e.player;
    Iterable<SlotNotation> iter = InventoryIterator.getIterable(player, EnumInventory.MAIN);
    for (SlotNotation slot : iter) {
        ItemStack stack = slot.getItem();
        if (stack != null && stack.getItem() instanceof IPlayerInventoryTick) {
            ((IPlayerInventoryTick) stack.getItem()).onPlayerInventoryTick(stack, slot, player);
            ;
        }
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) IPlayerInventoryTick(convenientadditions.api.item.IPlayerInventoryTick) ItemStack(net.minecraft.item.ItemStack) SlotNotation(convenientadditions.api.inventory.SlotNotation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with SlotNotation

use of convenientadditions.api.inventory.SlotNotation in project ConvenientAdditions by Necr0.

the class ItemClimbingClaws method onLivingUpdate.

@SubscribeEvent
public void onLivingUpdate(LivingEvent.LivingUpdateEvent event) {
    if (event.getEntityLiving() instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) event.getEntityLiving();
        for (SlotNotation slot : InventoryIterator.getIterable(player, EnumInventory.BAUBLES)) {
            ItemStack stack = slot.getItem();
            if (!stack.isEmpty() && stack.getItem() instanceof ItemClimbingClaws) {
                ItemClimbingClaws item = (ItemClimbingClaws) stack.getItem();
                if (item.wallClimbSpeed > 0) {
                    Vec3d ppos = new Vec3d(player.posX, player.posY, player.posZ);
                    Vec3d plook = player.getLookVec();
                    plook = plook.subtract(0, plook.yCoord, 0).normalize();
                    RayTraceResult r = player.world.rayTraceBlocks(ppos, ppos.add(plook.scale(.425)), false, true, false);
                    if (r != null && r.typeOfHit == RayTraceResult.Type.BLOCK) {
                        IBlockState state = player.world.getBlockState(r.getBlockPos());
                        if (state.isSideSolid(player.world, r.getBlockPos(), r.sideHit)) {
                            if (player.isSneaking()) {
                                if (player.moveForward > 0F) {
                                    player.motionY = Math.max(item.wallClimbSpeed, player.motionY);
                                } else {
                                    player.motionY = Math.max(0d, player.motionY);
                                }
                                player.fallDistance = 0;
                            } else {
                                player.motionY = Math.max(player.motionY, Math.min(player.motionY + .1d, -.15d));
                                if (player.motionY > -.666)
                                    player.fallDistance = 0;
                            }
                        }
                    }
                    break;
                }
            }
        }
        for (SlotNotation slot : InventoryIterator.getIterable(player, EnumInventory.BAUBLES)) {
            ItemStack stack = slot.getItem();
            if (!stack.isEmpty() && stack.getItem() instanceof ItemClimbingClaws) {
                ItemClimbingClaws item = (ItemClimbingClaws) stack.getItem();
                if (item.stepHeightBoost > 0) {
                    if (player.isSneaking())
                        player.stepHeight = .6f;
                    else
                        player.stepHeight = .6f + item.stepHeightBoost;
                    break;
                }
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SlotNotation(convenientadditions.api.inventory.SlotNotation) Vec3d(net.minecraft.util.math.Vec3d) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with SlotNotation

use of convenientadditions.api.inventory.SlotNotation in project ConvenientAdditions by Necr0.

the class ItemMultiJumpTrinket method onPlayerJump.

@SubscribeEvent
public void onPlayerJump(LivingEvent.LivingJumpEvent event) {
    if (event.getEntityLiving() instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) event.getEntityLiving();
        for (SlotNotation slot : InventoryIterator.getIterable(player, EnumInventory.BAUBLES)) {
            ItemStack stack = slot.getItem();
            if (!stack.isEmpty() && stack.getItem() instanceof ItemMultiJumpTrinket) {
                ItemMultiJumpTrinket item = (ItemMultiJumpTrinket) stack.getItem();
                if (item.jumpBoost > 0) {
                    player.motionY += item.jumpBoost;
                    if (player.fallDistance > 0)
                        player.fallDistance = 0;
                    player.fallDistance -= item.fallBuffer;
                    break;
                }
            }
        }
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SlotNotation(convenientadditions.api.inventory.SlotNotation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with SlotNotation

use of convenientadditions.api.inventory.SlotNotation in project ConvenientAdditions by Necr0.

the class ItemMultiJumpTrinket method onPlayerMovementJump.

@SubscribeEvent
public void onPlayerMovementJump(PlayerMovementEvent.PlayerJumpEvent event) {
    EntityPlayer player = event.getPlayer();
    if (!player.isAirBorne)
        return;
    int jumpTicks = 0;
    try {
        jumpTicks = ReflectionHelper.getPrivateValue(EntityLivingBase.class, player, "jumpTicks", "field_70773_bE");
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (jumpTicks == 10)
        return;
    for (SlotNotation slot : InventoryIterator.getIterable(player, EnumInventory.BAUBLES)) {
        ItemStack stack = slot.getItem();
        if (!stack.isEmpty() && stack.getItem() instanceof ItemMultiJumpTrinket) {
            ItemMultiJumpTrinket item = (ItemMultiJumpTrinket) stack.getItem();
            if (item.jumps > 0) {
                if (item.canDoubleJump(null, stack)) {
                    player.motionY = 0;
                    player.fallDistance = 0;
                    player.jump();
                    item.setJump(stack, (byte) (getJump(stack) + 1));
                    ModNetworking.INSTANCE.sendToServer(new PacketDoubleJump(slot));
                }
                break;
            }
        }
    }
}
Also used : EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SlotNotation(convenientadditions.api.inventory.SlotNotation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 5 with SlotNotation

use of convenientadditions.api.inventory.SlotNotation in project ConvenientAdditions by Necr0.

the class ItemSpeedTrinket method onLivingUpdate.

@SubscribeEvent
public void onLivingUpdate(LivingEvent.LivingUpdateEvent event) {
    if (event.getEntityLiving() instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) event.getEntityLiving();
        if (!player.isSneaking()) {
            if ((player.onGround || player.capabilities.isFlying) && player.moveForward > 0F && !player.isInWater()) {
                for (SlotNotation slot : InventoryIterator.getIterable(player, EnumInventory.BAUBLES)) {
                    ItemStack stack = slot.getItem();
                    if (!stack.isEmpty() && stack.getItem() instanceof ItemSpeedTrinket) {
                        ItemSpeedTrinket item = (ItemSpeedTrinket) stack.getItem();
                        if (item.speedBoost > 0) {
                            player.moveRelative(0F, 1F, item.speedBoost);
                            break;
                        }
                    }
                }
            }
            if (!player.onGround && !player.isInWater() && player.fallDistance != 0 && player.motionY < 0 && !player.isElytraFlying()) {
                for (SlotNotation slot : InventoryIterator.getIterable(player, EnumInventory.BAUBLES)) {
                    ItemStack stack = slot.getItem();
                    if (!stack.isEmpty() && stack.getItem() instanceof ItemSpeedTrinket) {
                        ItemSpeedTrinket item = (ItemSpeedTrinket) stack.getItem();
                        if (item.glidingLift != 0) {
                            player.motionY = Math.max(player.motionY, item.glidingLift / 2);
                            player.fallDistance = 0;
                            if (player.moveForward > 0F) {
                                for (SlotNotation slot1 : InventoryIterator.getIterable(player, EnumInventory.BAUBLES)) {
                                    ItemStack stack1 = slot1.getItem();
                                    if (!stack1.isEmpty() && stack1.getItem() instanceof ItemSpeedTrinket) {
                                        ItemSpeedTrinket item1 = (ItemSpeedTrinket) stack1.getItem();
                                        if (item1.glidingSpeed > 0) {
                                            player.moveRelative(0F, 1F, item1.glidingSpeed / 5);
                                            break;
                                        }
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
            }
        }
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SlotNotation(convenientadditions.api.inventory.SlotNotation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

SlotNotation (convenientadditions.api.inventory.SlotNotation)5 EntityPlayer (net.minecraft.entity.player.EntityPlayer)5 ItemStack (net.minecraft.item.ItemStack)5 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)5 IPlayerInventoryTick (convenientadditions.api.item.IPlayerInventoryTick)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 Vec3d (net.minecraft.util.math.Vec3d)1