Search in sources :

Example 1 with WorldProviderAsteroids

use of micdoodle8.mods.galacticraft.planets.asteroids.dimension.WorldProviderAsteroids in project Galacticraft by micdoodle8.

the class AsteroidsEventHandlerClient method onClientTick.

@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onClientTick(ClientTickEvent event) {
    Minecraft minecraft = Minecraft.getMinecraft();
    WorldClient world = minecraft.theWorld;
    if (world != null) {
        if (world.provider instanceof WorldProviderAsteroids) {
            if (world.provider.getSkyRenderer() == null) {
                world.provider.setSkyRenderer(new SkyProviderAsteroids((IGalacticraftWorldProvider) world.provider));
            }
            if (world.provider.getCloudRenderer() == null) {
                world.provider.setCloudRenderer(new CloudRenderer());
            }
        }
    }
}
Also used : IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) CloudRenderer(micdoodle8.mods.galacticraft.core.client.CloudRenderer) SkyProviderAsteroids(micdoodle8.mods.galacticraft.planets.asteroids.client.SkyProviderAsteroids) Minecraft(net.minecraft.client.Minecraft) WorldClient(net.minecraft.client.multiplayer.WorldClient) WorldProviderAsteroids(micdoodle8.mods.galacticraft.planets.asteroids.dimension.WorldProviderAsteroids) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with WorldProviderAsteroids

use of micdoodle8.mods.galacticraft.planets.asteroids.dimension.WorldProviderAsteroids in project Galacticraft by micdoodle8.

the class TileEntityMinerBase method findTargetPoints.

private void findTargetPoints() {
    this.targetPoints.clear();
    BlockVec3 posnTarget = new BlockVec3(this);
    if (this.worldObj.provider instanceof WorldProviderAsteroids) {
        ArrayList<BlockVec3> roids = ((WorldProviderAsteroids) this.worldObj.provider).getClosestAsteroidsXZ(posnTarget.x, posnTarget.y, posnTarget.z, this.facing.getIndex(), 100);
        if (roids != null && roids.size() > 0) {
            this.targetPoints.addAll(roids);
            return;
        }
    }
    posnTarget.modifyPositionFromSide(this.facing, this.worldObj.rand.nextInt(16) + 32);
    int miny = Math.min(this.getPos().getY() * 2 - 90, this.getPos().getY() - 22);
    if (miny < 5) {
        miny = 5;
    }
    posnTarget.y = miny + 5 + this.worldObj.rand.nextInt(4);
    this.targetPoints.add(posnTarget);
    EnumFacing lateral = EnumFacing.NORTH;
    EnumFacing inLine = this.facing;
    if (inLine.getAxis() == Axis.Z) {
        lateral = EnumFacing.WEST;
    }
    this.targetPoints.add(posnTarget.clone().modifyPositionFromSide(lateral, 13));
    this.targetPoints.add(posnTarget.clone().modifyPositionFromSide(lateral, -13));
    if (posnTarget.y > 17) {
        this.targetPoints.add(posnTarget.clone().modifyPositionFromSide(lateral, 7).modifyPositionFromSide(EnumFacing.DOWN, 11));
        this.targetPoints.add(posnTarget.clone().modifyPositionFromSide(lateral, -7).modifyPositionFromSide(EnumFacing.DOWN, 11));
    } else {
        this.targetPoints.add(posnTarget.clone().modifyPositionFromSide(lateral, 26));
        this.targetPoints.add(posnTarget.clone().modifyPositionFromSide(lateral, -26));
    }
    this.targetPoints.add(posnTarget.clone().modifyPositionFromSide(lateral, 7).modifyPositionFromSide(EnumFacing.UP, 11));
    this.targetPoints.add(posnTarget.clone().modifyPositionFromSide(lateral, -7).modifyPositionFromSide(EnumFacing.UP, 11));
    if (posnTarget.y < this.getPos().getY() - 38) {
        this.targetPoints.add(posnTarget.clone().modifyPositionFromSide(lateral, 13).modifyPositionFromSide(EnumFacing.UP, 22));
        this.targetPoints.add(posnTarget.clone().modifyPositionFromSide(EnumFacing.UP, 22));
        this.targetPoints.add(posnTarget.clone().modifyPositionFromSide(lateral, -13).modifyPositionFromSide(EnumFacing.UP, 22));
    }
    int s = this.targetPoints.size();
    for (int i = 0; i < s; i++) {
        this.targetPoints.add(this.targetPoints.get(i).clone().modifyPositionFromSide(inLine, EntityAstroMiner.MINE_LENGTH + 6));
    }
    this.markDirty();
    return;
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) WorldProviderAsteroids(micdoodle8.mods.galacticraft.planets.asteroids.dimension.WorldProviderAsteroids) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 3 with WorldProviderAsteroids

