Merge branch 'master' of https://github.com/Cr0s/WarpDrive into Cr0s-master2

Initial merge

Conflicts:
	client/ClientProxy.java
	src/assets/warpdrive/lang/en_US.lang
	src/assets/warpdrive/lua/cloakingdevicecore/cloak1
	src/assets/warpdrive/lua/cloakingdevicecore/cloak2
	src/assets/warpdrive/lua/radar/ping
	src/assets/warpdrive/lua/radar/scan
	src/assets/warpdrive/textures/blocks/transporterTop.png
	src/cr0s/WarpDrive/BlockAirGenerator.java
	src/cr0s/WarpDrive/BlockLift.java
	src/cr0s/WarpDrive/BlockRadar.java
	src/cr0s/WarpDrive/BlockReactor.java
	src/cr0s/WarpDrive/CloakChunkWatcher.java
	src/cr0s/WarpDrive/EntityJump.java
	src/cr0s/WarpDrive/GravityManager.java
	src/cr0s/WarpDrive/PacketHandler.java
	src/cr0s/WarpDrive/SpaceEventHandler.java
	src/cr0s/WarpDrive/TileEntityLaser.java
	src/cr0s/WarpDrive/TileEntityShipScanner.java
	src/cr0s/WarpDrive/WarpDrive.java
	src/cr0s/WarpDrive/WarpDriveConfig.java
	src/cr0s/WarpDrive/WorldGenStation.java
	src/cr0s/WarpDrive/api/IBreathingHelmet.java
	src/cr0s/WarpDrive/block/BlockAir.java
	src/cr0s/WarpDrive/block/BlockGas.java
	src/cr0s/WarpDrive/command/DebugCommand.java
	src/cr0s/WarpDrive/command/GenerateCommand.java
	src/cr0s/WarpDrive/command/JumpgateCommand.java
	src/cr0s/WarpDrive/data/CamRegistry.java
	src/cr0s/WarpDrive/data/CloakManager.java
	src/cr0s/WarpDrive/data/JumpgatesRegistry.java
	src/cr0s/WarpDrive/data/TransitionPlane.java
	src/cr0s/WarpDrive/data/WarpCoresRegistry.java
	src/cr0s/WarpDrive/item/ItemWarpComponent.java
	src/cr0s/WarpDrive/machines/BlockCamera.java
	src/cr0s/WarpDrive/machines/BlockCloakingCoil.java
	src/cr0s/WarpDrive/machines/BlockCloakingDeviceCore.java
	src/cr0s/WarpDrive/machines/BlockLaserCam.java
	src/cr0s/WarpDrive/machines/BlockMonitor.java
	src/cr0s/WarpDrive/machines/BlockParticleBooster.java
	src/cr0s/WarpDrive/machines/BlockPowerLaser.java
	src/cr0s/WarpDrive/machines/BlockPowerReactor.java
	src/cr0s/WarpDrive/machines/BlockShipScanner.java
	src/cr0s/WarpDrive/machines/BlockTransporter.java
	src/cr0s/WarpDrive/machines/TileEntityAbstractMiner.java
	src/cr0s/WarpDrive/machines/TileEntityAirGenerator.java
	src/cr0s/WarpDrive/machines/TileEntityCamera.java
	src/cr0s/WarpDrive/machines/TileEntityCloakingDeviceCore.java
	src/cr0s/WarpDrive/machines/TileEntityLaserReactorMonitor.java
	src/cr0s/WarpDrive/machines/TileEntityLaserTreeFarm.java
	src/cr0s/WarpDrive/machines/TileEntityLift.java
	src/cr0s/WarpDrive/machines/TileEntityMiningLaser.java
	src/cr0s/WarpDrive/machines/TileEntityParticleBooster.java
	src/cr0s/WarpDrive/machines/TileEntityPowerLaser.java
	src/cr0s/WarpDrive/machines/TileEntityPowerReactor.java
	src/cr0s/WarpDrive/machines/TileEntityProtocol.java
	src/cr0s/WarpDrive/machines/TileEntityRadar.java
	src/cr0s/WarpDrive/machines/TileEntityReactor.java
	src/cr0s/WarpDrive/machines/TileEntityTransporter.java
	src/cr0s/WarpDrive/machines/WarpChunkTE.java
	src/cr0s/WarpDrive/machines/WarpEnergyTE.java
	src/cr0s/WarpDrive/machines/WarpTE.java
	src/cr0s/WarpDrive/render/CameraOverlay.java
	src/cr0s/WarpDrive/render/ClientCameraUtils.java
	src/cr0s/WarpDrive/render/EntityCamera.java
	src/cr0s/WarpDrive/world/EntitySphereGen.java
	src/cr0s/WarpDrive/world/HyperSpaceWorldGenerator.java
	src/cr0s/WarpDrive/world/SpaceProvider.java
	src/cr0s/WarpDrive/world/SpaceWorldGenerator.java
	src/cr0s/WarpDrive/world/WorldGenStructure.java
This commit is contained in:
LemADEC 2014-08-27 16:29:30 +02:00
commit 37b0141393
40 changed files with 5330 additions and 111 deletions

1
.gitignore vendored
View file

@ -161,3 +161,4 @@ pip-log.txt
# Mac crap
.DS_Store
src/cr0s/WarpDrive/client/ClientProxy.java

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 545 B

View file

