This commit is contained in:
AlgorithmX2 2014-04-10 22:02:23 -05:00
commit 2de3ab4505
9 changed files with 98 additions and 49 deletions

View file

@ -271,7 +271,7 @@ public class BusRenderHelper implements IPartRenderHelper
bbr.renderBlockBounds( renderer, minX, minY, minZ, maxX, maxY, maxZ, ax, ay, az );
renderer.renderStandardBlock( renderer.blockAccess.getBlock( x, y, z ), x, y, z );
renderer.renderStandardBlock( blk, x, y, z );
}
@Override

View file

@ -1,9 +1,8 @@
package appeng.fmp;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import java.util.ArrayList;
import java.util.EnumSet;
@ -42,7 +41,6 @@ import appeng.tile.networking.TileCableBus;
import appeng.util.Platform;
import codechicken.lib.data.MCDataInput;
import codechicken.lib.data.MCDataOutput;
import codechicken.lib.lighting.LazyLightMatrix;
import codechicken.lib.raytracer.IndexedCuboid6;
import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Vector3;
@ -52,6 +50,7 @@ import codechicken.multipart.JNormalOcclusion;
import codechicken.multipart.NormalOcclusionTest;
import codechicken.multipart.NormallyOccludedPart;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.scalatraits.TIInventoryTile;
//TFacePart,
public class CableBusPart extends JCuboidPart implements JNormalOcclusion, IRedstonePart, IPartHost, AEMultiTile
@ -107,14 +106,14 @@ public class CableBusPart extends JCuboidPart implements JNormalOcclusion, IReds
@Override
public void writeDesc(MCDataOutput packet)
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream stream = new DataOutputStream( bytes );
ByteBuf stream = Unpooled.buffer();
try
{
cb.writeToStream( stream );
packet.writeInt( bytes.size() );
packet.writeByteArray( bytes.toByteArray() );
packet.writeInt( stream.readableBytes() );
stream.capacity( stream.readableBytes() );
packet.writeByteArray( stream.array() );
}
catch (IOException e)
{
@ -129,11 +128,13 @@ public class CableBusPart extends JCuboidPart implements JNormalOcclusion, IReds
int len = packet.readInt();
byte data[] = packet.readByteArray( len );
DataInputStream stream = new DataInputStream( new ByteArrayInputStream( data ) );
try
{
cb.readFromStream( stream );
if ( len > 0 )
{
ByteBuf bybuff = Unpooled.wrappedBuffer( data );
cb.readFromStream( bybuff );
}
}
catch (IOException e)
{
@ -262,12 +263,14 @@ public class CableBusPart extends JCuboidPart implements JNormalOcclusion, IReds
}
@Override
public void renderStatic(Vector3 pos, LazyLightMatrix olm, int pass)
public boolean renderStatic(Vector3 pos, int pass)
{
if ( pass == 0 )
{
cb.renderStatic( pos.x, pos.y, pos.z );
return true;
}
return false;
}
@Override
@ -425,8 +428,12 @@ public class CableBusPart extends JCuboidPart implements JNormalOcclusion, IReds
@Override
public void partChanged()
{
if ( worldObj != null )
worldObj.notifyBlocksOfNeighborChange( xCoord, yCoord, zCoord, Platform.air );
AELog.info( "rebuildSlotMap" );
if ( tile() instanceof TIInventoryTile )
((TIInventoryTile) tile()).rebuildSlotMap();
if ( world() != null )
world().notifyBlocksOfNeighborChange( x(), y(), z(), Platform.air );
}
@Override
@ -434,11 +441,12 @@ public class CableBusPart extends JCuboidPart implements JNormalOcclusion, IReds
{
return cb.getLayerFlags();
}
@Override
public void markForSave()
{
this.getTile().markDirty();
// mark the chunk for save...
this.getTile().getWorldObj().getChunkFromBlockCoords( x(), z() ).isModified = true;
}
@Override
@ -477,6 +485,11 @@ public class CableBusPart extends JCuboidPart implements JNormalOcclusion, IReds
cb.onInputsChanged( world, x, y, z, side, inputValues );
}
public void markDirty()
{
markForSave();
}
@Override
public void onInputChanged(World world, int x, int y, int z, ForgeDirection side, int inputValue)
{
@ -489,4 +502,10 @@ public class CableBusPart extends JCuboidPart implements JNormalOcclusion, IReds
return cb.isEmpty();
}
@Override
public void cleanup()
{
tile().remPart( this );
}
}

View file

