This commit is contained in:
tterrag1098 committed 2014-11-07 15:20:12 -05:00
commit f7ed5fb1ef
16 files changed
+360 -115

No files matched your search

@@ -420,9 +420,22 @@ public class ClientProxy extends CommonProxy {
return super.getReachDistanceForPlayer(entityPlayer);
}
@Override
public void setInstantConfusionOnPlayer(EntityPlayer ent, int duration) {
ent.addPotionEffect(new PotionEffect(Potion.confusion.getId(), duration, 1, true));
Minecraft.getMinecraft().thePlayer.timeInPortal = 1;
}
@Override
public long getTickCount() {
return clientTickCount;
}
@Override
protected void onClientTick() {
if(!Minecraft.getMinecraft().isGamePaused() && Minecraft.getMinecraft().theWorld != null) {
++clientTickCount;
}
}
}
@@ -6,6 +6,11 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent;
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
import cpw.mods.fml.common.gameevent.TickEvent.ServerTickEvent;
import crazypants.enderio.conduit.IConduit;
import crazypants.enderio.conduit.render.ConduitRenderer;
@@ -13,6 +18,10 @@ public class CommonProxy {
private static final DecimalFormat FORMAT = new DecimalFormat("########0.000");
protected long serverTickCount = 0;
protected long clientTickCount = 0;
protected final TickTimer tickTimer = new TickTimer();
public CommonProxy() {
}
@@ -30,18 +39,47 @@ public class CommonProxy {
public double getReachDistanceForPlayer(EntityPlayer entityPlayer) {
return 5;
}
public void load() {
FMLCommonHandler.instance().bus().register(tickTimer);
}
public boolean isNeiInstalled() {
public long getTickCount() {
return serverTickCount;
}
public boolean isNeiInstalled() {
return false;
}
public void setInstantConfusionOnPlayer(EntityPlayer ent, int duration) {
ent.addPotionEffect(new PotionEffect(Potion.confusion.getId(), duration, 1, true));
ent.addPotionEffect(new PotionEffect(Potion.confusion.getId(), duration, 1, true));
}
protected void onServerTick() {
++serverTickCount;
}
protected void onClientTick() {
}
public final class TickTimer {
@SubscribeEvent
public void onTick(ServerTickEvent evt) {
if(evt.phase == Phase.END) {
onServerTick();
}
}
@SubscribeEvent
public void onTick(ClientTickEvent evt) {
if(evt.phase == Phase.END) {
onClientTick();
}
}
}
}
@@ -4,6 +4,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper;
import crazypants.enderio.EnderIO;
import crazypants.enderio.conduit.gas.GasUtil;
import crazypants.enderio.conduit.me.MEUtil;
public enum ConduitDisplayMode {
ALL,
@@ -23,6 +24,9 @@ public enum ConduitDisplayMode {
if(res == GAS && !GasUtil.isGasConduitEnabled()) {
return next(res);
}
if(res == ME && !MEUtil.isMEEnabled()) {
return next(res);
}
return res;
}
@@ -35,6 +39,9 @@ public enum ConduitDisplayMode {
if(res == GAS && !GasUtil.isGasConduitEnabled()) {
return previous(res);
}
if(res == ME && !MEUtil.isMEEnabled()) {
return previous(res);
}
return res;
}
@@ -21,7 +21,7 @@ import crazypants.enderio.conduit.geom.Offset;
import crazypants.enderio.power.IInternalPowerReceptor;
import crazypants.util.BlockCoord;
@Interface(iface = "appeng.me.helpers.IGridProxyable", modid = "appliedenergistics2")
@Interface(iface = "appeng.api.networking.IGridHost", modid = "appliedenergistics2")
public interface IConduitBundle extends IInternalPowerReceptor, IFluidHandler, IItemDuct, IGasHandler, IGridHost {
TileEntity getEntity();
@@ -27,6 +27,8 @@ public class EnderLiquidConduitNetwork extends AbstractConduitNetwork<ILiquidCon
Map<NetworkTank, RoundRobinIterator<NetworkTank>> iterators;
boolean filling;
public EnderLiquidConduitNetwork() {
super(EnderLiquidConduit.class);
}
@@ -78,27 +80,40 @@ public class EnderLiquidConduitNetwork extends AbstractConduitNetwork<ILiquidCon
}
public int fillFrom(NetworkTank tank, FluidStack resource, boolean doFill) {
if(resource == null || tank == null || !matchedFilter(resource, tank.con, tank.conDir, true)) {
if(filling) {
return 0;
}
resource = resource.copy();
resource.amount = Math.min(resource.amount, MAX_IO_PER_TICK);
int filled = 0;
int remaining = resource.amount;
//TODO: Only change starting pos of iterator is doFill is true so a false then true returns the same
for (NetworkTank target : getIteratorForTank(tank)) {
if(!target.equals(tank) && target.acceptsOuput && target.isValid() && matchedFilter(resource, target.con, target.conDir, false)) {
int vol = target.externalTank.fill(target.tankDir, resource.copy(), doFill);
remaining -= vol;
filled += vol;
if(remaining <= 0) {
return filled;
}
resource.amount = remaining;
try {
filling = true;
if(resource == null || tank == null || !matchedFilter(resource, tank.con, tank.conDir, true)) {
return 0;
}
resource = resource.copy();
resource.amount = Math.min(resource.amount, MAX_IO_PER_TICK);
int filled = 0;
int remaining = resource.amount;
//TODO: Only change starting pos of iterator is doFill is true so a false then true returns the same
for (NetworkTank target : getIteratorForTank(tank)) {
if(!target.equals(tank) && target.acceptsOuput && target.isValid() && matchedFilter(resource, target.con, target.conDir, false)) {
int vol = target.externalTank.fill(target.tankDir, resource.copy(), doFill);
remaining -= vol;
filled += vol;
if(remaining <= 0) {
return filled;
}
resource.amount = remaining;
}
}
return filled;
} finally {
filling = false;
}
return filled;
}
private boolean matchedFilter(FluidStack drained, EnderLiquidConduit con, ForgeDirection conDir, boolean isInput) {
@@ -165,20 +180,26 @@ public class EnderLiquidConduitNetwork extends AbstractConduitNetwork<ILiquidCon
@Override
public boolean equals(Object obj) {
if(this == obj)
if(this == obj) {
return true;
if(obj == null)
}
if(obj == null) {
return false;
if(getClass() != obj.getClass())
}
if(getClass() != obj.getClass()) {
return false;
}
NetworkTankKey other = (NetworkTankKey) obj;
if(conDir != other.conDir)
if(conDir != other.conDir) {
return false;
}
if(conduitLoc == null) {
if(other.conduitLoc != null)
if(other.conduitLoc != null) {
return false;
} else if(!conduitLoc.equals(other.conduitLoc))
}
} else if(!conduitLoc.equals(other.conduitLoc)) {
return false;
}
return true;
}
@@ -217,20 +238,26 @@ public class EnderLiquidConduitNetwork extends AbstractConduitNetwork<ILiquidCon
@Override
public boolean equals(Object obj) {
if(this == obj)
if(this == obj) {
return true;
if(obj == null)
}
if(obj == null) {
return false;
if(getClass() != obj.getClass())
}
if(getClass() != obj.getClass()) {
return false;
}
NetworkTank other = (NetworkTank) obj;
if(conDir != other.conDir)
if(conDir != other.conDir) {
return false;
}
if(conduitLoc == null) {
if(other.conduitLoc != null)
if(other.conduitLoc != null) {
return false;
} else if(!conduitLoc.equals(other.conduitLoc))
}
} else if(!conduitLoc.equals(other.conduitLoc)) {
return false;
}
return true;
}
@@ -147,7 +147,7 @@ public class GuiEnderface extends GuiScreen {
guiLeft = (width - gw) / 2;
guiTop = (height - gh) / 2;
initTime = world.getTotalWorldTime();
initTime = EnderIO.proxy.getTickCount();
}
@Override
@@ -182,7 +182,7 @@ public class GuiEnderface extends GuiScreen {
distance -= Mouse.getDWheel() * 0.01;
distance = VecmathUtil.clamp(distance, 0.1, 20);
long elapsed = world.getTotalWorldTime() - initTime;
long elapsed = EnderIO.proxy.getTickCount() - initTime;
if(Mouse.getEventButton() == 1 && !Mouse.getEventButtonState() && camera.isValid() && elapsed > 10) {
@@ -389,7 +389,7 @@ public class GuiEnderface extends GuiScreen {
private float portalFade = 1;
private void drawEffectOverlay(float partialTick) {
ScaledResolution scaledresolution = new ScaledResolution(this.mc, this.mc.displayWidth, this.mc.displayHeight);
ScaledResolution scaledresolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0.0D, scaledresolution.getScaledWidth_double(), scaledresolution.getScaledHeight_double(), 0.0D, 1000.0D, 3000.0D);
@@ -518,10 +518,10 @@ public class GuiEnderface extends GuiScreen {
private void drawEnderfaceBackground() {
int w = this.gw;
int h = this.gh;
int left = this.guiLeft;
int top = this.guiTop;
int w = gw;
int h = gh;
int left = guiLeft;
int top = guiTop;
int cx = left + w / 2;
int cy = top + h / 2;
@@ -565,7 +565,7 @@ public class GuiEnderface extends GuiScreen {
private ViewableBlocks(int x, int y, int z, Block block) {
super();
this.bc = new BlockCoord(x, y, z);
bc = new BlockCoord(x, y, z);
this.block = block;
}
@@ -2,9 +2,6 @@ package crazypants.enderio.gui;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.ResourceLocation;
import crazypants.enderio.conduit.gas.GasConduit;
import crazypants.enderio.conduit.gas.GasUtil;
import crazypants.enderio.conduit.me.MEUtil;
import crazypants.render.RenderUtil;
public final class IconEIO {
@@ -24,9 +21,6 @@ public final class IconEIO {
public static final IconEIO BUTTON_DOWN = new IconEIO(48, 116);
public static final IconEIO BUTTON_DOWN_HIGHLIGHT = new IconEIO(64, 116);
public static final IconEIO WRENCH_OVERLAY_ALL_ON = new IconEIO(0, 148, MEUtil.isMEEnabled() || GasUtil.isGasConduitEnabled() ? 96 : 64, 64);
public static final IconEIO WRENCH_OVERLAY_ALL_OFF = new IconEIO(96, 148, MEUtil.isMEEnabled() || GasUtil.isGasConduitEnabled() ? 96 : 64, 64);
public static final IconEIO WRENCH_OVERLAY_POWER = new IconEIO(0, 148, 32, 32);
public static final IconEIO WRENCH_OVERLAY_POWER_OFF = new IconEIO(0 + 96, 148, 32, 32);
@@ -43,7 +37,7 @@ public final class IconEIO {
public static final IconEIO WRENCH_OVERLAY_GAS_OFF = new IconEIO(64 + 96, 148, 32, 32);
public static final IconEIO WRENCH_OVERLAY_ME = new IconEIO(64, 180, 32, 32);
public static final IconEIO WRENCH_OVERLAN_ME_OFF = new IconEIO(64 + 96, 180, 32, 32);
public static final IconEIO WRENCH_OVERLAY_ME_OFF = new IconEIO(64 + 96, 180, 32, 32);
public static final IconEIO PROBE_OVERLAY_PROBE = new IconEIO(112, 100, 32, 16);
public static final IconEIO PROBE_OVERLAY_COPY = new IconEIO(144, 100, 32, 16);
@@ -1,5 +1,9 @@
package crazypants.enderio.item;
import java.awt.Point;
import java.util.EnumMap;
import java.util.Map;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.item.ItemStack;
@@ -19,6 +23,11 @@ public class YetaWrenchOverlayRenderer {
private ItemYetaWrench wrench;
private IconEIO[] onIcons;
private IconEIO[] offIcons;
private Point[] iconOffsets;
private Map<ConduitDisplayMode, Integer> indices = new EnumMap<ConduitDisplayMode, Integer>(ConduitDisplayMode.class);
public YetaWrenchOverlayRenderer(ItemYetaWrench wrench) {
this.wrench = wrench;
MinecraftForge.EVENT_BUS.register(this);
@@ -41,35 +50,96 @@ public class YetaWrenchOverlayRenderer {
}
private void doRenderOverlay(RenderGameOverlayEvent event, ItemStack equippedWrench) {
initIcons();
ConduitDisplayMode mode = ConduitDisplayMode.getDisplayMode(equippedWrench);
ScaledResolution res = event.resolution;
double offsetX = 16;
double offsetY = res.getScaledHeight() - 16;
int width = MEUtil.isMEEnabled() || GasUtil.isGasConduitEnabled() ? 48 : 32;
if(mode == ConduitDisplayMode.ALL) {
GL11.glColor4f(1, 1, 1, 0.75f);
IconEIO.WRENCH_OVERLAY_ALL_ON.renderIcon(offsetX, offsetY - 32, width, 32, 0, true);
renderAll(onIcons, offsetX, offsetY);
return;
}
float c = 0.6f;
GL11.glColor4f(c, c, c, 0.33f);
IconEIO.WRENCH_OVERLAY_ALL_OFF.renderIcon(offsetX, offsetY - 32, width, 32, 0, true);
GL11.glColor4f(1, 1, 1, 0.75f);
if(mode == ConduitDisplayMode.POWER) {
IconEIO.WRENCH_OVERLAY_POWER.renderIcon(offsetX, offsetY - 32, 16, 16, 0, true);
} else if(mode == ConduitDisplayMode.REDSTONE) {
IconEIO.WRENCH_OVERLAY_REDSTONE.renderIcon(offsetX + 16, offsetY - 32, 16, 16, 0, true);
} else if(mode == ConduitDisplayMode.FLUID) {
IconEIO.WRENCH_OVERLAY_FLUID.renderIcon(offsetX, offsetY - 16, 16, 16, 0, true);
} else if(mode == ConduitDisplayMode.ITEM) {
IconEIO.WRENCH_OVERLAY_ITEM.renderIcon(offsetX + 16, offsetY - 16, 16, 16, 0, true);
} else if(mode == ConduitDisplayMode.GAS) {
IconEIO.WRENCH_OVERLAY_GAS.renderIcon(offsetX + 32, offsetY - 16, 16, 16, 0, true);
} else if(mode == ConduitDisplayMode.ME) {
IconEIO.WRENCH_OVERLAY_ME.renderIcon(offsetX + 32, offsetY - 32);
renderAll(offIcons, offsetX, offsetY);
if(indices.containsKey(mode)) {
GL11.glColor4f(1, 1, 1, 0.75f);
int index = indices.get(mode);
Point p = iconOffsets[index];
onIcons[index].renderIcon(offsetX + p.x, offsetY + p.y, 16, 16, 0, true);
}
}
private void renderAll(IconEIO[] icons, double offsetX, double offsetY) {
int i = 0;
for (Point p : iconOffsets) {
icons[i].renderIcon(offsetX + p.x, offsetY + p.y, 16, 16, 0, true);
i++;
}
}
private void initIcons() {
int numIcons = getNumConduitsEnabled();
if(onIcons != null && onIcons.length == numIcons) {
return;
}
boolean meEnabled = MEUtil.isMEEnabled();
boolean gasEnabled = GasUtil.isGasConduitEnabled();
onIcons = new IconEIO[numIcons];
offIcons = new IconEIO[numIcons];
iconOffsets = new Point[numIcons];
indices.put(ConduitDisplayMode.POWER, 0);
onIcons[0] = IconEIO.WRENCH_OVERLAY_POWER;
offIcons[0] = IconEIO.WRENCH_OVERLAY_POWER_OFF;
indices.put(ConduitDisplayMode.REDSTONE, 1);
onIcons[1] = IconEIO.WRENCH_OVERLAY_REDSTONE;
offIcons[1] = IconEIO.WRENCH_OVERLAY_REDSTONE_OFF;
indices.put(ConduitDisplayMode.FLUID, 2);
onIcons[2] = IconEIO.WRENCH_OVERLAY_FLUID;
offIcons[2] = IconEIO.WRENCH_OVERLAY_FLUID_OFF;
indices.put(ConduitDisplayMode.ITEM, 3);
onIcons[3] = IconEIO.WRENCH_OVERLAY_ITEM;
offIcons[3] = IconEIO.WRENCH_OVERLAY_ITEM_OFF;
if(meEnabled) {
indices.put(ConduitDisplayMode.ME, 4);
onIcons[4] = IconEIO.WRENCH_OVERLAY_ME;
offIcons[4] = IconEIO.WRENCH_OVERLAY_ME_OFF;
}
if(gasEnabled) {
int index = meEnabled ? 5 : 4;
indices.put(ConduitDisplayMode.GAS, index);
onIcons[index] = IconEIO.WRENCH_OVERLAY_GAS;
offIcons[index] = IconEIO.WRENCH_OVERLAY_GAS_OFF;
}
int xOffset = numIcons == 5 ? 8 : 0;
iconOffsets[0] = new Point(xOffset, -32);
iconOffsets[1] = new Point(xOffset + 16, -32);
xOffset = 0;
iconOffsets[2] = new Point(xOffset, -16);
iconOffsets[3] = new Point(xOffset + 16, -16);
if(numIcons == 5) {
iconOffsets[4] = new Point(xOffset + 32, -16);
} else if(numIcons == 6) {
iconOffsets[4] = new Point(xOffset + 32, -32);
iconOffsets[5] = new Point(xOffset + 32, -16);
}
}
private int getNumConduitsEnabled() {
boolean meEnabled = MEUtil.isMEEnabled();
boolean gasEnabled = GasUtil.isGasConduitEnabled();
return 4 + (meEnabled ? 1 : 0) + (gasEnabled ? 1 : 0);
}
}
@@ -313,14 +313,14 @@ public class ItemDarkSteelPickaxe extends ItemPickaxe implements IEnergyContaine
}
}
long ticksSinceBlink = player.worldObj.getTotalWorldTime() - lastBlickTick;
long ticksSinceBlink = EnderIO.proxy.getTickCount() - lastBlickTick;
if(ticksSinceBlink < 0) {
lastBlickTick = -1;
}
if(Config.travelStaffBlinkEnabled && world.isRemote && ticksSinceBlink >= Config.travelStaffBlinkPauseTicks) {
if(TravelController.instance.doBlink(stack, player)) {
player.swingItem();
lastBlickTick = player.worldObj.getTotalWorldTime();
lastBlickTick = EnderIO.proxy.getTickCount();
}
}
return stack;
@@ -324,14 +324,14 @@ public class ItemDarkSteelSword extends ItemSword implements IEnergyContainerIte
}
}
long ticksSinceBlink = player.worldObj.getTotalWorldTime() - lastBlickTick;
long ticksSinceBlink = EnderIO.proxy.getTickCount() - lastBlickTick;
if(ticksSinceBlink < 0) {
lastBlickTick = -1;
}
if(Config.travelStaffBlinkEnabled && world.isRemote && ticksSinceBlink >= Config.travelStaffBlinkPauseTicks) {
if(TravelController.instance.doBlink(stack, player)) {
player.swingItem();
lastBlickTick = player.worldObj.getTotalWorldTime();
lastBlickTick = EnderIO.proxy.getTickCount();
}
}
return stack;
@@ -1,54 +1,48 @@
package crazypants.enderio.machine;
import io.netty.buffer.ByteBuf;
import net.minecraft.nbt.NBTTagCompound;
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.enderio.network.NetworkUtil;
public class PacketCurrentTask extends MessageTileEntity<AbstractPoweredTaskEntity> implements IMessageHandler<PacketCurrentTask, IMessage> {
private NBTTagCompound nbtRoot;
private float progress;
public PacketCurrentTask() {
}
public PacketCurrentTask(AbstractPoweredTaskEntity tile) {
super(tile);
nbtRoot = new NBTTagCompound();
progress = -1;
if(tile.currentTask != null) {
NBTTagCompound tankRoot = new NBTTagCompound();
tile.currentTask.writeToNBT(tankRoot);
nbtRoot.setTag("currentTask", tankRoot);
progress = tile.currentTask.getProgress();
}
}
@Override
public void toBytes(ByteBuf buf) {
super.toBytes(buf);
NetworkUtil.writeNBTTagCompound(nbtRoot, buf);
buf.writeFloat(progress);
}
@Override
public void fromBytes(ByteBuf buf) {
super.fromBytes(buf);
nbtRoot = NetworkUtil.readNBTTagCompound(buf);
progress = buf.readFloat();
}
@Override
public IMessage onMessage(PacketCurrentTask message, MessageContext ctx) {
AbstractPoweredTaskEntity tile = message.getTileEntity(EnderIO.proxy.getClientWorld());
if (tile != null) {
if(message.nbtRoot.hasKey("currentTask")) {
NBTTagCompound tankRoot = message.nbtRoot.getCompoundTag("currentTask");
tile.currentTask = PoweredTask.readFromNBT(message.nbtRoot.getCompoundTag("currentTask"));
} else {
if(tile != null) {
if(message.progress < 0) {
tile.currentTask = null;
}
} else {
tile.currentTask = new PoweredTaskProgress(message.progress);
}
}
return null;
}
@@ -0,0 +1,64 @@
package crazypants.enderio.machine;
import net.minecraft.nbt.NBTTagCompound;
import crazypants.enderio.machine.IMachineRecipe.ResultStack;
/**
* Client side stub for reporting progress.
*/
public class PoweredTaskProgress implements IPoweredTask {
private float progress;
public PoweredTaskProgress(IPoweredTask task) {
progress = task.getProgress();
}
public PoweredTaskProgress(float progress) {
this.progress = progress;
}
@Override
public void update(float availableEnergy) {
}
@Override
public boolean isComplete() {
return getProgress() >= 1;
}
@Override
public float getProgress() {
return progress;
}
@Override
public ResultStack[] getCompletedResult() {
return new ResultStack[0];
}
@Override
public float getRequiredEnergy() {
return 0;
}
@Override
public float getChance() {
return 0;
}
@Override
public void writeToNBT(NBTTagCompound nbtRoot) {
}
@Override
public IMachineRecipe getRecipe() {
return null;
}
@Override
public MachineRecipeInput[] getInputs() {
return new MachineRecipeInput[0];
}
}
@@ -3,11 +3,21 @@ package crazypants.enderio.machine.transceiver;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import org.apache.commons.io.FileUtils;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
@@ -17,13 +27,6 @@ import crazypants.enderio.machine.SlotDefinition;
import crazypants.util.ItemUtil;
import crazypants.util.RoundRobinIterator;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
public class ServerChannelRegister extends ChannelRegister {
public static ServerChannelRegister instance = new ServerChannelRegister();
@@ -32,7 +35,12 @@ public class ServerChannelRegister extends ChannelRegister {
instance.reset();
File dataFile = getDataFile();
if(!dataFile.exists()) {
return;
dataFile = getFallbackDataFile();
if(!dataFile.exists()) {
return;
} else {
Log.warn("ServerChannelRegister: Using fallback save location " + dataFile.getAbsolutePath());
}
}
try {
@@ -63,34 +71,60 @@ public class ServerChannelRegister extends ChannelRegister {
}
public static void store() {
try {
File dataFile = getDataFile();
dataFile.getParentFile().mkdirs();
JsonWriter writer = new JsonWriter(new FileWriter(dataFile, false));
writer.setIndent(" ");
writer.beginArray();
for (List<Channel> chanList : instance.channels.values()) {
for (Channel chan : chanList) {
writer.beginObject();
writer.name("name").value(chan.getName());
if(chan.getUser() != null) {
writer.name("user").value(chan.getUser());
}
writer.name("type").value(chan.getType().ordinal());
writer.endObject();
}
File dataFile = getDataFile();
if(!createFolderAndWriteFile(dataFile)) {
dataFile = getFallbackDataFile();
Log.error("ServerChannelRegister: Attempting to write Dimensional Trasciever data to fallback location: " + dataFile.getAbsolutePath());
try {
writeFile(dataFile);
} catch (Exception e) {
Log.error("ServerChannelRegister: Could not write Dimensional Trasciever data fallback location " + dataFile.getAbsolutePath()
+ " channles not saved: " + e.getMessage());
return;
}
writer.endArray();
writer.close();
} catch (Exception e) {
Log.error("Could not write Dimensional trasciever channels to " + getDataFile().getAbsolutePath() + " : " + e);
}
Log.info("ServerChannelRegister: Dimensional Trasciever data saved to " + dataFile.getAbsolutePath());
}
protected static boolean createFolderAndWriteFile(File dataFile) {
try {
File parentFolder = dataFile.getParentFile();
FileUtils.forceMkdir(parentFolder);
writeFile(dataFile);
return true;
} catch (Exception e) {
Log.error("ServerChannelRegister: Could not write Dimensional Trasciever channels to " + dataFile.getAbsolutePath() + " : " + e);
return false;
}
}
protected static void writeFile(File dataFile) throws IOException {
JsonWriter writer = new JsonWriter(new FileWriter(dataFile, false));
writer.setIndent(" ");
writer.beginArray();
for (List<Channel> chanList : instance.channels.values()) {
for (Channel chan : chanList) {
writer.beginObject();
writer.name("name").value(chan.getName());
if(chan.getUser() != null) {
writer.name("user").value(chan.getUser());
}
writer.name("type").value(chan.getType().ordinal());
writer.endObject();
}
}
writer.endArray();
writer.close();
}
private static File getDataFile() {
return new File(DimensionManager.getCurrentSaveRootDirectory(), "enderio/dimensionalTransceiver.json");
}
private static File getFallbackDataFile() {
return new File(DimensionManager.getCurrentSaveRootDirectory(), "dimensionalTransceiver.json");
}
//-----------------------------------------------------------------------------------------------
private final List<TileTransceiver> transceivers = new ArrayList<TileTransceiver>();
@@ -64,14 +64,14 @@ public class ItemTravelStaff extends ItemEnergyContainer implements IItemOfTrave
@Override
public ItemStack onItemRightClick(ItemStack equipped, World world, EntityPlayer player) {
if(player.isSneaking()) {
long ticksSinceBlink = player.worldObj.getTotalWorldTime() - lastBlickTick;
long ticksSinceBlink = EnderIO.proxy.getTickCount() - lastBlickTick;
if(ticksSinceBlink < 0) {
lastBlickTick = -1;
}
if(Config.travelStaffBlinkEnabled && world.isRemote && ticksSinceBlink >= Config.travelStaffBlinkPauseTicks) {
if(TravelController.instance.doBlink(equipped, player)) {
player.swingItem();
lastBlickTick = player.worldObj.getTotalWorldTime();
lastBlickTick = EnderIO.proxy.getTickCount();
}
}
return equipped;
@@ -111,6 +111,7 @@ public class ItemTravelStaff extends ItemEnergyContainer implements IItemOfTrave
return res;
}
@Override
public void extractInternal(ItemStack item, int powerUse) {
int res = Math.max(0, getEnergyStored(item) - powerUse);
setEnergy(item, res);