Search in sources :

Example 21 with EntityPlayerSP

use of net.minecraft.client.entity.EntityPlayerSP in project malmo by Microsoft.

the class ObservationFromFullInventoryImplementation method getInventoryJSON.

public static void getInventoryJSON(JsonObject json, String prefix, int maxSlot) {
    EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
    int nSlots = Math.min(player.inventory.getSizeInventory(), maxSlot);
    for (int i = 0; i < nSlots; i++) {
        ItemStack is = player.inventory.getStackInSlot(i);
        if (is != null) {
            json.addProperty(prefix + i + "_size", is.stackSize);
            DrawItem di = MinecraftTypeHelper.getDrawItemFromItemStack(is);
            String name = di.getType();
            if (di.getColour() != null)
                json.addProperty(prefix + i + "_colour", di.getColour().value());
            if (di.getVariant() != null)
                json.addProperty(prefix + i + "_variant", di.getVariant().getValue());
            json.addProperty(prefix + i + "_item", name);
        }
    }
}
Also used : DrawItem(com.microsoft.Malmo.Schemas.DrawItem) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) ItemStack(net.minecraft.item.ItemStack)

Example 22 with EntityPlayerSP

use of net.minecraft.client.entity.EntityPlayerSP in project malmo by Microsoft.

the class ObservationFromFullInventoryImplementation method writeObservationsToJSON.

@Override
public void writeObservationsToJSON(JsonObject json, MissionInit missionInit) {
    EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
    getInventoryJSON(json, "InventorySlot_", player.inventory.getSizeInventory());
}
Also used : EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP)

Example 23 with EntityPlayerSP

use of net.minecraft.client.entity.EntityPlayerSP in project MinecraftForge by MinecraftForge.

the class EntitySpawnHandler method spawnEntity.

private void spawnEntity(FMLMessage.EntitySpawnMessage spawnMsg) {
    ModContainer mc = Loader.instance().getIndexedModList().get(spawnMsg.modId);
    EntityRegistration er = EntityRegistry.instance().lookupModSpawn(mc, spawnMsg.modEntityTypeId);
    if (er == null) {
        throw new RuntimeException("Could not spawn mod entity ModID: " + spawnMsg.modId + " EntityID: " + spawnMsg.modEntityTypeId + " at ( " + spawnMsg.rawX + "," + spawnMsg.rawY + ", " + spawnMsg.rawZ + ") Please contact mod author or server admin.");
    }
    WorldClient wc = FMLClientHandler.instance().getWorldClient();
    Class<? extends Entity> cls = er.getEntityClass();
    try {
        Entity entity;
        if (er.hasCustomSpawning()) {
            entity = er.doCustomSpawning(spawnMsg);
        } else {
            entity = cls.getConstructor(World.class).newInstance(wc);
            int offset = spawnMsg.entityId - entity.getEntityId();
            entity.setEntityId(spawnMsg.entityId);
            entity.setUniqueId(spawnMsg.entityUUID);
            entity.setLocationAndAngles(spawnMsg.rawX, spawnMsg.rawY, spawnMsg.rawZ, spawnMsg.scaledYaw, spawnMsg.scaledPitch);
            if (entity instanceof EntityLiving) {
                ((EntityLiving) entity).rotationYawHead = spawnMsg.scaledHeadYaw;
            }
            Entity[] parts = entity.getParts();
            if (parts != null) {
                for (int j = 0; j < parts.length; j++) {
                    parts[j].setEntityId(parts[j].getEntityId() + offset);
                }
            }
        }
        EntityTracker.updateServerPosition(entity, spawnMsg.rawX, spawnMsg.rawY, spawnMsg.rawZ);
        EntityPlayerSP clientPlayer = FMLClientHandler.instance().getClientPlayerEntity();
        if (entity instanceof IThrowableEntity) {
            Entity thrower = clientPlayer.getEntityId() == spawnMsg.throwerId ? clientPlayer : wc.getEntityByID(spawnMsg.throwerId);
            ((IThrowableEntity) entity).setThrower(thrower);
        }
        if (spawnMsg.dataWatcherList != null) {
            entity.getDataManager().setEntryValues(spawnMsg.dataWatcherList);
        }
        if (spawnMsg.throwerId > 0) {
            entity.setVelocity(spawnMsg.speedScaledX, spawnMsg.speedScaledY, spawnMsg.speedScaledZ);
        }
        if (entity instanceof IEntityAdditionalSpawnData) {
            ((IEntityAdditionalSpawnData) entity).readSpawnData(spawnMsg.dataStream);
        }
        wc.addEntityToWorld(spawnMsg.entityId, entity);
    } catch (Exception e) {
        FMLLog.log(Level.ERROR, e, "A severe problem occurred during the spawning of an entity at ( " + spawnMsg.rawX + "," + spawnMsg.rawY + ", " + spawnMsg.rawZ + ")");
        throw Throwables.propagate(e);
    }
}
Also used : IEntityAdditionalSpawnData(net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData) Entity(net.minecraft.entity.Entity) IThrowableEntity(net.minecraftforge.fml.common.registry.IThrowableEntity) ModContainer(net.minecraftforge.fml.common.ModContainer) EntityLiving(net.minecraft.entity.EntityLiving) IThrowableEntity(net.minecraftforge.fml.common.registry.IThrowableEntity) WorldClient(net.minecraft.client.multiplayer.WorldClient) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) EntityRegistration(net.minecraftforge.fml.common.registry.EntityRegistry.EntityRegistration)

