Work on things, may be unstable

This commit is contained in:
Aidan Brady 2013-12-07 17:06:11 -05:00
parent 5e50e920a6
commit c2737ff064
16 changed files with 311 additions and 60 deletions

View file

@ -0,0 +1,26 @@
package mekanism.client;
import mekanism.common.Mekanism;
import net.minecraft.entity.player.EntityPlayer;
import cpw.mods.fml.common.IPlayerTracker;
public class ClientPlayerTracker implements IPlayerTracker
{
@Override
public void onPlayerLogin(EntityPlayer player) {}
@Override
public void onPlayerLogout(EntityPlayer player)
{
Mekanism.jetpackOn.remove(player);
}
@Override
public void onPlayerChangedDimension(EntityPlayer player)
{
Mekanism.jetpackOn.remove(player);
}
@Override
public void onPlayerRespawn(EntityPlayer player) {}
}

View file

@ -54,6 +54,7 @@ import mekanism.client.render.tileentity.RenderMetallurgicInfuser;
import mekanism.client.render.tileentity.RenderObsidianTNT;
import mekanism.client.render.tileentity.RenderPressurizedTube;
import mekanism.client.render.tileentity.RenderRotaryCondensentrator;
import mekanism.client.render.tileentity.RenderTeleporter;
import mekanism.client.render.tileentity.RenderUniversalCable;
import mekanism.client.sound.Sound;
import mekanism.client.sound.SoundHandler;
@ -109,6 +110,7 @@ import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.client.registry.KeyBindingRegistry;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.TickRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -255,6 +257,7 @@ public class ClientProxy extends CommonProxy
ClientRegistry.registerTileEntity(TileEntityBin.class, "Bin", new RenderBin());
ClientRegistry.registerTileEntity(TileEntityDigitalMiner.class, "DigitalMiner", new RenderDigitalMiner());
ClientRegistry.registerTileEntity(TileEntityRotaryCondensentrator.class, "RotaryCondensentrator", new RenderRotaryCondensentrator());
ClientRegistry.registerTileEntity(TileEntityTeleporter.class, "MekanismTeleporter", new RenderTeleporter());
}
@Override
@ -381,6 +384,8 @@ public class ClientProxy extends CommonProxy
NetworkRegistry.instance().registerConnectionHandler(new ClientConnectionHandler());
KeyBindingRegistry.registerKeyBinding(new MekanismKeyHandler());
GameRegistry.registerPlayerTracker(new ClientPlayerTracker());
}
@Override

View file

@ -106,7 +106,7 @@ public class RenderConfigurableMachine extends TileEntitySpecialRenderer
toReturn.baseBlock = Block.stone;
toReturn.setTexture(MekanismRenderer.getColorIcon(color));
DisplayInteger display = new DisplayInteger();
DisplayInteger display = DisplayInteger.createAndStart();
if(cachedOverlays.containsKey(side))
{
@ -118,9 +118,6 @@ public class RenderConfigurableMachine extends TileEntitySpecialRenderer
cachedOverlays.put(side, map);
}
display.display = GLAllocation.generateDisplayLists(1);
GL11.glNewList(display.display, 4864);
switch(side)
{
case DOWN:
@ -196,7 +193,7 @@ public class RenderConfigurableMachine extends TileEntitySpecialRenderer
}
MekanismRenderer.renderObject(toReturn);
GL11.glEndList();
display.endList();
return display;
}

View file

