Последний кросоапдейт

This commit is contained in:
ZLOFENIX 2014-02-12 17:07:12 +04:00
parent b2d5d7f167
commit 09ed8621d2
26 changed files with 3337 additions and 773 deletions

View file

@ -10,278 +10,279 @@ import net.minecraft.world.World;
public class BlockAir extends Block
{
private final boolean TRANSPARENT_AIR = true;
private final boolean TRANSPARENT_AIR = true;
public BlockAir(int par1)
{
super(par1, Material.air);
}
public BlockAir(int par1)
{
super(par1, Material.air);
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
public boolean isAirBlock(World var1, int var2, int var3, int var4)
{
return true;
}
@Override
public boolean isAirBlock(World var1, int var2, int var3, int var4)
{
return true;
}
@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World var1, int var2, int var3, int var4)
{
return null;
}
@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World var1, int var2, int var3, int var4)
{
return null;
}
@Override
public boolean isBlockReplaceable(World var1, int var2, int var3, int var4)
{
return true;
}
@Override
public boolean isBlockReplaceable(World var1, int var2, int var3, int var4)
{
return true;
}
@Override
public boolean canPlaceBlockAt(World var1, int var2, int var3, int var4)
{
return true;
}
@Override
public boolean canPlaceBlockAt(World var1, int var2, int var3, int var4)
{
return true;
}
@Override
public boolean canCollideCheck(int var1, boolean var2)
{
return false;
}
@Override
public boolean canCollideCheck(int var1, boolean var2)
{
return false;
}
@Override
public int getRenderBlockPass()
{
return TRANSPARENT_AIR ? 1 : 0;
}
@Override
public int getRenderBlockPass()
{
return TRANSPARENT_AIR ? 1 : 0;
}
@Override
public void registerIcons(IconRegister par1IconRegister)
{
this.blockIcon = par1IconRegister.registerIcon("warpdrive:airBlock");
}
@Override
public void registerIcons(IconRegister par1IconRegister)
{
this.blockIcon = par1IconRegister.registerIcon("warpdrive:airBlock");
}
@Override
public int getMobilityFlag()
{
return 1;
}
@Override
public int getMobilityFlag()
{
return 1;
}
@Override
public int idDropped(int var1, Random var2, int var3)
{
return -1;
}
@Override
public int idDropped(int var1, Random var2, int var3)
{
return -1;
}
/**
* Returns the quantity of items to drop on block destruction.
*/
@Override
public int quantityDropped(Random par1Random)
{
return 0;
}
/**
* Returns the quantity of items to drop on block destruction.
*/
@Override
public int quantityDropped(Random par1Random)
{
return 0;
}
/**
* How many world ticks before ticking
*/
@Override
public int tickRate(World par1World)
{
return 20;
}
/**
* How many world ticks before ticking
*/
@Override
public int tickRate(World par1World)
{
return 20;
}
/**
* Ticks the block if it's been scheduled
*/
@Override
public void updateTick(World par1World, int x, int y, int z, Random par5Random)
{
int concentration = par1World.getBlockMetadata(x, y, z);
boolean isInSpaceWorld = par1World.provider.dimensionId == WarpDrive.instance.spaceDimID || par1World.provider.dimensionId == WarpDrive.instance.hyperSpaceDimID;
/**
* Ticks the block if it's been scheduled
*/
@Override
public void updateTick(World par1World, int x, int y, int z, Random par5Random)
{
int concentration = par1World.getBlockMetadata(x, y, z);
boolean isInSpaceWorld = par1World.provider.dimensionId == WarpDrive.instance.spaceDimID || par1World.provider.dimensionId == WarpDrive.instance.hyperSpaceDimID;
// Remove air block to vacuum block
if (concentration <= 0 || !isInSpaceWorld)
{
//System.out.println("Killing air block");
par1World.setBlock(x, y, z, 0, 0, 2); // replace our air block to vacuum block
}
else
{
//System.out.println("Conc: current " + concentration + " new: " + (concentration - 1) + " to spread: " + (concentration - 2));
// Try to spread the air
spreadAirBlock(par1World, x, y, z, concentration);
}
// Remove air block to vacuum block
if (concentration <= 0 || !isInSpaceWorld)
{
//System.out.println("Killing air block");
par1World.setBlock(x, y, z, 0, 0, 2); // replace our air block to vacuum block
}
else
{
//System.out.println("Conc: current " + concentration + " new: " + (concentration - 1) + " to spread: " + (concentration - 2));
// Try to spread the air
spreadAirBlock(par1World, x, y, z, concentration);
}
par1World.scheduleBlockUpdate(x, y, z, this.blockID, 20);
}
par1World.scheduleBlockUpdate(x, y, z, this.blockID, 20);
}
@Override
public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
{
if (par1IBlockAccess.getBlockId(par2, par3, par4) == this.blockID)
{
return false;
}
else
{
final int i = par1IBlockAccess.getBlockId(par2, par3, par4);
boolean var6 = false;
@Override
public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
{
if (par1IBlockAccess.getBlockId(par2, par3, par4) == this.blockID)
{
return false;
}
else
{
final int i = par1IBlockAccess.getBlockId(par2, par3, par4);
boolean var6 = false;
if (Block.blocksList[i] != null)
{
var6 = !Block.blocksList[i].isOpaqueCube();
}
if (Block.blocksList[i] != null)
{
var6 = !Block.blocksList[i].isOpaqueCube();
}
final boolean var7 = i == 0;
final boolean var7 = i == 0;
if ((var6 || var7) && par5 == 3 && !var6)
{
return true;
}
else if ((var6 || var7) && par5 == 4 && !var6)
{
return true;
}
else if ((var6 || var7) && par5 == 5 && !var6)
{
return true;
}
else if ((var6 || var7) && par5 == 2 && !var6)
{
return true;
}
else if ((var6 || var7) && par5 == 0 && !var6)
{
return true;
}
else if ((var6 || var7) && par5 == 1 && !var6)
{
return true;
}
else
{
return false;
}
}
}
if ((var6 || var7) && par5 == 3 && !var6)
{
return true;
}
else if ((var6 || var7) && par5 == 4 && !var6)
{
return true;
}
else if ((var6 || var7) && par5 == 5 && !var6)
{
return true;
}
else if ((var6 || var7) && par5 == 2 && !var6)
{
return true;
}
else if ((var6 || var7) && par5 == 0 && !var6)
{
return true;
}
else if ((var6 || var7) && par5 == 1 && !var6)
{
return true;
}
else
{
return false;
}
}
}
private void spreadAirBlock(World worldObj, int x, int y, int z, int concentration)
{
if (concentration <= 0)
{
return;
}
private void spreadAirBlock(World worldObj, int x, int y, int z, int concentration)
{
if (concentration <= 0)
{
return;
}
int mid_concentration;
int block_count = 1;
final int K = 128;
mid_concentration = worldObj.getBlockMetadata(x, y, z) * K;
int mid_concentration;
int block_count = 1;
mid_concentration = worldObj.getBlockMetadata(x, y, z);
if (worldObj.isAirBlock(x + 1, y, z))
{
block_count++;
mid_concentration += worldObj.getBlockMetadata(x + 1, y, z) * K;
}
// Count air in adjacent blocks
if (worldObj.isAirBlock(x + 1, y, z))
{
block_count++;
mid_concentration += worldObj.getBlockMetadata(x + 1, y, z);
}
if (worldObj.isAirBlock(x - 1, y, z))
{
block_count++;
mid_concentration += worldObj.getBlockMetadata(x - 1, y, z) * K;
}
if (worldObj.isAirBlock(x - 1, y, z))
{
block_count++;
mid_concentration += worldObj.getBlockMetadata(x - 1, y, z);
}
if (worldObj.isAirBlock(x, y + 1, z))
{
block_count++;
mid_concentration += worldObj.getBlockMetadata(x, y + 1, z) * K;
}
if (worldObj.isAirBlock(x, y + 1, z))
{
block_count++;
mid_concentration += worldObj.getBlockMetadata(x, y + 1, z);
}
if (worldObj.isAirBlock(x, y - 1, z))
{
block_count++;
mid_concentration += worldObj.getBlockMetadata(x, y - 1, z) * K;
}
if (worldObj.isAirBlock(x, y - 1, z))
{
block_count++;
mid_concentration += worldObj.getBlockMetadata(x, y - 1, z);
}
if (worldObj.isAirBlock(x, y, z + 1))
{
block_count++;
mid_concentration += worldObj.getBlockMetadata(x, y, z + 1) * K;
}
if (worldObj.isAirBlock(x, y, z + 1))
{
block_count++;
mid_concentration += worldObj.getBlockMetadata(x, y, z + 1);
}
if (worldObj.isAirBlock(x, y, z - 1))
{
block_count++;
mid_concentration += worldObj.getBlockMetadata(x, y, z - 1) * K;
}
if (worldObj.isAirBlock(x, y, z - 1))
{
block_count++;
mid_concentration += worldObj.getBlockMetadata(x, y, z - 1);
}
mid_concentration = mid_concentration / block_count;
SetAirBlockConcentration(worldObj, x, y, z, mid_concentration / K);
mid_concentration = (int)Math.floor(mid_concentration / block_count);
setNewAirBlockWithConcentration(worldObj, x, y, z, mid_concentration);
if (worldObj.isAirBlock(x + 1, y, z) && (mid_concentration > worldObj.getBlockMetadata(x + 1, y, z) * K))
{
SetAirBlockConcentration(worldObj, x + 1, y, z, mid_concentration / K);
}
// Check and setup air to adjacent blocks
if (worldObj.isAirBlock(x + 1, y, z) && (mid_concentration > worldObj.getBlockMetadata(x + 1, y, z)))
{
setNewAirBlockWithConcentration(worldObj, x + 1, y, z, mid_concentration);
}
if (worldObj.isAirBlock(x - 1, y, z) && (mid_concentration > worldObj.getBlockMetadata(x - 1, y, z) * K))
{
SetAirBlockConcentration(worldObj, x - 1, y, z, mid_concentration / K);
}
if (worldObj.isAirBlock(x - 1, y, z) && (mid_concentration > worldObj.getBlockMetadata(x - 1, y, z)))
{
setNewAirBlockWithConcentration(worldObj, x - 1, y, z, mid_concentration);
}
if (worldObj.isAirBlock(x, y + 1, z) && (mid_concentration > worldObj.getBlockMetadata(x, y + 1, z) * K))
{
SetAirBlockConcentration(worldObj, x, y + 1, z, mid_concentration / K);
}
if (worldObj.isAirBlock(x, y + 1, z) && (mid_concentration > worldObj.getBlockMetadata(x, y + 1, z)))
{
setNewAirBlockWithConcentration(worldObj, x, y + 1, z, mid_concentration);
}
if (worldObj.isAirBlock(x, y - 1, z) && (mid_concentration > worldObj.getBlockMetadata(x, y - 1, z) * K))
{
SetAirBlockConcentration(worldObj, x, y - 1, z, mid_concentration / K);
}
if (worldObj.isAirBlock(x, y - 1, z) && (mid_concentration > worldObj.getBlockMetadata(x, y - 1, z)))
{
setNewAirBlockWithConcentration(worldObj, x, y - 1, z, mid_concentration);
}
if (worldObj.isAirBlock(x, y, z + 1) && (mid_concentration > worldObj.getBlockMetadata(x, y, z + 1) * K))
{
SetAirBlockConcentration(worldObj, x, y, z + 1, mid_concentration / K);
}
if (worldObj.isAirBlock(x, y, z + 1) && (mid_concentration > worldObj.getBlockMetadata(x, y, z + 1)))
{
setNewAirBlockWithConcentration(worldObj, x, y, z + 1, mid_concentration);
}
if (worldObj.isAirBlock(x, y, z - 1) && (mid_concentration > worldObj.getBlockMetadata(x, y, z - 1) * K))
{
SetAirBlockConcentration(worldObj, x, y, z - 1, mid_concentration / K);
}
}
if (worldObj.isAirBlock(x, y, z - 1) && (mid_concentration > worldObj.getBlockMetadata(x, y, z - 1)))
{
setNewAirBlockWithConcentration(worldObj, x, y, z - 1, mid_concentration);
}
}
private void SetAirBlockConcentration(World worldObj, int x, int y, int z, int concentration)
{
worldObj.setBlock(x, y, z, this.blockID, concentration, 2);
}
private void setNewAirBlockWithConcentration(World worldObj, int x, int y, int z, int concentration)
{
worldObj.setBlock(x, y, z, this.blockID, concentration, 2);
}
@Override
public boolean func_82506_l()
{
return false;
}
@Override
public boolean func_82506_l()
{
return false;
}
/**
* Returns if this block is collidable. Args: x, y, z
*/
@Override
public boolean isCollidable()
{
return false;
}
/**
* Returns if this block is collidable. Args: x, y, z
*/
@Override
public boolean isCollidable()
{
return false;
}
@Override
public void onBlockAdded(World par1World, int par2, int par3, int par4)
{
if (par1World.provider.dimensionId == WarpDrive.instance.spaceDimID || par1World.provider.dimensionId == WarpDrive.instance.hyperSpaceDimID)
{
par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate(par1World));
}
else
{
par1World.setBlockToAir(par2, par3, par4);
}
}
@Override
public void onBlockAdded(World par1World, int par2, int par3, int par4)
{
if (par1World.provider.dimensionId == WarpDrive.instance.spaceDimID || par1World.provider.dimensionId == WarpDrive.instance.hyperSpaceDimID)
{
par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate(par1World));
}
else
{
par1World.setBlockToAir(par2, par3, par4);
}
}
}

View file

@ -0,0 +1,72 @@
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.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
public class BlockCloakingCoil extends Block
{
private Icon[] iconBuffer;
public BlockCloakingCoil(int id, int texture, Material material)
{
super(id, material);
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister)
{
iconBuffer = new Icon[2];
iconBuffer[0] = par1IconRegister.registerIcon("warpdrive:cloakCoilSide");
iconBuffer[1] = par1IconRegister.registerIcon("warpdrive:cloakCoilSideActive");
}
@Override
public Icon getIcon(int side, int metadata)
{
return iconBuffer[metadata];
}
/**
* 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;
}
@Override
public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
{
TileEntity te = par1World.getBlockTileEntity(par2, par3, par4);
if (te != null)
{
te.invalidate();
}
super.breakBlock(par1World, par2, par3, par4, par5, par6);
}
}

View file

@ -0,0 +1,98 @@
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.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
public class BlockCloakingDeviceCore extends BlockContainer
{
private Icon[] iconBuffer;
public BlockCloakingDeviceCore(int id, int texture, Material material)
{
super(id, material);
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister)
{
iconBuffer = new Icon[2];
iconBuffer[0] = par1IconRegister.registerIcon("warpdrive:cloakingCoreInactive");
iconBuffer[1] = par1IconRegister.registerIcon("warpdrive:cloakingCoreActive");
}
@Override
public Icon getIcon(int side, int metadata)
{
return iconBuffer[metadata];
}
@Override
public TileEntity createNewTileEntity(World var1)
{
return new TileEntityCloakingDeviceCore();
}
/**
* 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;
}
@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().isClient())
{
return false;
}
TileEntityCloakingDeviceCore me = (TileEntityCloakingDeviceCore)par1World.getBlockTileEntity(par2, par3, par4);
if (me != null)
{
par5EntityPlayer.addChatMessage("[CloakDeviceCore] Energy level: " + me.getCurrentEnergyValue() + " Eu");
}
return true;
}
@Override
public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
{
TileEntity te = par1World.getBlockTileEntity(par2, par3, par4);
if (te != null)
{
if (((TileEntityCloakingDeviceCore)te).isEnabled)
((TileEntityCloakingDeviceCore)te).disableCloakingField();
te.invalidate();
}
super.breakBlock(par1World, par2, par3, par4, par5, par6);
}
}

View file

@ -46,7 +46,7 @@ public class BlockReactor extends BlockContainer
return iconBuffer[ICON_TOP];
}
if (metadata == 0) // Inactive state
if (metadata == 0) //Inactive state
{
return iconBuffer[ICON_INACTIVE_SIDE];
}

View file

@ -0,0 +1,106 @@
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.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
public class BlockShipScanner extends BlockContainer
{
private Icon[] iconBuffer;
public BlockShipScanner(int id, int texture, Material material)
{
super(id, material);
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister)
{
iconBuffer = new Icon[3];
iconBuffer[0] = par1IconRegister.registerIcon("warpdrive:shipScannerUp");
iconBuffer[1] = par1IconRegister.registerIcon("warpdrive:shipScannerSide");
iconBuffer[2] = par1IconRegister.registerIcon("warpdrive:contBottom");
}
@Override
public Icon getIcon(int side, int metadata)
{
if (side == 1) // UP
{
return iconBuffer[0];
}
else if (side == 0) // DOWN
{
return iconBuffer[2];
}
return iconBuffer[1];
}
@Override
public TileEntity createNewTileEntity(World var1)
{
return new TileEntityShipScanner();
}
/**
* 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.)
*/
@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().isClient())
{
return false;
}
TileEntityShipScanner me = (TileEntityShipScanner)par1World.getBlockTileEntity(par2, par3, par4);
if (me != null)
{
par5EntityPlayer.addChatMessage("[Ship Scanner] Energy level: " + me.getCurrentEnergyValue());
}
return true;
}
@Override
public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
{
TileEntity te = par1World.getBlockTileEntity(par2, par3, par4);
if (te != null)
{
te.invalidate();
}
}
}

View file

@ -0,0 +1,26 @@
package cr0s.WarpDrive;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.packet.Packet56MapChunks;
import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.world.ChunkWatchEvent;
public class CloakChunkWatcher
{
@ForgeSubscribe
public void chunkLoaded(ChunkWatchEvent event)
{
EntityPlayerMP p = event.player;
ChunkCoordIntPair chunk = event.chunk;
ArrayList<CloakedArea> cloaks = WarpDrive.instance.cloaks.getCloaksForPoint(p.worldObj.provider.dimensionId, chunk.getCenterXPos(), 0, chunk.getCenterZPosition(), true);
if (cloaks.size() == 0)
return;
for (CloakedArea area : cloaks)
area.sendCloakPacketToPlayer(p, false);
}
}

View file

