use of net.minecraft.util.MovingObjectPosition in project SecurityCraft by Geforce132.
the class TileEntitySCTE method updateEntity.
public void updateEntity() {
if (viewActivated) {
if (blockPlaceCooldown > 0) {
blockPlaceCooldown--;
return;
}
if (viewCooldown > 0) {
viewCooldown--;
return;
}
int i = xCoord;
int j = yCoord;
int k = zCoord;
AxisAlignedBB axisalignedbb = AxisAlignedBB.getBoundingBox(i, j, k, i, j, k).expand(5, 5, 5);
List<?> list = this.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, axisalignedbb);
Iterator<?> iterator = list.iterator();
EntityLivingBase entity;
while (iterator.hasNext()) {
entity = (EntityLivingBase) iterator.next();
double eyeHeight = entity.getEyeHeight();
boolean isPlayer = (entity instanceof EntityPlayer);
Vec3 lookVec = Vec3.createVectorHelper((entity.posX + (entity.getLookVec().xCoord * 5)), ((eyeHeight + entity.posY) + (entity.getLookVec().yCoord * 5)), (entity.posZ + (entity.getLookVec().zCoord * 5)));
MovingObjectPosition mop = worldObj.rayTraceBlocks(Vec3.createVectorHelper(entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ), lookVec);
if (mop != null && mop.typeOfHit == MovingObjectType.BLOCK) {
if (mop.blockX == xCoord && mop.blockY == yCoord && mop.blockZ == zCoord) {
if ((isPlayer && activatedOnlyByPlayer()) || !activatedOnlyByPlayer()) {
entityViewed(entity);
viewCooldown = getViewCooldown();
}
}
}
}
}
if (attacks) {
if (attackCooldown < getTicksBetweenAttacks()) {
attackCooldown++;
return;
}
if (canAttack()) {
int i = xCoord;
int j = yCoord;
int k = zCoord;
AxisAlignedBB axisalignedbb = AxisAlignedBB.getBoundingBox(i, j, k, i + 1, j + 1, k + 1).expand(getAttackRange(), getAttackRange(), getAttackRange());
List<?> list = this.worldObj.getEntitiesWithinAABB(entityTypeToAttack(), axisalignedbb);
Iterator<?> iterator = list.iterator();
if (!worldObj.isRemote) {
boolean attacked = false;
while (iterator.hasNext()) {
Entity mobToAttack = (Entity) iterator.next();
if (mobToAttack == null || mobToAttack instanceof EntityItem || !shouldAttackEntityType(mobToAttack)) {
continue;
}
if (attackEntity(mobToAttack)) {
attacked = true;
}
}
if (attacked || shouldRefreshAttackCooldown()) {
attackCooldown = 0;
}
if (attacked || shouldSyncToClient()) {
sync();
}
}
}
}
}
use of net.minecraft.util.MovingObjectPosition in project SecurityCraft by Geforce132.
the class ForgeEventHandler method getMovingObjectPositionFromPlayer.
private MovingObjectPosition getMovingObjectPositionFromPlayer(World par1World, EntityPlayer par2EntityPlayer, boolean flag, double reach) {
float f = 1.0F;
float playerPitch = par2EntityPlayer.prevRotationPitch + (par2EntityPlayer.rotationPitch - par2EntityPlayer.prevRotationPitch) * f;
float playerYaw = par2EntityPlayer.prevRotationYaw + (par2EntityPlayer.rotationYaw - par2EntityPlayer.prevRotationYaw) * f;
double playerPosX = par2EntityPlayer.prevPosX + (par2EntityPlayer.posX - par2EntityPlayer.prevPosX) * f;
double playerPosY = (par2EntityPlayer.prevPosY + (par2EntityPlayer.posY - par2EntityPlayer.prevPosY) * f + 1.6200000000000001D) - par2EntityPlayer.yOffset;
double playerPosZ = par2EntityPlayer.prevPosZ + (par2EntityPlayer.posZ - par2EntityPlayer.prevPosZ) * f;
Vec3 vecPlayer = Vec3.createVectorHelper(playerPosX, playerPosY, playerPosZ);
float cosYaw = MathHelper.cos(-playerYaw * 0.01745329F - 3.141593F);
float sinYaw = MathHelper.sin(-playerYaw * 0.01745329F - 3.141593F);
float cosPitch = -MathHelper.cos(-playerPitch * 0.01745329F);
float sinPitch = -MathHelper.sin(-playerPitch * 0.01745329F);
float pointX = sinYaw * cosPitch;
float pointY = sinPitch;
float pointZ = cosYaw * cosPitch;
Vec3 vecPoint = vecPlayer.addVector(pointX * reach, pointY * reach, pointZ * reach);
MovingObjectPosition movingobjectposition = par1World.rayTraceBlocks(vecPlayer, vecPoint, flag);
return movingobjectposition;
}
use of net.minecraft.util.MovingObjectPosition in project Engine by VoltzEngine-Project.
the class RenderItemOverlayUtility method renderTopOverlay.
public static void renderTopOverlay(TileEntity tileEntity, ItemStack[] inventory, ForgeDirection dir, int matrixX, int matrixZ, double x, double y, double z, float scale) {
GL11.glPushMatrix();
/** Render the Crafting Matrix */
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
boolean isLooking = false;
MovingObjectPosition objectPosition = player.rayTrace(8, 1);
if (objectPosition != null) {
isLooking = objectPosition.blockX == tileEntity.xCoord && objectPosition.blockY == tileEntity.yCoord && objectPosition.blockZ == tileEntity.zCoord;
}
for (int i = 0; i < (matrixX * matrixZ); i++) {
if (inventory[i] != null) {
Pos translation = new Pos((double) (i / matrixX) / ((double) matrixX) + (0.5 / (matrixX)), 1.1, (double) (i % matrixZ) / ((double) matrixZ) + (0.5 / (matrixZ))).add(-0.5);
translation.multiply(0.85);
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5f, y + 0.5f, z + 0.5f);
RenderUtility.rotateBlockBasedOnDirection(dir);
GL11.glTranslated(translation.x(), translation.y(), translation.z());
GL11.glScalef(scale, scale, scale);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240);
renderItem(tileEntity.getWorldObj(), ForgeDirection.UP, inventory[i], new Pos(0, 0, 0), 0, 4);
GL11.glPopMatrix();
if (isLooking) {
GL11.glPushMatrix();
GL11.glTranslated(x, y, z);
int angle = WorldUtility.getAngleFromForgeDirection(WorldUtility.invertX(dir));
RenderUtility.renderFloatingText("" + inventory[i].stackSize, new Pos(translation.transform(new Quaternion(angle, Pos.up))).add(0.5).add(new Pos(0, 0.3, 0)));
GL11.glPopMatrix();
}
}
}
GL11.glPopMatrix();
}
use of net.minecraft.util.MovingObjectPosition in project Engine by VoltzEngine-Project.
the class ItemFluidBucket method onItemRightClick.
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
if (this.getFluid(stack) == null) {
return new ItemStack(Items.bucket);
} else {
MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(world, player, false);
if (movingobjectposition == null) {
return stack;
}
if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
int i = movingobjectposition.blockX;
int j = movingobjectposition.blockY;
int k = movingobjectposition.blockZ;
if (!world.canMineBlock(player, i, j, k)) {
return stack;
}
if (movingobjectposition.sideHit == 0) {
--j;
}
if (movingobjectposition.sideHit == 1) {
++j;
}
if (movingobjectposition.sideHit == 2) {
--k;
}
if (movingobjectposition.sideHit == 3) {
++k;
}
if (movingobjectposition.sideHit == 4) {
--i;
}
if (movingobjectposition.sideHit == 5) {
++i;
}
if (!player.canPlayerEdit(i, j, k, movingobjectposition.sideHit, stack)) {
return stack;
}
//TODO if bored fix so that stacked buckets work correctly
if (this.tryPlaceContainedLiquid(stack, world, i, j, k) && !player.capabilities.isCreativeMode) {
return new ItemStack(Items.bucket);
}
}
return stack;
}
}
use of net.minecraft.util.MovingObjectPosition in project Engine by VoltzEngine-Project.
the class RenderTaggedTile method renderTileEntityAt.
@Override
public void renderTileEntityAt(TileEntity t, double x, double y, double z, float f) {
if (t != null) {
if (t instanceof ITagRender && this.getPlayer().getDistance(t.xCoord, t.yCoord, t.zCoord) <= RendererLivingEntity.NAME_TAG_RANGE) {
HashMap<String, Integer> tags = new HashMap<>();
float height = ((ITagRender) t).addInformation(tags, this.getPlayer());
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
if (player.ridingEntity == null) {
MovingObjectPosition objectPosition = player.rayTrace(8, 1);
if (objectPosition != null) {
boolean isLooking = false;
for (int h = 0; h < height; h++) {
if (objectPosition.blockX == t.xCoord && objectPosition.blockY == t.yCoord + h && objectPosition.blockZ == t.zCoord) {
isLooking = true;
}
}
if (isLooking) {
Iterator<Entry<String, Integer>> it = tags.entrySet().iterator();
int i = 0;
while (it.hasNext()) {
Entry<String, Integer> entry = it.next();
if (entry.getKey() != null) {
RenderUtility.renderFloatingText(entry.getKey(), new Pos(x, y, z).add(new Pos(0.5, i * 0.25f + height, 0.5f)), entry.getValue());
}
i++;
}
}
}
}
}
}
}
Aggregations