use of micdoodle8.mods.galacticraft.planets.asteroids.dimension.WorldProviderAsteroids in project Galacticraft by micdoodle8.

the class EntityAstroMiner method setMinePoints.

private void setMinePoints() {
    // Still some areas left to mine from last visit (maybe it was full or out of power?)
    if (this.minePoints.size() > 0) {
        return;
    }
    BlockVec3 inFront = new BlockVec3(MathHelper.floor_double(this.posX + 0.5D), MathHelper.floor_double(this.posY + 1.5D), MathHelper.floor_double(this.posZ + 0.5D));
    int otherEnd = (this.worldObj.provider instanceof WorldProviderAsteroids) ? this.MINE_LENGTH_AST : this.MINE_LENGTH;
    if (this.baseFacing == EnumFacing.NORTH || this.baseFacing == EnumFacing.WEST) {
        otherEnd = -otherEnd;
    }
    switch(this.baseFacing) {
        case NORTH:
        case SOUTH:
            this.minePoints.add(inFront.clone().translate(0, 0, otherEnd));
            this.minePoints.add(inFront.clone().translate(4, 0, otherEnd));
            this.minePoints.add(inFront.clone().translate(4, 0, 0));
            this.minePoints.add(inFront.clone().translate(2, 3, 0));
            this.minePoints.add(inFront.clone().translate(2, 3, otherEnd));
            this.minePoints.add(inFront.clone().translate(-2, 3, otherEnd));
            this.minePoints.add(inFront.clone().translate(-2, 3, 0));
            this.minePoints.add(inFront.clone().translate(-4, 0, 0));
            this.minePoints.add(inFront.clone().translate(-4, 0, otherEnd));
            this.minePoints.add(inFront.clone().translate(-2, -3, otherEnd));
            this.minePoints.add(inFront.clone().translate(-2, -3, 0));
            this.minePoints.add(inFront.clone().translate(2, -3, 0));
            this.minePoints.add(inFront.clone().translate(2, -3, otherEnd));
            this.minePoints.add(inFront.clone().translate(0, 0, otherEnd));
            break;
        case WEST:
        case EAST:
            this.minePoints.add(inFront.clone().translate(otherEnd, 0, 0));
            this.minePoints.add(inFront.clone().translate(otherEnd, 0, 4));
            this.minePoints.add(inFront.clone().translate(0, 0, 4));
            this.minePoints.add(inFront.clone().translate(0, 3, 2));
            this.minePoints.add(inFront.clone().translate(otherEnd, 3, 2));
            this.minePoints.add(inFront.clone().translate(otherEnd, 3, -2));
            this.minePoints.add(inFront.clone().translate(0, 3, -2));
            this.minePoints.add(inFront.clone().translate(0, 0, -4));
            this.minePoints.add(inFront.clone().translate(otherEnd, 0, -4));
            this.minePoints.add(inFront.clone().translate(otherEnd, -3, -2));
            this.minePoints.add(inFront.clone().translate(0, -3, -2));
            this.minePoints.add(inFront.clone().translate(0, -3, 2));
            this.minePoints.add(inFront.clone().translate(otherEnd, -3, 2));
            this.minePoints.add(inFront.clone().translate(otherEnd, 0, 0));
            break;
    }
}
Also used : WorldProviderAsteroids(micdoodle8.mods.galacticraft.planets.asteroids.dimension.WorldProviderAsteroids) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 4 with WorldProviderAsteroids

