Skip to content

Commit

Permalink
Reintroduced tool upgrades (renamed from "temporal tool modules" and …
Browse files Browse the repository at this point in the history
…the "pocket watch" before that).
  • Loading branch information
Lumaceon committed Dec 2, 2015
1 parent 99f0948 commit acb8957
Show file tree
Hide file tree
Showing 35 changed files with 506 additions and 306 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public void preInitialize(FMLPreInitializationEvent event)
ModEntities.init();

proxy.registerKeybindings();

}

@Mod.EventHandler
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package lumaceon.mods.clockworkphase2.api.item;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;

public interface IKeybindActivation
{
/**
* Called CLIENT-SIDE when the activate keybind is pressed with this itemstack in hand.
*/
public void onKeyPressed(ItemStack item, EntityPlayer player);
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package lumaceon.mods.clockworkphase2.api.item;

import net.minecraft.item.ItemStack;

public interface IToolUpgrade
{
/**
* Called to activate or deactivate this tool upgrade
* @param item A stack representing the tool upgrade.
* @param active True to set this to active, false to turn it off.
*/
public void setActive(ItemStack item, boolean active);

/**
* @param item The tool upgrade stack.
* @return Whether or not this itemstack is active.
*/
public boolean getActive(ItemStack item);

public float getQualityMultiplier(ItemStack item);
public float getSpeedMultiplier(ItemStack item);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer p
if(player.isSneaking())
return false;
if(!world.isRemote)
player.openGui(ClockworkPhase2.instance, 4, world, x, y, z);
player.openGui(ClockworkPhase2.instance, 3, world, x, y, z);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package lumaceon.mods.clockworkphase2.client.gui;

import lumaceon.mods.clockworkphase2.api.util.internal.NBTHelper;
import lumaceon.mods.clockworkphase2.api.util.internal.NBTTags;
import lumaceon.mods.clockworkphase2.client.gui.components.GuiButtonItem;
import lumaceon.mods.clockworkphase2.network.PacketHandler;
import lumaceon.mods.clockworkphase2.network.message.MessageToolUpgradeActivate;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.item.ItemStack;

public class GuiClockworkTool extends GuiScreen
{
public ItemStack[] items;
public RenderItem itemRenders;
public int guiLeft, guiTop, xSize, ySize;

public GuiClockworkTool(ItemStack[] itemStacks) {
super();
itemRenders = new RenderItem();
if(itemStacks == null)
itemStacks = new ItemStack[0];
this.items = itemStacks;
this.xSize = 300;
this.ySize = 60;
}

@Override
public void initGui()
{
super.initGui();
this.guiLeft = (this.width - this.xSize) / 2;
this.guiTop = (this.height - this.ySize) / 2;
buttonList.clear();
int index = 0;
for(int x = 0; x < 10; x++)
{
for(int y = 0; y < 2; y++)
{
if(items.length > index && items[index] != null)
buttonList.add(new GuiButtonItem(items[index], index, guiLeft + (x % 10) * 30, guiTop + y * 30, "", itemRenders, fontRendererObj, NBTHelper.BOOLEAN.get(items[index], NBTTags.ACTIVE)));
else
buttonList.add(new GuiButtonItem(null, index, guiLeft + (x % 10) * 30, guiTop + y * 30, "", itemRenders, fontRendererObj, false));
index++;
}
}
}

@Override
public void actionPerformed(GuiButton button) {
PacketHandler.INSTANCE.sendToServer(new MessageToolUpgradeActivate(button.id));
((GuiButtonItem) buttonList.get(button.id)).active = !((GuiButtonItem) buttonList.get(button.id)).active;
}

@Override
protected void keyTyped(char p_73869_1_, int p_73869_2_) {
if(p_73869_2_ == 1 || p_73869_2_ == this.mc.gameSettings.keyBindInventory.getKeyCode())
this.mc.thePlayer.closeScreen();
}

@Override
public boolean doesGuiPauseGame() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import cpw.mods.fml.common.network.NetworkRegistry;
import lumaceon.mods.clockworkphase2.ClockworkPhase2;
import lumaceon.mods.clockworkphase2.api.assembly.ContainerAssemblyTable;
import lumaceon.mods.clockworkphase2.api.util.internal.NBTHelper;
import lumaceon.mods.clockworkphase2.api.util.internal.NBTTags;
import lumaceon.mods.clockworkphase2.container.ContainerClockworkFurnace;
import lumaceon.mods.clockworkphase2.container.ContainerTemporalFurnace;
import lumaceon.mods.clockworkphase2.container.ContainerTimeWell;
import lumaceon.mods.clockworkphase2.tile.clockwork.TileClockworkFurnace;
import lumaceon.mods.clockworkphase2.tile.temporal.TileTemporalFurnace;
import lumaceon.mods.clockworkphase2.tile.temporal.TileTimeWell;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

Expand All @@ -33,7 +36,7 @@ public Object getServerGuiElement(int ID, EntityPlayer player, World world, int
return new ContainerTimeWell(player.inventory, (TileTimeWell) te, world);
case 2:
return new ContainerClockworkFurnace(player.inventory, (TileClockworkFurnace) te, world);
case 4:
case 3:
return new ContainerTemporalFurnace(player.inventory, (TileTemporalFurnace) te, world);
}
return null;
Expand All @@ -51,8 +54,19 @@ public Object getClientGuiElement(int ID, EntityPlayer player, World world, int
return new GuiTimeWell(player.inventory, (TileTimeWell) te, world);
case 2:
return new GuiClockworkFurnace(player.inventory, (TileClockworkFurnace) te, world);
case 4:
case 3:
return new GuiTemporalFurnace(player.inventory, (TileTemporalFurnace) te, world);
case 4:
if(player == null || player.getHeldItem() == null || !NBTHelper.hasTag(player.getHeldItem(), NBTTags.COMPONENT_INVENTORY))
return null;
ItemStack[] items = new ItemStack[5];
ItemStack[] componentInventory = NBTHelper.INVENTORY.get(player.getHeldItem(), NBTTags.COMPONENT_INVENTORY);
items[0] = componentInventory[2];
items[1] = componentInventory[3];
items[2] = componentInventory[4];
items[3] = componentInventory[5];
items[4] = componentInventory[6];
return new GuiClockworkTool(items);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package lumaceon.mods.clockworkphase2.client.gui.components;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.item.ItemStack;
import org.lwjgl.opengl.GL11;

public class GuiButtonItem extends GuiButton
{
public boolean active;
public ItemStack item;
public RenderItem itemRender;
public FontRenderer fontRenderer;
public Minecraft mc;

public GuiButtonItem(ItemStack is, int p_i1020_1_, int p_i1020_2_, int p_i1020_3_, String p_i1020_4_, RenderItem renderItem, FontRenderer fontRenderer, boolean active) {
super(p_i1020_1_, p_i1020_2_, p_i1020_3_, 20, 20, p_i1020_4_);
this.item = is;
this.itemRender = renderItem;
this.itemRender.renderWithColor = false;
this.mc = Minecraft.getMinecraft();
this.active = active;
}

@Override
public void drawButton(Minecraft p_146112_1_, int p_146112_2_, int p_146112_3_)
{
if(this.visible)
{
FontRenderer fontrenderer = p_146112_1_.fontRenderer;
p_146112_1_.getTextureManager().bindTexture(buttonTextures);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glDisable(GL11.GL_LIGHTING);
this.field_146123_n = p_146112_2_ >= this.xPosition && p_146112_3_ >= this.yPosition && p_146112_2_ < this.xPosition + this.width && p_146112_3_ < this.yPosition + this.height;
int k = this.getHoverState(this.field_146123_n);
GL11.glEnable(GL11.GL_BLEND);
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + k * 20, this.width / 2, this.height);
this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition, 200 - this.width / 2, 46 + k * 20, this.width / 2, this.height);
this.mouseDragged(p_146112_1_, p_146112_2_, p_146112_3_);
int l = 14737632;

if(packedFGColour != 0)
l = packedFGColour;
else if(!this.enabled)
l = 10526880;
else if(this.field_146123_n)
l = 16777120;

if(item != null)
{
if(!active)
GL11.glColor4f(0.5F, 0.5F, 0.5F, 1.0F);
else
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.drawItemStack(item, this.xPosition + 2, this.yPosition + 2, this.displayString);
}
}
}

private void drawItemStack(ItemStack is, int x, int y, String name)
{
GL11.glTranslatef(0.0F, 0.0F, 32.0F);
float zLevelOrigin = this.zLevel;
this.zLevel = 200.0F;
itemRender.zLevel = 200.0F;
FontRenderer font = null;
if (is != null) font = is.getItem().getFontRenderer(is);
if (font == null) font = fontRenderer;
itemRender.renderItemAndEffectIntoGUI(font, this.mc.getTextureManager(), is, x, y);
this.zLevel = zLevelOrigin;
itemRender.zLevel = 0.0F;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
package lumaceon.mods.clockworkphase2.client.keybind;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent;
import lumaceon.mods.clockworkphase2.api.item.IKeybindActivation;
import lumaceon.mods.clockworkphase2.lib.KeyLib;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;

public class KeyHandler
{
public static KeyLib.Keys getKeyPressed()
{
if(Keybindings.activate.isPressed())
return KeyLib.Keys.ACTIVATE;
else
return KeyLib.Keys.IRRELEVANT;
}

@SubscribeEvent
public void handleKeyPress(InputEvent.KeyInputEvent event)
{
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
KeyLib.Keys keyPressed = getKeyPressed();
if(keyPressed.equals(KeyLib.Keys.ACTIVATE))
{
ItemStack item = player.inventory.getCurrentItem();
if(item != null && item.getItem() instanceof IKeybindActivation)
((IKeybindActivation) item.getItem()).onKeyPressed(item, player);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package lumaceon.mods.clockworkphase2.client.keybind;

import lumaceon.mods.clockworkphase2.lib.KeyLib;
import net.minecraft.client.settings.KeyBinding;
import org.lwjgl.input.Keyboard;

public class Keybindings
{
public static KeyBinding activate = new KeyBinding(KeyLib.ACTIVATE, Keyboard.KEY_R, KeyLib.CATEGORY);
}
Loading

0 comments on commit acb8957

Please sign in to comment.