Search in sources :

Example 6 with EntityItem

use of net.minecraft.entity.item.EntityItem in project malmo by Microsoft.

the class ObservationFromRayImplementation method buildMouseOverData.

/** Build the json object for the object under the cursor, whether it is a block or a creature.<br>
     * If there is any data to be returned, the json will be added in a subnode called "LineOfSight".
     * @param json a JSON object into which the info for the object under the mouse will be added.
     */
public static void buildMouseOverData(JsonObject json) {
    // We could use Minecraft.getMinecraft().objectMouseOver but it's limited to the block reach distance, and
    // doesn't register floating tile items.
    // Ideally use Minecraft.timer.renderPartialTicks - but we don't need sub-tick resolution.
    float partialTicks = 0;
    Entity viewer = Minecraft.getMinecraft().thePlayer;
    // Hard-coded for now - in future will be parameterised via the XML.
    float depth = 50;
    Vec3 eyePos = viewer.getPositionEyes(partialTicks);
    Vec3 lookVec = viewer.getLook(partialTicks);
    Vec3 searchVec = eyePos.addVector(lookVec.xCoord * depth, lookVec.yCoord * depth, lookVec.zCoord * depth);
    MovingObjectPosition mop = Minecraft.getMinecraft().theWorld.rayTraceBlocks(eyePos, searchVec, false, false, false);
    MovingObjectPosition mopEnt = findEntity(eyePos, lookVec, depth, mop, true);
    if (mopEnt != null)
        mop = mopEnt;
    if (mop == null) {
        // Nothing under the mouse.
        return;
    }
    // Calculate ranges for player interaction:
    double hitDist = mop.hitVec.distanceTo(eyePos);
    double blockReach = Minecraft.getMinecraft().playerController.getBlockReachDistance();
    double entityReach = Minecraft.getMinecraft().playerController.extendedReach() ? 6.0 : 3.0;
    JsonObject jsonMop = new JsonObject();
    if (mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
        // We're looking at a block - send block data:
        jsonMop.addProperty("hitType", "block");
        jsonMop.addProperty("x", mop.hitVec.xCoord);
        jsonMop.addProperty("y", mop.hitVec.yCoord);
        jsonMop.addProperty("z", mop.hitVec.zCoord);
        IBlockState state = Minecraft.getMinecraft().theWorld.getBlockState(mop.getBlockPos());
        List<IProperty> extraProperties = new ArrayList<IProperty>();
        DrawBlock db = MinecraftTypeHelper.getDrawBlockFromBlockState(state, extraProperties);
        jsonMop.addProperty("type", db.getType().value());
        if (db.getColour() != null)
            jsonMop.addProperty("colour", db.getColour().value());
        if (db.getVariant() != null)
            jsonMop.addProperty("variant", db.getVariant().getValue());
        if (db.getFace() != null)
            jsonMop.addProperty("facing", db.getFace().value());
        if (extraProperties.size() > 0) {
            // Add the extra properties that aren't covered by colour/variant/facing.
            for (IProperty prop : extraProperties) {
                String key = "prop_" + prop.getName();
                if (prop.getValueClass() == Boolean.class)
                    jsonMop.addProperty(key, Boolean.valueOf(state.getValue(prop).toString()));
                else if (prop.getValueClass() == Integer.class)
                    jsonMop.addProperty(key, Integer.valueOf(state.getValue(prop).toString()));
                else
                    jsonMop.addProperty(key, state.getValue(prop).toString());
            }
        }
        jsonMop.addProperty("inRange", hitDist <= blockReach);
        jsonMop.addProperty("distance", hitDist);
    } else if (mop.typeOfHit == MovingObjectPosition.MovingObjectType.ENTITY) {
        // Looking at an entity:
        Entity entity = mop.entityHit;
        if (entity != null) {
            jsonMop.addProperty("x", entity.posX);
            jsonMop.addProperty("y", entity.posY);
            jsonMop.addProperty("z", entity.posZ);
            String name = entity.getName();
            String hitType = "entity";
            if (entity instanceof EntityItem) {
                ItemStack is = ((EntityItem) entity).getEntityItem();
                DrawItem di = MinecraftTypeHelper.getDrawItemFromItemStack(is);
                if (di.getColour() != null)
                    jsonMop.addProperty("colour", di.getColour().value());
                if (di.getVariant() != null)
                    jsonMop.addProperty("variant", di.getVariant().getValue());
                jsonMop.addProperty("stackSize", is.stackSize);
                name = di.getType();
                hitType = "item";
            }
            jsonMop.addProperty("type", name);
            jsonMop.addProperty("hitType", hitType);
        }
        jsonMop.addProperty("inRange", hitDist <= entityReach);
        jsonMop.addProperty("distance", hitDist);
    }
    json.add("LineOfSight", jsonMop);
}
Also used : Entity(net.minecraft.entity.Entity) IBlockState(net.minecraft.block.state.IBlockState) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) IProperty(net.minecraft.block.properties.IProperty) Vec3(net.minecraft.util.Vec3) DrawItem(com.microsoft.Malmo.Schemas.DrawItem) DrawBlock(com.microsoft.Malmo.Schemas.DrawBlock) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 7 with EntityItem

