This commit is contained in:
Calclavia 2013-08-03 14:38:33 -04:00
commit edb370b7d5
8 changed files with 212 additions and 92 deletions

View file

@ -5,6 +5,7 @@ package resonantinduction;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.util.ArrayList;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.INetworkManager; import net.minecraft.network.INetworkManager;
@ -52,6 +53,19 @@ public class PacketHandler implements IPacketHandler
((IPacketReceiver) tileEntity).handle(dataStream); ((IPacketReceiver) tileEntity).handle(dataStream);
} }
} }
else if (packetType == PacketType.DATA_REQUEST.ordinal())
{
int x = dataStream.readInt();
int y = dataStream.readInt();
int z = dataStream.readInt();
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof IPacketReceiver)
{
sendTileEntityPacketToClients(tileEntity, ((IPacketReceiver) tileEntity).getNetworkedData(new ArrayList()).toArray());
}
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -90,12 +104,40 @@ public class PacketHandler implements IPacketHandler
{ {
output.writeByte((Byte) data); output.writeByte((Byte) data);
} }
else if (data instanceof Object[])
{
encode((Object[])data, output);
}
} }
} }
catch (Exception e) catch (Exception e)
{ {
} }
} }
public static void sendDataRequest(TileEntity tileEntity)
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream data = new DataOutputStream(bytes);
try
{
data.writeInt(PacketType.DATA_REQUEST.ordinal());
data.writeInt(tileEntity.xCoord);
data.writeInt(tileEntity.yCoord);
data.writeInt(tileEntity.zCoord);
}
catch (Exception e)
{
}
Packet250CustomPayload packet = new Packet250CustomPayload();
packet.channel = ResonantInduction.CHANNEL;
packet.data = bytes.toByteArray();
packet.length = packet.data.length;
PacketDispatcher.sendPacketToServer(packet);
}
public static void sendTileEntityPacketToServer(TileEntity tileEntity, Object... dataValues) public static void sendTileEntityPacketToServer(TileEntity tileEntity, Object... dataValues)
{ {
@ -135,6 +177,7 @@ public class PacketHandler implements IPacketHandler
public static enum PacketType public static enum PacketType
{ {
TILE TILE,
DATA_REQUEST
} }
} }

View file

@ -10,6 +10,7 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.common.Configuration; import net.minecraftforge.common.Configuration;
import net.minecraftforge.oredict.ShapedOreRecipe; import net.minecraftforge.oredict.ShapedOreRecipe;
import resonantinduction.contractor.BlockEMContractor; import resonantinduction.contractor.BlockEMContractor;
import resonantinduction.contractor.ItemBlockContractor;
import resonantinduction.contractor.TileEntityEMContractor; import resonantinduction.contractor.TileEntityEMContractor;
import resonantinduction.entangler.ItemQuantumEntangler; import resonantinduction.entangler.ItemQuantumEntangler;
import resonantinduction.tesla.BlockTesla; import resonantinduction.tesla.BlockTesla;
@ -125,7 +126,7 @@ public class ResonantInduction
GameRegistry.registerBlock(blockTesla, blockTesla.getUnlocalizedName()); GameRegistry.registerBlock(blockTesla, blockTesla.getUnlocalizedName());
blockEMContractor = new BlockEMContractor(getNextBlockID()); blockEMContractor = new BlockEMContractor(getNextBlockID());
GameRegistry.registerBlock(blockEMContractor, blockEMContractor.getUnlocalizedName()); GameRegistry.registerBlock(blockEMContractor, ItemBlockContractor.class, blockEMContractor.getUnlocalizedName());
CONFIGURATION.save(); CONFIGURATION.save();

View file

@ -1,8 +1,12 @@
package resonantinduction.base; package resonantinduction.base;
import java.util.ArrayList;
import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataInput;
public interface IPacketReceiver public interface IPacketReceiver
{ {
public void handle(ByteArrayDataInput input); public void handle(ByteArrayDataInput input);
public ArrayList getNetworkedData(ArrayList data);
} }

View file

