Added Annihilation Plane.

This commit is contained in:
AlgorithmX2
2014-02-13 22:27:15 -06:00
parent 3d09f6918f
commit 07b1bb8473
5 changed files with 387 additions and 13 deletions
+26 -10
View File
@@ -6,6 +6,7 @@ import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.item.Item;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
@@ -21,6 +22,10 @@ public class EnergyFx extends EntityBreakingFX
private IIcon particleTextureIndex;
private int startBlkX;
private int startBlkY;
private int startBlkZ;
public EnergyFx(World par1World, double par2, double par4, double par6, Item par8Item) {
super( par1World, par2, par4, par6, par8Item );
particleGravity = 0;
@@ -30,6 +35,10 @@ public class EnergyFx extends EntityBreakingFX
this.particleAlpha = 1.4f;
this.particleScale = 3.5f;
this.particleTextureIndex = ExtraTextures.BlockEnergyParticle.getIcon();
startBlkX = MathHelper.floor_double( posX );
startBlkY = MathHelper.floor_double( posY );
startBlkZ = MathHelper.floor_double( posZ );
}
public void fromItem(ForgeDirection d)
@@ -49,7 +58,6 @@ public class EnergyFx extends EntityBreakingFX
public void renderParticle(Tessellator par1Tessellator, float par2, float par3, float par4, float par5, float par6, float par7)
{
Minecraft.getMinecraft().getTextureManager().bindTexture( TextureMap.locationBlocksTexture );
GL11.glPushMatrix();
@@ -72,15 +80,23 @@ public class EnergyFx extends EntityBreakingFX
float f13 = (float) (this.prevPosZ + (this.posZ - this.prevPosZ) * (double) par2 - interpPosZ);
float f14 = 1.0F;
par1Tessellator.setColorRGBA_F( this.particleRed * f14, this.particleGreen * f14, this.particleBlue * f14, this.particleAlpha );
par1Tessellator.addVertexWithUV( (double) (f11 - par3 * f10 - par6 * f10), (double) (f12 - par4 * f10), (double) (f13 - par5 * f10 - par7 * f10),
(double) f7, (double) f9 );
par1Tessellator.addVertexWithUV( (double) (f11 - par3 * f10 + par6 * f10), (double) (f12 + par4 * f10), (double) (f13 - par5 * f10 + par7 * f10),
(double) f7, (double) f8 );
par1Tessellator.addVertexWithUV( (double) (f11 + par3 * f10 + par6 * f10), (double) (f12 + par4 * f10), (double) (f13 + par5 * f10 + par7 * f10),
(double) f6, (double) f8 );
par1Tessellator.addVertexWithUV( (double) (f11 + par3 * f10 - par6 * f10), (double) (f12 - par4 * f10), (double) (f13 + par5 * f10 - par7 * f10),
(double) f6, (double) f9 );
int blkX = MathHelper.floor_double( posX );
int blkY = MathHelper.floor_double( posY );
int blkZ = MathHelper.floor_double( posZ );
if ( blkX == startBlkX && blkY == startBlkY && blkZ == startBlkZ )
{
par1Tessellator.setColorRGBA_F( this.particleRed * f14, this.particleGreen * f14, this.particleBlue * f14, this.particleAlpha );
par1Tessellator.addVertexWithUV( (double) (f11 - par3 * f10 - par6 * f10), (double) (f12 - par4 * f10), (double) (f13 - par5 * f10 - par7 * f10),
(double) f7, (double) f9 );
par1Tessellator.addVertexWithUV( (double) (f11 - par3 * f10 + par6 * f10), (double) (f12 + par4 * f10), (double) (f13 - par5 * f10 + par7 * f10),
(double) f7, (double) f8 );
par1Tessellator.addVertexWithUV( (double) (f11 + par3 * f10 + par6 * f10), (double) (f12 + par4 * f10), (double) (f13 + par5 * f10 + par7 * f10),
(double) f6, (double) f8 );
par1Tessellator.addVertexWithUV( (double) (f11 + par3 * f10 - par6 * f10), (double) (f12 - par4 * f10), (double) (f13 + par5 * f10 - par7 * f10),
(double) f6, (double) f9 );
}
GL11.glPopAttrib();
GL11.glPopMatrix();
}
+3
View File
@@ -16,6 +16,7 @@ import appeng.core.sync.packets.PacketMockExplosion;
import appeng.core.sync.packets.PacketMultiPart;
import appeng.core.sync.packets.PacketPartPlacement;
import appeng.core.sync.packets.PacketSwitchGuis;
import appeng.core.sync.packets.PacketTransitionEffect;
import appeng.core.sync.packets.PacketValueConfig;
public class AppEngPacketHandlerBase
@@ -43,6 +44,8 @@ public class AppEngPacketHandlerBase
PACKET_VALUE_CONFIG(PacketValueConfig.class),
PACKET_TRANSITION_EFFECT(PacketTransitionEffect.class),
PACKET_SWITCH_GUIS(PacketSwitchGuis.class);
final public Class pc;
@@ -0,0 +1,99 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.client.ClientHelper;
import appeng.client.render.effects.EnergyFx;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.util.Platform;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PacketTransitionEffect extends AppEngPacket
{
final double x;
final double y;
final double z;
final ForgeDirection d;
final public boolean mode;
// automatic.
public PacketTransitionEffect(ByteBuf stream) throws IOException {
x = stream.readFloat();
y = stream.readFloat();
z = stream.readFloat();
d = ForgeDirection.getOrientation( stream.readByte() );
mode = stream.readBoolean();
}
@Override
@SideOnly(Side.CLIENT)
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
{
World world = ClientHelper.proxy.getWorld();
for (int zz = 0; zz < (mode ? 32 : 8); zz++)
{
EnergyFx fx = new EnergyFx( world, x + (mode ? (Platform.getRandomInt() % 100) * 0.01 : (Platform.getRandomInt() % 100) * 0.005 - 0.25), y
+ (mode ? (Platform.getRandomInt() % 100) * 0.01 : (Platform.getRandomInt() % 100) * 0.005 - 0.25), z
+ (mode ? (Platform.getRandomInt() % 100) * 0.01 : (Platform.getRandomInt() % 100) * 0.005 - 0.25), Items.diamond );
if ( !mode )
fx.fromItem( d );
fx.motionX = -0.1 * d.offsetX;
fx.motionY = -0.1 * d.offsetY;
fx.motionZ = -0.1 * d.offsetZ;
Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx );
}
if ( mode )
{
Block block = world.getBlock( (int) x, (int) y, (int) z );
Minecraft
.getMinecraft()
.getSoundHandler()
.playSound(
new PositionedSoundRecord( new ResourceLocation( block.stepSound.getBreakSound() ), (block.stepSound.getVolume() + 1.0F) / 2.0F,
block.stepSound.getPitch() * 0.8F, (float) x + 0.5F, (float) y + 0.5F, (float) z + 0.5F ) );
}
}
// api
public PacketTransitionEffect(double x, double y, double z, ForgeDirection dir, boolean wasBlock) throws IOException {
this.x = x;
this.y = y;
this.z = z;
this.d = dir;
this.mode = wasBlock;
ByteBuf data = Unpooled.buffer();
data.writeInt( getPacketID() );
data.writeFloat( (float) x );
data.writeFloat( (float) y );
data.writeFloat( (float) z );
data.writeByte( this.d.ordinal() );
data.writeBoolean( wasBlock );
configureWrite( data );
}
}
+2 -1
View File
@@ -6,6 +6,7 @@ import appeng.api.parts.IPart;
import appeng.api.util.AEColor;
import appeng.core.features.AEFeature;
import appeng.core.localization.GuiText;
import appeng.parts.automation.PartAnnihilationPlane;
import appeng.parts.automation.PartExportBus;
import appeng.parts.automation.PartImportBus;
import appeng.parts.automation.PartLevelEmitter;
@@ -61,7 +62,7 @@ public enum PartType
LevelEmitter(AEFeature.LevelEmiter, PartLevelEmitter.class),
// AnnihilationPlane(AEFeature.AnnihilationPlane, PartAnnihilationPlane.class),
AnnihilationPlane(AEFeature.AnnihilationPlane, PartAnnihilationPlane.class),
// FormationPlane(AEFeature.FormationPlane, PartFormationPlane.class),
+257 -2
View File
@@ -1,19 +1,46 @@
package appeng.parts.automation;
import java.io.IOException;
import java.util.LinkedList;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.MachineSource;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.networking.ticking.IGridTickable;
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.networking.ticking.TickingRequest;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartCollsionHelper;
import appeng.api.parts.IPartHost;
import appeng.api.parts.IPartRenderHelper;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.texture.CableBusTextures;
import appeng.core.AELog;
import appeng.core.sync.packets.PacketTransitionEffect;
import appeng.me.GridAccessException;
import appeng.parts.PartBasicState;
import appeng.server.ServerHelper;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PartAnnihilationPlane extends PartBasicState
public class PartAnnihilationPlane extends PartBasicState implements IGridTickable
{
public PartAnnihilationPlane(ItemStack is) {
@@ -120,7 +147,7 @@ public class PartAnnihilationPlane extends PartBasicState
maxY = 16;
bch.addBox( 5, 5, 14, 11, 11, 15 );
bch.addBox( minX, minY, 15, maxX, maxY, 16 );
bch.addBox( minX, minY, 15, maxX, maxY, bch.isBBCollision() ? 15 : 16 );
}
@Override
@@ -129,4 +156,232 @@ public class PartAnnihilationPlane extends PartBasicState
return 1;
}
LinkedList<IAEItemStack> Buffer = new LinkedList();
BaseActionSource mySrc = new MachineSource( this );
@Override
public void writeToNBT(NBTTagCompound data)
{
super.writeToNBT( data );
data.setInteger( "bufferSize", Buffer.size() );
for (int x = 0; x < Buffer.size(); x++)
{
NBTTagCompound pack = new NBTTagCompound();
Buffer.get( x ).writeToNBT( pack );
data.setTag( "buffer" + x, pack );
}
}
@Override
public void readFromNBT(NBTTagCompound data)
{
super.readFromNBT( data );
int size = data.getInteger( "bufferSize" );
Buffer.clear();
for (int x = 0; x < size; x++)
{
NBTTagCompound pack = (NBTTagCompound) data.getTag( "buffer" + x );
IAEItemStack ais = AEItemStack.loadItemStackFromNBT( pack );
if ( ais != null )
Buffer.add( ais );
}
}
private boolean isAccepting()
{
return Buffer.isEmpty();
}
public TickRateModulation EatBlock()
{
if ( isAccepting() && proxy.isActive() )
{
try
{
TileEntity te = getTile();
WorldServer w = (WorldServer) te.getWorldObj();
int x = te.xCoord + side.offsetX;
int y = te.yCoord + side.offsetY;
int z = te.zCoord + side.offsetZ;
Block blk = w.getBlock( x, y, z );
IStorageGrid storage = (IStorageGrid) proxy.getStorage();
IEnergyGrid energy = (IEnergyGrid) proxy.getEnergy();
Material mat = blk.getMaterial();
boolean ignore = mat == Material.air || mat == Material.lava || mat == Material.water || mat.isLiquid() || blk == Blocks.bedrock
|| blk == Blocks.end_portal || blk == Blocks.end_portal_frame || blk == Blocks.command_block;
if ( !ignore )
{
if ( !w.isAirBlock( x, y, z ) && w.blockExists( x, y, z ) && blk != null && w.canMineBlock( Platform.getPlayer( w ), x, y, z ) )
{
float hardness = blk.getBlockHardness( w, x, y, z );
if ( hardness >= 0.0 )
{
ItemStack[] out = Platform.getBlockDrops( w, x, y, z );
float total = 1 + hardness;
for (ItemStack is : out)
total += is.stackSize;
boolean hasPower = energy.extractAEPower( total, Actionable.SIMULATE, PowerMultiplier.CONFIG ) > total - 0.1;
if ( hasPower )
{
w.setBlock( x, y, z, Platform.air, 0, 3 );
try
{
ServerHelper.proxy.sendToAllNearExcept( null, x, y, z, 64, w, new PacketTransitionEffect( x, y, z, side, true ) );
}
catch (IOException e)
{
AELog.error( e );
}
for (ItemStack is : out)
{
IAEItemStack storedItem = AEItemStack.create( is );
storedItem = Platform.poweredInsert( energy, storage.getItemInventory(), storedItem, mySrc );
if ( storedItem != null )
Buffer.add( storedItem );
}
if ( isAccepting() )
return TickRateModulation.URGENT; // tick again in a sec..
return TickRateModulation.IDLE;
}
}
}
}
}
catch (GridAccessException e1)
{
// :P
}
}
// nothing to do here :)
return TickRateModulation.SLEEP;
}
@Override
public TickingRequest getTickingRequest(IGridNode node)
{
return new TickingRequest( 2, 120, false, true );
}
@Override
public void onNeighborChanged()
{
try
{
proxy.getTick().alertDevice( proxy.getNode() );
}
catch (GridAccessException e)
{
// :P
}
}
@Override
public void onEntityCollision(Entity entity)
{
if ( entity instanceof EntityItem && !entity.isDead && isAccepting() )
{
boolean capture = false;
switch (side)
{
case DOWN:
case UP:
if ( entity.posX > tile.xCoord && entity.posX < tile.xCoord + 1 )
if ( entity.posZ > tile.zCoord && entity.posZ < tile.zCoord + 1 )
if ( (entity.posY > tile.yCoord + 0.9 && side == ForgeDirection.UP) || (entity.posY < tile.yCoord + 0.1 && side == ForgeDirection.DOWN) )
capture = true;
break;
case SOUTH:
case NORTH:
if ( entity.posX > tile.xCoord && entity.posX < tile.xCoord + 1 )
if ( entity.posY > tile.yCoord && entity.posY < tile.yCoord + 1 )
if ( (entity.posZ > tile.zCoord + 0.9 && side == ForgeDirection.SOUTH)
|| (entity.posZ < tile.zCoord + 0.1 && side == ForgeDirection.NORTH) )
capture = true;
break;
case EAST:
case WEST:
if ( entity.posZ > tile.zCoord && entity.posZ < tile.zCoord + 1 )
if ( entity.posY > tile.yCoord && entity.posY < tile.yCoord + 1 )
if ( (entity.posX > tile.xCoord + 0.9 && side == ForgeDirection.EAST)
|| (entity.posX < tile.xCoord + 0.1 && side == ForgeDirection.WEST) )
capture = true;
break;
default:
// umm?
break;
}
if ( capture && Platform.isServer() )
{
IAEItemStack stack = AEItemStack.create( ((EntityItem) entity).getEntityItem() );
if ( stack != null )
{
try
{
ServerHelper.proxy.sendToAllNearExcept( null, tile.xCoord, tile.yCoord, tile.zCoord, 64, tile.getWorldObj(),
new PacketTransitionEffect( entity.posX, entity.posY, entity.posZ, side, false ) );
}
catch (IOException e)
{
AELog.error( e );
}
Buffer.add( stack );
storeBuffer();
entity.setDead();
}
}
}
}
@Override
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
{
if ( isAccepting() )
return EatBlock();
else
{
storeBuffer();
return TickRateModulation.IDLE;
}
}
private void storeBuffer()
{
try
{
IStorageGrid storage = (IStorageGrid) proxy.getStorage();
IEnergyGrid energy = (IEnergyGrid) proxy.getEnergy();
while (!Buffer.isEmpty())
{
IAEItemStack storedItem = Buffer.pop();
storedItem = Platform.poweredInsert( energy, storage.getItemInventory(), storedItem, mySrc );
if ( storedItem != null )
{
Buffer.add( storedItem );
break;
}
}
}
catch (GridAccessException e1)
{
// :P
}
}
}