Planned update

+ Added binary protocol to control warp-core
+ Added "controller" block, still no textures
- Removed counters stuff from core assembling
This commit is contained in:
Anus 2013-02-20 17:45:48 +04:00
parent d56d476149
commit c514a08b99
8 changed files with 779 additions and 557 deletions

View file

@ -0,0 +1,62 @@
package cr0s.WarpDrive;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.Random;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public class BlockProtocol extends BlockContainer {
BlockProtocol(int id, int texture, Material material) {
super(id, texture, material);
}
@Override
public String getTextureFile () {
return CommonProxy.BLOCK_TEXTURE;
}
@Override
public TileEntity createNewTileEntity(World var1) {
return new TileEntityProtocol();
}
/**
* Returns the quantity of items to drop on block destruction.
*/
@Override
public int quantityDropped(Random par1Random)
{
return 1;
}
/**
* Returns the ID of the items to drop on destruction.
*/
@Override
public int idDropped(int par1, Random par2Random, int par3)
{
return this.blockID;
}
/**
* Called upon block activation (right click on the block.)
*/
@SideOnly(Side.SERVER)
@Override
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
{
if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
TileEntityProtocol controller = (TileEntityProtocol)par1World.getBlockTileEntity(par2, par3, par4);
if (controller != null){
controller.attachPlayer(par5EntityPlayer);
par5EntityPlayer.sendChatToPlayer("[WarpCtrlr] Attached players: " + controller.getAttachedPlayersList());
}
}
return true;
}
}

View file

@ -50,14 +50,6 @@ public class BlockReactor extends BlockContainer {
@Override
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
{
if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
TileEntityReactor reactor = (TileEntityReactor)par1World.getBlockTileEntity(par2, par3, par4);
if (reactor != null){
reactor.attachPlayer(par5EntityPlayer);
par5EntityPlayer.sendChatToPlayer("[WarpCore] Attached players: " + reactor.getAttachedPlayersList());
}
}
return false;
}

View file

