diff options
Diffstat (limited to 'src')
11 files changed, 830 insertions, 256 deletions
diff --git a/src/main/java/lance5057/tDefense/core/blocks/ArmorStationBlock.java b/src/main/java/lance5057/tDefense/core/blocks/ArmorStationBlock.java new file mode 100644 index 0000000..71abf9f --- /dev/null +++ b/src/main/java/lance5057/tDefense/core/blocks/ArmorStationBlock.java @@ -0,0 +1,62 @@ +package lance5057.tDefense.core.blocks; + +import javax.annotation.Nonnull; + +import lance5057.tDefense.core.tileentities.ArmorStationTile; +import net.minecraft.block.SoundType; +import net.minecraft.block.material.Material; +import net.minecraft.block.properties.IProperty; +import net.minecraft.block.state.BlockStateContainer; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.common.property.ExtendedBlockState; +import net.minecraftforge.common.property.IUnlistedProperty; +import slimeknights.mantle.inventory.BaseContainer; +import slimeknights.tconstruct.TConstruct; +import slimeknights.tconstruct.library.TinkerRegistry; +import slimeknights.tconstruct.shared.block.BlockTable; +import slimeknights.tconstruct.tools.common.block.ITinkerStationBlock; + +public class ArmorStationBlock extends BlockTable implements ITinkerStationBlock { + + public ArmorStationBlock() { + super(Material.WOOD); + this.setCreativeTab(TinkerRegistry.tabGeneral); + this.setSoundType(SoundType.WOOD); + this.setResistance(5f); + this.setHardness(1f); + this.setHarvestLevel("axe", 0); + } + + @Nonnull + @Override + public TileEntity createNewTileEntity(@Nonnull World worldIn, int meta) { + return new ArmorStationTile(); + } + + @Nonnull + @Override + protected BlockStateContainer createBlockState() { + return new ExtendedBlockState(this, new IProperty[]{}, new IUnlistedProperty[]{TEXTURE, INVENTORY, FACING}); + } + + @Override + public boolean openGui(EntityPlayer player, World world, BlockPos pos) { + if(!world.isRemote) { + player.openGui(TConstruct.instance, 0, world, pos.getX(), pos.getY(), pos.getZ()); + if(player.openContainer instanceof BaseContainer) { + ((BaseContainer) player.openContainer).syncOnOpen((EntityPlayerMP) player); + } + } + return true; + } + + @Override + public int getGuiNumber(IBlockState state) { + return 55; + } +}
\ No newline at end of file diff --git a/src/main/java/lance5057/tDefense/core/blocks/Stations.java b/src/main/java/lance5057/tDefense/core/blocks/Stations.java deleted file mode 100644 index eea9afb..0000000 --- a/src/main/java/lance5057/tDefense/core/blocks/Stations.java +++ /dev/null @@ -1,243 +0,0 @@ -//package lance5057.tDefense.core.blocks; -// -//import java.util.List; -//import java.util.Locale; -// -//import javax.annotation.Nonnull; -// -//import com.google.common.collect.Lists; -// -//import net.minecraft.block.Block; -//import net.minecraft.block.SoundType; -//import net.minecraft.block.material.Material; -//import net.minecraft.block.properties.IProperty; -//import net.minecraft.block.properties.PropertyEnum; -//import net.minecraft.block.state.BlockStateContainer; -//import net.minecraft.block.state.IBlockState; -//import net.minecraft.creativetab.CreativeTabs; -//import net.minecraft.entity.player.EntityPlayer; -//import net.minecraft.entity.player.EntityPlayerMP; -//import net.minecraft.item.Item; -//import net.minecraft.item.ItemStack; -//import net.minecraft.tileentity.TileEntity; -//import net.minecraft.util.IStringSerializable; -//import net.minecraft.util.math.AxisAlignedBB; -//import net.minecraft.util.math.BlockPos; -//import net.minecraft.util.math.RayTraceResult; -//import net.minecraft.util.math.Vec3d; -//import net.minecraft.world.IBlockAccess; -//import net.minecraft.world.World; -//import net.minecraftforge.common.property.ExtendedBlockState; -//import net.minecraftforge.common.property.IUnlistedProperty; -//import net.minecraftforge.fml.relauncher.Side; -//import net.minecraftforge.fml.relauncher.SideOnly; -//import net.minecraftforge.oredict.OreDictionary; -//import slimeknights.mantle.inventory.BaseContainer; -//import slimeknights.tconstruct.TConstruct; -//import slimeknights.tconstruct.common.config.Config; -//import slimeknights.tconstruct.library.TinkerRegistry; -//import slimeknights.tconstruct.shared.block.BlockTable; -//import slimeknights.tconstruct.tools.common.block.ITinkerStationBlock; -//import slimeknights.tconstruct.tools.common.tileentity.TileCraftingStation; -//import slimeknights.tconstruct.tools.common.tileentity.TilePartBuilder; -//import slimeknights.tconstruct.tools.common.tileentity.TilePartChest; -//import slimeknights.tconstruct.tools.common.tileentity.TilePatternChest; -//import slimeknights.tconstruct.tools.common.tileentity.TileStencilTable; -//import slimeknights.tconstruct.tools.common.tileentity.TileToolStation; -// -//public class Stations extends BlockTable implements ITinkerStationBlock { -// -// public static final PropertyEnum<TableTypes> TABLES = PropertyEnum.func_177709_a("type", TableTypes.class); -// -// public Stations() { -// super(Material.field_151575_d); -// this.func_149647_a(TinkerRegistry.tabGeneral); -// -// this.func_149672_a(SoundType.field_185848_a); -// this.func_149752_b(5f); -// this.func_149711_c(1f); -// -// // set axe as effective tool for all variants -// this.setHarvestLevel("axe", 0); -// } -// -// -// @Nonnull -// @Override -// public TileEntity func_149915_a(@Nonnull World worldIn, int meta) { -// switch(TableTypes.fromMeta(meta)) { -// case CraftingStation: -// return new TileCraftingStation(); -// case StencilTable: -// return new TileStencilTable(); -// case PartBuilder: -// return new TilePartBuilder(); -// case ToolStation: -// return new TileToolStation(); -// case PatternChest: -// return new TilePatternChest(); -// case PartChest: -// return new TilePartChest(); -// default: -// return super.func_149915_a(worldIn, meta); -// } -// } -// -// @Override -// public boolean openGui(EntityPlayer player, World world, BlockPos pos) { -// if(!world.field_72995_K) { -// player.openGui(TConstruct.instance, 0, world, pos.func_177958_n(), pos.func_177956_o(), pos.func_177952_p()); -// if(player.field_71070_bA instanceof BaseContainer) { -// ((BaseContainer) player.field_71070_bA).syncOnOpen((EntityPlayerMP) player); -// } -// } -// return true; -// } -// -// @SideOnly(Side.CLIENT) -// @Override -// public void func_149666_a(@Nonnull Item itemIn, CreativeTabs tab, List<ItemStack> list) { -// // crafting station is boring -// list.add(new ItemStack(this, 1, TableTypes.CraftingStation.meta)); -// -// // planks for the stencil table -// addBlocksFromOredict("plankWood", TableTypes.StencilTable.meta, list); -// -// list.add(new ItemStack(this, 1, TableTypes.PatternChest.meta)); -// -// // logs for the part builder -// addBlocksFromOredict("logWood", TableTypes.PartBuilder.meta, list); -// -// list.add(new ItemStack(this, 1, TableTypes.PartChest.meta)); -// -// // stencil table is boring -// //addBlocksFromOredict("workbench", TableTypes.ToolStation.ordinal(), list); -// list.add(new ItemStack(this, 1, TableTypes.ToolStation.meta)); -// -// } -// -// private void addBlocksFromOredict(String oredict, int meta, List<ItemStack> list) { -// for(ItemStack stack : OreDictionary.getOres(oredict)) { -// Block block = func_149634_a(stack.func_77973_b()); -// int blockMeta = stack.func_77952_i(); -// -// if(blockMeta == OreDictionary.WILDCARD_VALUE) { -// List<ItemStack> subBlocks = Lists.newLinkedList(); -// block.func_149666_a(stack.func_77973_b(), null, subBlocks); -// -// for(ItemStack subBlock : subBlocks) { -// list.add(createItemstack(this, meta, func_149634_a(subBlock.func_77973_b()), subBlock.func_77952_i())); -// if(!Config.listAllTables) { -// return; -// } -// } -// } -// else { -// list.add(createItemstack(this, meta, block, blockMeta)); -// if(!Config.listAllTables) { -// return; -// } -// } -// } -// } -// -// @Override -// protected boolean keepInventory(IBlockState state) { -// return Config.chestsKeepInventory && -// (state.func_177229_b(TABLES) == TableTypes.PatternChest || state.func_177229_b(TABLES) == TableTypes.PartChest); -// } -// -// @Nonnull -// @Override -// protected BlockStateContainer func_180661_e() { -// return new ExtendedBlockState(this, new IProperty[]{TABLES}, new IUnlistedProperty[]{TEXTURE, INVENTORY, FACING}); -// } -// -// @Nonnull -// @Override -// public IBlockState func_176203_a(int meta) { -// return this.func_176223_P().func_177226_a(TABLES, TableTypes.fromMeta(meta)); -// } -// -// @Override -// public int func_176201_c(IBlockState state) { -// return (state.func_177229_b(TABLES)).meta; -// } -// -// /* Bounds */ -// private static AxisAlignedBB BOUNDS_Chest = new AxisAlignedBB(0, 0, 0, 1, 0.875, 1); -// -// @Nonnull -// @Override -// public AxisAlignedBB func_185496_a(IBlockState state, IBlockAccess source, BlockPos pos) { -// if(state.func_177229_b(TABLES).isChest) { -// return BOUNDS_Chest; -// } -// -// return super.func_185496_a(state, source, pos); -// } -// -// @Override -// public RayTraceResult func_180636_a(IBlockState blockState, @Nonnull World worldIn, @Nonnull BlockPos pos, @Nonnull Vec3d start, @Nonnull Vec3d end) { -// if(blockState.func_177229_b(TABLES).isChest) { -// return func_185503_a(pos, start, end, BOUNDS_Chest); -// } -// -// return super.func_180636_a(blockState, worldIn, pos, start, end); -// } -// -// @Override -// public int getGuiNumber(IBlockState state) { -// switch(state.func_177229_b(TABLES)) { -// case StencilTable: -// return 10; -// case PatternChest: -// return 15; -// case PartChest: -// return 16; -// case PartBuilder: -// return 20; -// case ToolStation: -// return 25; -// case CraftingStation: -// return 50; -// default: -// return 0; -// } -// } -// -// public enum TableTypes implements IStringSerializable { -// CraftingStation, -// StencilTable, -// PartBuilder, -// ToolStation, -// PatternChest(true), -// PartChest(true); -// -// TableTypes() { -// meta = this.ordinal(); -// this.isChest = false; -// } -// -// TableTypes(boolean chest) { -// meta = this.ordinal(); -// this.isChest = chest; -// } -// -// public final int meta; -// public final boolean isChest; -// -// public static TableTypes fromMeta(int meta) { -// if(meta < 0 || meta >= values().length) { -// meta = 0; -// } -// -// return values()[meta]; -// } -// -// @Override -// public String func_176610_l() { -// return this.toString().toLowerCase(Locale.US); -// } -// } -//} diff --git a/src/main/java/lance5057/tDefense/core/gui/ArmorStationContainer.java b/src/main/java/lance5057/tDefense/core/gui/ArmorStationContainer.java new file mode 100644 index 0000000..c0b7016 --- /dev/null +++ b/src/main/java/lance5057/tDefense/core/gui/ArmorStationContainer.java @@ -0,0 +1,6 @@ +package lance5057.tDefense.core.gui; + +public class ArmorStationContainer +{ + +} diff --git a/src/main/java/lance5057/tDefense/core/gui/ArmorStationGui.java b/src/main/java/lance5057/tDefense/core/gui/ArmorStationGui.java new file mode 100644 index 0000000..8bcea9c --- /dev/null +++ b/src/main/java/lance5057/tDefense/core/gui/ArmorStationGui.java @@ -0,0 +1,577 @@ +package lance5057.tDefense.core.gui; + +import java.io.IOException; +import java.util.List; +import java.util.Set; + +import org.lwjgl.input.Keyboard; +import org.lwjgl.util.Point; + +import com.google.common.collect.Lists; + +import lance5057.tDefense.core.tools.bases.ArmorCore; +import lance5057.tDefense.util.ArmorBuildGuiInfo; +import lance5057.tDefense.util.TDClientRegistry; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiTextField; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Slot; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.util.text.translation.I18n; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import slimeknights.mantle.client.gui.GuiElement; +import slimeknights.mantle.client.gui.GuiElementScalable; +import slimeknights.mantle.client.gui.GuiModule; +import slimeknights.tconstruct.common.TinkerNetwork; +import slimeknights.tconstruct.library.TinkerRegistry; +import slimeknights.tconstruct.library.TinkerRegistryClient; +import slimeknights.tconstruct.library.Util; +import slimeknights.tconstruct.library.client.Icons; +import slimeknights.tconstruct.library.client.ToolBuildGuiInfo; +import slimeknights.tconstruct.library.modifiers.IModifier; +import slimeknights.tconstruct.library.modifiers.ModifierNBT; +import slimeknights.tconstruct.library.tinkering.IModifyable; +import slimeknights.tconstruct.library.tinkering.IToolStationDisplay; +import slimeknights.tconstruct.library.tinkering.PartMaterialType; +import slimeknights.tconstruct.library.tinkering.TinkersItem; +import slimeknights.tconstruct.library.tools.IToolPart; +import slimeknights.tconstruct.library.tools.ToolCore; +import slimeknights.tconstruct.library.utils.TagUtil; +import slimeknights.tconstruct.tools.common.client.GuiButtonRepair; +import slimeknights.tconstruct.tools.common.client.GuiTinkerStation; +import slimeknights.tconstruct.tools.common.client.module.GuiButtonsToolStation; +import slimeknights.tconstruct.tools.common.client.module.GuiInfoPanel; +import slimeknights.tconstruct.tools.common.inventory.ContainerTinkerStation; +import slimeknights.tconstruct.tools.common.inventory.ContainerToolStation; +import slimeknights.tconstruct.tools.common.inventory.SlotToolStationIn; +import slimeknights.tconstruct.tools.common.network.ToolStationSelectionPacket; +import slimeknights.tconstruct.tools.common.network.ToolStationTextPacket; +import slimeknights.tconstruct.tools.common.tileentity.TileToolStation; + +@SideOnly(Side.CLIENT) +public class ArmorStationGui extends GuiTinkerStation { + + private static final ResourceLocation BACKGROUND = Util.getResource("textures/gui/toolstation.png"); + + private static final GuiElement TextFieldActive = new GuiElement(0, 210, 102, 12, 256, 256); + private static final GuiElement ItemCover = new GuiElement(176, 18, 80, 64); + private static final GuiElement SlotBackground = new GuiElement(176, 0, 18, 18); + private static final GuiElement SlotBorder = new GuiElement(194, 0, 18, 18); + + private static final GuiElement SlotSpaceTop = new GuiElement(0, 174 + 2, 18, 2); + private static final GuiElement SlotSpaceBottom = new GuiElement(0, 174, 18, 2); + private static final GuiElement PanelSpaceL = new GuiElement(0, 174, 5, 4); + private static final GuiElement PanelSpaceR = new GuiElement(9, 174, 9, 4); + + private static final GuiElement BeamLeft = new GuiElement(0, 180, 2, 7); + private static final GuiElement BeamRight = new GuiElement(131, 180, 2, 7); + private static final GuiElementScalable BeamCenter = new GuiElementScalable(2, 180, 129, 7); + + public static final int Column_Count = 5; + private static final int Table_slot_count = 6; + + protected GuiElement buttonDecorationTop = SlotSpaceTop; + protected GuiElement buttonDecorationBot = SlotSpaceBottom; + protected GuiElement panelDecorationL = PanelSpaceL; + protected GuiElement panelDecorationR = PanelSpaceR; + + protected GuiElement beamL = new GuiElement(0, 0, 0, 0); + protected GuiElement beamR = new GuiElement(0, 0, 0, 0); + protected GuiElementScalable beamC = new GuiElementScalable(0, 0, 0, 0); + + protected ArmorStationGuiButtons buttons; + protected int activeSlots; // how many of the available slots are active + + public GuiTextField textField; + + protected GuiInfoPanel toolInfo; + protected GuiInfoPanel traitInfo; + + public ArmorBuildGuiInfo currentInfo = ArmorStationGuiButtonRepair.info; + + public ArmorStationGui(InventoryPlayer playerInv, World world, BlockPos pos, TileToolStation tile) { + super(world, pos, (ContainerTinkerStation) tile.createContainer(playerInv, world, pos)); + + buttons = new ArmorStationGuiButtons(this, inventorySlots); + this.addModule(buttons); + toolInfo = new GuiInfoPanel(this, inventorySlots); + this.addModule(toolInfo); + traitInfo = new GuiInfoPanel(this, inventorySlots); + this.addModule(traitInfo); + + toolInfo.yOffset = 5; + traitInfo.yOffset = toolInfo.getYSize() + 9; + + this.ySize = 174; + + wood(); + } + + @Override + public void initGui() { + super.initGui(); + Keyboard.enableRepeatEvents(true); + + // workaround to line up the tabs on switching even though the GUI is a tad higher + this.guiTop += 4; + this.cornerY += 4; + + textField = new GuiTextField(0, fontRenderer, cornerX + 70, cornerY + 7, 92, 12); + //textField.setFocused(true); + //textField.setCanLoseFocus(false); + textField.setEnableBackgroundDrawing(false); + textField.setMaxStringLength(40); + + buttons.xOffset = -2; + buttons.yOffset = beamC.h + buttonDecorationTop.h; + toolInfo.xOffset = 2; + toolInfo.yOffset = beamC.h + panelDecorationL.h; + traitInfo.xOffset = toolInfo.xOffset; + traitInfo.yOffset = toolInfo.yOffset + toolInfo.getYSize() + 4; + +// for(GuiModule module : modules) { +// module.guiTop += 4; +// } + + updateGUI(); + } + + @Override + public void onGuiClosed() { + super.onGuiClosed(); + Keyboard.enableRepeatEvents(false); + } + + public Set<ToolCore> getBuildableItems() { + return TinkerRegistry.getToolStationCrafting(); + } + + public void onToolSelection(ArmorBuildGuiInfo data) { + activeSlots = Math.min(data.positions.size(), Table_slot_count); + currentInfo = data; + + ToolCore tool = null; + + if(data.armor.getItem() instanceof ToolCore) { + tool = (ToolCore) data.armor.getItem(); + } + + ((ContainerToolStation) inventorySlots).setToolSelection(tool, activeSlots); + // update the server (and others) + TinkerNetwork.sendToServer(new ToolStationSelectionPacket(tool, activeSlots)); + updateGUI(); + } + + public void onToolSelectionPacket(ToolStationSelectionPacket packet) { + ArmorBuildGuiInfo info = TDClientRegistry.getArmorBuildInfoForArmor(packet.tool); + if(info == null) { + info = ArmorStationGuiButtonRepair.info; + } + activeSlots = packet.activeSlots; + currentInfo = info; + + buttons.setSelectedButtonByTool(currentInfo.armor); + + updateGUI(); + } + + public void updateGUI() { + int i; + for(i = 0; i < activeSlots; i++) { + Point point = currentInfo.positions.get(i); + + Slot slot = inventorySlots.getSlot(i); + slot.xPos = point.getX(); + slot.yPos = point.getY(); + } + + // remaining slots + int stillFilled = 0; + for(; i < Table_slot_count; i++) { + Slot slot = inventorySlots.getSlot(i); + + if(slot.getHasStack()) { + slot.xPos = 87 + 20 * stillFilled; + slot.yPos = 62; + stillFilled++; + } + else { + // todo: slot.disable + slot.xPos = 0; + slot.yPos = 0; + } + } + + updateDisplay(); + } + + @Override + public void updateDisplay() { + // tool info of existing or tool to build + ContainerToolStation container = (ContainerToolStation) inventorySlots; + ItemStack toolStack = container.getResult(); + if(toolStack.isEmpty()) { + toolStack = inventorySlots.getSlot(0).getStack(); + } + + // current tool to build or repair/modify + if(toolStack.getItem() instanceof IModifyable) { + if(toolStack.getItem() instanceof IToolStationDisplay) { + IToolStationDisplay tool = (IToolStationDisplay) toolStack.getItem(); + toolInfo.setCaption(tool.getLocalizedToolName()); + toolInfo.setText(tool.getInformation(toolStack)); + } + else { + toolInfo.setCaption(toolStack.getDisplayName()); + toolInfo.setText(); + } + + traitInfo.setCaption(I18n.translateToLocal("gui.toolstation.traits")); + + List<String> mods = Lists.newLinkedList(); + List<String> tips = Lists.newLinkedList(); + NBTTagList tagList = TagUtil.getModifiersTagList(toolStack); + for(int i = 0; i < tagList.tagCount(); i++) { + NBTTagCompound tag = tagList.getCompoundTagAt(i); + ModifierNBT data = ModifierNBT.readTag(tag); + + // get matching modifier + IModifier modifier = TinkerRegistry.getModifier(data.identifier); + if(modifier == null || modifier.isHidden()) { + continue; + } + + mods.add(data.getColorString() + modifier.getTooltip(tag, true)); + tips.add(data.getColorString() + modifier.getLocalizedDesc()); + } + + if(mods.isEmpty()) { + mods.add(I18n.translateToLocal("gui.toolstation.noTraits")); + } + + traitInfo.setText(mods, tips); + } + // repair info + else if(currentInfo.armor.isEmpty()) { + toolInfo.setCaption(I18n.translateToLocal("gui.toolstation.repair")); + toolInfo.setText(); + + traitInfo.setCaption(null); + String c = TextFormatting.DARK_GRAY.toString(); + String[] art = new String[]{ + c + "", + c + "", + c + " .", + c + " /( _________", + c + " | >:=========`", + c + " )( ", + c + " \"\"" + }; + traitInfo.setText(art); + } + // tool build info + else { + ArmorCore tool = (ArmorCore) currentInfo.armor.getItem(); + toolInfo.setCaption(tool.getLocalizedToolName()); + toolInfo.setText(tool.getLocalizedDescription()); + + // Components + List<String> text = Lists.newLinkedList(); + List<PartMaterialType> pms = tool.getRequiredComponents(); + for(int i = 0; i < pms.size(); i++) { + PartMaterialType pmt = pms.get(i); + StringBuilder sb = new StringBuilder(); + + ItemStack slotStack = container.getSlot(i).getStack(); + if(!pmt.isValid(slotStack)) { + sb.append(TextFormatting.RED); + + // is an item in the slot? + if(slotStack.getItem() instanceof IToolPart) { + if(pmt.isValidItem((IToolPart) slotStack.getItem())) { + // the item has an invalid material + warning(Util.translate("gui.error.wrong_material_part")); + } + } + } + + sb.append(" * "); + for(IToolPart part : pmt.getPossibleParts()) { + if(part instanceof Item) { + sb.append(((Item) part).getItemStackDisplayName(new ItemStack((Item) part))); + sb.append("/"); + } + } + sb.deleteCharAt(sb.length() - 1); // removes last '/' + text.add(sb.toString()); + } + traitInfo.setCaption(I18n.translateToLocal("gui.toolstation.components")); + traitInfo.setText(text.toArray(new String[text.size()])); + } + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + super.mouseClicked(mouseX, mouseY, mouseButton); + textField.mouseClicked(mouseX, mouseY, mouseButton); + } + + @Override + protected void keyTyped(char typedChar, int keyCode) throws IOException { + if(!textField.isFocused()) { + super.keyTyped(typedChar, keyCode); + } + else { + if(keyCode == 1) { + this.mc.player.closeScreen(); + } + + textField.textboxKeyTyped(typedChar, keyCode); + TinkerNetwork.sendToServer(new ToolStationTextPacket(textField.getText())); + ((ContainerToolStation) container).setToolName(textField.getText()); + } + } + + @Override + public void updateScreen() { + super.updateScreen(); + textField.updateCursorCounter(); + } + + @Override + public void drawSlot(Slot slotIn) { + // don't draw dormant slots with no item + if(slotIn instanceof SlotToolStationIn && ((SlotToolStationIn) slotIn).isDormant() && !slotIn.getHasStack()) { + return; + } + + super.drawSlot(slotIn); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { + drawBackground(BACKGROUND); + + if(textField.isFocused()) { + TextFieldActive.draw(cornerX + 68, cornerY + 6); + } + + // draw textfield + textField.drawTextBox(); + + //int xOff = 3; + //int yOff = 6; + + int x = 0; + int y = 0; + + // draw the item background + final float scale = 3.7f; + final float xOff = 10f; + final float yOff = 22f; + GlStateManager.translate(xOff, yOff, 0); + GlStateManager.scale(scale, scale, 1.0f); + { + int logoX = (int) (this.cornerX / scale); + int logoY = (int) (this.cornerY / scale); + + if(currentInfo != null) { + if(!currentInfo.armor.isEmpty()) { + itemRender.renderItemIntoGUI(currentInfo.armor, logoX, logoY); + } + else if(currentInfo == ArmorStationGuiButtonRepair.info) { + this.mc.getTextureManager().bindTexture(Icons.ICON); + Icons.ICON_Anvil.draw(logoX, logoY); + } + } + } + GlStateManager.scale(1f / scale, 1f / scale, 1.0f); + GlStateManager.translate(-xOff, -yOff, 0); + + // rebind gui texture since itemstack drawing sets it to something else + this.mc.getTextureManager().bindTexture(BACKGROUND); + + // reset state after item drawing + GlStateManager.enableBlend(); + GlStateManager.enableAlpha(); + RenderHelper.disableStandardItemLighting(); + GlStateManager.disableDepth(); + + // draw the halftransparent "cover" over the item + GlStateManager.color(1.0f, 1.0f, 1.0f, 0.82f); + ItemCover.draw(this.cornerX + 7, this.cornerY + 18); + + // the slot backgrounds + GlStateManager.color(1.0f, 1.0f, 1.0f, 0.28f); + for(int i = 0; i < activeSlots; i++) { + Slot slot = inventorySlots.getSlot(i); + SlotBackground.draw(x + this.cornerX + slot.xPos - 1, y + this.cornerY + slot.yPos - 1); + } + + // full opaque. Draw the borders of the slots + GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f); + for(int i = 0; i < Table_slot_count; i++) { + Slot slot = inventorySlots.getSlot(i); + if(slot instanceof SlotToolStationIn && (!((SlotToolStationIn) slot).isDormant() || slot.getHasStack())) { + SlotBorder.draw( + x + this.cornerX + slot.xPos - 1, y + this.cornerY + slot.yPos - 1); + } + } + + this.mc.getTextureManager().bindTexture(Icons.ICON); + + // slot logos + if(currentInfo == ArmorStationGuiButtonRepair.info) { + drawRepairSlotIcons(); + } + else if(currentInfo.armor.getItem() instanceof TinkersItem) { + for(int i = 0; i < activeSlots; i++) { + Slot slot = inventorySlots.getSlot(i); + if(!(slot instanceof SlotToolStationIn)) { + continue; + } + + ItemStack stack = ((SlotToolStationIn) slot).icon; + if(stack == null) { + continue; + } + + itemRender.renderItemIntoGUI(stack, + x + this.cornerX + slot.xPos, + y + this.cornerY + slot.yPos); + } + } + + this.mc.getTextureManager().bindTexture(BACKGROUND); + x = buttons.getGuiLeft() - beamL.w; + y = cornerY; + // draw the beams at the top + x += beamL.draw(x, y); + x += beamC.drawScaledX(x, y, buttons.getXSize()); + beamR.draw(x, y); + + x = toolInfo.getGuiLeft() - beamL.w; + x += beamL.draw(x, y); + x += beamC.drawScaledX(x, y, toolInfo.getXSize()); + beamR.draw(x, y); + + // draw the decoration for the buttons +// for(Object o : buttons.buttonList) { +// GuiButton button = (GuiButton) o; +// +// buttonDecorationTop.draw(button.x, button.y - buttonDecorationTop.h); +// // don't draw the bottom for the buttons in the last row +// if(button.id < buttons.buttonList.size() - Column_Count) { +// buttonDecorationBot.draw(button.x, button.y + button.height); +// } +// } + + // draw the decorations for the panels + panelDecorationL.draw(toolInfo.getGuiLeft() + 5, toolInfo.getGuiTop() - panelDecorationL.h); + panelDecorationR.draw(toolInfo.guiRight() - 5 - panelDecorationR.w, toolInfo.getGuiTop() - panelDecorationR.h); + panelDecorationL.draw(traitInfo.getGuiLeft() + 5, traitInfo.getGuiTop() - panelDecorationL.h); + panelDecorationR.draw(traitInfo.guiRight() - 5 - panelDecorationR.w, traitInfo.getGuiTop() - panelDecorationR.h); + + GlStateManager.enableDepth(); + + // continue as usual and hope that the drawing state is not completely wrecked + super.drawGuiContainerBackgroundLayer(partialTicks, mouseX, mouseY); + } + + protected void drawRepairSlotIcons() { + for(int i = 0; i < activeSlots; i++) { + drawRepairSlotIcon(i); + } + } + + protected void drawRepairSlotIcon(int i) { + GuiElement icon = null; + Slot slot = inventorySlots.getSlot(i); + // only empty solts get the logo since something else than the displayed thing might be in there. + // which would look weird. + if(slot.getHasStack()) { + return; + } + + if(i == 0) { + icon = Icons.ICON_Pickaxe; + } + else if(i == 1) { + icon = Icons.ICON_Dust; + } + else if(i == 2) { + icon = Icons.ICON_Lapis; + } + else if(i == 3) { + icon = Icons.ICON_Ingot; + } + else if(i == 4) { + icon = Icons.ICON_Gem; + } + else if(i == 5) { + icon = Icons.ICON_Quartz; + } + + if(icon != null) { + drawIconEmpty(slot, icon); + } + } + + protected void wood() { + toolInfo.wood(); + traitInfo.wood(); + + buttonDecorationTop = SlotSpaceTop.shift(SlotSpaceTop.w, 0); + buttonDecorationBot = SlotSpaceBottom.shift(SlotSpaceBottom.w, 0); + panelDecorationL = PanelSpaceL.shift(18, 0); + panelDecorationR = PanelSpaceR.shift(18, 0); + + buttons.wood(); + + beamL = BeamLeft; + beamR = BeamRight; + beamC = BeamCenter; + } + + protected void metal() { + toolInfo.metal(); + traitInfo.metal(); + + buttonDecorationTop = SlotSpaceTop.shift(SlotSpaceTop.w * 2, 0); + buttonDecorationBot = SlotSpaceBottom.shift(SlotSpaceBottom.w * 2, 0); + panelDecorationL = PanelSpaceL.shift(18 * 2, 0); + panelDecorationR = PanelSpaceR.shift(18 * 2, 0); + + buttons.metal(); + + beamL = BeamLeft.shift(0, BeamLeft.h); + beamR = BeamRight.shift(0, BeamRight.h); + beamC = BeamCenter.shift(0, BeamCenter.h); + } + + @Override + public void error(String message) { + toolInfo.setCaption(I18n.translateToLocal("gui.error")); + toolInfo.setText(message); + traitInfo.setCaption(null); + traitInfo.setText(); + } + + @Override + public void warning(String message) { + toolInfo.setCaption(I18n.translateToLocal("gui.warning")); + toolInfo.setText(message); + traitInfo.setCaption(null); + traitInfo.setText(); + } +}
\ No newline at end of file diff --git a/src/main/java/lance5057/tDefense/core/gui/ArmorStationGuiButtonRepair.java b/src/main/java/lance5057/tDefense/core/gui/ArmorStationGuiButtonRepair.java new file mode 100644 index 0000000..dba33e8 --- /dev/null +++ b/src/main/java/lance5057/tDefense/core/gui/ArmorStationGuiButtonRepair.java @@ -0,0 +1,38 @@ +package lance5057.tDefense.core.gui; + +import lance5057.tDefense.util.ArmorBuildGuiInfo; +import net.minecraft.client.Minecraft; +import net.minecraft.util.text.translation.I18n; +import slimeknights.tconstruct.library.client.Icons; +import slimeknights.tconstruct.library.client.ToolBuildGuiInfo; +import slimeknights.tconstruct.tools.common.client.GuiButtonItem; + +public class ArmorStationGuiButtonRepair extends GuiButtonItem<ArmorBuildGuiInfo> { + + public static final ArmorBuildGuiInfo info; + + public ArmorStationGuiButtonRepair(int buttonId, int x, int y) { + super(buttonId, x, y, I18n.translateToLocal("gui.repair"), info); + } + + @Override + protected void drawIcon(Minecraft mc) { + mc.getTextureManager().bindTexture(Icons.ICON); + Icons.ICON_Anvil.draw(x, y); + } + + static { + int x = 7 + 80 / 2 - 8 - 6; + int y = 18 + 64 / 2 - 8; + + info = new ArmorBuildGuiInfo(); + + info.addSlotPosition(x, y); + + info.addSlotPosition(x - 18, y + 20); // -20,+20 + info.addSlotPosition(x - 22, y - 5); // -22, -7 + info.addSlotPosition(x, y - 23); // +-0, -21 + info.addSlotPosition(x + 22, y - 5); // +22, -7 + info.addSlotPosition(x + 18, y + 20); // +20,+20 + } +}
\ No newline at end of file diff --git a/src/main/java/lance5057/tDefense/core/gui/ArmorStationGuiButtons.java b/src/main/java/lance5057/tDefense/core/gui/ArmorStationGuiButtons.java new file mode 100644 index 0000000..d89b002 --- /dev/null +++ b/src/main/java/lance5057/tDefense/core/gui/ArmorStationGuiButtons.java @@ -0,0 +1,115 @@ +package lance5057.tDefense.core.gui; + +import java.io.IOException; + +import lance5057.tDefense.util.ArmorBuildGuiInfo; +import lance5057.tDefense.util.TDClientRegistry; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.inventory.Container; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import slimeknights.tconstruct.library.client.Icons; +import slimeknights.tconstruct.library.client.ToolBuildGuiInfo; +import slimeknights.tconstruct.tools.common.client.GuiButtonItem; +import slimeknights.tconstruct.tools.common.client.GuiToolStation; +import slimeknights.tconstruct.tools.common.client.module.GuiSideButtons; + +public class ArmorStationGuiButtons extends GuiSideButtons { + + protected final ArmorStationGui parent; + + public ArmorStationGuiButtons(ArmorStationGui parent, Container container) { + super(parent, container, GuiToolStation.Column_Count); + + this.parent = parent; + } + + protected int selected = 0; + + private int style = 0; + + + @Override + public void updatePosition(int parentX, int parentY, int parentSizeX, int parentSizeY) { + super.updatePosition(parentX, parentY, parentSizeX, parentSizeY); + + int index = 0; + buttonCount = 0; + + { + GuiButtonItem<ArmorBuildGuiInfo> button = new ArmorStationGuiButtonRepair(index++, -1, -1); + shiftButton(button, 0, -18 * style); + addSideButton(button); + } + + for(Item item : parent.getBuildableItems()) { + ArmorBuildGuiInfo info = TDClientRegistry.getArmorBuildInfoForArmor(item); + if(info != null) { + GuiButtonItem<ArmorBuildGuiInfo> button = new GuiButtonItem<ArmorBuildGuiInfo>(index++, -1, -1, info.armor, info); + shiftButton(button, 0, -18 * style); + addSideButton(button); + + if(index - 1 == selected) { + button.pressed = true; + } + } + } + + super.updatePosition(parentX, parentY, parentSizeX, parentSizeY); + + // activate currently selected/default + parent.updateGUI(); + } + + public void setSelectedButtonByTool(ItemStack stack) { + for(Object o : buttonList) { + if(o instanceof GuiButtonItem) { + @SuppressWarnings("unchecked") + GuiButtonItem<ToolBuildGuiInfo> btn = (GuiButtonItem<ToolBuildGuiInfo>) o; + btn.pressed = ItemStack.areItemStacksEqual(btn.data.tool, stack); + } + } + } + + + @Override + @SuppressWarnings("unchecked") + protected void actionPerformed(GuiButton button) throws IOException { + for(Object o : buttonList) { + if(o instanceof GuiButtonItem) { + ((GuiButtonItem<ArmorBuildGuiInfo>) o).pressed = false; + } + } + if(button instanceof GuiButtonItem) { + ((GuiButtonItem<ArmorBuildGuiInfo>) button).pressed = true; + selected = button.id; + + parent.onToolSelection(((GuiButtonItem<ArmorBuildGuiInfo>) button).data); + } + } + + @SuppressWarnings("unchecked") + public void wood() { + for(Object o : buttonList) { + shiftButton((GuiButtonItem<ArmorBuildGuiInfo>) o, 0, -36); + } + + style = 2; + } + + @SuppressWarnings("unchecked") + public void metal() { + for(Object o : buttonList) { + shiftButton((GuiButtonItem<ArmorBuildGuiInfo>) o, 0, -18); + } + + style = 1; + } + + protected void shiftButton(GuiButtonItem<ArmorBuildGuiInfo> button, int xd, int yd) { + button.setGraphics(Icons.ICON_Button.shift(xd, yd), + Icons.ICON_ButtonHover.shift(xd, yd), + Icons.ICON_ButtonPressed.shift(xd, yd), + Icons.ICON); + } +}
\ No newline at end of file diff --git a/src/main/java/lance5057/tDefense/core/items/TDOreDictItem.java b/src/main/java/lance5057/tDefense/core/items/TDOreDictItem.java index 13627f3..7391c75 100644 --- a/src/main/java/lance5057/tDefense/core/items/TDOreDictItem.java +++ b/src/main/java/lance5057/tDefense/core/items/TDOreDictItem.java @@ -71,7 +71,7 @@ public class TDOreDictItem extends Item { @SideOnly(Side.CLIENT) public static class ColorHandler implements IItemColor { @Override - public int getColorFromItemstack(ItemStack stack, int tintIndex) { + public int colorMultiplier(ItemStack stack, int tintIndex) { if (tintIndex == 0) { if (stack.getItem() instanceof TDOreDictItem) { return ((TDOreDictItem) stack.getItem()).getColor(stack); diff --git a/src/main/java/lance5057/tDefense/core/tileentities/ArmorStationTile.java b/src/main/java/lance5057/tDefense/core/tileentities/ArmorStationTile.java new file mode 100644 index 0000000..e2d3654 --- /dev/null +++ b/src/main/java/lance5057/tDefense/core/tileentities/ArmorStationTile.java @@ -0,0 +1,29 @@ +package lance5057.tDefense.core.tileentities; + +import lance5057.tDefense.core.gui.ArmorStationGui; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import slimeknights.tconstruct.tools.common.tileentity.TileToolStation; + +public class ArmorStationTile extends TileToolStation { + + public ArmorStationTile() { + inventoryTitle = "armorstation.name"; + } + + @Override + @SideOnly(Side.CLIENT) + public GuiContainer createGui(InventoryPlayer inventoryPlayer, World world, BlockPos pos) { + return new ArmorStationGui(inventoryPlayer, world, pos, this); + } + + @Override + public Container createContainer(InventoryPlayer inventoryPlayer, World world, BlockPos pos) { + return new ArmorStationContainer(inventoryPlayer, this, false); + } +}
\ No newline at end of file diff --git a/src/main/java/lance5057/tDefense/core/tools/TDToolEvents.java b/src/main/java/lance5057/tDefense/core/tools/TDToolEvents.java index cbecb12..1214fae 100644 --- a/src/main/java/lance5057/tDefense/core/tools/TDToolEvents.java +++ b/src/main/java/lance5057/tDefense/core/tools/TDToolEvents.java @@ -19,11 +19,6 @@ import slimeknights.tconstruct.library.utils.ToolHelper; public class TDToolEvents { - ItemStack prevHead = new ItemStack(Items.AIR); - ItemStack prevChest = new ItemStack(Items.AIR); - ItemStack prevLegs = new ItemStack(Items.AIR); - ItemStack prevFeet = new ItemStack(Items.AIR); - public TDToolEvents() { } @@ -57,11 +52,6 @@ public class TDToolEvents { @SubscribeEvent public void ArmorTick(TickEvent.PlayerTickEvent event) { - prevFeet = armorChanged(event, prevFeet, event.player.inventory.armorInventory.get(0)); - prevLegs = armorChanged(event, prevLegs, event.player.inventory.armorInventory.get(1)); - prevChest = armorChanged(event, prevChest, event.player.inventory.armorInventory.get(2)); - prevHead = armorChanged(event, prevHead, event.player.inventory.armorInventory.get(3)); - onArmorTick(event); } diff --git a/src/main/java/lance5057/tDefense/core/tools/basic/Shears.java b/src/main/java/lance5057/tDefense/core/tools/basic/Shears.java index 16ef196..f2442be 100644 --- a/src/main/java/lance5057/tDefense/core/tools/basic/Shears.java +++ b/src/main/java/lance5057/tDefense/core/tools/basic/Shears.java @@ -70,7 +70,7 @@ public class Shears extends ToolCore { public float getStrVsBlock(ItemStack stack, IBlockState state) { Block block = state.getBlock(); - return block != Blocks.WEB && state.getMaterial() != net.minecraft.block.material.Material.LEAVES ? (block == Blocks.WOOL ? 5.0F : super.getStrVsBlock(stack, state)) : 15.0F; + return block != Blocks.WEB && state.getMaterial() != net.minecraft.block.material.Material.LEAVES ? (block == Blocks.WOOL ? 5.0F : 15f) : 15.0F; } diff --git a/src/main/java/lance5057/tDefense/core/tools/basic/Zweihander.java b/src/main/java/lance5057/tDefense/core/tools/basic/Zweihander.java index 19934db..b9fdb82 100644 --- a/src/main/java/lance5057/tDefense/core/tools/basic/Zweihander.java +++ b/src/main/java/lance5057/tDefense/core/tools/basic/Zweihander.java @@ -61,7 +61,7 @@ public class Zweihander extends SwordCore { EntityLivingBase.class, entity.getEntityBoundingBox().expand(2.0D, 0.25D, 2.0D))) { if (entitylivingbase != player && entitylivingbase != entity && !player.isOnSameTeam(entitylivingbase) - && player.getDistanceSqToEntity(entitylivingbase) < 9.0D) { + && player.getDistanceSq(entitylivingbase) < 9.0D) { entitylivingbase.knockBack(player, 0.4F, (double) MathHelper.sin(player.rotationYaw * 0.017453292F), (double) (-MathHelper.cos(player.rotationYaw * 0.017453292F))); |