@ -0,0 +1,343 @@
package cr0s.WarpDrive;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.FMLNetworkHandler;
import cpw.mods.fml.relauncher.Side;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLeashKnot;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.boss.EntityDragon;
import net.minecraft.entity.item.EntityBoat;
import net.minecraft.entity.item.EntityEnderCrystal;
import net.minecraft.entity.item.EntityEnderEye;
import net.minecraft.entity.item.EntityEnderPearl;
import net.minecraft.entity.item.EntityExpBottle;
import net.minecraft.entity.item.EntityFallingSand;
import net.minecraft.entity.item.EntityFireworkRocket;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.item.EntityItemFrame;
import net.minecraft.entity.item.EntityMinecart;
import net.minecraft.entity.item.EntityPainting;
import net.minecraft.entity.item.EntityTNTPrimed;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.passive.IAnimals;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.entity.projectile.EntityEgg;
import net.minecraft.entity.projectile.EntityFireball;
import net.minecraft.entity.projectile.EntityFishHook;
import net.minecraft.entity.projectile.EntityPotion;
import net.minecraft.entity.projectile.EntitySmallFireball;
import net.minecraft.entity.projectile.EntitySnowball;
import net.minecraft.entity.projectile.EntityWitherSkull;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet20NamedEntitySpawn;
import net.minecraft.network.packet.Packet23VehicleSpawn;
import net.minecraft.network.packet.Packet24MobSpawn;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.network.packet.Packet25EntityPainting;
import net.minecraft.network.packet.Packet26EntityExpOrb;
import net.minecraft.network.packet.Packet56MapChunks;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
/**
* Cloak manager stores cloaking devices covered areas
* @author Cr0s
*
*/
public class CloakManager
{
private ArrayList<CloakedArea> cloaks;
public CloakManager() {
this.cloaks = new ArrayList<CloakedArea>();
}
public boolean isInCloak(int dimensionID, int x, int y, int z, boolean chunk) {
for (int i = 0; i < this.cloaks.size(); i++){
if (this.cloaks.get(i).world == null || this.cloaks.get(i).world.provider.dimensionId != dimensionID)
continue;
AxisAlignedBB axisalignedbb = this.cloaks.get(i).aabb;
if (axisalignedbb.minX <= (double) x && axisalignedbb.maxX >= (double) x && (chunk || (axisalignedbb.minY <= (double) y && axisalignedbb.maxY >= (double) y)) && axisalignedbb.minZ <= (double) z && axisalignedbb.maxZ >= (double) z) {
return true;
}
}
return false;
}
public ArrayList<CloakedArea> getCloaksForPoint(int dimensionID, int x, int y, int z, boolean chunk) {
ArrayList<CloakedArea> res = new ArrayList<CloakedArea>();
for (int i = 0; i < this.cloaks.size(); i++){
if (this.cloaks.get(i).world == null || this.cloaks.get(i).world.provider.dimensionId != dimensionID)
continue;
AxisAlignedBB axisalignedbb = this.cloaks.get(i).aabb;
//System.outprint("[Cloak] checking (" + x + "; " + y + "; " + z + ") -> " + this.cloaks.get(i).aabb);
if (axisalignedbb.minX <= (double) x && axisalignedbb.maxX >= (double) x && (chunk || (axisalignedbb.minY <= (double) y && axisalignedbb.maxY >= (double) y)) && axisalignedbb.minZ <= (double) z && axisalignedbb.maxZ >= (double) z) {
res.add(cloaks.get(i));
//System.outprintln(": YES");
}// else
//System.outprintln(": NO");
}
return res;
}
public boolean isAreaExists(int frequency) {
for (int i = 0; i < this.cloaks.size(); i++){
if (this.cloaks.get(i).frequency == frequency)
return true;
}
return false;
}
public void addCloakedAreaWorld(World worldObj, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, int frequency, byte tier) {
cloaks.add(new CloakedArea(worldObj, frequency, AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ), tier));
}
public void removeCloakedArea(int frequency) {
int index = 0;
for (int i = 0; i < this.cloaks.size(); i++){
if (this.cloaks.get(i).frequency == frequency) {
this.cloaks.get(i).sendCloakPacketToPlayersEx(true); // send info about collapsing cloaking field
index = i;
break;
}
}
cloaks.remove(index);
}
public CloakedArea getCloakedArea(int frequency) {
for (CloakedArea area : this.cloaks) {
if (area.frequency == frequency)
return area;
}
return null;
}
public void playerEnteringCloakedArea(CloakedArea area, EntityPlayer player) {
area.playersInArea.add(player);
revealChunksToPlayer(area, player);
revealEntityToPlayer(area, player);
area.sendCloakPacketToPlayer(player, false);
}
public void revealEntityToPlayer(CloakedArea area, EntityPlayer p) {
List<Entity> list = p.worldObj.getEntitiesWithinAABBExcludingEntity(p, area.aabb);
for (Entity e : list) {
((EntityPlayerMP)p).playerNetServerHandler.sendPacketToPlayer(getPacketForThisEntity(e));
}
}
public void checkPlayerLeavedArea(EntityPlayer p) {
for (CloakedArea area : this.cloaks) {
if (!area.isPlayerWithinArea(p) && area.isPlayerInArea(p)) {
area.removePlayerFromArea(p);
//System.outprintln("[Cloak] Player " + p.username + " has leaved cloaked area " + area.frequency);
MinecraftServer.getServer().getConfigurationManager().sendToAllNearExcept(p, p.posX, p.posY, p.posZ, 100, p.worldObj.provider.dimensionId, getPacketForThisEntity(p));
area.sendCloakPacketToPlayer(p, false);
}
}
}
public void revealChunksToPlayer(CloakedArea area, EntityPlayer p) {
//System.outprintln("[Cloak] Revealing cloaked chunks in area " + area.frequency + " to player " + p.username);
for (int x = (int)area.aabb.minX; x < (int)area.aabb.maxX; x++)
for (int z = (int)area.aabb.minZ; z < (int)area.aabb.maxZ; z++)
for (int y = (int)area.aabb.minY; y < (int)area.aabb.maxY; y++) {
if (p.worldObj.getBlockId(x, y, z) != 0)
p.worldObj.markBlockForUpdate(x, y, z);
}
/*ArrayList<Chunk> chunksToSend = new ArrayList<Chunk>();
for (int x = (int)area.aabb.minX >> 4; x <= (int)area.aabb.maxX >> 4; x++)
for (int z = (int)area.aabb.minZ >> 4; z <= (int)area.aabb.maxZ >> 4; z++) {
chunksToSend.add(p.worldObj.getChunkFromChunkCoords(x, z));
}
//System.outprintln("[Cloak] Sending " + chunksToSend.size() + " chunks to player " + p.username);
((EntityPlayerMP)p).playerNetServerHandler.sendPacketToPlayer(new Packet56MapChunks(chunksToSend));
//System.outprintln("[Cloak] Sending decloak packet to player " + p.username);
area.sendCloakPacketToPlayer(p, true); // decloak = true
*/
}
private Packet getPacketForThisEntity(Entity e)
{
if (e.isDead)
{
e.worldObj.getWorldLogAgent().logWarning("Fetching addPacket for removed entity");
}
Packet pkt = FMLNetworkHandler.getEntitySpawningPacket(e);
if (pkt != null)
{
return pkt;
}
if (e instanceof EntityItem)
{
return new Packet23VehicleSpawn(e, 2, 1);
}
else if (e instanceof EntityPlayerMP)
{
return new Packet20NamedEntitySpawn((EntityPlayer)e);
}
else if (e instanceof EntityMinecart)
{
EntityMinecart entityminecart = (EntityMinecart)e;
return new Packet23VehicleSpawn(e, 10, entityminecart.getMinecartType());
}
else if (e instanceof EntityBoat)
{
return new Packet23VehicleSpawn(e, 1);
}
else if (!(e instanceof IAnimals) && !(e instanceof EntityDragon))
{
if (e instanceof EntityFishHook)
{
EntityPlayer entityplayer = ((EntityFishHook)e).angler;
return new Packet23VehicleSpawn(e, 90, entityplayer != null ? entityplayer.entityId : e.entityId);
}
else if (e instanceof EntityArrow)
{
Entity entity = ((EntityArrow)e).shootingEntity;
return new Packet23VehicleSpawn(e, 60, entity != null ? entity.entityId : e.entityId);
}
else if (e instanceof EntitySnowball)
{
return new Packet23VehicleSpawn(e, 61);
}
else if (e instanceof EntityPotion)
{
return new Packet23VehicleSpawn(e, 73, ((EntityPotion)e).getPotionDamage());
}
else if (e instanceof EntityExpBottle)
{
return new Packet23VehicleSpawn(e, 75);
}
else if (e instanceof EntityEnderPearl)
{
return new Packet23VehicleSpawn(e, 65);
}
else if (e instanceof EntityEnderEye)
{
return new Packet23VehicleSpawn(e, 72);
}
else if (e instanceof EntityFireworkRocket)
{
return new Packet23VehicleSpawn(e, 76);
}
else
{
Packet23VehicleSpawn packet23vehiclespawn;
if (e instanceof EntityFireball)
{
EntityFireball entityfireball = (EntityFireball)e;
packet23vehiclespawn = null;
byte b0 = 63;
if (e instanceof EntitySmallFireball)
{
b0 = 64;
}
else if (e instanceof EntityWitherSkull)
{
b0 = 66;
}
if (entityfireball.shootingEntity != null)
{
packet23vehiclespawn = new Packet23VehicleSpawn(e, b0, ((EntityFireball)e).shootingEntity.entityId);
}
else
{
packet23vehiclespawn = new Packet23VehicleSpawn(e, b0, 0);
}
packet23vehiclespawn.speedX = (int)(entityfireball.accelerationX * 8000.0D);
packet23vehiclespawn.speedY = (int)(entityfireball.accelerationY * 8000.0D);
packet23vehiclespawn.speedZ = (int)(entityfireball.accelerationZ * 8000.0D);
return packet23vehiclespawn;
}
else if (e instanceof EntityEgg)
{
return new Packet23VehicleSpawn(e, 62);
}
else if (e instanceof EntityTNTPrimed)
{
return new Packet23VehicleSpawn(e, 50);
}
else if (e instanceof EntityEnderCrystal)
{
return new Packet23VehicleSpawn(e, 51);
}
else if (e instanceof EntityFallingSand)
{
EntityFallingSand entityfallingsand = (EntityFallingSand)e;
return new Packet23VehicleSpawn(e, 70, entityfallingsand.blockID | entityfallingsand.metadata << 16);
}
else if (e instanceof EntityPainting)
{
return new Packet25EntityPainting((EntityPainting)e);
}
else if (e instanceof EntityItemFrame)
{
EntityItemFrame entityitemframe = (EntityItemFrame)e;
packet23vehiclespawn = new Packet23VehicleSpawn(e, 71, entityitemframe.hangingDirection);
packet23vehiclespawn.xPosition = MathHelper.floor_float((float)(entityitemframe.xPosition * 32));
packet23vehiclespawn.yPosition = MathHelper.floor_float((float)(entityitemframe.yPosition * 32));
packet23vehiclespawn.zPosition = MathHelper.floor_float((float)(entityitemframe.zPosition * 32));
return packet23vehiclespawn;
}
else if (e instanceof EntityLeashKnot)
{
EntityLeashKnot entityleashknot = (EntityLeashKnot)e;
packet23vehiclespawn = new Packet23VehicleSpawn(e, 77);
packet23vehiclespawn.xPosition = MathHelper.floor_float((float)(entityleashknot.xPosition * 32));
packet23vehiclespawn.yPosition = MathHelper.floor_float((float)(entityleashknot.yPosition * 32));
packet23vehiclespawn.zPosition = MathHelper.floor_float((float)(entityleashknot.zPosition * 32));
return packet23vehiclespawn;
}
else if (e instanceof EntityXPOrb)
{
return new Packet26EntityExpOrb((EntityXPOrb)e);
}
else
{
throw new IllegalArgumentException("Don\'t know how to add " + e.getClass() + "!");
}
}
}
else
{
return new Packet24MobSpawn((EntityLivingBase)e);
}
}
}

View file