@ -0,0 +1,64 @@
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 BlockCamera extends BlockContainer
{
private Icon[] iconBuffer;
private final int ICON_SIDE = 0;
public BlockCamera(int id, int texture, Material material)
{
super(id, material);
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister)
{
iconBuffer = new Icon[1];
// Solid textures
iconBuffer[ICON_SIDE] = par1IconRegister.registerIcon("warpdrive:cameraSide");
}
@Override
public Icon getIcon(int side, int metadata)
{
return iconBuffer[ICON_SIDE];
}
@Override
public TileEntity createNewTileEntity(World var1)
{
return new TileEntityCamera();
}
/**
* 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;
}
}

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

@ -1,47 +1,46 @@
package cr0s.WarpDrive.machines;
package cr0s.WarpDrive;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import cr0s.WarpDrive.WarpDrive;
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 BlockLaser extends BlockContainer {
public class BlockLaser extends BlockContainer
{
private Icon[] iconBuffer;
private final int ICON_SIDE = 0;
public BlockLaser(int id, int texture, Material material) {
public BlockLaser(int id, int texture, Material material)
{
super(id, material);
setHardness(0.5F);
setStepSound(Block.soundMetalFootstep);
setCreativeTab(WarpDrive.warpdriveTab);
setUnlocalizedName("warpdrive.machines.Laser");
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister) {
public void registerIcons(IconRegister par1IconRegister)
{
iconBuffer = new Icon[1];
// Solid textures
iconBuffer[ICON_SIDE] = par1IconRegister.registerIcon("warpdrive:laserSide");
}
@Override
public Icon getIcon(int side, int metadata) {
public Icon getIcon(int side, int metadata)
{
return iconBuffer[ICON_SIDE];
}
@Override
public TileEntity createNewTileEntity(World parWorld) {
public TileEntity createNewTileEntity(World var1)
{
return new TileEntityLaser();
}
@ -49,7 +48,8 @@ public class BlockLaser extends BlockContainer {
* Returns the quantity of items to drop on block destruction.
*/
@Override
public int quantityDropped(Random par1Random) {
public int quantityDropped(Random par1Random)
{
return 1;
}
@ -57,7 +57,8 @@ public class BlockLaser extends BlockContainer {
* Returns the ID of the items to drop on destruction.
*/
@Override
public int idDropped(int par1, Random par2Random, int par3) {
public int idDropped(int par1, Random par2Random, int par3)
{
return this.blockID;
}
}

View file

@ -0,0 +1,64 @@
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 BlockLaserCam extends BlockContainer
{
private Icon[] iconBuffer;
private final int ICON_SIDE = 0;
public BlockLaserCam(int id, int texture, Material material)
{
super(id, material);
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister)
{
iconBuffer = new Icon[1];
// Solid textures
iconBuffer[ICON_SIDE] = par1IconRegister.registerIcon("warpdrive:laserSideCam");
}
@Override
public Icon getIcon(int side, int metadata)
{
return iconBuffer[ICON_SIDE];
}
@Override
public TileEntity createNewTileEntity(World var1)
{
return new TileEntityLaser();
}
/**
* 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;
}
}

View file

@ -1,58 +1,61 @@
package cr0s.WarpDrive.machines;
package cr0s.WarpDrive;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import cr0s.WarpDrive.WarpDrive;
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 BlockLaserTreeFarm extends BlockContainer {
public class BlockMiningLaser extends BlockContainer
{
private Icon[] iconBuffer;
public BlockLaserTreeFarm(int id, int texture, Material material) {
private final int ICON_SIDE = 0;
public BlockMiningLaser(int id, int texture, Material material)
{
super(id, material);
setHardness(0.5F);
setStepSound(Block.soundMetalFootstep);
setCreativeTab(WarpDrive.warpdriveTab);
setUnlocalizedName("warpdrive.machines.LaserTreeFarm");
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister) {
public void registerIcons(IconRegister par1IconRegister)
{
iconBuffer = new Icon[2];
// Solid textures
iconBuffer[0] = par1IconRegister.registerIcon("warpdrive:particleBoosterTopBottom");
iconBuffer[1] = par1IconRegister.registerIcon("warpdrive:laserTreeFarmSide0");
iconBuffer[1] = par1IconRegister.registerIcon("warpdrive:miningLaserSide0");
}
@Override
public Icon getIcon(int side, int metadata) {
if (side == 0 || side == 1) {
public Icon getIcon(int side, int metadata)
{
if (side == 0 || side == 1)
{
return iconBuffer[0];
}
return iconBuffer[1];
return iconBuffer[metadata + 1];
}
@Override
public TileEntity createNewTileEntity(World var1) {
return new TileEntityLaserTreeFarm();
public TileEntity createNewTileEntity(World var1)
{
return new TileEntityMiningLaser();
}
/**
* Returns the quantity of items to drop on block destruction.
*/
@Override
public int quantityDropped(Random par1Random) {
public int quantityDropped(Random par1Random)
{
return 1;
}
@ -60,7 +63,8 @@ public class BlockLaserTreeFarm extends BlockContainer {
* Returns the ID of the items to drop on destruction.
*/
@Override
public int idDropped(int par1, Random par2Random, int par3) {
public int idDropped(int par1, Random par2Random, int par3)
{
return this.blockID;
}
}

View file

@ -0,0 +1,112 @@
package cr0s.WarpDrive;
import java.util.List;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.BlockDirectional;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Icon;
import net.minecraft.world.ChunkPosition;
import net.minecraft.world.World;
public class BlockMonitor extends BlockContainer
{
private Icon frontIcon;
private Icon blockIcon;
public BlockMonitor(int id)
{
super(id, Material.iron);
}
@SideOnly(Side.CLIENT)
/**
* From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
*/
public Icon getIcon(int side, int meta)
{
meta &= 3;
return side == 2 ? (meta == 0 ? this.frontIcon : this.blockIcon) : (side == 3 ? (meta == 2 ? this.frontIcon : this.blockIcon) : (side == 4 ? (meta == 3 ? this.frontIcon : this.blockIcon) : (side == 5 ? (meta == 1 ? this.frontIcon : this.blockIcon) : this.blockIcon)));
}
/**
* When this method is called, your block should register all the icons it needs with the given IconRegister. This
* is the only chance you get to register icons.
*/
public void registerIcons(IconRegister reg)
{
this.frontIcon = reg.registerIcon("warpdrive:monitorFront");
this.blockIcon = reg.registerIcon("warpdrive:monitorSide");
}
/**
* Called when the block is placed in the world.
*/
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityliving, ItemStack itemstack)
{
int dir = Math.round(entityliving.rotationYaw / 90.0F) & 3;
world.setBlockMetadataWithNotify(x, y, z, dir, 3);
}
/**
* Called upon block activation (right click on the block.)
*/
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int par6, float par7, float par8, float par9)
{
if (!FMLCommonHandler.instance().getEffectiveSide().isClient())
{
return true;
}
// Get camera frequency
TileEntity te = world.getBlockTileEntity(x, y, z);
if (te != null && te instanceof TileEntityMonitor)
{
int freq = ((TileEntityMonitor)te).getFrequency();
WarpDrive.instance.cams.removeDeadCams();
CamRegistryItem cam = WarpDrive.instance.cams.getCamByFreq(freq, world);
if (cam == null || cam.worldObj == null || cam.worldObj != world || !WarpDrive.instance.cams.isCamAlive(cam))
{
entityplayer.addChatMessage("[Monitor: " + freq + "] Invalid frequency or camera is too far!");
return false;
}
else
{
// Spawn camera entity
EntityCamera e = new EntityCamera(world, cam.camPos, entityplayer);
world.spawnEntityInWorld(e);
e.setPositionAndUpdate(cam.camPos.x, cam.camPos.y, cam.camPos.z);
//e.setPositionAndRotation(camPos.x, camPos.y, camPos.z, entityplayer.rotationYaw, entityplayer.rotationPitch);
ClientCameraUtils.playerData = entityplayer;
WarpDrive.instance.overlayType = cam.type;
ClientCameraUtils.setupViewpoint(e);
}
}
return false;
}
public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
{
}
@Override
public TileEntity createNewTileEntity(World world)
{
return new TileEntityMonitor();
}
}

View file

@ -0,0 +1,118 @@
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 BlockParticleBooster extends BlockContainer
{
private Icon[] iconBuffer;
public BlockParticleBooster(int id, int texture, Material material)
{
super(id, material);
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister)
{
iconBuffer = new Icon[12];
iconBuffer[0] = par1IconRegister.registerIcon("warpdrive:particleBoosterSide0");
iconBuffer[1] = par1IconRegister.registerIcon("warpdrive:particleBoosterSide1");
iconBuffer[2] = par1IconRegister.registerIcon("warpdrive:particleBoosterSide2");
iconBuffer[3] = par1IconRegister.registerIcon("warpdrive:particleBoosterSide3");
iconBuffer[4] = par1IconRegister.registerIcon("warpdrive:particleBoosterSide4");
iconBuffer[5] = par1IconRegister.registerIcon("warpdrive:particleBoosterSide5");
iconBuffer[6] = par1IconRegister.registerIcon("warpdrive:particleBoosterSide6");
iconBuffer[7] = par1IconRegister.registerIcon("warpdrive:particleBoosterSide7");
iconBuffer[8] = par1IconRegister.registerIcon("warpdrive:particleBoosterSide8");
iconBuffer[9] = par1IconRegister.registerIcon("warpdrive:particleBoosterSide9");
iconBuffer[10] = par1IconRegister.registerIcon("warpdrive:particleBoosterSide10");
iconBuffer[11] = par1IconRegister.registerIcon("warpdrive:particleBoosterTopBottom");
}
@Override
public Icon getIcon(int side, int metadata)
{
if (side == 0 || side == 1)
{
return iconBuffer[11];
}
if (metadata > 10)
{
metadata = 10;
}
return iconBuffer[metadata];
}
@Override
public TileEntity createNewTileEntity(World var1)
{
return new TileEntityParticleBooster();
}
/**
* 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;
}
TileEntityParticleBooster booster = (TileEntityParticleBooster)par1World.getBlockTileEntity(par2, par3, par4);
if (booster != null)
{
par5EntityPlayer.addChatMessage("[Particle Booster] Energy level: " + booster.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();
}
super.breakBlock(par1World, par2, par3, par4, par5, par6);
}
}

View file

@ -0,0 +1,117 @@
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 BlockProtocol extends BlockContainer
{
private Icon[] iconBuffer;
private final int ICON_INACTIVE_SIDE = 0, ICON_BOTTOM = 1, ICON_TOP = 2, ICON_SIDE_ACTIVATED = 3;
//private final int ANIMATION_
//private int currentTexture;
public BlockProtocol(int id, int texture, Material material)
{
super(id, material);
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister)
{
iconBuffer = new Icon[9];
// Solid textures
iconBuffer[ICON_INACTIVE_SIDE] = par1IconRegister.registerIcon("warpdrive:contSideInactive");
iconBuffer[ICON_BOTTOM] = par1IconRegister.registerIcon("warpdrive:contBottom");
iconBuffer[ICON_TOP] = par1IconRegister.registerIcon("warpdrive:contTop");
// Animated textures
iconBuffer[ICON_SIDE_ACTIVATED] = par1IconRegister.registerIcon("warpdrive:contSideActive1");
iconBuffer[ICON_SIDE_ACTIVATED + 1] = par1IconRegister.registerIcon("warpdrive:contSideActive2");
iconBuffer[ICON_SIDE_ACTIVATED + 2] = par1IconRegister.registerIcon("warpdrive:contSideActive3");
iconBuffer[ICON_SIDE_ACTIVATED + 3] = par1IconRegister.registerIcon("warpdrive:contSideActive4");
iconBuffer[ICON_SIDE_ACTIVATED + 4] = par1IconRegister.registerIcon("warpdrive:contSideActive5");
iconBuffer[ICON_SIDE_ACTIVATED + 5] = par1IconRegister.registerIcon("warpdrive:contSideActive6");
}
@Override
public Icon getIcon(int side, int metadata)
{
if (side == 0)
{
return iconBuffer[ICON_BOTTOM];
}
else if (side == 1)
{
return iconBuffer[ICON_TOP];
}
if (metadata == 0) // Inactive state
{
return iconBuffer[ICON_INACTIVE_SIDE];
}
else if (metadata > 0) // Activated, in metadata stored mode number
{
if (ICON_SIDE_ACTIVATED + metadata - 1 < iconBuffer.length)
return iconBuffer[ICON_SIDE_ACTIVATED + metadata - 1];
else
return iconBuffer[ICON_SIDE_ACTIVATED];
}
else
return iconBuffer[ICON_SIDE_ACTIVATED];
}
@Override
public TileEntity createNewTileEntity(World var1)
{
return new TileEntityProtocol();
}
/**
* Returns the quantity of items to drop on block destruction.
*/
@Override
public int quantityDropped(Random par1Random)
{
return 1;
}
/**
* Returns the ID of the items to drop on destruction.
*/
@Override
public int idDropped(int par1, Random par2Random, int par3)
{
return this.blockID;
}
/**
* Called upon block activation (right click on the block.)
*/
@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;
}
TileEntityProtocol controller = (TileEntityProtocol)par1World.getBlockTileEntity(par2, par3, par4);
if (controller != null)
{
controller.attachPlayer(par5EntityPlayer);
par5EntityPlayer.addChatMessage("[WarpCtrlr] Attached players: " + controller.getAttachedPlayersList());
}
return true;
}
}

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

@ -1,36 +1,38 @@
package cr0s.WarpDrive.machines;
package cr0s.WarpDrive;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import cr0s.WarpDrive.WarpDrive;
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.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
public class BlockWarpIsolation extends Block {
public class BlockWarpIsolation extends Block
{
private Icon[] iconBuffer;
public BlockWarpIsolation(int id, int texture, Material material) {
public BlockWarpIsolation(int id, int texture, Material material)
{
super(id, material);
setHardness(0.5F);
setStepSound(Block.soundMetalFootstep);
setCreativeTab(WarpDrive.warpdriveTab);
setUnlocalizedName("warpdrive.blocks.WarpIsolation");
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister) {
public void registerIcons(IconRegister par1IconRegister)
{
iconBuffer = new Icon[1];
iconBuffer[0] = par1IconRegister.registerIcon("warpdrive:warpIsolation");
}
@Override
public Icon getIcon(int side, int metadata) {
public Icon getIcon(int side, int metadata)
{
return iconBuffer[0];
}
@ -38,7 +40,8 @@ public class BlockWarpIsolation extends Block {
* Returns the quantity of items to drop on block destruction.
*/
@Override
public int quantityDropped(Random par1Random) {
public int quantityDropped(Random par1Random)
{
return 1;
}
@ -46,7 +49,8 @@ public class BlockWarpIsolation extends Block {
* Returns the ID of the items to drop on destruction.
*/
@Override
public int idDropped(int par1, Random par2Random, int par3) {
public int idDropped(int par1, Random par2Random, int par3)
{
return this.blockID;
}
}

View file

@ -1,20 +1,20 @@
package cr0s.WarpDrive.client;
package cr0s.WarpDrive;
import net.minecraft.world.World;
import cpw.mods.fml.client.FMLClientHandler;
import cr0s.WarpDrive.CommonProxy;
import cr0s.WarpDrive.render.FXBeam;
import cr0s.WarpDrive.data.Vector3;
import cr0s.WarpDrive.WarpDrive;
import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
public class ClientProxy extends CommonProxy {
public class ClientProxy extends CommonProxy
{
@Override
public void registerRenderers() {
public void registerRenderers()
{
}
@Override
public void renderBeam(World world, Vector3 position, Vector3 target, float red, float green, float blue, int age, int energy) {
// WarpDrive.debugPrint("Rendering beam...");
public void renderBeam(World world, Vector3 position, Vector3 target, float red, float green, float blue, int age, int energy)
{
//System.out.println("Rendering beam...");
FMLClientHandler.instance().getClient().effectRenderer.addEffect(new FXBeam(world, position, target, red, green, blue, age, energy));
}
}

View file

@ -11,10 +11,10 @@ public class CommonProxy
{
public void registerEntities()
{
EntityRegistry.registerModEntity(EntityJump.class, "EntityJump", 240, WarpDrive.instance, 80, 1, false); // Lem
EntityRegistry.registerModEntity(EntitySphereGen.class, "EntitySphereGenerator", 241, WarpDrive.instance, 200, 1, false); // Lem
EntityRegistry.registerModEntity(EntityStarCore.class, "EntityStarCore", 242, WarpDrive.instance, 300, 1, false); // Lem
EntityRegistry.registerModEntity(EntityCamera.class, "EntityCamera", 243, WarpDrive.instance, 300, 1, false); // Lem
EntityRegistry.registerModEntity(EntityJump.class, "EntityJump", 240, WarpDrive.instance, 80, 1, false);
EntityRegistry.registerModEntity(EntitySphereGen.class, "EntitySphereGenerator", 241, WarpDrive.instance, 200, 1, false);
EntityRegistry.registerModEntity(EntityStarCore.class, "EntityStarCore", 242, WarpDrive.instance, 300, 1, false);
EntityRegistry.registerModEntity(EntityCamera.class, "EntityCamera", 243, WarpDrive.instance, 300, 1, false);
}
public void registerRenderers()

View file

@ -0,0 +1,180 @@
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;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.MinecraftForge;
public class TileEntityAirGenerator extends TileEntity implements IEnergySink
{
public boolean addedToEnergyNet = false;
private final int EU_PER_AIRBLOCK = 10;
private final int MAX_ENERGY_VALUE = 36 * EU_PER_AIRBLOCK;
private int currentEnergyValue = 0;
private int cooldownTicks = 0;
private final float AIR_POLLUTION_INTERVAL = 4; // seconds
private final int START_CONCENTRATION_VALUE = 15;
@Override
public void updateEntity()
{
if (FMLCommonHandler.instance().getEffectiveSide().isClient())
{
return;
}
if (!addedToEnergyNet && !this.tileEntityInvalid)
{
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
addedToEnergyNet = true;
}
// Air generator works only in spaces
if (worldObj.provider.dimensionId != WarpDrive.instance.spaceDimID && worldObj.provider.dimensionId != WarpDrive.instance.hyperSpaceDimID)
{
return;
}
if (addedToEnergyNet && currentEnergyValue > EU_PER_AIRBLOCK)
{
if (cooldownTicks++ > AIR_POLLUTION_INTERVAL * 20)
{
cooldownTicks = 0;
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 1, 2); // set enabled texture
releaseAir();
}
}
else
{
if (cooldownTicks++ > 20)
{
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 2); // set disabled texture
cooldownTicks = 0;
}
}
}
private void releaseAir()
{
if (worldObj.isAirBlock(xCoord + 1, yCoord, zCoord) && (currentEnergyValue - EU_PER_AIRBLOCK >= 0))
{
worldObj.setBlock(xCoord + 1, yCoord, zCoord, WarpDriveConfig.i.airID, START_CONCENTRATION_VALUE, 2);
currentEnergyValue -= EU_PER_AIRBLOCK;
}
if (worldObj.isAirBlock(xCoord - 1, yCoord, zCoord) && (currentEnergyValue - EU_PER_AIRBLOCK >= 0))
{
worldObj.setBlock(xCoord - 1, yCoord, zCoord, WarpDriveConfig.i.airID, START_CONCENTRATION_VALUE, 2);
currentEnergyValue -= EU_PER_AIRBLOCK;
}
if (worldObj.isAirBlock(xCoord, yCoord + 1, zCoord) && (currentEnergyValue - EU_PER_AIRBLOCK >= 0))
{
worldObj.setBlock(xCoord, yCoord + 1, zCoord, WarpDriveConfig.i.airID, START_CONCENTRATION_VALUE, 2);
currentEnergyValue -= EU_PER_AIRBLOCK;
}
if (worldObj.isAirBlock(xCoord, yCoord - 1, zCoord) && (currentEnergyValue - EU_PER_AIRBLOCK >= 0))
{
worldObj.setBlock(xCoord, yCoord - 1, zCoord, WarpDriveConfig.i.airID, START_CONCENTRATION_VALUE, 2);
currentEnergyValue -= EU_PER_AIRBLOCK;
}
if (worldObj.isAirBlock(xCoord, yCoord, zCoord + 1) && (currentEnergyValue - EU_PER_AIRBLOCK >= 0))
{
worldObj.setBlock(xCoord, yCoord, zCoord + 1, WarpDriveConfig.i.airID, START_CONCENTRATION_VALUE, 2);
currentEnergyValue -= EU_PER_AIRBLOCK;
}
if (worldObj.isAirBlock(xCoord, yCoord, zCoord - 1) && (currentEnergyValue - EU_PER_AIRBLOCK >= 0))
{
worldObj.setBlock(xCoord, yCoord, zCoord - 1, WarpDriveConfig.i.airID, START_CONCENTRATION_VALUE, 2);
currentEnergyValue -= EU_PER_AIRBLOCK;
}
}
@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());
}
// 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;
}
@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

@ -0,0 +1,167 @@
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 java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.network.packet.Packet62LevelSound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.ChunkPosition;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.MinecraftForge;
public class TileEntityCamera extends TileEntity implements IPeripheral
{
private int dx, dz, dy;
private float yaw, pitch; // laser direction
private int frequency = -1; // beam frequency
private float r, g, b; // beam color (corresponds to frequency)
private boolean isEmitting = false;
private String[] methodsArray =
{
"freq"
};
private final int REGISTRY_UPDATE_INTERVAL_SEC = 10;
private int ticks = 0;
private int packetSendTicks = 20;
@Override
public void updateEntity()
{
// Update frequency on clients
if (FMLCommonHandler.instance().getEffectiveSide().isServer())
{
if (packetSendTicks-- == 0)
{
packetSendTicks = 20 * 5;
sendFreqPacket();
}
return;
}
if (++ticks > 20 * REGISTRY_UPDATE_INTERVAL_SEC)
{
ticks = 0;
WarpDrive.instance.cams.updateInRegistry(new CamRegistryItem(this.frequency, new ChunkPosition(xCoord, yCoord, zCoord), worldObj).setType(0));
}
}
public int getFrequency()
{
return frequency;
}
public void setFrequency(int freq)
{
frequency = freq;
}
@Override
public void readFromNBT(NBTTagCompound tag)
{
super.readFromNBT(tag);
frequency = tag.getInteger("frequency");
}
@Override
public void writeToNBT(NBTTagCompound tag)
{
super.writeToNBT(tag);
tag.setInteger("frequency", frequency);
}
public void sendFreqPacket()
{
Side side = FMLCommonHandler.instance().getEffectiveSide();
if (side == Side.SERVER)
{
ByteArrayOutputStream bos = new ByteArrayOutputStream(8);
DataOutputStream outputStream = new DataOutputStream(bos);
try
{
// Write source vector
outputStream.writeInt(xCoord);
outputStream.writeInt(yCoord);
outputStream.writeInt(zCoord);
outputStream.writeInt(this.frequency);
}
catch (Exception ex)
{
ex.printStackTrace();
}
Packet250CustomPayload packet = new Packet250CustomPayload();
packet.channel = "WarpDriveFreq";
packet.data = bos.toByteArray();
packet.length = bos.size();
MinecraftServer.getServer().getConfigurationManager().sendToAllNear(xCoord, yCoord, zCoord, 100, worldObj.provider.dimensionId, packet);
}
}
// IPeripheral methods implementation
@Override
public String getType()
{
return "camera";
}
@Override
public String[] getMethodNames()
{
return methodsArray;
}
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
{
if (arguments.length == 1)
frequency = ((Double)arguments[0]).intValue();
return new Integer[] { frequency };
}
@Override
public boolean canAttachToSide(int side)
{
return true;
}
@Override
public void attach(IComputerAccess computer)
{
}
@Override
public void detach(IComputerAccess computer)
{
}
}

View file

@ -0,0 +1,480 @@
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) {
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 {
currentEnergyValue = 0;
setCoilsState(false);
disableCloakingField();
}
} else if (!validateAssembly() && isEnabled) {
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);
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

@ -0,0 +1,343 @@
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 java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraftforge.common.MinecraftForge;
public class TileEntityLift extends TileEntity implements IEnergySink
{
public boolean addedToEnergyNet = false;
private final int MAX_ENERGY_VALUE = 2048; // eU
private int currentEnergyValue = 0;
private int mode = 0; // 0 - inactive, 1 - up, 2 - down
private int firstUncoveredY;
private boolean isEnabled = false;
int ticks = 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 (++ticks > 40)
{
ticks = 0;
// Switching mode
if (worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord))
{
mode = 2; // down
}
else
{
mode = 1; // up
}
isEnabled = (worldObj.isAirBlock(xCoord, yCoord + 1, zCoord) && worldObj.isAirBlock(xCoord, yCoord + 2, zCoord));
if (currentEnergyValue != MAX_ENERGY_VALUE || !isEnabled)
{
mode = 0;
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 2); // disabled
return;
}
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, mode, 2); // current mode
// Launch a beam
if (isEnabled)
{
// Search non-air blocks under lift
for (int ny = yCoord - 1; ny > 0; ny--)
{
if (!worldObj.isAirBlock(xCoord, ny, zCoord))
{
firstUncoveredY = ny;
break;
}
}
if (yCoord - firstUncoveredY > 0)
if (mode == 1)
{
sendLaserPacket(new Vector3(this).add(0.5), new Vector3(xCoord, firstUncoveredY, zCoord).add(0.5), 0f, 1f, 0f, 40, 0, 100);
}
else if (mode == 2)
{
sendLaserPacket(new Vector3(this).add(0.5), new Vector3(xCoord, firstUncoveredY, zCoord).add(0.5), 0f, 0f, 1f, 40, 0, 100);
}
liftEntity();
}
}
}
public void liftEntity()
{
int xmax, zmax, x1, x2, z1, z2;
int xmin, zmin;
final int CUBE_SIDE = 2;
x1 = xCoord + CUBE_SIDE / 2;
x2 = xCoord - CUBE_SIDE / 2;
if (x1 < x2)
{
xmin = x1;
xmax = x2;
}
else
{
xmin = x2;
xmax = x1;
}
z1 = zCoord + CUBE_SIDE / 2;
z2 = zCoord - CUBE_SIDE / 2;
if (z1 < z2)
{
zmin = z1;
zmax = z2;
}
else
{
zmin = z2;
zmax = z1;
}
// Lift up
if (mode == 1)
{
AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(xmin + 0.3, firstUncoveredY, zmin + 0.3, xmax - 0.3, yCoord, zmax - 0.3);
List list = worldObj.getEntitiesWithinAABBExcludingEntity(null, aabb);
if (list != null) // up
{
for (Object o : list)
{
if (o != null && o instanceof EntityLivingBase)
{
((EntityLivingBase)o).setPositionAndUpdate(xCoord + 0.5f, yCoord + 1, zCoord + 0.5f);
sendLaserPacket(new Vector3(this).add(0.5), new Vector3(xCoord, firstUncoveredY, zCoord).add(0.5), 1, 1, 0, 40, 0, 100);
worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:hilaser", 4F, 1F);
currentEnergyValue = 0;
return;
}
}
}
}
else if (mode == 2) // down
{
AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(xmin + 0.3, yCoord, zmin + 0.3, xmax - 0.3, yCoord + 2, zmax - 0.3);
List list = worldObj.getEntitiesWithinAABBExcludingEntity(null, aabb);
if (list != null)
{
for (Object o : list)
{
if (o != null && o instanceof EntityLivingBase)
{
((EntityLivingBase)o).setPositionAndUpdate(xCoord + 0.5f, firstUncoveredY + 1, zCoord + 0.5f);
sendLaserPacket(new Vector3(this).add(0.5), new Vector3(xCoord, firstUncoveredY + 1, zCoord).add(0.5), 1, 1, 0, 40, 0, 100);
worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:hilaser", 4F, 1F);
currentEnergyValue = 0;
return;
}
}
}
}
}
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);
}
}
@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());
}
// 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

@ -0,0 +1,700 @@
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 java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.network.packet.Packet62LevelSound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.inventory.IInventory;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidRegistry;
import appeng.api.WorldCoord;
import appeng.api.IAEItemStack;
import appeng.api.Util;
import appeng.api.events.GridTileLoadEvent;
import appeng.api.events.GridTileUnloadEvent;
import appeng.api.me.tiles.IGridMachine;
import appeng.api.me.tiles.ITileCable;
import appeng.api.me.util.IGridInterface;
import appeng.api.me.util.IMEInventoryHandler;
public class TileEntityMiningLaser extends TileEntity implements IPeripheral, IGridMachine, ITileCable
{
Boolean powerStatus = false;
private IGridInterface grid;
private int dx, dz, dy;
private boolean isMining = false;
private boolean isQuarry = false;
private boolean useDeiterium = false;
private boolean AENetworkReady = false;
private String[] methodsArray =
{
"mine", //0
"stop", //1
"isMining", //2
"quarry", //3
"state", //4
"offset" //5
};
private int delayTicksScan = 0;
private int delayTicksMine = 0;
private int currentMode = 0; // 0 - scan next layer, 1 - collect valuables
private int currentLayer;
private ArrayList<Vector3> valuablesInLayer = new ArrayList<Vector3>();
private int valuableIndex = 0;
private int layerOffset = 1;
private Vector3 minerVector;
//private long uid = 0;
TileEntityParticleBooster booster = null;
private boolean isOnEarth = false;
//int t = 20;
@Override
public void updateEntity()
{
if (isMining)
{
isOnEarth = (worldObj.provider.dimensionId == 0);
if (minerVector != null)
{
minerVector.x = xCoord;
minerVector.y = yCoord - 1;
minerVector.z = zCoord;
minerVector = minerVector.add(0.5);
}
if (currentMode == 0)
{
if (++delayTicksScan > WarpDriveConfig.i.ML_SCAN_DELAY)
{
delayTicksScan = 0;
valuablesInLayer.clear();
valuableIndex = 0;
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 ? 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);
int blockID = worldObj.getBlockId(xCoord, currentLayer, zCoord);
if (blockID != 0)
if (canDig(blockID))
harvestBlock(new Vector3(xCoord, currentLayer, zCoord));
currentMode = 1;
return;
}
else
--currentLayer;
}
if (currentLayer <= 0)
isMining = false;
}
}
else
{
if (++delayTicksMine > WarpDriveConfig.i.ML_MINE_DELAY && isMining)
{
delayTicksMine = 0;
while(valuableIndex < valuablesInLayer.size() && isMining)
{
Vector3 valuable = valuablesInLayer.get(valuableIndex++);
int blockID = worldObj.getBlockId(valuable.intX(), valuable.intY(), valuable.intZ());
if (blockID == 0 || !canDig(blockID))
continue;
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);
return;//top lel, yes yes
}
delayTicksMine = 0;
currentMode = 0;
--currentLayer;
}
}
}
}
private boolean canDig(int blockID)
{
if (blockID == 0)
return false;
if (Block.blocksList[blockID] != null)
return ( (WarpDriveConfig.i.MinerOres.contains(blockID) ||
Block.blocksList[blockID].blockHardness <= Block.obsidian.blockHardness) &&
blockID !=WarpDriveConfig.i.MFFS_Field &&
blockID != Block.bedrock.blockID );
else
return (blockID != WarpDriveConfig.i.MFFS_Field && blockID != Block.bedrock.blockID);
}
private void harvestBlock(Vector3 valuable)
{
int blockID = worldObj.getBlockId(valuable.intX(), valuable.intY(), valuable.intZ());
int blockMeta = worldObj.getBlockMetadata(valuable.intX(), valuable.intY(), valuable.intZ());
if (blockID != Block.waterMoving.blockID && blockID != Block.waterStill.blockID && blockID != Block.lavaMoving.blockID && blockID != Block.lavaStill.blockID)
{
List<ItemStack> stacks = getItemStackFromBlock(valuable.intX(), valuable.intY(), valuable.intZ(), blockID, blockMeta);
if (stacks != null)
for (ItemStack stack : stacks)
{
if (grid != null && AENetworkReady)
putInGrid(stack);
else
putInChest(findChest(), stack);
}
worldObj.playAuxSFXAtEntity(null, 2001, valuable.intX(), valuable.intY(), valuable.intZ(), blockID + (blockMeta << 12));
}
else if (blockID == Block.waterMoving.blockID || blockID == Block.waterStill.blockID)
// Evaporate water
worldObj.playSoundEffect((double)((float)valuable.intX() + 0.5F), (double)((float)valuable.intY() + 0.5F), (double)((float)valuable.intZ() + 0.5F), "random.fizz", 0.5F, 2.6F + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) * 0.8F);
worldObj.setBlockToAir(valuable.intX(), valuable.intY(), valuable.intZ());
}
private IInventory findChest()
{
TileEntity result = null;
result = worldObj.getBlockTileEntity(xCoord + 1, yCoord, zCoord);
if (result != null && result instanceof IInventory)
{
return (IInventory) result;
}
result = worldObj.getBlockTileEntity(xCoord - 1, yCoord, zCoord);
if (result != null && result instanceof IInventory)
{
return (IInventory) result;
}
result = worldObj.getBlockTileEntity(xCoord, yCoord, zCoord + 1);
if (result != null && result instanceof IInventory)
{
return (IInventory) result;
}
result = worldObj.getBlockTileEntity(xCoord, yCoord, zCoord - 1);
if (result != null && result instanceof IInventory)
{
return (IInventory) result;
}
result = worldObj.getBlockTileEntity(xCoord, yCoord + 1, zCoord);
if (result != null && result instanceof IInventory)
{
return (IInventory) result;
}
return null;
}
public List<ItemStack> getItemStackFromBlock(int i, int j, int k, int blockID, int blockMeta)
{
Block block = Block.blocksList[blockID];
if (block == null)
return null;
if (useDeiterium && grid != null && AENetworkReady)
{
IMEInventoryHandler cellArray = grid.getCellArray();
if (cellArray != null)
{
int consume = isQuarry?15:1000;
IAEItemStack entryToAEIS = Util.createItemStack(new ItemStack(WarpDriveConfig.i.AEExtraFDI, consume, FluidRegistry.getFluidID("deuterium")));
long contained = cellArray.countOfItemType(entryToAEIS);
if (block.canSilkHarvest(worldObj, null, i, j, k, blockMeta) && contained >= consume)
{
cellArray.extractItems(entryToAEIS);
ArrayList<ItemStack> t = new ArrayList<ItemStack>();
t.add(new ItemStack(blockID, 1, blockMeta));
return t;
}
}
}
return block.getBlockDropped(worldObj, i, j, k, blockMeta, 0);
}
public int putInGrid(ItemStack itemStackSource)
{
int transferred = itemStackSource.stackSize;
IMEInventoryHandler cellArray = grid.getCellArray();
if (cellArray != null)
{
IAEItemStack ret = cellArray.addItems(Util.createItemStack(itemStackSource));
if (ret != null)
transferred -= ret.getStackSize();
}
return transferred;
}
public int putInChest(IInventory inventory, ItemStack itemStackSource)
{
if (inventory == null || itemStackSource == null)
{
isMining = false; //stopping operation
return 0;
}
int transferred = 0;
for (int i = 0; i < inventory.getSizeInventory(); i++)
{
if (!inventory.isItemValidForSlot(i, itemStackSource))
{
continue;
}
ItemStack itemStack = inventory.getStackInSlot(i);
if (itemStack == null || !itemStack.isItemEqual(itemStackSource))
{
continue;
}
int transfer = Math.min(itemStackSource.stackSize - transferred, itemStack.getMaxStackSize() - itemStack.stackSize);
itemStack.stackSize += transfer;
transferred += transfer;
if (transferred == itemStackSource.stackSize)
{
return transferred;
}
}
for (int i = 0; i < inventory.getSizeInventory(); i++)
{
if (!inventory.isItemValidForSlot(i, itemStackSource))
{
continue;
}
ItemStack itemStack = inventory.getStackInSlot(i);
if (itemStack != null)
{
continue;
}
int transfer = Math.min(itemStackSource.stackSize - transferred, itemStackSource.getMaxStackSize());
ItemStack dest = copyWithSize(itemStackSource, transfer);
inventory.setInventorySlotContents(i, dest);
transferred += transfer;
if (transferred == itemStackSource.stackSize)
{
return transferred;
}
}
return transferred;
}
public ItemStack copyWithSize(ItemStack itemStack, int newSize)
{
ItemStack ret = itemStack.copy();
ret.stackSize = newSize;
return ret;
}
private void scanLayer()
{
valuablesInLayer.clear();
int xmax, zmax, x1, x2, z1, z2;
int xmin, zmin;
final int CUBE_SIDE = 8;
x1 = xCoord + CUBE_SIDE / 2;
x2 = xCoord - CUBE_SIDE / 2;
if (x1 < x2)
{
xmin = x1;
xmax = x2;
}
else
{
xmin = x2;
xmax = x1;
}
z1 = zCoord + CUBE_SIDE / 2;
z2 = zCoord - CUBE_SIDE / 2;
if (z1 < z2)
{
zmin = z1;
zmax = z2;
}
else
{
zmin = z2;
zmax = z1;
}
// Search for valuable blocks
for (int x = xmin; x <= xmax; x++)
for (int z = zmin; z <= zmax; z++)
{
int blockID = worldObj.getBlockId(x, currentLayer, z);
if (canDig(blockID))
if (isQuarry) // Quarry collects all blocks
{
if (!worldObj.isAirBlock(x, currentLayer, z) && blockID != Block.lavaMoving.blockID && blockID != Block.lavaStill.blockID)
valuablesInLayer.add(new Vector3(x, currentLayer, z));
}
else // Not-quarry collect only valuables blocks
if (WarpDriveConfig.i.MinerOres.contains(worldObj.getBlockId(x, currentLayer, z)))
valuablesInLayer.add(new Vector3(x, currentLayer, z));
}
valuableIndex = 0;
}
private boolean collectEnergyPacketFromBooster(int packet, boolean test)
{
if (booster == null)
booster = findFirstBooster();
if (booster != null)
if (test)
return packet <= booster.getCurrentEnergyValue();
else
return booster.consumeEnergy(packet);
return false;
}
private TileEntityParticleBooster findFirstBooster()
{
TileEntity result;
result = worldObj.getBlockTileEntity(xCoord + 1, yCoord, zCoord);
if (result != null && result instanceof TileEntityParticleBooster)
{
dx = 1;
dz = 0;
dy = 0;
return (TileEntityParticleBooster) result;
}
result = worldObj.getBlockTileEntity(xCoord - 1, yCoord, zCoord);
if (result != null && result instanceof TileEntityParticleBooster)
{
dx = -1;
dz = 0;
dy = 0;
return (TileEntityParticleBooster) result;
}
result = worldObj.getBlockTileEntity(xCoord, yCoord, zCoord + 1);
if (result != null && result instanceof TileEntityParticleBooster)
{
dx = 0;
dz = 1;
dy = 0;
return (TileEntityParticleBooster) result;
}
result = worldObj.getBlockTileEntity(xCoord, yCoord, zCoord - 1);
if (result != null && result instanceof TileEntityParticleBooster)
{
dx = 0;
dz = -1;
dy = 0;
return (TileEntityParticleBooster) result;
}
result = worldObj.getBlockTileEntity(xCoord, yCoord + 1, zCoord);
if (result != null && result instanceof TileEntityParticleBooster)
{
dx = 0;
dz = 0;
dy = 1;
return (TileEntityParticleBooster) result;
}
return null;
}
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)
{
if (source == null || dest == null || worldObj == null)
{
return;
}
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(0);
}
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);
MinecraftServer.getServer().getConfigurationManager().sendToAllNear(dest.intX(), dest.intY(), dest.intZ(), radius, worldObj.provider.dimensionId, packet);
}
}
@Override
public void readFromNBT(NBTTagCompound tag)
{
super.readFromNBT(tag);
isMining = tag.getBoolean("isMining");
isQuarry = tag.getBoolean("isQuarry");
currentLayer = tag.getInteger("currentLayer");
useDeiterium = tag.getBoolean("useDeiterium");
minerVector = new Vector3(xCoord, yCoord - 1, zCoord).add(0.5);
}
@Override
public void writeToNBT(NBTTagCompound tag)
{
super.writeToNBT(tag);
tag.setBoolean("isMining", isMining);
tag.setBoolean("isQuarry", isQuarry);
tag.setInteger("currentLayer", currentLayer);
tag.setBoolean("useDeiterium", useDeiterium);
}
//CC
// IPeripheral methods implementation
@Override
public String getType()
{
return "mininglaser";
}
@Override
public String[] getMethodNames()
{
return methodsArray;
}
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
{
switch (method)
{
case 0: // Mine()
if (isMining)
return new Boolean[] { false };
isQuarry = false;
delayTicksScan = 0;
currentMode = 0;
minerVector = new Vector3(xCoord, yCoord - 1, zCoord).add(0.5);
currentLayer = yCoord - layerOffset;
isMining = true;
useDeiterium = (arguments.length == 1 && FluidRegistry.isFluidRegistered("deuterium"));
return new Boolean[] { true };
case 1: // stop()
isMining = false;
break;
case 2: // isMining()
return new Boolean[] { isMining };
case 3: // Quarry()
if (isMining)
return new Boolean[] { false };
isQuarry = true;
delayTicksScan = 0;
currentMode = 0;
minerVector = new Vector3(xCoord, yCoord - 1, zCoord).add(0.5);
currentLayer = yCoord - layerOffset;
isMining = true;
useDeiterium = (arguments.length == 1 && FluidRegistry.isFluidRegistered("deuterium"));
return new Boolean[] { true };
case 4: // State is: state, energy, currentLayer, valuablesMined, valuablesInLayer = getMinerState()
int energy = 0;
if (booster != null)
energy = booster.getCurrentEnergyValue();
String state = "not mining";
Integer valuablesInLayer, valuablesMined;
if (isMining)
{
valuablesInLayer = this.valuablesInLayer.size();
valuablesMined = this.valuableIndex;
state = "mining" + ((isQuarry) ? " (quarry mode)" : "");
if (energy < 0)
state = "out of energy";
return new Object[] {state, energy, currentLayer, valuablesMined, valuablesInLayer};
}
return new Object[] {state, energy, currentLayer, 0, 0};
case 5: // Offset
if (arguments.length == 1)
{
int t = ((Double)arguments[0]).intValue();
if (t < 0)
t = 0;
layerOffset = t + 1;
}
return new Integer[] { layerOffset-1 };
}
return null;
}
@Override
public boolean canAttachToSide(int side)
{
return true;
}
@Override
public void attach(IComputerAccess computer)
{
}
@Override
public void detach(IComputerAccess computer)
{
}
//AE
@Override
public float getPowerDrainPerTick()
{
return 1;
}
@Override
public void validate()
{
super.validate();
MinecraftForge.EVENT_BUS.post(new GridTileLoadEvent(this, worldObj, getLocation()));
}
@Override
public void invalidate()
{
super.invalidate();
MinecraftForge.EVENT_BUS.post(new GridTileUnloadEvent(this, worldObj, getLocation()));
}
@Override
public WorldCoord getLocation()
{
return new WorldCoord(xCoord, yCoord, zCoord);
}
@Override
public boolean isValid()
{
return true;
}
@Override
public void setPowerStatus(boolean hasPower)
{
powerStatus = hasPower;
}
@Override
public boolean isPowered()
{
return powerStatus;
}
@Override
public IGridInterface getGrid()
{
return grid;
}
@Override
public void setGrid(IGridInterface gi)
{
grid = gi;
}
@Override
public World getWorld()
{
return worldObj;
}
@Override
public boolean coveredConnections()
{
return true;
}
public void setNetworkReady( boolean isReady )
{
AENetworkReady = isReady;
}
public boolean isMachineActive()
{
return true;
}
}