use of micdoodle8.mods.galacticraft.planets.asteroids.dimension.WorldProviderAsteroids in project Galacticraft by micdoodle8.

the class EntityAstroMiner method onUpdate.

@Override
public void onUpdate() {
    if (this.posY < -64.0D) {
        this.setDead();
        return;
    }
    if (this.getDamage() > 0.0F) {
        this.setDamage(this.getDamage() - 1.0F);
    }
    stopForTurn = !this.checkRotation();
    this.facing = this.getFacingFromRotation();
    this.setBoundingBoxForFacing();
    if (this.worldObj.isRemote) {
        // CLIENT CODE
        if (this.turnProgress == 0) {
            this.turnProgress++;
            if (this.AIstate < AISTATE_TRAVELLING) {
                // It should be stationary, so this deals with the spooky movement (due to minor differences between server and client position)
                this.posX = this.minecartX;
                this.posY = this.minecartY;
                this.posZ = this.minecartZ;
            } else {
                double diffX = this.minecartX - this.posX;
                double diffY = this.minecartY - this.posY;
                double diffZ = this.minecartZ - this.posZ;
                if (Math.abs(diffX) > 1.0D || Math.abs(diffY) > 1.0D || Math.abs(diffZ) > 1.0D) {
                    this.posX = this.minecartX;
                    this.posY = this.minecartY;
                    this.posZ = this.minecartZ;
                } else {
                    if (Math.abs(diffX) > Math.abs(this.motionX)) {
                        this.motionX += diffX / 10D;
                    }
                    if (Math.abs(diffY) > Math.abs(this.motionY)) {
                        this.motionY += diffY / 10D;
                    }
                    if (Math.abs(diffZ) > Math.abs(this.motionZ)) {
                        this.motionZ += diffZ / 10D;
                    }
                }
            }
        }
        this.posX += this.motionX;
        this.posY += this.motionY;
        this.posZ += this.motionZ;
        setEntityBoundingBox(getEntityBoundingBox().offset(this.motionX, this.motionY, this.motionZ));
        this.setRotation(this.rotationYaw, this.rotationPitch);
        if (this.AIstate == AISTATE_MINING && this.ticksExisted % 2 == 0) {
            this.prepareMoveClient(TEMPFAST ? 8 : 1, 2);
        }
        // Sound updates on client
        if (this.AIstate < AISTATE_ATBASE) {
            this.stopRocketSound();
        }
        return;
    }
    if (this.toAddToServer) {
        this.toAddToServer = false;
        this.serverIndex = AsteroidsTickHandlerServer.monitorMiner(this);
    }
    // SERVER CODE
    if (this.ticksExisted % 10 == 0 || this.flagLink) {
        this.flagLink = false;
        this.checkPlayer();
        if (posBase.blockExists(worldObj)) {
            TileEntity tileEntity = posBase.getTileEntity(this.worldObj);
            if (tileEntity instanceof TileEntityMinerBase && ((TileEntityMinerBase) tileEntity).isMaster && !tileEntity.isInvalid()) {
                // Create link with base on loading the EntityAstroMiner
                UUID linker = ((TileEntityMinerBase) tileEntity).getLinkedMiner();
                if (!this.getUniqueID().equals(linker)) {
                    if (linker == null) {
                        ((TileEntityMinerBase) tileEntity).linkMiner(this);
                    } else {
                        this.freeze(FAIL_ANOTHERWASLINKED);
                        return;
                    }
                } else if (((TileEntityMinerBase) tileEntity).linkedMiner != this) {
                    ((TileEntityMinerBase) tileEntity).linkMiner(this);
                }
            } else {
                if (this.playerMP != null && (this.givenFailMessage & (1 << FAIL_BASEDESTROYED)) == 0) {
                    this.playerMP.addChatMessage(new ChatComponentText(GCCoreUtil.translate("gui.message.astro_miner" + FAIL_BASEDESTROYED + ".fail")));
                    this.givenFailMessage += (1 << FAIL_BASEDESTROYED);
                // Continue mining even though base was destroyed - maybe it will be replaced
                }
            }
        }
    } else if (this.flagCheckPlayer) {
        this.checkPlayer();
    }
    if (this.playerMP == null) {
        // but do not actually set the dormant state on the server, so can resume immediately if player comes online
        if (this.motionX != 0 || this.motionY != 0 || this.motionZ != 0) {
            this.motionX = 0;
            this.motionY = 0;
            this.motionZ = 0;
            GalacticraftCore.packetPipeline.sendToDimension(new PacketDynamic(this), GCCoreUtil.getDimensionID(this.worldObj));
        }
        return;
    }
    if (this.lastFacing != this.facingAI) {
        this.lastFacing = this.facingAI;
        this.prepareMove(12, 0);
        this.prepareMove(12, 1);
        this.prepareMove(12, 2);
    }
    this.lastTickPosX = this.posX;
    this.lastTickPosY = this.posY;
    this.lastTickPosZ = this.posZ;
    this.prevPosX = this.posX;
    this.prevPosY = this.posY;
    this.prevPosZ = this.posZ;
    this.prevRotationPitch = this.rotationPitch;
    this.prevRotationYaw = this.rotationYaw;
    if (this.AIstate > AISTATE_ATBASE) {
        if (this.energyLevel <= 0) {
            this.freeze(FAIL_OUTOFENERGY);
        } else if (!(this.worldObj.provider instanceof WorldProviderAsteroids) && this.ticksExisted % 2 == 0) {
            this.energyLevel--;
        }
    // No energy consumption when moving in space in Asteroids dimension (this reduces the risk of the Astro Miner becoming stranded!)
    }
    switch(this.AIstate) {
        case AISTATE_STUCK:
            // Attempt to re-start every 30 seconds or so
            if (this.ticksExisted % 600 == 0) {
                if ((this.givenFailMessage & 8) > 0) {
                    // The base was destroyed - see if it has been replaced?
                    this.atBase();
                } else {
                    // See if the return path has been unblocked, and give a small amount of backup energy to try to get home
                    this.AIstate = AISTATE_RETURNING;
                    if (this.energyLevel <= 0) {
                        this.energyLevel = 20;
                    }
                }
            }
            break;
        case AISTATE_ATBASE:
            this.atBase();
            break;
        case AISTATE_TRAVELLING:
            if (!this.moveToTarget()) {
                this.prepareMove(TEMPFAST ? 8 : 2, 2);
            }
            break;
        case AISTATE_MINING:
            if (!this.doMining() && this.ticksExisted % 2 == 0) {
                this.energyLevel--;
                this.prepareMove(TEMPFAST ? 8 : 1, 2);
            }
            break;
        case AISTATE_RETURNING:
            this.moveToBase();
            this.prepareMove(TEMPFAST ? 8 : 4, 1);
            break;
        case AISTATE_DOCKING:
            if (this.waypointBase != null) {
                this.speed = speedbase / 1.6;
                this.rotSpeed = rotSpeedBase / 1.6F;
                if (this.moveToPos(this.waypointBase, true)) {
                    this.AIstate = AISTATE_ATBASE;
                    this.motionX = 0;
                    this.motionY = 0;
                    this.motionZ = 0;
                    this.speed = speedbase;
                    this.rotSpeed = rotSpeedBase;
                }
            } else {
                GCLog.severe("AstroMiner missing base position: this is a bug.");
                this.AIstate = AISTATE_STUCK;
            }
            break;
    }
    GalacticraftCore.packetPipeline.sendToDimension(new PacketDynamic(this), GCCoreUtil.getDimensionID(this.worldObj));
    this.posX += this.motionX;
    this.posY += this.motionY;
    this.posZ += this.motionZ;
    setEntityBoundingBox(getEntityBoundingBox().offset(this.motionX, this.motionY, this.motionZ));
/*        if (this.dataWatcher.getWatchableObjectInt(this.timeSinceHit) > 0)
        {
            this.dataWatcher.updateObject(this.timeSinceHit, Integer.valueOf(this.dataWatcher.getWatchableObjectInt(this.timeSinceHit) - 1));
        }

        if (this.dataWatcher.getWatchableObjectInt(this.currentDamage) > 0)
        {
            this.dataWatcher.updateObject(this.currentDamage, Integer.valueOf(this.dataWatcher.getWatchableObjectInt(this.currentDamage) - 1));
        }       
*/
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityMinerBase(micdoodle8.mods.galacticraft.planets.asteroids.tile.TileEntityMinerBase) UUID(java.util.UUID) PacketDynamic(micdoodle8.mods.galacticraft.core.network.PacketDynamic) WorldProviderAsteroids(micdoodle8.mods.galacticraft.planets.asteroids.dimension.WorldProviderAsteroids)

Example 5 with WorldProviderAsteroids

use of micdoodle8.mods.galacticraft.planets.asteroids.dimension.WorldProviderAsteroids in project Galacticraft by micdoodle8.

the class AsteroidsPlayerHandler method onPlayerUpdate.

public void onPlayerUpdate(EntityPlayerMP player) {
    if (!player.worldObj.isRemote && player.worldObj.provider instanceof WorldProviderAsteroids) {
        final int f = 50;
        if (player.worldObj.rand.nextInt(f) == 0 && player.posY < 260D) {
            final EntityPlayer closestPlayer = player.worldObj.getClosestPlayerToEntity(player, 100);
            if (closestPlayer == null || closestPlayer.getEntityId() <= player.getEntityId()) {
                double x, y, z;
                double motX, motY, motZ;
                double r = player.worldObj.rand.nextInt(60) + 30D;
                double theta = Math.PI * 2.0 * player.worldObj.rand.nextDouble();
                x = player.posX + Math.cos(theta) * r;
                y = player.posY + player.worldObj.rand.nextInt(5);
                z = player.posZ + Math.sin(theta) * r;
                motX = (player.posX - x + (player.worldObj.rand.nextDouble() - 0.5) * 40) / 400.0F;
                motY = (player.worldObj.rand.nextDouble() - 0.5) * 0.4;
                motZ = (player.posZ - z + (player.worldObj.rand.nextDouble() - 0.5) * 40) / 400.0F;
                final EntitySmallAsteroid smallAsteroid = new EntitySmallAsteroid(player.worldObj);
                smallAsteroid.setPosition(x, y, z);
                smallAsteroid.motionX = motX;
                smallAsteroid.motionY = motY;
                smallAsteroid.motionZ = motZ;
                smallAsteroid.spinYaw = player.worldObj.rand.nextFloat() * 4;
                smallAsteroid.spinPitch = player.worldObj.rand.nextFloat() * 2;
                player.worldObj.spawnEntityInWorld(smallAsteroid);
            }
        }
    }
}
Also used : EntitySmallAsteroid(micdoodle8.mods.galacticraft.planets.asteroids.entities.EntitySmallAsteroid) EntityPlayer(net.minecraft.entity.player.EntityPlayer) WorldProviderAsteroids(micdoodle8.mods.galacticraft.planets.asteroids.dimension.WorldProviderAsteroids)

Aggregations

WorldProviderAsteroids (micdoodle8.mods.galacticraft.planets.asteroids.dimension.WorldProviderAsteroids)10 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)4 Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)3 ItemStack (net.minecraft.item.ItemStack)3 UUID (java.util.UUID)2 IGalacticraftWorldProvider (micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider)2 ITeleportType (micdoodle8.mods.galacticraft.api.world.ITeleportType)2 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 WorldServer (net.minecraft.world.WorldServer)2 Chunk (net.minecraft.world.chunk.Chunk)2 Field (java.lang.reflect.Field)1 IZeroGDimension (micdoodle8.mods.galacticraft.api.world.IZeroGDimension)1 CloudRenderer (micdoodle8.mods.galacticraft.core.client.CloudRenderer)1 SpaceRace (micdoodle8.mods.galacticraft.core.dimension.SpaceRace)1 WorldProviderMoon (micdoodle8.mods.galacticraft.core.dimension.WorldProviderMoon)1 WorldProviderSpaceStation (micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)1 EntityLanderBase (micdoodle8.mods.galacticraft.core.entities.EntityLanderBase)1 EntityParachest (micdoodle8.mods.galacticraft.core.entities.EntityParachest)1 InventoryExtended (micdoodle8.mods.galacticraft.core.inventory.InventoryExtended)1