use of net.minecraft.entity.item.EntityItem in project PneumaticCraft by MineMaarten.

the class ModelUVLightBox method renderStatic.

@Override
public void renderStatic(float size, TileEntity te) {
    if (te instanceof TileEntityUVLightBox) {
        TileEntityUVLightBox tile = (TileEntityUVLightBox) te;
        renderModel(size, tile.leftConnected, tile.rightConnected, tile.areLightsOn);
        if (blueprintEntity == null) {
            blueprintEntity = new EntityItem(tile.getWorldObj());
            blueprintEntity.setEntityItemStack(new ItemStack(Itemss.PCBBlueprint));
            blueprintEntity.hoverStart = 0.0F;
        }
        if (pcbEntity == null) {
            pcbEntity = new EntityItem(tile.getWorldObj());
            pcbEntity.setEntityItemStack(new ItemStack(Itemss.emptyPCB));
            pcbEntity.hoverStart = 0.0F;
        }
        // getGhostItemScaleFactor(tileGlassBell.getStackInSlot(TileGlassBell.DISPLAY_SLOT_INVENTORY_INDEX));
        float scaleFactor = 1.0F;
        // float rotationAngle = (float) (720.0 *
        // (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL);
        // GL11.glTranslatef(10F / 16F, (float)d1 + 2.0F / 16F, (float)d2 + 0.5F); // size
        // size
        GL11.glTranslatef(0, 22.0F / 16F, 2F / 16F);
        // translateGhostItemByOrientation(ghostEntityItem.getEntityItem(),
        // x, y, z, tileGlassBell.getOrientation());
        GL11.glScalef(scaleFactor, scaleFactor, scaleFactor);
        // GL11.glRotatef(rotationAngle, 0.0F, 1.0F, 0.0F);
        GL11.glRotated(-90, 1, 0, 0);
        //GL11.glRotated(90, 0, 0, 1);
        boolean fancySetting = RenderManager.instance.options.fancyGraphics;
        RenderManager.instance.options.fancyGraphics = true;
        customRenderItem.doRender(blueprintEntity, 0, 0, 0, 0, 0);
        if (tile.inventory[TileEntityUVLightBox.PCB_INDEX] != null && tile.inventory[TileEntityUVLightBox.PCB_INDEX].getItem() == Itemss.emptyPCB) {
            GL11.glTranslated(0, 0, 0.5 / 16D);
            customRenderItem.doRender(pcbEntity, 0, 0, 0, 0, 0);
        }
        RenderManager.instance.options.fancyGraphics = fancySetting;
    } else {
        renderModel(size, false, false, false);
    }
}
Also used : TileEntityUVLightBox(pneumaticCraft.common.tileentity.TileEntityUVLightBox) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 8 with EntityItem

use of net.minecraft.entity.item.EntityItem in project PneumaticCraft by MineMaarten.

the class ModelPressureChamberInterface method renderDynamic.

@Override
public void renderDynamic(float size, TileEntity te, float partialTicks) {
    if (te instanceof TileEntityPressureChamberInterface) {
        TileEntityPressureChamberInterface tile = (TileEntityPressureChamberInterface) te;
        float renderInputProgress = tile.oldInputProgress + (tile.inputProgress - tile.oldInputProgress) * partialTicks;
        float renderOutputProgress = tile.oldOutputProgress + (tile.outputProgress - tile.oldOutputProgress) * partialTicks;
        renderModel(size, renderInputProgress / TileEntityPressureChamberInterface.MAX_PROGRESS, renderOutputProgress / TileEntityPressureChamberInterface.MAX_PROGRESS);
        if (tile.getStackInSlot(0) != null) {
            GL11.glTranslated(0, 17 / 16F, 0);
            GL11.glScalef(1.0F, -1F, -1F);
            // GL11.glRotatef(rotationAngle, 0.0F, 1.0F, 0.0F);
            boolean fancySetting = RenderManager.instance.options.fancyGraphics;
            RenderManager.instance.options.fancyGraphics = true;
            EntityItem ghostItem = new EntityItem(te.getWorldObj(), 0, 0, 0, tile.getStackInSlot(0));
            ghostItem.hoverStart = 0;
            customRenderItem.doRender(ghostItem, 0, 0, 0, 0, 0);
            RenderManager.instance.options.fancyGraphics = fancySetting;
        }
    } else {
        renderModel(size, 0, 0);
    }
}
Also used : TileEntityPressureChamberInterface(pneumaticCraft.common.tileentity.TileEntityPressureChamberInterface) EntityItem(net.minecraft.entity.item.EntityItem)