View file

@ -0,0 +1,151 @@
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 java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.network.packet.Packet62LevelSound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.ChunkPosition;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.MinecraftForge;
public class TileEntityMonitor extends TileEntity implements IPeripheral
{
private int frequency;
private String[] methodsArray =
{
"freq"
};
private int packetSendTicks = 20;
@Override
public void updateEntity()
{
if (FMLCommonHandler.instance().getEffectiveSide().isServer())
{
if (packetSendTicks-- == 0)
{
packetSendTicks = 20 * 5;
sendFreqPacket();
}
return;
}
}
public int getFrequency()
{
return frequency;
}
public void setFrequency(int freq)
{
frequency = freq;
}
@Override
public void readFromNBT(NBTTagCompound tag)
{
super.readFromNBT(tag);
frequency = tag.getInteger("frequency");
}
@Override
public void writeToNBT(NBTTagCompound tag)
{
super.writeToNBT(tag);
tag.setInteger("frequency", frequency);
}
// IPeripheral methods implementation
@Override
public String getType()
{
return "monitor";
}
@Override
public String[] getMethodNames()
{
return methodsArray;
}
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
{
if (arguments.length == 1)
frequency = ((Double)arguments[0]).intValue();
return new Integer[] { frequency };
}
public void sendFreqPacket()
{
Side side = FMLCommonHandler.instance().getEffectiveSide();
if (side == Side.SERVER)
{
ByteArrayOutputStream bos = new ByteArrayOutputStream(8);
DataOutputStream outputStream = new DataOutputStream(bos);
try
{
// Write source vector
outputStream.writeInt(xCoord);
outputStream.writeInt(yCoord);
outputStream.writeInt(zCoord);
outputStream.writeInt(this.frequency);
}
catch (Exception ex)
{
ex.printStackTrace();
}
Packet250CustomPayload packet = new Packet250CustomPayload();
packet.channel = "WarpDriveFreq";
packet.data = bos.toByteArray();
packet.length = bos.size();
MinecraftServer.getServer().getConfigurationManager().sendToAllNear(xCoord, yCoord, zCoord, 100, worldObj.provider.dimensionId, packet);
}
}
@Override
public boolean canAttachToSide(int side)
{
return true;
}
@Override
public void attach(IComputerAccess computer)
{
}
@Override
public void detach(IComputerAccess computer)
{
}
}