Example 24 with EntityPlayerSP

use of net.minecraft.client.entity.EntityPlayerSP in project LogisticsPipes by RS485.

the class ModuleCrafter method openAttachedGui.

public void openAttachedGui(EntityPlayer player) {
    if (MainProxy.isClient(player.worldObj)) {
        if (player instanceof EntityPlayerMP) {
            player.closeScreen();
        } else if (player instanceof EntityPlayerSP) {
            player.closeScreen();
        }
        MainProxy.sendPacketToServer(PacketHandler.getPacket(CraftingPipeOpenConnectedGuiPacket.class).setModulePos(this));
        return;
    }
    // hack to avoid wrenching blocks
    int savedEquipped = player.inventory.currentItem;
    boolean foundSlot = false;
    // try to find a empty slot
    for (int i = 0; i < 9; i++) {
        if (player.inventory.getStackInSlot(i) == null) {
            foundSlot = true;
            player.inventory.currentItem = i;
            break;
        }
    }
    // okay, anything that's a block?
    if (!foundSlot) {
        for (int i = 0; i < 9; i++) {
            ItemStack is = player.inventory.getStackInSlot(i);
            if (is.getItem() instanceof ItemBlock) {
                foundSlot = true;
                player.inventory.currentItem = i;
                break;
            }
        }
    }
    // give up and select whatever is right of the current slot
    if (!foundSlot) {
        player.inventory.currentItem = (player.inventory.currentItem + 1) % 9;
    }
    WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(getWorld(), getX(), getY(), getZ());
    worldCoordinates.getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).anyMatch(adjacent -> {
        boolean found = SimpleServiceLocator.craftingRecipeProviders.stream().anyMatch(provider -> provider.canOpenGui(adjacent.tileEntity));
        if (!found) {
            found = (adjacent.tileEntity instanceof IInventory);
        }
        if (found) {
            Block block = getWorld().getBlock(adjacent.tileEntity.xCoord, adjacent.tileEntity.yCoord, adjacent.tileEntity.zCoord);
            if (block != null && block.onBlockActivated(getWorld(), adjacent.tileEntity.xCoord, adjacent.tileEntity.yCoord, adjacent.tileEntity.zCoord, player, 0, 0, 0, 0)) {
                return true;
            }
        }
        return false;
    });
    player.inventory.currentItem = savedEquipped;
}
Also used : IInventory(net.minecraft.inventory.IInventory) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock)

Example 25 with EntityPlayerSP

use of net.minecraft.client.entity.EntityPlayerSP in project ArsMagica2 by Mithion.

the class SpellBase method onUpdate.

@Override
@SideOnly(Side.CLIENT)
public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5) {
    super.onUpdate(stack, world, entity, par4, par5);
    if (entity instanceof EntityPlayerSP) {
        EntityPlayerSP player = (EntityPlayerSP) entity;
        ItemStack usingItem = player.getItemInUse();
        if (usingItem != null && usingItem.getItem() == this) {
            if (SkillData.For(player).isEntryKnown(SkillTreeManager.instance.getSkillTreeEntry(SkillManager.instance.getSkill("SpellMotion")))) {
                player.movementInput.moveForward *= 2.5F;
                player.movementInput.moveStrafe *= 2.5F;
            }
        }
    }
}
Also used : EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) ItemStack(net.minecraft.item.ItemStack) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Aggregations

EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)44 ItemStack (net.minecraft.item.ItemStack)9 Entity (net.minecraft.entity.Entity)7 BlockPos (net.minecraft.util.math.BlockPos)6 Minecraft (net.minecraft.client.Minecraft)5 WorldClient (net.minecraft.client.multiplayer.WorldClient)5 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)5 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)4 SideOnly (cpw.mods.fml.relauncher.SideOnly)3 ArrayList (java.util.ArrayList)3 RailcraftContainer (mods.railcraft.common.gui.containers.RailcraftContainer)3 World (net.minecraft.world.World)3 JsonObject (com.google.gson.JsonObject)2 DrawItem (com.microsoft.Malmo.Schemas.DrawItem)2 EntityTypes (com.microsoft.Malmo.Schemas.EntityTypes)2 List (java.util.List)2 UUID (java.util.UUID)2 IBlockState (net.minecraft.block.state.IBlockState)2 NetworkPlayerInfo (net.minecraft.client.network.NetworkPlayerInfo)2