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);
}
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);
}
}
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);
}
}
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();
}
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;
}
}
}
Aggregations