Search in sources :

Example 36 with EntityPlayer

use of net.minecraft.entity.player.EntityPlayer in project SimplyJetpacks by Tonius.

the class Jetpack method flyUser.

public void flyUser(EntityLivingBase user, ItemStack stack, ItemPack item, boolean force) {
    if (this.isOn(stack)) {
        boolean hoverMode = this.isHoverModeOn(stack);
        double hoverSpeed = Config.invertHoverSneakingBehavior == SyncHandler.isDescendKeyDown(user) ? this.speedVerticalHoverSlow : this.speedVerticalHover;
        boolean flyKeyDown = force || SyncHandler.isFlyKeyDown(user);
        boolean descendKeyDown = SyncHandler.isDescendKeyDown(user);
        double currentAccel = this.accelVertical * (user.motionY < 0.3D ? 2.5D : 1.0D);
        double currentSpeedVertical = this.speedVertical * (user.isInWater() ? 0.4D : 1.0D);
        if (flyKeyDown || hoverMode && !user.onGround) {
            if (this.usesFuel) {
                item.useFuel(stack, (int) (user.isSprinting() ? Math.round(this.getFuelUsage(stack) * this.sprintFuelModifier) : this.getFuelUsage(stack)), false);
            }
            if (item.getFuelStored(stack) > 0) {
                if (flyKeyDown) {
                    if (!hoverMode) {
                        user.motionY = Math.min(user.motionY + currentAccel, currentSpeedVertical);
                    } else {
                        if (descendKeyDown) {
                            user.motionY = Math.min(user.motionY + currentAccel, -this.speedVerticalHoverSlow);
                        } else {
                            user.motionY = Math.min(user.motionY + currentAccel, this.speedVerticalHover);
                        }
                    }
                } else {
                    user.motionY = Math.min(user.motionY + currentAccel, -hoverSpeed);
                }
                float speedSideways = (float) (user.isSneaking() ? this.speedSideways * 0.5F : this.speedSideways);
                float speedForward = (float) (user.isSprinting() ? speedSideways * this.sprintSpeedModifier : speedSideways);
                if (SyncHandler.isForwardKeyDown(user)) {
                    user.moveFlying(0, speedForward, speedForward);
                }
                if (SyncHandler.isBackwardKeyDown(user)) {
                    user.moveFlying(0, -speedSideways, speedSideways * 0.8F);
                }
                if (SyncHandler.isLeftKeyDown(user)) {
                    user.moveFlying(speedSideways, 0, speedSideways);
                }
                if (SyncHandler.isRightKeyDown(user)) {
                    user.moveFlying(-speedSideways, 0, speedSideways);
                }
                if (!user.worldObj.isRemote) {
                    user.fallDistance = 0.0F;
                    if (user instanceof EntityPlayerMP) {
                        ((EntityPlayerMP) user).playerNetServerHandler.floatingTickCount = 0;
                    }
                    if (Config.flammableFluidsExplode) {
                        if (!(user instanceof EntityPlayer) || !((EntityPlayer) user).capabilities.isCreativeMode) {
                            int x = Math.round((float) user.posX - 0.5F);
                            int y = Math.round((float) user.posY);
                            int z = Math.round((float) user.posZ - 0.5F);
                            Block fluidBlock = user.worldObj.getBlock(x, y, z);
                            if (fluidBlock instanceof IFluidBlock && fluidBlock.isFlammable(user.worldObj, x, y, z, ForgeDirection.UNKNOWN)) {
                                user.worldObj.playSoundAtEntity(user, "mob.ghast.fireball", 2.0F, 1.0F);
                                user.worldObj.createExplosion(user, user.posX, user.posY, user.posZ, 3.5F, false);
                                user.attackEntityFrom(new EntityDamageSource("jetpackexplode", user), 100.0F);
                            }
                        }
                    }
                }
            }
        }
    }
    if (!user.worldObj.isRemote && this.emergencyHoverMode && this.isEHoverOn(stack)) {
        if (item.getEnergyStored(stack) > 0 && (!this.isHoverModeOn(stack) || !this.isOn(stack))) {
            if (user.posY < -5) {
                this.doEHover(stack, user);
            } else if (user instanceof EntityPlayer) {
                if (!((EntityPlayer) user).capabilities.isCreativeMode && user.fallDistance - 1.2F >= user.getHealth()) {
                    for (int i = 0; i <= 16; i++) {
                        int x = Math.round((float) user.posX - 0.5F);
                        int y = Math.round((float) user.posY) - i;
                        int z = Math.round((float) user.posZ - 0.5F);
                        if (!user.worldObj.isAirBlock(x, y, z)) {
                            this.doEHover(stack, user);
                            break;
                        }
                    }
                }
            }
        }
    }
}
Also used : IFluidBlock(net.minecraftforge.fluids.IFluidBlock) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) EntityDamageSource(net.minecraft.util.EntityDamageSource)