Example 9 with EntityItem

use of net.minecraft.entity.item.EntityItem in project PneumaticCraft by MineMaarten.

the class RenderEntityChopperSeeds method renderChopperSeeds.

public void renderChopperSeeds(EntityChopperSeeds entity, double x, double y, double z, float var1, float partialTicks) {
    float scaleFactor = 0.7F;
    // start
    GL11.glPushMatrix();
    // size
    GL11.glTranslatef((float) x, (float) y, (float) z);
    // GL11.glScalef(1.0F, -1F, -1F);
    GL11.glScalef(scaleFactor, scaleFactor, scaleFactor);
    EntityItem ghostEntityItem = new EntityItem(entity.worldObj);
    ghostEntityItem.hoverStart = 0.0F;
    ghostEntityItem.setEntityItemStack(iStack);
    double radius = 0.25D;
    for (int i = 0; i < 4; i++) {
        GL11.glPushMatrix();
        GL11.glTranslated(Math.sin(0.5D * Math.PI * i + (entity.ticksExisted + partialTicks) * 0.4D) * radius, 0, Math.cos(0.5D * Math.PI * i + (entity.ticksExisted + partialTicks) * 0.4D) * radius);
        itemRenderer.doRender(ghostEntityItem, 0, 0, 0, 0, 0);
        GL11.glPopMatrix();
    }
    GL11.glPopMatrix();
}
Also used : EntityItem(net.minecraft.entity.item.EntityItem)

Example 10 with EntityItem

use of net.minecraft.entity.item.EntityItem in project PneumaticCraft by MineMaarten.

the class SearchUpgradeHandler method update.

@Override
@SideOnly(Side.CLIENT)
public void update(EntityPlayer player, int rangeUpgrades) {
    ticksExisted++;
    ItemStack searchStack = ItemPneumaticArmor.getSearchedStack(player.getCurrentArmor(3));
    if (ticksExisted % 20 == 0) {
        List<EntityItem> items = player.worldObj.getEntitiesWithinAABB(EntityItem.class, EntityTrackUpgradeHandler.getAABBFromRange(player, rangeUpgrades));
        searchedItems.clear();
        for (EntityItem item : items) {
            if (item.getEntityItem() != null && searchStack != null) {
                if (item.getEntityItem().isItemEqual(searchStack))
                    searchedItems.put(item, item.getEntityItem().stackSize);
                else {
                    List<ItemStack> inventoryItems = PneumaticCraftUtils.getStacksInItem(item.getEntityItem());
                    int itemCount = 0;
                    for (ItemStack inventoryItem : inventoryItems) {
                        if (inventoryItem.isItemEqual(searchStack)) {
                            itemCount += inventoryItem.stackSize;
                        }
                    }
                    if (itemCount > 0)
                        searchedItems.put(item, itemCount);
                }
            }
        }
        totalSearchedItemCount = searchedItemCounter;
        searchedItemCounter = 0;
        for (Integer itemCount : searchedItems.values()) {
            searchedItemCounter += itemCount;
        }
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) SideOnly(cpw.mods.fml.relauncher.SideOnly)

Aggregations

EntityItem (net.minecraft.entity.item.EntityItem)284 ItemStack (net.minecraft.item.ItemStack)178 TileEntity (net.minecraft.tileentity.TileEntity)45 EntityPlayer (net.minecraft.entity.player.EntityPlayer)36 Entity (net.minecraft.entity.Entity)26 ArrayList (java.util.ArrayList)19 BlockPos (net.minecraft.util.math.BlockPos)19 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)18 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)16 World (net.minecraft.world.World)16 Random (java.util.Random)15 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)14 Item (net.minecraft.item.Item)13 IInventory (net.minecraft.inventory.IInventory)12 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)12 List (java.util.List)11 Block (net.minecraft.block.Block)11 EntityLivingBase (net.minecraft.entity.EntityLivingBase)11 IBlockState (net.minecraft.block.state.IBlockState)10 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)6