Quantum gates now work between dimensions
This commit is contained in:
parent
ded5f53816
commit
1c6aa00f43
4 changed files with 109 additions and 90 deletions
|
@ -14,7 +14,6 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import resonantinduction.core.ResonantInduction;
|
||||
import resonantinduction.electrical.Electrical;
|
||||
import universalelectricity.api.vector.VectorWorld;
|
||||
import codechicken.lib.data.MCDataInput;
|
||||
|
@ -33,19 +32,21 @@ public class PartQuantumGlyph extends JCuboidPart implements JNormalOcclusion, I
|
|||
|
||||
static
|
||||
{
|
||||
bounds[0] = new Cuboid6(0, 0, 0, 0.5, 0.5, 0.5);
|
||||
bounds[1] = new Cuboid6(0, 0, 0.5, 0.5, 0.5, 1);
|
||||
bounds[2] = new Cuboid6(0.5, 0, 0, 1, 0.5, 0.5);
|
||||
bounds[3] = new Cuboid6(0.5, 0, 0.5, 1, 0.5, 1);
|
||||
float expansion = -0.02f;
|
||||
bounds[0] = new Cuboid6(0, 0, 0, 0.5, 0.5, 0.5).expand(expansion);
|
||||
bounds[1] = new Cuboid6(0, 0, 0.5, 0.5, 0.5, 1).expand(expansion);
|
||||
bounds[2] = new Cuboid6(0.5, 0, 0, 1, 0.5, 0.5).expand(expansion);
|
||||
bounds[3] = new Cuboid6(0.5, 0, 0.5, 1, 0.5, 1).expand(expansion);
|
||||
|
||||
bounds[4] = new Cuboid6(0, 0.5, 0, 0.5, 1, 0.5);
|
||||
bounds[5] = new Cuboid6(0, 0.5, 0.5, 0.5, 1, 1);
|
||||
bounds[6] = new Cuboid6(0.5, 0.5, 0, 1, 1, 0.5);
|
||||
bounds[7] = new Cuboid6(0.5, 0.5, 0.5, 1, 1, 1);
|
||||
bounds[4] = new Cuboid6(0, 0.5, 0, 0.5, 1, 0.5).expand(expansion);
|
||||
bounds[5] = new Cuboid6(0, 0.5, 0.5, 0.5, 1, 1).expand(expansion);
|
||||
bounds[6] = new Cuboid6(0.5, 0.5, 0, 1, 1, 0.5).expand(expansion);
|
||||
bounds[7] = new Cuboid6(0.5, 0.5, 0.5, 1, 1, 1).expand(expansion);
|
||||
}
|
||||
|
||||
private byte side;
|
||||
byte number;
|
||||
int ticks;
|
||||
|
||||
public void preparePlacement(int side, int itemDamage)
|
||||
{
|
||||
|
@ -69,7 +70,14 @@ public class PartQuantumGlyph extends JCuboidPart implements JNormalOcclusion, I
|
|||
@Override
|
||||
public void onEntityCollision(Entity entity)
|
||||
{
|
||||
transport(entity);
|
||||
if (!world().isRemote)
|
||||
{
|
||||
if (entity instanceof EntityPlayer)
|
||||
if (!((EntityPlayer) entity).isSneaking())
|
||||
return;
|
||||
|
||||
transport(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -94,7 +102,8 @@ public class PartQuantumGlyph extends JCuboidPart implements JNormalOcclusion, I
|
|||
{
|
||||
IQuantumGate gate = gates.get(gates.size() > 1 ? entity.worldObj.rand.nextInt(gates.size() - 1) : 0);
|
||||
VectorWorld position = new VectorWorld((TileEntity) gate).translate(0.5, 2, 0.5);
|
||||
QuantumGateManager.moveEntity(entity, position);
|
||||
if (QuantumGateManager.moveEntity(entity, position))
|
||||
world().playSoundAtEntity(entity, "mob.endermen.portal", 1.0F, 1.0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -102,6 +111,10 @@ public class PartQuantumGlyph extends JCuboidPart implements JNormalOcclusion, I
|
|||
@Override
|
||||
public void update()
|
||||
{
|
||||
if (ticks == 0)
|
||||
FrequencyGrid.instance().register((IQuantumGate) tile());
|
||||
ticks++;
|
||||
|
||||
if (world().isRemote)
|
||||
{
|
||||
int frequency = ((IBlockFrequency) tile()).getFrequency();
|
||||
|
|
|
@ -8,102 +8,109 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.world.Teleporter;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
import universalelectricity.api.vector.VectorWorld;
|
||||
|
||||
public class QuantumGateManager
|
||||
{
|
||||
private static HashMap<Integer, QuantumGateManager> managerList = new HashMap<Integer, QuantumGateManager>();
|
||||
private HashSet<TileQuantumGate> teleporters = new HashSet<TileQuantumGate>();
|
||||
private static HashMap<String, Long> coolDown = new HashMap<String, Long>();
|
||||
private static HashMap<String, Long> playerCooldown = new HashMap<String, Long>();
|
||||
|
||||
public static QuantumGateManager getManagerForDim(int dim)
|
||||
protected static boolean moveEntity(Entity currentEntity, final VectorWorld location)
|
||||
{
|
||||
if (managerList.get(dim) == null)
|
||||
if (currentEntity != null && location != null && location.world instanceof WorldServer)
|
||||
{
|
||||
managerList.put(dim, new QuantumGateManager());
|
||||
}
|
||||
|
||||
return managerList.get(dim);
|
||||
}
|
||||
location.world.markBlockForUpdate(location.intX(), location.intY(), location.intZ());
|
||||
|
||||
/** Adds a teleport anchor to this list or anchors */
|
||||
public static void addAnchor(TileQuantumGate anch)
|
||||
{
|
||||
if (anch != null)
|
||||
{
|
||||
QuantumGateManager manager = getManagerForDim(anch.worldObj.provider.dimensionId);
|
||||
|
||||
if (!manager.teleporters.contains(anch))
|
||||
int dimID = location.world.provider.dimensionId;
|
||||
|
||||
if (currentEntity instanceof EntityPlayerMP)
|
||||
{
|
||||
manager.teleporters.add(anch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Removes a teleport anchor to this list or anchors */
|
||||
public static void remAnchor(TileQuantumGate anch)
|
||||
{
|
||||
if (anch != null)
|
||||
{
|
||||
QuantumGateManager manager = getManagerForDim(anch.worldObj.provider.dimensionId);
|
||||
manager.teleporters.remove(anch);
|
||||
}
|
||||
}
|
||||
|
||||
public static HashSet<TileQuantumGate> getConnectedAnchors(World world)
|
||||
{
|
||||
return getManagerForDim(world.provider.dimensionId).teleporters;
|
||||
}
|
||||
|
||||
public boolean contains(TileQuantumGate anch)
|
||||
{
|
||||
return teleporters.contains(anch);
|
||||
}
|
||||
|
||||
public static TileQuantumGate getClosestWithFrequency(VectorWorld vec, int frequency, TileQuantumGate... anchors)
|
||||
{
|
||||
TileQuantumGate tele = null;
|
||||
List<TileQuantumGate> ignore = new ArrayList<TileQuantumGate>();
|
||||
if (anchors != null)
|
||||
{
|
||||
ignore.addAll(Arrays.asList(anchors));
|
||||
}
|
||||
Iterator<TileQuantumGate> it = new ArrayList(QuantumGateManager.getConnectedAnchors(vec.world)).iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
TileQuantumGate teleporter = it.next();
|
||||
if (!ignore.contains(teleporter) && teleporter.getFrequency() == frequency)
|
||||
{
|
||||
if (tele == null || new Vector3(tele).distance(vec) > new Vector3(teleporter).distance(vec))
|
||||
if (playerCooldown.get(((EntityPlayerMP) currentEntity).username) == null || (System.currentTimeMillis() - playerCooldown.get(((EntityPlayerMP) currentEntity).username) > 2000))
|
||||
{
|
||||
tele = teleporter;
|
||||
}
|
||||
}
|
||||
}
|
||||
return tele;
|
||||
}
|
||||
EntityPlayerMP player = (EntityPlayerMP) currentEntity;
|
||||
|
||||
protected static void moveEntity(Entity entity, VectorWorld location)
|
||||
{
|
||||
if (entity != null && location != null)
|
||||
{
|
||||
location.world.markBlockForUpdate((int) location.x, (int) location.y, (int) location.z);
|
||||
|
||||
if (entity instanceof EntityPlayerMP)
|
||||
{
|
||||
if (coolDown.get(((EntityPlayerMP) entity).username) == null || (System.currentTimeMillis() - coolDown.get(((EntityPlayerMP) entity).username) > 30))
|
||||
{
|
||||
((EntityPlayerMP) entity).playerNetServerHandler.setPlayerLocation(location.x, location.y, location.z, 0, 0);
|
||||
coolDown.put(((EntityPlayerMP) entity).username, System.currentTimeMillis());
|
||||
if (location.world != currentEntity.worldObj)
|
||||
{
|
||||
Teleporter dummyTeleporter = new Teleporter((WorldServer) location.world)
|
||||
{
|
||||
@Override
|
||||
public void placeInPortal(Entity teleportEntity, double x, double y, double z, float par8)
|
||||
{
|
||||
teleportEntity.setLocationAndAngles(location.x, location.y, location.z, teleportEntity.rotationYaw, 0.0F);
|
||||
teleportEntity.motionX = teleportEntity.motionY = teleportEntity.motionZ = 0.0D;
|
||||
}
|
||||
};
|
||||
|
||||
player.mcServer.getConfigurationManager().transferPlayerToDimension(player, dimID, dummyTeleporter);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.playerNetServerHandler.setPlayerLocation(location.x, location.y, location.z, 0, 0);
|
||||
}
|
||||
|
||||
playerCooldown.put(((EntityPlayerMP) currentEntity).username, System.currentTimeMillis());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.setPosition(location.x, location.y, location.z);
|
||||
if (location.world != currentEntity.worldObj)
|
||||
{
|
||||
|
||||
currentEntity.worldObj.theProfiler.startSection("changeDimension");
|
||||
MinecraftServer minecraftserver = MinecraftServer.getServer();
|
||||
int j = currentEntity.dimension;
|
||||
WorldServer worldserver = minecraftserver.worldServerForDimension(j);
|
||||
WorldServer worldserver1 = minecraftserver.worldServerForDimension(dimID);
|
||||
currentEntity.dimension = dimID;
|
||||
|
||||
if (j == 1 && dimID == 1)
|
||||
{
|
||||
worldserver1 = minecraftserver.worldServerForDimension(0);
|
||||
currentEntity.dimension = 0;
|
||||
}
|
||||
|
||||
currentEntity.worldObj.removeEntity(currentEntity);
|
||||
currentEntity.isDead = false;
|
||||
currentEntity.worldObj.theProfiler.startSection("reposition");
|
||||
minecraftserver.getConfigurationManager().transferEntityToWorld(currentEntity, j, worldserver, worldserver1);
|
||||
currentEntity.worldObj.theProfiler.endStartSection("reloading");
|
||||
Entity entity = EntityList.createEntityByName(EntityList.getEntityString(currentEntity), worldserver1);
|
||||
|
||||
if (entity != null)
|
||||
{
|
||||
entity.copyDataFrom(currentEntity, true);
|
||||
|
||||
if (j == 1 && dimID == 1)
|
||||
{
|
||||
ChunkCoordinates chunkcoordinates = worldserver1.getSpawnPoint();
|
||||
chunkcoordinates.posY = currentEntity.worldObj.getTopSolidOrLiquidBlock(chunkcoordinates.posX, chunkcoordinates.posZ);
|
||||
entity.setLocationAndAngles((double) chunkcoordinates.posX, (double) chunkcoordinates.posY, (double) chunkcoordinates.posZ, entity.rotationYaw, entity.rotationPitch);
|
||||
}
|
||||
|
||||
worldserver1.spawnEntityInWorld(entity);
|
||||
}
|
||||
|
||||
currentEntity.isDead = true;
|
||||
currentEntity.worldObj.theProfiler.endSection();
|
||||
worldserver.resetUpdateEntityTick();
|
||||
worldserver1.resetUpdateEntityTick();
|
||||
currentEntity.worldObj.theProfiler.endSection();
|
||||
return true;
|
||||
}
|
||||
|
||||
currentEntity.setPosition(location.x, location.y, location.z);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,8 +25,7 @@ public class RenderQuantumGlyph implements ISimpleItemRenderer
|
|||
{
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslated(x, y, z);
|
||||
Cuboid6 bound = part.getBounds().copy();
|
||||
bound.expand(-0.02);
|
||||
Cuboid6 bound = part.getBounds();
|
||||
RenderUtility.bind(TextureMap.locationBlocksTexture);
|
||||
RenderUtility.renderCube(bound.min.x, bound.min.y, bound.min.z, bound.max.x, bound.max.y, bound.max.z, Block.stone, RenderUtility.getIcon(Reference.PREFIX + "glyph_" + part.number));
|
||||
GL11.glPopMatrix();
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 843 B |
Loading…
Reference in a new issue