@ -0,0 +1,206 @@
package cr0s.WarpDrive;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.util.LinkedList;
import java.util.List;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.FMLNetworkHandler;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
public class CloakedArea
{
public int frequency;
public AxisAlignedBB aabb;
public LinkedList<EntityPlayer> playersInArea;
public byte tier = 0;
public World world = null;
public boolean isPlayerInArea(EntityPlayer player) {
for (EntityPlayer p : this.playersInArea) {
//System.outprintln("[Cloak] Checking player: " + p.username + "(" + p.entityId + ")" + " =? " + player.username + " (" + p.entityId + ")");
if (p.username.equals(player.username))
return true;
}
return false;
}
public void removePlayerFromArea(EntityPlayer p) {
for (int i = 0; i < this.playersInArea.size(); i++) {
if (this.playersInArea.get(i).username.equals(p.username)) {
this.playersInArea.remove(i);
return;
}
}
}
public boolean isPlayerWithinArea(EntityPlayer player) {
return (aabb.minX <= player.posX && aabb.maxX >= player.posX && aabb.minY <= player.posY && aabb.maxY >= player.posY && aabb.minZ <= player.posZ && aabb.maxZ >= player.posZ);
}
public CloakedArea(World worldObj, int frequency, AxisAlignedBB aabb, byte tier) {
this.frequency = frequency;
this.aabb = aabb;
this.tier = tier;
this.playersInArea = new LinkedList<EntityPlayer>();
if (worldObj == null || aabb == null)
return;
this.world = worldObj;
if (this.world == null)
return;
try {
// Added all players, who inside the field
List<Entity> list = worldObj.getEntitiesWithinAABB(EntityPlayerMP.class, this.aabb);
for (Entity e : list) {
if (e instanceof EntityPlayer)
this.playersInArea.add((EntityPlayer)e);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public Chunk obscureChunkBlocksWithinArea(Chunk chunk) {
for (int x = (int)this.aabb.minX; x < (int)this.aabb.maxX; x++)
for (int z = (int)this.aabb.minZ; z < (int)this.aabb.maxZ; z++)
for (int y = (int)this.aabb.minY; y < (int)this.aabb.maxY; y++) {
myChunkSBIDWMT(chunk, x & 15, y, z & 15, 0, 0);
}
return chunk;
}
// Sending only if field changes: sets up or collapsing
public void sendCloakPacketToPlayersEx(boolean decloak) {
final int RADIUS = 250;
double midX = this.aabb.minX + (Math.abs(this.aabb.maxX - this.aabb.minX) / 2);
double midY = this.aabb.minY + (Math.abs(this.aabb.maxY - this.aabb.minY) / 2);
double midZ = this.aabb.minZ + (Math.abs(this.aabb.maxZ - this.aabb.minZ) / 2);
for (int j = 0; j < MinecraftServer.getServer().getConfigurationManager().playerEntityList.size(); ++j)
{
EntityPlayerMP entityplayermp = (EntityPlayerMP)MinecraftServer.getServer().getConfigurationManager().playerEntityList.get(j);
if (entityplayermp.dimension == this.world.provider.dimensionId)
{
double d4 = midX - entityplayermp.posX;
double d5 = midY - entityplayermp.posY;
double d6 = midZ - entityplayermp.posZ;
if (d4 * d4 + d5 * d5 + d6 * d6 < RADIUS * RADIUS)
{
if (decloak) {
WarpDrive.instance.cloaks.revealChunksToPlayer(this, (EntityPlayer)entityplayermp);
WarpDrive.instance.cloaks.revealEntityToPlayer(this, (EntityPlayer)entityplayermp);
}
if (!isPlayerWithinArea((EntityPlayer)entityplayermp) && !decloak)
sendCloakPacketToPlayer((EntityPlayer)entityplayermp, false);
else if (decloak) {
sendCloakPacketToPlayer((EntityPlayer)entityplayermp, true);
}
}
}
}
}
public void sendCloakPacketToPlayer(EntityPlayer player, boolean decloak) {
//System.outprintln("[Cloak] Sending cloak packet to player " + player.username);
if (isPlayerInArea(player)) {
//System.outprintln("[Cloak] Player " + player.username + " is inside cloaking field");
return;
}
ByteArrayOutputStream bos = new ByteArrayOutputStream(8);
DataOutputStream outputStream = new DataOutputStream(bos);
try
{
outputStream.writeInt((int) this.aabb.minX);
outputStream.writeInt((int) this.aabb.minY);
outputStream.writeInt((int) this.aabb.minZ);
outputStream.writeInt((int) this.aabb.maxX);
outputStream.writeInt((int) this.aabb.maxY);
outputStream.writeInt((int) this.aabb.maxZ);
outputStream.writeBoolean(decloak);
outputStream.writeByte(this.tier);
}
catch (Exception ex)
{
ex.printStackTrace();
}
Packet250CustomPayload packet = new Packet250CustomPayload();
packet.channel = "WarpDriveCloaks";
packet.data = bos.toByteArray();
packet.length = bos.size();
((EntityPlayerMP)player).playerNetServerHandler.sendPacketToPlayer(packet);
}
public boolean myChunkSBIDWMT(Chunk c, int x, int y, int z, int blockId, int blockMeta)
{
int j1 = z << 4 | x;
if (y >= c.precipitationHeightMap[j1] - 1)
{
c.precipitationHeightMap[j1] = -999;
}
int l1 = c.getBlockID(x, y, z);
int i2 = c.getBlockMetadata(x, y, z);
if (l1 == blockId && i2 == blockMeta)
{
return false;
}
else
{
ExtendedBlockStorage[] storageArrays = c.getBlockStorageArray();
ExtendedBlockStorage extendedblockstorage = storageArrays[y >> 4];
if (extendedblockstorage == null)
{
if (blockId == 0)
{
return false;
}
extendedblockstorage = storageArrays[y >> 4] = new ExtendedBlockStorage(y >> 4 << 4, !c.worldObj.provider.hasNoSky);
}
int j2 = c.xPosition * 16 + x;
int k2 = c.zPosition * 16 + z;
extendedblockstorage.setExtBlockID(x, y & 15, z, blockId);
if (extendedblockstorage.getExtBlockID(x, y & 15, z) != blockId)
{
return false;
}
else
{
extendedblockstorage.setExtBlockMetadata(x, y & 15, z, blockMeta);
c.isModified = true;
return true;
}
}
}
}

View file

@ -384,7 +384,6 @@ public class EntityJump extends Entity
moveY = movementVector[1] * distance;
moveZ = movementVector[2] * distance;
// Нужно не упереться в пол мира и потолок космоса
if ((maxY + moveY) > 255)
{
moveY = 255 - maxY;
@ -654,9 +653,6 @@ public class EntityJump extends Entity
return testDistance;
}
/*
* Получить реальное количество блоков, из которых состоит корабль
*/
public int getRealShipSize()
{
LocalProfiler.start("EntityJump.getRealShipSize");
@ -706,19 +702,10 @@ public class EntityJump extends Entity
Entity entity = (Entity)o;
MovingEntity movingEntity = new MovingEntity(entity);
// Добавим в список Entity
entitiesOnShip.add(movingEntity);
}
}
/**
* Перемещение сущностей вместе с кораблем
* @param axisalignedbb область корабля
* @param distance расстояние перемещения
* @param direction направление перемещения
* @param restorePositions восстановление старых позиций для предотвращения выпадения, либо перемещение на новую
* @return
*/
public boolean moveEntities(boolean restorePositions)
{
System.out.println("[JE] Moving entities");
@ -779,7 +766,6 @@ public class EntityJump extends Entity
if (entity instanceof EntityPlayerMP)
{
EntityPlayerMP player = (EntityPlayerMP) entity;
// Если на корабле есть кровать, то передвинуть точку спауна игрока
ChunkCoordinates bedLocation = player.getBedLocation();
if (bedLocation != null && testBB(axisalignedbb, bedLocation.posX, bedLocation.posY, bedLocation.posZ))
@ -802,15 +788,11 @@ public class EntityJump extends Entity
return true;
}
/**
* Проверка на вхождение точки в область (bounding-box)
*/
public boolean testBB(AxisAlignedBB axisalignedbb, int x, int y, int z)
{
return axisalignedbb.minX <= (double) x && axisalignedbb.maxX >= (double) x && axisalignedbb.minY <= (double) y && axisalignedbb.maxY >= (double) y && axisalignedbb.minZ <= (double) z && axisalignedbb.maxZ >= (double) z;
}
// Получение вектора в зависимости от направления прыжка
public int[] getVector(int i)
{
int v[] =
@ -851,13 +833,6 @@ public class EntityJump extends Entity
return v;
}
/**
* Проверка возможности установки корабля в месте, удалённом от корабля на
* определённом расстоянии в сторону прыжка
*
* @param i
* @return true, если корабль уместился на новом месте
*/
public boolean checkMovement(int testDistance)
{
if ((dir == -1 && maxY + testDistance > 255) && !toSpace)
@ -919,23 +894,11 @@ public class EntityJump extends Entity
return true;
}
/**
* Точка находится в варп-поле корабля?
*
* @param x
* @param y
* @param z
* @return true, если находится
*/
public boolean isBlockInShip(int x, int y, int z)
{
return x >= minX && x <= maxX && y >= minY && y <= maxY && z >= minZ && z <= maxZ;
}
/**
* Выключение модема, если периферийное устройство является модемом
* @param p - периферийное устройство
*/
private void turnOffModem(IPeripheral p)
{
// FIXME
@ -954,9 +917,6 @@ public class EntityJump extends Entity
}*/
}
/**
* Выключение всех модемов на корабле
*/
private void turnOffModems()
{
// FIXME
@ -1109,7 +1069,7 @@ public class EntityJump extends Entity
//System.out.println("[JE@"+this+"] writeEntityToNBT()");
}
// Own implementation of setting blocks withow light recalculation in optimization purposes
// Own implementation of setting blocks without light recalculation in optimization purposes
public boolean mySetBlock(World w, int x, int y, int z, int blockId, int blockMeta, int par6)
{
if (x >= -30000000 && z >= -30000000 && x < 30000000 && z < 30000000)

View file

@ -3,165 +3,285 @@ package cr0s.WarpDrive;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.ChunkPosition;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.Player;
import net.minecraft.client.multiplayer.WorldClient;
public class PacketHandler implements IPacketHandler
{
@Override
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player)
{
if (packet.channel.equals("WarpDriveBeam"))
{
handleBeam(packet, (EntityPlayer)player);
}
else if (packet.channel.equals("WarpDriveFreq"))
{
handleFreqUpdate(packet, (EntityPlayer)player);
}
else if (packet.channel.equals("WarpDriveLaserT"))
{
handleLaserTargeting(packet, (EntityPlayer)player);
}
}
@Override
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player)
{
if (packet.channel.equals("WarpDriveBeam"))
{
handleBeam(packet, (EntityPlayer)player);
}
else if (packet.channel.equals("WarpDriveFreq"))
{
handleFreqUpdate(packet, (EntityPlayer)player);
}
else if (packet.channel.equals("WarpDriveLaserT"))
{
handleLaserTargeting(packet, (EntityPlayer)player);
}
else if (packet.channel.equals("WarpDriveCloaks"))
{
handleCloak(packet, (EntityPlayer)player);
}
}
public void handleLaserTargeting(Packet250CustomPayload packet, EntityPlayer player)
{
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
public void handleCloak(Packet250CustomPayload packet, EntityPlayer player) {
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
try
{
int x = inputStream.readInt();
int y = inputStream.readInt();
int z = inputStream.readInt();
float yaw = inputStream.readFloat();
float pitch = inputStream.readFloat();
System.out.println("Got target packet: (" + x + "; " + y + "; " + z + ") | yaw: " + yaw + " | pitch: " + pitch);
TileEntity te = player.worldObj.getBlockTileEntity(x, y, z);
try
{
// Read cloaked area parameters
int minX = inputStream.readInt();
int minY = inputStream.readInt();
int minZ = inputStream.readInt();
int maxX = inputStream.readInt();
int maxY = inputStream.readInt();
int maxZ = inputStream.readInt();
boolean decloak = inputStream.readBoolean();
byte tier = inputStream.readByte();
int w = Math.abs(maxX - minX);
int h = Math.abs(maxY - minY);
int l = Math.abs(maxZ - minZ);
//(-2099; 208; 423) -> (-2069; 243; 453)
//
int size = w * h * l;
//System.out.println("[Cloak Packet] Received " + ((decloak) ? "DEcloaked" : "cloaked") + "area: (" + minX + "; " + minY + "; " + minZ + ") -> (" + maxX + "; " + maxY + "; " + maxZ + ")");
if (minX <= player.chunkCoordX && maxX >= player.chunkCoordY && minY <= player.chunkCoordY && maxY >= player.chunkCoordY && minZ <= player.chunkCoordZ && maxZ >= player.chunkCoordZ)
return;
// Hide the area
if (!decloak)
{
//System.out.println("[Cloak Packet] Removing " + size + " blocks...");
// Now hide the blocks within area
World worldObj = player.worldObj;
for (int y = minY; y <= maxY; y++)
for (int x = minX; x <= maxX; x++)
for(int z = minZ; z <= maxZ; z++)
if (worldObj.getBlockId(x, y, z) != 0)
worldObj.setBlock(x, y, z, (tier == 1) ? WarpDriveConfig.i.gasID : 0, 5, 4);
//System.out.println("[Cloak Packet] Removing entity...");
// Hide any entities inside area
AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
List<Entity> list = worldObj.getEntitiesWithinAABBExcludingEntity(player, aabb);
for (Entity e : list)
{
worldObj.removeEntity(e);
((WorldClient)worldObj).removeEntityFromWorld(e.entityId);
}
}
else
{ // reveal the area
player.worldObj.markBlockRangeForRenderUpdate(minX, minY, minZ, maxX, maxY, maxZ);
// Make some graphics
int numLasers = 25 + player.worldObj.rand.nextInt(300);
for (int i = 0; i < numLasers; i++)
{
int randX1 = minX + player.worldObj.rand.nextInt(maxX - minX);
int randX2 = minX + player.worldObj.rand.nextInt(maxX - minX);
int randY1 = minY + player.worldObj.rand.nextInt(maxY - minY);
int randY2 = minY + player.worldObj.rand.nextInt(maxY - minY);
int randZ1 = minZ + player.worldObj.rand.nextInt(maxZ - minZ);
int randZ2 = minZ + player.worldObj.rand.nextInt(maxZ - minZ);
float r = 0, g = 0, b = 0;
switch (player.worldObj.rand.nextInt(6))
{
case 0:
r = 1.0f;
g = b = 0;
break;
case 1:
r = b = 0;
g = 1.0f;
break;
case 2:
r = g = 0;
b = 1.0f;
break;
case 3:
r = b = 0.5f;
g = 0;
break;
case 4:
r = g = 1.0f;
b = 0;
break;
case 5:
r = 1.0f;
b = 0.5f;
g = 0f;
}
WarpDrive.proxy.renderBeam(player.worldObj, new Vector3(randX1, randY1, randZ1), new Vector3(randX2, randY2, randZ2), r, g, b, 10, 100);
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void handleLaserTargeting(Packet250CustomPayload packet, EntityPlayer player)
{
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
if (te != null)
{
System.out.println("TE is NULL");
try
{
int x = inputStream.readInt();
int y = inputStream.readInt();
int z = inputStream.readInt();
float yaw = inputStream.readFloat();
float pitch = inputStream.readFloat();
System.out.println("Got target packet: (" + x + "; " + y + "; " + z + ") | yaw: " + yaw + " | pitch: " + pitch);
TileEntity te = player.worldObj.getBlockTileEntity(x, y, z);
if (te instanceof TileEntityLaser)
{
TileEntityLaser l = (TileEntityLaser)te;
l.yaw = yaw;
l.pitch = pitch;
l.delayTicks = 0;
l.isEmitting = true;
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
if (te != null)
{
System.out.println("TE is NULL");
public void handleFreqUpdate(Packet250CustomPayload packet, EntityPlayer player)
{
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
if (te instanceof TileEntityLaser)
{
TileEntityLaser l = (TileEntityLaser)te;
l.yaw = yaw;
l.pitch = pitch;
l.delayTicks = 0;
l.isEmitting = true;
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
try
{
int x = inputStream.readInt();
int y = inputStream.readInt();
int z = inputStream.readInt();
int freq = inputStream.readInt();
//System.out.println("Got freq packet: (" + x + "; " + y + "; " + z + ") | freq: " + freq);
TileEntity te = player.worldObj.getBlockTileEntity(x, y, z);
public void handleFreqUpdate(Packet250CustomPayload packet, EntityPlayer player)
{
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
if (te != null)
{
if (te instanceof TileEntityMonitor)
{
((TileEntityMonitor)te).setFrequency(freq);
}
else if (te instanceof TileEntityCamera)
{
((TileEntityCamera)te).setFrequency(freq);
WarpDrive.instance.cams.updateInRegistry(new CamRegistryItem(freq, new ChunkPosition(x, y, z), player.worldObj).setType(0));
}
else if (te instanceof TileEntityLaser)
{
((TileEntityLaser)te).camFreq = freq;
WarpDrive.instance.cams.updateInRegistry(new CamRegistryItem(freq, new ChunkPosition(x, y, z), player.worldObj).setType(1));
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
try
{
int x = inputStream.readInt();
int y = inputStream.readInt();
int z = inputStream.readInt();
int freq = inputStream.readInt();
//System.out.println("Got freq packet: (" + x + "; " + y + "; " + z + ") | freq: " + freq);
TileEntity te = player.worldObj.getBlockTileEntity(x, y, z);
private void handleBeam(Packet250CustomPayload packet, EntityPlayer player)
{
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
int dimID;
Vector3 source, target;
double sx, sy, sz;
double tx, ty, tz;
float r, g, b;
int age;
int energy;
World worldObj = player.worldObj;
if (te != null)
{
if (te instanceof TileEntityMonitor)
{
((TileEntityMonitor)te).setFrequency(freq);
}
else if (te instanceof TileEntityCamera)
{
((TileEntityCamera)te).setFrequency(freq);
WarpDrive.instance.cams.updateInRegistry(new CamRegistryItem(freq, new ChunkPosition(x, y, z), player.worldObj).setType(0));
}
else if (te instanceof TileEntityLaser)
{
((TileEntityLaser)te).camFreq = freq;
WarpDrive.instance.cams.updateInRegistry(new CamRegistryItem(freq, new ChunkPosition(x, y, z), player.worldObj).setType(1));
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
try
{
// Read source vector
sx = inputStream.readDouble();
sy = inputStream.readDouble();
sz = inputStream.readDouble();
source = new Vector3(sx, sy, sz);
// Read target vector
tx = inputStream.readDouble();
ty = inputStream.readDouble();
tz = inputStream.readDouble();
target = new Vector3(tx, ty, tz);
// Read r, g, b of laser
r = inputStream.readFloat();
g = inputStream.readFloat();
b = inputStream.readFloat();
// Read age
age = inputStream.readByte();
// Read energy value
energy = inputStream.readInt();
private void handleBeam(Packet250CustomPayload packet, EntityPlayer player)
{
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
int dimID;
Vector3 source, target;
double sx, sy, sz;
double tx, ty, tz;
float r, g, b;
int age;
int energy;
World worldObj = player.worldObj;
// Render beam
/*System.out.println("sx: " + sx + " sy: " + sy + " sz: " + sz);
System.out.println("tx: " + sx + " ty: " + sy + " tz: " + sz);
try
{
// Read source vector
sx = inputStream.readDouble();
sy = inputStream.readDouble();
sz = inputStream.readDouble();
source = new Vector3(sx, sy, sz);
// Read target vector
tx = inputStream.readDouble();
ty = inputStream.readDouble();
tz = inputStream.readDouble();
target = new Vector3(tx, ty, tz);
// Read r, g, b of laser
r = inputStream.readFloat();
g = inputStream.readFloat();
b = inputStream.readFloat();
// Read age
age = inputStream.readByte();
// Read energy value
energy = inputStream.readInt();
System.out.println("source: " + source);
System.out.println("target: " + target);
System.out.println("r: " + r);
System.out.println("g: " + g);
System.out.println("b " + b);
System.out.println("age: " + age);
System.out.println("energy: " + energy);*/
// Render beam
/*System.out.println("sx: " + sx + " sy: " + sy + " sz: " + sz);
System.out.println("tx: " + sx + " ty: " + sy + " tz: " + sz);
// To avoid NPE at logging in
if (worldObj == null)
{
System.out.println("WorldObj is null");
return;
}
System.out.println("source: " + source);
System.out.println("target: " + target);
System.out.println("r: " + r);
System.out.println("g: " + g);
System.out.println("b " + b);
System.out.println("age: " + age);
System.out.println("energy: " + energy);*/
WarpDrive.proxy.renderBeam(worldObj, source.clone(), target.clone(), r, g, b, age, energy);
}
catch (IOException e)
{
e.printStackTrace();
return;
}
}
// To avoid NPE at logging in
if (worldObj == null)
{
System.out.println("WorldObj is null");
return;
}
WarpDrive.proxy.renderBeam(worldObj, source.clone(), target.clone(), r, g, b, age, energy);
}
catch (IOException e)
{
e.printStackTrace();
return;
}
}
}

View file

@ -1,6 +1,7 @@
package cr0s.WarpDrive;
import java.util.HashMap;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
@ -19,10 +20,16 @@ import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
public class SpaceEventHandler
{
private HashMap<String, Integer> vacuumPlayers;
private HashMap<String, Integer> cloakPlayersTimers;
private long lastTimer = 0;
private final int CLOAK_CHECK_TIMEOUT_SEC = 5;
public SpaceEventHandler()
{
vacuumPlayers = new HashMap<String, Integer>();
cloakPlayersTimers = new HashMap<String, Integer>();
this.lastTimer = 0;
}
@ForgeSubscribe
@ -43,8 +50,10 @@ public class SpaceEventHandler
entity.attackEntityFrom(DamageSource.outOfWorld, 9000);
return;
}
if (entity instanceof EntityPlayerMP)
updatePlayerCloakState(entity);
// Обновление происходит в космическом или гипер пространстве
// If player in vaccum, check and start consuming air cells
if (entity.worldObj.provider.dimensionId == WarpDrive.instance.spaceDimID || entity.worldObj.provider.dimensionId == WarpDrive.instance.hyperSpaceDimID)
{
boolean inVacuum = isEntityInVacuum(entity);
@ -87,7 +96,7 @@ public class SpaceEventHandler
entity.attackEntityFrom(DamageSource.drown, 1);
}
// Отправить назад на Землю
// If player falling down, teleport on earth
if (entity.posY < -10.0D)
{
((EntityPlayerMP)entity).mcServer.getConfigurationManager().transferPlayerToDimension(((EntityPlayerMP) entity), 0, new SpaceTeleporter(DimensionManager.getWorld(WarpDrive.instance.spaceDimID), 0, MathHelper.floor_double(entity.posX), 250, MathHelper.floor_double(entity.posZ)));
@ -103,6 +112,57 @@ public class SpaceEventHandler
}
}
private void updatePlayerCloakState(EntityLivingBase entity)
{
// Make sure for elapsed time is second after last update
if (System.currentTimeMillis() - this.lastTimer > 1000)
lastTimer = System.currentTimeMillis();
else
return;
try {
EntityPlayerMP p = (EntityPlayerMP)entity;
Integer cloakTicks = this.cloakPlayersTimers.get(p.username);
if (cloakTicks == null)
{
this.cloakPlayersTimers.remove(p.username);
this.cloakPlayersTimers.put(p.username, 0);
return;
}
if (cloakTicks >= CLOAK_CHECK_TIMEOUT_SEC)
{
this.cloakPlayersTimers.remove(p.username);
this.cloakPlayersTimers.put(p.username, 0);
List<CloakedArea> cloaks = WarpDrive.instance.cloaks.getCloaksForPoint(p.worldObj.provider.dimensionId, MathHelper.floor_double(p.posX), MathHelper.floor_double(p.posY), MathHelper.floor_double(p.posZ), false);
if (cloaks.size() != 0)
{
//System.out.println("[Cloak] Player inside " + cloaks.size() + " cloaked areas");
for (CloakedArea area : cloaks)
{
//System.out.println("[Cloak] Frequency: " + area.frequency + ". In: " + area.isPlayerInArea(p) + ", W: " + area.isPlayerWithinArea(p));
if (!area.isPlayerInArea(p) && area.isPlayerWithinArea(p))
{
WarpDrive.instance.cloaks.playerEnteringCloakedArea(area, p);
}
}
} else
{
//System.out.println("[Cloak] Player is not inside any cloak fields. Check, which field player may left...");
WarpDrive.instance.cloaks.checkPlayerLeavedArea(p);
}
}
else
{
this.cloakPlayersTimers.remove(p.username);
this.cloakPlayersTimers.put(p.username, cloakTicks + 1);
}
} catch (Exception e) { e.printStackTrace(); }
}
private void setPlayerAirValue(EntityLivingBase entity, Integer air)
{
vacuumPlayers.remove(((EntityPlayerMP)entity).username);

View file

@ -18,7 +18,7 @@ public class TileEntityAirGenerator extends TileEntity implements IEnergySink
private int currentEnergyValue = 0;
private int cooldownTicks = 0;
private final float AIR_POLLUTION_INTERVAL = 10;
private final float AIR_POLLUTION_INTERVAL = 4; // seconds
private final int START_CONCENTRATION_VALUE = 15;
@ -44,7 +44,7 @@ public class TileEntityAirGenerator extends TileEntity implements IEnergySink
if (addedToEnergyNet && currentEnergyValue > EU_PER_AIRBLOCK)
{
if (cooldownTicks++ > AIR_POLLUTION_INTERVAL)
if (cooldownTicks++ > AIR_POLLUTION_INTERVAL * 20)
{
cooldownTicks = 0;
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 1, 2); // set enabled texture

View file

@ -0,0 +1,484 @@
package cr0s.WarpDrive;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.ILuaContext;
import dan200.computer.api.IPeripheral;
import net.minecraftforge.common.ForgeDirection;
import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.event.EnergyTileUnloadEvent;
import ic2.api.energy.tile.IEnergySink;
import ic2.api.energy.tile.IEnergyTile;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.server.MinecraftServer;
import net.minecraft.src.ModLoader;
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.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import net.minecraftforge.common.MinecraftForge;
import net.minecraft.entity.player.EntityPlayerMP;
public class TileEntityCloakingDeviceCore extends TileEntity implements IEnergySink,
IPeripheral {
public boolean addedToEnergyNet = false;
private final int MAX_ENERGY_VALUE = 500000000; // 500kk eU
private int currentEnergyValue = 0;
private String[] methodsArray = { "setFieldTier", // 0 setFieldTier(1 or 2)
"isAssemblyValid", // 1 - returns true or false
"getEnergyLevel", // 2
"enableCloakingField", // 3 enables field if assembled right
"disableCloakingField", // 4 disables cloaking field
"setFieldFrequency" // 5 setFieldFrequency(int)
};
public boolean isEnabled = false;
public byte tier = 1; // cloaking field tier, 1 or 2
public int frequency = 0;
// Spatial cloaking field parameters
public int front, back, up, down, left, right;
public int minX = 0, minY = 0, minZ = 0, maxX = 0, maxY = 0, maxZ = 0;
private int updateTicks = 0;
private int laserDrawingTicks = 0;
@Override
public void updateEntity() {
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
return;
}
if (!addedToEnergyNet && !this.tileEntityInvalid) {
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
addedToEnergyNet = true;
}
if (--this.updateTicks <= 0) {
//System.out.println("[CloakDev] Updating cloaking state...");
this.updateTicks = ((this.tier == 1) ? 20 : (tier == 2) ? 10 : 20) * WarpDriveConfig.i.CD_FIELD_REFRESH_INTERVAL_SECONDS; // resetting timer
if (validateAssembly() && isEnabled) {
// Consume power for sustaining cloaking field
countBlocksAndConsumeEnergy();
if (currentEnergyValue >= 0) {
if (!WarpDrive.instance.cloaks.isAreaExists(this.frequency)) {
WarpDrive.instance.cloaks.addCloakedAreaWorld(worldObj, minX, minY, minZ, maxX, maxY, maxZ, frequency, tier);
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 1, 2);
worldObj.playSoundEffect(xCoord + 0.5f, yCoord + 0.5f, zCoord + 0.5f, "warpdrive:cloak", 4F, 1F);
// Enable coils
setCoilsState(true);
} else {
// Refresh the field
CloakedArea area = WarpDrive.instance.cloaks.getCloakedArea(frequency);
if (area != null)
area.sendCloakPacketToPlayersEx(false); // recloak field
}
} else {
System.out.println("[CloakDev] Low power, cloak field collapsing...");
currentEnergyValue = 0;
setCoilsState(false);
disableCloakingField();
}
} else if (!validateAssembly() && isEnabled) {
System.out.println("[CloakDev] Device lost coils, field collapsing");
currentEnergyValue = 0;
setCoilsState(false);
disableCloakingField();
}
}
if (laserDrawingTicks++ > 100) {
laserDrawingTicks = 0;
if (isEnabled)
drawLasers();
}
}
public void setCoilsState(boolean enabled) {
final int START_LENGTH = 2; // Step length from core block to main coils
// Directions to check (all six directions: left, right, up, down, front, back)
byte[] dx = { 1, -1, 0, 0, 0, 0 };
byte[] dy = { 0, 0, -1, 1, 0, 0 };
byte[] dz = { 0, 0, 0, 0, -1, 1 };
for (int i = 0; i < 6; i++)
searchCoilInDirectionAndSetState(dx[i], dy[i], dz[i], enabled);
}
public void searchCoilInDirectionAndSetState(byte dx, byte dy, byte dz, boolean state) {
for (int i = 0; i < WarpDriveConfig.i.CD_MAX_CLOAKING_FIELD_SIDE; i++) {
if (worldObj.getBlockId(xCoord + i * dx, yCoord + i * dy, zCoord + i * dz) == WarpDriveConfig.i.cloakCoilID)
worldObj.setBlockMetadataWithNotify(xCoord + i * dx, yCoord + i * dy, zCoord + i * dz, (state) ? 1 : 0, 2);
}
}
public void searchCoilInDirectionAndDrawLaser(byte dx, byte dy, byte dz) {
final int START_LENGTH = 2;
float r = 0.0f, g = 1.0f, b = 0;
if (this.tier == 1) {
r = 0.0f; g = 1.0f;
} else if (this.tier == 2) {
r = 1.0f; g = 0.0f;
}
for (int i = START_LENGTH + 1; i < WarpDriveConfig.i.CD_MAX_CLOAKING_FIELD_SIDE; i++) {
if (worldObj.getBlockId(xCoord + i * dx, yCoord + i * dy, zCoord + i * dz) == WarpDriveConfig.i.cloakCoilID)
sendLaserPacket(new Vector3(this).add(0.5), new Vector3(xCoord + i * dx, yCoord + i * dy, zCoord + i * dz).add(0.5), r, g, b, 110, 0, 100);
}
}
public void drawLasers() {
final int START_LENGTH = 2;
float r = 0.0f, g = 1.0f, b = 0;
if (this.tier == 1) {
r = 0.0f; g = 1.0f;
} else if (this.tier == 2) {
r = 1.0f; g = 0.0f;
}
// Directions to check (all six directions: left, right, up, down, front, back)
byte[] dx = { 1, -1, 0, 0, 0, 0 };
byte[] dy = { 0, 0, -1, 1, 0, 0 };
byte[] dz = { 0, 0, 0, 0, -1, 1 };
for (int k = 0; k < 6; k++)
searchCoilInDirectionAndDrawLaser(dx[k], dy[k], dz[k]);
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 6; j++) {
switch (worldObj.rand.nextInt(6)) {
case 0:
r = 1.0f;
g = b = 0;
break;
case 1:
r = b = 0;
g = 1.0f;
break;
case 2:
r = g = 0;
b = 1.0f;
break;
case 3:
r = b = 0.5f;
g = 0;
break;
case 4:
r = g = 1.0f;
b = 0;
break;
case 5:
r = 1.0f;
b = 0.5f;
g = 0f;
}
sendLaserPacket(new Vector3(xCoord + START_LENGTH * dx[i], yCoord + START_LENGTH * dy[i], zCoord + START_LENGTH * dz[i]).add(0.5), new Vector3(xCoord + START_LENGTH * dx[j], yCoord + START_LENGTH * dy[j], zCoord + START_LENGTH * dz[j]).add(0.5), r, g, b, 110, 0, 100);
}
}
}
public void disableCloakingField() {
this.isEnabled = false;
if (WarpDrive.instance.cloaks.isAreaExists(this.frequency))
WarpDrive.instance.cloaks.removeCloakedArea(this.frequency);
worldObj.playSoundEffect(xCoord + 0.5f, yCoord + 0.5f, zCoord + 0.5f, "warpdrive:decloak", 4F, 1F);
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 2);
}
public void countBlocksAndConsumeEnergy() {
int blocksCount = 0;
for (int y = minY; y <= maxY; y++)
for (int x = minX; x <= maxX; x++)
for(int z = minZ; z <= maxZ; z++)
if (worldObj.getBlockId(x, y, z) != 0)
blocksCount++;
int energyToConsume = blocksCount * ((this.tier == 1) ? WarpDriveConfig.i.CD_ENERGY_PER_BLOCK_TIER1 : WarpDriveConfig.i.CD_ENERGY_PER_BLOCK_TIER2);
//System.out.println("[CloakDev] Consuming " + energyToConsume + " eU for " + blocksCount + " blocks");
this.currentEnergyValue -= energyToConsume;
}
public void sendLaserPacket(Vector3 source, Vector3 dest, float r, float g, float b, int age, int energy, int radius) {
Side side = FMLCommonHandler.instance().getEffectiveSide();
if (side == Side.SERVER) {
ByteArrayOutputStream bos = new ByteArrayOutputStream(8);
DataOutputStream outputStream = new DataOutputStream(bos);
try {
// Write source vector
outputStream.writeDouble(source.x);
outputStream.writeDouble(source.y);
outputStream.writeDouble(source.z);
// Write target vector
outputStream.writeDouble(dest.x);
outputStream.writeDouble(dest.y);
outputStream.writeDouble(dest.z);
// Write r, g, b of laser
outputStream.writeFloat(r);
outputStream.writeFloat(g);
outputStream.writeFloat(b);
// Write age
outputStream.writeByte(age);
// Write energy value
outputStream.writeInt(energy);
} catch (Exception ex) {
ex.printStackTrace();
}
Packet250CustomPayload packet = new Packet250CustomPayload();
packet.channel = "WarpDriveBeam";
packet.data = bos.toByteArray();
packet.length = bos.size();
// Send packet to all players within cloaked area
List<Entity> list = worldObj.getEntitiesWithinAABB(EntityPlayerMP.class, AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ));
for (Entity e : list) {
if (e != null && e instanceof EntityPlayer) {
((EntityPlayerMP)e).playerNetServerHandler.sendPacketToPlayer(packet);
}
}
}
}
@Override
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
this.currentEnergyValue = tag.getInteger("energy");
this.tier = tag.getByte("tier");
this.frequency = tag.getInteger("frequency");
this.isEnabled = tag.getBoolean("enabled");
}
@Override
public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
tag.setInteger("energy", this.getCurrentEnergyValue());
tag.setByte("tier", this.tier);
tag.setInteger("frequency", this.frequency);
tag.setBoolean("enabled", this.isEnabled);
}
public int searchCoilInDirection(byte dx, byte dy, byte dz) {
for (int i = 3; i < WarpDriveConfig.i.CD_MAX_CLOAKING_FIELD_SIDE; i++) {
if (worldObj.getBlockId(xCoord + i * dx, yCoord + i * dy, zCoord + i * dz) == WarpDriveConfig.i.cloakCoilID)
return i;
}
return 0;
}
public boolean validateAssembly() {
final int START_LENGTH = 2; // Step length from core block to main coils
// Directions to check (all six directions: left, right, up, down, front, back)
byte[] dx = { 1, -1, 0, 0, 0, 0 };
byte[] dy = { 0, 0, -1, 1, 0, 0 };
byte[] dz = { 0, 0, 0, 0, -1, 1 };
for (int i = 0; i < 6; i++)
if (worldObj.getBlockId(xCoord + START_LENGTH * dx[i], yCoord + START_LENGTH * dy[i], zCoord + START_LENGTH * dz[i]) != WarpDriveConfig.i.cloakCoilID)
return false;
// Check cloaking field parameters defining coils
this.left = searchCoilInDirection((byte)1, (byte)0, (byte)0) + WarpDriveConfig.i.CD_COIL_CAPTURE_BLOCKS;
if (this.left == WarpDriveConfig.i.CD_COIL_CAPTURE_BLOCKS) return false;
this.right = searchCoilInDirection((byte)-1, (byte)0, (byte)0) + WarpDriveConfig.i.CD_COIL_CAPTURE_BLOCKS;
if (this.right == WarpDriveConfig.i.CD_COIL_CAPTURE_BLOCKS) return false;
this.up = searchCoilInDirection((byte)0, (byte)1, (byte)0) + WarpDriveConfig.i.CD_COIL_CAPTURE_BLOCKS;
if (this.up == WarpDriveConfig.i.CD_COIL_CAPTURE_BLOCKS) return false;
this.down = searchCoilInDirection((byte)0, (byte)-1, (byte)0) + WarpDriveConfig.i.CD_COIL_CAPTURE_BLOCKS;
if (this.down == WarpDriveConfig.i.CD_COIL_CAPTURE_BLOCKS) return false;
this.front = searchCoilInDirection((byte)0, (byte)0, (byte)1) + WarpDriveConfig.i.CD_COIL_CAPTURE_BLOCKS;
if (this.front == WarpDriveConfig.i.CD_COIL_CAPTURE_BLOCKS) return false;
this.back = searchCoilInDirection((byte)0, (byte)0, (byte)-1) + WarpDriveConfig.i.CD_COIL_CAPTURE_BLOCKS;
if (this.back == WarpDriveConfig.i.CD_COIL_CAPTURE_BLOCKS) return false;
int x1 = 0, x2 = 0, z1 = 0, z2 = 0;
z1 = zCoord - this.back;
z2 = zCoord + this.front;
x1 = xCoord - this.right;
x2 = xCoord + this.left;
if (x1 < x2) {
this.minX = x1;this. maxX = x2;
}
else {
this.minX = x2; this.maxX = x1;
}
if (z1 < z2) {
this.minZ = z1; this.maxZ = z2;
}
else {
this.minZ = z2; this.maxZ = z1;
}
this.minY = yCoord - this.down;
this.maxY = yCoord + this.up;
return true;
}
// CC
// IPeripheral methods implementation
@Override
public String getType() {
return "cloakingdevicecore";
}
@Override
public String[] getMethodNames() {
return methodsArray;
}
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context,
int method, Object[] arguments) throws Exception {
switch (method) {
case 0: // setFieldTier(1 or 2)
if (arguments.length == 1) {
this.tier = ((Double)arguments[0]).byteValue();
}
break;
case 1: // isAssemblyValid()
return new Object[] { (boolean)validateAssembly() };
case 2: // getEnergyLevel()
return new Object[] { currentEnergyValue };
case 3: // enableCloakingField()
this.isEnabled = true;
break;
case 4: // disableCloakingField()
disableCloakingField();
setCoilsState(false);
break;
case 5: // setFieldFrequency(int)
if (arguments.length == 1) {
if (isEnabled)
disableCloakingField();
if (WarpDrive.instance.cloaks.isAreaExists(((Double)arguments[0]).intValue()))
return new Object[] { (Boolean)false };
this.frequency = ((Double)arguments[0]).intValue();
return new Object[] { (Boolean)true };
}
break;
}
return null;
}
@Override
public boolean canAttachToSide(int side) {
return true;
}
@Override
public void attach(IComputerAccess computer) {
}
@Override
public void detach(IComputerAccess computer) {
}
// IEnergySink methods implementation
@Override
public double demandedEnergyUnits() {
return (MAX_ENERGY_VALUE - currentEnergyValue);
}
@Override
public double injectEnergyUnits(ForgeDirection directionFrom, double amount) {
double leftover = 0;
currentEnergyValue += Math.round(amount);
if (getCurrentEnergyValue() > MAX_ENERGY_VALUE) {
leftover = (getCurrentEnergyValue() - MAX_ENERGY_VALUE);
currentEnergyValue = MAX_ENERGY_VALUE;
}
return leftover;
}
@Override
public int getMaxSafeInput() {
return Integer.MAX_VALUE;
}
@Override
public boolean acceptsEnergyFrom(TileEntity emitter,
ForgeDirection direction) {
return true;
}
/**
* @return the currentEnergyValue
*/
public int getCurrentEnergyValue() {
return currentEnergyValue;
}
public int collectAllEnergy() {
int energy = currentEnergyValue;
currentEnergyValue = 0;
return energy;
}
@Override
public void onChunkUnload() {
if (addedToEnergyNet) {
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
addedToEnergyNet = false;
}
}
@Override
public void invalidate() {
if (addedToEnergyNet) {
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
addedToEnergyNet = false;
}
super.invalidate();
}
}

View file

@ -34,9 +34,6 @@ import net.minecraftforge.common.MinecraftForge;
public class TileEntityLaser extends TileEntity implements IPeripheral
{
private final int MAX_BOOSTERS_NUMBER = 10;
private final int MAX_LASER_ENERGY = 4000000;
private int dx, dz, dy;
public float yaw, pitch; // laser direction
@ -68,7 +65,7 @@ public class TileEntityLaser extends TileEntity implements IPeripheral
public void updateEntity()
{
// Frequency is not set
if (frequency == -1)
if (frequency <= 0)
{
return;
}
@ -88,11 +85,11 @@ public class TileEntityLaser extends TileEntity implements IPeripheral
}
}
if (isEmitting && ++delayTicks > 20 * 3)
if (isEmitting && (frequency != 1420 && ++delayTicks > WarpDriveConfig.i.LE_EMIT_DELAY_TICKS) || ((frequency == 1420) && ++delayTicks > WarpDriveConfig.i.LE_EMIT_SCAN_DELAY_TICKS))
{
delayTicks = 0;
isEmitting = false;
emitBeam(Math.min(this.collectEnergyFromBoosters() + MathHelper.floor_double(energyFromOtherBeams * 0.60D), MAX_LASER_ENERGY));
emitBeam(Math.min(this.collectEnergyFromBoosters() + MathHelper.floor_double(energyFromOtherBeams * WarpDriveConfig.i.LE_COLLECT_ENERGY_MULTIPLIER), WarpDriveConfig.i.LE_MAX_LASER_ENERGY));
energyFromOtherBeams = 0;
}
}
@ -102,11 +99,11 @@ public class TileEntityLaser extends TileEntity implements IPeripheral
if (isEmitting)
{
energyFromOtherBeams += amount;
System.out.println("[EL] Added energy: " + amount);
System.out.println("[LE] Added energy: " + amount);
}
else
{
System.out.println("[EL] Ignored energy: " + amount);
System.out.println("[LE] Ignored energy: " + amount);
}
}
@ -116,7 +113,7 @@ public class TileEntityLaser extends TileEntity implements IPeripheral
if (findFirstBooster() != null)
{
for (int shift = 1; shift <= MAX_BOOSTERS_NUMBER; shift++)
for (int shift = 1; shift <= WarpDriveConfig.i.LE_MAX_BOOSTERS_NUMBER; shift++)
{
int newX = xCoord + (dx * shift);
int newY = yCoord + (dy * shift);
@ -141,7 +138,7 @@ public class TileEntityLaser extends TileEntity implements IPeripheral
private void emitBeam(int energy)
{
// Beam power calculations
int beamLengthBlocks = energy / 5000;
int beamLengthBlocks = energy / WarpDriveConfig.i.LE_BEAM_LENGTH_PER_ENERGY_DIVIDER;
System.out.println("Energy: " + energy + " | beamLengthBlocks: " + beamLengthBlocks);
if (energy == 0 || beamLengthBlocks < 1)
@ -204,16 +201,16 @@ public class TileEntityLaser extends TileEntity implements IPeripheral
{
if (distanceToEntity <= beamLengthBlocks)
{
((EntityLivingBase)e).setFire(100);
((EntityLivingBase)e).attackEntityFrom(DamageSource.inFire, energy / 10000);
((EntityLivingBase)e).setFire(WarpDriveConfig.i.LE_ENTITY_HIT_SET_ON_FIRE_TIME);
((EntityLivingBase)e).attackEntityFrom(DamageSource.inFire, energy / WarpDriveConfig.i.LE_ENTITY_HIT_DAMAGE_PER_ENERGY_DIVIDER);
if (energy > 1000000)
if (energy > WarpDriveConfig.i.LE_ENTITY_HIT_EXPLOSION_LASER_ENERGY)
{
worldObj.newExplosion(null, e.posX, e.posY, e.posZ, 4F, true, true);
}
// consume energy
energy -= 10000 + (10 * distanceToEntity);
energy -= WarpDriveConfig.i.LE_ENTITY_HIT_DAMAGE_PER_ENERGY_DIVIDER + (10 * distanceToEntity);
endPoint = new Vector3(entityHit.hitVec);
break;
}
@ -268,7 +265,7 @@ public class TileEntityLaser extends TileEntity implements IPeripheral
endPoint = new Vector3(hit.hitVec);
}
energy -= 70000 + (resistance * 1000) + (distance * 10);
energy -= WarpDriveConfig.i.LE_BLOCK_HIT_CONSUME_ENERGY + (resistance * WarpDriveConfig.i.LE_BLOCK_HIT_CONSUME_ENERGY_PER_BLOCK_RESISTANCE) + (distance * WarpDriveConfig.i.LE_BLOCK_HIT_CONSUME_ENERGY_PER_DISTANCE);
endPoint = new Vector3(hit.hitVec);
if (energy <= 0)

View file

@ -64,15 +64,8 @@ public class TileEntityMiningLaser extends TileEntity implements IPeripheral, IG
"offset" //5
};
private final int SCAN_DELAY = 20 * 5;
private int delayTicksScan = 0;
private final int MINE_DELAY = 10;
private int delayTicksMine = 0;
private final int EU_PER_LAYER_SPACE = 500;
private final int EU_PER_LAYER_EARTH = 5000;
private int currentMode = 0; // 0 - scan next layer, 1 - collect valuables
private int currentLayer;
@ -105,19 +98,19 @@ public class TileEntityMiningLaser extends TileEntity implements IPeripheral, IG
if (currentMode == 0)
{
if (++delayTicksScan > SCAN_DELAY)
if (++delayTicksScan > WarpDriveConfig.i.ML_SCAN_DELAY)
{
delayTicksScan = 0;
valuablesInLayer.clear();
valuableIndex = 0;
if (!collectEnergyPacketFromBooster(isOnEarth ? EU_PER_LAYER_EARTH : EU_PER_LAYER_SPACE, true))
if (!collectEnergyPacketFromBooster(isOnEarth ? WarpDriveConfig.i.ML_EU_PER_LAYER_EARTH : WarpDriveConfig.i.ML_EU_PER_LAYER_SPACE, true))
return;
while (currentLayer > 0)
{
scanLayer();
if (valuablesInLayer.size() > 0)
{
if (!collectEnergyPacketFromBooster(isOnEarth ? EU_PER_LAYER_EARTH : EU_PER_LAYER_SPACE, false))
if (!collectEnergyPacketFromBooster(isOnEarth ? WarpDriveConfig.i.ML_EU_PER_LAYER_EARTH : WarpDriveConfig.i.ML_EU_PER_LAYER_SPACE, false))
return;
sendLaserPacket(minerVector, new Vector3(xCoord, currentLayer, zCoord).add(0.5), 0, 0, 1, 20, 0, 50);
worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:hilaser", 4F, 1F);
@ -137,7 +130,7 @@ public class TileEntityMiningLaser extends TileEntity implements IPeripheral, IG
}
else
{
if (++delayTicksMine > MINE_DELAY)
if (++delayTicksMine > WarpDriveConfig.i.ML_MINE_DELAY)
{
delayTicksMine = 0;
@ -152,7 +145,7 @@ public class TileEntityMiningLaser extends TileEntity implements IPeripheral, IG
if (!canDig(blockID))
return;
sendLaserPacket(minerVector, new Vector3(valuable.intX(), valuable.intY(), valuable.intZ()).add(0.5), 1, 1, 0, 2 * MINE_DELAY, 0, 50);
sendLaserPacket(minerVector, new Vector3(valuable.intX(), valuable.intY(), valuable.intZ()).add(0.5), 1, 1, 0, 2 * WarpDriveConfig.i.ML_MINE_DELAY, 0, 50);
worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:lowlaser", 4F, 1F);
harvestBlock(valuable);
}

View file

@ -26,7 +26,6 @@ public class TileEntityParticleBooster extends TileEntity implements IEnergySink
{
public boolean addedToEnergyNet = false;
private final int MAX_ENERGY_VALUE = 100000; // eU
private int currentEnergyValue = 0;
int ticks = 0;
@ -48,7 +47,7 @@ public class TileEntityParticleBooster extends TileEntity implements IEnergySink
if (++ticks > 40)
{
ticks = 0;
currentEnergyValue = Math.min(currentEnergyValue, MAX_ENERGY_VALUE);
currentEnergyValue = Math.min(currentEnergyValue, WarpDriveConfig.i.PB_MAX_ENERGY_VALUE);
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, currentEnergyValue / 10000, 2);
}
}
@ -71,7 +70,7 @@ public class TileEntityParticleBooster extends TileEntity implements IEnergySink
@Override
public double demandedEnergyUnits()
{
return (MAX_ENERGY_VALUE - currentEnergyValue);
return (WarpDriveConfig.i.PB_MAX_ENERGY_VALUE - currentEnergyValue);
}
@Override
@ -80,10 +79,10 @@ public class TileEntityParticleBooster extends TileEntity implements IEnergySink
double leftover = 0;
currentEnergyValue += Math.round(amount);
if (getCurrentEnergyValue() > MAX_ENERGY_VALUE)
if (getCurrentEnergyValue() > WarpDriveConfig.i.PB_MAX_ENERGY_VALUE)
{
leftover = (getCurrentEnergyValue() - MAX_ENERGY_VALUE);
currentEnergyValue = MAX_ENERGY_VALUE;
leftover = (getCurrentEnergyValue() - WarpDriveConfig.i.PB_MAX_ENERGY_VALUE);
currentEnergyValue = WarpDriveConfig.i.PB_MAX_ENERGY_VALUE;
}
return leftover;

View file

@ -591,7 +591,7 @@ public class TileEntityProtocol extends TileEntity implements IPeripheral
return new Object[] { (Integer)core.zCoord };
case 13:
case 13: // get_energy_value
if (core != null)
{
return new Object[] { (Integer)((TileEntityReactor)core).currentEnergyValue };
@ -639,7 +639,7 @@ public class TileEntityProtocol extends TileEntity implements IPeripheral
case 19: // set_core_frequency
if (arguments.length == 1 && (core != null && core instanceof TileEntityReactor))
{
((TileEntityReactor)core).coreFrequency = ((String)arguments[0]);
((TileEntityReactor)core).coreFrequency = ((String)arguments[0]).replace("/", "").replace(".", "").replace("\\", ".");
}
break;

View file

@ -26,7 +26,6 @@ public class TileEntityRadar extends TileEntity implements IPeripheral, IEnergyS
{
public boolean addedToEnergyNet = false;
private final int MAX_ENERGY_VALUE = 100 * (1000 * 1000); // 100 000 000 Eu
private int currentEnergyValue = 0;
private String[] methodsArray =
@ -197,7 +196,7 @@ public class TileEntityRadar extends TileEntity implements IPeripheral, IEnergyS
@Override
public double demandedEnergyUnits()
{
return (MAX_ENERGY_VALUE - currentEnergyValue);
return (WarpDriveConfig.i.WR_MAX_ENERGY_VALUE - currentEnergyValue);
}
@Override
@ -206,10 +205,10 @@ public class TileEntityRadar extends TileEntity implements IPeripheral, IEnergyS
double leftover = 0;
currentEnergyValue += Math.round(amount);
if (getCurrentEnergyValue() > MAX_ENERGY_VALUE)
if (getCurrentEnergyValue() > WarpDriveConfig.i.WR_MAX_ENERGY_VALUE)
{
leftover = (getCurrentEnergyValue() - MAX_ENERGY_VALUE);
currentEnergyValue = MAX_ENERGY_VALUE;
leftover = (getCurrentEnergyValue() - WarpDriveConfig.i.WR_MAX_ENERGY_VALUE);
currentEnergyValue = WarpDriveConfig.i.WR_MAX_ENERGY_VALUE;
}
return leftover;

View file

@ -1,7 +1,5 @@
package cr0s.WarpDrive;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraftforge.common.ForgeDirection;
import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.event.EnergyTileUnloadEvent;
import ic2.api.energy.tile.IEnergySink;
@ -23,7 +21,9 @@ import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.FMLCommonHandler;
/**
* @author Cr0s
@ -58,35 +58,22 @@ public class TileEntityReactor extends TileEntity implements IEnergySink
int currentMode = 0;
int currentEnergyValue = 0;
int maxEnergyValue = 100000000;
private final int ENERGY_PER_BLOCK_MODE1 = 10; // eU
private final int ENERGY_PER_DISTANCE_MODE1 = 100; // eU
private final int ENERGY_PER_BLOCK_MODE2 = 1000; // eU
private final int ENERGY_PER_DISTANCE_MODE2 = 1000; // eU
private final int ENERGY_PER_ENTITY_TO_SPACE = 1000000; // eU
private final byte MODE_BASIC_JUMP = 1; // 0-128
private final byte MODE_LONG_JUMP = 2; // 0-12800
private final byte MODE_BEACON_JUMP = 4; // Jump ship by beacon
private final byte MODE_HYPERSPACE = 5; // Jump to Hyperspace
private final byte MODE_TELEPORT = -1;
private final byte MODE_GATE_JUMP = 6; // Jump via jumpgate
private final int MAX_JUMP_DISTANCE = 128; // Maximum jump length value
private final int MAX_SHIP_VOLUME_ON_SURFACE = 15000; // Maximum ship mass to jump on earth (15k blocks)
private final int MIN_SHIP_VOLUME_FOR_HYPERSPACE = 500; // Minimum ship volume value for
public final int MAX_SHIP_SIDE = 100;
int cooldownTime = 0;
private final int COOLDOWN_INTERVAL_SECONDS = 4;
public int randomCooldownAddition = 0;
private final int CORES_REGISTRY_UPDATE_INTERVAL_SECONDS = 10;
private int registryUpdateTicks = 0;
public String coreFrequency = "default";
public int isolationBlocksCount = 0;
public int isolationUpdateTicks = 0;
private final int ISOLATION_UPDATE_INTARVAL_SECONDS = 10;
public String coreState = "";
public TileEntityProtocol controller;
@ -103,7 +90,7 @@ public class TileEntityReactor extends TileEntity implements IEnergySink
}
// Update warp core in cores registry
if (++registryUpdateTicks > CORES_REGISTRY_UPDATE_INTERVAL_SECONDS * 20)
if (++registryUpdateTicks > WarpDriveConfig.i.WC_CORES_REGISTRY_UPDATE_INTERVAL_SECONDS * 20)
{
registryUpdateTicks = 0;
WarpDrive.instance.registry.updateInRegistry(this);
@ -114,7 +101,7 @@ public class TileEntityReactor extends TileEntity implements IEnergySink
return;
}
if (++isolationUpdateTicks > ISOLATION_UPDATE_INTARVAL_SECONDS * 20)
if (++isolationUpdateTicks > WarpDriveConfig.i.WC_ISOLATION_UPDATE_INTARVAL_SECONDS * 20)
{
isolationUpdateTicks = 0;
updateIsolationState();
@ -190,7 +177,6 @@ public class TileEntityReactor extends TileEntity implements IEnergySink
// Set up activated animation
if (worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 0)
{
// TODO: check for "warpcore turns into dirt" bug
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 1, 1 + 2); // Set block state to "active"
makePlayersOnShipDrunk();
}
@ -202,7 +188,7 @@ public class TileEntityReactor extends TileEntity implements IEnergySink
}
// Awaiting cooldown time
if (/*currentMode != MODE_BASIC_JUMP && */cooldownTime++ < ((COOLDOWN_INTERVAL_SECONDS) * 20) + randomCooldownAddition)
if (/*currentMode != MODE_BASIC_JUMP && */cooldownTime++ < ((WarpDriveConfig.i.WC_COOLDOWN_INTERVAL_SECONDS) * 20) + randomCooldownAddition)
{
return;
}
@ -222,6 +208,13 @@ public class TileEntityReactor extends TileEntity implements IEnergySink
return;
}
if (WarpDrive.instance.cloaks.isInCloak(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, false))
{
this.controller.setJumpFlag(false);
messageToAllPlayersOnShip("Wap-Core is inside cloaking field. Can't jump. Disable cloaking field to jump!");
return;
}
System.out.println("[W-C] Jumping!");
doJump();
controller.setJumpFlag(false);
@ -365,7 +358,7 @@ public class TileEntityReactor extends TileEntity implements IEnergySink
public void summonPlayer(EntityPlayerMP player, int x, int y, int z)
{
if (this.currentEnergyValue - this.ENERGY_PER_ENTITY_TO_SPACE >= 0)
if (this.currentEnergyValue - WarpDriveConfig.i.WC_ENERGY_PER_ENTITY_TO_SPACE >= 0)
{
player.setPositionAndUpdate(x, y, z);
@ -374,12 +367,15 @@ public class TileEntityReactor extends TileEntity implements IEnergySink
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;
this.currentEnergyValue -= WarpDriveConfig.i.WC_ENERGY_PER_ENTITY_TO_SPACE;
}
}
public boolean prepareToJump()
{
if (controller == null)
return false;
this.direction = controller.getDirection();
this.shipFront = controller.getFront();
this.shipRight = controller.getRight();
@ -387,7 +383,7 @@ public class TileEntityReactor extends TileEntity implements IEnergySink
this.shipBack = controller.getBack();
this.shipLeft = controller.getLeft();
this.shipDown = controller.getDown();
this.distance = Math.min(this.MAX_JUMP_DISTANCE, controller.getDistance());
this.distance = Math.min(WarpDriveConfig.i.WC_MAX_JUMP_DISTANCE, controller.getDistance());
return calculateSpatialShipParameters();
}
@ -475,7 +471,7 @@ public class TileEntityReactor extends TileEntity implements IEnergySink
}
// Ship side is too big
if (shipLength > MAX_SHIP_SIDE || shipWidth > MAX_SHIP_SIDE || shipHeight > MAX_SHIP_SIDE)
if (shipLength > WarpDriveConfig.i.WC_MAX_SHIP_SIDE || shipWidth > WarpDriveConfig.i.WC_MAX_SHIP_SIDE || shipHeight > WarpDriveConfig.i.WC_MAX_SHIP_SIDE)
{
this.controller.setJumpFlag(false);
return false;
@ -483,7 +479,7 @@ public class TileEntityReactor extends TileEntity implements IEnergySink
this.shipVolume = getRealShipVolume();
if (shipVolume > MAX_SHIP_VOLUME_ON_SURFACE && worldObj.provider.dimensionId == 0)
if (shipVolume > WarpDriveConfig.i.WC_MAX_JUMP_DISTANCE && worldObj.provider.dimensionId == 0)
{
this.controller.setJumpFlag(false);
return false;
@ -785,9 +781,9 @@ public class TileEntityReactor extends TileEntity implements IEnergySink
if (t != null && !isShipInJumpgate(t))
{
if (shipVolume < MIN_SHIP_VOLUME_FOR_HYPERSPACE)
if (shipVolume < WarpDriveConfig.i.WC_MIN_SHIP_VOLUME_FOR_HYPERSPACE)
{
this.messageToAllPlayersOnShip("Ship is too small (" + shipVolume + "/" + MIN_SHIP_VOLUME_FOR_HYPERSPACE + "). Insufficient ship mass to open hyperspace portal.");
this.messageToAllPlayersOnShip("Ship is too small (" + shipVolume + "/" + WarpDriveConfig.i.WC_MIN_SHIP_VOLUME_FOR_HYPERSPACE + "). Insufficient ship mass to open hyperspace portal.");
this.controller.setJumpFlag(false);
return;
}
@ -802,6 +798,7 @@ public class TileEntityReactor extends TileEntity implements IEnergySink
if (this.currentEnergyValue - calculateRequiredEnergy(shipVolume, distance) < 0)
{
System.out.println("[WP-TE] Insufficient energy to jump");
messageToAllPlayersOnShip("Insufficient energy to jump!");
this.controller.setJumpFlag(false);
return;
}
@ -870,12 +867,12 @@ public class TileEntityReactor extends TileEntity implements IEnergySink
for (Object o : list)
{
if (currentEnergyValue - ENERGY_PER_ENTITY_TO_SPACE < 0)
if (currentEnergyValue - WarpDriveConfig.i.WC_ENERGY_PER_ENTITY_TO_SPACE < 0)
{
return;
}
currentEnergyValue -= ENERGY_PER_ENTITY_TO_SPACE;
currentEnergyValue -= WarpDriveConfig.i.WC_ENERGY_PER_ENTITY_TO_SPACE;
Entity entity = (Entity) o;
int x = MathHelper.floor_double(entity.posX);
int z = MathHelper.floor_double(entity.posZ);
@ -1009,19 +1006,19 @@ public class TileEntityReactor extends TileEntity implements IEnergySink
switch (currentMode)
{
case MODE_BASIC_JUMP:
energyValue = (ENERGY_PER_BLOCK_MODE1 * shipVolume) + (ENERGY_PER_DISTANCE_MODE1 * jumpDistance);
energyValue = (WarpDriveConfig.i.WC_ENERGY_PER_BLOCK_MODE1 * shipVolume) + (WarpDriveConfig.i.WC_ENERGY_PER_DISTANCE_MODE1 * jumpDistance);
break;
case MODE_LONG_JUMP:
energyValue = (ENERGY_PER_BLOCK_MODE2 * shipVolume) + (ENERGY_PER_DISTANCE_MODE2 * jumpDistance);
energyValue = (WarpDriveConfig.i.WC_ENERGY_PER_BLOCK_MODE2 * shipVolume) + (WarpDriveConfig.i.WC_ENERGY_PER_DISTANCE_MODE2 * jumpDistance);
break;
case MODE_HYPERSPACE:
energyValue = this.maxEnergyValue / 10; // 10% of maximum
energyValue = WarpDriveConfig.i.WC_MAX_ENERGY_VALUE / 10; // 10% of maximum
break;
case MODE_BEACON_JUMP:
energyValue = this.maxEnergyValue / 2; // half of maximum
energyValue = WarpDriveConfig.i.WC_MAX_ENERGY_VALUE / 2; // half of maximum
break;
case MODE_GATE_JUMP:
@ -1104,7 +1101,7 @@ public class TileEntityReactor extends TileEntity implements IEnergySink
return 0;
}
return (maxEnergyValue - currentEnergyValue);
return (WarpDriveConfig.i.WC_MAX_ENERGY_VALUE - currentEnergyValue);
}
@Override
@ -1113,10 +1110,10 @@ public class TileEntityReactor extends TileEntity implements IEnergySink
double leftover = 0;
currentEnergyValue += Math.round(amount);
if (currentEnergyValue > maxEnergyValue)
if (currentEnergyValue > WarpDriveConfig.i.WC_MAX_ENERGY_VALUE)
{
leftover = (currentEnergyValue - maxEnergyValue);
currentEnergyValue = maxEnergyValue;
leftover = (currentEnergyValue - WarpDriveConfig.i.WC_MAX_ENERGY_VALUE);
currentEnergyValue = WarpDriveConfig.i.WC_MAX_ENERGY_VALUE;
}
return leftover;

View file

@ -0,0 +1,931 @@
package cr0s.WarpDrive;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.ILuaContext;
import dan200.computer.api.IPeripheral;
import net.minecraftforge.common.ForgeDirection;
import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.event.EnergyTileUnloadEvent;
import ic2.api.energy.tile.IEnergySink;
import ic2.api.energy.tile.IEnergyTile;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.server.MinecraftServer;
import net.minecraft.src.ModLoader;
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.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import net.minecraftforge.common.MinecraftForge;
public class TileEntityShipScanner extends TileEntity implements IEnergySink,
IPeripheral {
public boolean addedToEnergyNet = false;
private final int MAX_ENERGY_VALUE = 500000000; // 500kk eU
private int currentEnergyValue = 0;
private int state = 0; // 0 - inactive, 1 - active
private int firstUncoveredY;
private boolean isEnabled = false;
private TileEntityReactor core = null;
int laserTicks = 0;
int scanTicks = 0;
int deployDelayTicks = 0;
int warpCoreSearchTicks = 0;
// Config
private final String SCHEMATICS_DIR = "/home/cros/mc_site/schematics/";
private final int EU_PER_BLOCK_SCAN = 100; // eU per block of ship volume (including air)
private final int EU_PER_BLOCK_DEPLOY = 5000;
private final int BLOCK_TO_DEPLOY_PER_TICK = 1000;
private final int ALLOWED_DEPLOY_RADIUS = 50; // blocks
private String[] methodsArray = { "scanShip", // 0
"getSchematicFileName", // 1
"getEnergyLevel", // 2
"deployShipFromSchematic" // 3 deployShipFromSchematic(file, offsetX, offsetY, offsetZ)
};
private String schematicFileName;
private JumpBlock[] blocksToDeploy; // JumpBlock class stores a basic information about block
private int currentDeployIndex;
private int blocksToDeployCount;
private boolean isDeploying = false;
private int newX, newY, newZ;
@Override
public void updateEntity() {
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
return;
}
if (!addedToEnergyNet && !this.tileEntityInvalid) {
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
addedToEnergyNet = true;
}
if (++warpCoreSearchTicks > 20) {
core = searchWarpCore();
warpCoreSearchTicks = 0;
}
// Warp core is not found
if (!isDeploying && core == null) {
switchState(0); // disable scanner
return;
}
if (state == 0) { // inactive
if (++laserTicks > 20) {
sendLaserPacket(new Vector3(this).add(0.5), new Vector3(
core.xCoord, core.yCoord, core.zCoord).add(0.5), 0f,
1f, 0f, 40, 0, 100);
laserTicks = 0;
}
} else if (state == 1 && !isDeploying) { // active: scanning
if (++laserTicks > 5) {
laserTicks = 0;
for (int i = 0; i < core.maxX - core.minX; i++) {
int x = core.minX + i;
int randomZ = core.minZ + worldObj.rand.nextInt(core.maxZ - core.minZ);
worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:lowlaser", 4F, 1F);
float r = 0.0f, g = 0.0f, b = 0.0f;
switch (worldObj.rand.nextInt(6)) {
case 0:
r = 1.0f;
g = b = 0;
break;
case 1:
r = b = 0;
g = 1.0f;
break;
case 2:
r = g = 0;
b = 1.0f;
break;
case 3:
r = b = 0.5f;
g = 0;
break;
case 4:
r = g = 1.0f;
b = 0;
break;
case 5:
r = 1.0f;
b = 0.5f;
g = 0f;
}
sendLaserPacket(new Vector3(this).add(0.5), new Vector3(x, core.maxY, randomZ).add(0.5), r, g, b, 15, 0, 100);
}
}
if (++scanTicks > 20 * (1 + core.shipVolume / 10)) {
switchState(0);
scanTicks = 0;
}
} if (state == 1 && isDeploying) { // active: deploying
if (++deployDelayTicks < 20)
return;
deployDelayTicks = 0;
int blocks = Math.min(BLOCK_TO_DEPLOY_PER_TICK, blocksToDeployCount - currentDeployIndex);
System.out.println("[ShipScanner] Deploying ship part: " + currentDeployIndex + "/" + blocksToDeployCount + " [remains: " + blocks + "]");
if (blocks == 0) {
isDeploying = false;
switchState(0);
return;
}
for (int index = 0; index < blocks; index++)
{
if (currentDeployIndex >= blocksToDeployCount)
{
isDeploying = false;
switchState(0);
break;
}
// Deploy single block
JumpBlock block = blocksToDeploy[currentDeployIndex];
if (block!= null && worldObj.isAirBlock(newX + block.x, newY + block.y, newZ + block.z))
{
moveBlockSimple(block);
if (worldObj.rand.nextInt(100) <= 10) {
worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:lowlaser", 4F, 1F);
sendLaserPacket(new Vector3(this).add(0.5), new Vector3(
newX + block.x, newY + block.y, newZ + block.z).add(0.5), 0f,
1f, 0f, 15, 0, 100);
}
}
currentDeployIndex++;
}
}
}
private void switchState(int newState) {
this.state = newState;
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, newState, 2);
}
private TileEntityReactor searchWarpCore() {
TileEntityReactor result = null;
// Search for warp cores above
for (int newY = yCoord + 1; newY <= 255; newY++) {
if (worldObj.getBlockId(xCoord, newY, zCoord) == WarpDriveConfig.i.coreID) { // found
// warp
// core
// above
result = (TileEntityReactor) worldObj.getBlockTileEntity(
xCoord, newY, zCoord);
if (result != null) {
if (!result.prepareToJump()) { // If we can't refresh ship's
// spatial parameters
result = null;
}
}
break;
}
}
return result;
}
public void sendLaserPacket(Vector3 source, Vector3 dest, float r, float g,
float b, int age, int energy, int radius) {
Side side = FMLCommonHandler.instance().getEffectiveSide();
if (side == Side.SERVER) {
ByteArrayOutputStream bos = new ByteArrayOutputStream(8);
DataOutputStream outputStream = new DataOutputStream(bos);
try {
// Write source vector
outputStream.writeDouble(source.x);
outputStream.writeDouble(source.y);
outputStream.writeDouble(source.z);
// Write target vector
outputStream.writeDouble(dest.x);
outputStream.writeDouble(dest.y);
outputStream.writeDouble(dest.z);
// Write r, g, b of laser
outputStream.writeFloat(r);
outputStream.writeFloat(g);
outputStream.writeFloat(b);
// Write age
outputStream.writeByte(age);
// Write energy value
outputStream.writeInt(energy);
} catch (Exception ex) {
ex.printStackTrace();
}
Packet250CustomPayload packet = new Packet250CustomPayload();
packet.channel = "WarpDriveBeam";
packet.data = bos.toByteArray();
packet.length = bos.size();
MinecraftServer
.getServer()
.getConfigurationManager()
.sendToAllNear(source.intX(), source.intY(), source.intZ(),
radius, worldObj.provider.dimensionId, packet);
ByteArrayOutputStream bos2 = new ByteArrayOutputStream(8);
DataOutputStream outputStream2 = new DataOutputStream(bos2);
try {
// Write source vector
outputStream2.writeDouble(source.x);
outputStream2.writeDouble(source.y);
outputStream2.writeDouble(source.z);
// Write target vector
outputStream2.writeDouble(dest.x);
outputStream2.writeDouble(dest.y);
outputStream2.writeDouble(dest.z);
// Write r, g, b of laser
outputStream2.writeFloat(r);
outputStream2.writeFloat(g);
outputStream2.writeFloat(b);
// Write age
outputStream2.writeByte(age);
// Write energy value
outputStream2.writeInt(energy);
} catch (Exception ex) {
ex.printStackTrace();
}
Packet250CustomPayload packet2 = new Packet250CustomPayload();
packet.channel = "WarpDriveBeam";
packet.data = bos.toByteArray();
packet.length = bos.size();
MinecraftServer
.getServer()
.getConfigurationManager()
.sendToAllNear(dest.intX(), dest.intY(), dest.intZ(),
radius, worldObj.provider.dimensionId, packet);
}
}
// Checks energy level
private boolean isEnoughEnergyForScan() {
if (core != null) {
return core.shipVolume * EU_PER_BLOCK_SCAN <= currentEnergyValue;
}
return false;
}
private void saveShipToSchematic(String fileName) {
NBTTagCompound schematic = new NBTTagCompound("Schematic");
short width = (short) Math.abs(core.maxX - core.minX);
short length = (short) Math.abs(core.maxZ - core.minZ);
short height = (short) (core.maxY - core.minY);
width++;
height++;
length++;
schematic.setShort("Width", width);
schematic.setShort("Length", length);
schematic.setShort("Height", height);
System.out.println("[ShipScanner] Ship parameters: w: " + width + ", l: " + length + ", h:" + height);
int size = width * length * height;
// Consume energy
currentEnergyValue = Math.abs(currentEnergyValue - size * EU_PER_BLOCK_SCAN);
System.out.println("[ShipScanner] Size: " + size);
byte localBlocks[] = new byte[size];
byte localMetadata[] = new byte[size];
byte extraBlocks[] = new byte[size];
byte extraBlocksNibble[] = new byte[(int) Math.ceil(size / 2.0)];
boolean extra = false;
NBTTagList tileEntitiesList = new NBTTagList();
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
for (int z = 0; z < length; z++) {
int blockID = worldObj.getBlockId(core.minX + x, core.minY + y, core.minZ + z);
// Do not scan air, bedrock and specified forbidden blocks (like ore or Warp-Cores)
if (worldObj.isAirBlock(core.minX + x, core.minY + y, core.minZ + z) || blockID == Block.bedrock.blockID || WarpDriveConfig.i.scannerIgnoreBlocks.contains(blockID))
blockID = 0;
int blockMetadata = (byte) worldObj.getBlockMetadata(core.minX + x, core.minY + y, core.minZ + z);
localBlocks[x + (y * length + z) * width] = (byte) blockID;
localMetadata[x + (y * length + z) * width] = (byte) blockMetadata;
if ((extraBlocks[x + (y * length + z) * width] = (byte) (blockID >> 8)) > 0) {
extra = true;
}
if (blockID != 0) {
TileEntity te = worldObj.getBlockTileEntity(core.minX + x, core.minY + y, core.minZ + z);
if (te != null && !(te instanceof IInventory))
{
try {
NBTTagCompound tileTag = new NBTTagCompound();
te.writeToNBT(tileTag);
// Remove energy from energy storages
if (te instanceof IEnergyTile) {
if (tileTag.hasKey("energy"))
tileTag.setInteger("energy", 0);
}
// Transform TE's coordinates from local axis to .schematic offset-axis
tileTag.setInteger("x", te.xCoord - core.minX);
tileTag.setInteger("y", te.yCoord - core.minY);
tileTag.setInteger("z", te.zCoord - core.minZ);
tileEntitiesList.appendTag(tileTag);
} catch (Exception e) {}
}
}
}
}
}
for (int i = 0; i < extraBlocksNibble.length; i++) {
if (i * 2 + 1 < extraBlocks.length) {
extraBlocksNibble[i] = (byte) ((extraBlocks[i * 2 + 0] << 4) | extraBlocks[i * 2 + 1]);
} else {
extraBlocksNibble[i] = (byte) (extraBlocks[i * 2 + 0] << 4);
}
}
schematic.setString("Materials", "Alpha");
schematic.setByteArray("Blocks", localBlocks);
schematic.setByteArray("Data", localMetadata);
if (extra)
schematic.setByteArray("AddBlocks", extraBlocksNibble);
schematic.setTag("Entities", new NBTTagList()); // don't save entities
schematic.setTag("TileEntities", tileEntitiesList);
writeNBTToFile(fileName, schematic);
}
private void writeNBTToFile(String fileName, NBTTagCompound nbttagcompound) {
System.out.println("[ShipScanner] Filename: " + fileName);
try {
File file = new File(fileName);
if (!file.exists()) {
file.createNewFile();
}
FileOutputStream fileoutputstream = new FileOutputStream(file);
CompressedStreamTools.writeCompressed(nbttagcompound,
fileoutputstream);
fileoutputstream.close();
} catch (Exception exception) {
exception.printStackTrace();
}
}
// Begins ship scan
private void scanShip() {
// Enable scanner
switchState(1);
// Generate unique file name
do {
schematicFileName = (new StringBuilder().append(core.coreFrequency)
.append(System.currentTimeMillis()).append(".schematic"))
.toString();
} while (new File(this.SCHEMATICS_DIR + schematicFileName).exists());
saveShipToSchematic(this.SCHEMATICS_DIR + schematicFileName);
}
private NBTTagCompound readNBTFromFile(String fileName) {
try {
File file = new File(fileName);
if (!file.exists()) {
return null;
}
FileInputStream fileinputstream = new FileInputStream(file);
NBTTagCompound nbttagcompound = CompressedStreamTools
.readCompressed(fileinputstream);
fileinputstream.close();
return nbttagcompound;
} catch (Exception exception) {
exception.printStackTrace();
}
return null;
}
private boolean isEnoughEnergyForDeploy(int size) {
return size * EU_PER_BLOCK_DEPLOY <= currentEnergyValue;
}
// Returns result array for CC interface: [ code, "message" ]
private Object[] deployShip(String fileName, int offsetX, int offsetY, int offsetZ) {
NBTTagCompound schematic = readNBTFromFile(SCHEMATICS_DIR + fileName);
if (schematic == null) {
System.out.println("[ShipScanner] Schematic is null!");
return new Object[] { -1, "Unknow error. Schematic NBT is null" };
}
short width = schematic.getShort("Width");
short height = schematic.getShort("Height");
short length = schematic.getShort("Length");
int targetX = xCoord + offsetX;
int targetY = yCoord + offsetY;
int targetZ = zCoord + offsetZ;
double d3 = xCoord - targetX;
double d4 = yCoord - targetY;
double d5 = zCoord - targetZ;
double distance = MathHelper.sqrt_double(d3 * d3 + d4 * d4 + d5 * d5);
if (distance > ALLOWED_DEPLOY_RADIUS)
return new Object[] { 5, "Cannot deploy ship so far away from scanner." };
int size = width* height * length;
System.out.println("[ShipScanner] Deploying ship: (size: " + size + ", h: " + height + ", w: " + width + ", l: " + length + ")");
// Check energy level
if (!isEnoughEnergyForDeploy(size)) {
System.out.println("[ShipScanner] Not enough energy! Need at least " + (Math.abs(size * EU_PER_BLOCK_DEPLOY - currentEnergyValue)) + " Eu");
return new Object[] { 1, "Not enough energy! Need at least " + (Math.abs(size * EU_PER_BLOCK_DEPLOY - currentEnergyValue)) + " Eu" };
}
// Check specified area for occupation by blocks
// If specified area occupied, break deploying with error message
int occupiedBlockCount = 0;
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
for (int z = 0; z < length; z++) {
if (!worldObj.isAirBlock(targetX + x, targetY + y, targetZ + z))
occupiedBlockCount++;
}
}
}
if (occupiedBlockCount > 0) {
System.out.println("[ShipScanner] Deploying area occupied with " + occupiedBlockCount + " blocks. Can't deploy ship.");
return new Object[] { 2, "Deploying area occupied with " + occupiedBlockCount + " blocks. Can't deploy ship." };
}
// Consume energy
currentEnergyValue = Math.abs(currentEnergyValue - size * EU_PER_BLOCK_DEPLOY);
// Set deployment vars
this.blocksToDeploy = new JumpBlock[size];
this.isDeploying = true;
this.currentDeployIndex = 0;
this.blocksToDeployCount = size;
this.newX = targetX;
this.newY = targetY;
this.newZ = targetZ;
System.out.println("[ShipScanner] Target to deploy: (" + targetX + ", " + targetY + ", " + targetZ + ")");
// Read blocks and TileEntities from NBT to internal storage array
System.out.println("[ShipScanner] Loading blocks...");
byte localBlocks[] = schematic.getByteArray("Blocks");
byte localMetadata[] = schematic.getByteArray("Data");
boolean extra = schematic.hasKey("Add") || schematic.hasKey("AddBlocks");
byte extraBlocks[] = null;
byte extraBlocksNibble[] = null;
if (schematic.hasKey("AddBlocks")) {
extraBlocksNibble = schematic.getByteArray("AddBlocks");
extraBlocks = new byte[extraBlocksNibble.length * 2];
for (int i = 0; i < extraBlocksNibble.length; i++) {
extraBlocks[i * 2 + 0] = (byte) ((extraBlocksNibble[i] >> 4) & 0xF);
extraBlocks[i * 2 + 1] = (byte) (extraBlocksNibble[i] & 0xF);
}
} else if (schematic.hasKey("Add")) {
extraBlocks = schematic.getByteArray("Add");
}
// Load Tile Entities
System.out.println("[ShipScanner] Loading TileEntities...");
NBTTagCompound[] tileEntities = new NBTTagCompound[size];
NBTTagList tileEntitiesList = schematic.getTagList("TileEntities");
for (int i = 0; i < tileEntitiesList.tagCount(); i++) {
NBTTagCompound teTag = (NBTTagCompound) tileEntitiesList.tagAt(i);
int teX = teTag.getInteger("x");
int teY = teTag.getInteger("y");
int teZ = teTag.getInteger("z");
System.out.println("[ShipScanner] Loaded TE: " + teTag.getString("id"));
tileEntities[teX + (teY * length + teZ) * width] = teTag;
}
// Create list of blocks to deploy
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
for (int z = 0; z < length; z++) {
JumpBlock jb = new JumpBlock();
jb.blockID = (localBlocks[x + (y * length + z) * width]) & 0xFF;
if (extra)
jb.blockID |= ((extraBlocks[x + (y * length + z) * width]) & 0xFF) << 8;
jb.blockMeta = (localMetadata[x + (y * length + z) * width]) & 0xFF;
jb.blockNBT = tileEntities[x + (y * length + z) * width];
jb.x = x;
jb.y = y;
jb.z = z;
if (jb.blockID != 0 && Block.blocksList[jb.blockID] != null) {
System.out.print("[ShipScanner] Saving block: " + Block.blocksList[jb.blockID].getUnlocalizedName() + ", TE: ");
if (tileEntities[x + (y * length + z) * width] == null) {
System.out.println("null!");
} else
System.out.println(tileEntities[x + (y * length + z) * width].getString("id"));
}
blocksToDeploy[x + (y * length + z) * width] = jb;
}
}
}
switchState(1);
System.out.println("[ShipScanner] Ship deployed.");
return new Object[] { 3, "Ship deployed." };
}
@Override
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
this.currentEnergyValue = tag.getInteger("energy");
}
@Override
public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
tag.setInteger("energy", this.getCurrentEnergyValue());
}
// CC
// IPeripheral methods implementation
@Override
public String getType() {
return "shipscanner";
}
@Override
public String[] getMethodNames() {
return methodsArray;
}
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context,
int method, Object[] arguments) throws Exception {
switch (method) {
case 0: // scanShip()
// Already scanning?
if (this.state == 1)
return new Object[] { false, 0, "Already scanning" };
if (core != null && isEnoughEnergyForScan()) {
scanShip();
} else if (core == null) {
return new Object[] { false, 1, "Warp-Core not found" };
} else {
return new Object[] { false, 2, "Not enough energy!" };
}
break;
case 1: // getSchematicFileName()
if (state != 0 && !schematicFileName.isEmpty())
return new Object[] { "Scanning in process. Please wait." };
return new Object[] { schematicFileName };
case 2: // getEnergyLevel()
return new Object[] { currentEnergyValue };
case 3: // deployShipFromSchematic(schematicFileName, offsetX, offsetY, offsetZ)
if (arguments.length == 4) {
String fileName = (String)arguments[0];
int x = ((Double)arguments[1]).intValue();
int y = ((Double)arguments[2]).intValue();
int z = ((Double)arguments[3]).intValue();
if (!new File(SCHEMATICS_DIR + fileName).exists())
return new Object[] { 0, "Specified .schematic file not found!" };
else
{
System.out.println("[ShipScanner] Trying to deploy ship");
return deployShip(fileName, x, y, z);
}
} else
return new Object[] { 4, ".schematic file name not specified or invalid arguments count!" };
}
return null;
}
@Override
public boolean canAttachToSide(int side) {
return true;
}
@Override
public void attach(IComputerAccess computer) {
}
@Override
public void detach(IComputerAccess computer) {
}
// IEnergySink methods implementation
@Override
public double demandedEnergyUnits() {
return (MAX_ENERGY_VALUE - currentEnergyValue);
}
@Override
public double injectEnergyUnits(ForgeDirection directionFrom, double amount) {
double leftover = 0;
currentEnergyValue += Math.round(amount);
if (getCurrentEnergyValue() > MAX_ENERGY_VALUE) {
leftover = (getCurrentEnergyValue() - MAX_ENERGY_VALUE);
currentEnergyValue = MAX_ENERGY_VALUE;
}
return leftover;
}
@Override
public int getMaxSafeInput() {
return Integer.MAX_VALUE;
}
@Override
public boolean acceptsEnergyFrom(TileEntity emitter,
ForgeDirection direction) {
return true;
}
/**
* @return the currentEnergyValue
*/
public int getCurrentEnergyValue() {
return currentEnergyValue;
}
public int collectAllEnergy() {
int energy = currentEnergyValue;
currentEnergyValue = 0;
return energy;
}
@Override
public void onChunkUnload() {
if (addedToEnergyNet) {
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
addedToEnergyNet = false;
}
}
@Override
public void invalidate() {
if (addedToEnergyNet) {
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
addedToEnergyNet = false;
}
super.invalidate();
}
public boolean moveBlockSimple(JumpBlock shipBlock)
{
try
{
if (shipBlock == null)
{
return false;
}
int oldX = shipBlock.x;
int oldY = shipBlock.y;
int oldZ = shipBlock.z;
int blockID = shipBlock.blockID;
int blockMeta = shipBlock.blockMeta;
mySetBlock(worldObj, oldX + newX, oldY + newY, oldZ + newZ, blockID, blockMeta, 2);
NBTTagCompound oldnbt = new NBTTagCompound();
oldnbt = shipBlock.blockNBT;
if (oldnbt != null) {
TileEntity newTileEntity;
newTileEntity = TileEntity.createAndLoadEntity(oldnbt);
newTileEntity.worldObj = worldObj;
newTileEntity.validate();
worldObj.setBlockTileEntity(oldX + newX, oldY + newY, oldZ + newZ, newTileEntity);
}
}
catch (Exception exception)
{
exception.printStackTrace();
return false;
}
return true;
}
// Own implementation of setting blocks without light recalculation in optimization purposes
public boolean mySetBlock(World w, int x, int y, int z, int blockId, int blockMeta, int par6)
{
if (x >= -30000000 && z >= -30000000 && x < 30000000 && z < 30000000)
{
if (y < 0)
{
return false;
}
else if (y >= 256)
{
return false;
}
else
{
w.markBlockForUpdate(x, y, z);
Chunk chunk = w.getChunkFromChunkCoords(x >> 4, z >> 4);
return myChunkSBIDWMT(chunk, x & 15, y, z & 15, blockId, blockMeta);
}
}
else
{
return false;
}
}
public boolean myChunkSBIDWMT(Chunk c, int x, int y, int z, int blockId, int blockMeta)
{
int j1 = z << 4 | x;
if (y >= c.precipitationHeightMap[j1] - 1)
{
c.precipitationHeightMap[j1] = -999;
}
//int k1 = c.heightMap[j1];
int l1 = c.getBlockID(x, y, z);
int i2 = c.getBlockMetadata(x, y, z);
if (l1 == blockId && i2 == blockMeta)
{
return false;
}
else
{
ExtendedBlockStorage[] storageArrays = c.getBlockStorageArray();
ExtendedBlockStorage extendedblockstorage = storageArrays[y >> 4];
if (extendedblockstorage == null)
{
if (blockId == 0)
{
return false;
}
extendedblockstorage = storageArrays[y >> 4] = new ExtendedBlockStorage(y >> 4 << 4, !c.worldObj.provider.hasNoSky);
}
int j2 = c.xPosition * 16 + x;
int k2 = c.zPosition * 16 + z;
extendedblockstorage.setExtBlockID(x, y & 15, z, blockId);
if (l1 != 0)
{
if (!c.worldObj.isRemote)
{
Block.blocksList[l1].breakBlock(c.worldObj, j2, y, k2, l1, i2);
}
else if (Block.blocksList[l1] != null && Block.blocksList[l1].hasTileEntity(i2))
{
TileEntity te = worldObj.getBlockTileEntity(j2, y, k2);
if (te != null && te.shouldRefresh(l1, blockId, i2, blockMeta, worldObj, j2, y, k2))
{
c.worldObj.removeBlockTileEntity(j2, y, k2);
}
}
}
if (extendedblockstorage.getExtBlockID(x, y & 15, z) != blockId)
{
return false;
}
else
{
extendedblockstorage.setExtBlockMetadata(x, y & 15, z, blockMeta);
// Removed light recalculations
/*if (flag)
{
c.generateSkylightMap();
}
else
{
if (c.getBlockLightOpacity(par1, par2, par3) > 0)
{
if (par2 >= k1)
{
c.relightBlock(par1, par2 + 1, par3);
}
}
else if (par2 == k1 - 1)
{
c.relightBlock(par1, par2, par3);
}
c.propagateSkylightOcclusion(par1, par3);
}*/
TileEntity tileentity;
if (blockId != 0)
{
if (Block.blocksList[blockId] != null && Block.blocksList[blockId].hasTileEntity(blockMeta))
{
tileentity = c.getChunkBlockTileEntity(x, y, z);
if (tileentity == null)
{
tileentity = Block.blocksList[blockId].createTileEntity(c.worldObj, blockMeta);
c.worldObj.setBlockTileEntity(j2, y, k2, tileentity);
}
if (tileentity != null)
{
tileentity.updateContainingBlockInfo();
tileentity.blockMetadata = blockMeta;
}
}
}
c.isModified = true;
return true;
}
}
}
}

View file

@ -6,8 +6,8 @@ import net.minecraft.entity.Entity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
/**
* @authorCr0s
/** Registry of active Warp Cores in world
* @author Cr0s
*/
public class WarpCoresRegistry
{
@ -143,7 +143,7 @@ public class WarpCoresRegistry
double d5 = c.zCoord - core.zCoord;
double distance = MathHelper.sqrt_double(d3 * d3 + d4 * d4 + d5 * d5);
if (distance <= (2 * core.MAX_SHIP_SIDE) - 1)
if (distance <= (2 * WarpDriveConfig.i.WC_MAX_SHIP_SIDE) - 1)
{
// Check for warpfields intersections
core.prepareToJump(); // calculate spatial parameters

View file

@ -34,265 +34,308 @@ import net.minecraftforge.common.ForgeChunkManager.LoadingCallback;
import net.minecraftforge.common.ForgeChunkManager.Ticket;
import net.minecraftforge.common.MinecraftForge;
@Mod(modid = "WarpDrive", name = "WarpDrive", version = "1.1.5_ZLO", dependencies="required-after:IC2; after:required-AppliedEnergistics; after:extracells; required-after:ComputerCraft; after:CCTurtle; after:gregtech_addon; after:AdvancedSolarPanel; after:AtomicScience; after:ICBM|Explosion; after:MFFS; after:GraviSuite")
@NetworkMod(clientSideRequired = true, serverSideRequired = true, channels = {"WarpDriveBeam", "WarpDriveFreq", "WarpDriveLaserT"}, packetHandler = PacketHandler.class)
@Mod(modid = "WarpDrive", name = "WarpDrive", version = "1.2.0_ZLO", dependencies="required-after:IC2; after:required-AppliedEnergistics; after:extracells; required-after:ComputerCraft; after:CCTurtle; after:gregtech_addon; after:AdvancedSolarPanel; after:AtomicScience; after:ICBM|Explosion; after:MFFS; after:GraviSuite")
@NetworkMod(clientSideRequired = true, serverSideRequired = true, channels = {
"WarpDriveBeam",
"WarpDriveFreq",
"WarpDriveLaserT",
"WarpDriveCloaks" }, packetHandler = PacketHandler.class)
/**
* @author Cr0s
*/
public class WarpDrive implements LoadingCallback
{
// World limits
public final static int WORLD_LIMIT_BLOCKS = 100000;
// World limits
public final static int WORLD_LIMIT_BLOCKS = 100000;
public static Block warpCore;
public static Block protocolBlock;
public static Block radarBlock;
public static Block isolationBlock;
public static Block airgenBlock;
public static Block laserBlock;
public static Block laserCamBlock;
public static Block cameraBlock;
public static Block monitorBlock;
public static Block boosterBlock;
public static Block miningLaserBlock;
public static Block liftBlock;
public static Block warpCore;
public static Block protocolBlock;
public static Block radarBlock;
public static Block isolationBlock;
public static Block airgenBlock;
public static Block laserBlock;
public static Block laserCamBlock;
public static Block cameraBlock;
public static Block monitorBlock;
public static Block boosterBlock;
public static Block miningLaserBlock;
public static Block liftBlock;
public static Block scannerBlock;
public static Block cloakBlock;
public static Block cloakCoilBlock;
public static Block airBlock;
public static Block gasBlock;
public static Block airBlock;
public static Block gasBlock;
public static Block iridiumBlock;
public static Block iridiumBlock;
public static BiomeGenBase spaceBiome;
public World space;
private int spaceProviderID;
public int spaceDimID;
public SpaceWorldGenerator spaceWorldGenerator;
public HyperSpaceWorldGenerator hyperSpaceWorldGenerator;
public static BiomeGenBase spaceBiome;
public World space;
private int spaceProviderID;
public int spaceDimID;
public SpaceWorldGenerator spaceWorldGenerator;
public HyperSpaceWorldGenerator hyperSpaceWorldGenerator;
public World hyperSpace;
private int hyperSpaceProviderID;
public int hyperSpaceDimID;
public World hyperSpace;
private int hyperSpaceProviderID;
public int hyperSpaceDimID;
@Instance("WarpDrive")
public static WarpDrive instance;
@SidedProxy(clientSide = "cr0s.WarpDrive.ClientProxy", serverSide = "cr0s.WarpDrive.CommonProxy")
public static CommonProxy proxy;
@Instance("WarpDrive")
public static WarpDrive instance;
@SidedProxy(clientSide = "cr0s.WarpDrive.ClientProxy", serverSide = "cr0s.WarpDrive.CommonProxy")
public static CommonProxy proxy;
public WarpCoresRegistry registry;
public JumpGatesRegistry jumpGates;
public WarpCoresRegistry registry;
public JumpGatesRegistry jumpGates;
public CloakManager cloaks;
public CamRegistry cams;
public boolean isOverlayEnabled = false;
public int overlayType = 0;
public CamRegistry cams;
public boolean isOverlayEnabled = false;
public int overlayType = 0;
@EventHandler
//@PreInit
public void preInit(FMLPreInitializationEvent event)
{
WarpDriveConfig.Init(new Configuration(event.getSuggestedConfigurationFile()));
@EventHandler
//@PreInit
public void preInit(FMLPreInitializationEvent event)
{
WarpDriveConfig.Init(new Configuration(event.getSuggestedConfigurationFile()));
if (FMLCommonHandler.instance().getSide().isClient())
{
System.out.println("[WarpDrive] Registering sounds event handler...");
MinecraftForge.EVENT_BUS.register(new SoundHandler());
}
}
if (FMLCommonHandler.instance().getSide().isClient())
{
System.out.println("[WarpDrive] Registering sounds event handler...");
MinecraftForge.EVENT_BUS.register(new SoundHandler());
}
}
@Init
public void load(FMLInitializationEvent event)
{
@Init
public void load(FMLInitializationEvent event)
{
WarpDriveConfig.i.Init2();
// WARP CORE
this.warpCore = new BlockReactor(WarpDriveConfig.i.coreID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("Warp Core");
LanguageRegistry.addName(warpCore, "Warp Core");
GameRegistry.registerBlock(warpCore, "warpCore");
GameRegistry.registerTileEntity(TileEntityReactor.class, "warpCore");
// CORE CONTROLLER
this.protocolBlock = new BlockProtocol(WarpDriveConfig.i.controllerID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("Warp Controller");
LanguageRegistry.addName(protocolBlock, "Warp Controller");
GameRegistry.registerBlock(protocolBlock, "protocolBlock");
GameRegistry.registerTileEntity(TileEntityProtocol.class, "protocolBlock");
// WARP RADAR
this.radarBlock = new BlockRadar(WarpDriveConfig.i.radarID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("W-Radar");
LanguageRegistry.addName(radarBlock, "W-Radar");
GameRegistry.registerBlock(radarBlock, "radarBlock");
GameRegistry.registerTileEntity(TileEntityRadar.class, "radarBlock");
// WARP ISOLATION
this.isolationBlock = new BlockWarpIsolation(WarpDriveConfig.i.isolationID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("Warp-Field Isolation Block");
LanguageRegistry.addName(isolationBlock, "Warp-Field Isolation Block");
GameRegistry.registerBlock(isolationBlock, "isolationBlock");
// AIR GENERATOR
this.airgenBlock = new BlockAirGenerator(WarpDriveConfig.i.airgenID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("Air Generator");
LanguageRegistry.addName(airgenBlock, "Air Generator");
GameRegistry.registerBlock(airgenBlock, "airgenBlock");
GameRegistry.registerTileEntity(TileEntityAirGenerator.class, "airgenBlock");
// AIR BLOCK
this.airBlock = (new BlockAir(WarpDriveConfig.i.airID)).setHardness(0.0F).setUnlocalizedName("Air block");
LanguageRegistry.addName(airBlock, "Air block");
GameRegistry.registerBlock(airBlock, "airBlock");
// GAS BLOCK
this.gasBlock = (new BlockGas(WarpDriveConfig.i.gasID)).setHardness(0.0F).setUnlocalizedName("Gas block");
LanguageRegistry.addName(gasBlock, "Gas block");
GameRegistry.registerBlock(gasBlock, "gasBlock");
// LASER EMITTER
this.laserBlock = new BlockLaser(WarpDriveConfig.i.laserID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("Laser Emitter");
LanguageRegistry.addName(laserBlock, "Laser Emitter");
GameRegistry.registerBlock(laserBlock, "laserBlock");
GameRegistry.registerTileEntity(TileEntityLaser.class, "laserBlock");
// LASER EMITTER WITH CAMERA
this.laserCamBlock = new BlockLaserCam(WarpDriveConfig.i.laserCamID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("Laser Emitter + Camera");
LanguageRegistry.addName(laserCamBlock, "Laser Emitter + Camera");
GameRegistry.registerBlock(laserCamBlock, "laserCamBlock");
// CAMERA
this.cameraBlock = new BlockCamera(WarpDriveConfig.i.camID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("Camera block");
LanguageRegistry.addName(cameraBlock, "Camera");
GameRegistry.registerBlock(cameraBlock, "cameraBlock");
GameRegistry.registerTileEntity(TileEntityCamera.class, "cameraBlock");
// MONITOR
this.monitorBlock = new BlockMonitor(WarpDriveConfig.i.monitorID)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("Monitor");
LanguageRegistry.addName(monitorBlock, "Monitor");
GameRegistry.registerBlock(monitorBlock, "monitorBlock");
GameRegistry.registerTileEntity(TileEntityMonitor.class, "monitorBlock");
// MINING LASER
this.miningLaserBlock = new BlockMiningLaser(WarpDriveConfig.i.miningLaserID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("Mining Laser");
LanguageRegistry.addName(miningLaserBlock, "Mining Laser");
GameRegistry.registerBlock(miningLaserBlock, "miningLaserBlock");
GameRegistry.registerTileEntity(TileEntityMiningLaser.class, "miningLaserBlock");
// PARTICLE BOOSTER
this.boosterBlock = new BlockParticleBooster(WarpDriveConfig.i.particleBoosterID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("Particle Booster");
LanguageRegistry.addName(boosterBlock, "Particle Booster");
GameRegistry.registerBlock(boosterBlock, "boosterBlock");
GameRegistry.registerTileEntity(TileEntityParticleBooster.class, "boosterBlock");
// RAY LIFT
this.liftBlock = new BlockLift(WarpDriveConfig.i.liftID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("Laser lift");
LanguageRegistry.addName(liftBlock, "Laser lift");
GameRegistry.registerBlock(liftBlock, "liftBlock");
GameRegistry.registerTileEntity(TileEntityLift.class, "liftBlock");
// IRIDIUM BLOCK
this.iridiumBlock = new BlockIridium(WarpDriveConfig.i.iridiumID)
.setHardness(0.8F).setResistance(150 * 4).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("Block of Iridium");
LanguageRegistry.addName(iridiumBlock, "Block of Iridium");
GameRegistry.registerBlock(iridiumBlock, "iridiumBlock");
proxy.registerEntities();
ForgeChunkManager.setForcedChunkLoadingCallback(instance, instance);
spaceWorldGenerator = new SpaceWorldGenerator();
GameRegistry.registerWorldGenerator(spaceWorldGenerator);
hyperSpaceWorldGenerator = new HyperSpaceWorldGenerator();
GameRegistry.registerWorldGenerator(hyperSpaceWorldGenerator);
registerSpaceDimension();
registerHyperSpaceDimension();
MinecraftForge.EVENT_BUS.register(new SpaceEventHandler());
// WARP CORE
this.warpCore = new BlockReactor(WarpDriveConfig.i.coreID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("Warp Core");
LanguageRegistry.addName(warpCore, "Warp Core");
GameRegistry.registerBlock(warpCore, "warpCore");
GameRegistry.registerTileEntity(TileEntityReactor.class, "warpCore");
// CORE CONTROLLER
this.protocolBlock = new BlockProtocol(WarpDriveConfig.i.controllerID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("Warp Controller");
LanguageRegistry.addName(protocolBlock, "Warp Controller");
GameRegistry.registerBlock(protocolBlock, "protocolBlock");
GameRegistry.registerTileEntity(TileEntityProtocol.class, "protocolBlock");
// WARP RADAR
this.radarBlock = new BlockRadar(WarpDriveConfig.i.radarID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("W-Radar");
LanguageRegistry.addName(radarBlock, "W-Radar");
GameRegistry.registerBlock(radarBlock, "radarBlock");
GameRegistry.registerTileEntity(TileEntityRadar.class, "radarBlock");
// WARP ISOLATION
this.isolationBlock = new BlockWarpIsolation(WarpDriveConfig.i.isolationID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("Warp-Field Isolation Block");
LanguageRegistry.addName(isolationBlock, "Warp-Field Isolation Block");
GameRegistry.registerBlock(isolationBlock, "isolationBlock");
// AIR GENERATOR
this.airgenBlock = new BlockAirGenerator(WarpDriveConfig.i.airgenID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("Air Generator");
LanguageRegistry.addName(airgenBlock, "Air Generator");
GameRegistry.registerBlock(airgenBlock, "airgenBlock");
GameRegistry.registerTileEntity(TileEntityAirGenerator.class, "airgenBlock");
// AIR BLOCK
this.airBlock = (new BlockAir(WarpDriveConfig.i.airID)).setHardness(0.0F).setUnlocalizedName("Air block");
LanguageRegistry.addName(airBlock, "Air block");
GameRegistry.registerBlock(airBlock, "airBlock");
// GAS BLOCK
this.gasBlock = (new BlockGas(WarpDriveConfig.i.gasID)).setHardness(0.0F).setUnlocalizedName("Gas block");
LanguageRegistry.addName(gasBlock, "Gas block");
GameRegistry.registerBlock(gasBlock, "gasBlock");
// LASER EMITTER
this.laserBlock = new BlockLaser(WarpDriveConfig.i.laserID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("Laser Emitter");
LanguageRegistry.addName(laserBlock, "Laser Emitter");
GameRegistry.registerBlock(laserBlock, "laserBlock");
GameRegistry.registerTileEntity(TileEntityLaser.class, "laserBlock");
// LASER EMITTER WITH CAMERA
this.laserCamBlock = new BlockLaserCam(WarpDriveConfig.i.laserCamID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("Laser Emitter + Camera");
LanguageRegistry.addName(laserCamBlock, "Laser Emitter + Camera");
GameRegistry.registerBlock(laserCamBlock, "laserCamBlock");
// CAMERA
this.cameraBlock = new BlockCamera(WarpDriveConfig.i.camID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("Camera block");
LanguageRegistry.addName(cameraBlock, "Camera");
GameRegistry.registerBlock(cameraBlock, "cameraBlock");
GameRegistry.registerTileEntity(TileEntityCamera.class, "cameraBlock");
// MONITOR
this.monitorBlock = new BlockMonitor(WarpDriveConfig.i.monitorID)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("Monitor");
LanguageRegistry.addName(monitorBlock, "Monitor");
GameRegistry.registerBlock(monitorBlock, "monitorBlock");
GameRegistry.registerTileEntity(TileEntityMonitor.class, "monitorBlock");
// MINING LASER
this.miningLaserBlock = new BlockMiningLaser(WarpDriveConfig.i.miningLaserID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("Mining Laser");
LanguageRegistry.addName(miningLaserBlock, "Mining Laser");
GameRegistry.registerBlock(miningLaserBlock, "miningLaserBlock");
GameRegistry.registerTileEntity(TileEntityMiningLaser.class, "miningLaserBlock");
// PARTICLE BOOSTER
this.boosterBlock = new BlockParticleBooster(WarpDriveConfig.i.particleBoosterID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("Particle Booster");
LanguageRegistry.addName(boosterBlock, "Particle Booster");
GameRegistry.registerBlock(boosterBlock, "boosterBlock");
GameRegistry.registerTileEntity(TileEntityParticleBooster.class, "boosterBlock");
// LASER LIFT
this.liftBlock = new BlockLift(WarpDriveConfig.i.liftID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("Laser lift");
LanguageRegistry.addName(liftBlock, "Laser lift");
GameRegistry.registerBlock(liftBlock, "liftBlock");
GameRegistry.registerTileEntity(TileEntityLift.class, "liftBlock");
// IRIDIUM BLOCK
this.iridiumBlock = new BlockIridium(WarpDriveConfig.i.iridiumID)
.setHardness(0.8F).setResistance(150 * 4).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("Block of Iridium");
LanguageRegistry.addName(iridiumBlock, "Block of Iridium");
GameRegistry.registerBlock(iridiumBlock, "iridiumBlock");
if (FMLCommonHandler.instance().getEffectiveSide().isClient())
{
MinecraftForge.EVENT_BUS.register(new CameraOverlay(Minecraft.getMinecraft()));
}
}
// SHIP SCANNER
this.scannerBlock = new BlockShipScanner(WarpDriveConfig.i.shipScannerID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("Ship Scanner");
@PostInit
public void postInit(FMLPostInitializationEvent event)
{
space = DimensionManager.getWorld(spaceDimID);
hyperSpace = DimensionManager.getWorld(hyperSpaceDimID);
GameRegistry.addRecipe(new ItemStack(warpCore), "ici", "cmc", "ici",
'i', WarpDriveConfig.i.getIC2Item("iridiumPlate"), 'm', WarpDriveConfig.i.getIC2Item("advancedMachine"), 'c', WarpDriveConfig.i.getIC2Item("advancedCircuit"));
GameRegistry.addRecipe(new ItemStack(protocolBlock), "iic", "imi", "cii",
'i', WarpDriveConfig.i.getIC2Item("iridiumPlate"), 'm', WarpDriveConfig.i.getIC2Item("advancedMachine"), 'c', WarpDriveConfig.i.getIC2Item("advancedCircuit"));
GameRegistry.addRecipe(new ItemStack(radarBlock), "ifi", "imi", "imi",
'i', WarpDriveConfig.i.getIC2Item("iridiumPlate"), 'm', WarpDriveConfig.i.getIC2Item("advancedMachine"), 'f', WarpDriveConfig.i.getIC2Item("frequencyTransmitter"));
GameRegistry.addRecipe(new ItemStack(isolationBlock), "iii", "idi", "iii",
'i', WarpDriveConfig.i.getIC2Item("iridiumPlate"), 'm', WarpDriveConfig.i.getIC2Item("advancedMachine"), 'd', Block.blockDiamond);
GameRegistry.addRecipe(new ItemStack(airgenBlock), "lcl", "lml", "lll",
'l', Block.leaves, 'm', WarpDriveConfig.i.getIC2Item("advancedMachine"), 'c', WarpDriveConfig.i.getIC2Item("advancedCircuit"));
GameRegistry.addRecipe(new ItemStack(laserBlock), "sss", "ama", "aaa",
'm', WarpDriveConfig.i.getIC2Item("advancedMachine"), 'a', WarpDriveConfig.i.Compot, 's', WarpDriveConfig.i.getIC2Item("advancedCircuit"));
GameRegistry.addRecipe(new ItemStack(miningLaserBlock), "aaa", "ama", "ccc",
'c', WarpDriveConfig.i.getIC2Item("advancedCircuit"), 'a', WarpDriveConfig.i.Compot, 'm', WarpDriveConfig.i.getIC2Item("miner"));
GameRegistry.addRecipe(new ItemStack(boosterBlock), "afc", "ama", "cfa",
'c', WarpDriveConfig.i.getIC2Item("advancedCircuit"), 'a', WarpDriveConfig.i.Compot, 'f', WarpDriveConfig.i.getIC2Item("glassFiberCableItem"), 'm', WarpDriveConfig.i.getIC2Item("mfeUnit"));
GameRegistry.addRecipe(new ItemStack(liftBlock), "aca", "ama", "a#a",
'c', WarpDriveConfig.i.getIC2Item("advancedCircuit"), 'a', WarpDriveConfig.i.Compot, 'm', WarpDriveConfig.i.getIC2Item("magnetizer"));
/*
GameRegistry.addRecipe(new ItemStack(Item.enderPearl), "uuu", "uuu", "uuu",
'u', WarpDriveConfig.i.getIC2Item("uraniumDrop"));
*/
GameRegistry.addRecipe(new ItemStack(iridiumBlock), "iii", "iii", "iii",
'i', WarpDriveConfig.i.getIC2Item("iridiumPlate"));
GameRegistry.addShapelessRecipe(new ItemStack(WarpDriveConfig.i.getIC2Item("iridiumPlate").getItem(), 9), new ItemStack(iridiumBlock));
GameRegistry.addRecipe(new ItemStack(laserCamBlock), "imi", "cec", "#k#",
'i', WarpDriveConfig.i.getIC2Item("iridiumPlate"), 'm', WarpDriveConfig.i.getIC2Item("advancedMachine"), 'c', WarpDriveConfig.i.getIC2Item("advancedCircuit"), 'e', laserBlock, 'k', cameraBlock);
GameRegistry.addRecipe(new ItemStack(cameraBlock), "cgc", "gmg", "cgc",
'm', WarpDriveConfig.i.getIC2Item("advancedMachine"), 'c', WarpDriveConfig.i.getIC2Item("advancedCircuit"), 'g', Block.glass);
GameRegistry.addRecipe(new ItemStack(monitorBlock), "gcg", "gmg", "ggg",
'm', WarpDriveConfig.i.getIC2Item("advancedMachine"), 'c', WarpDriveConfig.i.getIC2Item("advancedCircuit"), 'g', Block.glass);
registry = new WarpCoresRegistry();
LanguageRegistry.addName(scannerBlock, "Ship Scanner");
GameRegistry.registerBlock(scannerBlock, "scannerBlock");
GameRegistry.registerTileEntity(TileEntityShipScanner.class, "scannerBlock");
if (FMLCommonHandler.instance().getEffectiveSide().isServer())
{
jumpGates = new JumpGatesRegistry();
}
else
{
cams = new CamRegistry();
}
}
// CLOAKING DEVICE CORE
this.cloakBlock = new BlockCloakingDeviceCore(WarpDriveConfig.i.cloakCoreID, 0, Material.rock)
.setHardness(0.5F).setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("Cloaking Device Core");
private void registerSpaceDimension()
{
spaceBiome = (new BiomeSpace(23)).setColor(0).setDisableRain().setBiomeName("Space");
this.spaceProviderID = 14;
DimensionManager.registerProviderType(this.spaceProviderID, SpaceProvider.class, true);
this.spaceDimID = DimensionManager.getNextFreeDimId();
DimensionManager.registerDimension(this.spaceDimID, this.spaceProviderID);
}
LanguageRegistry.addName(cloakBlock, "Cloaking Device Core");
GameRegistry.registerBlock(cloakBlock, "cloakBlock");
GameRegistry.registerTileEntity(TileEntityCloakingDeviceCore.class, "cloakBlock");
private void registerHyperSpaceDimension()
{
this.hyperSpaceProviderID = 15;
DimensionManager.registerProviderType(this.hyperSpaceProviderID, HyperSpaceProvider.class, true);
this.hyperSpaceDimID = DimensionManager.getNextFreeDimId();
DimensionManager.registerDimension(this.hyperSpaceDimID, this.hyperSpaceProviderID);
}
// CLOAKING DEVICE COIL
this.cloakCoilBlock = new BlockCloakingCoil(WarpDriveConfig.i.cloakCoilID, 0, Material.rock)
.setHardness(0.5F)
.setStepSound(Block.soundMetalFootstep)
.setCreativeTab(CreativeTabs.tabRedstone)
.setUnlocalizedName("Cloaking Device Coil");
@ServerStarting
public void serverLoad(FMLServerStartingEvent event)
{
event.registerServerCommand(new GenerateCommand());
event.registerServerCommand(new SpaceTpCommand());
event.registerServerCommand(new InvisibleCommand());
}
LanguageRegistry.addName(cloakCoilBlock, "Cloaking Device Coil");
GameRegistry.registerBlock(cloakCoilBlock, "cloakCoilBlock");
@Override
public void ticketsLoaded(List<Ticket> tickets, World world)
{
for (Ticket ticket : tickets)
{
ForgeChunkManager.releaseTicket(ticket);
}
}
proxy.registerEntities();
ForgeChunkManager.setForcedChunkLoadingCallback(instance, instance);
spaceWorldGenerator = new SpaceWorldGenerator();
GameRegistry.registerWorldGenerator(spaceWorldGenerator);
hyperSpaceWorldGenerator = new HyperSpaceWorldGenerator();
GameRegistry.registerWorldGenerator(hyperSpaceWorldGenerator);
registerSpaceDimension();
registerHyperSpaceDimension();
MinecraftForge.EVENT_BUS.register(new SpaceEventHandler());
if (FMLCommonHandler.instance().getEffectiveSide().isClient())
{
MinecraftForge.EVENT_BUS.register(new CameraOverlay(Minecraft.getMinecraft()));
}
}
@PostInit
public void postInit(FMLPostInitializationEvent event)
{
space = DimensionManager.getWorld(spaceDimID);
hyperSpace = DimensionManager.getWorld(hyperSpaceDimID);
GameRegistry.addRecipe(new ItemStack(warpCore), "ici", "cmc", "ici",
'i', WarpDriveConfig.i.getIC2Item("iridiumPlate"), 'm', WarpDriveConfig.i.getIC2Item("advancedMachine"), 'c', WarpDriveConfig.i.getIC2Item("advancedCircuit"));
GameRegistry.addRecipe(new ItemStack(protocolBlock), "iic", "imi", "cii",
'i', WarpDriveConfig.i.getIC2Item("iridiumPlate"), 'm', WarpDriveConfig.i.getIC2Item("advancedMachine"), 'c', WarpDriveConfig.i.getIC2Item("advancedCircuit"));
GameRegistry.addRecipe(new ItemStack(radarBlock), "ifi", "imi", "imi",
'i', WarpDriveConfig.i.getIC2Item("iridiumPlate"), 'm', WarpDriveConfig.i.getIC2Item("advancedMachine"), 'f', WarpDriveConfig.i.getIC2Item("frequencyTransmitter"));
GameRegistry.addRecipe(new ItemStack(isolationBlock), "iii", "idi", "iii",
'i', WarpDriveConfig.i.getIC2Item("iridiumPlate"), 'm', WarpDriveConfig.i.getIC2Item("advancedMachine"), 'd', Block.blockDiamond);
GameRegistry.addRecipe(new ItemStack(airgenBlock), "lcl", "lml", "lll",
'l', Block.leaves, 'm', WarpDriveConfig.i.getIC2Item("advancedMachine"), 'c', WarpDriveConfig.i.getIC2Item("advancedCircuit"));
GameRegistry.addRecipe(new ItemStack(laserBlock), "sss", "ama", "aaa",
'm', WarpDriveConfig.i.getIC2Item("advancedMachine"), 'a', WarpDriveConfig.i.getIC2Item("advancedAlloy"), 's', WarpDriveConfig.i.getIC2Item("advancedCircuit"));
GameRegistry.addRecipe(new ItemStack(miningLaserBlock), "aaa", "ama", "ccc",
'c', WarpDriveConfig.i.getIC2Item("advancedCircuit"), 'a', WarpDriveConfig.i.getIC2Item("advancedAlloy"), 'm', WarpDriveConfig.i.getIC2Item("miner"));
GameRegistry.addRecipe(new ItemStack(boosterBlock), "afc", "ama", "cfa",
'c', WarpDriveConfig.i.getIC2Item("advancedCircuit"), 'a', WarpDriveConfig.i.getIC2Item("advancedAlloy"), 'f', WarpDriveConfig.i.getIC2Item("glassFiberCableItem"), 'm', WarpDriveConfig.i.getIC2Item("mfeUnit"));
GameRegistry.addRecipe(new ItemStack(liftBlock), "aca", "ama", "a#a",
'c', WarpDriveConfig.i.getIC2Item("advancedCircuit"), 'a', WarpDriveConfig.i.getIC2Item("advancedAlloy"), 'm', WarpDriveConfig.i.getIC2Item("magnetizer"));
GameRegistry.addRecipe(new ItemStack(iridiumBlock), "iii", "iii", "iii",
'i', WarpDriveConfig.i.getIC2Item("iridiumPlate"));
GameRegistry.addShapelessRecipe(new ItemStack(WarpDriveConfig.i.getIC2Item("iridiumPlate").getItem(), 9), new ItemStack(iridiumBlock));
GameRegistry.addRecipe(new ItemStack(laserCamBlock), "imi", "cec", "#k#",
'i', WarpDriveConfig.i.getIC2Item("iridiumPlate"), 'm', WarpDriveConfig.i.getIC2Item("advancedMachine"), 'c', WarpDriveConfig.i.getIC2Item("advancedCircuit"), 'e', laserBlock, 'k', cameraBlock);
GameRegistry.addRecipe(new ItemStack(cameraBlock), "cgc", "gmg", "cgc",
'm', WarpDriveConfig.i.getIC2Item("advancedMachine"), 'c', WarpDriveConfig.i.getIC2Item("advancedCircuit"), 'g', Block.glass);
GameRegistry.addRecipe(new ItemStack(monitorBlock), "gcg", "gmg", "ggg",
'm', WarpDriveConfig.i.getIC2Item("advancedMachine"), 'c', WarpDriveConfig.i.getIC2Item("advancedCircuit"), 'g', Block.glass);
GameRegistry.addRecipe(new ItemStack(scannerBlock), "sgs", "mma", "amm",
'm', WarpDriveConfig.i.getIC2Item("advancedMachine"), 'a', WarpDriveConfig.i.getIC2Item("advancedAlloy"), 's', WarpDriveConfig.i.getIC2Item("advancedCircuit"), 'g', Block.glass);
GameRegistry.addRecipe(new ItemStack(cloakBlock), "imi", "mcm", "imi",
'i', iridiumBlock, 'c', cloakCoilBlock, 'm', WarpDriveConfig.i.getIC2Item("advancedMachine"));
GameRegistry.addRecipe(new ItemStack(cloakCoilBlock), "iai", "aca", "iai",
'i', WarpDriveConfig.i.getIC2Item("iridiumPlate"), 'c', WarpDriveConfig.i.getIC2Item("advancedCircuit"), 'a', WarpDriveConfig.i.getIC2Item("advancedAlloy"));
registry = new WarpCoresRegistry();
if (FMLCommonHandler.instance().getEffectiveSide().isServer())
{
jumpGates = new JumpGatesRegistry();
}
else
{
cams = new CamRegistry();
}
}
private void registerSpaceDimension()
{
spaceBiome = (new BiomeSpace(23)).setColor(0).setDisableRain().setBiomeName("Space");
this.spaceProviderID = 14;
DimensionManager.registerProviderType(this.spaceProviderID, SpaceProvider.class, true);
this.spaceDimID = DimensionManager.getNextFreeDimId();
DimensionManager.registerDimension(this.spaceDimID, this.spaceProviderID);
}
private void registerHyperSpaceDimension()
{
this.hyperSpaceProviderID = 15;
DimensionManager.registerProviderType(this.hyperSpaceProviderID, HyperSpaceProvider.class, true);
this.hyperSpaceDimID = DimensionManager.getNextFreeDimId();
DimensionManager.registerDimension(this.hyperSpaceDimID, this.hyperSpaceProviderID);
}
@ServerStarting
public void serverLoad(FMLServerStartingEvent event)
{
cloaks = new CloakManager();
MinecraftForge.EVENT_BUS.register(new CloakChunkWatcher());
event.registerServerCommand(new GenerateCommand());
event.registerServerCommand(new SpaceTpCommand());
event.registerServerCommand(new InvisibleCommand());
}
@Override
public void ticketsLoaded(List<Ticket> tickets, World world)
{
for (Ticket ticket : tickets)
{
ForgeChunkManager.releaseTicket(ticket);
}
}
}

View file

@ -9,7 +9,6 @@ import java.util.Random;
import java.lang.reflect.*;
import cpw.mods.fml.common.Loader;
import net.minecraftforge.common.Configuration;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@ -19,20 +18,69 @@ public class WarpDriveConfig
{
public static WarpDriveConfig i;
private Configuration config;
public int coreID, controllerID, radarID, isolationID, airID, airgenID, gasID, laserID, miningLaserID, particleBoosterID, liftID, laserCamID, camID, monitorID, iridiumID;
public int coreID, controllerID, radarID, isolationID, airID, airgenID, gasID, laserID, miningLaserID, particleBoosterID, liftID, laserCamID, camID, monitorID, iridiumID, shipScannerID, cloakCoreID, cloakCoilID;
//
public boolean isGregLoaded = false, isAELoaded = false, isAEExtraLoaded = false, isAdvSolPanelLoaded = false, isASLoaded = false, isICBMLoaded = false, isMFFSLoaded = false, isGraviSuiteLoaded = false;
//
public int[] IC2_Air;
public int CC_Computer = 0, CC_peripheral = 0, CCT_Turtle = 0, CCT_Upgraded = 0, CCT_Advanced = 0, GT_Ores = 0, GT_Granite = 0, GT_Machine = 0, ASP = 0, AS_Turbine = 0, ICBM_Machine = 0, ICBM_Missile = 0, MFFS_Field = 0;
public ItemStack Compot;
public Set<Integer> SpaceHelmets, Jetpacks, MinerOres;
public Set<Integer> SpaceHelmets, Jetpacks, MinerOres, scannerIgnoreBlocks;
private Class<?> AEBlocks;
private Class<?> AEMaterials;
private Class<?> AEItems;
public Item AEExtraFDI;
public ArrayList<int[]> CommonWorldGenOres;
// Mod config
// Warp Core
public int WC_MAX_ENERGY_VALUE = 100000000;
public int WC_ENERGY_PER_BLOCK_MODE1 = 10; // eU
public int WC_ENERGY_PER_DISTANCE_MODE1 = 100; // eU
public int WC_ENERGY_PER_BLOCK_MODE2 = 1000; // eU
public int WC_ENERGY_PER_DISTANCE_MODE2 = 1000; // eU
public int WC_ENERGY_PER_ENTITY_TO_SPACE = 1000000; // eU
public int WC_MAX_JUMP_DISTANCE = 128; // Maximum jump length value
public int WC_MAX_SHIP_VOLUME_ON_SURFACE = 15000; // Maximum ship mass to jump on earth (15k blocks)
public int WC_MIN_SHIP_VOLUME_FOR_HYPERSPACE = 500; // Minimum ship volume value for
public int WC_MAX_SHIP_SIDE = 100;
public int WC_COOLDOWN_INTERVAL_SECONDS = 4;
public int WC_CORES_REGISTRY_UPDATE_INTERVAL_SECONDS = 10;
public int WC_ISOLATION_UPDATE_INTARVAL_SECONDS = 10;
// Warp Radar
public int WR_MAX_ENERGY_VALUE = 100000000; // 100kk eU
// Particle Booster
public int PB_MAX_ENERGY_VALUE = 100000;
// Mining Laser
public int ML_MAX_BOOSTERS_NUMBER = 1;
public int ML_SCAN_DELAY = 20 * 5;
public int ML_MINE_DELAY = 10;
public int ML_EU_PER_LAYER_SPACE = 500;
public int ML_EU_PER_LAYER_EARTH = 5000;
// Laser Emitter
public int LE_MAX_BOOSTERS_NUMBER = 10;
public int LE_MAX_LASER_ENERGY = 4000000;
public int LE_EMIT_DELAY_TICKS = 20 * 3;
public int LE_EMIT_SCAN_DELAY_TICKS = 10;
public double LE_COLLECT_ENERGY_MULTIPLIER = 0.60D;
public int LE_BEAM_LENGTH_PER_ENERGY_DIVIDER = 5000;
public int LE_ENTITY_HIT_SET_ON_FIRE_TIME = 100;
public int LE_ENTITY_HIT_DAMAGE_PER_ENERGY_DIVIDER = 10000;
public int LE_ENTITY_HIT_EXPLOSION_LASER_ENERGY = 1000000;
public int LE_BLOCK_HIT_CONSUME_ENERGY = 70000;
public int LE_BLOCK_HIT_CONSUME_ENERGY_PER_BLOCK_RESISTANCE = 1000;
public int LE_BLOCK_HIT_CONSUME_ENERGY_PER_DISTANCE = 10;
// Cloaking device core
public int CD_MAX_CLOAKING_FIELD_SIDE = 100;
public int CD_ENERGY_PER_BLOCK_TIER1 = 1000;
public int CD_ENERGY_PER_BLOCK_TIER2 = 5000;
public int CD_FIELD_REFRESH_INTERVAL_SECONDS = 10;
public int CD_COIL_CAPTURE_BLOCKS = 5;
private WarpDriveConfig() {}
public ItemStack getIC2Item(String id)
@ -92,6 +140,61 @@ public class WarpDriveConfig
i.config = config;
}
public void loadWarpDriveConfig()
{
// Warp Core
WC_MAX_ENERGY_VALUE = config.get("WarpCore", "max_energy_value", 100000000).getInt();
WC_ENERGY_PER_BLOCK_MODE1 = config.get("WarpCore", "energy_per_block_mode1", 10).getInt();
WC_ENERGY_PER_DISTANCE_MODE1 = config.get("WarpCore", "energy_per_distance_mode1", 100).getInt();
WC_ENERGY_PER_DISTANCE_MODE2 = config.get("WarpCore", "energy_per_distance_mode2", 1000).getInt();
WC_ENERGY_PER_BLOCK_MODE2 = config.get("WarpCore", "energy_per_block_mode2", 1000).getInt();
WC_ENERGY_PER_ENTITY_TO_SPACE = config.get("WarpCore", "energy_ped_entity_to_space", 1000000).getInt();
WC_MAX_JUMP_DISTANCE = config.get("WarpCore", "max_jump_distance", 128).getInt();
WC_MAX_SHIP_VOLUME_ON_SURFACE = config.get("WarpCore", "max_ship_volume_on_surface", 15000).getInt(); // Maximum ship mass to jump on earth (15k blocks)
WC_MIN_SHIP_VOLUME_FOR_HYPERSPACE = config.get("WarpCore", "min_ship_volume_for_hyperspace", 500).getInt(); ; // Minimum ship volume value for hyper space
WC_MAX_SHIP_SIDE = config.get("WarpCore", "max_ship_side", 100).getInt();
WC_COOLDOWN_INTERVAL_SECONDS = config.get("WarpCore", "cooldown_interval_seconds", 4).getInt();
WC_CORES_REGISTRY_UPDATE_INTERVAL_SECONDS = config.get("WarpCore", "cores_registry_update_interval", 10).getInt();
WC_ISOLATION_UPDATE_INTARVAL_SECONDS = config.get("WarpCore", "isolation_update_interval", 10).getInt();
// Warp Radar
WR_MAX_ENERGY_VALUE = config.get("WarpRadar", "max_energy_value", 100000000).getInt();
// Particle Booster
PB_MAX_ENERGY_VALUE = config.get("ParticleBooster", "max_energy_value", 100000).getInt();
// Mining Laser
ML_MAX_BOOSTERS_NUMBER = config.get("MiningLaser", "max_boosters_number", 1).getInt();
ML_SCAN_DELAY = 20 * config.get("MiningLaser", "scan_delay_seconds", 5).getInt();
ML_MINE_DELAY = config.get("MiningLaser", "mine_delay_ticks", 10).getInt();
ML_EU_PER_LAYER_SPACE = config.get("MiningLaser", "eu_per_layer_space", 500).getInt();
ML_EU_PER_LAYER_EARTH = config.get("MiningLaser", "eu_per_layer_earth", 5000).getInt();
// Laser Emitter
LE_MAX_BOOSTERS_NUMBER = config.get("LaserEmitter", "max_boosters_number", 10).getInt();
LE_MAX_LASER_ENERGY = config.get("LaserEmitter", "max_laser_energy", 4000000).getInt();
LE_EMIT_DELAY_TICKS = config.get("LaserEmitter", "emit_delay_ticks", 60).getInt();
LE_EMIT_SCAN_DELAY_TICKS = config.get("LaserEmitter", "emit_scan_delay_ticks", 10).getInt();
// Laser Emitter tweaks
LE_COLLECT_ENERGY_MULTIPLIER = config.get("LaserEmitterTweaks", "collect_energy_multiplier", 0.6D).getDouble(0.6D);
LE_BEAM_LENGTH_PER_ENERGY_DIVIDER = config.get("LaserEmitterTweaks", "beam_length_per_energy_divider", 5000).getInt();
LE_ENTITY_HIT_SET_ON_FIRE_TIME = config.get("LaserEmitterTweaks", "entity_hit_set_on_fire_time", 100).getInt();
LE_ENTITY_HIT_DAMAGE_PER_ENERGY_DIVIDER = config.get("LaserEmitterTweaks", "entity_hit_damage_per_energy_divider", 10000).getInt();
LE_ENTITY_HIT_EXPLOSION_LASER_ENERGY = config.get("LaserEmitterTweaks", "entity_hit_explosion_laser_energy", 1000000).getInt();
LE_BLOCK_HIT_CONSUME_ENERGY = config.get("LaserEmitterTweaks", "block_hit_consume_energy", 70000).getInt();
LE_BLOCK_HIT_CONSUME_ENERGY_PER_BLOCK_RESISTANCE = config.get("LaserEmitterTweaks", "block_hit_consume_energy_per_block_resistance", 1000).getInt();
LE_BLOCK_HIT_CONSUME_ENERGY_PER_DISTANCE = config.get("LaserEmitterTweaks", "block_hit_consume_energy_per_distance", 10).getInt();
// Cloaking device core
CD_MAX_CLOAKING_FIELD_SIDE = config.get("CloakingDevice", "max_cloaking_field_side", 100).getInt();
CD_ENERGY_PER_BLOCK_TIER1 = config.get("CloakingDevice", "energy_per_block_tier1", 125).getInt();
CD_ENERGY_PER_BLOCK_TIER2 = config.get("CloakingDevice", "energy_per_block_tier2", 500).getInt();
CD_FIELD_REFRESH_INTERVAL_SECONDS = config.get("CloakingDevice", "field_refresh_interval_seconds", 3).getInt();
CD_COIL_CAPTURE_BLOCKS = config.get("CloakingDevice", "coil_capture_blocks", 5).getInt();
}
public void Init2()
{
CommonWorldGenOres = new ArrayList<int[]>();
@ -106,6 +209,7 @@ public class WarpDriveConfig
SpaceHelmets = new HashSet<Integer>();
Jetpacks = new HashSet<Integer>();
MinerOres = new HashSet<Integer>();
scannerIgnoreBlocks = new HashSet<Integer>();
config.load();
coreID = config.getBlock("core", 500).getInt();
controllerID = config.getBlock("controller", 501).getInt();
@ -122,7 +226,9 @@ public class WarpDriveConfig
camID = config.getBlock("camera", 513).getInt();
monitorID = config.getBlock("monitor", 514).getInt();
iridiumID = config.getBlock("iridium", 515).getInt();
config.save();
shipScannerID = config.getBlock("shipscanner", 516).getInt();
cloakCoreID = config.getBlock("cloakcore", 517).getInt();
cloakCoilID = config.getBlock("cloakcoil", 518).getInt();
LoadIC2();
LoadCC();
isGregLoaded = Loader.isModLoaded("gregtech_addon");
@ -162,6 +268,23 @@ public class WarpDriveConfig
MinerOres.add(Block.web.blockID);
MinerOres.add(Block.fence.blockID);
MinerOres.add(Block.torchWood.blockID);
// Ignore WarpDrive blocks (which potentially will be duplicated by cheaters using ship scan/deploy)
scannerIgnoreBlocks.add(coreID);
scannerIgnoreBlocks.add(controllerID);
scannerIgnoreBlocks.add(iridiumID);
scannerIgnoreBlocks.add(Items.getItem("mfsUnit").itemID);
scannerIgnoreBlocks.add(Items.getItem("mfeUnit").itemID);
scannerIgnoreBlocks.add(Items.getItem("cesuUnit").itemID);
scannerIgnoreBlocks.add(Items.getItem("batBox").itemID);
// Do not scan ores and valuables
for (int[] t : CommonWorldGenOres) // each element of this set is pair [id, meta]
scannerIgnoreBlocks.add(t[0]); // we adding ID only
loadWarpDriveConfig();
config.save();
}
private void LoadIC2()
@ -170,15 +293,12 @@ public class WarpDriveConfig
SpaceHelmets.add(Items.getItem("hazmatHelmet").itemID);
SpaceHelmets.add(Items.getItem("quantumHelmet").itemID);
Jetpacks.add(Items.getItem("jetpack").itemID);
System.out.println("ZLO1 " + Items.getItem("jetpack").itemID);
Jetpacks.add(Items.getItem("electricJetpack").itemID);
System.out.println("ZLO1 " + Items.getItem("electricJetpack").itemID);
IC2_Air = new int[] {Items.getItem("airCell").itemID, Items.getItem("airCell").getItemDamage()};
CommonWorldGenOres.add(new int[] {Items.getItem("uraniumOre").itemID, Items.getItem("uraniumOre").getItemDamage()});
CommonWorldGenOres.add(new int[] {Items.getItem("copperOre").itemID, Items.getItem("uraniumOre").getItemDamage()});
CommonWorldGenOres.add(new int[] {Items.getItem("tinOre").itemID, Items.getItem("uraniumOre").getItemDamage()});
MinerOres.add(Items.getItem("rubberWood").itemID);
Compot = Items.getItem("advancedAlloy");
AEExtraFDI = Items.getItem("FluidCell").getItem();
}
@ -211,14 +331,6 @@ System.out.println("ZLO1 " + Items.getItem("electricJetpack").itemID);
GT_Granite = t[5]; // 0 - black, 1 - black cobble, 8 - red, 9 - red cobble
MinerOres.add(GT_Ores);
MinerOres.add(GT_Granite);
/*
ArrayList<ItemStack> t1 = new ArrayList<ItemStack>();
t1.addAll(OreDictionary.getOres("craftingPlateSteel"));
if (t1.size() >= 3)
Compot = t1.get(2);
else
System.out.println("WarpDriveConfig Error getting craftingPlateSteel " + t1.size());
*/
}
catch (Exception e)
{
@ -251,7 +363,7 @@ System.out.println("ZLO1 " + Items.getItem("electricJetpack").itemID);
{
Class<?> z = Class.forName("extracells.ItemEnum");
Object z1 = z.getEnumConstants()[6];
AEExtraFDI = (Item)z1.getClass().getDeclaredMethod("getItemEntry").invoke(z1);
AEExtraFDI = (Item)z1.getClass().getDeclaredMethod("getItemInstance").invoke(z1);
}
catch (Exception e)
{
@ -283,6 +395,11 @@ System.out.println("ZLO1 " + Items.getItem("electricJetpack").itemID);
{
try
{
/*
Class<?> z = Class.forName("atomicscience.AtomicScience");
CommonWorldGenOres.add(new int[] {((Block)z.getField("blockUraniumOre").get(null)).blockID, 0});
AS_Turbine = ((Block)z.getField("blockElectricTurbine").get(null)).blockID;
*/
Class<?> z = Class.forName("atomicscience.ZhuYaoAS");
CommonWorldGenOres.add(new int[] {((Block)z.getField("bHeOre").get(null)).blockID, 0});
AS_Turbine = ((Block)z.getField("bWoLun").get(null)).blockID;
@ -290,6 +407,7 @@ System.out.println("ZLO1 " + Items.getItem("electricJetpack").itemID);
catch (Exception e)
{
System.out.println("WarpDriveConfig Error loading AS classes");
e.printStackTrace();
isASLoaded = false;
}
}

View file

@ -24,49 +24,60 @@ public class WCClassTransformer implements net.minecraft.launchwrapper.IClassTra
public WCClassTransformer()
{
// Obfuscated Notch methods
nodemap.put("worldClass", "abv");
nodemap.put("playerMP", "ju");
nodemap.put("netLoginHandler", "jx");
nodemap.put("confManagerClass", "hm");
nodemap.put("worldClass", "abw");
nodemap.put("playerMP", "jv");
nodemap.put("netLoginHandler", "jy");
nodemap.put("confManagerClass", "hn");
nodemap.put("createPlayerMethod", "a");
nodemap.put("createPlayerDesc", (new StringBuilder()).append("(Ljava/lang/String;)L").append((String)nodemap.get("playerMP")).append(";").toString());
nodemap.put("respawnPlayerMethod", "a");
nodemap.put("respawnPlayerDesc", (new StringBuilder()).append("(L").append((String)nodemap.get("playerMP")).append(";IZ)L").append((String)nodemap.get("playerMP")).append(";").toString());
nodemap.put("itemInWorldManagerClass", "jv");
nodemap.put("itemInWorldManagerClass", "jw");
nodemap.put("attemptLoginMethodBukkit", "attemptLogin");
nodemap.put("attemptLoginDescBukkit", (new StringBuilder()).append("(L").append((String)nodemap.get("netLoginHandler")).append(";Ljava/lang/String;Ljava/lang/String;)L").append((String)nodemap.get("playerMP")).append(";").toString());
nodemap.put("playerControllerClass", "bcz");
nodemap.put("playerClient", "bdf");
nodemap.put("netClientHandler", "bct");
nodemap.put("playerControllerClass", "bdc");
nodemap.put("playerClient", "bdi");
nodemap.put("netClientHandler", "bcw");
nodemap.put("createClientPlayerMethod", "a");
nodemap.put("createClientPlayerDesc", (new StringBuilder()).append("(L").append((String)nodemap.get("worldClass")).append(";)L").append((String)nodemap.get("playerClient")).append(";").toString());
nodemap.put("entityLivingClass", "oe");
nodemap.put("entityLivingClass", "of");
nodemap.put("moveEntityMethod", "e");
nodemap.put("moveEntityDesc", "(FF)V");
nodemap.put("entityItemClass", "sr");
nodemap.put("entityItemClass", "ss");
nodemap.put("onUpdateMethod", "l_");
nodemap.put("onUpdateDesc", "()V");
nodemap.put("entityRendererClass", "bfb");
nodemap.put("entityRendererClass", "bfe");
nodemap.put("updateLightmapMethod", "h");
nodemap.put("updateLightmapDesc", "(F)V");
nodemap.put("player", "ue");
nodemap.put("containerPlayer", "vu");
nodemap.put("invPlayerClass", "uc");
nodemap.put("minecraft", "ats");
nodemap.put("session", "aup");
nodemap.put("guiPlayer", "axs");
nodemap.put("thePlayer", "g");
nodemap.put("player", "uf");
nodemap.put("containerPlayer", "vv");
nodemap.put("invPlayerClass", "ud");
nodemap.put("minecraft", "atv");
nodemap.put("session", "aus");
nodemap.put("guiPlayer", "axv");
nodemap.put("thePlayer", "h");
nodemap.put("displayGui", "a");
nodemap.put("guiScreen", "avv");
nodemap.put("guiScreen", "awe");
nodemap.put("displayGuiDesc", (new StringBuilder()).append("(L").append((String)nodemap.get("guiScreen")).append(";)V").toString());
nodemap.put("runTick", "k");
nodemap.put("runTickDesc", "()V");
nodemap.put("clickMiddleMouseButton", "W");
nodemap.put("clickMiddleMouseButtonDesc", "()V");
nodemap.put("itemRendererClass", "bfg");
nodemap.put("itemRendererClass", "bfj");
nodemap.put("renderOverlaysMethod", "b");
nodemap.put("renderOverlaysDesc", "(F)V");
nodemap.put("updateFogColorMethod", "i");
nodemap.put("updateFogColorDesc", "(F)V");
nodemap.put("getFogColorMethod", "f");
nodemap.put("getSkyColorMethod", "a");
nodemap.put("vecClass", "atc");
nodemap.put("entityClass", "nn");
nodemap.put("getFogColorDesc", (new StringBuilder()).append("(F)L").append((String)nodemap.get("vecClass")).append(";").toString());
nodemap.put("getSkyColorDesc", (new StringBuilder()).append("(L").append((String)nodemap.get("entityClass")).append(";F)L").append((String)nodemap.get("vecClass")).append(";").toString());
nodemap.put("guiSleepClass", "avm");
nodemap.put("wakeEntityMethod", "g");
nodemap.put("wakeEntityDesc", "()V");
nodemap.put("orientCameraDesc", (new StringBuilder()).append("(L").append((String)nodemap.get("minecraft")).append(";L").append((String)nodemap.get("entityLivingClass")).append(";)V").toString());
}
@Override

View file

@ -21,7 +21,7 @@ public class WCDummyContainer extends DummyModContainer
ModMetadata meta = getMetadata();
meta.modId = "WarpDriveCore";
meta.name = "WarpDriveCore";
meta.version = "1.0.0.0";
meta.version = "1.0.0.1";
meta.credits = "Cr0s";
meta.authorList = Arrays.asList("cr0s");
meta.description = "";

View file

@ -7,7 +7,7 @@ import cpw.mods.fml.relauncher.IFMLCallHook;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.MCVersion;
@MCVersion(value = "1.6.2")
@MCVersion(value = "1.6.4")
public class WCFMLLoadingPlugin implements IFMLLoadingPlugin, IFMLCallHook
{
public static File location;