@ -6,16 +6,16 @@ import net.minecraft.block.Block;
import net.minecraft.block.BlockFence;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.Packet15Place;
import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
import appeng.block.AEBaseItemBlock;
import appeng.core.AELog;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketMultiPart;
import appeng.integration.modules.helpers.FMPPacketEvent;
import codechicken.lib.packet.PacketCustom;
@ -24,7 +24,7 @@ import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Vector3;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.TileMultipart;
import cpw.mods.fml.common.network.PacketDispatcher;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
/**
* Basically a total rip of of the FMP version for vanilla, seemed to work well enough...
@ -34,13 +34,13 @@ public class FMPEvent
private ThreadLocal<Object> placing = new ThreadLocal<Object>();
@ForgeSubscribe
@SubscribeEvent
public void ServerFMPEvent(FMPPacketEvent event)
{
FMPEvent.place( event.sender, event.sender.worldObj );
}
@ForgeSubscribe
@SubscribeEvent
public void playerInteract(PlayerInteractEvent event)
{
if ( event.action == Action.RIGHT_CLICK_BLOCK && event.entityPlayer.worldObj.isRemote )
@ -72,7 +72,7 @@ public class FMPEvent
if ( held.getItem() instanceof AEBaseItemBlock )
{
AEBaseItemBlock ib = (AEBaseItemBlock) held.getItem();
blk = Block.blocksList[ib.getBlockID()];
blk = Block.getBlockFromItem(ib);
part = PartRegistry.getPartByBlock( blk, hit.sideHit );
}
@ -83,12 +83,12 @@ public class FMPEvent
// the right stuff
{
Vector3 f = new Vector3( hit.hitVec ).add( -hit.blockX, -hit.blockY, -hit.blockZ );
Block block = Block.blocksList[world.getBlockId( hit.blockX, hit.blockY, hit.blockZ )];
Block block = world.getBlock( hit.blockX, hit.blockY, hit.blockZ );
if ( block != null && !ignoreActivate( block )
&& block.onBlockActivated( world, hit.blockX, hit.blockY, hit.blockZ, player, hit.sideHit, (float) f.x, (float) f.y, (float) f.z ) )
{
player.swingItem();
PacketCustom.sendToServer( new Packet15Place( hit.blockX, hit.blockY, hit.blockZ, hit.sideHit, player.inventory.getCurrentItem(), (float) f.x,
PacketCustom.sendToServer(new C08PacketPlayerBlockPlacement( hit.blockX, hit.blockY, hit.blockZ, hit.sideHit, player.inventory.getCurrentItem(), (float) f.x,
(float) f.y, (float) f.z ) );
return false;
}
@ -101,7 +101,7 @@ public class FMPEvent
if ( !world.isRemote )
{
TileMultipart.addPart( world, pos, part );
world.playSoundEffect( pos.x + 0.5, pos.y + 0.5, pos.z + 0.5, blk.stepSound.getPlaceSound(), (blk.stepSound.getVolume() + 1.0F) / 2.0F,
world.playSoundEffect( pos.x + 0.5, pos.y + 0.5, pos.z + 0.5, blk.stepSound.func_150496_b(), (blk.stepSound.getVolume() + 1.0F) / 2.0F,
blk.stepSound.getPitch() * 0.8F );
if ( !player.capabilities.isCreativeMode )
{
@ -118,7 +118,7 @@ public class FMPEvent
player.swingItem();
try
{
PacketDispatcher.sendPacketToServer( (new PacketMultiPart()).getPacket() );
NetworkHandler.instance.sendToServer( new PacketMultiPart() );
}
catch (IOException e)
{

View file

@ -65,7 +65,7 @@ public class QuartzTorchPart extends McSidedMetaPart implements IRandomDisplayTi
public static McBlockPart placement(World world, BlockCoord pos, int side)
{
pos = pos.copy().offset( side );
if ( !world.isBlockSolidOnSide( pos.x, pos.y, pos.z, ForgeDirection.getOrientation( side ) ) )
if ( !world.isSideSolid( pos.x, pos.y, pos.z, ForgeDirection.getOrientation( side ) ) )
{
return null;
}

View file

@ -1,10 +1,14 @@
package appeng.integration.modules.dead;
package appeng.integration.modules;
import java.util.Arrays;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import appeng.api.AEApi;
import appeng.api.definitions.Blocks;
import appeng.api.parts.IPartHost;
import appeng.core.AELog;
import appeng.fmp.CableBusPart;
@ -12,6 +16,7 @@ import appeng.fmp.FMPEvent;
import appeng.fmp.PartRegistry;
import appeng.integration.IIntegrationModule;
import appeng.integration.abstraction.IFMP;
import appeng.integration.modules.helpers.FMPPacketEvent;
import appeng.parts.CableBusContainer;
import appeng.util.Platform;
import codechicken.lib.vec.BlockCoord;
@ -22,6 +27,7 @@ import codechicken.multipart.MultiPartRegistry.IPartFactory;
import codechicken.multipart.MultipartGenerator;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.TileMultipart;
import cpw.mods.fml.common.eventhandler.Event;
public class FMP implements IIntegrationModule, IPartFactory, IPartConverter, IFMP
{
@ -39,20 +45,14 @@ public class FMP implements IIntegrationModule, IPartFactory, IPartConverter, IF
return null;
}
@Override
public boolean canConvert(int blockID)
{
return PartRegistry.isPart( Block.blocksList[blockID] );
}
@Override
public TMultiPart convert(World world, BlockCoord pos)
{
int blockID = world.getBlockId( pos.x, pos.y, pos.z );
Block blk = world.getBlock( pos.x, pos.y, pos.z );
int meta = world.getBlockMetadata( pos.x, pos.y, pos.z );
TMultiPart part = PartRegistry.getPartByBlock( Block.blocksList[blockID], meta );
TMultiPart part = PartRegistry.getPartByBlock( blk, meta );
if ( part instanceof CableBusPart )
{
CableBusPart cbp = (CableBusPart) part;
@ -64,10 +64,14 @@ public class FMP implements IIntegrationModule, IPartFactory, IPartConverter, IF
@Override
public void Init() throws Throwable
{
BlockMicroMaterial.createAndRegister( AEApi.instance().blocks().blockQuartz.block() );
BlockMicroMaterial.createAndRegister( AEApi.instance().blocks().blockQuartzPiller.block() );
BlockMicroMaterial.createAndRegister( AEApi.instance().blocks().blockQuartzChiseled.block() );
{
createAndRegister( AEApi.instance().blocks().blockQuartz.block(),0 );
createAndRegister( AEApi.instance().blocks().blockQuartzPiller.block(),0 );
createAndRegister( AEApi.instance().blocks().blockQuartzChiseled.block(),0 );
createAndRegister( AEApi.instance().blocks().blockSkyStone.block(),0 );
createAndRegister( AEApi.instance().blocks().blockSkyStone.block(),1 );
createAndRegister( AEApi.instance().blocks().blockSkyStone.block(),2 );
createAndRegister( AEApi.instance().blocks().blockSkyStone.block(),3 );
PartRegistry reg[] = PartRegistry.values();
@ -81,6 +85,11 @@ public class FMP implements IIntegrationModule, IPartFactory, IPartConverter, IF
MultipartGenerator.registerPassThroughInterface( "appeng.helpers.AEMultiTile" );
}
private void createAndRegister(Block block, int i) {
if ( block != null )
BlockMicroMaterial.createAndRegister(block, i);
}
@Override
public void PostInit() throws Throwable
{
@ -94,7 +103,7 @@ public class FMP implements IIntegrationModule, IPartFactory, IPartConverter, IF
{
BlockCoord loc = new BlockCoord( tile.xCoord, tile.yCoord, tile.zCoord );
TileMultipart mp = TileMultipart.getOrConvertTile( tile.worldObj, loc );
TileMultipart mp = TileMultipart.getOrConvertTile( tile.getWorldObj(), loc );
if ( mp != null )
{
scala.collection.Iterator<TMultiPart> i = mp.partList().iterator();
@ -107,7 +116,7 @@ public class FMP implements IIntegrationModule, IPartFactory, IPartConverter, IF
TMultiPart part = PartRegistry.CableBusPart.construct( 0 );
if ( mp.canAddPart( part ) && Platform.isServer() )
TileMultipart.addPart( tile.worldObj, loc, part );
TileMultipart.addPart( tile.getWorldObj(), loc, part );
return (CableBusPart) part;
}
}
@ -149,4 +158,15 @@ public class FMP implements IIntegrationModule, IPartFactory, IPartConverter, IF
}
}
@Override
public Event newFMPPacketEvent(EntityPlayerMP sender) {
return new FMPPacketEvent(sender);
}
@Override
public Iterable<Block> blockTypes() {
Blocks def= AEApi.instance().blocks();
return Arrays.asList( def.blockMultiPart.block(), def.blockQuartzTorch.block() );
}
}

View file

@ -1,7 +1,7 @@
package appeng.integration.modules.helpers.dead;
package appeng.integration.modules.helpers;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.event.Event;
public class FMPPacketEvent extends Event
{

View file

@ -968,4 +968,9 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
return myLayerFlags;
}
@Override
public void cleanup() {
tcb.cleanup();
}
}

View file

@ -104,7 +104,7 @@ public class PartPlacement
}
if ( host.isEmpty() )
world.setBlock( x, y, z, Platform.air );
host.cleanup();
if ( is != null && !is.isEmpty() )
{

View file

@ -41,7 +41,7 @@ public class TileCableBus extends AEBaseTile implements AEMultiTile, ICustomColl
public CableBusContainer cb = new CableBusContainer( this );
private int oldLV = -1; // on re-calculate light when it changes
class CableBusHandler extends AETileEventHandler
{
@ -319,6 +319,11 @@ public class TileCableBus extends AEBaseTile implements AEMultiTile, ICustomColl
{
return cb.getLayerFlags();
}
@Override
public void cleanup() {
getWorldObj().setBlock( xCoord, yCoord, zCoord, Platform.air );
}
/**
* Immibis MB Support