View file

@ -0,0 +1,150 @@
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 java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraftforge.common.MinecraftForge;
public class TileEntityParticleBooster extends TileEntity implements IEnergySink
{
public boolean addedToEnergyNet = false;
private int currentEnergyValue = 0;
int ticks = 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 (++ticks > 40)
{
ticks = 0;
currentEnergyValue = Math.min(currentEnergyValue, WarpDriveConfig.i.PB_MAX_ENERGY_VALUE);
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, currentEnergyValue / 10000, 2);
}
}
@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());
}
// IEnergySink methods implementation
@Override
public double demandedEnergyUnits()
{
return (WarpDriveConfig.i.PB_MAX_ENERGY_VALUE - currentEnergyValue);
}
@Override
public double injectEnergyUnits(ForgeDirection directionFrom, double amount)
{
double leftover = 0;
currentEnergyValue += Math.round(amount);
if (getCurrentEnergyValue() > WarpDriveConfig.i.PB_MAX_ENERGY_VALUE)
{
leftover = (getCurrentEnergyValue() - WarpDriveConfig.i.PB_MAX_ENERGY_VALUE);
currentEnergyValue = WarpDriveConfig.i.PB_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 boolean consumeEnergy(int amount)
{
if (currentEnergyValue - amount < 0)
{
return false;
}
currentEnergyValue -= amount;
return true;
}
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

@ -0,0 +1,683 @@
package cr0s.WarpDrive;
import cpw.mods.fml.common.FMLCommonHandler;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.ILuaContext;
import dan200.computer.api.IPeripheral;
import java.util.ArrayList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.DamageSource;
/**
* Protocol block tile entity
* @author Cr0s
*/
public class TileEntityProtocol extends TileEntity implements IPeripheral
{
// Variables
private int distance = 0;
private int direction = 0;
private int mode = 0;
private boolean jumpFlag = false;
private boolean summonFlag = false;
private String toSummon = "";
private String targetJumpgateName = "";
// Gabarits
private int front, right, up;
private int back, left, down;
// Player attaching
public ArrayList<String> players = new ArrayList();
public String playersString = "";
private String beaconFrequency = "";
boolean ready = false; // Ready to operate (valid assembly)
public String[] methodsArray =
{
"dim_getp", "dim_setp", // 0, 1
"dim_getn", "dim_setn", // 2, 3
"set_mode", "set_distance", "set_direction", // 4, 5, 6
"get_attached_players", "summon", "summon_all", // 7, 8, 9
"get_x", "get_y", "get_z", // 10, 11, 12
"get_energy_level", "do_jump", "get_ship_size", // 13, 14, 15
"set_beacon_frequency", "get_dx", "get_dz", // 16, 17, 18
"set_core_frequency", "is_in_space", "is_in_hyperspace", // 19, 20, 21
"set_target_jumpgate", // 22
};
private int ticks = 0;
private final int BLOCK_UPDATE_INTERVAL = 20 * 3; // 3 seconds
private TileEntity core;
@Override
public void updateEntity()
{
if (FMLCommonHandler.instance().getEffectiveSide().isClient())
{
return;
}
if (++ticks >= BLOCK_UPDATE_INTERVAL)
{
findCoreBlock();
if (core != null)
{
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, this.mode, 1 + 2); // Activated
}
else
{
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 1 + 2); // Inactive
}
ticks = 0;
}
}
private void setJumpDistance(int distance)
{
this.distance = distance;
}
private void setMode(int mode)
{
this.mode = mode;
}
private void setDirection(int dir)
{
if (dir == 1)
{
dir = -1;
}
else if (dir == 2)
{
dir = -2;
}
else if (dir == 255)
{
dir = 270;
}
this.direction = dir;
}
private void doJump()
{
if (core != null && core instanceof TileEntityReactor)
{
((TileEntityReactor)core).randomCooldownAddition = worldObj.rand.nextInt(60); // Adding random ticks to cooldown
}
setJumpFlag(true);
}
@Override
public void readFromNBT(NBTTagCompound tag)
{
super.readFromNBT(tag);
setMode(tag.getInteger("mode"));
setFront(tag.getInteger("front"));
setRight(tag.getInteger("right"));
setUp(tag.getInteger("up"));
setBack(tag.getInteger("back"));
setLeft(tag.getInteger("left"));
setDown(tag.getInteger("down"));
setDistance(tag.getInteger("distance"));
playersString = tag.getString("players");
updatePlayersList();
setBeaconFrequency(tag.getString("bfreq"));
}
@Override
public void writeToNBT(NBTTagCompound tag)
{
super.writeToNBT(tag);
updatePlayersString();
tag.setString("players", playersString);
tag.setInteger("mode", this.mode);
tag.setInteger("front", this.front);
tag.setInteger("right", this.right);
tag.setInteger("up", this.up);
tag.setInteger("back", this.back);
tag.setInteger("left", this.left);
tag.setInteger("down", this.down);
tag.setInteger("distance", this.distance);
tag.setString("bfreq", getBeaconFrequency());
}
public void attachPlayer(EntityPlayer ep)
{
for (int i = 0; i < players.size(); i++)
{
String nick = players.get(i);
if (ep.username.equals(nick))
{
ep.addChatMessage("[WarpCtrlr] Detached.");
players.remove(i);
return;
}
}
ep.attackEntityFrom(DamageSource.generic, 1);
ep.addChatMessage("[WarpCtrlr] Successfully attached.");
players.add(ep.username);
updatePlayersString();
}
public void updatePlayersString()
{
String nick;
this.playersString = "";
for (int i = 0; i < players.size(); i++)
{
nick = players.get(i);
this.playersString += nick + "|";
}
}
public void updatePlayersList()
{
String[] playersArray = playersString.split("\\|");
for (int i = 0; i < playersArray.length; i++)
{
String nick = playersArray[i];
if (!nick.isEmpty())
{
players.add(nick);
}
}
}
public String getAttachedPlayersList()
{
String list = "";
for (int i = 0; i < this.players.size(); i++)
{
String nick = this.players.get(i);
list += nick + ((i == this.players.size() - 1) ? "" : ", ");
}
if (players.isEmpty())
{
list = "<nobody>";
}
return list;
}
/**
* @return the jumpFlag
*/
public boolean isJumpFlag()
{
return jumpFlag;
}
/**
* @param jumpFlag the jumpFlag to set
*/
public void setJumpFlag(boolean jumpFlag)
{
this.jumpFlag = jumpFlag;
}
/**
* @return the front
*/
public int getFront()
{
return front;
}
/**
* @param front the front to set
*/
public void setFront(int front)
{
this.front = front;
}
/**
* @return the right
*/
public int getRight()
{
return right;
}
/**
* @param right the right to set
*/
public void setRight(int right)
{
this.right = right;
}
/**
* @return the up
*/
public int getUp()
{
return up;
}
/**
* @param up the up to set
*/
public void setUp(int up)
{
this.up = up;
}
/**
* @return the back
*/
public int getBack()
{
return back;
}
/**
* @param back the back to set
*/
public void setBack(int back)
{
this.back = back;
}
/**
* @return the left
*/
public int getLeft()
{
return left;
}
/**
* @param left the left to set
*/
public void setLeft(int left)
{
this.left = left;
}
/**
* @return the down
*/
public int getDown()
{
return down;
}
/**
* @param down the down to set
*/
public void setDown(int down)
{
this.down = down;
}
public void setDistance(int distance)
{
this.distance = distance;
}
public int getDistance()
{
return this.distance;
}
/**
* @return the mode
*/
public int getMode()
{
return mode;
}
/**
* @return the direction
*/
public int getDirection()
{
return direction;
}
/**
* @return the summonFlag
*/
public boolean isSummonAllFlag()
{
return summonFlag;
}
/**
* @param summonFlag the summonFlag to set
*/
public void setSummonAllFlag(boolean summonFlag)
{
this.summonFlag = summonFlag;
}
@Override
public String getType()
{
return "warpcore";
}
@Override
public String[] getMethodNames()
{
return (methodsArray);
}
@Override
public boolean canAttachToSide(int side)
{
return true;
}
@Override
public void attach(IComputerAccess computer)
{
}
@Override
public void detach(IComputerAccess computer)
{
}
/**
* @return the toSummon
*/
public String getToSummon()
{
return toSummon;
}
/**
* @param toSummon the toSummon to set
*/
public void setToSummon(String toSummon)
{
this.toSummon = toSummon;
}
/**
* @return the beaconFrequency
*/
public String getBeaconFrequency()
{
return beaconFrequency;
}
/**
* @param beaconFrequency the beaconFrequency to set
*/
public void setBeaconFrequency(String beaconFrequency)
{
this.beaconFrequency = beaconFrequency;
}
public TileEntity findCoreBlock()
{
this.core = worldObj.getBlockTileEntity(xCoord + 1, yCoord, zCoord);
if (this.core != null && this.core instanceof TileEntityReactor)
{
return this.core;
}
this.core = worldObj.getBlockTileEntity(xCoord - 1, yCoord, zCoord);
if (this.core != null && this.core instanceof TileEntityReactor)
{
return this.core;
}
this.core = worldObj.getBlockTileEntity(xCoord, yCoord, zCoord + 1);
if (this.core != null && this.core instanceof TileEntityReactor)
{
return this.core;
}
this.core = worldObj.getBlockTileEntity(xCoord, yCoord, zCoord - 1);
if (this.core != null && this.core instanceof TileEntityReactor)
{
return this.core;
}
return null;
}
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
{
switch (method)
{
case 0: // dim_getp ()
return new Integer[] { getFront(), getRight(), getUp() };
case 1: // dim_setp (front, right, up)
if ( arguments.length != 3 ||
( ( (Double)arguments[0] ).intValue() < 0 ||
( (Double)arguments[1] ).intValue() < 0 ||
( (Double)arguments[2] ).intValue() < 0 ||
( (Double)arguments[0] ).intValue() > WarpDriveConfig.i.WC_MAX_SHIP_SIDE ||
( (Double)arguments[1] ).intValue() > WarpDriveConfig.i.WC_MAX_SHIP_SIDE ||
( (Double)arguments[2] ).intValue() > WarpDriveConfig.i.WC_MAX_SHIP_SIDE ) )
{
return new Integer[] { -1 };
}
setFront(((Double)arguments[0]).intValue());
setRight(((Double)arguments[1]).intValue());
setUp(((Double)arguments[2]).intValue());
WarpDrive.instance.registry.removeDeadCores();
break;
case 2: // dim_getn ()
return new Integer[] { getBack(), getLeft(), getDown() };
case 3: // dim_setn (back, left, down)
if ( arguments.length != 3 ||
( ( (Double)arguments[0] ).intValue() < 0 ||
( (Double)arguments[1] ).intValue() < 0 ||
( (Double)arguments[2] ).intValue() < 0 ||
( (Double)arguments[0] ).intValue() > WarpDriveConfig.i.WC_MAX_SHIP_SIDE ||
( (Double)arguments[1] ).intValue() > WarpDriveConfig.i.WC_MAX_SHIP_SIDE ||
( (Double)arguments[2] ).intValue() > WarpDriveConfig.i.WC_MAX_SHIP_SIDE ) )
{
return new Integer[] { -1 };
}
setBack(((Double)arguments[0]).intValue());
setLeft(((Double)arguments[1]).intValue());
setDown(((Double)arguments[2]).intValue());
WarpDrive.instance.registry.removeDeadCores();
break;
case 4: // set_mode (mode)
if (arguments.length != 1)
{
return new Integer[] { -1 };
}
setMode(((Double)arguments[0]).intValue());
break;
case 5: // set_distance (distance)
if (arguments.length != 1)
{
return new Integer[] { -1 };
}
setJumpDistance(((Double)arguments[0]).intValue());
break;
case 6: // set_direction (dir)
if (arguments.length != 1)
{
return new Integer[] { -1 };
}
setDirection(((Double)arguments[0]).intValue());
break;
case 7: // get_attached_players
String list = "";
for (int i = 0; i < this.players.size(); i++)
{
String nick = this.players.get(i);
list += nick + ((i == this.players.size() - 1) ? "" : ",");
}
if (players.isEmpty())
{
list = "";
}
return new Object[] { (String)list };
case 8: // summon
if (arguments.length != 1)
{
return new Integer[] { -1 };
}
int playerID = ((Double)arguments[0]).intValue();
if (playerID >= 0 && playerID < players.size())
{
setToSummon(players.get(playerID));
}
break;
case 9: // summon_all
this.setSummonAllFlag(true);
case 10: // get_x
if (core == null)
{
return null;
}
return new Object[] { (Integer)core.xCoord };
case 11: // get_y
if (core == null)
{
return null;
}
return new Object[] { (Integer)core.yCoord };
case 12: // get_z
if (core == null)
{
return null;
}
return new Object[] { (Integer)core.zCoord };
case 13: // get_energy_value
if (core != null)
{
return new Object[] { (Integer)((TileEntityReactor)core).currentEnergyValue };
}
return null;
case 14: // do_jump
doJump();
break;
case 15: // get_ship_size
if (core != null)
{
((TileEntityReactor)core).calculateSpatialShipParameters();
return new Object[] { (Integer)((TileEntityReactor)core).getRealShipVolume() };
}
break;
case 16: // set_beacon_frequency
if (arguments.length == 1)
{
setBeaconFrequency((String)arguments[0]);
}
break;
case 17: // get_dx
if (core != null && core instanceof TileEntityReactor)
{
return new Object[] { (Integer)(((TileEntityReactor)core).dx) };
}
break;
case 18: // get_dz
if (core != null && core instanceof TileEntityReactor)
{
return new Object[] { (Integer)(((TileEntityReactor)core).dz) };
}
break;
case 19: // set_core_frequency
if (arguments.length == 1 && (core != null && core instanceof TileEntityReactor))
{
((TileEntityReactor)core).coreFrequency = ((String)arguments[0]).replace("/", "").replace(".", "").replace("\\", ".");
}
break;
case 20: // is_in_space
return new Boolean[] { worldObj.provider.dimensionId == WarpDrive.instance.spaceDimID };
case 21: // is_in_hyperspace
return new Boolean[] { worldObj.provider.dimensionId == WarpDrive.instance.hyperSpaceDimID };
case 22: // set_target_jumpgate
if (arguments.length == 1)
{
setTargetJumpgateName((String)arguments[0]);
}
break;
}
return new Integer[] { 0 };
}
/**
* @return the targetJumpgateName
*/
public String getTargetJumpgateName()
{
return targetJumpgateName;
}
/**
* @param targetJumpgateName the targetJumpgateName to set
*/
public void setTargetJumpgateName(String targetJumpgateName)
{
this.targetJumpgateName = targetJumpgateName;
}
}

