mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-26 06:52:58 +00:00
Finish off the Hourglass.
This commit is contained in:
1 parent
40237cdb66
commit
fbeea5007e
7 files changed
+164
-4
No files matched your search
@@ -10,20 +10,42 @@
|
||||
*/
|
||||
package vazkii.botania.common.block.tile;
|
||||
|
||||
import io.netty.util.internal.StringUtil;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.client.renderer.ItemRenderer;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.util.StringUtils;
|
||||
import vazkii.botania.common.lib.LibBlockNames;
|
||||
import vazkii.botania.common.lib.LibItemNames;
|
||||
|
||||
public class TileHourglass extends TileSimpleInventory {
|
||||
|
||||
private static final String TAG_TIME = "time";
|
||||
private static final String TAG_TIME_FRACTION = "timeFraction";
|
||||
private static final String TAG_FLIP = "flip";
|
||||
private static final String TAG_FLIP_TICKS = "flipTicks";
|
||||
private static final String TAG_LOCK = "lock";
|
||||
private static final String TAG_MOVE = "move";
|
||||
|
||||
int time = 0;
|
||||
public float timeFraction = 0F;
|
||||
public boolean flip = false;
|
||||
public int flipTicks = 0;
|
||||
public boolean lock = false;
|
||||
public boolean move = true;
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
@@ -31,7 +53,8 @@ public class TileHourglass extends TileSimpleInventory {
|
||||
|
||||
int totalTime = getTotalTime();
|
||||
if(totalTime > 0) {
|
||||
time++;
|
||||
if(move)
|
||||
time++;
|
||||
if(time >= totalTime) {
|
||||
time = 0;
|
||||
flip = !flip;
|
||||
@@ -82,12 +105,22 @@ public class TileHourglass extends TileSimpleInventory {
|
||||
public void writeCustomNBT(NBTTagCompound par1nbtTagCompound) {
|
||||
super.writeCustomNBT(par1nbtTagCompound);
|
||||
par1nbtTagCompound.setInteger(TAG_TIME, time);
|
||||
par1nbtTagCompound.setFloat(TAG_TIME_FRACTION, timeFraction);
|
||||
par1nbtTagCompound.setBoolean(TAG_FLIP, flip);
|
||||
par1nbtTagCompound.setInteger(TAG_FLIP_TICKS, flipTicks);
|
||||
par1nbtTagCompound.setBoolean(TAG_MOVE, move);
|
||||
par1nbtTagCompound.setBoolean(TAG_LOCK, lock);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readCustomNBT(NBTTagCompound par1nbtTagCompound) {
|
||||
super.readCustomNBT(par1nbtTagCompound);
|
||||
time = par1nbtTagCompound.getInteger(TAG_TIME);
|
||||
timeFraction = par1nbtTagCompound.getFloat(TAG_TIME_FRACTION);
|
||||
flip = par1nbtTagCompound.getBoolean(TAG_FLIP);
|
||||
flipTicks = par1nbtTagCompound.getInteger(TAG_FLIP_TICKS);
|
||||
move = par1nbtTagCompound.getBoolean(TAG_MOVE);
|
||||
lock = par1nbtTagCompound.getBoolean(TAG_LOCK);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -101,6 +134,35 @@ public class TileHourglass extends TileSimpleInventory {
|
||||
time = 0;
|
||||
timeFraction = 0F;
|
||||
}
|
||||
|
||||
public void renderHUD(ScaledResolution res) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
int x = res.getScaledWidth() / 2 + 10;
|
||||
int y = res.getScaledHeight() / 2 - 10;
|
||||
|
||||
ItemStack stack = getStackInSlot(0);
|
||||
if(stack != null) {
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
RenderItem.getInstance().renderItemIntoGUI(mc.fontRenderer, mc.renderEngine, stack, x, y);
|
||||
RenderItem.getInstance().renderItemOverlayIntoGUI(mc.fontRenderer, mc.renderEngine, stack, x, y);
|
||||
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
|
||||
int time = getTotalTime();
|
||||
String timeStr = StringUtils.ticksToElapsedTime(time);
|
||||
mc.fontRenderer.drawStringWithShadow(timeStr, x + 20, y, getColor());
|
||||
|
||||
String status = "";
|
||||
if(lock)
|
||||
status = "locked";
|
||||
if(!move)
|
||||
status = status.isEmpty() ? "stopped" : "lockedStopped";
|
||||
if(!status.isEmpty())
|
||||
mc.fontRenderer.drawStringWithShadow(StatCollector.translateToLocal("botaniamisc." + status), x + 20, y + 12, getColor());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
|
||||
Reference in new issue
Block a user