@ -18,7 +18,6 @@ import mekanism.common.util.MekanismUtils.ResourceType;
import mekanism.common.util.TransporterUtils;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GLAllocation;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
@ -215,7 +214,7 @@ public class RenderLogisticalTransporter extends TileEntitySpecialRenderer
toReturn.baseBlock = Block.stone;
toReturn.setTexture(icon);
DisplayInteger display = new DisplayInteger();
DisplayInteger display = DisplayInteger.createAndStart();
if(cachedOverlays.containsKey(side))
{
@ -227,9 +226,6 @@ public class RenderLogisticalTransporter extends TileEntitySpecialRenderer
cachedOverlays.put(side, map);
}
display.display = GLAllocation.generateDisplayLists(1);
GL11.glNewList(display.display, 4864);
switch(side)
{
case DOWN:
@ -305,7 +301,7 @@ public class RenderLogisticalTransporter extends TileEntitySpecialRenderer
}
MekanismRenderer.renderObject(toReturn);
GL11.glEndList();
display.endList();
return display;
}

View file

@ -249,7 +249,7 @@ public class RenderMechanicalPipe extends TileEntitySpecialRenderer
}
MekanismRenderer.renderObject(toReturn);
DisplayInteger.endList();
displays[i].endList();
}
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

View file

@ -300,7 +300,7 @@ public class RenderPressurizedTube extends TileEntitySpecialRenderer
}
MekanismRenderer.renderObject(toReturn);
DisplayInteger.endList();
display.endList();
return display;
}

View file

@ -0,0 +1,127 @@
package mekanism.client.render.tileentity;
import java.util.HashMap;
import mekanism.api.EnumColor;
import mekanism.api.Object3D;
import mekanism.api.gas.GasRegistry;
import mekanism.client.render.MekanismRenderer;
import mekanism.client.render.MekanismRenderer.DisplayInteger;
import mekanism.client.render.MekanismRenderer.Model3D;
import mekanism.common.Mekanism;
import mekanism.common.tileentity.TileEntityTeleporter;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.GLAllocation;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import org.lwjgl.opengl.GL11;
public class RenderTeleporter extends TileEntitySpecialRenderer
{
private HashMap<Integer, DisplayInteger> cachedOverlays = new HashMap<Integer, DisplayInteger>();
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float partialTick)
{
renderAModelAt((TileEntityTeleporter)tileEntity, x, y, z, partialTick);
}
public void renderAModelAt(TileEntityTeleporter tileEntity, double x, double y, double z, float partialTick)
{
if(tileEntity.shouldRender)
{
push();
GL11.glColor4f(EnumColor.PURPLE.getColor(0), EnumColor.PURPLE.getColor(1), EnumColor.PURPLE.getColor(2), 0.75F);
bindTexture(MekanismRenderer.getBlocksTexture());
GL11.glTranslatef((float)x, (float)y, (float)z);
Object3D obj = Object3D.get(tileEntity).getFromSide(ForgeDirection.WEST);
int type = 0;
if(obj.getBlockId(tileEntity.worldObj) == Mekanism.basicBlockID && obj.getMetadata(tileEntity.worldObj) == 7)
{
type = 1;
}
int display = getOverlayDisplay(type).display;
GL11.glCallList(display);
pop();
}
}
private void pop()
{
GL11.glPopAttrib();
MekanismRenderer.glowOff();
MekanismRenderer.blendOff();
GL11.glPopMatrix();
}
private void push()
{
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glDisable(GL11.GL_LIGHTING);
MekanismRenderer.glowOn();
MekanismRenderer.blendOn();
}
private DisplayInteger getOverlayDisplay(Integer type)
{
if(cachedOverlays.containsKey(type))
{
return cachedOverlays.get(type);
}
Model3D toReturn = new Model3D();
toReturn.baseBlock = Block.stone;
toReturn.setTexture(GasRegistry.getGas("oxygen").getIcon());
DisplayInteger display = DisplayInteger.createAndStart();
if(cachedOverlays.containsKey(type))
{
cachedOverlays.get(type);
}
else {
cachedOverlays.put(type, display);
}
switch(type)
{
case 0:
{
toReturn.minY = 1;
toReturn.maxY = 3;
toReturn.minX = 0.46;
toReturn.minZ = 0;
toReturn.maxX = 0.54;
toReturn.maxZ = 1;
break;
}
case 1:
{
toReturn.minY = 1;
toReturn.maxY = 3;
toReturn.minX = 0;
toReturn.minZ = 0.46;
toReturn.maxX = 1;
toReturn.maxZ = 0.54;
break;
}
}
MekanismRenderer.renderObject(toReturn);
display.endList();
return display;
}
}

