Search in sources :

Example 1 with Entity

use of net.minecraft.entity.Entity in project BetterStorage by copygirl.

the class CommonProxy method onEntityInteract.

@SubscribeEvent
public void onEntityInteract(EntityInteractEvent event) {
    if (event.entity.worldObj.isRemote || event.isCanceled())
        return;
    EntityPlayer player = event.entityPlayer;
    Entity target = event.target;
    ItemStack holding = player.getCurrentEquippedItem();
    if ((target.getClass() == EntityChicken.class) && (holding != null) && (holding.getItem() == Items.name_tag)) {
        EntityChicken chicken = (EntityChicken) target;
        if (!chicken.isDead && !chicken.isChild() && "Cluckington".equals(holding.getDisplayName()))
            EntityCluckington.spawn(chicken);
    }
    if ((BetterStorageItems.slimeBucket != null) && (target instanceof EntityLiving) && (holding != null) && (holding.getItem() == Items.bucket)) {
        ItemBucketSlime.pickUpSlime(player, (EntityLiving) target);
        if (player.getCurrentEquippedItem().getItem() instanceof ItemBucketSlime)
            preventSlimeBucketUse = true;
    }
}
Also used : Entity(net.minecraft.entity.Entity) EntityChicken(net.minecraft.entity.passive.EntityChicken) EntityLiving(net.minecraft.entity.EntityLiving) ItemBucketSlime(net.mcft.copy.betterstorage.item.ItemBucketSlime) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 2 with Entity

use of net.minecraft.entity.Entity in project BetterStorage by copygirl.

the class ItemBucketSlime method onItemUse.

@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
    // instead of placing it in the world.
    if (player.isSneaking())
        return false;
    if (world.isRemote)
        return true;
    x += Facing.offsetsXForSide[side];
    y += Facing.offsetsYForSide[side];
    z += Facing.offsetsZForSide[side];
    String id = getSlimeId(stack);
    String name = StackUtils.get(stack, (String) null, "Slime", "name");
    Entity entity = EntityList.createEntityByName(id, world);
    Handler handler = getHandler(id);
    if ((entity != null) && (handler != null) && (entity instanceof EntityLiving)) {
        EntityLiving slime = (EntityLiving) entity;
        float rotation = MathHelper.wrapAngleTo180_float(world.rand.nextFloat() * 360.0F);
        slime.setLocationAndAngles(x + 0.5, y, z + 0.5, rotation, 0.0F);
        slime.rotationYawHead = slime.renderYawOffset = rotation;
        if (name != null)
            slime.setCustomNameTag(name);
        handler.setSize(slime, 1);
        NBTTagList effectList = (NBTTagList) StackUtils.getTag(stack, "Effects");
        if (effectList != null)
            for (int i = 0; i < effectList.tagCount(); i++) slime.addPotionEffect(PotionEffect.readCustomPotionEffectFromNBT(effectList.getCompoundTagAt(i)));
        world.spawnEntityInWorld(slime);
        slime.playSound("mob.slime.big", 1.2F, 0.6F);
        player.setCurrentItemOrArmor(EquipmentSlot.HELD, new ItemStack(Items.bucket));
    }
    return true;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) Entity(net.minecraft.entity.Entity) EntityLiving(net.minecraft.entity.EntityLiving) ItemStack(net.minecraft.item.ItemStack)

Example 3 with Entity

use of net.minecraft.entity.Entity in project SimplyJetpacks by Tonius.

the class ClientTickHandler method tickEnd.