View file

@ -0,0 +1,256 @@
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 java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraftforge.common.MinecraftForge;
public class TileEntityRadar extends TileEntity implements IPeripheral, IEnergySink
{
public boolean addedToEnergyNet = false;
private int currentEnergyValue = 0;
private String[] methodsArray =
{
"scanRay", // 0
"scanRadius", // 1
"getResultsCount", // 2
"getResult", // 3
"getEnergyLevel", // 4
"pos" // 5
};
private ArrayList<TileEntityReactor> results;
private int scanRadius = 0;
private int cooldownTime = 0;
private boolean isEnergyEnoughForScanRadiusW(int radius)
{
int needEnergy = (radius * radius);
return ((getCurrentEnergyValue() - needEnergy) > 0);
}
@Override
public void updateEntity()
{
if (!addedToEnergyNet && !this.tileEntityInvalid)
{
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
addedToEnergyNet = true;
}
if (FMLCommonHandler.instance().getEffectiveSide().isClient())
{
return;
}
try
{
if (worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 2)
{
if (cooldownTime++ > (20 * ((scanRadius / 1000) + 1)))
{
WarpDrive.instance.registry.removeDeadCores();
results = WarpDrive.instance.registry.searchWarpCoresInRadius(xCoord, yCoord, zCoord, scanRadius);
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 1, 1 + 2);
cooldownTime = 0;
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
@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());
}
// IPeripheral methods implementation
@Override
public String getType()
{
return "radar";
}
@Override
public String[] getMethodNames()
{
return methodsArray;
}
@Override
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception
{
switch (method)
{
case 0: // scanRay (toX, toY, toZ)
return new Object[] { -1 };
case 1: // scanRadius (radius)
if (arguments.length == 1)
{
int radius = ((Double)arguments[0]).intValue();
if (radius <= 0 || radius > 10000)
{
scanRadius = 0;
return new Boolean[] { false };
}
if (radius != 0 && isEnergyEnoughForScanRadiusW(radius))
{
// Consume energy
this.currentEnergyValue -= radius * radius;
// Begin searching
scanRadius = radius;
cooldownTime = 0;
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 2, 1 + 2);
}
else
{
results = null;
return new Boolean[] { false };
}
}
else
return new Boolean[] { false };
return new Boolean[] { true };
case 2: // getResultsCount
if (results != null)
return new Integer[] { results.size() };
return new Integer[] { 0 };
case 3: // getResult
if (arguments.length == 1 && (results != null))
{
int index = ((Double)arguments[0]).intValue();
if (index > -1 && index < results.size())
{
TileEntityReactor res = results.get(index);
if (res != null)
{
int yAddition = (res.worldObj.provider.dimensionId == WarpDrive.instance.spaceDimID) ? 256 : (res.worldObj.provider.dimensionId == WarpDrive.instance.hyperSpaceDimID) ? 512 : 0;
return new Object[] { (String)res.coreFrequency, (Integer)res.xCoord, (Integer)res.yCoord + yAddition, (Integer)res.zCoord };
}
}
}
return new Object[] { (String)"FAIL", 0, 0, 0 };
case 4: // getEnergyLevel
return new Integer[] { getCurrentEnergyValue() };
case 5: // Pos
return new Integer[] { xCoord, yCoord, zCoord };
}
return null;
}
@Override
public boolean canAttachToSide(int side)
{
return true;
}
@Override
public void attach(IComputerAccess computer)
{
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 1, 1 + 2);
}
@Override
public void detach(IComputerAccess computer)
{
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 1 + 2);
}
// IEnergySink methods implementation
@Override
public double demandedEnergyUnits()
{
return (WarpDriveConfig.i.WR_MAX_ENERGY_VALUE - currentEnergyValue);
}
@Override
public double injectEnergyUnits(ForgeDirection directionFrom, double amount)
{
double leftover = 0;
currentEnergyValue += Math.round(amount);
if (getCurrentEnergyValue() > WarpDriveConfig.i.WR_MAX_ENERGY_VALUE)
{
leftover = (getCurrentEnergyValue() - WarpDriveConfig.i.WR_MAX_ENERGY_VALUE);
currentEnergyValue = WarpDriveConfig.i.WR_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;
}
@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();
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,48 +0,0 @@
package cr0s.WarpDrive.client;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import mcp.mobius.waila.api.IWailaDataProvider;
import mcp.mobius.waila.api.IWailaRegistrar;
import java.util.List;
import cr0s.WarpDrive.machines.TileEntityReactor;
import cr0s.WarpDrive.machines.WarpEnergyTE;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
public class WailaHandler implements IWailaDataProvider {
@Override
public ItemStack getWailaStack(IWailaDataAccessor accessor, IWailaConfigHandler config) {
return null;
}
@Override
public List<String> getWailaHead(ItemStack itemStack, List<String> toolTip, IWailaDataAccessor accessor, IWailaConfigHandler config) {
return toolTip;
}
@Override
public List<String> getWailaBody(ItemStack itemStack, List<String> toolTip, IWailaDataAccessor accessor, IWailaConfigHandler config) {
if (accessor.getTileEntity() instanceof WarpEnergyTE) {
WarpEnergyTE energyTE = (WarpEnergyTE) accessor.getTileEntity();
toolTip.add(String.format("Energy level %.0f %% (%d/%d EU)", (energyTE.getEnergyStored() * 100.0F / energyTE.getMaxEnergyStored()), energyTE.getEnergyStored(), + energyTE.getMaxEnergyStored()));
if (energyTE instanceof TileEntityReactor) {
TileEntityReactor reactorTE = (TileEntityReactor) energyTE;
toolTip.add(String.format("Cooldown remaining: %d s", Math.ceil(reactorTE.getCooldown() / 20)));
}
}
return toolTip;
}
@Override
public List<String> getWailaTail(ItemStack itemStack, List<String> toolTip, IWailaDataAccessor accessor, IWailaConfigHandler config) {
return toolTip;
}
public static void callbackRegister(IWailaRegistrar registrar) {
WailaHandler instance = new WailaHandler();
registrar.registerBodyProvider(instance, WarpEnergyTE.class);
}
}

View file

@ -0,0 +1,42 @@
package cr0s.serverMods;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.MathHelper;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.living.LivingFallEvent;
/**
* Гашение урона при падении с джетпаком или квантовыми бутсами
* @author Cr0s
*/
public class AntiFallDamage
{
private final int JETPACK_ID = 29954;
private final int ELECTRIC_JETPACK_ID = 29953;
private final int QUANTUM_BOOTS_ID = 29915;
@ForgeSubscribe
public void livingFall(LivingFallEvent event)
{
EntityLivingBase entity = event.entityLiving;
float distance = event.distance;
if (entity instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer) entity;
int check = MathHelper.ceiling_float_int(distance - 3.0F);
if (check > 0) // Падение может нанести урон
{
// Проверяем наличие защиты
if ((player.getCurrentArmor(0) != null && player.getCurrentArmor(0).itemID == QUANTUM_BOOTS_ID) ||
(player.getCurrentArmor(2) != null && player.getCurrentArmor(2).itemID == JETPACK_ID) ||
(player.getCurrentArmor(2) != null && player.getCurrentArmor(2).itemID == ELECTRIC_JETPACK_ID))
{
event.setCanceled(true); // Блокируем падение, если защита есть
}
}
}
}
}