View file

@ -19,6 +19,10 @@ public class GasMaskSound extends PlayerSound
{
return false;
}
else if(player.worldObj != world)
{
return false;
}
else if(!world.loadedEntityList.contains(player))
{
return false;

View file

@ -20,6 +20,10 @@ public class JetpackSound extends PlayerSound
{
return false;
}
else if(player.worldObj != world)
{
return false;
}
else if(!world.loadedEntityList.contains(player))
{
return false;

View file

@ -1,9 +1,6 @@
package mekanism.client.sound;
import mekanism.client.ClientPlayerTickHandler;
import mekanism.common.item.ItemJetpack;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import universalelectricity.core.vector.Vector3;
public abstract class PlayerSound extends Sound
@ -39,7 +36,4 @@ public abstract class PlayerSound extends Sound
ticksSincePlay = 0;
}
@Override
public abstract boolean update(World world);
}

View file

@ -14,7 +14,10 @@ public class CommonPlayerTracker implements IPlayerTracker
}
@Override
public void onPlayerChangedDimension(EntityPlayer player) {}
public void onPlayerChangedDimension(EntityPlayer player)
{
Mekanism.jetpackOn.remove(player);
}
@Override
public void onPlayerRespawn(EntityPlayer player) {}

View file

@ -100,6 +100,7 @@ public class CommonProxy
GameRegistry.registerTileEntity(TileEntityDigitalMiner.class, "DigitalMiner");
GameRegistry.registerTileEntity(TileEntityObsidianTNT.class, "ObsidianTNT");
GameRegistry.registerTileEntity(TileEntityRotaryCondensentrator.class, "RotaryCondensentrator");
GameRegistry.registerTileEntity(TileEntityTeleporter.class, "Teleporter");
}
/**

View file

@ -1084,7 +1084,6 @@ public class Mekanism
//Tile entities
GameRegistry.registerTileEntity(TileEntityBoundingBlock.class, "BoundingBlock");
GameRegistry.registerTileEntity(TileEntityAdvancedBoundingBlock.class, "AdvancedBoundingBlock");
GameRegistry.registerTileEntity(TileEntityTeleporter.class, "MekanismTeleporter");
//Load tile entities that have special renderers.
proxy.registerSpecialTileEntities();

View file

@ -627,23 +627,7 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds
if(tileEntity != null)
{
if(metadata == MachineType.TELEPORTER.meta)
{
if(entityplayer.isSneaking())
{
entityplayer.openGui(Mekanism.instance, 13, world, x, y, z);
return true;
}
TileEntityTeleporter teleporter = (TileEntityTeleporter)tileEntity;
if(teleporter.canTeleport() == 1)
{
teleporter.teleport();
return true;
}
}
else if(metadata == MachineType.ELECTRIC_CHEST.meta)
if(metadata == MachineType.ELECTRIC_CHEST.meta)
{
TileEntityElectricChest electricChest = (TileEntityElectricChest)tileEntity;

View file

@ -7,6 +7,7 @@ import mekanism.common.PacketHandler;
import mekanism.common.Teleporter;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.item.ItemPortableTeleporter;
import mekanism.common.tileentity.TileEntityTeleporter;
import mekanism.common.util.MekanismUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
@ -15,6 +16,8 @@ import net.minecraft.world.World;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.common.FMLCommonHandler;
public class PacketPortableTeleport implements IMekanismPacket
{
@Override
@ -49,6 +52,11 @@ public class PacketPortableTeleport implements IMekanismPacket
((EntityPlayerMP)player).travelToDimension(coords.dimensionId);
}
World teleWorld = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(coords.dimensionId);
TileEntityTeleporter teleporter = (TileEntityTeleporter)coords.getTileEntity(teleWorld);
teleporter.didTeleport.add(player);
teleporter.teleDelay = 5;
((EntityPlayerMP)player).playerNetServerHandler.setPlayerLocation(coords.xCoord+0.5, coords.yCoord+1, coords.zCoord+0.5, player.rotationYaw, player.rotationPitch);
world.playSoundAtEntity(player, "mob.endermen.portal", 1.0F, 1.0F);

View file

@ -1,7 +1,9 @@
package mekanism.common.tileentity;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import mekanism.api.EnumColor;
import mekanism.api.Object3D;
@ -11,18 +13,22 @@ import mekanism.common.PacketHandler.Transmission;
import mekanism.common.Teleporter;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.network.PacketPortalFX;
import mekanism.common.network.PacketTileEntity;
import mekanism.common.util.ChargeUtils;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.network.packet.Packet34EntityTeleport;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection;
import net.minecraft.world.World;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.PacketDispatcher;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.ILuaContext;
import dan200.computer.api.IPeripheral;
@ -32,6 +38,16 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IPe
/** This teleporter's frequency. */
public Teleporter.Code code;
public AxisAlignedBB teleportBounds = null;
public Set<Entity> didTeleport = new HashSet<Entity>();
public int teleDelay = 0;
public boolean shouldRender;
public boolean prevShouldRender;
/** This teleporter's current status. */
public String status = (EnumColor.DARK_RED + "Not ready.");
@ -47,8 +63,13 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IPe
{
super.onUpdate();
if(!worldObj.isRemote)
if(teleportBounds == null)
{
resetBounds();
}
if(!worldObj.isRemote)
{
if(Mekanism.teleporters.containsKey(code))
{
if(!Mekanism.teleporters.get(code).contains(Object3D.get(this)) && hasFrame())
@ -88,11 +109,47 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IPe
status = EnumColor.DARK_GREEN + "Idle.";
break;
}
if(canTeleport() == 1 && teleDelay == 0)
{
teleport();
}
if(teleDelay == 0 && didTeleport.size() > 0)
{
cleanTeleportCache();
}
byte b = canTeleport();
shouldRender = b == 1 || b > 4;
if(shouldRender != prevShouldRender)
{
PacketHandler.sendPacket(Transmission.CLIENTS_RANGE, new PacketTileEntity().setParams(Object3D.get(this), getNetworkedData(new ArrayList())), Object3D.get(this), 40D);
}
prevShouldRender = shouldRender;
teleDelay = Math.max(0, teleDelay-1);
}
ChargeUtils.discharge(0, this);
}
public void cleanTeleportCache()
{
List<Entity> list = worldObj.getEntitiesWithinAABB(Entity.class, teleportBounds);
Set<Entity> teleportCopy = (Set<Entity>)((HashSet<Entity>)didTeleport).clone();
for(Entity entity : teleportCopy)
{
if(!list.contains(entity))
{
didTeleport.remove(entity);
}
}
}
@Override
public int[] getAccessibleSlotsFromSide(int side)
{
@ -110,6 +167,11 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IPe
return true;
}
public void resetBounds()
{
teleportBounds = AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord+1, yCoord+3, zCoord+1);
}
/**
* 1: yes
* 2: no frame
@ -138,7 +200,7 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IPe
if(Mekanism.teleporters.get(code).size() == 2)
{
List<EntityPlayer> entitiesInPortal = worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(xCoord-1, yCoord, zCoord-1, xCoord+1, yCoord+3, zCoord+1));
List<Entity> entitiesInPortal = getToTeleport();
Object3D closestCoords = null;
@ -153,7 +215,7 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IPe
int electricityNeeded = 0;
for(EntityPlayer entity : entitiesInPortal)
for(Entity entity : entitiesInPortal)
{
electricityNeeded += calculateEnergyCost(entity, closestCoords);
}
@ -178,7 +240,7 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IPe
{
if(worldObj.isRemote) return;
List<EntityPlayer> entitiesInPortal = worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(xCoord-1, yCoord, zCoord-1, xCoord+1, yCoord+3, zCoord+1));
List<Entity> entitiesInPortal = getToTeleport();
Object3D closestCoords = null;
@ -191,26 +253,58 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IPe
}
}
for(EntityPlayer entity : entitiesInPortal)
{
setEnergy(getEnergy() - calculateEnergyCost(entity, closestCoords));
for(Entity entity : entitiesInPortal)
{
World teleWorld = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(closestCoords.dimensionId);
TileEntityTeleporter teleporter = (TileEntityTeleporter)closestCoords.getTileEntity(teleWorld);
worldObj.playSoundAtEntity((EntityPlayerMP)entity, "mob.endermen.portal", 1.0F, 1.0F);
if(entity.worldObj.provider.dimensionId != closestCoords.dimensionId)
if(teleporter != null)
{
entity.travelToDimension(closestCoords.dimensionId);
}
((EntityPlayerMP)entity).playerNetServerHandler.setPlayerLocation(closestCoords.xCoord+0.5, closestCoords.yCoord+1, closestCoords.zCoord+0.5, entity.rotationYaw, entity.rotationPitch);
for(Object3D coords : Mekanism.teleporters.get(code))
{
PacketHandler.sendPacket(Transmission.CLIENTS_RANGE, new PacketPortalFX().setParams(coords), coords, 40D);
teleporter.didTeleport.add(entity);
teleporter.teleDelay = 5;
if(entity.worldObj.provider.dimensionId != closestCoords.dimensionId)
{
entity.travelToDimension(closestCoords.dimensionId);
}
if(entity instanceof EntityPlayerMP)
{
((EntityPlayerMP)entity).playerNetServerHandler.setPlayerLocation(closestCoords.xCoord+0.5, closestCoords.yCoord+1, closestCoords.zCoord+0.5, entity.rotationYaw, entity.rotationPitch);
}
else {
entity.setLocationAndAngles(closestCoords.xCoord+0.5, closestCoords.yCoord+1, closestCoords.zCoord+0.5, entity.rotationYaw, entity.rotationPitch);
PacketDispatcher.sendPacketToAllPlayers(new Packet34EntityTeleport(entity));
}
for(Object3D coords : Mekanism.teleporters.get(code))
{
PacketHandler.sendPacket(Transmission.CLIENTS_RANGE, new PacketPortalFX().setParams(coords), coords, 40D);
}
setEnergy(getEnergy() - calculateEnergyCost(entity, closestCoords));
worldObj.playSoundAtEntity(entity, "mob.endermen.portal", 1.0F, 1.0F);
}
}
}
public List<Entity> getToTeleport()
{
List<Entity> entities = worldObj.getEntitiesWithinAABB(Entity.class, teleportBounds);
List<Entity> ret = new ArrayList<Entity>();
for(Entity entity : entities)
{
if(!didTeleport.contains(entity))
{
ret.add(entity);
}
}
return ret;
}
@Override
public void invalidate()
{
@ -333,6 +427,7 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IPe
code.digitTwo = dataStream.readInt();
code.digitThree = dataStream.readInt();
code.digitFour = dataStream.readInt();
shouldRender = dataStream.readBoolean();
}
@Override
@ -345,6 +440,7 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IPe
data.add(code.digitTwo);
data.add(code.digitThree);
data.add(code.digitFour);
data.add(shouldRender);
return data;
}
@ -420,10 +516,17 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IPe
{
return true;
}
@Override
public void attach(IComputerAccess computer) {}
@Override
public void detach(IComputerAccess computer) {}
@Override
@SideOnly(Side.CLIENT)
public AxisAlignedBB getRenderBoundingBox()
{
return INFINITE_EXTENT_AABB;
}
}