use of micdoodle8.mods.galacticraft.api.vector.BlockVec3 in project Galacticraft by micdoodle8.
the class TileEntityMethaneSynthesizer method produceOutput.
private boolean produceOutput(EnumFacing outputDirection) {
int provide = this.getMethaneProvide();
if (provide > 0) {
TileEntity outputTile = new BlockVec3(this).getTileEntityOnSide(this.worldObj, outputDirection);
FluidNetwork outputNetwork = NetworkHelper.getFluidNetworkFromTile(outputTile, outputDirection);
if (outputNetwork != null) {
int gasRequested = outputNetwork.getRequest();
if (gasRequested > 0) {
int usedGas = outputNetwork.emitToBuffer(new FluidStack(AsteroidsModule.fluidMethaneGas, Math.min(gasRequested, provide)), true);
this.liquidTank.drain(usedGas, true);
return true;
}
}
}
return false;
}
use of micdoodle8.mods.galacticraft.api.vector.BlockVec3 in project Galacticraft by micdoodle8.
the class PacketSimpleAsteroids method handleClientSide.
@SideOnly(Side.CLIENT)
@Override
public void handleClientSide(EntityPlayer player) {
EntityPlayerSP playerBaseClient = null;
if (player instanceof EntityPlayerSP) {
playerBaseClient = (EntityPlayerSP) player;
}
TileEntity tile;
switch(this.type) {
case C_TELEPAD_SEND:
Entity entity = playerBaseClient.worldObj.getEntityByID((Integer) this.data.get(1));
if (entity != null && entity instanceof EntityLivingBase) {
BlockVec3 pos = (BlockVec3) this.data.get(0);
entity.setPosition(pos.x + 0.5, pos.y + 2.2, pos.z + 0.5);
}
break;
case C_UPDATE_GRAPPLE_POS:
entity = playerBaseClient.worldObj.getEntityByID((Integer) this.data.get(0));
if (entity != null && entity instanceof EntityGrapple) {
Vector3 vec = (Vector3) this.data.get(1);
entity.setPosition(vec.x, vec.y, vec.z);
}
break;
default:
break;
}
}
use of micdoodle8.mods.galacticraft.api.vector.BlockVec3 in project Galacticraft by micdoodle8.
the class ChunkProviderAsteroids method populate.
@Override
public void populate(IChunkProvider par1IChunkProvider, int chunkX, int chunkZ) {
int x = chunkX << 4;
int z = chunkZ << 4;
if (!ChunkProviderAsteroids.chunksDone.add(new BlockVec3(x, 0, z))) {
return;
}
BlockFalling.fallInstantly = true;
this.worldObj.getBiomeGenForCoords(new BlockPos(x + 16, 0, z + 16));
BlockFalling.fallInstantly = false;
this.rand.setSeed(this.worldObj.getSeed());
long var7 = this.rand.nextLong() / 2L * 2L + 1L;
long var9 = this.rand.nextLong() / 2L * 2L + 1L;
this.rand.setSeed(chunkX * var7 + chunkZ * var9 ^ this.worldObj.getSeed());
// 50:50 chance to include small blocks each chunk
if (this.rand.nextBoolean()) {
double density = this.asteroidDensity.getNoise(chunkX * 16, chunkZ * 16) * 0.54;
double numOfBlocks = this.clamp(this.randFromPoint(chunkX, chunkZ), .4, 1) * ChunkProviderAsteroids.MAX_BLOCKS_PER_CHUNK * density + ChunkProviderAsteroids.MIN_BLOCKS_PER_CHUNK;
int y0 = this.rand.nextInt(2);
Block block;
int meta;
int yRange = ChunkProviderAsteroids.MAX_ASTEROID_Y - ChunkProviderAsteroids.MIN_ASTEROID_Y;
x += 4;
z += 4;
for (int i = 0; i < numOfBlocks; i++) {
int y = this.rand.nextInt(yRange) + ChunkProviderAsteroids.MIN_ASTEROID_Y;
// 50:50 chance vertically as well
if (y0 == (y / 16) % 2) {
int px = x + this.rand.nextInt(ChunkProviderAsteroids.CHUNK_SIZE_X);
int pz = z + this.rand.nextInt(ChunkProviderAsteroids.CHUNK_SIZE_Z);
block = this.ASTEROID_STONE;
meta = this.ASTEROID_STONE_META_1;
if (this.rand.nextInt(ILMENITE_CHANCE) == 0) {
meta = 4;
if (ConfigManagerAsteroids.disableIlmeniteGen) {
continue;
}
} else if (this.rand.nextInt(IRON_CHANCE) == 0) {
meta = 5;
if (ConfigManagerAsteroids.disableIronGen) {
continue;
}
} else if (this.rand.nextInt(ALUMINUM_CHANCE) == 0) {
meta = 3;
if (ConfigManagerAsteroids.disableAluminumGen) {
continue;
}
}
worldObj.setBlockState(new BlockPos(px, y, pz), block.getStateFromMeta(meta), 2);
int count = 9;
if (!(worldObj.getBlockState(new BlockPos(px - 1, y, pz)).getBlock() instanceof BlockAir)) {
count = 1;
} else if (!(worldObj.getBlockState(new BlockPos(px - 2, y, pz)).getBlock() instanceof BlockAir)) {
count = 3;
} else if (!(worldObj.getBlockState(new BlockPos(px - 3, y, pz)).getBlock() instanceof BlockAir)) {
count = 5;
} else if (!(worldObj.getBlockState(new BlockPos(px - 4, y, pz)).getBlock() instanceof BlockAir)) {
count = 7;
}
// LIGHTEMP worldObj.setLightFor(EnumSkyBlock.BLOCK, new BlockPos(px - (count > 1 ? 1 : 0), y, pz), count);
}
}
}
if (this.largeAsteroidsLastChunkX != chunkX || this.largeAsteroidsLastChunkZ != chunkZ) {
this.generateTerrain(chunkX, chunkZ, null, true);
}
this.rand.setSeed(chunkX * var7 + chunkZ * var9 ^ this.worldObj.getSeed());
// Look for hollow asteroids to populate
if (!this.largeAsteroids.isEmpty()) {
for (AsteroidData asteroidIndex : new ArrayList<AsteroidData>(this.largeAsteroids)) {
if (!asteroidIndex.isHollow) {
continue;
}
float[] sizeYArray = asteroidIndex.sizeYArray;
int xMin = asteroidIndex.xMinArray;
int zMin = asteroidIndex.zMinArray;
int zSize = asteroidIndex.zSizeArray;
int asteroidY = asteroidIndex.asteroidYArray;
int asteroidSize = asteroidIndex.asteroidSizeArray;
boolean treesdone = false;
if (ConfigManagerCore.challengeAsteroidPopulation || rand.nextInt(ChunkProviderAsteroids.TREE_CHANCE) == 0) {
int treeType = rand.nextInt(3);
if (treeType == 1) {
treeType = 0;
}
IBlockState log = Blocks.log.getDefaultState().withProperty(BlockOldLog.VARIANT, BlockPlanks.EnumType.OAK);
IBlockState leaves = Blocks.leaves.getDefaultState().withProperty(BlockOldLeaf.VARIANT, BlockPlanks.EnumType.OAK).withProperty(BlockLeaves.CHECK_DECAY, Boolean.valueOf(false));
WorldGenTrees wg = new WorldGenTrees(false, 2, log, leaves, false);
for (int tries = 0; tries < 5; tries++) {
int i = rand.nextInt(16) + x + 8;
int k = rand.nextInt(16) + z + 8;
if (wg.generate(worldObj, rand, new BlockPos(i, this.getTerrainHeightAt(i - x, k - z, sizeYArray, xMin, zMin, zSize, asteroidY, asteroidSize), k))) {
break;
}
}
treesdone = true;
}
if (!treesdone || rand.nextInt(ChunkProviderAsteroids.TALL_GRASS_CHANCE) == 0) {
int i = rand.nextInt(16) + x + 8;
int k = rand.nextInt(16) + z + 8;
new WorldGenTallGrass(GRASS_TYPE).generate(worldObj, rand, new BlockPos(i, this.getTerrainHeightAt(i - x, k - z, sizeYArray, xMin, zMin, zSize, asteroidY, asteroidSize), k));
}
if (rand.nextInt(ChunkProviderAsteroids.FLOWER_CHANCE) == 0) {
int i = rand.nextInt(16) + x + 8;
int k = rand.nextInt(16) + z + 8;
int[] types = new int[] { 2, 4, 5, 7 };
new WorldGenFlowers(this.FLOWER, EnumFlowerType.getType(BlockFlower.EnumFlowerColor.RED, types[rand.nextInt(types.length)])).generate(worldObj, rand, new BlockPos(i, this.getTerrainHeightAt(i - x, k - z, sizeYArray, xMin, zMin, zSize, asteroidY, asteroidSize), k));
}
if (rand.nextInt(ChunkProviderAsteroids.LAVA_CHANCE) == 0) {
int i = rand.nextInt(16) + x + 8;
int k = rand.nextInt(16) + z + 8;
new WorldGenLakes(this.LAVA).generate(worldObj, rand, new BlockPos(i, this.getTerrainHeightAt(i - x, k - z, sizeYArray, xMin, zMin, zSize, asteroidY, asteroidSize), k));
}
if (rand.nextInt(ChunkProviderAsteroids.WATER_CHANCE) == 0) {
int i = rand.nextInt(16) + x + 8;
int k = rand.nextInt(16) + z + 8;
new WorldGenLakes(this.WATER).generate(worldObj, rand, new BlockPos(i, this.getTerrainHeightAt(i - x, k - z, sizeYArray, xMin, zMin, zSize, asteroidY, asteroidSize), k));
}
}
}
// Update all block lighting
for (int xx = 0; xx < 16; xx++) {
int xPos = x + xx;
for (int zz = 0; zz < 16; zz++) {
int zPos = z + zz;
// Asteroid at min height 48, size 20, can't have lit blocks below 16
for (int y = 16; y < 240; y++) {
// LIGHTTEMP worldObj.checkLightFor(EnumSkyBlock.BLOCK, new BlockPos(xPos, y, zPos));
}
}
}
this.dungeonGenerator.generateStructure(this.worldObj, this.rand, new ChunkCoordIntPair(chunkX, chunkZ));
}
use of micdoodle8.mods.galacticraft.api.vector.BlockVec3 in project Galacticraft by micdoodle8.
the class TileEntityShortRangeTelepad method update.
@Override
public void update() {
if (this.ticks % 40 == 0 && !worldObj.isRemote) {
this.setAddress(this.address);
this.setTargetAddress(this.targetAddress);
}
if (!this.worldObj.isRemote) {
if (this.targetAddressResult == EnumTelepadSearchResult.VALID && (this.ticks % 5 == 0 || teleporting)) {
List containedEntities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.fromBounds(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), this.getPos().getX() + 1, this.getPos().getY() + 2, this.getPos().getZ() + 1));
if (containedEntities.size() > 0 && this.getEnergyStoredGC() >= ENERGY_USE_ON_TELEPORT) {
ShortRangeTelepadHandler.TelepadEntry entry = ShortRangeTelepadHandler.getLocationFromAddress(this.targetAddress);
if (entry != null) {
teleporting = true;
}
} else {
teleporting = false;
}
}
if (this.teleporting) {
this.teleportTime++;
if (teleportTime >= MAX_TELEPORT_TIME) {
ShortRangeTelepadHandler.TelepadEntry entry = ShortRangeTelepadHandler.getLocationFromAddress(this.targetAddress);
BlockVec3 finalPos = (entry == null) ? null : entry.position;
if (finalPos != null) {
TileEntity tileAt = finalPos.getTileEntity(this.worldObj);
List<EntityLivingBase> containedEntities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.fromBounds(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), this.getPos().getX() + 1, this.getPos().getY() + 2, this.getPos().getZ() + 1));
if (tileAt != null && tileAt instanceof TileEntityShortRangeTelepad) {
TileEntityShortRangeTelepad destTelepad = (TileEntityShortRangeTelepad) tileAt;
int teleportResult = destTelepad.canTeleportHere();
if (teleportResult == 0) {
for (EntityLivingBase e : containedEntities) {
e.setPosition(finalPos.x + 0.5F, finalPos.y + 1.0F, finalPos.z + 0.5F);
this.worldObj.updateEntityWithOptionalForce(e, true);
if (e instanceof EntityPlayerMP) {
((EntityPlayerMP) e).playerNetServerHandler.setPlayerLocation(finalPos.x, finalPos.y, finalPos.z, e.rotationYaw, e.rotationPitch);
}
GalacticraftCore.packetPipeline.sendToDimension(new PacketSimpleAsteroids(PacketSimpleAsteroids.EnumSimplePacketAsteroids.C_TELEPAD_SEND, GCCoreUtil.getDimensionID(this.worldObj), new Object[] { finalPos, e.getEntityId() }), GCCoreUtil.getDimensionID(this.worldObj));
}
if (containedEntities.size() > 0) {
this.storage.setEnergyStored(this.storage.getEnergyStoredGC() - ENERGY_USE_ON_TELEPORT);
destTelepad.storage.setEnergyStored(this.storage.getEnergyStoredGC() - ENERGY_USE_ON_TELEPORT);
}
} else {
switch(teleportResult) {
case -1:
for (EntityLivingBase e : containedEntities) {
if (e instanceof EntityPlayer) {
// No need for translation, since this should never happen
((EntityPlayer) e).addChatComponentMessage(new ChatComponentText("Cannot Send client-side"));
}
}
break;
case 1:
for (EntityLivingBase e : containedEntities) {
if (e instanceof EntityPlayer) {
// No need for translation, since this should never happen
((EntityPlayer) e).addChatComponentMessage(new ChatComponentText("Target address invalid"));
}
}
break;
case 2:
for (EntityLivingBase e : containedEntities) {
if (e instanceof EntityPlayer) {
((EntityPlayer) e).addChatComponentMessage(new ChatComponentText(GCCoreUtil.translate("gui.message.target_no_energy.name")));
}
}
break;
}
}
}
}
this.teleportTime = 0;
this.teleporting = false;
}
} else {
this.teleportTime = Math.max(--this.teleportTime, 0);
}
}
super.update();
}
use of micdoodle8.mods.galacticraft.api.vector.BlockVec3 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;
}
Aggregations