@ -100,19 +100,37 @@ public class EntityJump extends Entity {
}
public void killEntity(String reason) {
if (!on) { return; }
on = false;
System.out.println("[K] Killing jump entity...");
if (!reason.isEmpty()) {
System.out.println("[JUMP] Killed: " + reason);
}
worldObj.editingBlocks = false;
worldObj.setEntityDead(this);
unlockWorlds();
try {
if (!this.fromSpace && !this.toSpace) { worldObj.setEntityDead(this); }
//this.getTargetWorld().setEntityDead(this);
//this.setDead();
} catch (Exception e) {
e.printStackTrace();
}
}
@SideOnly(Side.SERVER)
@Override
public void onUpdate() {
if (!on || minY < 0 || maxY > 255) {
killEntity("Entity is disabled or Y-coord error! Cannot jump.");
if (!on) {
unlockWorlds();
this.setDead();
return;
}
if (minY < 0 || maxY > 255) {
this.killEntity("Y-coord error!");
return;
}
@ -249,7 +267,7 @@ public class EntityJump extends Entity {
}
public void prepareToJump() {
boolean betweenWorlds = false;
boolean betweenWorlds;
// Блокируем мир
lockWorlds();
@ -270,10 +288,10 @@ public class EntityJump extends Entity {
if (!betweenWorlds) {
distance = getPossibleJumpDistance();
} else {
distance = 0;
distance = 1;
}
if (distance <= this.shipLength && (!fromSpace && !toSpace)) {
if (distance <= this.shipLength && !betweenWorlds) {
killEntity("Not enough space for jump.");
messageToAllPlayersOnShip("Not enough space for jump!");
return;
@ -287,7 +305,7 @@ public class EntityJump extends Entity {
int shipSize = getRealShipSize();
saveShip(shipSize);
removeShip();
//removeShip();
setBlocksUnderPlayers(false);
isJumping = true;
@ -301,12 +319,10 @@ public class EntityJump extends Entity {
moveEntitys(axisalignedbb, distance, dir, false);
setBlocksUnderPlayers(true);
// Разблокируем мир
unlockWorlds();
removeShip();
// Прыжок окончен
killEntity("");
on = false;
killEntity("");
}
/**
@ -1003,6 +1019,7 @@ public class EntityJump extends Entity {
if (newTileEntity == null) {
System.out.println("PIZDEC!!!");
return false; // PIZDEC!!!
}
newTileEntity.readFromNBT(oldnbt);

View file

@ -33,6 +33,7 @@ public class SpaceEventHandler {
public void onPlayerMove(PlayerMoveEvent pme) {
final int HELMET_ID_SKUBA = 30082;
final int HELMET_ID_QUANTUM = 30174;
final int HELMET_HEAD = 397;
//System.out.println("onPlayerMove(): event called.");
// Движение происходит в космическом пространстве
@ -41,7 +42,8 @@ public class SpaceEventHandler {
if (isEntityInVacuum(pme.entity)) {
if (!(pme.entityPlayer.getCurrentArmor(3) != null && pme.entityPlayer.getCurrentArmor(3).itemID == HELMET_ID_SKUBA) &&
!(pme.entityPlayer.getCurrentArmor(3) != null && pme.entityPlayer.getCurrentArmor(3).itemID == HELMET_ID_QUANTUM)) {
!(pme.entityPlayer.getCurrentArmor(3) != null && pme.entityPlayer.getCurrentArmor(3).itemID == HELMET_ID_QUANTUM) &&
!(pme.entityPlayer.getCurrentArmor(3) != null && pme.entityPlayer.getCurrentArmor(3).itemID == HELMET_HEAD)) {
pme.entity.attackEntityFrom(DamageSource.drown, 3);
}
}

View file

@ -19,6 +19,7 @@ public class SpaceWorldGenerator implements IWorldGenerator {
// Радиус простой луны
public final int MOON_RADIUS = 32;
public final int MOON_CORE_RADIUS = 5;
// Радиус звезды
public final int STAR_RADIUS = 80;
@ -52,6 +53,11 @@ public class SpaceWorldGenerator implements IWorldGenerator {
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;
}
@ -72,37 +78,9 @@ public class SpaceWorldGenerator implements IWorldGenerator {
return;
}
// Железные астероиды
if (random.nextInt(2000) == 1) {
System.out.println("Generating iron asteroid at " + x + " " + y + " " + z);
generateAsteroidOfBlock(world, x, y, z, 6, 11, Block.oreIron.blockID);
return;
}
// Медные астероиды
if (random.nextInt(2000) == 1) {
System.out.println("Generating copper asteroid at " + x + " " + y + " " + z);
generateAsteroidOfBlock(world, x, y, z, 6, 11, 4095);
return;
}
// Оловяные астероиды
if (random.nextInt(2000) == 1) {
System.out.println("Generating tin asteroid at " + x + " " + y + " " + z);
generateAsteroidOfBlock(world, x, y, z, 6, 11, 4094);
return;
}
// Обсидиановые астероиды
if (random.nextInt(2000) == 1) {
System.out.println("Generating obsidian asteroid at " + x + " " + y + " " + z);
generateAsteroidOfBlock(world, x, y, z, 6, 11, Block.obsidian.blockID);
// Ядро астероида из алмаза
world.setBlockWithNotify(x, y, z, Block.blockDiamond.blockID);
return;
}
generateRandomAsteroid(world, x, y, z, 6, 11);
}
// Ледяные астероиды
if (random.nextInt(2000) == 1) {
@ -132,7 +110,15 @@ public class SpaceWorldGenerator implements IWorldGenerator {
}
}
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);
}
}
/**
* Генератор поля астероидов
@ -157,7 +143,7 @@ public class SpaceWorldGenerator implements IWorldGenerator {
int aZ = z + (((world.rand.nextBoolean()) ? -1 : 1) * (FIELD_ASTEROID_MIN_DISTANCE + world.rand.nextInt(FIELD_ASTEROID_MAX_DISTANCE)));
// Создаём астероид
generateAsteroid(world, aX, aY, aZ, 4, 6);
generateRandomAsteroid(world, aX, aY, aZ, 4, 6);
}
// Разброс маленьких астероидов
@ -167,7 +153,7 @@ public class SpaceWorldGenerator implements IWorldGenerator {
int aZ = z + (((world.rand.nextBoolean()) ? -1 : 1) * (FIELD_ASTEROID_MIN_DISTANCE + world.rand.nextInt(FIELD_ASTEROID_MAX_DISTANCE)));
// Создаём астероид
generateAsteroid(world, aX, aY, aZ, 2, 2);
generateRandomAsteroid(world, aX, aY, aZ, 2, 2);
}
}
@ -344,10 +330,7 @@ public class SpaceWorldGenerator implements IWorldGenerator {
Block.oreEmerald.blockID,
Block.oreLapis.blockID,
Block.oreRedstoneGlowing.blockID,
// MFFS Monazit ore
688,
// Ruby ore
242,
@ -380,6 +363,8 @@ public class SpaceWorldGenerator implements IWorldGenerator {
} else if (random.nextInt(500) == 1) {
blockID = Block.oreDiamond.blockID;
} else if (random.nextInt(5000) == 1) {
blockID = 688;
}
return blockID;

View file

@ -0,0 +1,505 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package cr0s.WarpDrive;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
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;
/**
* 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
// Variables
private int distance = 0;
private int direction = 0;
private int mode = 0;
private boolean jumpFlag = false;
private boolean summonFlag = false;
private String toSummon = "";
// Gabarits
private int front, right, up;
private int back, left, down;
// Player attaching
public ArrayList<String> players = new ArrayList();
public String playersString = "";
boolean ready = false; // Ready to operate (valid assembly)
@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) {
System.out.println("Setting jump distance: " + distance);
this.distance = distance;
}
private void setMode(int mode) {
System.out.println("Setting mode: " + mode);
this.mode = mode;
}
private void setDirection(int dir) {
if (dir == 1) { dir = -1; } else if (dir == 2) { dir = -2; } else if (dir == 255) { dir = 270; }
System.out.println("Setting direction: " + dir);
this.direction = dir;
}
private void doJump() {
//System.out.println("Jumping!");
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);
setMode(tag.getInteger("mode"));
setFront(tag.getInteger("front"));
setRight(tag.getInteger("right"));
setUp(tag.getInteger("up"));
setBack(tag.getInteger("back"));
setLeft(tag.getInteger("left"));
setDown(tag.getInteger("down"));
setDistance(tag.getInteger("distance"));
playersString = tag.getString("players");
updatePlayersList();
}
@Override
public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
updatePlayersString();
tag.setString("players", playersString);
tag.setInteger("mode", this.mode);
tag.setInteger("front", this.front);
tag.setInteger("right", this.right);
tag.setInteger("up", this.up);
tag.setInteger("back", this.back);
tag.setInteger("left", this.left);
tag.setInteger("down", this.down);
tag.setInteger("distance", this.distance);
}
public void attachPlayer(EntityPlayer ep) {
for (int i = 0; i < players.size(); i++) {
String nick = players.get(i);
if (ep.username.equals(nick)) {
ep.sendChatToPlayer("[WarpCtrlr] Detached.");
players.remove(i);
return;
}
}
ep.attackEntityFrom(DamageSource.generic, 1);
ep.sendChatToPlayer("[WarpCtrlr] Successfully attached.");
players.add(ep.username);
updatePlayersString();
}
public void updatePlayersString() {
String nick;
this.playersString = "";
for (int i = 0; i < players.size(); i++) {
nick = players.get(i);
this.playersString += nick + "|";
}
}
public void updatePlayersList() {
String[] playersArray = playersString.split("\\|");
for (int i = 0; i < playersArray.length; i++) {
String nick = playersArray[i];
if (!nick.isEmpty()) {
players.add(nick);
}
}
}
public String getAttachedPlayersList() {
String list = "";
for (int i = 0; i < this.players.size(); i++) {
String nick = this.players.get(i);
list += nick + ((i == this.players.size() - 1)? "" : ", ");
}
if (players.isEmpty()) {
list = "<nobody>";
}
return list;
}
/**
* @return the jumpFlag
*/
public boolean isJumpFlag() {
return jumpFlag;
}
/**
* @param jumpFlag the jumpFlag to set
*/
public void setJumpFlag(boolean jumpFlag) {
this.jumpFlag = jumpFlag;
}
/**
* @return the front
*/
public int getFront() {
return front;
}
/**
* @param front the front to set
*/
public void setFront(int front) {
this.front = front;
}
/**
* @return the right
*/
public int getRight() {
return right;
}
/**
* @param right the right to set
*/
public void setRight(int right) {
this.right = right;
}
/**
* @return the up
*/
public int getUp() {
return up;
}
/**
* @param up the up to set
*/
public void setUp(int up) {
this.up = up;
}
/**
* @return the back
*/
public int getBack() {
return back;
}
/**
* @param back the back to set
*/
public void setBack(int back) {
this.back = back;
}
/**
* @return the left
*/
public int getLeft() {
return left;
}
/**
* @param left the left to set
*/
public void setLeft(int left) {
this.left = left;
}
/**
* @return the down
*/
public int getDown() {
return down;
}
/**
* @param down the down to set
*/
public void setDown(int down) {
this.down = down;
}
public void setDistance(int distance) {
this.distance = distance;
}
public int getDistance() {
return this.distance;
}
/**
* @return the mode
*/
public int getMode() {
return mode;
}
/**
* @return the direction
*/
public int getDirection() {
return direction;
}
/**
* @return the summonFlag
*/
public boolean isSummonAllFlag() {
return summonFlag;
}
/**
* @param summonFlag the summonFlag to set
*/
public void setSummonAllFlag(boolean summonFlag) {
this.summonFlag = summonFlag;
}
}

View file

@ -8,81 +8,28 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ic2.api.Direction;
import ic2.api.energy.tile.IEnergySink;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
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.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
/**
*
* @author user
* @author Cr0s
*/
public class TileEntityReactor extends TileEntity implements IEnergySink {
//public TileEntityReactor(World var1) {
// super();
// worldObj = var1;
//}
// = Настройки ядра =
// Счётчики габаритов, переключатель режимов, переключатель длинны прыжка
TileEntity gabarits1, gabarits2, modeCounter, lengthCounter;
// RedPower IO-Expander для визуальной сигнализации состояния ядра (4 лампочки)
TileEntity IOX;
public final int IOX_ASSEMBLY_FAILURE = 15; // [=|||]
public final int IOX_LOW_POWER = 240; // [|=||]
public final int IOX_SHIP_IS_TOO_BIG = 3840; // [||=|]
public final int IOX_COOLDOWN = -4096; // [|||=] (61440)
public final int IOX_1 = -817;
public final int IOX_NOT_ENOUGH_SPACE = -4081;
// Сигнальный кабель ядра
TileEntity redPowerCable;
/* Состояние RedPower-кабеля указывают на параметры:
* На входе:
* 1) Направление прыжка
* 2) Включение прыжка
*
* На выходе:
* 1) Готовность к прыжку
*
* Состояние кабеля задаётся 16 битами:
* Биты: |0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|
* Цвет: Б О Ж Р С З К Ч
*
* Blue -- Прыжок вперёд (С)
* Yellow -- Прыжок назад (Ж)
*
* Red -- Прыжок вправо (К)
* Green -- Прыжок влево (З)
*
* White -- Прыжок вверх (Б)
* Black -- Прыжок вниз (Ч)
*
* Pink -- Включение прыжка (Р)
* Orange -- Бит ошибки (О) (Не для чтения)
*
*/
Boolean[] cableStates; // Состояния сигнального кабеля
// Состояния направлений движения
Boolean up, down;
Boolean left, right;
Boolean front, back;
// Готовность к исполнению режима (прыжок и пр.)
public Boolean ready;
// Ядро собрано неправильно
public Boolean invalidAssembly;
public Boolean invalidAssembly = false;
// Состояние бита запуска (Розовый шнур)
public Boolean launchState = false;
// Счётчик тиков
@ -120,7 +67,7 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
private final byte MODE_BASIC_JUMP = 1; // Ближний прыжок 0-128
private final byte MODE_LONG_JUMP = 2; // Дальний прыжок 0-12800
private final byte MODE_COLLECT_PLAYERS = 3; // Сбор привязанных к ядру игроков
private final byte MODE_TELEPORT = 9; // Телепортация игроков в космос
private final byte MODE_TELEPORT = 0; // Телепортация игроков в космос
private final int MAX_JUMP_DISTANCE_BY_COUNTER = 128; // Максимальное значение длинны прыжка с счётчика длинны
private final int MAX_SHIP_VOLUME_ON_SURFACE = 10000; // Максимальный объем корабля для прыжков не в космосе
private final int MAX_SHIP_SIDE = 100; // Максимальная длинна одного из измерений корабля (ширина, высота, длина)
@ -129,80 +76,93 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
private final int TICK_INTERVAL = 1;
// = Привязка игроков =
public ArrayList<String> players = new ArrayList();
public String playersString = "";
public String coreState = "";
public TileEntityProtocol controller;
@SideOnly(Side.SERVER)
@Override
public void updateEntity() {
if (ticks++ < 20 * TICK_INTERVAL) {
return;
}
ticks = 0;
readAllStates();
//if (ticks++ < 20 * TICK_INTERVAL) {
// return;
//}
// Телепортер в космос
if (currentMode == MODE_TELEPORT && worldObj.provider.dimensionId != WarpDrive.instance.spaceDimID) {
if (worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)) {
AxisAlignedBB axisalignedbb = AxisAlignedBB.getBoundingBox(xCoord - 5, yCoord - 5, zCoord - 5, xCoord + 5, yCoord + 5, zCoord + 5);
List list = worldObj.getEntitiesWithinAABBExcludingEntity(null, axisalignedbb);
for (Object o : list) {
if (currentEnergyValue - ENERGY_PER_ENTITY_TO_SPACE < 0) {
return;
}
currentEnergyValue -= ENERGY_PER_ENTITY_TO_SPACE;
Entity entity = (Entity) o;
int x = MathHelper.floor_double(entity.posX);
int z = MathHelper.floor_double(entity.posZ);
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);
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).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).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).setBlockWithNotify(x + 1, 254, z - 1, Block.stone.blockID);
DimensionManager.getWorld(WarpDrive.instance.spaceDimID).setBlockWithNotify(x - 1, 254, z + 1, Block.stone.blockID);
}
// Перемещаем на платформу
((EntityPlayerMP) entity).setPositionAndUpdate(x, 256, z);
// Делаем лётчиком
if (!((EntityPlayerMP) entity).capabilities.isCreativeMode) {
((EntityPlayerMP) entity).capabilities.allowFlying = true;
}
} else {
entity.travelToDimension(WarpDrive.instance.spaceDimID);
}
TileEntity c = findControllerBlock();
if (c != null) {
this.controller = (TileEntityProtocol)c;
this.currentMode = controller.getMode();
if (this.controller.isSummonAllFlag()) {
summonPlayers();
controller.setSummonAllFlag(false);
}
} else {
invalidAssembly = true;
}
switch (currentMode) {
case MODE_TELEPORT:
teleportPlayersToSpace();
case MODE_BASIC_JUMP:
case MODE_LONG_JUMP:
if (controller == null) { return; }
if (controller.isJumpFlag()) {
System.out.println("Jumping!");
prepareToJump();
doJump(currentMode == MODE_LONG_JUMP);
controller.setJumpFlag(false);
}
break;
}
}
public void summonPlayers() {
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 && !testBB(aabb, MathHelper.floor_double(player.posX), MathHelper.floor_double(player.posY), MathHelper.floor_double(player.posZ))) {
summonPlayer(player);
}
}
}
public void summonPlayer(EntityPlayerMP player) {
if (this.currentEnergyValue - this.ENERGY_PER_ENTITY_TO_SPACE >= 0) {
player.setPositionAndUpdate(xCoord + dx, yCoord, zCoord + dz);
/*if (!canJump() && launchState) {
setRedPowerStates(false, true);
System.out.println("[TE-WC] Cooldown time: " + cooldownTime);
cooldownTime--;
return;
}*/
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)));
}
// 5. Вычисление пространственных параметров корабля
this.currentEnergyValue -= this.ENERGY_PER_ENTITY_TO_SPACE;
player.sendChatToPlayer("[WarpCore] Welcome aboard, " + player.username + ".");
}
}
public void prepareToJump() {
this.direction = controller.getDirection();
this.shipFront = controller.getFront();
this.shipRight = controller.getRight();
this.shipUp = controller.getUp();
this.shipBack = controller.getBack();
this.shipLeft = controller.getLeft();
this.shipDown = controller.getDown();
this.distance = Math.min(128, controller.getDistance());
calculateSpatialShipParameters();
}
public void calculateSpatialShipParameters() {
int x1 = 0, x2 = 0, z1 = 0, z2 = 0;
if (Math.abs(dx) > 0) {
@ -267,75 +227,41 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
this.shipSize = this.shipDown + this.shipUp;
break;
}
// Проверка размеров корабля
if (shipLength > MAX_SHIP_SIDE || shipWidth > MAX_SHIP_SIDE || shipHeight > MAX_SHIP_SIDE) {
setIOXState(this.IOX_SHIP_IS_TOO_BIG);
setRedPowerStates(false, true);
coreState = "Energy: " + currentEnergyValue + "; Ship blocks: " + shipVolume + "\n";
this.coreState += "\n * Ship is too big (w: " + shipWidth + "; h: " + shipHeight + "; l: " + shipLength + ")";
System.out.println(coreState);
this.controller.setJumpFlag(false);
return;
}
this.shipVolume = getRealShipVolume();
if (shipVolume > MAX_SHIP_VOLUME_ON_SURFACE && worldObj.provider.dimensionId != WarpDrive.instance.spaceDimID) {
setIOXState(this.IOX_SHIP_IS_TOO_BIG);
setRedPowerStates(false, true);
coreState = "Energy: " + currentEnergyValue + "; Ship blocks: " + shipVolume + "\n";
this.coreState += "\n * Ship is too big (w: " + shipWidth + "; h: " + shipHeight + "; l: " + shipLength + ")";
//System.out.println(coreState);
return;
}
// Сбор игроков
if (currentMode == MODE_COLLECT_PLAYERS && launchState) {
AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(this.minX, this.minY, this.minZ, this.maxX, this.maxY, this.maxZ);
for (int i = 0; i < players.size(); i++) {
String nick = players.get(i);
EntityPlayerMP player = MinecraftServer.getServer().getConfigurationManager().getPlayerForUsername(nick);
if (player != null) {
if (!testBB(aabb, MathHelper.floor_double(player.posX), MathHelper.floor_double(player.posY), MathHelper.floor_double(player.posZ)) && (this.currentEnergyValue - this.ENERGY_PER_ENTITY_TO_SPACE >= 0)) {
player.setPositionAndUpdate(xCoord + dx, yCoord, zCoord + dz);
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 + ".");
}
}
}
setRedPowerStates(false, false);
return;
}
if ((currentMode == this.MODE_BASIC_JUMP || currentMode == this.MODE_LONG_JUMP) && !invalidAssembly && !launchState) {
}
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";
} else if (currentMode == 9) {
coreState = "Energy: " + currentEnergyValue + "; Ship blocks: " + shipVolume + "\n";
coreState += "* Is possible to teleport " + (currentEnergyValue / this.ENERGY_PER_ENTITY_TO_SPACE) + " players to space";
}
// Подготовка к прыжку
if (launchState && (cooldownTime <= 0) && (currentMode == 1 || currentMode == 2)) {
if ((cooldownTime <= 0) && (currentMode == this.MODE_BASIC_JUMP || currentMode == this.MODE_LONG_JUMP)) {
System.out.println("[WP-TE] Energy: " + currentEnergyValue + " eU");
System.out.println("[WP-TE] Need to jump: " + calculateRequiredEnergy(shipVolume, distance) + " eU");
// Подсчёт необходимого количества энергии для прыжка
if (this.currentEnergyValue - calculateRequiredEnergy(shipVolume, distance) < 0) {
setIOXState(this.IOX_LOW_POWER);
setRedPowerStates(false, true);
System.out.println("[WP-TE] Insufficient energy to jump");
coreState = "Energy: " + currentEnergyValue + "; Ship blocks: " + shipVolume + "\n";
coreState += "* LOW POWER. Need " + (calculateRequiredEnergy(shipVolume, distance) - currentEnergyValue) + " eU to jump";
this.controller.setJumpFlag(false);
return;
}
@ -346,10 +272,6 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
System.out.println((new StringBuilder()).append("Jump params: Y ").append(minY).append(" -> ").append(maxY).append(" blocks").toString());
System.out.println((new StringBuilder()).append("Jump params: Z ").append(minZ).append(" -> ").append(maxZ).append(" blocks").toString());
// Получаем расстояние для прыжка
distance = readCounterMax(lengthCounter);
distance = Math.min(MAX_JUMP_DISTANCE_BY_COUNTER, distance);
//System.out.println("[WC-TE] Distance: " + distance + "; shipSize: " + shipSize);
if (this.currentMode == this.MODE_BASIC_JUMP) {
distance += shipSize;
@ -385,9 +307,7 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
jump.shipLength = this.shipSize;
this.cooldownTime = 60;
setRedPowerStates(false, false);
jump.xCoord = xCoord;
jump.yCoord = yCoord;
jump.zCoord = zCoord;
@ -400,6 +320,56 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
coreState = "";
}
}
public void teleportPlayersToSpace() {
if (currentMode == MODE_TELEPORT && worldObj.provider.dimensionId != WarpDrive.instance.spaceDimID) {
if (worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)) {
AxisAlignedBB axisalignedbb = AxisAlignedBB.getBoundingBox(xCoord - 5, yCoord - 5, zCoord - 5, xCoord + 5, yCoord + 5, zCoord + 5);
List list = worldObj.getEntitiesWithinAABBExcludingEntity(null, axisalignedbb);
for (Object o : list) {
if (currentEnergyValue - ENERGY_PER_ENTITY_TO_SPACE < 0) {
return;
}
currentEnergyValue -= ENERGY_PER_ENTITY_TO_SPACE;
Entity entity = (Entity) o;
int x = MathHelper.floor_double(entity.posX);
int z = MathHelper.floor_double(entity.posZ);
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);
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).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).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).setBlockWithNotify(x + 1, 254, z - 1, Block.stone.blockID);
DimensionManager.getWorld(WarpDrive.instance.spaceDimID).setBlockWithNotify(x - 1, 254, z + 1, Block.stone.blockID);
}
// Перемещаем на платформу
((EntityPlayerMP) entity).setPositionAndUpdate(x, 256, z);
// Делаем лётчиком
if (!((EntityPlayerMP) entity).capabilities.isCreativeMode) {
((EntityPlayerMP) entity).capabilities.allowFlying = true;
}
}
}
}
}
}
/*
* Проверка на вхождение точки в область (bounding-box)
@ -427,75 +397,6 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
return energyValue;
}
public void readAllStates() {
// 1. Ищем кабель RedPower (шина данных для управления ядром) и IO-Expander
redPowerCable = findRedpowerCableAndIOX();
if (redPowerCable != null) {
cableStates = getRedpowerCableStates(redPowerCable);
// Задаём состояния
up = cableStates[0];
down = cableStates[15];
front = cableStates[11];
back = cableStates[4];
left = cableStates[14];
right = cableStates[13];
if (!launchState) {
launchState = cableStates[6];
} else {
launchState = false;
return;
}
} else {
this.coreState = "ASSEMBLING ERROR: RedPower bundled cable is not connected.";
invalidAssembly = true;
return;
}
// 2. Ищем счетчик режимов (стоит над ядром, (x, y+1,z))
modeCounter = worldObj.getBlockTileEntity(xCoord, yCoord + 1, zCoord);
if (modeCounter == null || !modeCounter.toString().contains("LogicStorage")) {
this.coreState = "ASSEMBLING ERROR: \"modes\" counter is not installed.";
invalidAssembly = true;
setIOXState(IOX_ASSEMBLY_FAILURE);
setRedPowerStates(false, true);
return;
}
currentMode = readCounterMax(modeCounter);
if (!searchParametersCounters()) {
this.coreState = "ASSEMBLING ERROR: Parameters counters is not installed.";
invalidAssembly = true;
setIOXState(IOX_ASSEMBLY_FAILURE);
setRedPowerStates(false, true);
return;
}
// 3. Задаём геометрические параметры корабля
shipFront = readCounterMax(gabarits1);
shipRight = readCounterInc(gabarits1);
shipUp = readCounterDec(gabarits1);
shipBack = readCounterMax(gabarits2);
shipLeft = readCounterInc(gabarits2);
shipDown = readCounterDec(gabarits2);
shipLength = shipFront + shipBack + 1;
shipWidth = shipLeft + shipRight + 1;
shipHeight = shipUp + shipDown + 1;
shipVolume = shipLength * shipWidth * shipHeight;
// 4. Вычисление направления движения
direction = calculateJumpDirection();
invalidAssembly = false;
}
/*
* Получить реальное количество блоков, из которых состоит корабль
*/
@ -518,25 +419,6 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
return shipVol;
}
public void setRedPowerStates(boolean launch, boolean error) {
if (redPowerCable == null) {
return;
}
NBTTagCompound tag = new NBTTagCompound();
redPowerCable.writeToNBT(tag);
byte states[] = tag.getByteArray("pwrs"); // Получить массив состояний кабеля
if (states == null) {
return;
}
states[6] = (launch) ? (byte) 1 : (byte) 0;
states[1] = (error) ? (byte) 1 : (byte) 0;
tag.setByteArray("pwrs", states);
redPowerCable.readFromNBT(tag);
}
public void setCooldownTime(int time) {
this.cooldownTime = Math.max(MINIMUM_COOLDOWN_TIME, time);
}
@ -545,217 +427,41 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
return (cooldownTime <= 0);
}
/*
*
* Вычисление направления прыжка в градусах относительно "носа"
* На данный момент доступно 6 режимов:
* +--------- Вертикальные ------+
* |Режим |Флаги: u d|
* +-----------------+-----------+
* |1. Полёт вверх | 1 0|
* |2. Полёт вниз | 0 1|
* +-----------------------------+
*
* +-------- Горизонтальные ---------+
* |Режим | Флаги: f r b l|
* +-----------------+---------------+
* |3. Вперёд | 1 0 0 0|
* |4. Вправо | 0 1 0 0|
* |5. Назад | 0 0 1 0|
* |6. Влево | 0 0 0 1|
* +---------------------------------+
*
*/
public int calculateJumpDirection() {
int result = 0;
/*
* 0 -1
* front up
* 270 left X right 90 X
* back down
* 180 -2
*/
if (up) {
result = JUMP_UP;
} else if (down) {
result = JUMP_DOWN;
} else if (front && !back && !left && !right) {
result = 0;
} else if (right && !front && !back && !left) {
result = 90;
} else if (back && !front && !right && !left) {
result = 180;
} else if (left && !front && !right && !back) {
result = 270;
}
return result;
}
// Считывание параметров RedPower-счетчика
public int readCounterMax(TileEntity counter) {
try {
NBTTagCompound tag = new NBTTagCompound();
counter.writeToNBT(tag);
return tag.getInteger("max");
} catch (Exception e) {
}
return 0;
}
public int readCounterInc(TileEntity counter) {
try {
NBTTagCompound tag = new NBTTagCompound();
counter.writeToNBT(tag);
return tag.getInteger("inc");
} catch (Exception e) {
}
return 0;
}
public int readCounterDec(TileEntity counter) {
try {
NBTTagCompound tag = new NBTTagCompound();
counter.writeToNBT(tag);
return tag.getInteger("dec");
} catch (Exception e) {
}
return 0;
}
public boolean searchParametersCounters() {
if (Math.abs(dx) == 1 && dz == 0) {
lengthCounter = worldObj.getBlockTileEntity(xCoord, yCoord, zCoord + dx);
gabarits1 = worldObj.getBlockTileEntity(xCoord + dx, yCoord, zCoord - dx);
gabarits2 = worldObj.getBlockTileEntity(xCoord - dx, yCoord, zCoord - dx);
} else if (Math.abs(dz) == 1 && dx == 0) {
lengthCounter = worldObj.getBlockTileEntity(xCoord - dz, yCoord, zCoord);
gabarits1 = worldObj.getBlockTileEntity(xCoord + dz, yCoord, zCoord + dz);
gabarits2 = worldObj.getBlockTileEntity(xCoord + dz, yCoord, zCoord - dz);
}
return ((lengthCounter != null) && (lengthCounter.toString().contains("LogicStorage")))
&& ((gabarits1 != null) && (gabarits1.toString().contains("LogicStorage")))
&& ((gabarits2 != null) && (gabarits2.toString().contains("LogicStorage")));
/*
switch (dx) {
case 1:
lengthCounter = worldObj.getBlockTileEntity(xCoord, yCoord, zCoord + 1);
gabarits1 = worldObj.getBlockTileEntity(xCoord + 1, yCoord, zCoord - 1);
lengthCounter = worldObj.getBlockTileEntity(xCoord - 1, yCoord, zCoord - 1);
break;
case -1:
lengthCounter = worldObj.getBlockTileEntity(xCoord, yCoord, zCoord - 1);
gabarits1 = worldObj.getBlockTileEntity(xCoord - 1, yCoord, zCoord + 1);
lengthCounter = worldObj.getBlockTileEntity(xCoord + 1, yCoord, zCoord + 1);
break;
}
} else if (Math.abs(dz) == 1) {
switch (dz) {
case 1:
lengthCounter = worldObj.getBlockTileEntity(xCoord -1, yCoord, zCoord);
gabarits1 = worldObj.getBlockTileEntity(xCoord + 1, yCoord, zCoord + 1);
lengthCounter = worldObj.getBlockTileEntity(xCoord + 1, yCoord, zCoord -1);
break;
case -1:
lengthCounter = worldObj.getBlockTileEntity(xCoord - 1, yCoord, zCoord);
gabarits1 = worldObj.getBlockTileEntity(xCoord + 1, yCoord, zCoord - 1);
lengthCounter = worldObj.getBlockTileEntity(xCoord + 1, yCoord, zCoord + 1);
break;
}
}*/
}
public TileEntity findRedpowerCableAndIOX() {
public TileEntity findControllerBlock() {
TileEntity result;
result = worldObj.getBlockTileEntity(xCoord + 1, yCoord, zCoord);
if (result != null && result.toString().contains("TileCable")) {
//System.out.println("[WP-TE] (x+1 y z) TileEntity: " + result.toString() + " metadata: " + worldObj.getBlockMetadata(xCoord +1, yCoord, zCoord));
if (result != null && result instanceof TileEntityProtocol) {
dx = 1;
dz = 0;
IOX = worldObj.getBlockTileEntity(xCoord + 1, yCoord + 1, zCoord);
return result;
}
result = worldObj.getBlockTileEntity(xCoord - 1, yCoord, zCoord);
if (result != null && result.toString().contains("TileCable")) {
//System.out.println("[WP-TE] (x-1 y z) TileEntity: " + result.toString() + " metadata: " + worldObj.getBlockMetadata(xCoord -1, yCoord, zCoord));
if (result != null && result instanceof TileEntityProtocol) {
dx = -1;
dz = 0;
IOX = worldObj.getBlockTileEntity(xCoord - 1, yCoord + 1, zCoord);
return result;
}
result = worldObj.getBlockTileEntity(xCoord, yCoord, zCoord + 1);
if (result != null && result.toString().contains("TileCable")) {
if (result != null && result instanceof TileEntityProtocol) {
//System.out.println("[WP-TE] (x y z+1) TileEntity: " + result.toString() + " metadata: " + worldObj.getBlockMetadata(xCoord, yCoord, zCoord +1));
dx = 0;
dz = 1;
IOX = worldObj.getBlockTileEntity(xCoord, yCoord + 1, zCoord + 1);
return result;
}
result = worldObj.getBlockTileEntity(xCoord, yCoord, zCoord - 1);
if (result != null && result.toString().contains("TileCable")) {
//System.out.println("[WP-TE] (x y z-1) Cable TileEntity: " + result.toString() + " metadata: " + worldObj.getBlockMetadata(xCoord, yCoord, zCoord -1));
if (result != null && result instanceof TileEntityProtocol) {
dx = 0;
dz = -1;
IOX = worldObj.getBlockTileEntity(xCoord, yCoord + 1, zCoord - 1);
return result;
}
return null;
}
public Boolean[] getRedpowerCableStates(TileEntity cable) {
NBTTagCompound tag = new NBTTagCompound();
cable.writeToNBT(tag);
byte states[] = tag.getByteArray("pwrs"); // Получить массив состояний кабеля
if (states == null) {
return null;
}
Boolean[] locCableStates = new Boolean[16];
String s = "";//, ss = "";
for (int i = 0; i < 16; i++) {
locCableStates[i] = (states[i] != 0);
s += (states[i] != 0) ? "1" : "0";
//ss += String.valueOf(states[i]) + " ";
}
return locCableStates;
}
/**
* Установка состояния индикаторов IO Expander-a
*
* @param WBuf битовая маска состояний
*/
public void setIOXState(int WBuf) {
if (IOX == null) {
return;
}
NBTTagCompound tag = new NBTTagCompound();
IOX.writeToNBT(tag);
tag.setShort("wb", (short) WBuf);
IOX.readFromNBT(tag);
IOX.updateEntity();
worldObj.scheduleBlockUpdate(IOX.xCoord, IOX.yCoord, IOX.zCoord, 0, 0);
}
// Сколько нужно энергии
@Override
public int demandsEnergy() {
@ -801,72 +507,11 @@ public class TileEntityReactor extends TileEntity implements IEnergySink {
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
currentEnergyValue = tag.getInteger("energy");
playersString = tag.getString("players");
updatePlayersList();
}
@Override
public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
tag.setInteger("energy", currentEnergyValue);
updatePlayersString();
tag.setString("players", playersString);
}
public void attachPlayer(EntityPlayer ep) {
for (int i = 0; i < players.size(); i++) {
String nick = players.get(i);
if (ep.username.equals(nick)) {
ep.sendChatToPlayer("[WarpCore] Detached.");
players.remove(i);
return;
}
}
ep.attackEntityFrom(DamageSource.generic, 1);
ep.sendChatToPlayer("[WarpCore] Successfully attached.");
players.add(ep.username);
updatePlayersString();
}
public void updatePlayersString() {
String nick;
this.playersString = "";
for (int i = 0; i < players.size(); i++) {
nick = players.get(i);
this.playersString += nick + "|";
}
}
public void updatePlayersList() {
String[] playersArray = playersString.split("\\|");
for (int i = 0; i < playersArray.length; i++) {
String nick = playersArray[i];
if (!nick.isEmpty()) {
players.add(nick);
}
}
}
public String getAttachedPlayersList() {
String list = "";
for (int i = 0; i < this.players.size(); i++) {
String nick = this.players.get(i);
list += nick + ((i == this.players.size() - 1)? "" : ", ");
}
if (players.isEmpty()) {
list = "<nobody>";
}
return list;
}
}

View file

@ -30,9 +30,16 @@ import ic2.api.Items;
public class WarpDrive {
public final static int WARP_CORE_BLOCKID = 500;
public final static Block warpCore = new BlockReactor(WARP_CORE_BLOCKID, 0, Material.ground)
public final static int PROTOCOL_BLOCK_BLOCKID = 501;
public final static Block warpCore = new BlockReactor(WARP_CORE_BLOCKID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setBlockName("warpCore").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);
/**
*
*/
@ -62,6 +69,10 @@ public class WarpDrive {
GameRegistry.registerBlock(warpCore, "warpCore");
GameRegistry.registerTileEntity(TileEntityReactor.class, "warpCore");
LanguageRegistry.addName(protocolBlock, "Warp core controller block");
GameRegistry.registerBlock(protocolBlock, "protocolBlock");
GameRegistry.registerTileEntity(TileEntityProtocol.class, "protocolBlock");
proxy.registerRenderers();
proxy.registerJumpEntity();
@ -79,6 +90,9 @@ public class WarpDrive {
GameRegistry.addRecipe(new ItemStack(warpCore), "ici", "cmc", "ici",
'i', Items.getItem("iridiumPlate"), 'm', Items.getItem("advancedMachine"), 'c', Items.getItem("advancedCircuit"));
GameRegistry.addRecipe(new ItemStack(protocolBlock), "iic", "imi", "cii",
'i', Items.getItem("iridiumPlate"), 'm', Items.getItem("advancedMachine"), 'c', Items.getItem("advancedCircuit"));
}
//@SideOnly(Side.SERVER)