@ -2,9 +2,12 @@ package resonantinduction.contractor;
import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import resonantinduction.ResonantInduction; import resonantinduction.ResonantInduction;
@ -28,26 +31,6 @@ public class BlockEMContractor extends BlockBase implements ITileEntityProvider
return BlockRenderingHandler.INSTANCE.getRenderId(); return BlockRenderingHandler.INSTANCE.getRenderId();
} }
@Override
public void onBlockAdded(World world, int x, int y, int z)
{
TileEntityEMContractor tileContractor = (TileEntityEMContractor)world.getBlockTileEntity(x, y, z);
tileContractor.updateBounds();
if(!tileContractor.isLatched())
{
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tileEntity = world.getBlockTileEntity(x+side.offsetX, y+side.offsetY, z+side.offsetZ);
if(tileEntity instanceof IInventory)
{
tileContractor.setFacing(side.getOpposite());
}
}
}
}
@Override @Override
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
{ {
@ -69,7 +52,7 @@ public class BlockEMContractor extends BlockBase implements ITileEntityProvider
{ {
TileEntityEMContractor tileContractor = (TileEntityEMContractor)world.getBlockTileEntity(x, y, z); TileEntityEMContractor tileContractor = (TileEntityEMContractor)world.getBlockTileEntity(x, y, z);
if(!tileContractor.isLatched()) if(!world.isRemote && !tileContractor.isLatched())
{ {
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{ {
@ -78,6 +61,7 @@ public class BlockEMContractor extends BlockBase implements ITileEntityProvider
if(tileEntity instanceof IInventory) if(tileEntity instanceof IInventory)
{ {
tileContractor.setFacing(side.getOpposite()); tileContractor.setFacing(side.getOpposite());
return;
} }
} }
} }

View file

@ -0,0 +1,45 @@
package resonantinduction.contractor;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
public class ItemBlockContractor extends ItemBlock
{
public ItemBlockContractor(int id)
{
super(id);
}
@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata)
{
boolean place = super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata);
if(place)
{
TileEntityEMContractor tileContractor = (TileEntityEMContractor)world.getBlockTileEntity(x, y, z);
tileContractor.setFacing(ForgeDirection.getOrientation(side));
if(!tileContractor.isLatched())
{
for(ForgeDirection side1 : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tileEntity = world.getBlockTileEntity(x+side1.offsetX, y+side1.offsetY, z+side1.offsetZ);
if(tileEntity instanceof IInventory)
{
tileContractor.setFacing(side1.getOpposite());
break;
}
}
}
}
return place;
}
}

View file

@ -1,7 +1,13 @@
package resonantinduction.contractor; package resonantinduction.contractor;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.google.common.io.ByteArrayDataInput;
import resonantinduction.PacketHandler;
import resonantinduction.base.IPacketReceiver;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
@ -10,7 +16,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
public class TileEntityEMContractor extends TileEntity public class TileEntityEMContractor extends TileEntity implements IPacketReceiver
{ {
public static int MAX_REACH = 40; public static int MAX_REACH = 40;
public static double MAX_SPEED = .1; public static double MAX_SPEED = .1;
@ -88,63 +94,6 @@ public class TileEntityEMContractor extends TileEntity
entityItem.isAirBorne = true; entityItem.isAirBorne = true;
break; break;
case NORTH: case NORTH:
if(!worldObj.isRemote)
{
entityItem.setPosition(entityItem.posX, yCoord+0.5, zCoord+0.5);
}
entityItem.motionY = 0;
entityItem.motionZ = 0;
if(!suck)
{
entityItem.motionX = Math.min(MAX_SPEED, entityItem.motionX+ACCELERATION);
}
else {
entityItem.motionX = Math.max(-MAX_SPEED, entityItem.motionX-ACCELERATION);
}
entityItem.isAirBorne = true;
break;
case SOUTH:
if(!worldObj.isRemote)
{
entityItem.setPosition(entityItem.posX, yCoord+0.5, zCoord+0.5);
}
entityItem.motionY = 0;
entityItem.motionZ = 0;
if(!suck)
{
entityItem.motionX = Math.max(-MAX_SPEED, entityItem.motionX-ACCELERATION);
}
else {
entityItem.motionX = Math.min(MAX_SPEED, entityItem.motionX+ACCELERATION);
}
entityItem.isAirBorne = true;
break;
case WEST:
if(!worldObj.isRemote)
{
entityItem.setPosition(xCoord+0.5, yCoord+0.5, entityItem.posZ);
}
entityItem.motionX = 0;
entityItem.motionY = 0;
if(!suck)
{
entityItem.motionZ = Math.min(MAX_SPEED, entityItem.motionZ+ACCELERATION);
}
else {
entityItem.motionZ = Math.max(-MAX_SPEED, entityItem.motionZ-ACCELERATION);
}
entityItem.isAirBorne = true;
break;
case EAST:
if(!worldObj.isRemote) if(!worldObj.isRemote)
{ {
entityItem.setPosition(xCoord+0.5, yCoord+0.5, entityItem.posZ); entityItem.setPosition(xCoord+0.5, yCoord+0.5, entityItem.posZ);
@ -161,6 +110,63 @@ public class TileEntityEMContractor extends TileEntity
entityItem.motionZ = Math.min(MAX_SPEED, entityItem.motionZ+ACCELERATION); entityItem.motionZ = Math.min(MAX_SPEED, entityItem.motionZ+ACCELERATION);
} }
entityItem.isAirBorne = true;
break;
case SOUTH:
if(!worldObj.isRemote)
{
entityItem.setPosition(xCoord+0.5, yCoord+0.5, entityItem.posZ);
}
entityItem.motionX = 0;
entityItem.motionY = 0;
if(!suck)
{
entityItem.motionZ = Math.min(MAX_SPEED, entityItem.motionZ+ACCELERATION);
}
else {
entityItem.motionZ = Math.max(-MAX_SPEED, entityItem.motionZ-ACCELERATION);
}
entityItem.isAirBorne = true;
break;
case WEST:
if(!worldObj.isRemote)
{
entityItem.setPosition(entityItem.posX, yCoord+0.5, zCoord+0.5);
}
entityItem.motionY = 0;
entityItem.motionZ = 0;
if(!suck)
{
entityItem.motionX = Math.max(-MAX_SPEED, entityItem.motionX-ACCELERATION);
}
else {
entityItem.motionX = Math.min(MAX_SPEED, entityItem.motionX+ACCELERATION);
}
entityItem.isAirBorne = true;
break;
case EAST:
if(!worldObj.isRemote)
{
entityItem.setPosition(entityItem.posX, yCoord+0.5, zCoord+0.5);
}
entityItem.motionY = 0;
entityItem.motionZ = 0;
if(!suck)
{
entityItem.motionX = Math.min(MAX_SPEED, entityItem.motionX+ACCELERATION);
}
else {
entityItem.motionX = Math.max(-MAX_SPEED, entityItem.motionX-ACCELERATION);
}
entityItem.isAirBorne = true; entityItem.isAirBorne = true;
break; break;
} }
@ -169,6 +175,17 @@ public class TileEntityEMContractor extends TileEntity
} }
} }
@Override
public void validate()
{
super.validate();
if(worldObj.isRemote)
{
PacketHandler.sendDataRequest(this);
}
}
public void updateBounds() public void updateBounds()
{ {
switch(facing) switch(facing)
@ -180,7 +197,7 @@ public class TileEntityEMContractor extends TileEntity
operationBounds = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord+1, Math.min(yCoord+MAX_REACH, 255), zCoord+1); operationBounds = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord+1, Math.min(yCoord+MAX_REACH, 255), zCoord+1);
break; break;
case NORTH: case NORTH:
operationBounds = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord+MAX_REACH, yCoord+1, zCoord+1); operationBounds = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord-MAX_REACH, xCoord+1, yCoord+1, zCoord);
break; break;
case SOUTH: case SOUTH:
operationBounds = AxisAlignedBB.getBoundingBox(xCoord-MAX_REACH, yCoord, zCoord, xCoord, yCoord+1, zCoord+1); operationBounds = AxisAlignedBB.getBoundingBox(xCoord-MAX_REACH, yCoord, zCoord, xCoord, yCoord+1, zCoord+1);
@ -189,7 +206,7 @@ public class TileEntityEMContractor extends TileEntity
operationBounds = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord+1, yCoord+1, zCoord+MAX_REACH); operationBounds = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord+1, yCoord+1, zCoord+MAX_REACH);
break; break;
case EAST: case EAST:
operationBounds = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord-MAX_REACH, xCoord+1, yCoord+1, zCoord); operationBounds = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord+MAX_REACH, yCoord+1, zCoord+1);
break; break;
} }
} }
@ -212,8 +229,6 @@ public class TileEntityEMContractor extends TileEntity
{ {
int newOrdinal = facing.ordinal() < 5 ? facing.ordinal()+1 : 0; int newOrdinal = facing.ordinal() < 5 ? facing.ordinal()+1 : 0;
setFacing(ForgeDirection.getOrientation(newOrdinal)); setFacing(ForgeDirection.getOrientation(newOrdinal));
updateBounds();
} }
public ForgeDirection getFacing() public ForgeDirection getFacing()
@ -224,6 +239,13 @@ public class TileEntityEMContractor extends TileEntity
public void setFacing(ForgeDirection side) public void setFacing(ForgeDirection side)
{ {
facing = side; facing = side;
if(!worldObj.isRemote)
{
PacketHandler.sendTileEntityPacketToClients(this, getNetworkedData(new ArrayList()).toArray());
}
updateBounds();
} }
@Override @Override
@ -243,4 +265,20 @@ public class TileEntityEMContractor extends TileEntity
nbtTags.setInteger("facing", facing.ordinal()); nbtTags.setInteger("facing", facing.ordinal());
nbtTags.setBoolean("suck", suck); nbtTags.setBoolean("suck", suck);
} }
@Override
public void handle(ByteArrayDataInput input)
{
try {
facing = ForgeDirection.getOrientation(input.readInt());
worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord);
} catch(Exception e) {}
}
@Override
public ArrayList getNetworkedData(ArrayList data)
{
data.add(facing.ordinal());
return data;
}
} }