Example 37 with EntityPlayer

use of net.minecraft.entity.player.EntityPlayer in project SimplyJetpacks by Tonius.

the class JetpackPotato method flyUser.

@Override
public void flyUser(EntityLivingBase user, ItemStack stack, ItemPack item, boolean force) {
    if (this.isFired(stack)) {
        super.flyUser(user, stack, item, true);
        user.rotationYawHead += 37.5F;
        if (item.getFuelStored(stack) <= 0) {
            user.setCurrentItemOrArmor(3, null);
            if (!user.worldObj.isRemote) {
                user.worldObj.createExplosion(user, user.posX, user.posY, user.posZ, 4.0F, false);
                for (int i = 0; i <= MathHelper.RANDOM.nextInt(3) + 4; i++) {
                    ItemStack firework = FireworksHelper.getRandomFireworks(0, 1, MathHelper.RANDOM.nextInt(6) + 1, 1);
                    user.worldObj.spawnEntityInWorld(new EntityFireworkRocket(user.worldObj, user.posX + MathHelper.RANDOM.nextDouble() * 6.0D - 3.0D, user.posY, user.posZ + MathHelper.RANDOM.nextDouble() * 6.0D - 3.0D, firework));
                }
                user.attackEntityFrom(new EntityDamageSource("jetpackpotato", user), 100.0F);
                if (user instanceof EntityPlayer) {
                    user.dropItem(Items.baked_potato, 1);
                }
            }
        }
    } else {
        if (force || SyncHandler.isFlyKeyDown(user)) {
            if (this.isTimerSet(stack)) {
                this.decrementTimer(stack, user);
            } else {
                this.setTimer(stack, 50);
            }
        }
    }
}
Also used : EntityFireworkRocket(net.minecraft.entity.item.EntityFireworkRocket) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) EntityDamageSource(net.minecraft.util.EntityDamageSource)

Example 38 with EntityPlayer

use of net.minecraft.entity.player.EntityPlayer in project BluePower by Qmunity.

the class GuiGateWireless method renderGUI.

