use of net.minecraft.entity.item.EntityFallingBlock in project SpongeCommon by SpongePowered.
the class TrackingUtil method tickEntity.
public static void tickEntity(net.minecraft.entity.Entity entityIn) {
checkArgument(entityIn instanceof Entity, "Entity %s is not an instance of SpongeAPI's Entity!", entityIn);
checkNotNull(entityIn, "Cannot capture on a null ticking entity!");
final IMixinEntity mixinEntity = EntityUtil.toMixin(entityIn);
if (!mixinEntity.shouldTick()) {
return;
}
final EntityTickContext tickContext = TickPhase.Tick.ENTITY.createPhaseContext().source(entityIn);
try (final StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame();
final EntityTickContext context = tickContext;
final Timing entityTiming = mixinEntity.getTimingsHandler().startTiming()) {
mixinEntity.getNotifierUser().ifPresent(notifier -> {
frame.addContext(EventContextKeys.NOTIFIER, notifier);
context.notifier(notifier);
});
mixinEntity.getCreatorUser().ifPresent(owner -> {
if (mixinEntity instanceof EntityFallingBlock) {
frame.pushCause(owner);
}
frame.addContext(EventContextKeys.OWNER, owner);
context.owner(owner);
});
context.buildAndSwitch();
entityIn.onUpdate();
} catch (Exception | NoClassDefFoundError e) {
PhaseTracker.getInstance().printExceptionFromPhase(e, tickContext);
}
}
use of net.minecraft.entity.item.EntityFallingBlock in project SpongeCommon by SpongePowered.
the class MixinWorld method createEntity.
private Entity createEntity(EntityType type, Vector3d position, boolean naturally) throws IllegalArgumentException, IllegalStateException {
checkNotNull(type, "The entity type cannot be null!");
checkNotNull(position, "The position cannot be null!");
Entity entity = null;
Class<? extends Entity> entityClass = type.getEntityClass();
double x = position.getX();
double y = position.getY();
double z = position.getZ();
if (entityClass.isAssignableFrom(EntityPlayerMP.class) || entityClass.isAssignableFrom(MultiPartEntityPart.class)) {
// Unable to construct these
throw new IllegalArgumentException("Cannot construct " + type.getId() + " please look to using entity types correctly!");
}
net.minecraft.world.World world = (net.minecraft.world.World) (Object) this;
// Not all entities have a single World parameter as their constructor
if (entityClass.isAssignableFrom(EntityLightningBolt.class)) {
entity = (Entity) new EntityLightningBolt(world, x, y, z, false);
} else if (entityClass.isAssignableFrom(EntityEnderPearl.class)) {
EntityArmorStand tempEntity = new EntityArmorStand(world, x, y, z);
tempEntity.posY -= tempEntity.getEyeHeight();
entity = (Entity) new EntityEnderPearl(world, tempEntity);
((EnderPearl) entity).setShooter(ProjectileSource.UNKNOWN);
}
// set them is to use the more specialised constructor).
if (entityClass.isAssignableFrom(EntityFallingBlock.class)) {
entity = (Entity) new EntityFallingBlock(world, x, y, z, Blocks.SAND.getDefaultState());
} else if (entityClass.isAssignableFrom(EntityItem.class)) {
entity = (Entity) new EntityItem(world, x, y, z, new ItemStack(Blocks.STONE));
}
if (entity == null) {
try {
entity = ConstructorUtils.invokeConstructor(entityClass, this);
((net.minecraft.entity.Entity) entity).setPosition(x, y, z);
} catch (Exception e) {
throw new RuntimeException("There was an issue attempting to construct " + type.getId(), e);
}
}
if (naturally && entity instanceof EntityLiving) {
// Adding the default equipment
((EntityLiving) entity).onInitialSpawn(world.getDifficultyForLocation(new BlockPos(x, y, z)), null);
}
if (entity instanceof EntityPainting) {
// This is default when art is null when reading from NBT, could
// choose a random art instead?
((EntityPainting) entity).art = EnumArt.KEBAB;
}
return entity;
}
use of net.minecraft.entity.item.EntityFallingBlock in project SpongeCommon by SpongePowered.
the class MixinEntityFallingBlock method beforeFall.
@Inject(method = "fall(FF)V", at = @At(value = "JUMP", opcode = Opcodes.IFEQ, ordinal = 1))
public void beforeFall(float distance, float damageMultipleier, CallbackInfo callbackInfo) {
this.isAnvil = this.fallTile.getBlock() == Blocks.ANVIL;
this.original = this.isAnvil ? DamageSource.ANVIL : DamageSource.FALLING_BLOCK;
if (this.isAnvil) {
DamageSource.ANVIL = new MinecraftFallingBlockDamageSource("anvil", (EntityFallingBlock) (Object) this);
} else {
DamageSource.FALLING_BLOCK = new MinecraftFallingBlockDamageSource("fallingblock", (EntityFallingBlock) (Object) this);
}
}
use of net.minecraft.entity.item.EntityFallingBlock in project Galacticraft by micdoodle8.
the class SpinManager method updateSpin.
public void updateSpin() {
if (!this.clientSide) {
if (this.dataNotLoaded) {
this.savefile = OrbitSpinSaveData.initWorldData(this.worldProvider.worldObj);
this.readFromNBT(this.savefile.datacompound);
if (ConfigManagerCore.enableDebug) {
GCLog.info("Loading data from save: " + this.savefile.datacompound.getFloat("omegaSky"));
}
this.dataNotLoaded = false;
}
if (this.doSpinning) {
boolean updateNeeded = true;
if (this.angularVelocityTarget < this.angularVelocityRadians) {
float newAngle = this.angularVelocityRadians - this.angularVelocityAccel;
if (newAngle < this.angularVelocityTarget) {
newAngle = this.angularVelocityTarget;
}
this.setSpinRate(newAngle);
this.thrustersFiring = true;
} else if (this.angularVelocityTarget > this.angularVelocityRadians) {
float newAngle = this.angularVelocityRadians + this.angularVelocityAccel;
if (newAngle > this.angularVelocityTarget) {
newAngle = this.angularVelocityTarget;
}
this.setSpinRate(newAngle);
this.thrustersFiring = true;
} else if (this.thrustersFiring) {
this.thrustersFiring = false;
} else {
updateNeeded = false;
}
if (updateNeeded) {
this.writeToNBT(this.savefile.datacompound);
this.savefile.markDirty();
List<Object> objList = new ArrayList<Object>();
objList.add(Float.valueOf(this.angularVelocityRadians));
objList.add(Boolean.valueOf(this.thrustersFiring));
GalacticraftCore.packetPipeline.sendToDimension(new PacketSimple(PacketSimple.EnumSimplePacket.C_UPDATE_STATION_SPIN, GCCoreUtil.getDimensionID(this.worldProvider), objList), GCCoreUtil.getDimensionID(this.worldProvider));
}
}
// Update entity positions if in freefall
this.loadedEntities.clear();
this.loadedEntities.addAll(this.worldProvider.worldObj.loadedEntityList);
for (Entity e : this.loadedEntities) {
// TODO: What about vehicles from GC (buggies) and other mods?
if ((e instanceof EntityItem || e instanceof EntityLivingBase && !(e instanceof EntityPlayer) || e instanceof EntityTNTPrimed || e instanceof EntityFallingBlock) && !e.onGround) {
AxisAlignedBB entityBoundingBox = e.getEntityBoundingBox();
boolean outsideStation = entityBoundingBox.maxX < this.ssBoundsMinX || entityBoundingBox.minX > this.ssBoundsMaxX || entityBoundingBox.maxY < this.ssBoundsMinY || entityBoundingBox.minY > this.ssBoundsMaxY || entityBoundingBox.maxZ < this.ssBoundsMinZ || entityBoundingBox.minZ > this.ssBoundsMaxZ;
if (outsideStation || FreefallHandler.testEntityFreefall(this.worldProvider.worldObj, entityBoundingBox)) {
if (this.doSpinning) {
this.moveRotatedEntity(e, this.spinCentreX, this.spinCentreZ, this.angularVelocityRadians);
}
FreefallHandler.tickFreefallEntity(e);
if (e instanceof ITumblable) {
((ITumblable) e).setTumbling(3F);
}
} else {
if (e instanceof ITumblable) {
((ITumblable) e).setTumbling(0F);
}
}
}
}
}
}
use of net.minecraft.entity.item.EntityFallingBlock in project Galacticraft by micdoodle8.
the class FreefallHandler method tickFreefallEntity.
/**
* Call this on every freefalling non-player entity in a dimension
* either at the end of the world tick (ideal) or else during the
* start of the next world tick (e.g. during updateWeather())
*
* May require iteration through the world's loadedEntityList
* See SpinManager.updateSpin() for an example
* @param e
*/
public static void tickFreefallEntity(Entity e) {
if (e.worldObj.provider instanceof IZeroGDimension)
((IZeroGDimension) e.worldObj.provider).setInFreefall(e);
// Undo deceleration applied at the end of the previous tick
boolean warnLog = false;
if (e instanceof EntityLivingBase) {
ZeroGravityEvent zeroGEvent = new ZeroGravityEvent.InFreefall((EntityLivingBase) e);
MinecraftForge.EVENT_BUS.post(zeroGEvent);
if (!zeroGEvent.isCanceled()) {
// 0.91F;
e.motionX /= (double) 0.91F;
// 0.91F;
e.motionZ /= (double) 0.91F;
e.motionY /= (e instanceof EntityFlying) ? 0.91F : 0.9800000190734863D;
if (e.motionX > 10D) {
warnLog = true;
e.motionX = 10D;
} else if (e.motionX < -10D) {
warnLog = true;
e.motionX = -10D;
}
if (e.motionY > 10D) {
warnLog = true;
e.motionY = 10D;
} else if (e.motionY < -10D) {
warnLog = true;
e.motionY = -10D;
}
if (e.motionZ > 10D) {
warnLog = true;
e.motionZ = 10D;
} else if (e.motionZ < -10D) {
warnLog = true;
e.motionZ = -10D;
}
}
} else if (e instanceof EntityFallingBlock) {
e.motionY /= 0.9800000190734863D;
// e.lastTickPosY += 0.03999999910593033D;
if (e.motionY > 10D) {
warnLog = true;
e.motionY = 10D;
} else if (e.motionY < -10D) {
warnLog = true;
e.motionY = -10D;
}
} else {
e.motionX /= 0.9800000190734863D;
e.motionY /= 0.9800000190734863D;
e.motionZ /= 0.9800000190734863D;
if (e.motionX > 10D) {
warnLog = true;
e.motionX = 10D;
} else if (e.motionX < -10D) {
warnLog = true;
e.motionX = -10D;
}
if (e.motionY > 10D) {
warnLog = true;
e.motionY = 10D;
} else if (e.motionY < -10D) {
warnLog = true;
e.motionY = -10D;
}
if (e.motionZ > 10D) {
warnLog = true;
e.motionZ = 10D;
} else if (e.motionZ < -10D) {
warnLog = true;
e.motionZ = -10D;
}
}
if (warnLog)
GCLog.debug(e.getName() + " moving too fast");
}
Aggregations