use of net.minecraft.entity.EntityLivingBase in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class EntityCollisionInjector method alterEntityMovement.
// Returns false if game should use default collision
public static boolean alterEntityMovement(Entity entity, double dx, double dy, double dz) {
if (entity instanceof PhysicsWrapperEntity) {
return true;
}
Vector velVec = new Vector(dx, dy, dz);
double origDx = dx;
double origDy = dy;
double origDz = dz;
boolean isLiving = entity instanceof EntityLivingBase;
boolean isMoving = false;
if (isLiving) {
EntityLivingBase living = (EntityLivingBase) entity;
isMoving = Math.abs(living.moveForward) > .01 || Math.abs(living.moveStrafing) > .01;
}
Vec3d velocity = new Vec3d(dx, dy, dz);
ArrayList<EntityPolygonCollider> fastCollisions = new ArrayList<EntityPolygonCollider>();
EntityPolygon playerBeforeMove = new EntityPolygon(entity.getEntityBoundingBox(), entity);
ArrayList<Polygon> colPolys = getCollidingPolygonsAndDoBlockCols(entity, velocity);
PhysicsWrapperEntity worldBelow = null;
EntityDraggable draggable = EntityDraggable.getDraggableFromEntity(entity);
for (Polygon poly : colPolys) {
if (poly instanceof ShipPolygon) {
ShipPolygon shipPoly = (ShipPolygon) poly;
EntityPolygonCollider fast = new EntityPolygonCollider(playerBeforeMove, shipPoly, shipPoly.normals, velVec);
if (!fast.seperated) {
fastCollisions.add(fast);
worldBelow = shipPoly.shipFrom.wrapper;
}
}
}
//TODO: Make this more comprehensive
draggable.worldBelowFeet = worldBelow;
if (fastCollisions.isEmpty()) {
return false;
}
int contX = 0;
int contY = 0;
int contZ = 0;
Vector total = new Vector();
for (EntityPolygonCollider col : fastCollisions) {
Vector response = col.collisions[col.minDistanceIndex].getResponse();
// TODO: Add more potential yResponses
double stepSquared = entity.stepHeight * entity.stepHeight;
boolean isStep = isLiving && entity.onGround;
if (response.Y > 0 && BigBastardMath.canStandOnNormal(col.potentialSeperatingAxes[col.minDistanceIndex])) {
response = new Vector(0, -col.collisions[col.minDistanceIndex].penetrationDistance / col.potentialSeperatingAxes[col.minDistanceIndex].Y, 0);
}
if (isStep) {
EntityLivingBase living = (EntityLivingBase) entity;
if (Math.abs(living.moveForward) > .01 || Math.abs(living.moveStrafing) > .01) {
for (int i = 3; i < 6; i++) {
Vector tempResponse = col.collisions[i].getResponse();
if (tempResponse.Y > 0 && BigBastardMath.canStandOnNormal(col.collisions[i].axis) && tempResponse.lengthSq() < stepSquared) {
response = tempResponse;
}
}
}
}
// total.add(response);
if (Math.abs(response.X) > .01) {
total.X += response.X;
contX++;
}
if (Math.abs(response.Y) > .01) {
total.Y += response.Y;
contY++;
}
if (Math.abs(response.Z) > .01) {
total.Z += response.Z;
contZ++;
}
}
if (contX != 0) {
total.X /= contX;
}
if (contY != 0) {
total.Y /= contY;
}
if (contZ != 0) {
total.Z /= contZ;
}
dx += total.X;
dy += total.Y;
dz += total.Z;
boolean alreadyOnGround = entity.onGround && (dy == origDy) && origDy < 0;
Vector original = new Vector(origDx, origDy, origDz);
Vector newMov = new Vector(dx - origDx, dy - origDy, dz - origDz);
entity.isCollidedHorizontally = original.dot(newMov) < 0;
entity.isCollidedVertically = isDifSignificant(dy, origDy);
entity.onGround = entity.isCollidedVertically && origDy < 0 || alreadyOnGround;
entity.isCollided = entity.isCollidedHorizontally || entity.isCollidedVertically;
if (entity instanceof EntityLivingBase) {
EntityLivingBase base = (EntityLivingBase) entity;
base.motionY = dy;
if (base.isOnLadder()) {
float f9 = 0.15F;
base.motionX = MathHelper.clamp_double(base.motionX, -0.15000000596046448D, 0.15000000596046448D);
base.motionZ = MathHelper.clamp_double(base.motionZ, -0.15000000596046448D, 0.15000000596046448D);
base.fallDistance = 0.0F;
if (base.motionY < -0.15D) {
base.motionY = -0.15D;
}
boolean flag = base.isSneaking() && base instanceof EntityPlayer;
if (flag && base.motionY < 0.0D) {
base.motionY = 0.0D;
}
}
entity.moveEntity(dx, base.motionY, dz);
} else {
entity.moveEntity(dx, dy, dz);
}
entity.isCollidedHorizontally = (motionInterfering(dx, origDx)) || (motionInterfering(dz, origDz));
entity.isCollidedVertically = isDifSignificant(dy, origDy);
entity.onGround = entity.isCollidedVertically && origDy < 0 || alreadyOnGround || entity.onGround;
entity.isCollided = entity.isCollidedHorizontally || entity.isCollidedVertically;
if (dx != origDx) {
entity.motionX = dx;
}
if (dy != origDy) {
if (!(entity.motionY > 0 && dy > 0)) {
entity.motionY = 0;
}
}
if (dz != origDz) {
entity.motionZ = dz;
}
return true;
}
use of net.minecraft.entity.EntityLivingBase in project Skree by Skelril.
the class LoadedBow method applyPropertyOverrides.
private void applyPropertyOverrides() {
this.addPropertyOverride(new ResourceLocation("skree", "pull"), new IItemPropertyGetter() {
@SideOnly(Side.CLIENT)
public float apply(ItemStack item, @Nullable World world, @Nullable EntityLivingBase living) {
if (living == null) {
return 0.0F;
} else {
ItemStack itemstack = living.getActiveItemStack();
return itemstack != null ? (item.getMaxItemUseDuration() - living.getItemInUseCount()) / 20.0F : 0.0F;
}
}
});
this.addPropertyOverride(new ResourceLocation("skree", "pulling"), new IItemPropertyGetter() {
@SideOnly(Side.CLIENT)
public float apply(ItemStack item, @Nullable World world, @Nullable EntityLivingBase living) {
return living != null && living.isHandActive() && living.getActiveItemStack() == item ? 1.0F : 0.0F;
}
});
}
use of net.minecraft.entity.EntityLivingBase in project Railcraft by Railcraft.
the class MinecartHooks method onEntityCollision.
@Override
public void onEntityCollision(EntityMinecart cart, Entity other) {
if (Game.isClient(cart.worldObj) || cart.isPassenger(other) || !other.isEntityAlive() || !cart.isEntityAlive())
return;
ILinkageManager lm = LinkageManager.instance();
EntityMinecart link = lm.getLinkedCartA(cart);
if (link != null && (link == other || link.isPassenger(other)))
return;
link = lm.getLinkedCartB(cart);
if (link != null && (link == other || link.isPassenger(other)))
return;
boolean isLiving = other instanceof EntityLivingBase;
boolean isPlayer = other instanceof EntityPlayer;
//TODO: needs more thought in regards to passenger handling
if (isLiving && !isPlayer && cart.canBeRidden() && !(other instanceof EntityIronGolem) && cart.motionX * cart.motionX + cart.motionZ * cart.motionZ > 0.001D && !cart.isBeingRidden() && !other.isRiding()) {
int mountPrevention = cart.getEntityData().getInteger("MountPrevention");
if (mountPrevention <= 0)
other.startRiding(cart);
}
if (isLiving && WorldPlugin.isBlockAt(cart.worldObj, cart.getPosition(), RailcraftBlocks.TRACK_ELEVATOR.block()))
return;
// System.out.println(cart.getClass().getSimpleName() + ": " + cart.entityId + " collided with " + other.getClass().getSimpleName() + ": " + other.entityId);
Vec2D cartPos = new Vec2D(cart.posX, cart.posZ);
Vec2D otherPos = new Vec2D(other.posX, other.posZ);
Vec2D unit = Vec2D.subtract(otherPos, cartPos);
unit.normalize();
double distance = cart.getDistanceToEntity(other);
double depth = distance - OPTIMAL_DISTANCE;
double forceX = 0;
double forceZ = 0;
if (depth < 0) {
double spring = isPlayer ? COEF_SPRING_PLAYER : COEF_SPRING;
double penaltyX = spring * depth * unit.getX();
double penaltyZ = spring * depth * unit.getY();
forceX += penaltyX;
forceZ += penaltyZ;
if (!isPlayer) {
double impulseX = unit.getX();
double impulseZ = unit.getY();
impulseX *= -(1.0 + COEF_RESTITUTION);
impulseZ *= -(1.0 + COEF_RESTITUTION);
Vec2D cartVel = new Vec2D(cart.motionX, cart.motionZ);
Vec2D otherVel = new Vec2D(other.motionX, other.motionZ);
double dot = Vec2D.subtract(otherVel, cartVel).dotProduct(unit);
impulseX *= dot;
impulseZ *= dot;
impulseX *= 0.5;
impulseZ *= 0.5;
forceX -= impulseX;
forceZ -= impulseZ;
}
}
if (other instanceof EntityMinecart) {
EntityMinecart otherCart = (EntityMinecart) other;
if (!cart.isPoweredCart() || otherCart.isPoweredCart())
if (!TrackToolsAPI.isCartLockedDown(cart))
cart.addVelocity(forceX, 0, forceZ);
if (!otherCart.isPoweredCart() || cart.isPoweredCart())
if (!TrackToolsAPI.isCartLockedDown(otherCart))
other.addVelocity(-forceX, 0, -forceZ);
} else {
// if(isPlayer) {
// forceX += Math.abs(cart.motionX - other.motionX) / 2;
// forceZ += Math.abs(cart.motionZ - other.motionZ) / 2;
// }
// System.out.printf("forceX=%f, forceZ=%f%n", forceX, forceZ);
Vec2D cartVel = new Vec2D(cart.motionX + forceX, cart.motionZ + forceZ);
Vec2D otherVel = new Vec2D(other.motionX - forceX, other.motionZ - forceZ);
double dot = Vec2D.subtract(otherVel, cartVel).dotProduct(unit);
double dampX = COEF_DAMPING * dot * unit.getX();
double dampZ = COEF_DAMPING * dot * unit.getY();
forceX += dampX;
forceZ += dampZ;
// System.out.printf("dampX=%f, dampZ=%f%n", dampX, dampZ);
if (!isPlayer)
other.addVelocity(-forceX, 0.0D, -forceZ);
if (!TrackToolsAPI.isCartLockedDown(cart))
cart.addVelocity(forceX, 0, forceZ);
}
}
use of net.minecraft.entity.EntityLivingBase in project Railcraft by Railcraft.
the class TileRockCrusher method update.
@Override
public void update() {
super.update();
if (Game.isHost(getWorld())) {
BlockPos pos = getPos();
double x = pos.getX();
double y = pos.getZ();
double z = pos.getZ();
if (isStructureValid()) {
// TileEntityHopper.getItemsAroundAPointOrSomethingLikeThat
for (EntityItem item : TileEntityHopper.getCaptureItems(getWorld(), x, y + 1, z)) {
if (item != null && useMasterEnergy(SUCKING_POWER_COST, false)) {
ItemStack stack = item.getEntityItem().copy();
InventoryManipulator.get((IInventory) invInput).addStack(stack);
useMasterEnergy(SUCKING_POWER_COST, true);
item.setDead();
}
}
EntityLivingBase entity = MiscTools.getEntityAt(worldObj, EntityLivingBase.class, getPos().up());
if (entity != null && useMasterEnergy(KILLING_POWER_COST, false))
if (entity.attackEntityFrom(RailcraftDamageSource.CRUSHER, 10))
useMasterEnergy(KILLING_POWER_COST, true);
}
if (isMaster()) {
if (clock % 16 == 0)
processActions();
if (paused)
return;
ItemStack input = InvTools.emptyStack();
ICrusherCraftingManager.ICrusherRecipe recipe = null;
for (IInvSlot slot : InventoryIterator.getVanilla((IInventory) invInput)) {
input = slot.getStack();
if (!InvTools.isEmpty(input)) {
recipe = RailcraftCraftingManager.rockCrusher.getRecipe(input);
if (recipe == null)
recipe = RockCrusherCraftingManager.NULL_RECIPE;
break;
}
}
if (recipe != null)
if (processTime >= PROCESS_TIME) {
isWorking = false;
InventoryCopy tempInv = new InventoryCopy(invOutput);
boolean hasRoom = true;
List<ItemStack> outputs = recipe.getProcessedOutputs();
for (ItemStack output : outputs) {
output = InvTools.moveItemStack(output, tempInv);
if (!InvTools.isEmpty(output)) {
hasRoom = false;
break;
}
}
if (hasRoom) {
for (ItemStack output : outputs) {
InvTools.moveItemStack(output, invOutput);
}
InvTools.removeOneItem(invInput, input);
SoundHelper.playSound(worldObj, null, getPos(), SoundEvents.ENTITY_IRONGOLEM_DEATH, SoundCategory.BLOCKS, 1.0f, worldObj.rand.nextFloat() * 0.25F + 0.7F);
processTime = 0;
}
} else {
isWorking = true;
if (energyStorage != null) {
int energy = energyStorage.extractEnergy(CRUSHING_POWER_COST_PER_TICK, true);
if (energy >= CRUSHING_POWER_COST_PER_TICK) {
processTime++;
energyStorage.extractEnergy(CRUSHING_POWER_COST_PER_TICK, false);
}
} else
processTime++;
}
else {
processTime = 0;
isWorking = false;
}
}
}
}
use of net.minecraft.entity.EntityLivingBase in project Railcraft by Railcraft.
the class EntityAISitBred method shouldExecute.
/**
* Returns whether the EntityAIBase should begin execution.
*/
//TODO: test
@Override
public boolean shouldExecute() {
if (!theEntity.isTamed())
return false;
else if (theEntity.isInWater())
return false;
else if (!theEntity.onGround)
return false;
else {
Entity owner = theEntity.getOwner();
UUID ownerId = theEntity.getOwnerId();
if (ownerId != null && owner == null)
return true;
//noinspection ConstantConditions
if (owner != null && theEntity.getDistanceSqToEntity(owner) > 144.0D && ((EntityLivingBase) owner).getAITarget() != null)
return false;
return isSitting;
}
}
Aggregations