View file

@ -22,6 +22,7 @@ public class RenderEMContractor extends TileEntitySpecialRenderer
GL11.glPushMatrix(); GL11.glPushMatrix();
GL11.glTranslated(x + 0.5, y + 1.5, z + 0.5); GL11.glTranslated(x + 0.5, y + 1.5, z + 0.5);
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F); GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
GL11.glRotatef(90F, 0.0F, 1.0F, 0.0F);
switch(((TileEntityEMContractor)t).getFacing()) switch(((TileEntityEMContractor)t).getFacing())
{ {
@ -32,13 +33,13 @@ public class RenderEMContractor extends TileEntitySpecialRenderer
case UP: case UP:
break; break;
case NORTH: case NORTH:
GL11.glTranslatef(-1, 1, 0);
GL11.glRotatef(-90, 0, 0, 1);
break;
case SOUTH:
GL11.glTranslatef(1, 1, 0); GL11.glTranslatef(1, 1, 0);
GL11.glRotatef(90, 0, 0, 1); GL11.glRotatef(90, 0, 0, 1);
break; break;
case SOUTH:
GL11.glTranslatef(-1, 1, 0);
GL11.glRotatef(-90, 0, 0, 1);
break;
case WEST: case WEST:
GL11.glTranslatef(0, 1, 1); GL11.glTranslatef(0, 1, 1);
GL11.glRotatef(-90, 1, 0, 0); GL11.glRotatef(-90, 1, 0, 0);

View file

@ -3,18 +3,16 @@
*/ */
package resonantinduction.tesla; package resonantinduction.tesla;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
import net.minecraft.block.BlockFurnace; import net.minecraft.block.BlockFurnace;
import net.minecraft.entity.Entity;
import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.Packet;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace; import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.AxisAlignedBB;
import resonantinduction.ITesla; import resonantinduction.ITesla;
import resonantinduction.PacketHandler; import resonantinduction.PacketHandler;
import resonantinduction.ResonantInduction; import resonantinduction.ResonantInduction;
@ -181,6 +179,12 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe
{ {
return PacketHandler.getTileEntityPacket(this, (byte) 1, this.getEnergyStored(), this.dyeID); return PacketHandler.getTileEntityPacket(this, (byte) 1, this.getEnergyStored(), this.dyeID);
} }
@Override
public ArrayList getNetworkedData(ArrayList data)
{
return null;
}
@Override @Override
public void handle(ByteArrayDataInput input) public void handle(ByteArrayDataInput input)