View file

@ -0,0 +1,9 @@
package cr0s.serverMods;
public class CommonProxy
{
// some code goes here
public void setupLoginHook()
{
}
}

View file

@ -0,0 +1,135 @@
package cr0s.serverMods;
import cpw.mods.fml.common.network.IConnectionHandler;
import cpw.mods.fml.common.network.Player;
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.NetLoginHandler;
import net.minecraft.network.packet.NetHandler;
import net.minecraft.network.packet.Packet1Login;
import net.minecraft.server.MinecraftServer;
import com.google.common.base.Strings;
public class LoginHookClass implements IConnectionHandler
{
private String checkLogin(String s) throws FileNotFoundException, IOException
{
if (s.indexOf(".") == -1 || s.split("\\.").length != 2)
return "Никнейм и пароль должны быть разделены точками.";
if (!s.matches("^[a-zA-Z0-9_.]+$"))
return "Имя пользователя или пароль содержат недопустимые символы.";
String s4 = s.split("\\.")[0].trim();
String s5 = s.split("\\.")[1].trim();
if (s4.length() < 2 && !s4.equals("Q"))
return "Имя пользователя слишком короткое.";
if (s5.length() < 3)
return "Пароль слишком короткий.";
if (s4.length() > 15)
return "Слишком длинный логин! (>15)";
BufferedReader bufferedreader = new BufferedReader(new FileReader(MinecraftServer.getServer().getFile("users.txt")));
String s1;
while ((s1 = bufferedreader.readLine()) != null)
{
String s2;
String s3;
try
{
s2 = s1.split("\\.")[0];
s3 = s1.split("\\.")[1];
}
catch (Exception exception)
{
bufferedreader.close();
return "login.password error, database is corrupted.";
}
if (s2.toLowerCase().equals(s4.toLowerCase()))
{
if (!s3.equals(s5))
{
System.out.println((new StringBuilder()).append(s).append(" failed to login (pwd: ").append(s3).append(")").toString());
bufferedreader.close();
return "Неправильный пароль!";
}
else
{
bufferedreader.close();
return "";
}
}
}
bufferedreader.close();
PrintWriter printwriter = new PrintWriter(new FileWriter(MinecraftServer.getServer().getFile("users.txt"), true));
printwriter.println(s);
printwriter.close();
return "";
}
@Override
public void playerLoggedIn(Player player, NetHandler netHandler, INetworkManager manager)
{
//throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public String connectionReceived(NetLoginHandler netHandler, INetworkManager manager)
{
String kickReason = "";
String s = netHandler.clientUsername;
try
{
kickReason = checkLogin(s);
System.out.println("[SERVER MODS] Logging in user: " + s + " Result: " + kickReason);
}
catch (FileNotFoundException ex)
{
Logger.getLogger(LoginHookClass.class.getName()).log(Level.SEVERE, null, ex);
}
catch (IOException ex)
{
Logger.getLogger(LoginHookClass.class.getName()).log(Level.SEVERE, null, ex);
}
if (Strings.isNullOrEmpty(kickReason))
netHandler.clientUsername = s.split("\\.")[0];
return kickReason;
}
@Override
public void connectionOpened(NetHandler netClientHandler, String server, int port, INetworkManager manager)
{
//throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void connectionOpened(NetHandler netClientHandler, MinecraftServer server, INetworkManager manager)
{
//throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void connectionClosed(INetworkManager manager)
{
//throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void clientLoggedIn(NetHandler clientHandler, INetworkManager manager, Packet1Login login)
{
//throw new UnsupportedOperationException("Not supported yet.");
}
}

View file

@ -0,0 +1,47 @@
package cr0s.serverMods;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import net.minecraftforge.common.MinecraftForge;
import cr0s.WarpDrive.SpaceEventHandler;
@Mod(modid = "ServerMods", name = "ServerMods", version = "0.0.1")
@NetworkMod(clientSideRequired = false, serverSideRequired = true, connectionHandler = LoginHookClass.class)
/**
* @author Cr0s
*/
public class ServerMods
{
// The instance of your mod that Forge uses.
@Instance("ServerMods")
public static ServerMods instance;
@PreInit
public void preInit(FMLPreInitializationEvent event)
{
// Stub Method
}
@Init
public void load(FMLInitializationEvent event)
{
// Включить авторизацию (включается автоматически)
//proxy.setupLoginHook();
// Снять урон от падения с джетпаком и крузис-тапками
MinecraftForge.EVENT_BUS.register(new AntiFallDamage());
}
@PostInit
public void postInit(FMLPostInitializationEvent event)
{
// Stub Method
}
}