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.nbt.NBTTagCompound;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.MovingObjectPosition;
|
import net.minecraft.util.MovingObjectPosition;
|
||||||
import resonantinduction.core.ResonantInduction;
|
|
||||||
import resonantinduction.electrical.Electrical;
|
import resonantinduction.electrical.Electrical;
|
||||||
import universalelectricity.api.vector.VectorWorld;
|
import universalelectricity.api.vector.VectorWorld;
|
||||||
import codechicken.lib.data.MCDataInput;
|
import codechicken.lib.data.MCDataInput;
|
||||||
|
@ -33,19 +32,21 @@ public class PartQuantumGlyph extends JCuboidPart implements JNormalOcclusion, I
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
bounds[0] = new Cuboid6(0, 0, 0, 0.5, 0.5, 0.5);
|
float expansion = -0.02f;
|
||||||
bounds[1] = new Cuboid6(0, 0, 0.5, 0.5, 0.5, 1);
|
bounds[0] = new Cuboid6(0, 0, 0, 0.5, 0.5, 0.5).expand(expansion);
|
||||||
bounds[2] = new Cuboid6(0.5, 0, 0, 1, 0.5, 0.5);
|
bounds[1] = new Cuboid6(0, 0, 0.5, 0.5, 0.5, 1).expand(expansion);
|
||||||
bounds[3] = new Cuboid6(0.5, 0, 0.5, 1, 0.5, 1);
|
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[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);
|
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);
|
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);
|
bounds[7] = new Cuboid6(0.5, 0.5, 0.5, 1, 1, 1).expand(expansion);
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte side;
|
private byte side;
|
||||||
byte number;
|
byte number;
|
||||||
|
int ticks;
|
||||||
|
|
||||||
public void preparePlacement(int side, int itemDamage)
|
public void preparePlacement(int side, int itemDamage)
|
||||||
{
|
{
|
||||||
|
@ -69,8 +70,15 @@ public class PartQuantumGlyph extends JCuboidPart implements JNormalOcclusion, I
|
||||||
@Override
|
@Override
|
||||||
public void onEntityCollision(Entity entity)
|
public void onEntityCollision(Entity entity)
|
||||||
{
|
{
|
||||||
|
if (!world().isRemote)
|
||||||
|
{
|
||||||
|
if (entity instanceof EntityPlayer)
|
||||||
|
if (!((EntityPlayer) entity).isSneaking())
|
||||||
|
return;
|
||||||
|
|
||||||
transport(entity);
|
transport(entity);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void transport(Entity entity)
|
public void transport(Entity entity)
|
||||||
|
@ -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);
|
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);
|
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
|
@Override
|
||||||
public void update()
|
public void update()
|
||||||
{
|
{
|
||||||
|
if (ticks == 0)
|
||||||
|
FrequencyGrid.instance().register((IQuantumGate) tile());
|
||||||
|
ticks++;
|
||||||
|
|
||||||
if (world().isRemote)
|
if (world().isRemote)
|
||||||
{
|
{
|
||||||
int frequency = ((IBlockFrequency) tile()).getFrequency();
|
int frequency = ((IBlockFrequency) tile()).getFrequency();
|
||||||
|
|
|
@ -8,102 +8,109 @@ import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.EntityList;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
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.World;
|
||||||
|
import net.minecraft.world.WorldServer;
|
||||||
import universalelectricity.api.vector.Vector3;
|
import universalelectricity.api.vector.Vector3;
|
||||||
import universalelectricity.api.vector.VectorWorld;
|
import universalelectricity.api.vector.VectorWorld;
|
||||||
|
|
||||||
public class QuantumGateManager
|
public class QuantumGateManager
|
||||||
{
|
{
|
||||||
private static HashMap<Integer, QuantumGateManager> managerList = new HashMap<Integer, QuantumGateManager>();
|
private static HashMap<String, Long> playerCooldown = new HashMap<String, Long>();
|
||||||
private HashSet<TileQuantumGate> teleporters = new HashSet<TileQuantumGate>();
|
|
||||||
private static HashMap<String, Long> coolDown = 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());
|
location.world.markBlockForUpdate(location.intX(), location.intY(), location.intZ());
|
||||||
|
|
||||||
|
int dimID = location.world.provider.dimensionId;
|
||||||
|
|
||||||
|
if (currentEntity instanceof EntityPlayerMP)
|
||||||
|
{
|
||||||
|
if (playerCooldown.get(((EntityPlayerMP) currentEntity).username) == null || (System.currentTimeMillis() - playerCooldown.get(((EntityPlayerMP) currentEntity).username) > 2000))
|
||||||
|
{
|
||||||
|
EntityPlayerMP player = (EntityPlayerMP) currentEntity;
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
return managerList.get(dim);
|
playerCooldown.put(((EntityPlayerMP) currentEntity).username, System.currentTimeMillis());
|
||||||
}
|
return true;
|
||||||
|
|
||||||
/** 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))
|
|
||||||
{
|
|
||||||
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))
|
|
||||||
{
|
|
||||||
tele = teleporter;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tele;
|
|
||||||
}
|
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
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.glPushMatrix();
|
||||||
GL11.glTranslated(x, y, z);
|
GL11.glTranslated(x, y, z);
|
||||||
Cuboid6 bound = part.getBounds().copy();
|
Cuboid6 bound = part.getBounds();
|
||||||
bound.expand(-0.02);
|
|
||||||
RenderUtility.bind(TextureMap.locationBlocksTexture);
|
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));
|
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();
|
GL11.glPopMatrix();
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 843 B |
Loading…
Reference in a new issue