mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-18 11:29:33 +00:00
Started work on Levers
Made part conversion send the desc packet to the client rather than do a local conversion
This commit is contained in:
1 parent
ae74440783
commit
931da01077
10 files changed
+246
-91
No files matched your search
@@ -195,10 +195,8 @@ object MultipartGenerator
|
||||
{
|
||||
if(!tile.loaded)
|
||||
{
|
||||
if(world.isRemote)
|
||||
world.setBlock(pos.x, pos.y, pos.z, MultipartProxy.block.blockID, 0, 3)
|
||||
else
|
||||
world.setBlock(pos.x, pos.y, pos.z, MultipartProxy.block.blockID, 0, 1)//the add part packet will do the conversion on the client
|
||||
world.setBlock(pos.x, pos.y, pos.z, MultipartProxy.block.blockID, 0, 3)
|
||||
ntile.writeAddPart(ntile.partList(0))
|
||||
}
|
||||
|
||||
val tileTraits = tileTraitMap(tile.getClass)
|
||||
@@ -209,7 +207,7 @@ object MultipartGenerator
|
||||
world.setBlockTileEntity(pos.x, pos.y, pos.z, ntile)
|
||||
ntile.loadFrom(tile)
|
||||
}
|
||||
else if(!tile.loaded)
|
||||
else if(!tile.loaded)//converted
|
||||
{
|
||||
ntile.validate()
|
||||
world.setBlockTileEntity(pos.x, pos.y, pos.z, ntile)
|
||||
|
||||
@@ -148,7 +148,7 @@ trait TileMultipart extends TileEntity
|
||||
|
||||
def getWriteStream(part:TMultiPart):MCDataOutput = getWriteStream.writeByte(partList.indexOf(part))
|
||||
|
||||
private def getWriteStream = MultipartSPH.getTileStream(worldObj, new BlockCoord(this))
|
||||
private[multipart] def getWriteStream = MultipartSPH.getTileStream(worldObj, new BlockCoord(this))
|
||||
|
||||
private[multipart] def addPart(part:TMultiPart)
|
||||
{
|
||||
@@ -158,11 +158,14 @@ trait TileMultipart extends TileEntity
|
||||
markRender()
|
||||
|
||||
if(!worldObj.isRemote)
|
||||
{
|
||||
val stream = getWriteStream.writeByte(253)
|
||||
MultiPartRegistry.writePartID(stream, part)
|
||||
part.writeDesc(stream)
|
||||
}
|
||||
writeAddPart(part)
|
||||
}
|
||||
|
||||
private[multipart] def writeAddPart(part:TMultiPart)
|
||||
{
|
||||
val stream = getWriteStream.writeByte(253)
|
||||
MultiPartRegistry.writePartID(stream, part)
|
||||
part.writeDesc(stream)
|
||||
}
|
||||
|
||||
private[multipart] def addPart_do(part:TMultiPart)
|
||||
|
||||
@@ -14,6 +14,7 @@ public class Content implements IPartFactory, IPartConverter
|
||||
public TMultiPart createPart(String name, boolean client)
|
||||
{
|
||||
if(name.equals("mc_torch")) return new TorchPart();
|
||||
if(name.equals("mc_lever")) return new LeverPart();
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -22,14 +23,16 @@ public class Content implements IPartFactory, IPartConverter
|
||||
{
|
||||
MultiPartRegistry.registerConverter(this);
|
||||
MultiPartRegistry.registerParts(this, new String[]{
|
||||
"mc_torch"
|
||||
"mc_torch",
|
||||
"mc_lever"
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConvert(int blockID)
|
||||
{
|
||||
return blockID == Block.torchWood.blockID;
|
||||
return blockID == Block.torchWood.blockID ||
|
||||
blockID == Block.lever.blockID;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -39,6 +42,8 @@ public class Content implements IPartFactory, IPartConverter
|
||||
int meta = world.getBlockMetadata(pos.x, pos.y, pos.z);
|
||||
if(id == Block.torchWood.blockID)
|
||||
return new TorchPart(meta);
|
||||
if(id == Block.lever.blockID)
|
||||
return new LeverPart(meta);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,8 @@ public class EventHandler
|
||||
|
||||
if(held.itemID == Block.torchWood.blockID)
|
||||
part = TorchPart.placement(world, pos, hit.sideHit);
|
||||
else if(held.itemID == Block.lever.blockID)
|
||||
part = LeverPart.placement(world, pos, player, hit.sideHit);
|
||||
|
||||
if(part == null)
|
||||
return false;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package codechicken.multipart.minecraft;
|
||||
|
||||
import codechicken.core.vec.BlockCoord;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IPartMeta
|
||||
@@ -9,4 +10,6 @@ public interface IPartMeta
|
||||
public World getWorld();
|
||||
|
||||
public int getBlockId();
|
||||
|
||||
public BlockCoord getPos();
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package codechicken.multipart.minecraft;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockLever;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import codechicken.core.lighting.LazyLightMatrix;
|
||||
import codechicken.core.vec.BlockCoord;
|
||||
import codechicken.core.vec.Cuboid6;
|
||||
import codechicken.core.vec.Vector3;
|
||||
|
||||
public class LeverPart extends McSidedMetaPart
|
||||
{
|
||||
public static BlockLever lever = (BlockLever) Block.lever;
|
||||
public static int[] metaSideMap = new int[]{1, 4, 5, 2, 3, 0, 0, 1};
|
||||
public static int[] sideMetaMap = new int[]{6, 0, 3, 4, 1, 2};
|
||||
public static int[] metaSwapMap = new int[]{5, 7};
|
||||
|
||||
public LeverPart()
|
||||
{
|
||||
}
|
||||
|
||||
public LeverPart(int meta)
|
||||
{
|
||||
super(meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getBlock()
|
||||
{
|
||||
return lever;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType()
|
||||
{
|
||||
return "mc_lever";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cuboid6 getBounds()
|
||||
{
|
||||
int m = meta & 7;
|
||||
double d = 0.1875;
|
||||
|
||||
if (m == 1)
|
||||
return new Cuboid6(0, 0.2, 0.5 - d, d * 2, 0.8, 0.5 + d);
|
||||
if (m == 2)
|
||||
return new Cuboid6(1 - d * 2, 0.2, 0.5 - d, 1, 0.8, 0.5 + d);
|
||||
if (m == 3)
|
||||
return new Cuboid6(0.5 - d, 0.2, 0, 0.5 + d, 0.8, d * 2);
|
||||
if (m == 4)
|
||||
return new Cuboid6(0.5 - d, 0.2, 1 - d * 2, 0.5 + d, 0.8, 1);
|
||||
|
||||
d = 0.25;
|
||||
if (m == 0 || m == 7)
|
||||
return new Cuboid6(0.5 - d, 0.4, 0.5 - d, 0.5 + d, 1, 0.5 + d);
|
||||
|
||||
return new Cuboid6(0.5 - d, 0, 0.5 - d, 0.5 + d, 0.6, 0.5 + d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int sideForMeta(int meta)
|
||||
{
|
||||
return metaSideMap[meta&7];
|
||||
}
|
||||
|
||||
public static McBlockPart placement(World world, BlockCoord pos, EntityPlayer player, int side)
|
||||
{
|
||||
pos = pos.copy().offset(side^1);
|
||||
if(!world.isBlockSolidOnSide(pos.x, pos.y, pos.z, ForgeDirection.getOrientation(side)))
|
||||
return null;
|
||||
|
||||
int meta = sideMetaMap[side^1];
|
||||
if(side < 2 && ((int)(player.rotationYaw / 90 + 0.5) & 1) == 0)
|
||||
meta = metaSwapMap[side^1];
|
||||
|
||||
return new LeverPart(meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderStatic(Vector3 pos, LazyLightMatrix olm, int pass)
|
||||
{
|
||||
new RenderBlocks(new PartMetaAccess(this)).renderBlockLever(lever, getTile().xCoord, getTile().yCoord, getTile().zCoord);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package codechicken.multipart.minecraft;
|
||||
|
||||
import codechicken.core.data.MCDataInput;
|
||||
import codechicken.core.data.MCDataOutput;
|
||||
import codechicken.core.vec.BlockCoord;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public abstract class McMetaPart extends McBlockPart implements IPartMeta
|
||||
{
|
||||
public byte meta;
|
||||
|
||||
public McMetaPart()
|
||||
{
|
||||
}
|
||||
|
||||
public McMetaPart(int meta)
|
||||
{
|
||||
this.meta = (byte)meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(NBTTagCompound tag)
|
||||
{
|
||||
tag.setByte("meta", meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(NBTTagCompound tag)
|
||||
{
|
||||
meta = tag.getByte("meta");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDesc(MCDataOutput packet)
|
||||
{
|
||||
packet.writeByte(meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readDesc(MCDataInput packet)
|
||||
{
|
||||
meta = packet.readByte();
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld()
|
||||
{
|
||||
return getTile().worldObj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetadata()
|
||||
{
|
||||
return meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockId()
|
||||
{
|
||||
return getBlock().blockID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockCoord getPos()
|
||||
{
|
||||
return new BlockCoord(getTile());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package codechicken.multipart.minecraft;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import codechicken.core.vec.BlockCoord;
|
||||
import codechicken.core.vec.Vector3;
|
||||
import codechicken.multipart.TileMultipartObj;
|
||||
|
||||
public abstract class McSidedMetaPart extends McMetaPart
|
||||
{
|
||||
public McSidedMetaPart()
|
||||
{
|
||||
}
|
||||
|
||||
public McSidedMetaPart(int meta)
|
||||
{
|
||||
super(meta);
|
||||
}
|
||||
|
||||
public abstract int sideForMeta(int meta);
|
||||
|
||||
public void onNeighbourChanged()
|
||||
{
|
||||
TileEntity tile = getTile();
|
||||
if(!tile.worldObj.isRemote)
|
||||
{
|
||||
BlockCoord pos = new BlockCoord(tile).offset(sideForMeta(meta));
|
||||
if(!tile.worldObj.isBlockSolidOnSide(pos.x, pos.y, pos.z, ForgeDirection.getOrientation(sideForMeta(meta)^1)))
|
||||
drop();
|
||||
}
|
||||
}
|
||||
|
||||
public void drop()
|
||||
{
|
||||
tile().remPart(this);
|
||||
TileMultipartObj.dropItem(new ItemStack(getBlock()), getTile().worldObj, Vector3.fromTileEntityCenter(getTile()));
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package codechicken.multipart.minecraft;
|
||||
|
||||
import codechicken.core.vec.BlockCoord;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Vec3Pool;
|
||||
@@ -11,22 +13,28 @@ import net.minecraft.world.biome.BiomeGenBase;
|
||||
public class PartMetaAccess implements IBlockAccess
|
||||
{
|
||||
public IPartMeta part;
|
||||
private BlockCoord pos;
|
||||
|
||||
public PartMetaAccess(IPartMeta p)
|
||||
{
|
||||
part = p;
|
||||
pos = p.getPos();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockId(int i, int j, int k)
|
||||
{
|
||||
return part.getBlockId();
|
||||
if(i == pos.x && j == pos.y && k == pos.z)
|
||||
return part.getBlockId();
|
||||
return part.getWorld().getBlockId(i, j, k);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getBlockTileEntity(int i, int j, int k)
|
||||
{
|
||||
throw new IllegalArgumentException("Unsupported Operation");
|
||||
if(i == pos.x && j == pos.y && k == pos.z)
|
||||
throw new IllegalArgumentException("Unsupported Operation");
|
||||
return part.getWorld().getBlockTileEntity(i, j, k);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -39,7 +47,9 @@ public class PartMetaAccess implements IBlockAccess
|
||||
@Override
|
||||
public int getBlockMetadata(int i, int j, int k)
|
||||
{
|
||||
return part.getMetadata();
|
||||
if(i == pos.x && j == pos.y && k == pos.z)
|
||||
return part.getMetadata();
|
||||
return part.getWorld().getBlockMetadata(i, j, k);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -59,20 +69,20 @@ public class PartMetaAccess implements IBlockAccess
|
||||
@Override
|
||||
public Material getBlockMaterial(int i, int j, int k)
|
||||
{
|
||||
throw new IllegalArgumentException("Unsupported Operation");
|
||||
return Block.blocksList[getBlockId(i, j, k)].blockMaterial;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean isBlockOpaqueCube(int i, int j, int k)
|
||||
{
|
||||
throw new IllegalArgumentException("Unsupported Operation");
|
||||
return part.getWorld().isBlockOpaqueCube(i, j, k);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlockNormalCube(int i, int j, int k)
|
||||
{
|
||||
throw new IllegalArgumentException("Unsupported Operation");
|
||||
return part.getWorld().isBlockNormalCube(i, j, k);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,26 +5,19 @@ import java.util.Random;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockTorch;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import codechicken.multipart.IRandomDisplayTick;
|
||||
import codechicken.multipart.TileMultipartObj;
|
||||
import codechicken.core.data.MCDataInput;
|
||||
import codechicken.core.data.MCDataOutput;
|
||||
import codechicken.core.lighting.LazyLightMatrix;
|
||||
import codechicken.core.vec.BlockCoord;
|
||||
import codechicken.core.vec.Cuboid6;
|
||||
import codechicken.core.vec.Vector3;
|
||||
|
||||
public class TorchPart extends McBlockPart implements IPartMeta, IRandomDisplayTick
|
||||
public class TorchPart extends McSidedMetaPart implements IRandomDisplayTick
|
||||
{
|
||||
public static BlockTorch torch = (BlockTorch) Block.torchWood;
|
||||
public static int[] metaSideMap = new int[]{-1, 4, 5, 2, 3, 0};
|
||||
public static int[] sideMetaMap = new int[]{5, 0, 3, 4, 1, 2};
|
||||
public byte meta;
|
||||
|
||||
public TorchPart()
|
||||
{
|
||||
@@ -32,7 +25,7 @@ public class TorchPart extends McBlockPart implements IPartMeta, IRandomDisplayT
|
||||
|
||||
public TorchPart(int meta)
|
||||
{
|
||||
this.meta = (byte)meta;
|
||||
super(meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,82 +40,27 @@ public class TorchPart extends McBlockPart implements IPartMeta, IRandomDisplayT
|
||||
return "mc_torch";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(NBTTagCompound tag)
|
||||
{
|
||||
tag.setByte("meta", meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(NBTTagCompound tag)
|
||||
{
|
||||
meta = tag.getByte("meta");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDesc(MCDataOutput packet)
|
||||
{
|
||||
packet.writeByte(meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readDesc(MCDataInput packet)
|
||||
{
|
||||
meta = packet.readByte();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cuboid6 getBounds()
|
||||
{
|
||||
double d = 0.15;
|
||||
if (meta == 1)
|
||||
return new Cuboid6(0, 0.2, 0.5 - d, d * 2, 0.8, 0.5 + d);
|
||||
else if (meta == 2)
|
||||
if (meta == 2)
|
||||
return new Cuboid6(1 - d * 2, 0.2, 0.5 - d, 1, 0.8, 0.5 + d);
|
||||
else if (meta == 3)
|
||||
if (meta == 3)
|
||||
return new Cuboid6(0.5 - d, 0.2, 0, 0.5 + d, 0.8, d * 2);
|
||||
else if (meta == 4)
|
||||
if (meta == 4)
|
||||
return new Cuboid6(0.5 - d, 0.2, 1 - d * 2, 0.5 + d, 0.8, 1);
|
||||
else
|
||||
{
|
||||
d = 0.1;
|
||||
return new Cuboid6(0.5 - d, 0, 0.5 - d, 0.5 + d, 0.6, 0.5 + d);
|
||||
}
|
||||
}
|
||||
|
||||
public void onNeighbourChanged()
|
||||
{
|
||||
TileEntity tile = getTile();
|
||||
if(!tile.worldObj.isRemote)
|
||||
{
|
||||
BlockCoord pos = new BlockCoord(tile).offset(metaSideMap[meta]);
|
||||
if(!tile.worldObj.isBlockSolidOnSide(pos.x, pos.y, pos.z, ForgeDirection.getOrientation(metaSideMap[meta]^1)))
|
||||
drop();
|
||||
}
|
||||
}
|
||||
|
||||
public void drop()
|
||||
{
|
||||
tile().remPart(this);
|
||||
TileMultipartObj.dropItem(new ItemStack(torch), getTile().worldObj, Vector3.fromTileEntityCenter(getTile()));
|
||||
|
||||
d = 0.1;
|
||||
return new Cuboid6(0.5 - d, 0, 0.5 - d, 0.5 + d, 0.6, 0.5 + d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld()
|
||||
public int sideForMeta(int meta)
|
||||
{
|
||||
return getTile().worldObj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetadata()
|
||||
{
|
||||
return meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBlockId()
|
||||
{
|
||||
return torch.blockID;
|
||||
return metaSideMap[meta];
|
||||
}
|
||||
|
||||
public static McBlockPart placement(World world, BlockCoord pos, int side)
|
||||
|
||||
Reference in new issue
Block a user