From 327c1d4118ac7a59e1ad73a2053a5bcfc2aa0dbe Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Thu, 10 Apr 2014 14:52:17 -0500 Subject: [PATCH] Ported FMP Support to 1.7. --- client/render/BusRenderHelper.java | 2 +- fmp/CableBusPart.java | 41 +++++++++------ fmp/FMPEvent.java | 20 +++---- fmp/QuartzTorchPart.java | 2 +- integration/modules/{dead => }/FMP.java | 52 +++++++++++++------ .../helpers/{dead => }/FMPPacketEvent.java | 4 +- 6 files changed, 74 insertions(+), 47 deletions(-) rename integration/modules/{dead => }/FMP.java (70%) rename integration/modules/helpers/{dead => }/FMPPacketEvent.java (70%) diff --git a/client/render/BusRenderHelper.java b/client/render/BusRenderHelper.java index ea1843ee0..e9f24c76d 100644 --- a/client/render/BusRenderHelper.java +++ b/client/render/BusRenderHelper.java @@ -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 diff --git a/fmp/CableBusPart.java b/fmp/CableBusPart.java index 951263264..175c9f4c5 100644 --- a/fmp/CableBusPart.java +++ b/fmp/CableBusPart.java @@ -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; @@ -107,14 +105,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 +127,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 +262,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 +427,8 @@ public class CableBusPart extends JCuboidPart implements JNormalOcclusion, IReds @Override public void partChanged() { - if ( worldObj != null ) - worldObj.notifyBlocksOfNeighborChange( xCoord, yCoord, zCoord, Platform.air ); + if ( world() != null ) + world().notifyBlocksOfNeighborChange( x(), y(), z(), Platform.air ); } @Override @@ -438,7 +440,8 @@ public class CableBusPart extends JCuboidPart implements JNormalOcclusion, IReds @Override public void markForSave() { - this.getTile().markDirty(); + // mark the chunk for save... + this.getTile().getWorldObj().getChunkFromBlockCoords( x(), z() ).isModified = true; } @Override @@ -476,7 +479,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) { diff --git a/fmp/FMPEvent.java b/fmp/FMPEvent.java index 86cbdfd00..07ac5743a 100644 --- a/fmp/FMPEvent.java +++ b/fmp/FMPEvent.java @@ -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 placing = new ThreadLocal(); - @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) { diff --git a/fmp/QuartzTorchPart.java b/fmp/QuartzTorchPart.java index eb8080560..9cf227567 100644 --- a/fmp/QuartzTorchPart.java +++ b/fmp/QuartzTorchPart.java @@ -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; } diff --git a/integration/modules/dead/FMP.java b/integration/modules/FMP.java similarity index 70% rename from integration/modules/dead/FMP.java rename to integration/modules/FMP.java index d8f07a341..6eac37969 100644 --- a/integration/modules/dead/FMP.java +++ b/integration/modules/FMP.java @@ -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 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 blockTypes() { + Blocks def= AEApi.instance().blocks(); + return Arrays.asList( def.blockMultiPart.block(), def.blockQuartzTorch.block() ); + } + } diff --git a/integration/modules/helpers/dead/FMPPacketEvent.java b/integration/modules/helpers/FMPPacketEvent.java similarity index 70% rename from integration/modules/helpers/dead/FMPPacketEvent.java rename to integration/modules/helpers/FMPPacketEvent.java index 23d8742cc..10235d16a 100644 --- a/integration/modules/helpers/dead/FMPPacketEvent.java +++ b/integration/modules/helpers/FMPPacketEvent.java @@ -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 {