Planned update

This commit is contained in:
Anus 2013-05-19 17:52:40 +04:00
parent c514a08b99
commit 9824396ebb
12 changed files with 906 additions and 688 deletions

View file

@ -12,13 +12,13 @@ import net.minecraft.world.World;
public class BlockProtocol extends BlockContainer {
BlockProtocol(int id, int texture, Material material) {
super(id, texture, material);
super(id, material);
}
@Override
public String getTextureFile () {
return CommonProxy.BLOCK_TEXTURE;
}
// @Override
// public String getTextureFile () {
// return CommonProxy.BLOCK_TEXTURE;
// }
@Override
public TileEntity createNewTileEntity(World var1) {

View file

@ -12,13 +12,13 @@ import net.minecraft.world.World;
public class BlockReactor extends BlockContainer {
BlockReactor(int id, int texture, Material material) {
super(id, texture, material);
super(id, material);
}
@Override
public String getTextureFile () {
return CommonProxy.BLOCK_TEXTURE;
}
// @Override
// public String getTextureFile () {
// return CommonProxy.BLOCK_TEXTURE;
// }
@Override
public TileEntity createNewTileEntity(World var1) {

View file

@ -2,6 +2,7 @@ package cr0s.WarpDrive;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dan200.computer.api.IPeripheral;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
@ -100,6 +101,7 @@ public class EntityJump extends Entity {
}
public void killEntity(String reason) {
System.out.println("[JE] Tick:");
if (!on) { return; }
on = false;
@ -112,7 +114,7 @@ public class EntityJump extends Entity {
unlockWorlds();
try {
if (!this.fromSpace && !this.toSpace) { worldObj.setEntityDead(this); }
if (!this.fromSpace && !this.toSpace) { worldObj.removeEntity(this); }
//this.getTargetWorld().setEntityDead(this);
//this.setDead();
} catch (Exception e) {
@ -125,7 +127,7 @@ public class EntityJump extends Entity {
public void onUpdate() {
if (!on) {
unlockWorlds();
this.setDead();
worldObj.removeEntity(this);
return;
}
@ -133,18 +135,19 @@ public class EntityJump extends Entity {
this.killEntity("Y-coord error!");
return;
}
// Пропустить тик, ожидая генерации чанков
//if (!checkForChunksGeneratedIn(getTargetWorld())) {
// return;
//}
if ((getTargetWorld().provider.dimensionId == worldObj.provider.dimensionId) && !checkForChunksGeneratedIn(getTargetWorld())) {
return;
}
if (!isJumping) {
this.toSpace = (dir == -1 && (maxY + distance > 255) && worldObj.provider.dimensionId != WarpDrive.instance.spaceDimID);
this.fromSpace = (dir == -2 && (minY - distance < 0) && worldObj.provider.dimensionId == WarpDrive.instance.spaceDimID);
System.out.println("[JE] Preparing to jump...");
axisalignedbb = AxisAlignedBB.getBoundingBox(Xmin, minY, Zmin, Xmax, maxY, Zmax);
this.toSpace = (dir == -1 && (maxY + distance > 255) && worldObj.provider.dimensionId != WarpDrive.instance.spaceDimID);
this.fromSpace = (dir == -2 && (minY - distance < 0) && worldObj.provider.dimensionId == WarpDrive.instance.spaceDimID);
prepareToJump();
} else {
if (currentIndexInShip >= ship.length-1) {
@ -168,22 +171,24 @@ public class EntityJump extends Entity {
}
public void lockWorlds() {
getTargetWorld().editingBlocks = true;
System.out.println("Locking worlds...");
getTargetWorld().isRemote = true;
// При прыжках между измерениями необходимо блокировать текущий мир
// Для предотвращения рассыпания проводов на корабле
if (getTargetWorld().provider.dimensionId != worldObj.provider.dimensionId) {
worldObj.editingBlocks = true;
worldObj.isRemote = true;
}
}
public void unlockWorlds() {
getTargetWorld().editingBlocks = false;
System.out.println("Unlocking worlds..");
getTargetWorld().isRemote = false;
// При прыжках между измерениями необходимо блокировать оба мира
// Для предотвращения рассыпания проводов на корабле
if (getTargetWorld().provider.dimensionId != worldObj.provider.dimensionId) {
worldObj.editingBlocks = false;
worldObj.isRemote = false;
}
}
@ -235,8 +240,8 @@ public class EntityJump extends Entity {
int chunkZ = newZ >> 4;
if (!w.getChunkProvider().chunkExists(chunkX, chunkZ)) {
System.out.println("[JE] Need to generate chunk at (" + chunkX + "; " + chunkZ + "). Creating fake player");
w.getChunkProvider().provideChunk(chunkX, chunkZ);
messageToAllPlayersOnShip("Generating chunks...");
int blockID = w.getBlockId(newX, 128, newZ);
return false;
}
@ -286,7 +291,10 @@ public class EntityJump extends Entity {
}
if (!betweenWorlds) {
distance = getPossibleJumpDistance();
// Не проверять при дальних прыжках
if (this.distance < 256) {
distance = getPossibleJumpDistance();
}
} else {
distance = 1;
}
@ -335,7 +343,7 @@ public class EntityJump extends Entity {
}
//System.out.println("[EJ] Removing block: " + jb.x + " " + jb.y + " " + jb.z + " " + jb.blockID);
worldObj.setBlockAndMetadata(jb.x, jb.y, jb.z, 0, 0);
worldObj.setBlockToAir(jb.x, jb.y, jb.z);
}
}
@ -416,6 +424,7 @@ public class EntityJump extends Entity {
* прыжок невозможен в принципе
*/
public int getPossibleJumpDistance() {
System.out.println("[JUMP] Calculating possible jump distance...");
int testDistance = this.distance;
boolean canJump;
@ -994,12 +1003,12 @@ public class EntityJump extends Entity {
if (!toSpace && !fromSpace)
{
worldObj.setBlockAndMetadataWithNotify(newX, newY, newZ, blockID, blockMeta);
worldObj.setBlock(newX, newY, newZ, blockID, blockMeta, 2);
} else if (toSpace)
{
spaceWorld.setBlockAndMetadataWithNotify(newX, newY, newZ, blockID, blockMeta);
spaceWorld.setBlock(newX, newY, newZ, blockID, blockMeta, 2);
} else if (fromSpace) {
surfaceWorld.setBlockAndMetadataWithNotify(newX, newY, newZ, blockID, blockMeta);
surfaceWorld.setBlock(newX, newY, newZ, blockID, blockMeta, 2);
}
NBTTagCompound oldnbt = new NBTTagCompound();
@ -1008,21 +1017,39 @@ public class EntityJump extends Entity {
if (shipBlock.blockTileEntity != null && blockID != 159 && blockID != 149 && blockID != 156 && blockID != 146 && blockID != 145) {
shipBlock.blockTileEntity.writeToNBT(oldnbt);
TileEntity newTileEntity = null;
oldnbt.setInteger("x", newX);
oldnbt.setInteger("y", newY);
oldnbt.setInteger("z", newZ);
if (!toSpace && !fromSpace) {
newTileEntity = TileEntity.createAndLoadEntity(oldnbt);
newTileEntity.invalidate();
/*if (!toSpace && !fromSpace) {
newTileEntity = worldObj.getBlockTileEntity(newX, newY, newZ);
} else if (toSpace) {
newTileEntity = spaceWorld.getBlockTileEntity(newX, newY, newZ);
} else if (fromSpace) {
newTileEntity = surfaceWorld.getBlockTileEntity(newX, newY, newZ);
}
}*/
if (newTileEntity == null) {
System.out.println("PIZDEC!!!");
return false; // PIZDEC!!!
}
/*
newTileEntity.invalidate();
newTileEntity.readFromNBT(oldnbt);
newTileEntity.xCoord = newX;
newTileEntity.yCoord = newY;
newTileEntity.zCoord = newZ;
*/
newTileEntity.worldObj = getTargetWorld();
newTileEntity.validate();
if (!toSpace && !fromSpace)
{
worldObj.setBlockTileEntity(newX, newY, newZ, newTileEntity);
@ -1035,7 +1062,13 @@ public class EntityJump extends Entity {
surfaceWorld.setBlockTileEntity(newX, newY, newZ, newTileEntity);
}
worldObj.removeBlockTileEntity(oldX, oldY, oldZ);
worldObj.removeBlockTileEntity(oldX, oldY, oldZ);
if (newTileEntity.getClass().getName().contains("TileEntityComputer") && newTileEntity instanceof IPeripheral)
{
System.out.println(((IPeripheral)newTileEntity).getMethodNames());
}
}
} catch (Exception exception) {
exception.printStackTrace();

View file

@ -0,0 +1,167 @@
package cr0s.WarpDrive;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
public final class EntitySphereGen extends Entity {
public int xCoord;
public int yCoord;
public int zCoord;
public int type;
public int blockID;
public double radius, radiusSq, radius1Sq, surfaceRadius;
public int ceilRadius;
public boolean hollow = false;
private final int BLOCKS_PER_TICK = 2500;
private final int TYPE_STAR = 1;
private int currX, currY, currZ;
int blocksPassed, blocksTotal;
public boolean on;
public EntitySphereGen(World world) {
super(world);
}
public EntitySphereGen(World world, int x, int y, int z, int type) {
super(world);
this.xCoord = x;
this.posX = (double) x;
this.yCoord = y;
this.posY = (double) y;
this.zCoord = z;
this.posZ = (double) z;
this.currX = 0;
this.currY = 0;
this.currZ = 0;
this.type = type;
if (type == TYPE_STAR)
{
blockID = Block.glowStone.blockID;
//hollow = true;
surfaceRadius = 10D;
radius = 64D;
}
//radius += 0.5D;
radiusSq = radius * radius;
radius1Sq = (radius - 1.0D) * (radius - 1.0D);
ceilRadius = (int) Math.ceil(radius);
startGenerate();
}
public void startGenerate() {
this.on = true;
System.out.println("[SGEN] Generating sphere on (" + xCoord + "; " + yCoord + "; " + zCoord + ") with radius " + ceilRadius + " type: " + type);
}
public void killEntity() {
on = false;
worldObj.removeEntity(this);
}
@SideOnly(Side.SERVER)
@Override
public void onUpdate() {
if (!on)
{
System.out.println("[SGEN] onUpdate(): entity disabled.");
killEntity();
return;
}
System.out.print("[SGEN] Tick of generation...");
blocksPassed = 0;
for (; currX <= ceilRadius; currX++) {
if (blocksPassed > BLOCKS_PER_TICK) break;
for (currY = 0; currY <= ceilRadius; currY++) {
if (blocksPassed > BLOCKS_PER_TICK) break;
for (currZ = 0; currZ <= ceilRadius; currZ++) {
if (blocksPassed > BLOCKS_PER_TICK) break;
double dSq = lengthSq(currX, currY, currZ);
blocksTotal++;
blocksPassed++;
//if (blocksTotal % 1000 == 0) {
//System.out.println("[SGEN]: current (" + currX + "; " + currY + "; " + currZ + "); Blocks passed: " + blocksPassed + ", total: " + blocksTotal);
//}
// if (currX > ceilRadius && currY > ceilRadius && currZ > ceilRadius)
// {
// System.out.println("[SGEN] DONE");
// killEntity();
// return;
// }
if (dSq > radiusSq) {
continue;
}
if ((hollow) && (
(dSq < radius1Sq) || ((lengthSq(currX + 1, currY, currZ) <= radiusSq) && (lengthSq(currX, currY + 1, currZ) <= radiusSq) && (lengthSq(currX, currY, currZ + 1) <= radiusSq))))
{
continue;
}
int meta = 0;
worldObj.setBlock(xCoord + currX, yCoord + currY, zCoord + currZ, blockID, meta, 0);
worldObj.setBlock(xCoord - currX, yCoord + currY, zCoord + currZ, blockID, meta, 0);
worldObj.setBlock(xCoord + currX, yCoord - currY, zCoord + currZ, blockID, meta, 0);
worldObj.setBlock(xCoord + currX, yCoord + currY, zCoord - currZ, blockID, meta, 0);
worldObj.setBlock(xCoord - currX, yCoord - currY, zCoord + currZ, blockID, meta, 0);
worldObj.setBlock(xCoord + currX, yCoord - currY, zCoord - currZ, blockID, meta, 0);
worldObj.setBlock(xCoord - currX, yCoord + currY, zCoord - currZ, blockID, meta, 0);
worldObj.setBlock(xCoord - currX, yCoord - currY, zCoord - currZ, blockID, meta, 0);
}
}
}
System.out.println(" [tick done]");
}
private static double lengthSq(double x, double y, double z) {
return (x * x) + (y * y) + (z * z);
}
@Override
protected void readEntityFromNBT(NBTTagCompound nbttagcompound) {
}
@Override
protected void entityInit() {
System.out.println("[SGEN] entityInit() called");
}
@Override
protected void writeEntityToNBT(NBTTagCompound var1) {
}
}

View file

@ -29,6 +29,7 @@ public class SpaceGenerator extends ChunkProviderGenerate implements IChunkProvi
public SpaceGenerator(World par1World, long par2) {
super(par1World, par2, false);
rand = new Random();
this.worldObj = par1World;
}
@ -141,12 +142,6 @@ public class SpaceGenerator extends ChunkProviderGenerate implements IChunkProvi
MinecraftForge.EVENT_BUS.post(event);
if (event.getResult() == Event.Result.DENY) return; */
}
@Override
public boolean unload100OldestChunks() {
// TODO Auto-generated method stub
return super.unload100OldestChunks();
}
@Override
public boolean canSave() {

View file

@ -91,12 +91,6 @@ public class SpaceProvider extends WorldProvider {
}
}
@SideOnly(Side.CLIENT)
@Override
public int getMoonPhase(long par1, float par3) {
return 4;
}
@SideOnly(Side.CLIENT)
@Override
public String getSaveFolder() {
@ -171,25 +165,25 @@ public class SpaceProvider extends WorldProvider {
{
var5.posX += this.worldObj.rand.nextInt(spawnFuzz) - spawnFuzzHalf;
var5.posZ += this.worldObj.rand.nextInt(spawnFuzz) - spawnFuzzHalf;
var5.posY = 250;
var5.posY = 200;
}
if (worldObj.isAirBlock(var5.posX, var5.posY, var5.posZ)) {
worldObj.setBlockWithNotify(var5.posX, var5.posY, var5.posZ, Block.stone.blockID);
worldObj.setBlock(var5.posX, var5.posY, var5.posZ, Block.stone.blockID, 0, 2);
worldObj.setBlockWithNotify(var5.posX + 1, var5.posY + 1, var5.posZ, Block.glass.blockID);
worldObj.setBlockWithNotify(var5.posX + 1, var5.posY + 2, var5.posZ, Block.glass.blockID);
worldObj.setBlock(var5.posX + 1, var5.posY + 1, var5.posZ, Block.glass.blockID, 0, 2);
worldObj.setBlock(var5.posX + 1, var5.posY + 2, var5.posZ, Block.glass.blockID, 0, 2);
worldObj.setBlockWithNotify(var5.posX - 1, var5.posY + 1, var5.posZ, Block.glass.blockID);
worldObj.setBlockWithNotify(var5.posX - 1, var5.posY + 2, var5.posZ, Block.glass.blockID);
worldObj.setBlock(var5.posX - 1, var5.posY + 1, var5.posZ, Block.glass.blockID, 0, 2);
worldObj.setBlock(var5.posX - 1, var5.posY + 2, var5.posZ, Block.glass.blockID, 0, 2);
worldObj.setBlockWithNotify(var5.posX, var5.posY + 1, var5.posZ + 1, Block.glass.blockID);
worldObj.setBlockWithNotify(var5.posX, var5.posY + 2, var5.posZ + 1, Block.glass.blockID);
worldObj.setBlock(var5.posX, var5.posY + 1, var5.posZ + 1, Block.glass.blockID, 0, 2);
worldObj.setBlock(var5.posX, var5.posY + 2, var5.posZ + 1, Block.glass.blockID, 0, 2);
worldObj.setBlockWithNotify(var5.posX, var5.posY + 1, var5.posZ - 1, Block.glass.blockID);
worldObj.setBlockWithNotify(var5.posX, var5.posY + 2, var5.posZ - 1, Block.glass.blockID);
worldObj.setBlock(var5.posX, var5.posY + 1, var5.posZ - 1, Block.glass.blockID, 0, 2);
worldObj.setBlock(var5.posX, var5.posY + 3, var5.posZ - 1, Block.glass.blockID, 0, 2);
worldObj.setBlockWithNotify(var5.posX, var5.posY + 3, var5.posZ, Block.glass.blockID);
//worldObj.setBlockWithNotify(var5.posX, var5.posY + 3, var5.posZ, Block.glass.blockID);
}
return var5;
}

View file

@ -34,13 +34,16 @@ public class SpaceTeleporter extends Teleporter {
//player.setWorld(world);
//player.setPositionAndUpdate(x, y, z);
}
@Override
public boolean func_85188_a(Entity par1Entity) {
return true;
}
public boolean makePortal(Entity par1Entity)
{
return false;
}
@Override
public void func_85189_a(long par1) {
}
public boolean placeInExistingPortal(Entity par1Entity, double par2, double par4, double par6, float par8)
{
return false;
}
}

View file

@ -1,372 +1,356 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package cr0s.WarpDrive;
import cpw.mods.fml.common.IWorldGenerator;
import java.util.Random;
import java.util.Vector;
import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
/**
*
* @author user
*/
public class SpaceWorldGenerator implements IWorldGenerator {
// Радиус простой луны
public final int MOON_RADIUS = 32;
public final int MOON_CORE_RADIUS = 5;
// Радиус звезды
public final int STAR_RADIUS = 80;
// Выше 128 по Y почти ничего не будет сгенерировано
public final int Y_LIMIT = 128;
// Лимит по Y снизу
public final int Y_LIMIT_DOWN = 55;
/**
* Генерация для чанка
* @param random
* @param chunkX
* @param chunkZ
* @param world
* @param chunkGenerator
* @param chunkProvider
*/
@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {
if (world.provider.dimensionId != WarpDrive.instance.spaceDimID) {
return;
}
int x = (chunkX * 16) + (5 - random.nextInt(10));
int z = (chunkZ * 16) + (5 - random.nextInt(10));
int y = Y_LIMIT_DOWN + random.nextInt(Y_LIMIT - Y_LIMIT_DOWN);
// Установка луны
if (random.nextInt(8000) == 1) {
System.out.println("Generating moon at " + x + " " + y + " " + z);
generateSphere2(world, x, y, z, MOON_RADIUS, false, 0, false);
// Генерация ядра луны
generateSphere2(world, x, y, z, MOON_CORE_RADIUS, false, Block.lavaStill.blockID, false); // Лавовое ядро
generateSphere2(world, x, y, z, MOON_CORE_RADIUS, false, Block.obsidian.blockID, false); // Обсидиановая оболочка
return;
}
// Установка звезды
// DISABLED DUE LAG
/*if (random.nextInt(10000) == 1) {
System.out.println("Generating star at " + x + " " + y + " " + z);
generateSphere2(world, x, y, z, STAR_RADIUS, false, Block.glowStone.blockID, true);
generateSphere2(world, x, y, z, STAR_RADIUS -1, false, Block.glowStone.blockID, true);
generateSphere2(world, x, y, z, STAR_RADIUS -2, false, Block.glowStone.blockID, true);
return;
}*/
// Простые астероиды
if (random.nextInt(200) == 1) {
System.out.println("Generating asteroid at " + x + " " + y + " " + z);
generateAsteroid(world, x, y, z, 6, 11);
return;
}
if (random.nextInt(2000) == 1) {
generateRandomAsteroid(world, x, y, z, 6, 11);
}
// Ледяные астероиды
if (random.nextInt(2000) == 1) {
System.out.println("Generating ice asteroid at " + x + " " + y + " " + z);
generateAsteroidOfBlock(world, x, y, z, 6, 11, Block.ice.blockID);
return;
}
// Астероидные поля
if (random.nextInt(3000) == 1) {
System.out.println("Generating asteroid field at " + x + " " + y + " " + z);
generateAsteroidField(world, x, y, z);
return;
}
// Алмазные астероиды
if (random.nextInt(10000) == 1) {
System.out.println("Generating diamond asteroid at " + x + " " + y + " " + z);
generateAsteroidOfBlock(world, x, y, z, 4, 6, Block.oreDiamond.blockID);
// Ядро астероида из алмаза
world.setBlockWithNotify(x, y, z, Block.blockDiamond.blockID);
return;
}
}
private void generateRandomAsteroid(World world, int x, int y, int z, int asteroidSizeMax, int centerRadiusMax) {
Random random = new Random();
if (random.nextInt(100) == 1) {
generateAsteroidOfBlock(world, x, y, z, asteroidSizeMax, centerRadiusMax, getRandomSurfaceBlockID(random, false));
} else {
generateAsteroid(world, x, y, z, asteroidSizeMax, centerRadiusMax);
}
}
/**
* Генератор поля астероидов
* @param world мир
* @param x координата центра поля
* @param y координата центра поля
* @param z координата центра поля
*/
private void generateAsteroidField(World world, int x, int y, int z) {
int numOfAsteroids = 15 + world.rand.nextInt(30);
// Минимальное расстояние между астероидами в поле
final int FIELD_ASTEROID_MIN_DISTANCE = 5;
// Максимальное расстояние между астероидами
final int FIELD_ASTEROID_MAX_DISTANCE = 100;
// Разброс больших астероидов
for (int i = 1; i <= numOfAsteroids; i++) {
int aX = x + (((world.rand.nextBoolean()) ? -1 : 1) * (FIELD_ASTEROID_MIN_DISTANCE + world.rand.nextInt(FIELD_ASTEROID_MAX_DISTANCE)));
int aY = y + (((world.rand.nextBoolean()) ? -1 : 1) * (FIELD_ASTEROID_MIN_DISTANCE + world.rand.nextInt(FIELD_ASTEROID_MAX_DISTANCE)));
int aZ = z + (((world.rand.nextBoolean()) ? -1 : 1) * (FIELD_ASTEROID_MIN_DISTANCE + world.rand.nextInt(FIELD_ASTEROID_MAX_DISTANCE)));
// Создаём астероид
generateRandomAsteroid(world, aX, aY, aZ, 4, 6);
}
// Разброс маленьких астероидов
for (int i = 1; i <= numOfAsteroids; i++) {
int aX = x + (((world.rand.nextBoolean()) ? -1 : 1) * (FIELD_ASTEROID_MIN_DISTANCE + world.rand.nextInt(FIELD_ASTEROID_MAX_DISTANCE)));
int aY = y + (((world.rand.nextBoolean()) ? -1 : 1) * (FIELD_ASTEROID_MIN_DISTANCE + world.rand.nextInt(FIELD_ASTEROID_MAX_DISTANCE)));
int aZ = z + (((world.rand.nextBoolean()) ? -1 : 1) * (FIELD_ASTEROID_MIN_DISTANCE + world.rand.nextInt(FIELD_ASTEROID_MAX_DISTANCE)));
// Создаём астероид
generateRandomAsteroid(world, aX, aY, aZ, 2, 2);
}
}
/**
* Генератор астероидов одного типа. Создаёт астероид в точке.
*
* @param x координата центра астероида
* @param y координата центра астероида
* @param z координата центра астероида
* @param asteroidSizeMax максимальный размер астероида (по количеству составляющих его сфер)
* @param centerRadiusMax максимальный радиус центральной сферы
*/
private void generateAsteroidOfBlock(World world, int x, int y, int z, int asteroidSizeMax, int centerRadiusMax, int blockID) {
int asteroidSize = 1 + world.rand.nextInt(6);
if (asteroidSizeMax != 0) {
asteroidSize = Math.min(asteroidSizeMax, asteroidSize);
}
int centerRadius = 1 + world.rand.nextInt(6);
if (centerRadiusMax != 0) {
centerRadius = Math.min(centerRadiusMax, centerRadius);
}
final int CENTER_SHIFT = 2; // Смещение от центральной сферы
// Центр астероида
generateSphere2(world, x, y, z, centerRadius, true, blockID, false);
// Бугры астероида
for (int i = 1; i <= asteroidSize; i++) {
int radius = 2 + world.rand.nextInt(centerRadius);
int newX = x + (((world.rand.nextBoolean()) ? -1 : 1) * world.rand.nextInt(CENTER_SHIFT + centerRadius / 2));
int newY = y + (((world.rand.nextBoolean()) ? -1 : 1) * world.rand.nextInt(CENTER_SHIFT + centerRadius / 2));
int newZ = z + (((world.rand.nextBoolean()) ? -1 : 1) * world.rand.nextInt(CENTER_SHIFT + centerRadius / 2));
generateSphere2(world, newX, newY, newZ, radius, true, blockID, false);
}
}
/**
* Генератор простых астероидов. Создаёт астероид в точке.
*
* @param x координата центра астероида
* @param y координата центра астероида
* @param z координата центра астероида
* @param asteroidSizeMax максимальный размер астероида (по количеству составляющих его сфер)
* @param centerRadiusMax максимальный радиус центральной сферы
*/
private void generateAsteroid(World world, int x, int y, int z, int asteroidSizeMax, int centerRadiusMax) {
int asteroidSize = 1 + world.rand.nextInt(6);
if (asteroidSizeMax != 0) {
asteroidSize = Math.min(asteroidSizeMax, asteroidSize);
}
int centerRadius = 1 + world.rand.nextInt(6);
if (centerRadiusMax != 0) {
centerRadius = Math.min(centerRadiusMax, centerRadius);
}
final int CENTER_SHIFT = 2; // Смещение от центральной сферы
// Центр астероида
generateSphere2(world, x, y, z, centerRadius, true, 0, false);
// Бугры астероида
for (int i = 1; i <= asteroidSize; i++) {
int radius = 2 + world.rand.nextInt(centerRadius);
int newX = x + (((world.rand.nextBoolean()) ? -1 : 1) * world.rand.nextInt(CENTER_SHIFT + centerRadius / 2));
int newY = y + (((world.rand.nextBoolean()) ? -1 : 1) * world.rand.nextInt(CENTER_SHIFT + centerRadius / 2));
int newZ = z + (((world.rand.nextBoolean()) ? -1 : 1) * world.rand.nextInt(CENTER_SHIFT + centerRadius / 2));
generateSphere2(world, newX, newY, newZ, radius, true, 0, false);
}
}
/**
* Генератор сферических объектов
* @param world мир, в котором будет сгенерирована сфера/шар
* @param xCoord координата центра
* @param yCoord координата центра
* @param zCoord координата центра
* @param radius радиус сферы/шара
* @param corrupted пропускать случайные блоки при генерации
* @param forcedID генерировать сферу из определённых блоков, 0 если блоки случайные
* @return
*/
public void generateSphere2(World world, int xCoord, int yCoord, int zCoord, double radius, boolean corrupted, int forcedID, boolean hollow) {
// FIXME: блокировка мира обязательна?
//world.editingBlocks = true;
radius += 0.5D; // Отмеряем радиус от центра блока
double radiusSq = radius * radius; // Возведение радиуса в квадрат в целях оптимизации (избавлпние от кв. корней)
double radius1Sq = (radius - 1.0D) * (radius - 1.0D); // Квадратный радиус для пустой сферы
int ceilRadius = (int) Math.ceil(radius); // Округляем радиус
// Обходим куб со стороной, равной радиусу
// (проверка точек на удовлетворение уравнению сферы x^2 + y^2 + z^2 = r^2)
for (int x = 0; x <= ceilRadius; x++) {
for (int y = 0; y <= ceilRadius; y++) {
for (int z = 0; z <= ceilRadius; z++) {
double dSq = lengthSq(x, y, z); // Расстояние от центра до точки
// Пропускать блоки, которые удалены от центра больше, чем на радиус
if (dSq > radiusSq) {
continue;
}
// Генерация полой сферы
if ((hollow) && (
(dSq < radius1Sq) || ((lengthSq(x + 1, y, z) <= radiusSq) && (lengthSq(x, y + 1, z) <= radiusSq) && (lengthSq(x, y, z + 1) <= radiusSq))))
{
continue;
}
// Ставим блоки по всем осям в текущей точке
int blockID, meta = 0;
if (!corrupted || world.rand.nextInt(10) != 1)
{
blockID = (forcedID == 0) ? getRandomSurfaceBlockID(world.rand, corrupted) : forcedID;
if (blockID > 2000 && blockID < 2500) { meta = blockID % 10; blockID = blockID / 10; }
world.setBlockAndMetadata(xCoord + x, yCoord + y, zCoord + z, blockID, meta);
world.setBlockAndMetadata(xCoord - x, yCoord + y, zCoord + z, blockID, meta);
}
if (!corrupted || world.rand.nextInt(10) != 1)
{
blockID = (forcedID == 0) ? getRandomSurfaceBlockID(world.rand, corrupted) : forcedID;
if (blockID > 2000 && blockID < 2500) { meta = blockID % 10; blockID = blockID / 10; }
world.setBlockAndMetadata(xCoord + x, yCoord - y, zCoord + z, blockID, meta);
world.setBlockAndMetadata(xCoord + x, yCoord + y, zCoord - z, blockID, meta);
}
if (!corrupted || world.rand.nextInt(10) != 1)
{
blockID = (forcedID == 0) ? getRandomSurfaceBlockID(world.rand, corrupted) : forcedID;
if (blockID > 2000 && blockID < 2500) { meta = blockID % 10; blockID = blockID / 10; }
world.setBlockAndMetadata(xCoord - x, yCoord - y, zCoord + z, blockID, meta);
world.setBlockAndMetadata(xCoord + x, yCoord - y, zCoord - z, blockID, meta);
}
if (!corrupted || world.rand.nextInt(10) != 1)
{
blockID = (forcedID == 0) ? getRandomSurfaceBlockID(world.rand, corrupted) : forcedID;
if (blockID > 2000 && blockID < 2500) { meta = blockID % 10; blockID = blockID / 10; }
world.setBlockAndMetadata(xCoord - x, yCoord + y, zCoord - z, blockID, meta);
world.setBlockAndMetadata(xCoord - x, yCoord - y, zCoord - z, blockID, meta);
}
}
}
}
// Разблокируем мир
//world.editingBlocks = false;
}
private static double lengthSq(double x, double y, double z) {
return (x * x) + (y * y) + (z * z);
}
private int getRandomSurfaceBlockID(Random random, boolean corrupted) {
int[] ores = {
Block.oreIron.blockID,
Block.oreGold.blockID,
Block.oreCoal.blockID,
Block.oreEmerald.blockID,
Block.oreLapis.blockID,
Block.oreRedstoneGlowing.blockID,
// Ruby ore
242,
// IC ores
4093, // Uranium
4094, // Tin
4095, // Copper ore
4095, // Copper ore
};
int redPowerOreBlockID = 242;
int[] redPowerOres = {
0, 1, 2, 3, 4, 5, 6, 7 // Рубины -- Николит
};
int blockID = Block.stone.blockID;
if (corrupted) {
blockID = Block.cobblestone.blockID;
}
if (random.nextInt(10) == 1) {
switch (random.nextInt(2)) {
case 0:
blockID = ores[random.nextInt(ores.length - 1)];
break;
case 1: // OREM -- ORE (Руда), M - метаданные
blockID = Integer.parseInt(new StringBuilder().append(redPowerOreBlockID).append(redPowerOres[random.nextInt(redPowerOres.length - 1)]).toString());
}
} else if (random.nextInt(500) == 1) {
blockID = Block.oreDiamond.blockID;
} else if (random.nextInt(5000) == 1) {
blockID = 688;
}
return blockID;
}
}
package cr0s.WarpDrive;
import cpw.mods.fml.common.IWorldGenerator;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
/**
* @author Cr0s
*/
public class SpaceWorldGenerator implements IWorldGenerator {
// Radius of simple moon
public final int MOON_RADIUS = 32;
public final int MOON_CORE_RADIUS = 10;
// Star radius
public final int STAR_RADIUS = 80;
// Upper than 128 almost nothing will be generated
public final int Y_LIMIT = 128;
// Lower limit
public final int Y_LIMIT_DOWN = 55;
/**
* Generator for chunk
* @param random
* @param chunkX
* @param chunkZ
* @param world
* @param chunkGenerator
* @param chunkProvider
*/
@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {
if (world.provider.dimensionId != WarpDrive.instance.spaceDimID) {
return;
}
int x = (chunkX * 16) + (5 - random.nextInt(10));
int z = (chunkZ * 16) + (5 - random.nextInt(10));
int y = Y_LIMIT_DOWN + random.nextInt(Y_LIMIT - Y_LIMIT_DOWN);
// Moon setup
if (random.nextInt(8000) == 1) {
System.out.println("Generating moon at " + x + " " + y + " " + z);
generateSphere2(world, x, y, z, MOON_RADIUS, false, 0, false);
// Generate moon's core
generateSphere2(world, x, y, z, MOON_CORE_RADIUS, false, Block.lavaStill.blockID, false); // Lava core
generateSphere2(world, x, y, z, MOON_CORE_RADIUS + 1, false, Block.obsidian.blockID, true); // Obsidian shell
return;
}
// FIXME: Star setup
/*if (random.nextInt(250) == 1) {
EntitySphereGen esg = new EntitySphereGen(world, x, y, z, 1);
esg.xCoord = x;
esg.yCoord = y;
esg.zCoord = z;
esg.on = true;
world.spawnEntityInWorld(esg);
return;
}*/
// Simple asteroids
if (random.nextInt(200) == 1) {
System.out.println("Generating asteroid at " + x + " " + y + " " + z);
generateAsteroid(world, x, y, z, 6, 11);
return;
}
if (random.nextInt(1000) == 1) {
generateRandomAsteroid(world, x, y, z, 6, 11);
}
// Ice asteroid
if (random.nextInt(2000) == 1) {
System.out.println("Generating ice asteroid at " + x + " " + y + " " + z);
generateAsteroidOfBlock(world, x, y, z, 6, 11, Block.ice.blockID);
return;
}
// Asteroid field
if (random.nextInt(3000) == 1) {
System.out.println("Generating asteroid field at " + x + " " + y + " " + z);
generateAsteroidField(world, x, y, z);
return;
}
// Diamond asteroid
if (random.nextInt(10000) == 1) {
System.out.println("Generating diamond asteroid at " + x + " " + y + " " + z);
generateAsteroidOfBlock(world, x, y, z, 4, 6, Block.oreDiamond.blockID);
// Diamond block core
world.setBlock(x, y, z, Block.blockDiamond.blockID, 0, 2);
// return;
}
}
private void generateRandomAsteroid(World world, int x, int y, int z, int asteroidSizeMax, int centerRadiusMax) {
Random random = new Random();
if (random.nextInt(30) == 1) {
System.out.println("Generating random asteroid of block at " + x + "; " + y + "; " + z);
generateAsteroidOfBlock(world, x, y, z, asteroidSizeMax, centerRadiusMax, getRandomSurfaceBlockID(random, false, true));
} else {
generateAsteroid(world, x, y, z, asteroidSizeMax, centerRadiusMax);
}
}
/**
* Asteroid field generator
* @param world мир
* @param x координата центра поля
* @param y координата центра поля
* @param z координата центра поля
*/
private void generateAsteroidField(World world, int x, int y, int z) {
int numOfAsteroids = 15 + world.rand.nextInt(30);
// Minimal distance between asteroids in field
final int FIELD_ASTEROID_MIN_DISTANCE = 5;
// Maximum distance
final int FIELD_ASTEROID_MAX_DISTANCE = 100;
// Setting up of big asteroids
for (int i = 1; i <= numOfAsteroids; i++) {
int aX = x + (((world.rand.nextBoolean()) ? -1 : 1) * (FIELD_ASTEROID_MIN_DISTANCE + world.rand.nextInt(FIELD_ASTEROID_MAX_DISTANCE)));
int aY = y + (((world.rand.nextBoolean()) ? -1 : 1) * (FIELD_ASTEROID_MIN_DISTANCE + world.rand.nextInt(FIELD_ASTEROID_MAX_DISTANCE)));
int aZ = z + (((world.rand.nextBoolean()) ? -1 : 1) * (FIELD_ASTEROID_MIN_DISTANCE + world.rand.nextInt(FIELD_ASTEROID_MAX_DISTANCE)));
// Place an asteroid
generateRandomAsteroid(world, aX, aY, aZ, 4, 6);
}
// Setting up small asteroids
for (int i = 1; i <= numOfAsteroids; i++) {
int aX = x + (((world.rand.nextBoolean()) ? -1 : 1) * (FIELD_ASTEROID_MIN_DISTANCE + world.rand.nextInt(FIELD_ASTEROID_MAX_DISTANCE)));
int aY = y + (((world.rand.nextBoolean()) ? -1 : 1) * (FIELD_ASTEROID_MIN_DISTANCE + world.rand.nextInt(FIELD_ASTEROID_MAX_DISTANCE)));
int aZ = z + (((world.rand.nextBoolean()) ? -1 : 1) * (FIELD_ASTEROID_MIN_DISTANCE + world.rand.nextInt(FIELD_ASTEROID_MAX_DISTANCE)));
// Placing
generateRandomAsteroid(world, aX, aY, aZ, 2, 2);
}
}
/**
* Asteroid of block generator
*
* @param x x-coord of center
* @param y center
* @param z center
* @param asteroidSizeMax maximum asteroid size (by number of balls it consists)
* @param centerRadiusMax maximum radius of central ball
*/
private void generateAsteroidOfBlock(World world, int x, int y, int z, int asteroidSizeMax, int centerRadiusMax, int blockID) {
int asteroidSize = 1 + world.rand.nextInt(6);
if (asteroidSizeMax != 0) {
asteroidSize = Math.min(asteroidSizeMax, asteroidSize);
}
int centerRadius = 1 + world.rand.nextInt(6);
if (centerRadiusMax != 0) {
centerRadius = Math.min(centerRadiusMax, centerRadius);
}
final int CENTER_SHIFT = 2; // Offset from center of central ball
// Asteroid's center
generateSphere2(world, x, y, z, centerRadius, true, blockID, false);
// Asteroids knolls
for (int i = 1; i <= asteroidSize; i++) {
int radius = 2 + world.rand.nextInt(centerRadius);
int newX = x + (((world.rand.nextBoolean()) ? -1 : 1) * world.rand.nextInt(CENTER_SHIFT + centerRadius / 2));
int newY = y + (((world.rand.nextBoolean()) ? -1 : 1) * world.rand.nextInt(CENTER_SHIFT + centerRadius / 2));
int newZ = z + (((world.rand.nextBoolean()) ? -1 : 1) * world.rand.nextInt(CENTER_SHIFT + centerRadius / 2));
generateSphere2(world, newX, newY, newZ, radius, true, blockID, false);
}
}
/**
* Asteroid generator
*
* @param x x-coord of center
* @param y center
* @param z center
* @param asteroidSizeMax maximum asteroid size (by number of balls it consists)
* @param centerRadiusMax maximum radius of central ball
*/
private void generateAsteroid(World world, int x, int y, int z, int asteroidSizeMax, int centerRadiusMax) {
int asteroidSize = 1 + world.rand.nextInt(6);
if (asteroidSizeMax != 0) {
asteroidSize = Math.min(asteroidSizeMax, asteroidSize);
}
int centerRadius = 1 + world.rand.nextInt(6);
if (centerRadiusMax != 0) {
centerRadius = Math.min(centerRadiusMax, centerRadius);
}
final int CENTER_SHIFT = 2;
generateSphere2(world, x, y, z, centerRadius, true, 0, false);
for (int i = 1; i <= asteroidSize; i++) {
int radius = 2 + world.rand.nextInt(centerRadius);
int newX = x + (((world.rand.nextBoolean()) ? -1 : 1) * world.rand.nextInt(CENTER_SHIFT + centerRadius / 2));
int newY = y + (((world.rand.nextBoolean()) ? -1 : 1) * world.rand.nextInt(CENTER_SHIFT + centerRadius / 2));
int newZ = z + (((world.rand.nextBoolean()) ? -1 : 1) * world.rand.nextInt(CENTER_SHIFT + centerRadius / 2));
generateSphere2(world, newX, newY, newZ, radius, true, 0, false);
}
}
/**
* Sphere generator
* @param world target world
* @param xCoord center
* @param yCoord center
* @param zCoord center
* @param radius sphere radius
* @param corrupted skip random blocks when generating (corrupted effect)
* @param forcedID sphere of specified blocks or random blocks if not specified
* @return
*/
public void generateSphere2(World world, int xCoord, int yCoord, int zCoord, double radius, boolean corrupted, int forcedID, boolean hollow) {
radius += 0.5D; // Radius from center of block
double radiusSq = radius * radius; // Optimization to avoid sqrts...
double radius1Sq = (radius - 1.0D) * (radius - 1.0D); // for hollow sphere
int ceilRadius = (int) Math.ceil(radius);
// Pass the cube and check points for sphere equation x^2 + y^2 + z^2 = r^2
for (int x = 0; x <= ceilRadius; x++) {
for (int y = 0; y <= ceilRadius; y++) {
for (int z = 0; z <= ceilRadius; z++) {
double dSq = lengthSq(x, y, z); // Distance from current position to center
// Skip too far blocks
if (dSq > radiusSq) {
continue;
}
// Hollow sphere condition
if ((hollow) && (
(dSq < radius1Sq) || ((lengthSq(x + 1, y, z) <= radiusSq) && (lengthSq(x, y + 1, z) <= radiusSq) && (lengthSq(x, y, z + 1) <= radiusSq))))
{
continue;
}
// Place blocks
int blockID, meta = 0;
if (!corrupted || world.rand.nextInt(10) != 1)
{
blockID = (forcedID == 0) ? getRandomSurfaceBlockID(world.rand, corrupted, false) : forcedID;
if (blockID == 39701) { meta = blockID % 10; blockID = blockID / 10; }
world.setBlock(xCoord + x, yCoord + y, zCoord + z, blockID, meta, 2);
world.setBlock(xCoord - x, yCoord + y, zCoord + z, blockID, meta, 2);
}
if (!corrupted || world.rand.nextInt(10) != 1)
{
blockID = (forcedID == 0) ? getRandomSurfaceBlockID(world.rand, corrupted, false) : forcedID;
if (blockID == 39701) { meta = blockID % 10; blockID = blockID / 10; }
world.setBlock(xCoord + x, yCoord - y, zCoord + z, blockID, meta, 2);
world.setBlock(xCoord + x, yCoord + y, zCoord - z, blockID, meta, 2);
}
if (!corrupted || world.rand.nextInt(10) != 1)
{
blockID = (forcedID == 0) ? getRandomSurfaceBlockID(world.rand, corrupted, false) : forcedID;
if (blockID == 39701) { meta = blockID % 10; blockID = blockID / 10; }
world.setBlock(xCoord - x, yCoord - y, zCoord + z, blockID, meta, 2);
world.setBlock(xCoord + x, yCoord - y, zCoord - z, blockID, meta, 2);
}
if (!corrupted || world.rand.nextInt(10) != 1)
{
blockID = (forcedID == 0) ? getRandomSurfaceBlockID(world.rand, corrupted, false) : forcedID;
if (blockID == 39701) { meta = blockID % 10; blockID = blockID / 10; }
world.setBlock(xCoord - x, yCoord + y, zCoord - z, blockID, meta, 2);
world.setBlock(xCoord - x, yCoord - y, zCoord - z, blockID, meta, 2);
}
}
}
}
}
private static double lengthSq(double x, double y, double z) {
return (x * x) + (y * y) + (z * z);
}
private int getRandomSurfaceBlockID(Random random, boolean corrupted, boolean nocobble) {
int[] ores = {
Block.oreIron.blockID,
Block.oreGold.blockID,
Block.oreCoal.blockID,
Block.oreEmerald.blockID,
Block.oreLapis.blockID,
Block.oreRedstoneGlowing.blockID,
// ICBM
3880,
3970,
39701, // 3970:1
// IC2 ores
247,
248,
249
};
int blockID = Block.stone.blockID;
if (corrupted) {
blockID = Block.cobblestone.blockID;
}
if (random.nextInt(10) == 1 || nocobble) {
blockID = ores[random.nextInt(ores.length - 1)];
}
else if (random.nextInt(350) == 1) {
blockID = 902; // quarz (AE)
}
else if (random.nextInt(500) == 1) {
blockID = Block.oreDiamond.blockID;
}/* else if (random.nextInt(5000) == 1) {
blockID = 688;
}*/
return blockID;
}
}

View file

@ -6,35 +6,21 @@ package cr0s.WarpDrive;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dan200.computer.api.IComputerAccess;
import java.util.ArrayList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.DamageSource;
import dan200.computer.api.IPeripheral;
/**
* Protocol block tile entity
* @author Cr0s
*/
public class TileEntityProtocol extends TileEntity {
public Boolean[] bits;
public ArrayList<Integer> input;
public ArrayList<Integer> output;
public boolean RX, TX, RST;
//TileEntityReactor warpCore; // Warp core entity
TileEntity dataCable; // Data cable entity
private int ticks = 0;
private final int UPDATE_TIMEOUT = 5; // seconds
private final int TRANSFER_RATE = 1; // ticks
private final int MAX_INPUT_BUFFER_SIZE = 25; // 25 bytes per packet
public class TileEntityProtocol extends TileEntity implements IPeripheral {
// Variables
private int distance = 0;
private int direction = 0;
@ -54,189 +40,18 @@ public class TileEntityProtocol extends TileEntity {
boolean ready = false; // Ready to operate (valid assembly)
public String[] methodsArray = {
"dim_getp", "dim_setp", // 0, 1
"dim_getn", "dim_setn", // 2, 3
"set_mode", "set_distance", "set_direction", // 4, 5, 6
"get_attached_players", "summon", "summon_all", // 7, 8, 9
"get_x", "get_y", "get_z", // 10, 11, 12
"get_energy_level", "do_jump", "get_ship_size" // 13, 14, 15
};
@SideOnly(Side.SERVER)
@Override
public void updateEntity() {
ticks++;
ready = dataCable != null;
if (ticks == UPDATE_TIMEOUT) {
this.dataCable = searchRedPowerCable();
ticks = 0;
}
if (!ready) {
return;
}
bits = readCableStates();
if (dataCable == null || bits == null || bits[8] == null || bits.length == 0) {
return;
}
RX = bits[8];
TX = bits[9];
RST = bits[11];
if (input == null) {
input = new ArrayList<Integer>();
}
if (output == null) {
output = new ArrayList<Integer>();
}
if (RST) {
System.out.println("RST RECV");
if (TX) { analyzeInputData(); } else if (RX) { /* sendOutputData();*/ }
input.clear();
RST = false;
resetCableStates();
} else if (TX) {
int byteFromCable = readByte();
System.out.println("Byte from cable: " + byteFromCable + "");
input.add(byteFromCable);
if (input.size() > MAX_INPUT_BUFFER_SIZE) {
System.out.println("[!] Buffer overflow.");
}
resetCableStates();
} else if (RX) {
}
}
public TileEntity searchRedPowerCable() {
TileEntity result;
result = worldObj.getBlockTileEntity(xCoord + 1, yCoord, zCoord);
if (result != null && result.toString().contains("TileCable")) {
return result;
}
result = worldObj.getBlockTileEntity(xCoord - 1, yCoord, zCoord);
if (result != null && result.toString().contains("TileCable")) {
return result;
}
result = worldObj.getBlockTileEntity(xCoord, yCoord, zCoord + 1);
if (result != null && result.toString().contains("TileCable")) {
return result;
}
result = worldObj.getBlockTileEntity(xCoord, yCoord, zCoord - 1);
if (result != null && result.toString().contains("TileCable")) {
return result;
}
return null;
}
public Boolean[] readCableStates() {
if (dataCable == null) { return null; }
NBTTagCompound tag = new NBTTagCompound();
dataCable.writeToNBT(tag);
byte states[] = tag.getByteArray("pwrs"); // Получить массив состояний кабеля
if (states == null) {
return null;
}
Boolean[] locCableStates = new Boolean[16];
for (int i = 0; i < 16; i++) {
locCableStates[i] = (states[i] != 0);
}
/*
if (RX || TX) {
System.out.println("[C] Cable bits: " + s);
}
*/
return locCableStates;
}
private int readByte() {
int result = 0;
//String binaryString = "";
Boolean[] states = readCableStates();
// Get first 8 bits
for (int i = 0; i < 8; i++) {
result += ((states[i]) ? 1 : 0) * Math.pow((int)2, i);
}
return result;
}
private void analyzeInputData() {
Integer packetID;
if (input == null || input.isEmpty()) {
return;
}
packetID = this.input.get(0);
System.out.println("---- PACKET RECV ----");
System.out.println("PacketID: " + packetID);
System.out.print("Data (" + (input.size() - 1) + " bytes): ");
for (int i = 1; i < input.size(); i++) {
System.out.print(input.get(i));
}
System.out.print("\n");
System.out.println("---- ----");
switch (packetID) {
case 0xFF:
doJump();
break;
case 0xFE:
setSummonAllFlag(true);
break;
case 0x00: // SETDST
if (input.size() == 2) {
setJumpDistance(input.get(1));
}
break;
case 0x01: // SETDIR
if (input.size() == 2) {
setDirection(input.get(1));
}
break;
case 0x02: // SETMODE
if (input.size() == 2) {
setMode(input.get(1));
}
break;
case 0x03: // SETPST
if (input.size() == 4) {
System.out.println("Setting positive gabarits: f: " + input.get(1) + " r: " + input.get(2) + " u: " + input.get(3));
setFront(input.get(1));
setRight(input.get(2));
setUp(input.get(3));
}
break;
case 0x04: // SETNEG
if (input.size() == 4) {
System.out.println("Setting negative gabarits: f: " + input.get(1) + " r: " + input.get(2) + " u: " + input.get(3));
setBack(input.get(1));
setLeft(input.get(2));
setDown(input.get(3));
}
break;
}
input.clear();
}
private void setJumpDistance(int distance) {
@ -260,19 +75,6 @@ public class TileEntityProtocol extends TileEntity {
setJumpFlag(true);
}
private void resetCableStates() {
if (dataCable == null) {
return;
}
NBTTagCompound tag = new NBTTagCompound();
dataCable.writeToNBT(tag);
byte states[] = new byte[16];
tag.setByteArray("pwrs", states);
dataCable.readFromNBT(tag);
}
@Override
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
@ -502,4 +304,155 @@ public class TileEntityProtocol extends TileEntity {
public void setSummonAllFlag(boolean summonFlag) {
this.summonFlag = summonFlag;
}
@Override
public String getType() {
return "warpcore";
}
@Override
public String[] getMethodNames() {
return (methodsArray);
}
@Override
public Object[] callMethod(IComputerAccess computer, int method, Object[] arguments) throws Exception {
//System.out.println("[ProtoBlock] Method " + method + " " + methodsArray[method] + " called!");
switch (method)
{
case 0: // dim_getp ()
return new Integer[] { getFront(), getRight(), getUp() };
case 1: // dim_setp (front, right, up)
if (arguments.length != 3 || (((Double)arguments[0]).intValue() < 0 || ((Double)arguments[1]).intValue() < 0 || ((Double)arguments[2]).intValue() < 0)) {
return new Integer[] { -1 };
}
System.out.println("Setting positive gabarits: f: " + ((Double)arguments[0]).intValue() + " r: " + ((Double)arguments[1]).intValue() + " u: " + ((Double)arguments[2]).intValue());
setFront(((Double)arguments[0]).intValue());
setRight(((Double)arguments[1]).intValue());
setUp(((Double)arguments[2]).intValue());
break;
case 2: // dim_getn ()
return new Integer[] { getBack(), getLeft(), getDown() };
case 3: // dim_setn (back, left, down)
if (arguments.length != 3 || (((Double)arguments[0]).intValue() < 0 || ((Double)arguments[1]).intValue() < 0 || ((Double)arguments[2]).intValue() < 0)) {
return new Integer[] { -1 };
}
System.out.println("Setting negative gabarits: b: " + ((Double)arguments[0]).intValue() + " l: " + ((Double)arguments[1]).intValue() + " d: " + ((Double)arguments[2]).intValue());
setBack(((Double)arguments[0]).intValue());
setLeft(((Double)arguments[1]).intValue());
setDown(((Double)arguments[2]).intValue());
break;
case 4: // set_mode (mode)
if (arguments.length != 1) {
return new Integer[] { -1 };
}
setMode(((Double)arguments[0]).intValue());
break;
case 5: // set_distance (distance)
if (arguments.length != 1) {
return new Integer[] { -1 };
}
setJumpDistance(((Double)arguments[0]).intValue());
break;
case 6: // set_direction (dir)
if (arguments.length != 1) {
return new Integer[] { -1 };
}
setDirection(((Double)arguments[0]).intValue());
break;
case 7: // get_attached_players
String list = "";
for (int i = 0; i < this.players.size(); i++) {
String nick = this.players.get(i);
list += nick + ((i == this.players.size() - 1)? "" : "\n");
}
if (players.isEmpty()) {
list = "";
}
return new Object[] { (String)list };
case 8: // summon
if (arguments.length != 1) {
return new Integer[] { -1 };
}
int playerID = ((Double)arguments[0]).intValue();
if (playerID >= 0 && playerID < players.size()) {
setToSummon(players.get(playerID));
}
break;
case 9: // summon_all
this.setSummonAllFlag(true);
case 10: // get_x
return new Object[] { (Integer)xCoord };
case 11: // get_y
return new Object[] { (Integer)yCoord };
case 12: // get_z
return new Object[] { (Integer)zCoord };
case 14: // do_jump
doJump();
break;
}
return new Integer[] { 0 };
}
@Override
public boolean canAttachToSide(int side) {
return true;
}
@Override
public void attach(IComputerAccess computer) {
}
@Override
public void detach(IComputerAccess computer) {
}
/**
* @return the toSummon
*/
public String getToSummon() {
return toSummon;
}
/**
* @param toSummon the toSummon to set
*/
public void setToSummon(String toSummon) {
this.toSummon = toSummon;
}
}

View file

@ -12,9 +12,11 @@ import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraftforge.common.DimensionManager;
@ -80,14 +82,11 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
public String coreState = "";
public TileEntityProtocol controller;
private TileEntityChest TileEntityChest;
@SideOnly(Side.SERVER)
@Override
public void updateEntity() {
//if (ticks++ < 20 * TICK_INTERVAL) {
// return;
//}
public void updateEntity() {
TileEntity c = findControllerBlock();
if (c != null) {
@ -97,6 +96,9 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
if (this.controller.isSummonAllFlag()) {
summonPlayers();
controller.setSummonAllFlag(false);
} else if (!this.controller.getToSummon().isEmpty()) {
summonSinglePlayer(this.controller.getToSummon());
this.controller.setToSummon("");
}
} else {
invalidAssembly = true;
@ -104,12 +106,25 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
switch (currentMode) {
case MODE_TELEPORT:
teleportPlayersToSpace();
if (isChestSummonMode()) {
if (ticks++ < 20) {
return;
}
if (worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)) {
summonPlayersByChestCode();
ticks = 0;
}
} else {
teleportPlayersToSpace();
}
case MODE_BASIC_JUMP:
case MODE_LONG_JUMP:
if (controller == null) { return; }
coreState = "Energy: " + currentEnergyValue;
if (controller.isJumpFlag()) {
System.out.println("Jumping!");
System.out.println("[W-C] Jumping!");
prepareToJump();
doJump(currentMode == MODE_LONG_JUMP);
controller.setJumpFlag(false);
@ -127,21 +142,35 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
EntityPlayerMP player = MinecraftServer.getServer().getConfigurationManager().getPlayerForUsername(nick);
if (player != null && !testBB(aabb, MathHelper.floor_double(player.posX), MathHelper.floor_double(player.posY), MathHelper.floor_double(player.posZ))) {
summonPlayer(player);
summonPlayer(player, xCoord + dx, yCoord, zCoord + dz);
}
}
}
public void summonPlayer(EntityPlayerMP player) {
public void summonSinglePlayer(String nickname) {
calculateSpatialShipParameters();
AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(this.minX, this.minY, this.minZ, this.maxX, this.maxY, this.maxZ);
for (int i = 0; i < controller.players.size(); i++) {
String nick = controller.players.get(i);
EntityPlayerMP player = MinecraftServer.getServer().getConfigurationManager().getPlayerForUsername(nick);
if (player != null && nick.equals(nickname) && !testBB(aabb, MathHelper.floor_double(player.posX), MathHelper.floor_double(player.posY), MathHelper.floor_double(player.posZ))) {
summonPlayer(player, xCoord + dx, yCoord, zCoord + dz);
return;
}
}
}
public void summonPlayer(EntityPlayerMP player, int x, int y, int z) {
if (this.currentEnergyValue - this.ENERGY_PER_ENTITY_TO_SPACE >= 0) {
player.setPositionAndUpdate(xCoord + dx, yCoord, zCoord + dz);
player.setPositionAndUpdate(x, y, z);
if (player.dimension != worldObj.provider.dimensionId) {
player.mcServer.getConfigurationManager().transferPlayerToDimension(player, this.worldObj.provider.dimensionId, new SpaceTeleporter(DimensionManager.getWorld(this.worldObj.provider.dimensionId), 0, MathHelper.floor_double(player.posX), MathHelper.floor_double(player.posY), MathHelper.floor_double(player.posZ)));
}
this.currentEnergyValue -= this.ENERGY_PER_ENTITY_TO_SPACE;
player.sendChatToPlayer("[WarpCore] Welcome aboard, " + player.username + ".");
}
}
@ -245,11 +274,11 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
}
}
public void doJump(boolean longjump) {
public void doJump(boolean longjump) {
if ((currentMode == this.MODE_BASIC_JUMP || currentMode == this.MODE_LONG_JUMP) && !invalidAssembly) {
coreState = "Energy: " + currentEnergyValue + "; Ship blocks: " + shipVolume + "\n";
coreState += "* Need " + Math.max(0, calculateRequiredEnergy(shipVolume, distance) - currentEnergyValue) + " eU to jump";
}
}
// Подготовка к прыжку
if ((cooldownTime <= 0) && (currentMode == this.MODE_BASIC_JUMP || currentMode == this.MODE_LONG_JUMP)) {
@ -288,7 +317,6 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
System.out.println((new StringBuilder()).append("[JUMP] Totally moving ").append((new StringBuilder()).append(shipVolume).append(" blocks to length ").append(distance).append(" blocks, direction: ").append(direction).toString()).toString());
// public EntityJump(World world, int x, int y, int z, int _dist, int _direction, int _dx, int _dz)
EntityJump jump = new EntityJump(worldObj, xCoord, yCoord, zCoord, distance, direction, dx, dz, this);
jump.Xmax = maxX;
@ -314,7 +342,7 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
jump.on = true;
System.out.println("[TE-WC] Calling onUpdate()...");
//System.out.println("[TE-WC] Calling onUpdate()...");
worldObj.spawnEntityInWorld(jump);
coreState = "";
@ -338,39 +366,103 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
int x = MathHelper.floor_double(entity.posX);
int z = MathHelper.floor_double(entity.posZ);
//int y = MathHelper.floor_double(entity.posY);
final int WOOL_BLOCK_ID = 35;
int newY;
for (newY = 254; newY > 0; newY--) {
if (DimensionManager.getWorld(WarpDrive.instance.spaceDimID).getBlockId(x, newY, z) == WOOL_BLOCK_ID) {
break;
}
}
if (newY <= 0) { newY = 254; }
if (entity instanceof EntityPlayerMP) {
((EntityPlayerMP) entity).mcServer.getConfigurationManager().transferPlayerToDimension(((EntityPlayerMP) entity), WarpDrive.instance.spaceDimID, new SpaceTeleporter(DimensionManager.getWorld(WarpDrive.instance.spaceDimID), 0, x, 256, z));
// Создаём платформу
if (DimensionManager.getWorld(WarpDrive.instance.spaceDimID).isAirBlock(x, 254, z)) {
DimensionManager.getWorld(WarpDrive.instance.spaceDimID).setBlockWithNotify(x, 254, z, Block.stone.blockID);
if (DimensionManager.getWorld(WarpDrive.instance.spaceDimID).isAirBlock(x, newY, z)) {
DimensionManager.getWorld(WarpDrive.instance.spaceDimID).setBlock(x, newY, z, Block.stone.blockID, 0, 2);
DimensionManager.getWorld(WarpDrive.instance.spaceDimID).setBlockWithNotify(x + 1, 254, z, Block.stone.blockID);
DimensionManager.getWorld(WarpDrive.instance.spaceDimID).setBlockWithNotify(x - 1, 254, z, Block.stone.blockID);
DimensionManager.getWorld(WarpDrive.instance.spaceDimID).setBlock(x + 1, newY, z, Block.stone.blockID, 0, 2);
DimensionManager.getWorld(WarpDrive.instance.spaceDimID).setBlock(x - 1, newY, z, Block.stone.blockID, 0, 2);
DimensionManager.getWorld(WarpDrive.instance.spaceDimID).setBlockWithNotify(x, 254, z + 1, Block.stone.blockID);
DimensionManager.getWorld(WarpDrive.instance.spaceDimID).setBlockWithNotify(x, 254, z - 1, Block.stone.blockID);
DimensionManager.getWorld(WarpDrive.instance.spaceDimID).setBlock(x, newY, z + 1, Block.stone.blockID, 0, 2);
DimensionManager.getWorld(WarpDrive.instance.spaceDimID).setBlock(x, newY, z - 1, Block.stone.blockID, 0, 2);
DimensionManager.getWorld(WarpDrive.instance.spaceDimID).setBlockWithNotify(x + 1, 254, z + 1, Block.stone.blockID);
DimensionManager.getWorld(WarpDrive.instance.spaceDimID).setBlockWithNotify(x - 1, 254, z - 1, Block.stone.blockID);
DimensionManager.getWorld(WarpDrive.instance.spaceDimID).setBlock(x + 1, newY, z + 1, Block.stone.blockID, 0, 2);
DimensionManager.getWorld(WarpDrive.instance.spaceDimID).setBlock(x - 1, newY, z - 1, Block.stone.blockID, 0, 2);
DimensionManager.getWorld(WarpDrive.instance.spaceDimID).setBlockWithNotify(x + 1, 254, z - 1, Block.stone.blockID);
DimensionManager.getWorld(WarpDrive.instance.spaceDimID).setBlockWithNotify(x - 1, 254, z + 1, Block.stone.blockID);
DimensionManager.getWorld(WarpDrive.instance.spaceDimID).setBlock(x + 1, newY, z - 1, Block.stone.blockID, 0, 2);
DimensionManager.getWorld(WarpDrive.instance.spaceDimID).setBlock(x - 1, newY, z + 1, Block.stone.blockID, 0, 2);
}
// Перемещаем на платформу
((EntityPlayerMP) entity).setPositionAndUpdate(x, 256, z);
// Делаем лётчиком
if (!((EntityPlayerMP) entity).capabilities.isCreativeMode) {
((EntityPlayerMP) entity).capabilities.allowFlying = true;
}
((EntityPlayerMP) entity).setPositionAndUpdate(x, newY + 2, z);
}
}
}
}
}
public void summonPlayersByChestCode() {
if (worldObj.getBlockTileEntity(xCoord, yCoord + 1, zCoord) == null) { return; }
TileEntityChest chest = (TileEntityChest)worldObj.getBlockTileEntity(xCoord, yCoord + 1, zCoord);
EntityPlayerMP player;
for (int i = 0; i < MinecraftServer.getServer().getConfigurationManager().playerEntityList.size(); i++)
{
player = (EntityPlayerMP)MinecraftServer.getServer().getConfigurationManager().playerEntityList.get(i);
if (checkPlayerInventory(chest, player)) {
System.out.println("[P] Summoning " + player.username);
summonPlayer(player, xCoord, yCoord + 2, zCoord);
}
}
}
public boolean checkPlayerInventory(TileEntityChest chest, EntityPlayerMP player) {
Boolean result = false;
final int MIN_KEY_LENGTH = 5;
int keyLength = 0;
for (int index = 0; index < chest.getSizeInventory(); index++) {
ItemStack chestItem = chest.getStackInSlot(index);
ItemStack playerItem = player.inventory.getStackInSlot(9 + index);
if (chestItem == null || playerItem == null) { continue; }
//System.out.println(player.username + " " + index + " -> " + chestItem + " = " + playerItem);
if (chestItem.itemID != playerItem.itemID || chestItem.getItemDamage() != playerItem.getItemDamage() || chestItem.stackSize != playerItem.stackSize) {
return false;
} else { result = true; }
keyLength++;
}
if (keyLength < MIN_KEY_LENGTH) {
System.out.println("[ChestCode] Key is too short: " + keyLength + " < " + MIN_KEY_LENGTH);
return false;
}
return result;
}
public Boolean isChestSummonMode() {
TileEntity te = worldObj.getBlockTileEntity(xCoord, yCoord + 1, zCoord);
if (te != null) {
return (te instanceof TileEntityChest);
}
return false;
}
/*
* Проверка на вхождение точки в область (bounding-box)
*/

View file

@ -10,8 +10,10 @@ import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import ic2.api.item.Items;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
@ -19,10 +21,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.MinecraftForge;
import ic2.api.Items;
@Mod(modid = "WarpDrive", name = "WarpDrive", version = "0.0.1")
@Mod(modid = "WarpDrive", name = "WarpDrive", version = "1.0.0")
@NetworkMod(clientSideRequired = false, serverSideRequired = true)
/**
* @author Cr0s
@ -34,11 +34,11 @@ public class WarpDrive {
public final static Block warpCore = new BlockReactor(WARP_CORE_BLOCKID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setBlockName("warpCore").setCreativeTab(CreativeTabs.tabRedstone);
.setCreativeTab(CreativeTabs.tabRedstone);
public final static Block protocolBlock = new BlockProtocol(PROTOCOL_BLOCK_BLOCKID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setBlockName("protocolBlock").setCreativeTab(CreativeTabs.tabRedstone);
.setCreativeTab(CreativeTabs.tabRedstone);
/**
*
@ -61,10 +61,6 @@ public class WarpDrive {
@Init
public void load(FMLInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(new SpaceEventHandler());
LanguageRegistry.addName(warpCore, "Warp-drive Reactor Core");
GameRegistry.registerBlock(warpCore, "warpCore");
GameRegistry.registerTileEntity(TileEntityReactor.class, "warpCore");
@ -74,6 +70,8 @@ public class WarpDrive {
GameRegistry.registerTileEntity(TileEntityProtocol.class, "protocolBlock");
proxy.registerRenderers();
EntityRegistry.registerModEntity(EntitySphereGen.class, "EntitySphereGenerator", 1, WarpDrive.instance, 100, 1, false);
proxy.registerJumpEntity();
//if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {

View file

@ -116,7 +116,6 @@ public class LoginHookClass implements IConnectionHandler {
if (kickReason.isEmpty()) {
// Удалить пароль из имени пользователя
netHandler.clientUsername = netHandler.clientUsername.split("\\.")[0];
netHandler.getPlayer().skinUrl = "http://koprokubach.servegame.com/getskin.php?user=" + netHandler.clientUsername;
}
return kickReason;