mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-22 13:10:13 +00:00
Lots of telepad function/GUI work, add some rudimentary rendering
This commit is contained in:
1 parent
2cb28a72eb
commit
0c105c7c78
21 files changed
+429
-124
No files matched your search
@@ -129,6 +129,7 @@ import crazypants.enderio.teleport.TravelController;
|
||||
import crazypants.enderio.teleport.anchor.BlockTravelAnchor;
|
||||
import crazypants.enderio.teleport.anchor.TileTravelAnchor;
|
||||
import crazypants.enderio.teleport.anchor.TravelEntitySpecialRenderer;
|
||||
import crazypants.enderio.teleport.telepad.TeleportEntityRenderHandler;
|
||||
import crazypants.render.IconUtil;
|
||||
|
||||
public class ClientProxy extends CommonProxy {
|
||||
@@ -423,6 +424,8 @@ public class ClientProxy extends CommonProxy {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(new TeleportEntityRenderHandler());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -56,7 +56,7 @@ public abstract class AbstractMachineBlock<T extends AbstractMachineEntity> exte
|
||||
PacketHandler.INSTANCE.registerMessage(PacketIoMode.class, PacketIoMode.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketItemBuffer.class, PacketItemBuffer.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketPowerStorage.class, PacketPowerStorage.class, PacketHandler.nextID(), Side.CLIENT);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketCurrentTaskProgress.class,PacketCurrentTaskProgress.class,PacketHandler.nextID(),Side.CLIENT);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketProgress.class,PacketProgress.class,PacketHandler.nextID(),Side.CLIENT);
|
||||
}
|
||||
|
||||
protected AbstractMachineBlock(ModObject mo, Class<T> teClass, Material mat) {
|
||||
|
||||
@@ -24,6 +24,7 @@ import crazypants.enderio.TileEntityEio;
|
||||
import crazypants.enderio.api.redstone.IRedstoneConnectable;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.util.BlockCoord;
|
||||
import crazypants.util.IProgressTile;
|
||||
import crazypants.util.InventoryWrapper;
|
||||
import crazypants.util.ItemUtil;
|
||||
import crazypants.util.Lang;
|
||||
|
||||
@@ -6,12 +6,14 @@ import java.util.Random;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import crazypants.enderio.machine.IMachineRecipe.ResultStack;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.enderio.power.IInternalPowerReceiver;
|
||||
import crazypants.util.IProgressTile;
|
||||
|
||||
public abstract class AbstractPoweredTaskEntity extends AbstractPowerConsumerEntity implements IInternalPowerReceiver {
|
||||
public abstract class AbstractPoweredTaskEntity extends AbstractPowerConsumerEntity implements IInternalPowerReceiver, IProgressTile {
|
||||
|
||||
protected IPoweredTask currentTask = null;
|
||||
protected IMachineRecipe lastCompletedRecipe;
|
||||
@@ -19,8 +21,8 @@ public abstract class AbstractPoweredTaskEntity extends AbstractPowerConsumerEnt
|
||||
protected final Random random = new Random();
|
||||
|
||||
protected int ticksSinceCheckedRecipe = 0;
|
||||
protected boolean startFailed = false;
|
||||
|
||||
protected boolean startFailed = false;
|
||||
|
||||
protected int lastProgressScaled = -1;
|
||||
protected int ticksSinceLastProgressUpdate;
|
||||
|
||||
@@ -71,6 +73,16 @@ public abstract class AbstractPoweredTaskEntity extends AbstractPowerConsumerEnt
|
||||
return currentTask == null ? 0 : currentTask.getProgress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getTileEntity() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProgress(float progress) {
|
||||
this.currentTask = progress < 0 ? null : new PoweredTaskProgress(progress);
|
||||
}
|
||||
|
||||
public IPoweredTask getCurrentTask() {
|
||||
return currentTask;
|
||||
}
|
||||
@@ -81,21 +93,21 @@ public abstract class AbstractPoweredTaskEntity extends AbstractPowerConsumerEnt
|
||||
}
|
||||
return lastCompletedRecipe.getExperienceForOutput(output);
|
||||
}
|
||||
|
||||
|
||||
public boolean getRedstoneChecksPassed() {
|
||||
return redstoneCheckPassed;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean processTasks(boolean redstoneChecksPassed) {
|
||||
|
||||
if(!redstoneChecksPassed) {
|
||||
|
||||
if(!redstoneChecksPassed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean requiresClientSync = false;
|
||||
// Process any current items
|
||||
requiresClientSync |= checkProgress(redstoneChecksPassed);
|
||||
requiresClientSync |= checkProgress(redstoneChecksPassed);
|
||||
|
||||
if(currentTask != null || !hasPower() || !hasInputStacks()) {
|
||||
return requiresClientSync;
|
||||
@@ -113,18 +125,18 @@ public abstract class AbstractPoweredTaskEntity extends AbstractPowerConsumerEnt
|
||||
// Then see if we need to start a new one
|
||||
IMachineRecipe nextRecipe = canStartNextTask(chance);
|
||||
if(nextRecipe != null) {
|
||||
boolean started = startNextTask(nextRecipe, chance);
|
||||
sendTaskProgressPacket();
|
||||
startFailed = !started;
|
||||
boolean started = startNextTask(nextRecipe, chance);
|
||||
sendTaskProgressPacket();
|
||||
startFailed = !started;
|
||||
} else {
|
||||
startFailed = true;
|
||||
}
|
||||
|
||||
|
||||
return requiresClientSync;
|
||||
}
|
||||
|
||||
protected void sendTaskProgressPacket() {
|
||||
PacketHandler.sendToAllAround(new PacketCurrentTaskProgress(this), this);
|
||||
PacketHandler.sendToAllAround(new PacketProgress(this), this);
|
||||
ticksSinceLastProgressUpdate = 0;
|
||||
}
|
||||
|
||||
@@ -140,13 +152,13 @@ public abstract class AbstractPoweredTaskEntity extends AbstractPowerConsumerEnt
|
||||
taskComplete();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
int curScaled = getProgressScaled(16);
|
||||
if(++ticksSinceLastProgressUpdate >= 20 || curScaled != lastProgressScaled) {
|
||||
sendTaskProgressPacket();
|
||||
lastProgressScaled = curScaled;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -156,7 +168,7 @@ public abstract class AbstractPoweredTaskEntity extends AbstractPowerConsumerEnt
|
||||
|
||||
public int usePower(int wantToUse) {
|
||||
int used = Math.min(getEnergyStored(), wantToUse);
|
||||
setEnergyStored( Math.max(0, getEnergyStored() - used));
|
||||
setEnergyStored(Math.max(0, getEnergyStored() - used));
|
||||
if(currentTask != null) {
|
||||
currentTask.update(used);
|
||||
}
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
package crazypants.enderio.machine;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.network.MessageTileEntity;
|
||||
|
||||
public class PacketCurrentTaskProgress extends MessageTileEntity<AbstractPoweredTaskEntity> implements IMessageHandler<PacketCurrentTaskProgress, IMessage> {
|
||||
|
||||
private float progress;
|
||||
|
||||
public PacketCurrentTaskProgress() {
|
||||
}
|
||||
|
||||
public PacketCurrentTaskProgress(AbstractPoweredTaskEntity tile) {
|
||||
super(tile);
|
||||
progress = -1;
|
||||
if(tile.getCurrentTask() != null) {
|
||||
progress = tile.getCurrentTask().getProgress();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
super.toBytes(buf);
|
||||
buf.writeFloat(progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
super.fromBytes(buf);
|
||||
progress = buf.readFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketCurrentTaskProgress message, MessageContext ctx) {
|
||||
AbstractPoweredTaskEntity tile = message.getTileEntity(EnderIO.proxy.getClientWorld());
|
||||
if(tile != null) {
|
||||
if(message.progress < 0) {
|
||||
tile.currentTask = null;
|
||||
} else {
|
||||
tile.currentTask = new PoweredTaskProgress(message.progress);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package crazypants.enderio.machine;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.network.MessageTileEntity;
|
||||
import crazypants.util.IProgressTile;
|
||||
|
||||
public class PacketProgress extends MessageTileEntity<TileEntity> implements IMessageHandler<PacketProgress, IMessage> {
|
||||
|
||||
private float progress;
|
||||
|
||||
public PacketProgress() {
|
||||
}
|
||||
|
||||
public PacketProgress(IProgressTile tile) {
|
||||
super(tile.getTileEntity());
|
||||
progress = tile.getProgress();
|
||||
if (progress == 0) {
|
||||
progress = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
super.toBytes(buf);
|
||||
buf.writeFloat(progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
super.fromBytes(buf);
|
||||
progress = buf.readFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketProgress message, MessageContext ctx) {
|
||||
TileEntity tile = message.getTileEntity(EnderIO.proxy.getClientWorld());
|
||||
if(tile instanceof IProgressTile) {
|
||||
((IProgressTile) tile).setProgress(message.progress);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -175,17 +175,15 @@ public class GuiCapBank extends GuiContainerBase {
|
||||
x = inputX - 24;
|
||||
y = inputY;
|
||||
maxInputTF = new TextFieldEIO(fontRenderer, x, y, 68, 16);
|
||||
maxInputTF.setCanLoseFocus(true);
|
||||
maxInputTF.setMaxStringLength(10);
|
||||
maxInputTF.setFocused(false);
|
||||
|
||||
maxInputTF.setCharFilter(TextFieldEIO.FILTER_NUMERIC);
|
||||
|
||||
x = outputX - 24;
|
||||
y = outputY;
|
||||
maxOutputTF = new TextFieldEIO(fontRenderer, x, y, 68, 16);
|
||||
maxOutputTF.setCanLoseFocus(true);
|
||||
maxOutputTF.setMaxStringLength(10);
|
||||
maxOutputTF.setFocused(true);
|
||||
|
||||
maxOutputTF.setCharFilter(TextFieldEIO.FILTER_NUMERIC);
|
||||
|
||||
textFields.add(maxInputTF);
|
||||
textFields.add(maxOutputTF);
|
||||
}
|
||||
@@ -288,6 +286,7 @@ public class GuiCapBank extends GuiContainerBase {
|
||||
super.drawGuiContainerBackgroundLayer(par1, par2, par3);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void drawHoveringText(List par1List, int par2, int par3, FontRenderer font) {
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
|
||||
@@ -619,10 +619,8 @@ public class TravelController {
|
||||
if(MinecraftForge.EVENT_BUS.post(evt)) {
|
||||
return false;
|
||||
}
|
||||
bc.x = evt.targetX;
|
||||
bc.y = evt.targetY;
|
||||
bc.z = evt.targetZ;
|
||||
|
||||
bc = new BlockCoord(evt.targetX, evt.targetY, evt.targetZ);
|
||||
PacketTravelEvent p = new PacketTravelEvent(entity, bc.x, bc.y, bc.z, powerUse, conserveMomentum, source);
|
||||
PacketHandler.INSTANCE.sendToServer(p);
|
||||
return true;
|
||||
|
||||
@@ -83,6 +83,8 @@ public class PacketTravelEvent implements IMessage, IMessageHandler<PacketTravel
|
||||
|
||||
if(player != null) {
|
||||
player.setPositionAndUpdate(x + 0.5, y + 1.1, z + 0.5);
|
||||
} else {
|
||||
toTp.setPosition(x, y, z);
|
||||
}
|
||||
|
||||
toTp.worldObj.playSoundEffect(x, y, z, "mob.endermen.portal", 1.0F, 1.0F);
|
||||
|
||||
@@ -31,6 +31,8 @@ public class BlockTelePad extends BlockTravelAnchor {
|
||||
BlockTelePad ret = new BlockTelePad();
|
||||
PacketHandler.INSTANCE.registerMessage(PacketOpenServerGui.class, PacketOpenServerGui.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketUpdateCoords.class, PacketUpdateCoords.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketTeleport.class, PacketTeleport.class, PacketHandler.nextID(), Side.SERVER);
|
||||
PacketHandler.INSTANCE.registerMessage(PacketTeleport.class, PacketTeleport.class, PacketHandler.nextID(), Side.CLIENT);
|
||||
ret.init();
|
||||
return ret;
|
||||
}
|
||||
@@ -82,7 +84,6 @@ public class BlockTelePad extends BlockTravelAnchor {
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if(te instanceof TileTelePad) {
|
||||
TileTelePad tp = (TileTelePad) te;
|
||||
System.out.println(tp.inNetwork() + " " + tp);
|
||||
if (tp.inNetwork()) {
|
||||
if (!tp.isMaster()) {
|
||||
TileTelePad master = tp.getMaster();
|
||||
|
||||
@@ -16,12 +16,12 @@ public class ContainerTelePad extends Container {
|
||||
// add players inventory
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
for (int j = 0; j < 9; ++j) {
|
||||
addSlotToContainer(new Slot(playerInv, j + i * 9 + 9, 8 + j * 18, 103 + i * 18));
|
||||
addSlotToContainer(new Slot(playerInv, j + i * 9 + 9, 8 + j * 18, 118 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
addSlotToContainer(new Slot(playerInv, i, 8 + i * 18, 161));
|
||||
addSlotToContainer(new Slot(playerInv, i, 8 + i * 18, 176));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
package crazypants.enderio.teleport.telepad;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.util.List;
|
||||
|
||||
import joptsimple.internal.Strings;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
@@ -14,12 +19,13 @@ import com.google.common.collect.Lists;
|
||||
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.GuiHandler;
|
||||
import crazypants.enderio.gui.IconButtonEIO;
|
||||
import crazypants.enderio.gui.IconEIO;
|
||||
import crazypants.enderio.gui.TextFieldEIO;
|
||||
import crazypants.enderio.gui.TextFieldEIO.ICharFilter;
|
||||
import crazypants.enderio.machine.power.PowerDisplayUtil;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.gui.GuiContainerBase;
|
||||
import crazypants.gui.GuiToolTip;
|
||||
import crazypants.render.RenderUtil;
|
||||
import crazypants.util.BlockCoord;
|
||||
import crazypants.util.Lang;
|
||||
@@ -38,8 +44,8 @@ public class GuiTelePad extends GuiContainerBase implements IToggleableGui {
|
||||
}
|
||||
}
|
||||
|
||||
private static final int ID_SWITCH_BUTTON = 99;
|
||||
private static final int ID_TELEPORT_BUTTON = 100;
|
||||
private static final int ID_SWITCH_BUTTON = 95;
|
||||
private static final int ID_TELEPORT_BUTTON = 96;
|
||||
|
||||
ToggleTravelButton switchButton;
|
||||
GuiButton teleportButton;
|
||||
@@ -49,17 +55,41 @@ public class GuiTelePad extends GuiContainerBase implements IToggleableGui {
|
||||
|
||||
private TextFieldEIO xTF, yTF, zTF;
|
||||
|
||||
private int powerX = 8;
|
||||
private int powerY = 9;
|
||||
private int powerScale = 100;
|
||||
|
||||
private int progressX = 26;
|
||||
private int progressY = 90;
|
||||
private int progressScale = 124;
|
||||
|
||||
public static int SWITCH_X = 155, SWITCH_Y = 5;
|
||||
|
||||
public GuiTelePad(InventoryPlayer playerInv, TileTelePad te, World world) {
|
||||
super(new ContainerTelePad(playerInv));
|
||||
this.world = world;
|
||||
this.te = te;
|
||||
ySize += 19;
|
||||
ySize += 34;
|
||||
|
||||
addToolTip(new GuiToolTip(new Rectangle(powerX, powerY, 10, powerScale), "") {
|
||||
@Override
|
||||
protected void updateText() {
|
||||
text.clear();
|
||||
updatePowerBarTooltip(text);
|
||||
}
|
||||
});
|
||||
|
||||
addToolTip(new GuiToolTip(new Rectangle(progressX, progressY, progressScale, 10), "") {
|
||||
@Override
|
||||
protected void updateText() {
|
||||
text.clear();
|
||||
text.add(Math.round(GuiTelePad.this.te.getProgress() * 100) + "%");
|
||||
}
|
||||
});
|
||||
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
|
||||
int x = 24;
|
||||
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);
|
||||
@@ -75,6 +105,20 @@ public class GuiTelePad extends GuiContainerBase implements IToggleableGui {
|
||||
switchButton.setToolTip(Lang.localize("gui.telepad.configure.travel"));
|
||||
}
|
||||
|
||||
private String getPowerOutputLabel() {
|
||||
return StatCollector.translateToLocal("enderio.gui.max");
|
||||
}
|
||||
|
||||
protected int getPowerOutputValue() {
|
||||
return 500;
|
||||
}
|
||||
|
||||
protected void updatePowerBarTooltip(List<String> text) {
|
||||
text.add(getPowerOutputLabel() + PowerDisplayUtil.formatPower(getPowerOutputValue()) + " " + PowerDisplayUtil.abrevation()
|
||||
+ PowerDisplayUtil.perTickStr());
|
||||
text.add(PowerDisplayUtil.formatStoredPower(te.getEnergyStored(), te.getMaxEnergyStored()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
@@ -84,7 +128,7 @@ public class GuiTelePad extends GuiContainerBase implements IToggleableGui {
|
||||
int width = getFontRenderer().getStringWidth(text) + 10;
|
||||
|
||||
int x = guiLeft + (xSize / 2) - (width / 2);
|
||||
int y = guiTop + 70;
|
||||
int y = guiTop + 65;
|
||||
|
||||
teleportButton = new GuiButton(ID_TELEPORT_BUTTON, x, y, width, 20, text);
|
||||
addButton(teleportButton);
|
||||
@@ -119,7 +163,12 @@ public class GuiTelePad extends GuiContainerBase implements IToggleableGui {
|
||||
int sy = (height - ySize) / 2;
|
||||
|
||||
drawTexturedModalRect(sx, sy, 0, 0, this.xSize, this.ySize);
|
||||
|
||||
|
||||
int powerScaled = te.getPowerScaled(powerScale);
|
||||
drawTexturedModalRect(sx + powerX, sy + powerY + powerScale - powerScaled, xSize, 0, 10, powerScaled);
|
||||
int progressScaled = te.getProgressScaled(progressScale);
|
||||
drawTexturedModalRect(sx + progressX, sy + progressY, 0, ySize, progressScaled, 10);
|
||||
|
||||
FontRenderer fnt = getFontRenderer();
|
||||
|
||||
String[] text = { "X", "Y", "Z" };
|
||||
@@ -128,6 +177,12 @@ public class GuiTelePad extends GuiContainerBase implements IToggleableGui {
|
||||
fnt.drawString(text[i], f.xPosition - (fnt.getStringWidth(text[i]) / 2) - 6, f.yPosition + ((f.height - fnt.FONT_HEIGHT) / 2), 0x000000);
|
||||
}
|
||||
|
||||
Entity e = te.getCurrentTarget();
|
||||
if(e != null) {
|
||||
String name = e.getCommandSenderName();
|
||||
fnt.drawString(name, sx + xSize / 2 - fnt.getStringWidth(name) / 2, sy + progressY + fnt.FONT_HEIGHT + 6, 0x000000);
|
||||
}
|
||||
|
||||
super.drawGuiContainerBackgroundLayer(p_146976_1_, p_146976_2_, p_146976_3_);
|
||||
}
|
||||
|
||||
@@ -142,7 +197,7 @@ public class GuiTelePad extends GuiContainerBase implements IToggleableGui {
|
||||
super.actionPerformed(button);
|
||||
|
||||
if (button.id == ID_TELEPORT_BUTTON) {
|
||||
te.teleportSpecific(mc.thePlayer);
|
||||
te.teleportAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,7 @@ public class ItemCoordSelector extends Item implements IResourceTooltipProvider
|
||||
BlockCoord bc = getCoords(stack);
|
||||
BlockCoord cur = new BlockCoord(tp.getX(), tp.getY(), tp.getZ());
|
||||
if(!bc.equals(cur)) {
|
||||
tp.setCoords(getCoords(stack));
|
||||
tp.setCoords(bc);
|
||||
if(!world.isRemote) {
|
||||
player.addChatMessage(new ChatComponentText(Lang.localize("itemCoordSelector.chat.setCoords", bc.chatString())));
|
||||
}
|
||||
@@ -119,7 +119,7 @@ public class ItemCoordSelector extends Item implements IResourceTooltipProvider
|
||||
Vector3d headVec = Util.getEyePositionEio(player);
|
||||
Vec3 start = headVec.getVec3();
|
||||
Vec3 lookVec = player.getLook(1.0F);
|
||||
double reach = 200;
|
||||
double reach = 500;
|
||||
headVec.add(lookVec.xCoord * reach, lookVec.yCoord * reach, lookVec.zCoord * reach);
|
||||
MovingObjectPosition mop = world.rayTraceBlocks(start, headVec.getVec3());
|
||||
if (mop == null) {
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package crazypants.enderio.teleport.telepad;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.network.MessageTileEntity;
|
||||
|
||||
public class PacketTeleport extends MessageTileEntity<TileTelePad> implements IMessageHandler<PacketTeleport, IMessage> {
|
||||
|
||||
enum Type {
|
||||
BEGIN,
|
||||
END
|
||||
}
|
||||
|
||||
public PacketTeleport() {
|
||||
super();
|
||||
}
|
||||
|
||||
private int entityId;
|
||||
private Type type;
|
||||
|
||||
public PacketTeleport(Type type, TileTelePad te, int entityId) {
|
||||
super(te);
|
||||
this.entityId = entityId;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
super.toBytes(buf);
|
||||
buf.writeInt(entityId);
|
||||
buf.writeInt(type.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
super.fromBytes(buf);
|
||||
entityId = buf.readInt();
|
||||
type = Type.values()[buf.readInt()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketTeleport message, MessageContext ctx) {
|
||||
World world = ctx.side.isClient() ? EnderIO.proxy.getClientWorld() : message.getWorld(ctx);
|
||||
TileEntity te = message.getTileEntity(world);
|
||||
if(te instanceof TileTelePad) {
|
||||
if(message.type == Type.BEGIN) {
|
||||
((TileTelePad) te).enqueueTeleport(world.getEntityByID(message.entityId));
|
||||
} else {
|
||||
((TileTelePad) te).dequeueTeleport(world.getEntityByID(message.entityId));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -46,9 +46,9 @@ public class PacketUpdateCoords extends MessageTileEntity<TileTelePad> implement
|
||||
public IMessage onMessage(PacketUpdateCoords message, MessageContext ctx) {
|
||||
TileTelePad te = message.getTileEntity(message.getWorld(ctx));
|
||||
if(te != null) {
|
||||
te.setX(targetX);
|
||||
te.setY(targetY);
|
||||
te.setZ(targetZ);
|
||||
te.setX(message.targetX);
|
||||
te.setY(message.targetY);
|
||||
te.setZ(message.targetZ);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package crazypants.enderio.teleport.telepad;
|
||||
|
||||
import net.minecraft.client.renderer.RenderGlobal;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.event.RenderLivingEvent;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import crazypants.render.RenderUtil;
|
||||
|
||||
public class TeleportEntityRenderHandler {
|
||||
|
||||
private static final ResourceLocation RES_ITEM_GLINT = new ResourceLocation("textures/misc/enchanted_item_glint.png");
|
||||
|
||||
@SubscribeEvent
|
||||
public void onEntityRender(RenderLivingEvent.Post event) {
|
||||
EntityLivingBase e = event.entity;
|
||||
float radius = e.width / 2.0F;
|
||||
AxisAlignedBB bb = AxisAlignedBB.getBoundingBox(-radius, 0, -radius, radius, e.height + 0.25, radius);
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
|
||||
GL11.glDepthMask(false);
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_CULL_FACE);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glTranslated(event.x, event.y, event.z);
|
||||
bb = bb.expand(0.25, 0, 0.25);
|
||||
GL11.glRotatef((e.ticksExisted + RenderUtil.getTimer().renderPartialTicks) * 4, 0, 1, 0);
|
||||
if(event.entity.getEntityData().getBoolean(TileTelePad.TELEPORTING_KEY)) {
|
||||
RenderGlobal.drawOutlinedBoundingBox(bb, 0xAA55FF);
|
||||
}
|
||||
GL11.glPopAttrib();
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package crazypants.enderio.teleport.telepad;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -16,17 +17,23 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cofh.api.energy.EnergyStorage;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Queues;
|
||||
|
||||
import crazypants.enderio.api.teleport.ITelePad;
|
||||
import crazypants.enderio.api.teleport.TravelSource;
|
||||
import crazypants.enderio.machine.PacketPowerStorage;
|
||||
import crazypants.enderio.machine.PacketProgress;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.enderio.power.IInternalPowerReceiver;
|
||||
import crazypants.enderio.teleport.TravelController;
|
||||
import crazypants.enderio.teleport.anchor.TileTravelAnchor;
|
||||
import crazypants.enderio.teleport.packet.PacketTravelEvent;
|
||||
import crazypants.enderio.teleport.telepad.PacketTeleport.Type;
|
||||
import crazypants.util.BlockCoord;
|
||||
import crazypants.util.IProgressTile;
|
||||
import crazypants.util.Util;
|
||||
|
||||
public class TileTelePad extends TileTravelAnchor implements IInternalPowerReceiver, ITelePad {
|
||||
public class TileTelePad extends TileTravelAnchor implements IInternalPowerReceiver, ITelePad, IProgressTile {
|
||||
|
||||
private boolean inNetwork;
|
||||
|
||||
@@ -40,6 +47,13 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
|
||||
|
||||
private BlockCoord target = new BlockCoord();
|
||||
|
||||
private int lastSyncPowerStored;
|
||||
|
||||
private Queue<Entity> toTeleport = Queues.newLinkedBlockingQueue();
|
||||
private int powerUsed;
|
||||
private int maxPower;
|
||||
private int lastSyncPowerUsed;
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
@@ -51,6 +65,43 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
|
||||
updateConnectedState(true);
|
||||
autoUpdate = false;
|
||||
}
|
||||
if(!worldObj.isRemote) {
|
||||
if(active()) {
|
||||
System.out.println(maxPower);
|
||||
if(powerUsed >= maxPower) {
|
||||
teleport(toTeleport.poll());
|
||||
powerUsed = 0;
|
||||
} else {
|
||||
powerUsed += energy.extractEnergy(energy.getMaxExtract(), false);
|
||||
}
|
||||
if(worldObj.getTotalWorldTime() % 5 == 0) {
|
||||
updateQueuedEntities();
|
||||
}
|
||||
}
|
||||
|
||||
boolean powerChanged = (lastSyncPowerStored != getEnergyStored() && worldObj.getTotalWorldTime() % 5 == 0);
|
||||
if(powerChanged) {
|
||||
lastSyncPowerStored = getEnergyStored();
|
||||
PacketHandler.sendToAllAround(new PacketPowerStorage(this), this);
|
||||
}
|
||||
boolean progressChanged = (lastSyncPowerUsed != powerUsed);
|
||||
if(progressChanged) {
|
||||
lastSyncPowerUsed = getEnergyStored();
|
||||
PacketHandler.sendToAllAround(new PacketProgress(this), this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateQueuedEntities() {
|
||||
List<Entity> toRemove = Lists.newArrayList();
|
||||
for (Entity e : toTeleport) {
|
||||
if(!isEntityInRange(e)) {
|
||||
toRemove.add(e);
|
||||
}
|
||||
}
|
||||
for (Entity e : toRemove) {
|
||||
dequeueTeleport(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateConnectedState(boolean fromBlock) {
|
||||
@@ -89,6 +140,9 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
|
||||
updateBlock();
|
||||
if(inNetwork) {
|
||||
master = this;
|
||||
if(target.equals(new BlockCoord())) {
|
||||
target = new BlockCoord(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -154,7 +208,7 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
|
||||
protected void readCustomNBT(NBTTagCompound root) {
|
||||
super.readCustomNBT(root);
|
||||
energy.readFromNBT(root);
|
||||
target = new BlockCoord().readFromNBT(root);
|
||||
target = BlockCoord.readFromNBT(root);
|
||||
autoUpdate = true;
|
||||
}
|
||||
|
||||
@@ -171,6 +225,43 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
|
||||
this.inNetwork = pkt.func_148857_g().getBoolean("inNetwork");
|
||||
}
|
||||
|
||||
public int getPowerScaled(int scale) {
|
||||
return (int) ((((float) getEnergyStored()) / ((float) getMaxEnergyStored())) * scale);
|
||||
}
|
||||
|
||||
public int getProgressScaled(int scale) {
|
||||
return (int) (getProgress() * scale);
|
||||
}
|
||||
|
||||
private int getPowerForTeleport() {
|
||||
return new BlockCoord(this).distance(target) * 10;
|
||||
}
|
||||
|
||||
public boolean active() {
|
||||
return !toTeleport.isEmpty();
|
||||
}
|
||||
|
||||
public Entity getCurrentTarget() {
|
||||
return toTeleport.peek();
|
||||
}
|
||||
|
||||
/* IProgressTile */
|
||||
|
||||
@Override
|
||||
public float getProgress() {
|
||||
return ((float) powerUsed) / ((float) maxPower);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProgress(float progress) {
|
||||
this.powerUsed = progress < 0 ? 0 : (int) (((float) maxPower) * progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getTileEntity() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/* ITelePad */
|
||||
|
||||
@Override
|
||||
@@ -190,7 +281,7 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
if (inNetwork) {
|
||||
if(inNetwork) {
|
||||
return master.target.x;
|
||||
}
|
||||
return target.x;
|
||||
@@ -198,7 +289,7 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
|
||||
|
||||
@Override
|
||||
public int getY() {
|
||||
if (inNetwork) {
|
||||
if(inNetwork) {
|
||||
return master.target.y;
|
||||
}
|
||||
return target.y;
|
||||
@@ -206,7 +297,7 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
|
||||
|
||||
@Override
|
||||
public int getZ() {
|
||||
if (inNetwork) {
|
||||
if(inNetwork) {
|
||||
return master.target.z;
|
||||
}
|
||||
return target.z;
|
||||
@@ -215,7 +306,7 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
|
||||
@Override
|
||||
public ITelePad setX(int x) {
|
||||
if(inNetwork()) {
|
||||
target.x = x;
|
||||
setCoords(new BlockCoord(x, target.y, target.z));
|
||||
return master;
|
||||
}
|
||||
return null;
|
||||
@@ -224,7 +315,7 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
|
||||
@Override
|
||||
public ITelePad setY(int y) {
|
||||
if(inNetwork()) {
|
||||
target.y = y;
|
||||
setCoords(new BlockCoord(target.x, y, target.z));
|
||||
return master;
|
||||
}
|
||||
return null;
|
||||
@@ -233,7 +324,7 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
|
||||
@Override
|
||||
public ITelePad setZ(int z) {
|
||||
if(inNetwork()) {
|
||||
target.z = z;
|
||||
setCoords(new BlockCoord(target.x, target.y, z));
|
||||
return master;
|
||||
}
|
||||
return null;
|
||||
@@ -242,18 +333,23 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
|
||||
@Override
|
||||
public void setCoords(BlockCoord coords) {
|
||||
if(inNetwork()) {
|
||||
target = new BlockCoord(coords);
|
||||
if(isMaster()) {
|
||||
this.target = coords;
|
||||
this.maxPower = getPowerForTeleport();
|
||||
} else {
|
||||
this.master.setCoords(coords);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void teleportSpecific(Entity entity) {
|
||||
if(!inNetwork()) {
|
||||
return;
|
||||
}
|
||||
if(isMaster()) {
|
||||
if(getRange().isVecInside(Vec3.createVectorHelper(entity.posX, entity.posY, entity.posZ))) {
|
||||
teleport(entity);
|
||||
if(isEntityInRange(entity)) {
|
||||
enqueueTeleport(entity);
|
||||
}
|
||||
} else {
|
||||
master.teleportSpecific(entity);
|
||||
@@ -267,32 +363,60 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei
|
||||
}
|
||||
if(isMaster()) {
|
||||
for (Entity e : getEntitiesInRange()) {
|
||||
if(!teleport(e)) {
|
||||
return;
|
||||
}
|
||||
enqueueTeleport(e);
|
||||
}
|
||||
} else {
|
||||
master.teleportAll();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Entity> getEntitiesInRange() {
|
||||
return worldObj.getEntitiesWithinAABB(Entity.class, getRange());
|
||||
}
|
||||
|
||||
|
||||
private boolean isEntityInRange(Entity entity) {
|
||||
return getRange().isVecInside(Vec3.createVectorHelper(entity.posX, entity.posY, entity.posZ));
|
||||
}
|
||||
|
||||
private AxisAlignedBB getRange() {
|
||||
return AxisAlignedBB.getBoundingBox(xCoord - 1, yCoord, zCoord - 1, xCoord + 2, yCoord + 3, zCoord + 2);
|
||||
}
|
||||
|
||||
private boolean teleport(Entity entity) {
|
||||
if (entity.worldObj.isRemote) {
|
||||
return TravelController.instance.doClientTeleport(entity, target, TravelSource.TELEPAD, 0, false);
|
||||
} else {
|
||||
return PacketTravelEvent.doServerTeleport(entity, target.x, target.y, target.z, 0, false);
|
||||
|
||||
public static final String TELEPORTING_KEY = "eio:teleporting";
|
||||
|
||||
void enqueueTeleport(Entity entity) {
|
||||
entity.getEntityData().setBoolean(TELEPORTING_KEY, true);
|
||||
toTeleport.add(entity);
|
||||
if(entity.worldObj.isRemote) {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketTeleport(Type.BEGIN, this, entity.getEntityId()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void dequeueTeleport(Entity entity) {
|
||||
toTeleport.remove(entity);
|
||||
entity.getEntityData().setBoolean(TELEPORTING_KEY, false);
|
||||
if(!worldObj.isRemote) {
|
||||
PacketHandler.INSTANCE.sendToAll(new PacketTeleport(Type.END, this, entity.getEntityId()));
|
||||
}
|
||||
if(!active()) {
|
||||
powerUsed = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean teleport(Entity entity) {
|
||||
entity.getEntityData().setBoolean(TELEPORTING_KEY, false);
|
||||
if(entity.worldObj.isRemote) {
|
||||
return TravelController.instance.doClientTeleport(entity, target, TravelSource.TELEPAD, 0, false);
|
||||
} else {
|
||||
if(PacketTravelEvent.doServerTeleport(entity, target.x, target.y, target.z, 0, false)) {
|
||||
dequeueTeleport(entity);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* ITravelAccessable overrides */
|
||||
|
||||
@Override
|
||||
|
||||
@@ -70,8 +70,10 @@ public abstract class GuiContainerBase extends GuiContainer implements ToolTipRe
|
||||
if(hideOverlays()) {
|
||||
return;
|
||||
}
|
||||
if (focused == null) {
|
||||
if(focused == null) {
|
||||
this.mc.thePlayer.closeScreen();
|
||||
} else {
|
||||
focused.setFocused(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,9 +15,9 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public final class BlockCoord {
|
||||
|
||||
public int x;
|
||||
public int y;
|
||||
public int z;
|
||||
public final int x;
|
||||
public final int y;
|
||||
public final int z;
|
||||
|
||||
public BlockCoord(int x, int y, int z) {
|
||||
this.x = x;
|
||||
@@ -147,11 +147,8 @@ public final class BlockCoord {
|
||||
tag.setInteger("bc:y", y);
|
||||
tag.setInteger("bc:z", z);
|
||||
}
|
||||
|
||||
public BlockCoord readFromNBT(NBTTagCompound tag) {
|
||||
x = tag.getInteger("bc:x");
|
||||
y = tag.getInteger("bc:y");
|
||||
z = tag.getInteger("bc:z");
|
||||
return this;
|
||||
|
||||
public static BlockCoord readFromNBT(NBTTagCompound tag) {
|
||||
return new BlockCoord(tag.getInteger("bc:x"), tag.getInteger("bc:y"), tag.getInteger("bc:z"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package crazypants.util;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public interface IProgressTile {
|
||||
|
||||
float getProgress();
|
||||
|
||||
void setProgress(float progress);
|
||||
|
||||
TileEntity getTileEntity();
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user