use of micdoodle8.mods.galacticraft.planets.asteroids.entities.EntityAstroMiner in project Galacticraft by micdoodle8.
the class AsteroidsTickHandlerServer method onServerTick.
@SubscribeEvent
public void onServerTick(TickEvent.ServerTickEvent event) {
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
// Prevent issues when clients switch to LAN servers
if (server == null) {
return;
}
if (event.phase == TickEvent.Phase.START) {
TileEntityMinerBase.checkNewMinerBases();
if (AsteroidsTickHandlerServer.spaceRaceData == null) {
World world = server.worldServerForDimension(0);
AsteroidsTickHandlerServer.spaceRaceData = (ShortRangeTelepadHandler) world.getMapStorage().loadData(ShortRangeTelepadHandler.class, ShortRangeTelepadHandler.saveDataID);
if (AsteroidsTickHandlerServer.spaceRaceData == null) {
AsteroidsTickHandlerServer.spaceRaceData = new ShortRangeTelepadHandler(ShortRangeTelepadHandler.saveDataID);
world.getMapStorage().setData(ShortRangeTelepadHandler.saveDataID, AsteroidsTickHandlerServer.spaceRaceData);
}
}
int index = -1;
for (EntityAstroMiner miner : activeMiners) {
index++;
if (miner.isDead) {
// minerIt.remove(); Don't remove it, we want the index number to be static for the others
continue;
}
if (miner.playerMP != null) {
GCPlayerStats stats = GCPlayerStats.get(miner.playerMP);
if (stats != null) {
List<BlockVec3> list = stats.getActiveAstroMinerChunks();
boolean inListAlready = false;
Iterator<BlockVec3> it = list.iterator();
while (it.hasNext()) {
BlockVec3 data = it.next();
if (// SideDoneBits won't be saved to NBT, but during an active server session we can use it as a cross-reference to the index here - it's a 4th data int hidden inside a BlockVec3
data.sideDoneBits == index) {
if (miner.isDead) {
// Player stats should not save position of dead AstroMiner entity (probably broken by player deliberately breaking it)
it.remove();
} else {
data.x = miner.chunkCoordX;
data.z = miner.chunkCoordZ;
}
inListAlready = true;
break;
}
}
if (!inListAlready && !miner.isDead) {
BlockVec3 data = new BlockVec3(miner.chunkCoordX, miner.dimension, miner.chunkCoordZ);
data.sideDoneBits = index;
list.add(data);
}
}
}
}
}
}
use of micdoodle8.mods.galacticraft.planets.asteroids.entities.EntityAstroMiner in project Galacticraft by micdoodle8.
the class RenderAstroMiner method doRender.
@Override
public void doRender(EntityAstroMiner astroMiner, double x, double y, double z, float f, float partialTickTime) {
int ais = astroMiner.AIstate;
boolean active = ais > EntityAstroMiner.AISTATE_ATBASE;
float time = astroMiner.ticksExisted + partialTickTime;
float sinOfTheTime = (MathHelper.sin(time / 4) + 1F) / 4F + 0.5F;
float wx = active ? this.wobbleX.getNoise(time) + this.wobbleXX.getNoise(time) : 0F;
float wy = active ? this.wobbleY.getNoise(time) + this.wobbleYY.getNoise(time) : 0F;
float wz = active ? this.wobbleZ.getNoise(time) + this.wobbleZZ.getNoise(time) : 0F;
float partTime = partialTickTime - this.lastPartTime;
this.lastPartTime = partialTickTime;
while (partTime < 0) {
partTime += 1F;
}
this.updateModels();
this.bindEntityTexture(astroMiner);
if (Minecraft.isAmbientOcclusionEnabled()) {
GlStateManager.shadeModel(GL11.GL_SMOOTH);
} else {
GlStateManager.shadeModel(GL11.GL_FLAT);
}
GlStateManager.disableRescaleNormal();
GlStateManager.pushMatrix();
final float rotPitch = astroMiner.prevRotationPitch + (astroMiner.rotationPitch - astroMiner.prevRotationPitch) * partialTickTime;
final float rotYaw = astroMiner.prevRotationYaw + (astroMiner.rotationYaw - astroMiner.prevRotationYaw) * partialTickTime;
GlStateManager.translate((float) x, (float) y + 1.4F, (float) z);
float partBlock;
switch(astroMiner.facing) {
case DOWN:
partBlock = (float) (astroMiner.posY % 2D);
break;
case UP:
partBlock = 1F - (float) (astroMiner.posY % 2D);
break;
case NORTH:
partBlock = (float) (astroMiner.posZ % 2D);
break;
case SOUTH:
partBlock = 1F - (float) (astroMiner.posZ % 2D);
break;
case WEST:
partBlock = (float) (astroMiner.posX % 2D);
break;
case EAST:
partBlock = 1F - (float) (astroMiner.posX % 2D);
break;
default:
partBlock = 0F;
}
partBlock /= 0.06F;
GlStateManager.rotate(rotYaw + 180F, 0, 1, 0);
if (rotPitch != 0F) {
GlStateManager.translate(-0.65F, -0.65F, 0);
GlStateManager.rotate(rotPitch / 4F, 1, 0, 0);
GlStateManager.translate(0.65F, 0.65F, 0);
}
GlStateManager.translate(0F, -0.42F, 0.28F);
GlStateManager.scale(0.0495F, 0.0495F, 0.0495F);
GlStateManager.translate(wx, wy, wz);
if (active) {
ClientUtil.drawBakedModel(this.mainModel);
this.renderLaserModel(astroMiner.retraction);
float lightMapSaveX = OpenGlHelper.lastBrightnessX;
float lightMapSaveY = OpenGlHelper.lastBrightnessY;
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240F, 240F);
GlStateManager.disableLighting();
GlStateManager.color(sinOfTheTime, sinOfTheTime, sinOfTheTime, 1.0F);
ClientUtil.drawBakedModel(this.hoverPadMain);
GlStateManager.disableCull();
GlStateManager.disableAlpha();
GlStateManager.depthMask(false);
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
GlStateManager.enableBlend();
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
GlStateManager.color(sinOfTheTime, sinOfTheTime, sinOfTheTime, 0.6F);
ClientUtil.drawBakedModel(this.hoverPadGlow);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
if (ais < EntityAstroMiner.AISTATE_DOCKING) {
// This is the scanning lasers:
FMLClientHandler.instance().getClient().renderEngine.bindTexture(scanTexture);
final Tessellator tess = Tessellator.getInstance();
GlStateManager.color(0, 0.6F, 1.0F, 0.2F);
WorldRenderer worldRenderer = tess.getWorldRenderer();
float scanProgress = (MathHelper.cos(partBlock * 0.012F * 6.283F)) * 0.747F;
float scanAngle = 0.69866F - scanProgress * scanProgress;
float scanEndX = 38.77F * MathHelper.sin(scanAngle);
float scanEndY = 32F;
float scanEndZ = 38.77F * MathHelper.cos(scanAngle);
scanEndZ += 20F;
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
worldRenderer.pos(15.6F, -0.6F, -20F).tex(0D, 0D).endVertex();
worldRenderer.pos(15.6F + scanEndX, scanEndY - 0.6F, -scanEndZ).tex(1D, 0D).endVertex();
worldRenderer.pos(15.6F + scanEndX, -0.6F - scanEndY, -scanEndZ).tex(1D, 1D).endVertex();
worldRenderer.pos(15.6F, -0.7F, -20F).tex(0D, 1D).endVertex();
tess.draw();
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
worldRenderer.pos(-15.6F, -0.6F, -20F).tex(0D, 0D).endVertex();
worldRenderer.pos(-15.6F - scanEndX, scanEndY - 0.6F, -scanEndZ).tex(1D, 0D).endVertex();
worldRenderer.pos(-15.6F - scanEndX, -0.6F - scanEndY, -scanEndZ).tex(1D, 1D).endVertex();
worldRenderer.pos(-15.6F, -0.7F, -20F).tex(0D, 1D).endVertex();
tess.draw();
int removeCount = 0;
int afterglowCount = 0;
GlStateManager.popMatrix();
GlStateManager.pushMatrix();
GlStateManager.translate((float) (x - astroMiner.posX), (float) (y - astroMiner.posY), (float) (z - astroMiner.posZ));
for (Integer blockTime : new ArrayList<Integer>(astroMiner.laserTimes)) {
if (blockTime < astroMiner.ticksExisted - 19) {
removeCount++;
} else if (blockTime < astroMiner.ticksExisted - 3) {
afterglowCount++;
}
}
if (removeCount > 0) {
astroMiner.removeLaserBlocks(removeCount);
}
int count = 0;
for (BlockVec3 blockLaser : new ArrayList<BlockVec3>(astroMiner.laserBlocks)) {
if (count < afterglowCount) {
int fade = astroMiner.ticksExisted - astroMiner.laserTimes.get(count) - 8;
if (fade < 0) {
fade = 0;
}
this.doAfterGlow(blockLaser, fade);
} else {
this.doLaser(astroMiner, blockLaser);
}
count++;
}
if (astroMiner.retraction > 0F) {
astroMiner.retraction -= RETRACTIONSPEED * partTime;
if (astroMiner.retraction < 0F) {
astroMiner.retraction = 0F;
}
}
GlStateManager.popMatrix();
} else {
if (astroMiner.retraction < 1F) {
astroMiner.retraction += RETRACTIONSPEED * partTime;
if (astroMiner.retraction > 1F) {
astroMiner.retraction = 1F;
}
}
GlStateManager.popMatrix();
}
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.disableBlend();
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GlStateManager.enableCull();
GlStateManager.enableAlpha();
GlStateManager.enableLighting();
GlStateManager.depthMask(true);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, lightMapSaveX, lightMapSaveY);
} else {
this.bindEntityTexture(astroMiner);
ClientUtil.drawBakedModel(this.mainModelInactive);
this.renderLaserModel(astroMiner.retraction);
if (astroMiner.retraction < 1F) {
astroMiner.retraction += RETRACTIONSPEED * partTime;
if (astroMiner.retraction > 1F) {
astroMiner.retraction = 1F;
}
}
GlStateManager.popMatrix();
}
}
use of micdoodle8.mods.galacticraft.planets.asteroids.entities.EntityAstroMiner 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));
}
*/
}
use of micdoodle8.mods.galacticraft.planets.asteroids.entities.EntityAstroMiner in project Galacticraft by micdoodle8.
the class AsteroidsTickHandlerServer method removeChunkData.
public static void removeChunkData(GCPlayerStats stats, EntityAstroMiner entityToRemove) {
int index = 0;
for (EntityAstroMiner miner : activeMiners) {
if (// Found it in the list here
miner == entityToRemove) {
List<BlockVec3> list = stats.getActiveAstroMinerChunks();
Iterator<BlockVec3> it = list.iterator();
while (it.hasNext()) {
BlockVec3 data = it.next();
if (// Found it in the player's stats
data.sideDoneBits == index) {
it.remove();
return;
}
}
return;
}
index++;
}
}
use of micdoodle8.mods.galacticraft.planets.asteroids.entities.EntityAstroMiner in project Galacticraft by micdoodle8.
the class TileEntityMinerBase method updateGUIstate.
public void updateGUIstate() {
if (this.linkedMinerID == null) {
this.linkedMinerDataAIState = -3;
return;
}
EntityAstroMiner miner = this.linkedMiner;
if (miner == null || miner.isDead) {
this.linkedMinerDataAIState = -3;
return;
}
if (this.linkCountDown > 0) {
this.linkedMinerDataAIState = -2;
return;
}
this.linkedMinerDataAIState = miner.AIstate;
this.linkedMinerDataDX = (MathHelper.floor_double(this.linkedMiner.posX) - this.getPos().getX() - 1);
this.linkedMinerDataDY = (MathHelper.floor_double(this.linkedMiner.posY) - this.getPos().getY() - 1);
this.linkedMinerDataDZ = (MathHelper.floor_double(this.linkedMiner.posZ) - this.getPos().getZ() - 1);
this.linkedMinerDataCount = miner.mineCount;
}
Aggregations