use of micdoodle8.mods.galacticraft.core.network.PacketDynamic 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.core.network.PacketDynamic in project Galacticraft by micdoodle8.
the class EntityAdvanced method onUpdate.
@Override
public void onUpdate() {
super.onUpdate();
this.ticks++;
if (this.isNetworkedEntity()) {
if (!this.worldObj.isRemote && this.ticks % this.getPacketCooldown(Side.CLIENT) == 0) {
if (this.fieldCacheClient == null) {
try {
this.initFieldCache();
} catch (Exception e) {
e.printStackTrace();
}
}
PacketDynamic packet = new PacketDynamic(this);
if (networkDataChanged) {
GalacticraftCore.packetPipeline.sendToAllAround(packet, new TargetPoint(GCCoreUtil.getDimensionID(this.worldObj), this.posX, this.posY, this.posZ, this.getPacketRange()));
}
}
if (this.worldObj.isRemote && this.ticks % this.getPacketCooldown(Side.SERVER) == 0) {
if (// The target server cache may have been initialised to an empty set
this.fieldCacheClient == null) {
try {
this.initFieldCache();
} catch (Exception e) {
e.printStackTrace();
}
}
PacketDynamic packet = new PacketDynamic(this);
if (networkDataChanged) {
GalacticraftCore.packetPipeline.sendToServer(packet);
}
}
}
}
use of micdoodle8.mods.galacticraft.core.network.PacketDynamic in project Galacticraft by micdoodle8.
the class EntityLanderBase method readNetworkedData.
@Override
public void readNetworkedData(ByteBuf buffer) {
try {
if (this.worldObj.isRemote) {
if (!this.hasReceivedPacket) {
GalacticraftCore.packetPipeline.sendToServer(new PacketDynamic(this));
this.hasReceivedPacket = true;
}
int cargoLength = buffer.readInt();
if (this.containedItems == null || this.containedItems.length == 0) {
this.containedItems = new ItemStack[cargoLength];
GalacticraftCore.packetPipeline.sendToServer(new PacketDynamicInventory(this));
}
this.fuelTank.setFluid(new FluidStack(GCFluids.fluidFuel, buffer.readInt()));
this.shouldMoveServer = buffer.readBoolean();
// Check has correct rider on client
int shouldBeMountedId = buffer.readInt();
if (this.riddenByEntity == null) {
if (shouldBeMountedId > -1) {
Entity e = FMLClientHandler.instance().getWorldClient().getEntityByID(shouldBeMountedId);
if (e != null) {
if (e.dimension != this.dimension) {
if (e instanceof EntityPlayer) {
e = WorldUtil.forceRespawnClient(this.dimension, e.worldObj.getDifficulty().getDifficultyId(), e.worldObj.getWorldInfo().getTerrainType().getWorldTypeName(), ((EntityPlayerMP) e).theItemInWorldManager.getGameType().getID());
e.mountEntity(this);
this.syncAdjustFlag = true;
}
} else {
e.mountEntity(this);
this.syncAdjustFlag = true;
}
}
}
} else if (this.riddenByEntity.getEntityId() != shouldBeMountedId) {
if (shouldBeMountedId == -1) {
this.riddenByEntity.mountEntity(null);
} else {
Entity e = FMLClientHandler.instance().getWorldClient().getEntityByID(shouldBeMountedId);
if (e != null) {
if (e.dimension != this.dimension) {
if (e instanceof EntityPlayer) {
e = WorldUtil.forceRespawnClient(this.dimension, e.worldObj.getDifficulty().getDifficultyId(), e.worldObj.getWorldInfo().getTerrainType().getWorldTypeName(), ((EntityPlayerMP) e).theItemInWorldManager.getGameType().getID());
e.mountEntity(this);
this.syncAdjustFlag = true;
}
} else {
e.mountEntity(this);
this.syncAdjustFlag = true;
}
}
}
}
} else {
this.shouldMoveClient = buffer.readBoolean();
}
} catch (final Exception e) {
e.printStackTrace();
}
}
use of micdoodle8.mods.galacticraft.core.network.PacketDynamic in project Galacticraft by micdoodle8.
the class EntityParachest method onUpdate.
@Override
public void onUpdate() {
if (!this.placedChest) {
if (this.onGround && !this.worldObj.isRemote) {
for (int i = 0; i < 100; i++) {
final int x = MathHelper.floor_double(this.posX);
final int y = MathHelper.floor_double(this.posY);
final int z = MathHelper.floor_double(this.posZ);
BlockPos pos = new BlockPos(x, y + i, z);
Block block = this.worldObj.getBlockState(pos).getBlock();
if (block.getMaterial().isReplaceable()) {
if (this.placeChest(pos)) {
this.setDead();
return;
} else if (this.cargo != null) {
for (final ItemStack stack : this.cargo) {
final EntityItem e = new EntityItem(this.worldObj, this.posX, this.posY, this.posZ, stack);
this.worldObj.spawnEntityInWorld(e);
}
return;
}
}
}
if (this.cargo != null) {
for (final ItemStack stack : this.cargo) {
final EntityItem e = new EntityItem(this.worldObj, this.posX, this.posY, this.posZ, stack);
this.worldObj.spawnEntityInWorld(e);
}
}
} else {
this.motionY = -0.35;
}
this.moveEntity(0, this.motionY, 0);
}
if (!this.worldObj.isRemote && this.ticksExisted % 5 == 0) {
GalacticraftCore.packetPipeline.sendToAllAround(new PacketDynamic(this), new NetworkRegistry.TargetPoint(GCCoreUtil.getDimensionID(this.worldObj), this.posX, this.posY, this.posZ, 64.0));
}
}
use of micdoodle8.mods.galacticraft.core.network.PacketDynamic in project Galacticraft by micdoodle8.
the class NetworkedEntity method onUpdate.
@Override
public void onUpdate() {
super.onUpdate();
PacketDynamic packet = new PacketDynamic(this);
if (this.networkedDataChanged()) {
if (!this.worldObj.isRemote) {
GalacticraftCore.packetPipeline.sendToAllAround(packet, new TargetPoint(GCCoreUtil.getDimensionID(this.worldObj), this.posX, this.posY, this.posZ, this.getPacketRange()));
} else {
GalacticraftCore.packetPipeline.sendToServer(packet);
}
}
}
Aggregations