Search in sources :

Example 1 with EntityFallingBlock

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);
    }
}
Also used : IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) TileEntity(org.spongepowered.api.block.tileentity.TileEntity) IMixinTileEntity(org.spongepowered.common.interfaces.block.tile.IMixinTileEntity) Entity(org.spongepowered.api.entity.Entity) EntityTickContext(org.spongepowered.common.event.tracking.phase.tick.EntityTickContext) TileEntityTickContext(org.spongepowered.common.event.tracking.phase.tick.TileEntityTickContext) EntityFallingBlock(net.minecraft.entity.item.EntityFallingBlock) StackFrame(org.spongepowered.api.event.CauseStackManager.StackFrame) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) Timing(co.aikar.timings.Timing)

Example 2 with EntityFallingBlock

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;
}
Also used : Entity(org.spongepowered.api.entity.Entity) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) TileEntity(org.spongepowered.api.block.tileentity.TileEntity) IMixinTileEntity(org.spongepowered.common.interfaces.block.tile.IMixinTileEntity) EntityFallingBlock(net.minecraft.entity.item.EntityFallingBlock) EntityLiving(net.minecraft.entity.EntityLiving) MultiPartEntityPart(net.minecraft.entity.MultiPartEntityPart) EntityArmorStand(net.minecraft.entity.item.EntityArmorStand) EntityLightningBolt(net.minecraft.entity.effect.EntityLightningBolt) EntityEnderPearl(net.minecraft.entity.item.EntityEnderPearl) World(org.spongepowered.api.world.World) IMixinWorld(org.spongepowered.common.interfaces.world.IMixinWorld) EntityPainting(net.minecraft.entity.item.EntityPainting) PositionOutOfBoundsException(org.spongepowered.api.util.PositionOutOfBoundsException) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos) IMixinBlockPos(org.spongepowered.common.interfaces.util.math.IMixinBlockPos) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 3 with EntityFallingBlock

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);
    }
}
Also used : EntityFallingBlock(net.minecraft.entity.item.EntityFallingBlock) MinecraftFallingBlockDamageSource(org.spongepowered.common.event.damage.MinecraftFallingBlockDamageSource) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 4 with EntityFallingBlock

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);
                    }
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) Entity(net.minecraft.entity.Entity) EntityFallingBlock(net.minecraft.entity.item.EntityFallingBlock) EntityTNTPrimed(net.minecraft.entity.item.EntityTNTPrimed) ArrayList(java.util.ArrayList) PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple) ITumblable(micdoodle8.mods.galacticraft.core.entities.ITumblable) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityItem(net.minecraft.entity.item.EntityItem)

Example 5 with EntityFallingBlock

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");
}
Also used : ZeroGravityEvent(micdoodle8.mods.galacticraft.api.event.ZeroGravityEvent) EntityFallingBlock(net.minecraft.entity.item.EntityFallingBlock) EntityFlying(net.minecraft.entity.EntityFlying) EntityLivingBase(net.minecraft.entity.EntityLivingBase) IZeroGDimension(micdoodle8.mods.galacticraft.api.world.IZeroGDimension)

Aggregations

EntityFallingBlock (net.minecraft.entity.item.EntityFallingBlock)16 BlockPos (net.minecraft.util.math.BlockPos)8 EntityArmorStand (net.minecraft.entity.item.EntityArmorStand)4 Block (net.minecraft.block.Block)3 IBlockState (net.minecraft.block.state.IBlockState)3 Entity (net.minecraft.entity.Entity)3 EntityBoat (net.minecraft.entity.item.EntityBoat)3 EntityPig (net.minecraft.entity.passive.EntityPig)3 World (net.minecraft.world.World)3 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 EntityItem (net.minecraft.entity.item.EntityItem)2 ItemStack (net.minecraft.item.ItemStack)2 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)2 Entity (org.spongepowered.api.entity.Entity)2 IMixinTileEntity (org.spongepowered.common.interfaces.block.tile.IMixinTileEntity)2 IMixinEntity (org.spongepowered.common.interfaces.entity.IMixinEntity)2 EntityMountable (org.valkyrienskies.mod.common.entity.EntityMountable)2 Vector (ValkyrienWarfareBase.API.Vector)1 PhysicsWrapperEntity (ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity)1 EntityMountingWeaponBase (ValkyrienWarfareCombat.Entity.EntityMountingWeaponBase)1