Search in sources :

Example 1 with TileEntityMinerBase

use of micdoodle8.mods.galacticraft.planets.asteroids.tile.TileEntityMinerBase in project Galacticraft by micdoodle8.

the class EntityAstroMiner method decodePacketdata.

// packet with AIstate, energy, rotationP + Y, mining data count
@Override
public void decodePacketdata(ByteBuf buffer) {
    this.AIstate = buffer.readInt();
    this.energyLevel = buffer.readInt();
    this.targetPitch = buffer.readFloat();
    this.targetYaw = buffer.readFloat();
    this.mineCount = buffer.readInt();
    int x = buffer.readInt();
    int y = buffer.readInt();
    int z = buffer.readInt();
    BlockPos pos = new BlockPos(x, y, z);
    if (this.worldObj.isBlockLoaded(pos)) {
        TileEntity tile = this.worldObj.getTileEntity(pos);
        if (tile instanceof TileEntityMinerBase) {
            ((TileEntityMinerBase) tile).linkedMiner = this;
            ((TileEntityMinerBase) tile).linkCountDown = 20;
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityMinerBase(micdoodle8.mods.galacticraft.planets.asteroids.tile.TileEntityMinerBase)

Example 2 with TileEntityMinerBase

use of micdoodle8.mods.galacticraft.planets.asteroids.tile.TileEntityMinerBase 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 3 with TileEntityMinerBase

use of micdoodle8.mods.galacticraft.planets.asteroids.tile.TileEntityMinerBase in project Galacticraft by micdoodle8.

the class EntityAstroMiner method setDead.

@Override
public void setDead() {
    if (!this.worldObj.isRemote && this.playerMP != null) {
        GCPlayerStats stats = GCPlayerStats.get(this.playerMP);
        if (!this.spawnedInCreative) {
            int astroCount = stats.getAstroMinerCount();
            if (astroCount > 0) {
                stats.setAstroMinerCount(stats.getAstroMinerCount() - 1);
            }
        }
        AsteroidsTickHandlerServer.removeChunkData(stats, this);
    }
    super.setDead();
    if (posBase != null) {
        TileEntity tileEntity = posBase.getTileEntity(this.worldObj);
        if (tileEntity instanceof TileEntityMinerBase) {
            ((TileEntityMinerBase) tileEntity).unlinkMiner();
        }
    }
    if (this.soundUpdater != null) {
        this.soundUpdater.update();
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) TileEntityMinerBase(micdoodle8.mods.galacticraft.planets.asteroids.tile.TileEntityMinerBase)

Example 4 with TileEntityMinerBase

use of micdoodle8.mods.galacticraft.planets.asteroids.tile.TileEntityMinerBase in project Galacticraft by micdoodle8.

the class EntityAstroMiner method atBase.

private void atBase() {
    TileEntity tileEntity = posBase.getTileEntity(this.worldObj);
    if (!(tileEntity instanceof TileEntityMinerBase) || tileEntity.isInvalid() || !((TileEntityMinerBase) tileEntity).isMaster) {
        this.freeze(FAIL_BASEDESTROYED);
        return;
    }
    TileEntityMinerBase minerBase = (TileEntityMinerBase) tileEntity;
    // If it's successfully reached its base, clear all fail messages except number 6, which is that all mining areas are finished (see below)
    this.givenFailMessage &= 64;
    this.wayPoints.clear();
    boolean somethingTransferred = true;
    if (this.ticksExisted % 5 == 0) {
        somethingTransferred = this.emptyInventory(minerBase);
    }
    this.inventoryDrops = 0;
    // Recharge
    if (minerBase.hasEnoughEnergyToRun && this.energyLevel < MAXENERGY) {
        this.energyLevel += 16;
        minerBase.storage.extractEnergyGC(minerBase.storage.getMaxExtract(), false);
    }
    // When fully charged, set off again
    if (this.energyLevel >= MAXENERGY && !somethingTransferred && this.hasHoldSpace()) {
        this.energyLevel = MAXENERGY;
        if (this.findNextTarget(minerBase)) {
            this.AIstate = AISTATE_TRAVELLING;
            this.wayPoints.add(this.waypointBase.clone());
            this.mineCount = 0;
        } else {
            if (this.playerMP != null && (this.givenFailMessage & 64) == 0) {
                this.playerMP.addChatMessage(new ChatComponentText(GCCoreUtil.translate("gui.message.astro_miner6.fail")));
                this.givenFailMessage += 64;
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityMinerBase(micdoodle8.mods.galacticraft.planets.asteroids.tile.TileEntityMinerBase)

Example 5 with TileEntityMinerBase

use of micdoodle8.mods.galacticraft.planets.asteroids.tile.TileEntityMinerBase in project Galacticraft by micdoodle8.

the class BlockMinerBaseFull method breakBlock.

@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
    TileEntity tileEntity = worldIn.getTileEntity(pos);
    if (tileEntity instanceof TileEntityMinerBase) {
        ((TileEntityMinerBase) tileEntity).onBlockRemoval();
    }
    super.breakBlock(worldIn, pos, state);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityMinerBase(micdoodle8.mods.galacticraft.planets.asteroids.tile.TileEntityMinerBase)

Aggregations

TileEntityMinerBase (micdoodle8.mods.galacticraft.planets.asteroids.tile.TileEntityMinerBase)6 TileEntity (net.minecraft.tileentity.TileEntity)6 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)2 UUID (java.util.UUID)1 WorldProviderSpaceStation (micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation)1 PacketDynamic (micdoodle8.mods.galacticraft.core.network.PacketDynamic)1 TileEntityMulti (micdoodle8.mods.galacticraft.core.tile.TileEntityMulti)1 WorldProviderAsteroids (micdoodle8.mods.galacticraft.planets.asteroids.dimension.WorldProviderAsteroids)1 Block (net.minecraft.block.Block)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 ChatComponentText (net.minecraft.util.ChatComponentText)1