Search in sources :

Example 1 with ITumblable

use of micdoodle8.mods.galacticraft.core.entities.ITumblable 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)

Aggregations

ArrayList (java.util.ArrayList)1 ITumblable (micdoodle8.mods.galacticraft.core.entities.ITumblable)1 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)1 Entity (net.minecraft.entity.Entity)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityFallingBlock (net.minecraft.entity.item.EntityFallingBlock)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityTNTPrimed (net.minecraft.entity.item.EntityTNTPrimed)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)1