private static void tickEnd() {
    if (mc.thePlayer == null || mc.theWorld == null) {
        return;
    }
    if (!mc.isGamePaused()) {
        Iterator<Integer> itr = SyncHandler.getJetpackStates().keySet().iterator();
        int currentEntity;
        while (itr.hasNext()) {
            currentEntity = itr.next();
            Entity entity = mc.theWorld.getEntityByID(currentEntity);
            if (entity == null || !(entity instanceof EntityLivingBase) || entity.dimension != mc.thePlayer.dimension) {
                itr.remove();
            } else {
                ParticleType particle = SyncHandler.getJetpackStates().get(currentEntity);
                if (particle != null) {
                    if (entity.isInWater() && particle != ParticleType.NONE) {
                        particle = ParticleType.BUBBLE;
                    }
                    SimplyJetpacks.proxy.showJetpackParticles(mc.theWorld, (EntityLivingBase) entity, particle);
                    if (Config.jetpackSounds && !SoundJetpack.isPlayingFor(entity.getEntityId())) {
                        Minecraft.getMinecraft().getSoundHandler().playSound(new SoundJetpack((EntityLivingBase) entity));
                    }
                } else {
                    itr.remove();
                }
            }
        }
    }
    if (sprintKeyCheck && mc.thePlayer.movementInput.moveForward < 1.0F) {
        sprintKeyCheck = false;
    }
    if (!Config.doubleTapSprintInAir || !wearingJetpack || mc.thePlayer.onGround || mc.thePlayer.isSprinting() || mc.thePlayer.isUsingItem() || mc.thePlayer.isPotionActive(Potion.blindness)) {
        return;
    }
    if (!sprintKeyCheck && mc.thePlayer.movementInput.moveForward >= 1.0F && !mc.thePlayer.isCollidedHorizontally && (mc.thePlayer.getFoodStats().getFoodLevel() > 6.0F || mc.thePlayer.capabilities.allowFlying)) {
        if (mc.thePlayer.sprintToggleTimer <= 0 && !mc.gameSettings.keyBindSprint.getIsKeyPressed()) {
            mc.thePlayer.sprintToggleTimer = 7;
            sprintKeyCheck = true;
        } else {
            mc.thePlayer.setSprinting(true);
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) EntityLivingBase(net.minecraft.entity.EntityLivingBase) ParticleType(tonius.simplyjetpacks.setup.ParticleType) SoundJetpack(tonius.simplyjetpacks.client.audio.SoundJetpack)

Example 4 with Entity

use of net.minecraft.entity.Entity in project SimplyJetpacks by Tonius.

the class MessageJetpackSync method onMessage.

@Override
public IMessage onMessage(MessageJetpackSync msg, MessageContext ctx) {
    Entity entity = FMLClientHandler.instance().getClient().theWorld.getEntityByID(msg.entityId);
    if (entity != null && entity instanceof EntityLivingBase && entity != FMLClientHandler.instance().getClient().thePlayer) {
        if (msg.particleId >= 0) {
            ParticleType particle = ParticleType.values()[msg.particleId];
            SyncHandler.processJetpackUpdate(msg.entityId, particle);
        } else {
            SyncHandler.processJetpackUpdate(msg.entityId, null);
        }
    }
    return null;
}
Also used : Entity(net.minecraft.entity.Entity) EntityLivingBase(net.minecraft.entity.EntityLivingBase) ParticleType(tonius.simplyjetpacks.setup.ParticleType)

Example 5 with Entity

use of net.minecraft.entity.Entity in project malmo by Microsoft.

the class DiscreteMovementCommandsImplementation method onExecute.

@Override
protected boolean onExecute(String verb, String parameter, MissionInit missionInit) {
    boolean handled = false;
    EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
    if (player != null) {
        int z = 0;
        int x = 0;
        int y = 0;
        DiscreteMovementCommand command = verbToCommand(verb);
        if (command == null)
            // Did not recognise this command.
            return false;
        switch(command) {
            case MOVENORTH:
            case JUMPNORTH:
                z = -1;
                break;
            case MOVESOUTH:
            case JUMPSOUTH:
                z = 1;
                break;
            case MOVEEAST:
            case JUMPEAST:
                x = 1;
                break;
            case MOVEWEST:
            case JUMPWEST:
                x = -1;
                break;
            case MOVE:
            case JUMPMOVE:
            case STRAFE:
            case JUMPSTRAFE:
                if (parameter != null && parameter.length() != 0) {
                    float velocity = Float.valueOf(parameter);
                    int offset = (velocity > 0) ? 1 : ((velocity < 0) ? -1 : 0);
                    int direction = getDirectionFromYaw(player.rotationYaw);
                    // For strafing, add one to direction:
                    if (command == DiscreteMovementCommand.STRAFE || command == DiscreteMovementCommand.JUMPSTRAFE)
                        direction = (direction + 1) % 4;
                    switch(direction) {
                        case // North
                        0:
                            z = offset;
                            break;
                        case // East
                        1:
                            x = -offset;
                            break;
                        case // South
                        2:
                            z = -offset;
                            break;
                        case // West
                        3:
                            x = offset;
                            break;
                    }
                    break;
                }
            case TURN:
                if (parameter != null && parameter.length() != 0) {
                    float yawDelta = Float.valueOf(parameter);
                    int direction = getDirectionFromYaw(player.rotationYaw);
                    direction += (yawDelta > 0) ? 1 : ((yawDelta < 0) ? -1 : 0);
                    direction = (direction + 4) % 4;
                    player.rotationYaw = direction * 90;
                    player.onUpdate();
                    // Send a message that the ContinuousMovementCommands can pick up on:
                    Event event = new CommandForWheeledRobotNavigationImplementation.ResetPitchAndYawEvent(true, player.rotationYaw, false, 0);
                    MinecraftForge.EVENT_BUS.post(event);
                    handled = true;
                }
                break;
            case LOOK:
                if (parameter != null && parameter.length() != 0) {
                    float pitchDelta = Float.valueOf(parameter);
                    player.rotationPitch += (pitchDelta < 0) ? -45 : ((pitchDelta > 0) ? 45 : 0);
                    player.onUpdate();
                    // Send a message that the ContinuousMovementCommands can pick up on:
                    Event event = new CommandForWheeledRobotNavigationImplementation.ResetPitchAndYawEvent(false, 0, true, player.rotationPitch);
                    MinecraftForge.EVENT_BUS.post(event);
                    handled = true;
                }
                break;
            case ATTACK:
                {
                    MovingObjectPosition mop = Minecraft.getMinecraft().objectMouseOver;
                    if (mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
                        BlockPos hitPos = mop.getBlockPos();
                        EnumFacing face = mop.sideHit;
                        IBlockState iblockstate = player.worldObj.getBlockState(hitPos);
                        Block block = iblockstate.getBlock();
                        if (block.getMaterial() != Material.air) {
                            MalmoMod.network.sendToServer(new AttackActionMessage(hitPos, face));
                            // Trigger a reward for collecting the block
                            java.util.List<ItemStack> items = block.getDrops(player.worldObj, hitPos, iblockstate, 0);
                            for (ItemStack item : items) {
                                RewardForCollectingItemImplementation.GainItemEvent event = new RewardForCollectingItemImplementation.GainItemEvent(item);
                                MinecraftForge.EVENT_BUS.post(event);
                            }
                        }
                    }
                    handled = true;
                    break;
                }
            case USE:
            case JUMPUSE:
                {
                    MovingObjectPosition mop = getObjectMouseOver(command);
                    if (mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
                        if (player.getCurrentEquippedItem() != null) {
                            ItemStack itemStack = player.getCurrentEquippedItem();
                            Block b = Block.getBlockFromItem(itemStack.getItem());
                            if (b != null) {
                                BlockPos pos = mop.getBlockPos().add(mop.sideHit.getDirectionVec());
                                // Can we place this block here?
                                AxisAlignedBB axisalignedbb = b.getCollisionBoundingBox(player.worldObj, pos, b.getDefaultState());
                                Entity exceptedEntity = (command == DiscreteMovementCommand.USE) ? null : player;
                                // (Not ideal, but needed by jump-use to allow the player to place a block where their feet would be.)
                                if (axisalignedbb == null || player.worldObj.checkNoEntityCollision(axisalignedbb, exceptedEntity)) {
                                    boolean standOnBlockPlaced = (command == DiscreteMovementCommand.JUMPUSE && mop.getBlockPos().equals(new BlockPos(player.posX, player.posY - 1, player.posZ)));
                                    MalmoMod.network.sendToServer(new UseActionMessage(mop.getBlockPos(), itemStack, mop.sideHit, standOnBlockPlaced));
                                }
                            }
                        }
                    }
                    handled = true;
                    break;
                }
            case JUMP:
                // Handled below.
                break;
        }
        // Handle jumping cases:
        if (command == DiscreteMovementCommand.JUMP || command == DiscreteMovementCommand.JUMPNORTH || command == DiscreteMovementCommand.JUMPEAST || command == DiscreteMovementCommand.JUMPSOUTH || command == DiscreteMovementCommand.JUMPWEST || command == DiscreteMovementCommand.JUMPMOVE || command == DiscreteMovementCommand.JUMPUSE || command == DiscreteMovementCommand.JUMPSTRAFE)
            y = 1;
        if (this.params.isAutoJump() && y == 0 && (z != 0 || x != 0)) {
            // Do we need to jump?
            if (!player.worldObj.getCollidingBoundingBoxes(player, player.getEntityBoundingBox().offset(x, 0, z)).isEmpty())
                y = 1;
        }
        if (z != 0 || x != 0 || y != 0) {
            // Attempt to move the entity:
            double oldX = player.posX;
            double oldZ = player.posZ;
            player.moveEntity(x, y, z);
            player.onUpdate();
            if (this.params.isAutoFall()) {
                // Did we step off a block? If so, attempt to fast-forward our fall.
                // Give up after this many attempts
                int bailCountdown = 256;
                // (This is needed because, for example, if the player is caught in a web, the downward movement will have no effect.)
                while (!player.onGround && !player.capabilities.isFlying && bailCountdown > 0) {
                    // Fast-forward downwards.
                    player.moveEntity(0, Math.floor(player.posY - 0.0000001) - player.posY, 0);
                    player.onUpdate();
                    bailCountdown--;
                }
            }
            // Now check where we ended up:
            double newX = player.posX;
            double newZ = player.posZ;
            // Are we still in the centre of a square, or did we get shunted?
            double offsetX = newX - Math.floor(newX);
            double offsetZ = newZ - Math.floor(newZ);
            if (Math.abs(offsetX - 0.5) + Math.abs(offsetZ - 0.5) > 0.01) {
                // We failed to move to the centre of the target square.
                // This might be because the target square was occupied, and we
                // were shunted back into our source square,
                // or it might be that the target square is occupied by something smaller
                // than one block (eg a fence post), and we're in the target square but
                // shunted off-centre.
                // Either way, we can't stay here, so move back to our original position.
                // Before we do that, fire off a message - this will give the TouchingBlockType handlers
                // a chance to react to the current position:
                DiscretePartialMoveEvent event = new DiscretePartialMoveEvent(player.posX, player.posY, player.posZ);
                MinecraftForge.EVENT_BUS.post(event);
                // Now adjust the player:
                player.moveEntity(oldX - newX, 0, oldZ - newZ);
                player.onUpdate();
            }
            // Now set the last tick pos values, to turn off inter-tick positional interpolation:
            player.lastTickPosX = player.posX;
            player.lastTickPosY = player.posY;
            player.lastTickPosZ = player.posZ;
            try {
                MalmoMod.getPropertiesForCurrentThread().put(MOVE_ATTEMPTED_KEY, true);
            } catch (Exception e) {
                // TODO - proper error reporting.
                System.out.println("Failed to access properties for the client thread after discrete movement - reward may be incorrect.");
            }
            handled = true;
        }
    }
    return handled;
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) Entity(net.minecraft.entity.Entity) EnumFacing(net.minecraft.util.EnumFacing) DiscreteMovementCommand(com.microsoft.Malmo.Schemas.DiscreteMovementCommand) BlockPos(net.minecraft.util.BlockPos) IBlockState(net.minecraft.block.state.IBlockState) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) PlayerInteractEvent(net.minecraftforge.event.entity.player.PlayerInteractEvent) Event(net.minecraftforge.fml.common.eventhandler.Event) BlockEvent(net.minecraftforge.event.world.BlockEvent) Block(net.minecraft.block.Block) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) ItemStack(net.minecraft.item.ItemStack)

Aggregations

Entity (net.minecraft.entity.Entity)249 EntityPlayer (net.minecraft.entity.player.EntityPlayer)68 EntityLivingBase (net.minecraft.entity.EntityLivingBase)64 TileEntity (net.minecraft.tileentity.TileEntity)61 ItemStack (net.minecraft.item.ItemStack)47 BlockPos (net.minecraft.util.math.BlockPos)31 ArrayList (java.util.ArrayList)30 Vec3d (net.minecraft.util.math.Vec3d)27 EntityItem (net.minecraft.entity.item.EntityItem)24 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)24 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)24 List (java.util.List)22 Block (net.minecraft.block.Block)22 IBlockState (net.minecraft.block.state.IBlockState)21 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)21 World (net.minecraft.world.World)20 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)18 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)17 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)15 EntityLiving (net.minecraft.entity.EntityLiving)14