Fix AutoChisel shift clicking and add tooltips

This commit is contained in:
tterrag1098 committed 2015-01-07 23:36:27 -05:00
1 parent cb4ef91731
commit d32b71aa86
5 files changed
+80 -20

No files matched your search

@@ -12,6 +12,7 @@ import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.StatCollector;
import com.cricketcraft.chisel.carving.Carving;
import com.cricketcraft.chisel.init.ModItems;
@@ -22,7 +23,15 @@ import cpw.mods.fml.relauncher.SideOnly;
public class TileEntityAutoChisel extends TileEntity implements ISidedInventory {
public enum Upgrade {
SPEED, AUTOMATION, STACK
SPEED, AUTOMATION, STACK;
public String getUnlocalizedName() {
return ModItems.upgrade.getUnlocalizedName() + "_" + this.name().toLowerCase();
}
public String getLocalizedName() {
return StatCollector.translateToLocal(getUnlocalizedName() + ".name");
}
}
private final int BASE = 0, TARGET = 1, OUTPUT = 2, MIN_UPGRADE = 3;
@@ -1,13 +1,19 @@
package com.cricketcraft.chisel.client.gui;
import java.util.List;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import com.cricketcraft.chisel.block.tileentity.TileEntityAutoChisel;
import com.cricketcraft.chisel.inventory.ContainerAutoChisel;
import com.cricketcraft.chisel.inventory.ContainerAutoChisel.SlotUpgrade;
import com.google.common.collect.Lists;
public class GuiAutoChisel extends GuiContainer {
@@ -17,6 +23,29 @@ public class GuiAutoChisel extends GuiContainer {
super(new ContainerAutoChisel(inventoryPlayer, tileEntityAutoChisel));
}
@SuppressWarnings("unchecked")
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
int x = (this.width - this.xSize) / 2;
int y = (this.height - this.ySize) / 2;
for (Slot slot : (List<Slot>) inventorySlots.inventorySlots) {
if (mouseInside(slot, mouseX - x, mouseY - y)) {
if (slot instanceof SlotUpgrade) {
this.func_146283_a(Lists.newArrayList(((SlotUpgrade) slot).upgradeType.getLocalizedName()), mouseX - x, mouseY - y);
} else if (slot.slotNumber == 1) {
this.func_146283_a(Lists.newArrayList(StatCollector.translateToLocal("autochisel.slot.target.tooltip")), mouseX - x, mouseY - y);
}
}
}
}
private boolean mouseInside(Slot slot, int x, int y) {
return x >= slot.xDisplayPosition && x <= slot.xDisplayPosition + 16 && y >= slot.yDisplayPosition && y <= slot.yDisplayPosition + 16;
}
@Override
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
@@ -7,9 +7,26 @@ import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import com.cricketcraft.chisel.block.tileentity.TileEntityAutoChisel;
import com.cricketcraft.chisel.block.tileentity.TileEntityAutoChisel.Upgrade;
import com.cricketcraft.chisel.init.ModItems;
public class ContainerAutoChisel extends Container {
public static class SlotUpgrade extends Slot {
public Upgrade upgradeType;
public SlotUpgrade(TileEntityAutoChisel inv, int id, int x, int y, Upgrade upgrade) {
super(inv, id, x, y);
this.upgradeType = upgrade;
}
@Override
public boolean isItemValid(ItemStack stack) {
return stack.getItem() == ModItems.upgrade && stack.getItemDamage() == upgradeType.ordinal();
}
}
public static TileEntityAutoChisel autoChisel;
public static EntityPlayer player;
@@ -21,9 +38,9 @@ public class ContainerAutoChisel extends Container {
addSlotToContainer(new Slot(tileEntityAutoChisel, 0, 53, 15));
addSlotToContainer(new Slot(tileEntityAutoChisel, 1, 78, 51));
addSlotToContainer(new Slot(tileEntityAutoChisel, 2, 103, 15));
addSlotToContainer(new Slot(tileEntityAutoChisel, 3, 151, 11));
addSlotToContainer(new Slot(tileEntityAutoChisel, 4, 151, 31));
addSlotToContainer(new Slot(tileEntityAutoChisel, 5, 151, 51));
addSlotToContainer(new SlotUpgrade(tileEntityAutoChisel, 3, 151, 11, Upgrade.SPEED));
addSlotToContainer(new SlotUpgrade(tileEntityAutoChisel, 4, 151, 31, Upgrade.AUTOMATION));
addSlotToContainer(new SlotUpgrade(tileEntityAutoChisel, 5, 151, 51, Upgrade.STACK));
bindPlayerInventory(player);
}
@@ -49,29 +66,33 @@ public class ContainerAutoChisel extends Container {
public ItemStack transferStackInSlot(EntityPlayer player, int slotNumber) {
ItemStack itemStack = null;
Slot slot = (Slot) this.inventorySlots.get(slotNumber);
System.out.println(slotNumber);
if (slot != null && slot.getHasStack()) {
ItemStack itemStack1 = slot.getStack();
itemStack = itemStack1.copy();
if (slotNumber == 2) {
if (!this.mergeItemStack(itemStack1, 3, 39, true)) {
return null;
}
slot.onSlotChange(itemStack1, itemStack);
} else if (slotNumber != 1 && slotNumber != 0) {
if (!this.mergeItemStack(itemStack1, 0, 1, true)) {
return null;
} else if (slotNumber >= 3 && slotNumber < 30) {
if (this.mergeItemStack(itemStack1, 30, 39, false)) {
// if we are in the auto chisel
if (slotNumber <= 5) {
// merge hotbar
if (!this.mergeItemStack(itemStack1, 33, 42, false)) {
// merge rest of inventory
if (!this.mergeItemStack(itemStack1, 6, 33, false)) {
return null;
}
}
} else {
// if this is an upgrade, check the upgrade slots
if (itemStack1.getItem() == ModItems.upgrade) {
if (!this.mergeItemStack(itemStack1, 3, 6, false)) {
return null;
}
} else {
// otherwise just put it in one of the 3 other slots
if (!this.mergeItemStack(itemStack1, 1, 3, false)) {
return null;
}
} else if (slotNumber >= 30 && slotNumber < 39 && !this.mergeItemStack(itemStack1, 3, 30, false)) {
return null;
}
} else if (this.mergeItemStack(itemStack1, 3, 39, false)) {
return null;
}
if (itemStack1.stackSize == 0) {
@@ -61,6 +61,6 @@ public class ItemUpgrade extends BaseItem {
@Override
public String getUnlocalizedName(ItemStack stack) {
Upgrade[] upgrades = Upgrade.values();
return getUnlocalizedName() + "_" + upgrades[stack.getItemDamage() % upgrades.length].name().toLowerCase();
return upgrades[stack.getItemDamage() % upgrades.length].getUnlocalizedName();
}
}