mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-21 04:32:18 +00:00
Add interdimensional travel to telepad. Some improvements to text fields
This commit is contained in:
1 parent
350860fb2c
commit
42c99bbdae
9 files changed
+182
-63
No files matched your search
@@ -56,10 +56,20 @@ public interface ITelePad extends ITravelAccessable {
|
||||
*/
|
||||
int getZ();
|
||||
|
||||
/**
|
||||
* The target dimension ID for the telepad. Defaults to the dimension the
|
||||
* block is placed in.
|
||||
*
|
||||
* @return An int dimension ID.
|
||||
*/
|
||||
int getTargetDim();
|
||||
|
||||
/**
|
||||
* Sets the target X coordinate of the network. Has no effect if
|
||||
* {@link #inNetwork()} returns false.
|
||||
*
|
||||
* @param x
|
||||
* The X coord.
|
||||
* @return The master telepad TE. DOES NOT ALWAYS return itself.
|
||||
*/
|
||||
ITelePad setX(int x);
|
||||
@@ -68,6 +78,8 @@ public interface ITelePad extends ITravelAccessable {
|
||||
* Sets the target Y coordinate of the network. Has no effect if
|
||||
* {@link #inNetwork()} returns false.
|
||||
*
|
||||
* @param y
|
||||
* The Y coord.
|
||||
* @return The master telepad TE. DOES NOT ALWAYS return itself.
|
||||
*/
|
||||
ITelePad setY(int y);
|
||||
@@ -76,10 +88,22 @@ public interface ITelePad extends ITravelAccessable {
|
||||
* Sets the target Z coordinate of the network. Has no effect if
|
||||
* {@link #inNetwork()} returns false.
|
||||
*
|
||||
* @param z
|
||||
* The Z coord.
|
||||
* @return The master telepad TE. DOES NOT ALWAYS return itself.
|
||||
*/
|
||||
ITelePad setZ(int z);
|
||||
|
||||
/**
|
||||
* Sets the target dimension of the network. Has no effect if
|
||||
* {@link #inNetwork()} returns false.
|
||||
*
|
||||
* @param dimID
|
||||
* The dimension ID.
|
||||
* @return The master telepad TE. DOES NOT ALWAYS return itself.
|
||||
*/
|
||||
ITelePad setTargetDim(int dimID);
|
||||
|
||||
/**
|
||||
* Util method to set all coords using a {@link BlockCoord} object.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package crazypants.enderio.gui;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import crazypants.gui.IGuiScreen;
|
||||
@@ -8,27 +10,27 @@ public class TextFieldEIO extends GuiTextField {
|
||||
|
||||
public interface ICharFilter {
|
||||
|
||||
boolean passesFilter(char c);
|
||||
boolean passesFilter(TextFieldEIO tf, char c);
|
||||
}
|
||||
|
||||
public static final ICharFilter FILTER_NUMERIC = new ICharFilter() {
|
||||
@Override
|
||||
public boolean passesFilter(char c) {
|
||||
return Character.isDigit(c);
|
||||
public boolean passesFilter(TextFieldEIO tf, char c) {
|
||||
return Character.isDigit(c) || (c == '-' && Strings.isNullOrEmpty(tf.getText()));
|
||||
}
|
||||
};
|
||||
|
||||
public static ICharFilter FILTER_ALPHABETICAL = new ICharFilter() {
|
||||
@Override
|
||||
public boolean passesFilter(char c) {
|
||||
public boolean passesFilter(TextFieldEIO tf, char c) {
|
||||
return Character.isAlphabetic(c);
|
||||
}
|
||||
};
|
||||
|
||||
public static ICharFilter FILTER_ALPHANUMERIC = new ICharFilter() {
|
||||
@Override
|
||||
public boolean passesFilter(char c) {
|
||||
return FILTER_NUMERIC.passesFilter(c) || FILTER_ALPHABETICAL.passesFilter(c);
|
||||
public boolean passesFilter(TextFieldEIO tf, char c) {
|
||||
return FILTER_NUMERIC.passesFilter(tf, c) || FILTER_ALPHABETICAL.passesFilter(tf, c);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -37,9 +39,14 @@ public class TextFieldEIO extends GuiTextField {
|
||||
private ICharFilter filter;
|
||||
|
||||
public TextFieldEIO(FontRenderer fnt, int x, int y, int width, int height) {
|
||||
this(fnt, x, y, width, height, null);
|
||||
}
|
||||
|
||||
public TextFieldEIO(FontRenderer fnt, int x, int y, int width, int height, ICharFilter charFilter) {
|
||||
super(fnt, x, y, width, height);
|
||||
this.xOrigin = x;
|
||||
this.yOrigin = y;
|
||||
this.filter = charFilter;
|
||||
}
|
||||
|
||||
public void init(IGuiScreen gui) {
|
||||
@@ -54,7 +61,7 @@ public class TextFieldEIO extends GuiTextField {
|
||||
|
||||
@Override
|
||||
public boolean textboxKeyTyped(char c, int key) {
|
||||
if(filter == null || filter.passesFilter(c) || isSpecialChar(c, key)) {
|
||||
if(filter == null || filter.passesFilter(this, c) || isSpecialChar(c, key)) {
|
||||
return super.textboxKeyTyped(c, key);
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -16,7 +16,7 @@ import crazypants.util.EntityUtil;
|
||||
|
||||
public class PlayerTeleportHandler {
|
||||
|
||||
static PlayerTeleportHandler instance = new PlayerTeleportHandler();
|
||||
public static final PlayerTeleportHandler instance = new PlayerTeleportHandler();
|
||||
|
||||
List<TeleportAction> queue = new ArrayList<TeleportAction>();
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ public class PacketTravelEvent implements IMessage, IMessageHandler<PacketTravel
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean doServerTeleport(Entity toTp, int x, int y, int z, int powerUse, boolean conserveMotion, TravelSource source) {
|
||||
public static void doServerTeleport(Entity toTp, int x, int y, int z, int powerUse, boolean conserveMotion, TravelSource source) {
|
||||
EntityPlayer player = toTp instanceof EntityPlayer ? (EntityPlayer) toTp : null;
|
||||
toTp.worldObj.playSoundEffect(toTp.posX, toTp.posY, toTp.posZ, source.sound, 1.0F, 1.0F);
|
||||
|
||||
@@ -104,7 +104,5 @@ public class PacketTravelEvent implements IMessage, IMessageHandler<PacketTravel
|
||||
toTp.setCurrentItemOrArmor(0, item);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -32,18 +32,6 @@ import crazypants.util.Lang;
|
||||
|
||||
public class GuiTelePad extends GuiContainerBase implements IToggleableGui {
|
||||
|
||||
private class CoordCharFilter implements ICharFilter {
|
||||
private final TextFieldEIO f;
|
||||
public CoordCharFilter(TextFieldEIO f) {
|
||||
this.f = f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean passesFilter(char c) {
|
||||
return (c== '-' && Strings.isNullOrEmpty(f.getText())) || TextFieldEIO.FILTER_NUMERIC.passesFilter(c);
|
||||
}
|
||||
}
|
||||
|
||||
private static final int ID_SWITCH_BUTTON = 95;
|
||||
private static final int ID_TELEPORT_BUTTON = 96;
|
||||
|
||||
@@ -53,7 +41,7 @@ public class GuiTelePad extends GuiContainerBase implements IToggleableGui {
|
||||
private World world;
|
||||
private TileTelePad te;
|
||||
|
||||
private TextFieldEIO xTF, yTF, zTF;
|
||||
private TextFieldEIO xTF, yTF, zTF, dimTF;
|
||||
|
||||
private int powerX = 8;
|
||||
private int powerY = 9;
|
||||
@@ -89,17 +77,19 @@ public class GuiTelePad extends GuiContainerBase implements IToggleableGui {
|
||||
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
|
||||
int x = 38;
|
||||
int y = 10;
|
||||
xTF = new TextFieldEIO(fr, x, y, xSize - x * 2, 16);
|
||||
yTF = new TextFieldEIO(fr, x, y + xTF.height + 2, xSize - x * 2, 16);
|
||||
zTF = new TextFieldEIO(fr, x, y + (xTF.height * 2) + 4, xSize - x * 2, 16);
|
||||
int x = 42;
|
||||
int y = 8;
|
||||
xTF = new TextFieldEIO(fr, x, y, xSize - x * 2, 12, TextFieldEIO.FILTER_NUMERIC);
|
||||
yTF = new TextFieldEIO(fr, x, y + xTF.height + 2, xSize - x * 2, 12, TextFieldEIO.FILTER_NUMERIC);
|
||||
zTF = new TextFieldEIO(fr, x, y + (xTF.height * 2) + 4, xSize - x * 2, 12, TextFieldEIO.FILTER_NUMERIC);
|
||||
dimTF = new TextFieldEIO(fr, x, y + (xTF.height * 3) + 6, xSize - x * 2, 12, TextFieldEIO.FILTER_NUMERIC);
|
||||
|
||||
xTF.setCharFilter(new CoordCharFilter(xTF)).setText(Integer.toString(te.getX()));
|
||||
yTF.setCharFilter(new CoordCharFilter(yTF)).setText(Integer.toString(te.getY()));
|
||||
zTF.setCharFilter(new CoordCharFilter(zTF)).setText(Integer.toString(te.getZ()));
|
||||
xTF.setText(Integer.toString(te.getX()));
|
||||
yTF.setText(Integer.toString(te.getY()));
|
||||
zTF.setText(Integer.toString(te.getZ()));
|
||||
dimTF.setText(Integer.toString(te.getTargetDim()));
|
||||
|
||||
textFields.addAll(Lists.newArrayList(xTF, yTF, zTF));
|
||||
textFields.addAll(Lists.newArrayList(xTF, yTF, zTF, dimTF));
|
||||
|
||||
switchButton = new ToggleTravelButton(this, ID_SWITCH_BUTTON, SWITCH_X, SWITCH_Y, IconEIO.IO_WHATSIT);
|
||||
switchButton.setToolTip(Lang.localize("gui.telepad.configure.travel"));
|
||||
@@ -142,24 +132,29 @@ public class GuiTelePad extends GuiContainerBase implements IToggleableGui {
|
||||
@Override
|
||||
protected void keyTyped(char par1, int par2) {
|
||||
super.keyTyped(par1, par2);
|
||||
for (TextFieldEIO tf : textFields) {
|
||||
if("-".equals(tf.getText())) {
|
||||
tf.setText("");
|
||||
}
|
||||
}
|
||||
updateCoords();
|
||||
}
|
||||
|
||||
private void updateCoords() {
|
||||
BlockCoord bc = new BlockCoord(xTF.getText(), yTF.getText(), zTF.getText());
|
||||
if(bc.x != te.getX() || bc.y != te.getY() || bc.z != te.getZ()) {
|
||||
BlockCoord bc = new BlockCoord(getIntFromTextBox(xTF), getIntFromTextBox(yTF), getIntFromTextBox(zTF));
|
||||
int targetDim = getIntFromTextBox(dimTF);
|
||||
if(bc.x != te.getX() || bc.y != te.getY() || bc.z != te.getZ() || targetDim != te.getTargetDim()) {
|
||||
te.setX(bc.x);
|
||||
te.setY(bc.y);
|
||||
te.setZ(bc.z);
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketUpdateCoords(te, bc));
|
||||
te.setTargetDim(targetDim);
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketUpdateCoords(te, bc, targetDim));
|
||||
}
|
||||
}
|
||||
|
||||
private int getIntFromTextBox(TextFieldEIO tf) {
|
||||
String text = tf.getText();
|
||||
if("".equals(text) || "-".equals(text)) {
|
||||
return 0;
|
||||
}
|
||||
return Integer.parseInt(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) {
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
@@ -176,10 +171,10 @@ public class GuiTelePad extends GuiContainerBase implements IToggleableGui {
|
||||
|
||||
FontRenderer fnt = getFontRenderer();
|
||||
|
||||
String[] text = { "X", "Y", "Z" };
|
||||
String[] text = { "X", "Y", "Z", "DIM" };
|
||||
for (int i = 0; i < text.length; i++) {
|
||||
GuiTextField f = textFields.get(i);
|
||||
fnt.drawString(text[i], f.xPosition - (fnt.getStringWidth(text[i]) / 2) - 6, f.yPosition + ((f.height - fnt.FONT_HEIGHT) / 2), 0x000000);
|
||||
fnt.drawString(text[i], f.xPosition - (fnt.getStringWidth(text[i]) / 2) - 10, f.yPosition + ((f.height - fnt.FONT_HEIGHT) / 2) + 1, 0x000000);
|
||||
}
|
||||
|
||||
Entity e = te.getCurrentTarget();
|
||||
|
||||
@@ -93,12 +93,24 @@ public class ItemCoordSelector extends Item implements IResourceTooltipProvider
|
||||
if(tp.canBlockBeAccessed(player)) {
|
||||
BlockCoord bc = getCoords(stack);
|
||||
BlockCoord cur = new BlockCoord(tp.getX(), tp.getY(), tp.getZ());
|
||||
int dim = getDimension(stack);
|
||||
int curDim = tp.getTargetDim();
|
||||
|
||||
if(!bc.equals(cur)) {
|
||||
tp.setCoords(bc);
|
||||
if(!world.isRemote) {
|
||||
player.addChatMessage(new ChatComponentText(Lang.localize("itemCoordSelector.chat.setCoords", bc.chatString())));
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
if(dim != curDim) {
|
||||
tp.setTargetDim(dim);
|
||||
if(!world.isRemote) {
|
||||
player.addChatMessage(new ChatComponentText(Lang.localize("itemCoordSelector.chat.setDimension", EnumChatFormatting.GREEN.toString(), Integer.toString(dim))));
|
||||
}
|
||||
}
|
||||
|
||||
if (bc.equals(cur) && dim == curDim) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
@@ -106,7 +118,6 @@ public class ItemCoordSelector extends Item implements IResourceTooltipProvider
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(world.isRemote) {
|
||||
sendItemUsePacket(stack, player, world, x, y, z, side, hitX, hitY, hitZ);
|
||||
}
|
||||
@@ -137,14 +148,25 @@ public class ItemCoordSelector extends Item implements IResourceTooltipProvider
|
||||
ForgeDirection dir = ForgeDirection.VALID_DIRECTIONS[mop.sideHit];
|
||||
bc = bc.getLocation(dir);
|
||||
}
|
||||
|
||||
|
||||
int dim = world.provider.dimensionId;
|
||||
int curDim = getDimension(stack);
|
||||
|
||||
boolean changed = false;
|
||||
|
||||
if(!bc.equals(onStack)) {
|
||||
setCoords(stack, bc);
|
||||
onCoordsChanged(player, bc);
|
||||
return true;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (dim != curDim) {
|
||||
setDimension(stack, world);
|
||||
onDimensionChanged(player, getDimension(stack));
|
||||
changed = true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return changed;
|
||||
}
|
||||
|
||||
private void sendItemUsePacket(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
|
||||
@@ -157,14 +179,28 @@ public class ItemCoordSelector extends Item implements IResourceTooltipProvider
|
||||
player.addChatMessage(new ChatComponentText(Lang.localize("itemCoordSelector.chat.newCoords", bc.chatString())));
|
||||
}
|
||||
}
|
||||
|
||||
private void onDimensionChanged(EntityPlayer player, int dim) {
|
||||
if(!player.worldObj.isRemote) {
|
||||
player.addChatMessage(new ChatComponentText(Lang.localize("itemCoordSelector.chat.newDimension", EnumChatFormatting.GREEN.toString(), Integer.toString(dim))));
|
||||
}
|
||||
}
|
||||
|
||||
public void setCoords(ItemStack stack, BlockCoord bc) {
|
||||
stack.stackTagCompound.setBoolean("default", false);
|
||||
bc.writeToNBT(stack.stackTagCompound);
|
||||
}
|
||||
|
||||
public void setDimension(ItemStack stack, World world) {
|
||||
stack.stackTagCompound.setInteger("dimension", world.provider.dimensionId);
|
||||
}
|
||||
|
||||
public BlockCoord getCoords(ItemStack stack) {
|
||||
return new BlockCoord().readFromNBT(stack.stackTagCompound);
|
||||
return BlockCoord.readFromNBT(stack.stackTagCompound);
|
||||
}
|
||||
|
||||
public int getDimension(ItemStack stack) {
|
||||
return stack.stackTagCompound.getInteger("dimension");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,17 +13,18 @@ public class PacketUpdateCoords extends MessageTileEntity<TileTelePad> implement
|
||||
super();
|
||||
}
|
||||
|
||||
private int targetX, targetY, targetZ;
|
||||
private int targetX, targetY, targetZ, targetDim;
|
||||
|
||||
public PacketUpdateCoords(TileTelePad te, int x, int y, int z) {
|
||||
public PacketUpdateCoords(TileTelePad te, int x, int y, int z, int targetDim) {
|
||||
super(te);
|
||||
this.targetX = x;
|
||||
this.targetY = y;
|
||||
this.targetZ = z;
|
||||
this.targetDim = targetDim;
|
||||
}
|
||||
|
||||
public PacketUpdateCoords(TileTelePad te, BlockCoord bc) {
|
||||
this(te, bc.x, bc.y, bc.z);
|
||||
public PacketUpdateCoords(TileTelePad te, BlockCoord bc, int targetDim) {
|
||||
this(te, bc.x, bc.y, bc.z, targetDim);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -32,6 +33,7 @@ public class PacketUpdateCoords extends MessageTileEntity<TileTelePad> implement
|
||||
buf.writeInt(targetX);
|
||||
buf.writeInt(targetY);
|
||||
buf.writeInt(targetZ);
|
||||
buf.writeInt(targetDim);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -40,6 +42,7 @@ public class PacketUpdateCoords extends MessageTileEntity<TileTelePad> implement
|
||||
targetX = buf.readInt();
|
||||
targetY = buf.readInt();
|
||||
targetZ = buf.readInt();
|
||||
targetDim = buf.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -49,6 +52,7 @@ public class PacketUpdateCoords extends MessageTileEntity<TileTelePad> implement
|
||||
te.setX(message.targetX);
|
||||
te.setY(message.targetY);
|
||||
te.setZ(message.targetZ);
|
||||
te.setTargetDim(message.targetDim);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -7,14 +7,17 @@ import java.util.Queue;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cofh.api.energy.EnergyStorage;
|
||||
|
||||
@@ -32,6 +35,8 @@ import crazypants.enderio.machine.PacketPowerStorage;
|
||||
import crazypants.enderio.machine.PacketProgress;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.enderio.power.IInternalPowerReceiver;
|
||||
import crazypants.enderio.rail.PacketTeleportEffects;
|
||||
import crazypants.enderio.rail.TeleporterEIO;
|
||||
import crazypants.enderio.teleport.TravelController;
|
||||
import crazypants.enderio.teleport.anchor.TileTravelAnchor;
|
||||
import crazypants.enderio.teleport.packet.PacketTravelEvent;
|
||||
@@ -53,7 +58,8 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
|
||||
private boolean autoUpdate = false;
|
||||
|
||||
private BlockCoord target = new BlockCoord();
|
||||
|
||||
private int targetDim = Integer.MIN_VALUE;
|
||||
|
||||
private int lastSyncPowerStored;
|
||||
|
||||
private Queue<Entity> toTeleport = Queues.newArrayDeque();
|
||||
@@ -74,10 +80,20 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
|
||||
if(master != null && master.isInvalid()) {
|
||||
master.breakNetwork();
|
||||
}
|
||||
if(autoUpdate && worldObj != null) {
|
||||
|
||||
if (worldObj == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(autoUpdate) {
|
||||
updateConnectedState(true);
|
||||
autoUpdate = false;
|
||||
}
|
||||
|
||||
if(targetDim == Integer.MIN_VALUE) {
|
||||
targetDim = worldObj.provider.dimensionId;
|
||||
}
|
||||
|
||||
if(worldObj.isRemote) {
|
||||
if(active()) {
|
||||
if(activeSound == null) {
|
||||
@@ -251,6 +267,7 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
|
||||
super.writeCustomNBT(root);
|
||||
energy.writeToNBT(root);
|
||||
target.writeToNBT(root);
|
||||
root.setInteger("targetDim", targetDim);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -258,6 +275,7 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
|
||||
super.readCustomNBT(root);
|
||||
energy.readFromNBT(root);
|
||||
target = BlockCoord.readFromNBT(root);
|
||||
targetDim = root.getInteger("targetDim");
|
||||
autoUpdate = true;
|
||||
}
|
||||
|
||||
@@ -283,7 +301,12 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
|
||||
}
|
||||
|
||||
private int calculateTeleportPower() {
|
||||
return this.maxPower = new BlockCoord(this).distance(target) * 1000;
|
||||
if (worldObj.provider.dimensionId == targetDim) {
|
||||
this.maxPower = new BlockCoord(this).distance(target) * 1000;
|
||||
} else {
|
||||
this.maxPower = 100000;
|
||||
}
|
||||
return this.maxPower;
|
||||
}
|
||||
|
||||
public boolean active() {
|
||||
@@ -351,6 +374,11 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
|
||||
}
|
||||
return target.z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTargetDim() {
|
||||
return targetDim;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITelePad setX(int x) {
|
||||
@@ -378,6 +406,15 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITelePad setTargetDim(int dimID) {
|
||||
if (inNetwork()) {
|
||||
targetDim = dimID;
|
||||
return master;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCoords(BlockCoord coords) {
|
||||
@@ -457,15 +494,31 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
|
||||
|
||||
private boolean teleport(Entity entity) {
|
||||
entity.getEntityData().setBoolean(TELEPORTING_KEY, false);
|
||||
if(entity.worldObj.isRemote) {
|
||||
return entity.worldObj.isRemote ? clientTeleport(entity) : serverTeleport(entity);
|
||||
}
|
||||
|
||||
private boolean clientTeleport(Entity entity) {
|
||||
if(entity.worldObj.provider.dimensionId == targetDim) {
|
||||
return TravelController.instance.doClientTeleport(entity, target, TravelSource.TELEPAD, 0, false);
|
||||
} else {
|
||||
if(PacketTravelEvent.doServerTeleport(entity, target.x, target.y, target.z, 0, false, TravelSource.TELEPAD)) {
|
||||
dequeueTeleport(entity);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean serverTeleport(Entity entity) {
|
||||
dequeueTeleport(entity);
|
||||
if(entity.worldObj.provider.dimensionId != targetDim) {
|
||||
MinecraftServer server = MinecraftServer.getServer();
|
||||
int currentDim = entity.worldObj.provider.dimensionId;
|
||||
if(entity instanceof EntityPlayer) {
|
||||
EntityPlayerMP player = (EntityPlayerMP) entity;
|
||||
server.getConfigurationManager().transferPlayerToDimension(player, targetDim, new TeleporterEIO(server.worldServerForDimension(targetDim)));
|
||||
} else {
|
||||
WorldServer toDim = server.worldServerForDimension(targetDim);
|
||||
server.getConfigurationManager().transferEntityToWorld(entity, 0, server.worldServerForDimension(currentDim), toDim, new TeleporterEIO(toDim));
|
||||
}
|
||||
}
|
||||
PacketTravelEvent.doServerTeleport(entity, target.x, target.y, target.z, 0, false, TravelSource.TELEPAD);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* ITravelAccessable overrides */
|
||||
|
||||
Reference in new issue
Block a user