@Override
protected void renderGUI(int x, int y, float partialTick) {
    super.renderGUI(x, y, partialTick);
    EntityPlayer player = Minecraft.getMinecraft().thePlayer;
    // Enable/disable components depending on our needs
    {
        String txt = frequencyName.getText();
        removeFrequency.enabled = (gate.getFrequency() != null && (gate.getFrequency().getOwner().equals(player.getGameProfile().getId()) || player.capabilities.isCreativeMode)) || (selected != null && (selected.getOwner().equals(player.getGameProfile().getId()) || player.capabilities.isCreativeMode));
        accessLevel.enabled = selected != null || (txt.trim().length() > 0 && checkNoMatches());
        saveFrequency.enabled = selected != null && (acc != selected.getAccessibility() || (txt.trim().length() > 0 && !txt.trim().equals(selected.getFrequencyName())));
        addFrequency.enabled = selected == null && txt.trim().length() > 0 && checkNoMatches();
    }
    // Render title
    drawCenteredString(fontRendererObj, I18n.format("bluepower.gui.wireless"), guiLeft + (xSize / 2), guiTop + 8, 0xEFEFEF);
    // Filter
    {
        drawCenteredString(fontRendererObj, "Filter", guiLeft + 45, guiTop + 22 + 3, 0xEFEFEF);
        String accessLevelLabel = filterAccessLevel.value == 0 ? "bluepower.accessability.public" : (filterAccessLevel.value == 1 ? "bluepower.accessability.shared" : (filterAccessLevel.value == 2 ? "bluepower.accessability.private" : (filterAccessLevel.value == 3 ? "bluepower.gui.admin" : "bluepower.gui.none")));
        drawString(fontRendererObj, I18n.format(accessLevelLabel), guiLeft + 12 + 14 + 3, guiTop + 35 + 3, filterAccessLevel.enabled ? 0xEFEFEF : 0x565656);
    }
    // Label for the access level
    String accessLevelLabel = accessLevel.value == 0 ? "bluepower.accessability.public" : (accessLevel.value == 1 ? "bluepower.accessability.shared" : "bluepower.accessability.private");
    drawString(fontRendererObj, I18n.format(accessLevelLabel), guiLeft + 10 + 14 + 3, guiTop + ySize - 24 + 3, accessLevel.enabled ? 0xEFEFEF : 0x565656);
    // Label for the mode
    String modeLabel = modeSelector.value == 0 ? "bluepower.mode.sendreceive" : (modeSelector.value == 1 ? "bluepower.mode.send" : "bluepower.mode.receive");
    drawString(fontRendererObj, I18n.format(modeLabel), guiLeft + 10 + 14 + 3, guiTop + 57 + 3, 0xEFEFEF);
    // Render the textbox
    frequencyName.drawTextBox();
    // Get all frequencies and sort them
    List<Frequency> frequencies = getFrequencies();
    // Render the list
    for (int i = 0; i < Math.min(frequencies.size(), 12); i++) {
        Frequency f = frequencies.get(i + scrolled);
        int yPos = guiTop + 22 + 10 + 2 + (i * 12);
        int color = f.equals(gate.getFrequency()) ? 0x00CCCC : (f.equals(selected) ? 0x888888 : ((x > guiLeft + 88 && x <= guiLeft + 88 + 133 - (frequencies.size() > 12 ? 11 : 0) && y > yPos && y <= yPos + 11 && f.isBundled() == gate.isBundled()) ? 0xAAAAAA : 0x333333));
        int textColor = f.equals(gate.getFrequency()) ? 0x333333 : (f.isBundled() != gate.isBundled() ? 0x999999 : 0xFFFFFF);
        drawRect(guiLeft + 88, yPos, guiLeft + 88 + 133 - (frequencies.size() > 12 ? 11 : 0), yPos + 11, (0xFF << 24) + color);
        String format = f.isBundled() != gate.isBundled() ? EnumChatFormatting.STRIKETHROUGH.toString() : "";
        String txt = format + f.getFrequencyName() + ((filterAccessLevel.value == 3 || filterAccessLevel.value == 4) ? " [" + StringUtils.capitalize(f.getAccessibility().name().toLowerCase()) + "]" : "");
        fontRendererObj.drawString(txt, guiLeft + 88 + 2 + 12 + 2, yPos + 2, textColor, !f.equals(gate.getFrequency()));
        ItemStack item = PartManager.getPartInfo("wire.bluestone" + (f.isBundled() ? ".bundled" : "")).getStack();
        GL11.glPushMatrix();
        {
            if (f.isBundled() != gate.isBundled())
                GL11.glEnable(GL11.GL_LIGHTING);
            GL11.glTranslated(guiLeft + 88 + 1, yPos - 2, 0);
            GL11.glScaled(0.75, 0.75, 0.75);
            ForgeHooksClient.renderInventoryItem(RenderBlocks.getInstance(), Minecraft.getMinecraft().renderEngine, item, true, 1, 1, 1);
            if (f.isBundled() != gate.isBundled())
                GL11.glDisable(GL11.GL_LIGHTING);
        }
        GL11.glPopMatrix();
    }
    if (frequencies.size() > 12) {
        drawRect(guiLeft + 88 + 133 - 10, guiTop + 22 + 10 + 2, guiLeft + 88 + 133, guiTop + 22 + 10 + 1 + (12 * 12), 0xFF565656);
    }
    for (int i = 0; i < Math.min(frequencies.size(), 12); i++) {
        Frequency f = frequencies.get(i + scrolled);
        int yPos = guiTop + 22 + 10 + 2 + (i * 12);
        if (x > guiLeft + 88 && x <= guiLeft + 88 + 133 - (frequencies.size() > 12 ? 11 : 0) && y > yPos && y <= yPos + 11 && f.isBundled() == gate.isBundled()) {
            func_146283_a(Arrays.asList("Frequency: " + f.getFrequencyName(), EnumChatFormatting.GRAY + "Accessibility: " + StringUtils.capitalize(f.getAccessibility().name().toLowerCase()), EnumChatFormatting.GRAY + "Owner: " + f.getOwnerName(), "Devices: " + f.getDevices()), x, y);
        }
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) Frequency(com.bluepowermod.part.gate.wireless.Frequency) IFrequency(com.bluepowermod.api.wireless.IFrequency) ItemStack(net.minecraft.item.ItemStack)

Example 39 with EntityPlayer

use of net.minecraft.entity.player.EntityPlayer in project BluePower by Qmunity.

the class ItemScrewdriver method damage.

@Override
public boolean damage(ItemStack stack, int damage, EntityPlayer player, boolean simulated) {
    if (player != null && player.capabilities.isCreativeMode)
        return true;
    if ((stack.getItemDamage() % stack.getMaxDamage()) + damage > stack.getMaxDamage())
        return false;
    if (!simulated) {
        if (stack.attemptDamageItem(damage, new Random())) {
            if (player != null)
                player.renderBrokenItemStack(stack);
            --stack.stackSize;
            if (player != null && player instanceof EntityPlayer)
                player.addStat(StatList.objectBreakStats[Item.getIdFromItem(stack.getItem())], 1);
            if (stack.stackSize < 0)
                stack.stackSize = 0;
            stack.setItemDamage(0);
        }
    }
    return true;
}
Also used : Random(java.util.Random) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 40 with EntityPlayer

use of net.minecraft.entity.player.EntityPlayer in project BluePower by Qmunity.

the class BPEventHandler method dropHeads.

private void dropHeads(LivingDeathEvent event) {
    if (event.entityLiving instanceof EntityCreeper) {
        event.entityLiving.entityDropItem(new ItemStack(Items.skull, 1, 4), 0.0F);
    }
    if (event.entityLiving instanceof EntityPlayer) {
        ItemStack drop = new ItemStack(Items.skull, 1, 3);
        drop.stackTagCompound = new NBTTagCompound();
        drop.stackTagCompound.setString("SkullOwner", ((EntityPlayer) event.entityLiving).getDisplayName());
        event.entityLiving.entityDropItem(drop, 0.0F);
    }
    if (event.entityLiving instanceof EntitySkeleton) {
        EntitySkeleton sk = (EntitySkeleton) event.entityLiving;
        if (sk.getSkeletonType() == 0) {
            event.entityLiving.entityDropItem(new ItemStack(Items.skull, 1, 0), 0.0F);
        } else {
            event.entityLiving.entityDropItem(new ItemStack(Items.skull, 1, 1), 0.0F);
        }
    }
    if (event.entityLiving instanceof EntityZombie) {
        event.entityLiving.entityDropItem(new ItemStack(Items.skull, 1, 2), 0.0F);
    }
}
Also used : EntityCreeper(net.minecraft.entity.monster.EntityCreeper) EntityZombie(net.minecraft.entity.monster.EntityZombie) EntitySkeleton(net.minecraft.entity.monster.EntitySkeleton) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack)

Aggregations

EntityPlayer (net.minecraft.entity.player.EntityPlayer)625 ItemStack (net.minecraft.item.ItemStack)169 EntityLivingBase (net.minecraft.entity.EntityLivingBase)104 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)81 Entity (net.minecraft.entity.Entity)77 World (net.minecraft.world.World)73 BlockPos (net.minecraft.util.math.BlockPos)61 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)49 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)44 TileEntity (net.minecraft.tileentity.TileEntity)43 PotionEffect (net.minecraft.potion.PotionEffect)41 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)38 EntityItem (net.minecraft.entity.item.EntityItem)37 Block (net.minecraft.block.Block)36 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)35 ArrayList (java.util.ArrayList)33 IBlockState (net.minecraft.block.state.IBlockState)33 List (java.util.List)28 TextComponentString (net.minecraft.util.text.TextComponentString)27 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)23