quick and dirty port to 1.16.4
This commit is contained in:
@@ -1,33 +1,16 @@
|
||||
package de.skate702.craftingkeys;
|
||||
|
||||
|
||||
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraft.client.gui.screen.EnchantmentScreen;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.inventory.*;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
import net.minecraftforge.fml.common.Mod.Instance;
|
||||
import net.minecraftforge.fml.common.SidedProxy;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.InputEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import de.skate702.craftingkeys.config.Config;
|
||||
import de.skate702.craftingkeys.config.GuiConfig;
|
||||
import de.skate702.craftingkeys.config.GuiConfigHandler;
|
||||
import de.skate702.craftingkeys.config.KeyBindings;
|
||||
import de.skate702.craftingkeys.manager.*;
|
||||
import de.skate702.craftingkeys.proxies.CraftingKeysProxy;
|
||||
import de.skate702.craftingkeys.util.Logger;
|
||||
import de.skate702.craftingkeys.util.Util;
|
||||
import net.minecraft.client.gui.GuiEnchantment;
|
||||
import net.minecraft.client.gui.GuiMerchant;
|
||||
import net.minecraft.client.gui.GuiRepair;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.inventory.*;
|
||||
import net.minecraftforge.client.event.GuiOpenEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
/**
|
||||
@@ -36,7 +19,7 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
*
|
||||
* @author skate702
|
||||
*/
|
||||
@Mod(modid = CraftingKeys.MODID, name = CraftingKeys.NAME, version = CraftingKeys.VERSION)
|
||||
@Mod(CraftingKeys.MODID)
|
||||
public class CraftingKeys {
|
||||
|
||||
public static final String MODID = "craftingkeys";
|
||||
@@ -46,152 +29,73 @@ public class CraftingKeys {
|
||||
/**
|
||||
* Current Instance of CraftingKeys.
|
||||
*/
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
@Instance(value = MODID)
|
||||
public static CraftingKeys instance;
|
||||
|
||||
/**
|
||||
* Current Proxy (Common or Client)
|
||||
*/
|
||||
@SidedProxy(clientSide = "de.skate702.craftingkeys.proxies.CraftingKeysClientProxy",
|
||||
serverSide = "de.skate702.craftingkeys.proxies.CraftingKeysProxy")
|
||||
public static CraftingKeysProxy proxy;
|
||||
|
||||
/**
|
||||
* This method will be executed before Init.
|
||||
*
|
||||
* @param event Input Event from FML
|
||||
*/
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
Logger.info("preInit(e)", "Loading Config now.");
|
||||
Config.loadConfig(event);
|
||||
Logger.info("preInit(e)", "Finished loading Config.");
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be executed while loading.
|
||||
*
|
||||
* @param event Input Event from FML
|
||||
*/
|
||||
@EventHandler
|
||||
public void load(FMLInitializationEvent event) {
|
||||
|
||||
// Registering
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
public CraftingKeys() {
|
||||
instance = this;
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiConfigHandler());
|
||||
KeyBindings.init();
|
||||
Logger.info("load(e)", "Registered Mod.");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be executed after Init.
|
||||
*
|
||||
* @param event Input Event from FML
|
||||
*/
|
||||
@SuppressWarnings("EmptyMethod")
|
||||
@EventHandler
|
||||
public void postInit(FMLPostInitializationEvent event) {
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedParameters")
|
||||
@SubscribeEvent
|
||||
public void onKeyInput(InputEvent.KeyInputEvent event) {
|
||||
if (KeyBindings.openGuiBinding.isPressed()) {
|
||||
Logger.info("onKeyInput(e)", "Open Crafting Keys Config Gui.");
|
||||
Util.client.player.openGui(instance, GuiConfig.GuiID, Util.client.world,
|
||||
((int) Util.client.player.posX), (int) Util.client.player.posY,
|
||||
(int) Util.client.player.posZ);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be executed when the Config is changed. Update!
|
||||
*
|
||||
* @param eventArgs Input event from FML
|
||||
*/
|
||||
@SubscribeEvent
|
||||
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent eventArgs) {
|
||||
if (eventArgs.getModID().equals(MODID)) {
|
||||
Config.syncConfig();
|
||||
Logger.info("onConfigChanged(e)", "Changed config.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method listens on GUIs open. Just to test my own gui!
|
||||
*
|
||||
* @param event Some Forge input event
|
||||
*/
|
||||
@SuppressWarnings({"EmptyMethod", "UnusedParameters"})
|
||||
@SubscribeEvent
|
||||
public void onGuiOpened(GuiOpenEvent event) {
|
||||
//if (event.gui instanceof GuiMainMenu) {
|
||||
//event.gui = new GuiConfig(); // (Only for testing)
|
||||
//}
|
||||
}
|
||||
public static CraftingKeysProxy proxy = new CraftingKeysProxy();
|
||||
|
||||
/**
|
||||
* This method will be executed every Ingame Tick.
|
||||
*
|
||||
* @param tick This is a tick. What did you think about it?
|
||||
*/
|
||||
@SuppressWarnings("UnusedParameters")
|
||||
@SubscribeEvent
|
||||
public void onTick(TickEvent.ClientTickEvent tick) {
|
||||
|
||||
GuiScreen currentScreen = Util.client.currentScreen;
|
||||
Screen currentScreen = Util.client.currentScreen;
|
||||
|
||||
if (currentScreen != null) {
|
||||
|
||||
if (currentScreen instanceof GuiCrafting) {
|
||||
if (currentScreen instanceof CraftingScreen) {
|
||||
|
||||
ContainerManager con = CraftingManager.getInstance(
|
||||
((GuiCrafting) currentScreen).inventorySlots);
|
||||
((CraftingScreen) currentScreen).getContainer());
|
||||
con.acceptKey();
|
||||
|
||||
} else if (currentScreen instanceof GuiInventory) {
|
||||
} else if (currentScreen instanceof InventoryScreen) {
|
||||
|
||||
ContainerManager con = InventoryManager.getInstance(
|
||||
((GuiInventory) currentScreen).inventorySlots);
|
||||
((InventoryScreen) currentScreen).getContainer());
|
||||
con.acceptKey();
|
||||
|
||||
} else if (currentScreen instanceof GuiMerchant) {
|
||||
} else if (currentScreen instanceof MerchantScreen) {
|
||||
|
||||
ContainerManager con = VillagerManager.getInstance(
|
||||
((GuiMerchant) currentScreen).inventorySlots);
|
||||
((MerchantScreen) currentScreen).getContainer());
|
||||
con.acceptKey();
|
||||
|
||||
} else if (currentScreen instanceof GuiFurnace) {
|
||||
} else if (currentScreen instanceof FurnaceScreen) {
|
||||
|
||||
ContainerManager con = FurnaceManager.getInstance(
|
||||
((GuiFurnace) currentScreen).inventorySlots);
|
||||
((FurnaceScreen) currentScreen).getContainer());
|
||||
con.acceptKey();
|
||||
|
||||
} else if (currentScreen instanceof GuiDispenser) {
|
||||
} else if (currentScreen instanceof DispenserScreen) {
|
||||
|
||||
ContainerManager con = DispenserManager.getInstance(
|
||||
((GuiDispenser) currentScreen).inventorySlots);
|
||||
((DispenserScreen) currentScreen).getContainer());
|
||||
con.acceptKey();
|
||||
|
||||
} else if (currentScreen instanceof GuiBrewingStand) {
|
||||
} else if (currentScreen instanceof BrewingStandScreen) {
|
||||
|
||||
ContainerManager con = BrewingManager.getInstance(
|
||||
((GuiBrewingStand) currentScreen).inventorySlots);
|
||||
((BrewingStandScreen) currentScreen).getContainer());
|
||||
con.acceptKey();
|
||||
|
||||
} else if (currentScreen instanceof GuiEnchantment) {
|
||||
} else if (currentScreen instanceof EnchantmentScreen) {
|
||||
|
||||
ContainerManager con = EnchantmentManager.getInstance(
|
||||
((GuiEnchantment) currentScreen).inventorySlots);
|
||||
((EnchantmentScreen) currentScreen).getContainer());
|
||||
con.acceptKey();
|
||||
|
||||
} else if (currentScreen instanceof GuiRepair) {
|
||||
} else if (currentScreen instanceof AnvilScreen) {
|
||||
ContainerManager con = AnvilManager.getInstance(
|
||||
((GuiRepair) currentScreen).inventorySlots);
|
||||
((AnvilScreen) currentScreen).getContainer());
|
||||
con.acceptKey();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,170 +1,80 @@
|
||||
package de.skate702.craftingkeys.config;
|
||||
|
||||
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import de.skate702.craftingkeys.CraftingKeys;
|
||||
import de.skate702.craftingkeys.util.Logger;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.util.InputMappings;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
/**
|
||||
* Configuration Management for Keys, etc.
|
||||
*/
|
||||
public class Config {
|
||||
|
||||
|
||||
/**
|
||||
* Defines the config string for the keys-category.
|
||||
*/
|
||||
private static final String categoryKeys = "keys";
|
||||
|
||||
/**
|
||||
* Defines the config string for the other-category.
|
||||
*/
|
||||
private static final String categoryOther = "other";
|
||||
|
||||
/**
|
||||
* Standard Return Key if there is a problem reading the config.
|
||||
*/
|
||||
private static final int retDefKey = -1;
|
||||
/**
|
||||
* Defines all 11 Keys you can use with Crafting Keys.
|
||||
*/
|
||||
static Property keyTopLeft, keyTopCenter, keyTopRight,
|
||||
keyCenterLeft, keyCenterCenter, keyCenterRight,
|
||||
keyLowerLeft, keyLowerCenter, keyLowerRight,
|
||||
keyStack, keyInteract, keyDrop;
|
||||
/**
|
||||
* Provides the Suggested Config File.
|
||||
*/
|
||||
private static Configuration configFile = null;
|
||||
/**
|
||||
* Defines, if NumPad is always active for crafting.
|
||||
*/
|
||||
private static Property enableNumPad;
|
||||
private static int keyTopLeft = KeyEvent.VK_Q;
|
||||
private static int keyTopCenter = KeyEvent.VK_W;
|
||||
private static int keyTopRight = KeyEvent.VK_E;
|
||||
private static int keyCenterLeft = KeyEvent.VK_A;
|
||||
private static int keyCenterCenter = KeyEvent.VK_S;
|
||||
private static int keyCenterRight = KeyEvent.VK_D;
|
||||
private static int keyLowerLeft = KeyEvent.VK_Z;
|
||||
private static int keyLowerCenter = KeyEvent.VK_X;
|
||||
private static int keyLowerRight = KeyEvent.VK_C;
|
||||
private static int keyStack = Minecraft.getInstance().gameSettings.keyBindSneak.getKey().getKeyCode();
|
||||
private static int keyInteract = Minecraft.getInstance().gameSettings.keyBindSprint.getKey().getKeyCode();
|
||||
private static final int keyDrop = KeyEvent.VK_SPACE;
|
||||
|
||||
public static boolean isKeyDown(int keyCode) {
|
||||
return InputMappings.isKeyDown(Minecraft.getInstance().getMainWindow().getHandle(), keyCode);
|
||||
}
|
||||
|
||||
public static boolean isKeyTopLeftPressed() {
|
||||
return Keyboard.isKeyDown(keyTopLeft.getInt(retDefKey)) || isNumPadEnabled() && Keyboard.isKeyDown(71);
|
||||
return isKeyDown(keyTopLeft) || isKeyDown(KeyEvent.VK_NUMPAD7);
|
||||
}
|
||||
|
||||
public static boolean isKeyTopCenterPressed() {
|
||||
return Keyboard.isKeyDown(keyTopCenter.getInt(retDefKey)) || isNumPadEnabled() && Keyboard.isKeyDown(72);
|
||||
return isKeyDown(keyTopCenter) || isKeyDown(KeyEvent.VK_NUMPAD8);
|
||||
}
|
||||
|
||||
public static boolean isKeyTopRightPressed() {
|
||||
return Keyboard.isKeyDown(keyTopRight.getInt(retDefKey)) || isNumPadEnabled() && Keyboard.isKeyDown(73);
|
||||
return isKeyDown(keyTopRight) || isKeyDown(KeyEvent.VK_NUMPAD9);
|
||||
}
|
||||
|
||||
public static boolean isKeyCenterLeftPressed() {
|
||||
return Keyboard.isKeyDown(keyCenterLeft.getInt(retDefKey)) || isNumPadEnabled() && Keyboard.isKeyDown(75);
|
||||
return isKeyDown(keyCenterLeft) || isKeyDown(KeyEvent.VK_NUMPAD4);
|
||||
}
|
||||
|
||||
public static boolean isKeyCenterCenterPressed() {
|
||||
return Keyboard.isKeyDown(keyCenterCenter.getInt(retDefKey)) || isNumPadEnabled() && Keyboard.isKeyDown(76);
|
||||
return isKeyDown(keyCenterCenter) || isKeyDown(KeyEvent.VK_NUMPAD5);
|
||||
}
|
||||
|
||||
public static boolean isKeyCenterRightPressed() {
|
||||
return Keyboard.isKeyDown(keyCenterRight.getInt(retDefKey)) || isNumPadEnabled() && Keyboard.isKeyDown(77);
|
||||
return isKeyDown(keyCenterRight) || isKeyDown(KeyEvent.VK_NUMPAD6);
|
||||
}
|
||||
|
||||
public static boolean isKeyLowerLeftPressed() {
|
||||
return Keyboard.isKeyDown(keyLowerLeft.getInt(retDefKey)) || isNumPadEnabled() && Keyboard.isKeyDown(79);
|
||||
return isKeyDown(keyLowerLeft) || isKeyDown(KeyEvent.VK_NUMPAD1);
|
||||
}
|
||||
|
||||
public static boolean isKeyLowerCenterPressed() {
|
||||
return Keyboard.isKeyDown(keyLowerCenter.getInt(retDefKey)) || isNumPadEnabled() && Keyboard.isKeyDown(80);
|
||||
return isKeyDown(keyLowerCenter) || isKeyDown(KeyEvent.VK_NUMPAD2);
|
||||
}
|
||||
|
||||
public static boolean isKeyLowerRightPressed() {
|
||||
return Keyboard.isKeyDown(keyLowerRight.getInt(retDefKey)) || isNumPadEnabled() && Keyboard.isKeyDown(81);
|
||||
return isKeyDown(keyLowerRight) || isKeyDown(KeyEvent.VK_NUMPAD3);
|
||||
}
|
||||
|
||||
public static boolean isKeyStackPressed() {
|
||||
return Keyboard.isKeyDown(keyStack.getInt(retDefKey));
|
||||
return isKeyDown(keyStack);
|
||||
}
|
||||
|
||||
public static boolean isKeyInteractPressed() {
|
||||
return Keyboard.isKeyDown(keyInteract.getInt(retDefKey));
|
||||
return isKeyDown(keyInteract);
|
||||
}
|
||||
|
||||
public static boolean isKeyDropPressed() {
|
||||
return Keyboard.isKeyDown(keyDrop.getInt(retDefKey));
|
||||
return isKeyDown(keyDrop);
|
||||
}
|
||||
|
||||
private static boolean isNumPadEnabled() {
|
||||
return enableNumPad.getBoolean(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the configFile Files, loads all values (or sets them to default).
|
||||
*
|
||||
* @param event PreInitEvent from Main Class
|
||||
*/
|
||||
public static void loadConfig(FMLPreInitializationEvent event) {
|
||||
|
||||
configFile = new Configuration(event.getSuggestedConfigurationFile(), CraftingKeys.VERSION);
|
||||
|
||||
configFile.load();
|
||||
|
||||
genComments();
|
||||
|
||||
syncConfig();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Syncs and saves the configFile file.
|
||||
*/
|
||||
public static void syncConfig() {
|
||||
|
||||
if (configFile == null) {
|
||||
Logger.error("syncConfig()", "Unable to read config file!");
|
||||
return;
|
||||
}
|
||||
|
||||
syncProperties();
|
||||
|
||||
if (configFile.hasChanged())
|
||||
configFile.save();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates comments for easier understanding of the categories.
|
||||
*/
|
||||
private static void genComments() {
|
||||
configFile.addCustomCategoryComment(categoryKeys, "Keyboard codes based on http://minecraft.gamepedia.com/Key_codes");
|
||||
configFile.addCustomCategoryComment(categoryOther, "Other settings which have effects @ crafting keys");
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all properties from the configFile file.
|
||||
*/
|
||||
private static void syncProperties() {
|
||||
// Standard Keys
|
||||
|
||||
keyTopLeft = configFile.get(categoryKeys, "keyTopLeft", Keyboard.KEY_Q);
|
||||
keyTopCenter = configFile.get(categoryKeys, "keyTopCenter", Keyboard.KEY_W);
|
||||
keyTopRight = configFile.get(categoryKeys, "keyTopRight", Keyboard.KEY_E);
|
||||
|
||||
keyCenterLeft = configFile.get(categoryKeys, "keyCenterLeft", Keyboard.KEY_A);
|
||||
keyCenterCenter = configFile.get(categoryKeys, "keyCenterCenter", Keyboard.KEY_S);
|
||||
keyCenterRight = configFile.get(categoryKeys, "keyCenterRight", Keyboard.KEY_D);
|
||||
|
||||
keyLowerLeft = configFile.get(categoryKeys, "keyLowerLeft", Keyboard.KEY_Y); // German Keyboard Layout
|
||||
keyLowerCenter = configFile.get(categoryKeys, "keyLowerCenter", Keyboard.KEY_X);
|
||||
keyLowerRight = configFile.get(categoryKeys, "keyLowerRight", Keyboard.KEY_C);
|
||||
|
||||
// Special Keys
|
||||
|
||||
keyStack = configFile.get(categoryKeys, "keyStack", Keyboard.KEY_LSHIFT);
|
||||
keyInteract = configFile.get(categoryKeys, "keyInteract", Keyboard.KEY_LCONTROL);
|
||||
keyDrop = configFile.get(categoryKeys, "keyDrop", Keyboard.KEY_SPACE);
|
||||
|
||||
// Other Settings
|
||||
|
||||
enableNumPad = configFile.get(categoryOther, "numPadEnabled", true, "Activates the NumPad for crafting");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,421 +0,0 @@
|
||||
package de.skate702.craftingkeys.config;
|
||||
|
||||
import de.skate702.craftingkeys.CraftingKeys;
|
||||
import de.skate702.craftingkeys.util.LanguageLocalizer;
|
||||
import de.skate702.craftingkeys.util.Logger;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class GuiConfig extends GuiScreen {
|
||||
|
||||
public static final int GuiID = 702;
|
||||
|
||||
private static final Color pureWhite = new Color(255, 255, 255, 255);
|
||||
private static final Color lightGray = new Color(128, 128, 128, 255);
|
||||
private static final Color highlight = new Color(86, 144, 72, 255);
|
||||
private final int buttonSaveID = 901;
|
||||
private final int buttonAbortID = 902;
|
||||
/**
|
||||
* 0,1,2 = top,
|
||||
* 3,4,5 = mid,
|
||||
* 6,7,8 = low,
|
||||
* 9 = interact,
|
||||
* 10 = stack,
|
||||
* 11 = drop
|
||||
*/
|
||||
private int[] keyValues = new int[]{};
|
||||
private int guiBasePosition;
|
||||
private int guiShowBasePosX;
|
||||
private int guiShowBasePosY;
|
||||
private GuiType guiShowType;
|
||||
private int guiShowState;
|
||||
private long lastTime = 0;
|
||||
private long currentTime;
|
||||
@SuppressWarnings("FieldCanBeLocal")
|
||||
private ArrayList<GuiButton> configButtons;
|
||||
private int selectedButtonID = -1;
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
|
||||
// Fill vars
|
||||
int guiBaseOffset = 35;
|
||||
guiBasePosition = width / 2 - guiBaseOffset;
|
||||
|
||||
guiShowBasePosX = width / 2 - 35;
|
||||
guiShowBasePosY = height / 2 + 25;
|
||||
|
||||
guiShowType = GuiType.ANVIL;
|
||||
guiShowState = 0;
|
||||
lastTime = Minecraft.getSystemTime();
|
||||
currentTime = Minecraft.getSystemTime();
|
||||
|
||||
// Init Config
|
||||
initKeyValues();
|
||||
|
||||
// Init buttons
|
||||
addStandardButtons();
|
||||
addCraftingButtons();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
|
||||
//Setting up
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
drawDefaultBackground(); //drawWorldBackground(0);
|
||||
//Title
|
||||
drawCenteredString(fontRenderer, LanguageLocalizer.localize("craftingkeys.config.title"), width / 2, height / 2 - 115, pureWhite.getRGB());
|
||||
|
||||
// Info-text and fake line
|
||||
drawCenteredString(fontRenderer, LanguageLocalizer.localize("craftingkeys.config.description"), width / 2, height / 2 - 10, pureWhite.getRGB());
|
||||
drawCenteredString(fontRenderer, "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -", width / 2, height / 2 + 8, lightGray.getRGB());
|
||||
|
||||
// Key Info
|
||||
drawCenteredString(fontRenderer, LanguageLocalizer.localize("craftingkeys.config.stack"), guiBasePosition + 130, height / 2 - 96, pureWhite.getRGB());
|
||||
drawCenteredString(fontRenderer, LanguageLocalizer.localize("craftingkeys.config.drop"), guiBasePosition + 130, height / 2 - 58, pureWhite.getRGB());
|
||||
|
||||
//Draw line to let it look better
|
||||
drawHorizontalLine(guiBasePosition - 86, guiBasePosition + 85, height / 2 - 20, pureWhite.getRGB());
|
||||
|
||||
// Draw Crafting Table
|
||||
drawCraftingTable();
|
||||
|
||||
// Draw info
|
||||
drawInfo();
|
||||
|
||||
//Draw line to let it look better
|
||||
drawHorizontalLine(guiShowBasePosX - 86, guiShowBasePosX + 85, guiShowBasePosY + 80, lightGray.getRGB());
|
||||
|
||||
// Super
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
private void drawInfo() {
|
||||
|
||||
// Insert Gui by selected Type
|
||||
currentTime = Minecraft.getSystemTime();
|
||||
int waitingTimeMS = 3000;
|
||||
if (currentTime - lastTime > waitingTimeMS) {
|
||||
showNextGui();
|
||||
GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F);
|
||||
lastTime = Minecraft.getSystemTime();
|
||||
}
|
||||
|
||||
|
||||
switch (guiShowType) {
|
||||
|
||||
case FURNACE:
|
||||
genFurnaceInfo();
|
||||
break;
|
||||
case BREWINGSTAND:
|
||||
genBrewingStandInfo();
|
||||
break;
|
||||
case DISPENSER:
|
||||
genDispenserInfo();
|
||||
break;
|
||||
case ENCHANTMENT:
|
||||
genEnchantmentInfo();
|
||||
break;
|
||||
case INVENTORY:
|
||||
genInventoryInfo();
|
||||
break;
|
||||
case VILLAGER:
|
||||
genVillagerInfo();
|
||||
break;
|
||||
case ANVIL:
|
||||
genAnvilInfo();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(GuiButton button) {
|
||||
if (button.id == buttonAbortID) {
|
||||
Logger.info("actionPerformed(b)", "Closing Crafting Keys GUI now!");
|
||||
mc.player.closeScreen();
|
||||
} else if (button.id == buttonSaveID) {
|
||||
save();
|
||||
Logger.info("actionPerformed(b)", "Saving & closing Crafting Keys GUI now!");
|
||||
mc.player.closeScreen();
|
||||
} else if (button.id >= 0 && button.id <= 11) {
|
||||
if (selectedButtonID == -1) {
|
||||
selectedButtonID = button.id;
|
||||
configButtons.get(selectedButtonID).displayString = "...";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void save() {
|
||||
Config.keyTopLeft.set(keyValues[0]);
|
||||
Config.keyTopCenter.set(keyValues[1]);
|
||||
Config.keyTopRight.set(keyValues[2]);
|
||||
Config.keyCenterLeft.set(keyValues[3]);
|
||||
Config.keyCenterCenter.set(keyValues[4]);
|
||||
Config.keyCenterRight.set(keyValues[5]);
|
||||
Config.keyLowerLeft.set(keyValues[6]);
|
||||
Config.keyLowerCenter.set(keyValues[7]);
|
||||
Config.keyLowerRight.set(keyValues[8]);
|
||||
Config.keyInteract.set(keyValues[9]);
|
||||
Config.keyStack.set(keyValues[10]);
|
||||
Config.keyDrop.set(keyValues[11]);
|
||||
Config.syncConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char character, int keyCode) {
|
||||
|
||||
if (keyCode == Keyboard.KEY_ESCAPE) {
|
||||
if (selectedButtonID != -1) {
|
||||
selectedButtonID = -1;
|
||||
drawKeyValues();
|
||||
} else {
|
||||
Logger.info("keyTyped(c,i)", "Trying to close inventory with esc.");
|
||||
|
||||
try {
|
||||
super.keyTyped(character, keyCode); // Enable standard gui closing
|
||||
} catch (Exception ignored) {
|
||||
// support for newer versions, just do nothing
|
||||
}
|
||||
}
|
||||
|
||||
} else if (selectedButtonID != -1) {
|
||||
if (!ArrayUtils.contains(keyValues, keyCode) || keyValues[selectedButtonID] == keyCode) { // No double keys
|
||||
keyValues[selectedButtonID] = keyCode;
|
||||
selectedButtonID = -1;
|
||||
drawKeyValues();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void drawCraftingTable() {
|
||||
GL11.glColor4f(1F, 1F, 1F, 1F);
|
||||
mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/crafting_table.png"));
|
||||
drawTexturedModalRect(guiBasePosition - 86, height / 2 - 100, 1, 0, 174, 80);
|
||||
}
|
||||
|
||||
private void genFurnaceInfo() {
|
||||
|
||||
GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F);
|
||||
mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/furnace.png"));
|
||||
drawTexturedModalRect(guiShowBasePosX - 86, guiShowBasePosY, 1, 0, 174, 80);
|
||||
|
||||
GL11.glColor4f(1F, 1F, 1F, 1F);
|
||||
mc.renderEngine.bindTexture(new ResourceLocation(CraftingKeys.MODID, "textures/gui/symbols.png"));
|
||||
drawTexturedModalRect(guiShowBasePosX + 105, guiShowBasePosY + 17, 0, 100, 50, 50);
|
||||
|
||||
drawInfoString(1, 63, 21);
|
||||
drawInfoString(4, 63, 57);
|
||||
drawInfoString(9, 123, 39);
|
||||
}
|
||||
|
||||
private void genBrewingStandInfo() {
|
||||
|
||||
GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F);
|
||||
mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/brewing_stand.png"));
|
||||
drawTexturedModalRect(guiShowBasePosX - 86, guiShowBasePosY, 1, 0, 174, 80);
|
||||
|
||||
GL11.glColor4f(1F, 1F, 1F, 1F);
|
||||
mc.renderEngine.bindTexture(new ResourceLocation(CraftingKeys.MODID, "textures/gui/symbols.png"));
|
||||
drawTexturedModalRect(guiShowBasePosX + 105, guiShowBasePosY + 17, 200, 0, 50, 50);
|
||||
|
||||
drawInfoString(0, 24, 21);
|
||||
drawInfoString(4, 86, 63);
|
||||
drawInfoString(3, 64, 56);
|
||||
drawInfoString(5, 109, 56);
|
||||
|
||||
}
|
||||
|
||||
private void genEnchantmentInfo() {
|
||||
|
||||
GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F);
|
||||
mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/enchanting_table.png"));
|
||||
drawTexturedModalRect(guiShowBasePosX - 86, guiShowBasePosY, 1, 0, 174, 80);
|
||||
|
||||
GL11.glColor4f(1F, 1F, 1F, 1F);
|
||||
mc.renderEngine.bindTexture(new ResourceLocation(CraftingKeys.MODID, "textures/gui/symbols.png"));
|
||||
drawTexturedModalRect(guiShowBasePosX + 105, guiShowBasePosY + 17, 150, 50, 50, 50);
|
||||
|
||||
drawInfoString(1, 22, 51);
|
||||
drawInfoString(2, 42, 51);
|
||||
}
|
||||
|
||||
|
||||
private void genAnvilInfo() {
|
||||
|
||||
GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F);
|
||||
mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/anvil.png"));
|
||||
drawTexturedModalRect(guiShowBasePosX - 86, guiShowBasePosY, 1, 0, 174, 80);
|
||||
|
||||
drawRect(guiShowBasePosX + -30, guiShowBasePosY + 17, guiShowBasePosX + 83, guiShowBasePosY + 36, Color.black.getRGB());
|
||||
|
||||
GL11.glColor4f(1F, 1F, 1F, 1F);
|
||||
mc.renderEngine.bindTexture(new ResourceLocation(CraftingKeys.MODID, "textures/gui/symbols.png"));
|
||||
drawTexturedModalRect(guiShowBasePosX + 105, guiShowBasePosY + 17, 100, 0, 50, 50);
|
||||
|
||||
drawInfoString(4, 34, 51);
|
||||
drawInfoString(5, 83, 51);
|
||||
drawInfoString(9, 141, 51);
|
||||
}
|
||||
|
||||
private void genVillagerInfo() {
|
||||
|
||||
GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F);
|
||||
mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/villager.png"));
|
||||
drawTexturedModalRect(guiShowBasePosX - 86, guiShowBasePosY, 1, 0, 174, 80);
|
||||
|
||||
GL11.glColor4f(1F, 1F, 1F, 1F);
|
||||
mc.renderEngine.bindTexture(new ResourceLocation(CraftingKeys.MODID, "textures/gui/symbols.png"));
|
||||
drawTexturedModalRect(guiShowBasePosX + 105, guiShowBasePosY + 17, 100, 100, 50, 50);
|
||||
|
||||
drawInfoString(4, 43, 57);
|
||||
drawInfoString(5, 69, 57);
|
||||
drawInfoString(9, 126, 58);
|
||||
}
|
||||
|
||||
private void genInventoryInfo() {
|
||||
|
||||
GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F);
|
||||
mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/inventory.png"));
|
||||
drawTexturedModalRect(guiShowBasePosX - 86, guiShowBasePosY, 1, 0, 174, 80);
|
||||
|
||||
GL11.glColor4f(1F, 1F, 1F, 1F);
|
||||
mc.renderEngine.bindTexture(new ResourceLocation(CraftingKeys.MODID, "textures/gui/symbols.png"));
|
||||
drawTexturedModalRect(guiShowBasePosX + 105, guiShowBasePosY + 17, 0, 0, 50, 50);
|
||||
|
||||
drawInfoString(1, 105, 22);
|
||||
drawInfoString(2, 123, 22);
|
||||
drawInfoString(4, 105, 40);
|
||||
drawInfoString(5, 123, 40);
|
||||
drawInfoString(9, 164, 32);
|
||||
|
||||
}
|
||||
|
||||
private void genDispenserInfo() {
|
||||
|
||||
GL11.glColor4f(0.5F, 0.5F, 0.5F, 1F);
|
||||
mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/dispenser.png"));
|
||||
drawTexturedModalRect(guiShowBasePosX - 86, guiShowBasePosY, 1, 0, 174, 80);
|
||||
|
||||
GL11.glColor4f(1F, 1F, 1F, 1F);
|
||||
mc.renderEngine.bindTexture(new ResourceLocation(CraftingKeys.MODID, "textures/gui/symbols.png"));
|
||||
drawTexturedModalRect(guiShowBasePosX + 105, guiShowBasePosY + 17, 50, 50, 50, 50);
|
||||
|
||||
drawInfoString(0, 69, 21);
|
||||
drawInfoString(1, 87, 21);
|
||||
drawInfoString(2, 105, 21);
|
||||
|
||||
drawInfoString(3, 69, 39);
|
||||
drawInfoString(4, 87, 39);
|
||||
drawInfoString(5, 105, 39);
|
||||
|
||||
drawInfoString(6, 69, 57);
|
||||
drawInfoString(7, 87, 57);
|
||||
drawInfoString(8, 105, 57);
|
||||
}
|
||||
|
||||
private void drawInfoString(int index, int posX, int posY) {
|
||||
drawCenteredString(fontRenderer, Keyboard.getKeyName(keyValues[index]),
|
||||
guiShowBasePosX + posX - 86, guiShowBasePosY + posY, highlight.getRGB());
|
||||
}
|
||||
|
||||
private void addStandardButtons() {
|
||||
// Add control buttons
|
||||
buttonList.add((new GuiButton(buttonAbortID, width - 53, 3, 50, 20, LanguageLocalizer.localize("craftingkeys.config.button.abort"))));
|
||||
buttonList.add((new GuiButton(buttonSaveID, width - 53, 26, 50, 20, LanguageLocalizer.localize("craftingkeys.config.button.save"))));
|
||||
}
|
||||
|
||||
private void addCraftingButtons() {
|
||||
configButtons = new ArrayList<GuiButton>();
|
||||
configButtons.add((new GuiButton(0, guiBasePosition - 60, height / 2 - 87, 20, 20, "")));
|
||||
configButtons.add((new GuiButton(1, guiBasePosition - 41, height / 2 - 87, 20, 20, "")));
|
||||
configButtons.add((new GuiButton(2, guiBasePosition - 22, height / 2 - 87, 20, 20, "")));
|
||||
configButtons.add((new GuiButton(3, guiBasePosition - 60, height / 2 - 68, 20, 20, "")));
|
||||
configButtons.add((new GuiButton(4, guiBasePosition - 41, height / 2 - 68, 20, 20, "")));
|
||||
configButtons.add((new GuiButton(5, guiBasePosition - 22, height / 2 - 68, 20, 20, "")));
|
||||
configButtons.add((new GuiButton(6, guiBasePosition - 60, height / 2 - 49, 20, 20, "")));
|
||||
configButtons.add((new GuiButton(7, guiBasePosition - 41, height / 2 - 49, 20, 20, "")));
|
||||
configButtons.add((new GuiButton(8, guiBasePosition - 22, height / 2 - 49, 20, 20, "")));
|
||||
configButtons.add((new GuiButton(9, guiBasePosition + 34, height / 2 - 67, 22, 20, "")));
|
||||
configButtons.add((new GuiButton(10, guiBasePosition + 105, height / 2 - 84, 50, 20, "")));
|
||||
configButtons.add((new GuiButton(11, guiBasePosition + 105, height / 2 - 46, 50, 20, "")));
|
||||
buttonList.addAll(configButtons);
|
||||
drawKeyValues();
|
||||
}
|
||||
|
||||
private void initKeyValues() {
|
||||
if (keyValues.length == 0) {
|
||||
keyValues = new int[]{
|
||||
Config.keyTopLeft.getInt(), // 0
|
||||
Config.keyTopCenter.getInt(), // 1
|
||||
Config.keyTopRight.getInt(), // 2
|
||||
Config.keyCenterLeft.getInt(), // 3
|
||||
Config.keyCenterCenter.getInt(), // 4
|
||||
Config.keyCenterRight.getInt(), // 5
|
||||
Config.keyLowerLeft.getInt(), // 6
|
||||
Config.keyLowerCenter.getInt(), // 7
|
||||
Config.keyLowerRight.getInt(), // 8
|
||||
Config.keyInteract.getInt(), // 9
|
||||
Config.keyStack.getInt(), // 10
|
||||
Config.keyDrop.getInt()}; // 11
|
||||
}
|
||||
}
|
||||
|
||||
private void drawKeyValues() {
|
||||
for (int i = 0; i < keyValues.length; i++) {
|
||||
configButtons.get(i).displayString = Keyboard.getKeyName(keyValues[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void showNextGui() {
|
||||
switch (guiShowState) {
|
||||
case 0:
|
||||
guiShowType = GuiType.FURNACE;
|
||||
break;
|
||||
case 1:
|
||||
guiShowType = GuiType.BREWINGSTAND;
|
||||
break;
|
||||
case 2:
|
||||
guiShowType = GuiType.INVENTORY;
|
||||
break;
|
||||
case 3:
|
||||
guiShowType = GuiType.ENCHANTMENT;
|
||||
break;
|
||||
case 4:
|
||||
guiShowType = GuiType.DISPENSER;
|
||||
break;
|
||||
case 5:
|
||||
guiShowType = GuiType.VILLAGER;
|
||||
break;
|
||||
case 6:
|
||||
guiShowType = GuiType.ANVIL;
|
||||
break;
|
||||
}
|
||||
if (guiShowState >= 6) {
|
||||
guiShowState = 0;
|
||||
} else {
|
||||
guiShowState++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum GuiType {
|
||||
ANVIL,
|
||||
FURNACE,
|
||||
BREWINGSTAND,
|
||||
ENCHANTMENT,
|
||||
INVENTORY,
|
||||
VILLAGER,
|
||||
DISPENSER
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package de.skate702.craftingkeys.config;
|
||||
|
||||
|
||||
import net.minecraftforge.fml.common.network.IGuiHandler;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class GuiConfigHandler implements IGuiHandler {
|
||||
|
||||
@Override
|
||||
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
if (ID == GuiConfig.GuiID) {
|
||||
return new GuiConfig();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
package de.skate702.craftingkeys.config;
|
||||
|
||||
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
/**
|
||||
* Provides all Key Bindings and methods to register and check them.
|
||||
*/
|
||||
public class KeyBindings {
|
||||
|
||||
private static final String category = "craftingkeys.binding.cat";
|
||||
|
||||
public static final KeyBinding openGuiBinding = new KeyBinding("craftingkeys.binding.opengui",
|
||||
Keyboard.KEY_K, category);
|
||||
|
||||
/**
|
||||
* Initializes all key bindings and registers them to the client-side.
|
||||
*/
|
||||
public static void init() {
|
||||
ClientRegistry.registerKeyBinding(openGuiBinding);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package de.skate702.craftingkeys.manager;
|
||||
|
||||
import de.skate702.craftingkeys.util.Logger;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
|
||||
/**
|
||||
* Manages a Anvil GUI Inventory.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package de.skate702.craftingkeys.manager;
|
||||
|
||||
import de.skate702.craftingkeys.util.Logger;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
|
||||
/**
|
||||
* Manages a Brewing Stand GUI Inventory.
|
||||
|
||||
@@ -5,15 +5,13 @@ import de.skate702.craftingkeys.config.Config;
|
||||
import de.skate702.craftingkeys.util.InputUtil;
|
||||
import de.skate702.craftingkeys.util.Logger;
|
||||
import de.skate702.craftingkeys.util.Util;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.gui.inventory.GuiInventory;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.client.gui.screen.inventory.InventoryScreen;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
/**
|
||||
* Provides all needed methods to handle and manage a gui inventory. Does also provide frames for own implementations.
|
||||
@@ -41,7 +39,7 @@ public abstract class ContainerManager {
|
||||
public void acceptKey() {
|
||||
|
||||
// Get hovered slot and goal slotIndex of pressed key (if pressed)
|
||||
Slot currentHoveredSlot = InputUtil.getSlotAtMousePosition((GuiContainer) Util.client.currentScreen);
|
||||
Slot currentHoveredSlot = InputUtil.getSlotAtMousePosition(Util.client.currentScreen);
|
||||
int slotIndex = specificKeyToSlotIndex();
|
||||
|
||||
// Handle accepted key
|
||||
@@ -163,30 +161,30 @@ public abstract class ContainerManager {
|
||||
// hotbar-slots are always the last 9 slots of the currently opened inventory
|
||||
int hotbarStartIndex = Util.client.player.openContainer.getInventory().size() - 9 - 1;
|
||||
|
||||
if (Util.client.currentScreen instanceof GuiInventory) {
|
||||
if (Util.client.currentScreen instanceof InventoryScreen) {
|
||||
hotbarStartIndex -= 1;
|
||||
}
|
||||
|
||||
int inputdelta;
|
||||
KeyBinding[] hotbar = Util.client.gameSettings.keyBindsHotbar;
|
||||
|
||||
if (Keyboard.isKeyDown(hotbar[0].getKeyCode())) {
|
||||
if (Config.isKeyDown(hotbar[0].getKey().getKeyCode())) {
|
||||
inputdelta = 1;
|
||||
} else if (Keyboard.isKeyDown(hotbar[1].getKeyCode())) {
|
||||
} else if (Config.isKeyDown(hotbar[1].getKey().getKeyCode())) {
|
||||
inputdelta = 2;
|
||||
} else if (Keyboard.isKeyDown(hotbar[2].getKeyCode())) {
|
||||
} else if (Config.isKeyDown(hotbar[2].getKey().getKeyCode())) {
|
||||
inputdelta = 3;
|
||||
} else if (Keyboard.isKeyDown(hotbar[3].getKeyCode())) {
|
||||
} else if (Config.isKeyDown(hotbar[3].getKey().getKeyCode())) {
|
||||
inputdelta = 4;
|
||||
} else if (Keyboard.isKeyDown(hotbar[4].getKeyCode())) {
|
||||
} else if (Config.isKeyDown(hotbar[4].getKey().getKeyCode())) {
|
||||
inputdelta = 5;
|
||||
} else if (Keyboard.isKeyDown(hotbar[5].getKeyCode())) {
|
||||
} else if (Config.isKeyDown(hotbar[5].getKey().getKeyCode())) {
|
||||
inputdelta = 6;
|
||||
} else if (Keyboard.isKeyDown(hotbar[6].getKeyCode())) {
|
||||
} else if (Config.isKeyDown(hotbar[6].getKey().getKeyCode())) {
|
||||
inputdelta = 7;
|
||||
} else if (Keyboard.isKeyDown(hotbar[7].getKeyCode())) {
|
||||
} else if (Config.isKeyDown(hotbar[7].getKey().getKeyCode())) {
|
||||
inputdelta = 8;
|
||||
} else if (Keyboard.isKeyDown(hotbar[8].getKeyCode())) {
|
||||
} else if (Config.isKeyDown(hotbar[8].getKey().getKeyCode())) {
|
||||
inputdelta = 9;
|
||||
} else {
|
||||
return;
|
||||
@@ -209,14 +207,7 @@ public abstract class ContainerManager {
|
||||
Logger.info("handleNumKey()", "Moved to hotbar slot " + inputdelta + ".");
|
||||
|
||||
moveStackToInventory(-1);
|
||||
|
||||
// Handle Minecraft handling. Ah...
|
||||
while (Keyboard.next()) {
|
||||
Logger.info("handleNumKey()", "The cake is a lie!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -270,7 +261,6 @@ public abstract class ContainerManager {
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -288,7 +278,6 @@ public abstract class ContainerManager {
|
||||
} else {
|
||||
move(srcIndex, destIndex, source.getCount());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package de.skate702.craftingkeys.manager;
|
||||
|
||||
import de.skate702.craftingkeys.util.Logger;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
|
||||
/**
|
||||
* Manages a Crafting GUI Inventory.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package de.skate702.craftingkeys.manager;
|
||||
|
||||
import de.skate702.craftingkeys.util.Logger;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
|
||||
/**
|
||||
* Manages a Dispenser GUI Inventory.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package de.skate702.craftingkeys.manager;
|
||||
|
||||
import de.skate702.craftingkeys.util.Logger;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
|
||||
/**
|
||||
* Manages a Enchantment Table GUI Inventory.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package de.skate702.craftingkeys.manager;
|
||||
|
||||
import de.skate702.craftingkeys.util.Logger;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
|
||||
/**
|
||||
* Manages a Furnace GUI Inventory.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package de.skate702.craftingkeys.manager;
|
||||
|
||||
import de.skate702.craftingkeys.util.Logger;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
|
||||
/**
|
||||
* Manages a Inventory GUI Inventory.
|
||||
|
||||
@@ -2,7 +2,7 @@ package de.skate702.craftingkeys.manager;
|
||||
|
||||
|
||||
import de.skate702.craftingkeys.util.Logger;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.container.Container;
|
||||
|
||||
/**
|
||||
* Manages a Villager GUI Inventory.
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package de.skate702.craftingkeys.proxies;
|
||||
|
||||
import net.minecraft.client.multiplayer.PlayerControllerMP;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ClickType;
|
||||
|
||||
/**
|
||||
* Client Proxy, extending Common Proxy.
|
||||
*
|
||||
* @author skate702
|
||||
*/
|
||||
public class CraftingKeysClientProxy extends CraftingKeysProxy {
|
||||
|
||||
@Override
|
||||
public void sendSlotClick(PlayerControllerMP controller, int windowId, int slot, int rightClick, int action,
|
||||
EntityPlayer player) {
|
||||
|
||||
controller.windowClick(windowId, slot, rightClick, ClickType.PICKUP, player);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
package de.skate702.craftingkeys.proxies;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.multiplayer.PlayerControllerMP;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.client.multiplayer.PlayerController;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.container.ClickType;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
/**
|
||||
* The common proxy.
|
||||
@@ -22,9 +23,10 @@ public class CraftingKeysProxy {
|
||||
* @param action 0
|
||||
* @param player The current player (from Client)
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void sendSlotClick(PlayerControllerMP controller, int windowId, int slot, int rightClick, @SuppressWarnings("SameParameterValue") int action,
|
||||
EntityPlayer player) {
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void sendSlotClick(PlayerController controller, int windowId, int slot, int rightClick, @SuppressWarnings("SameParameterValue") int action,
|
||||
PlayerEntity player) {
|
||||
controller.windowClick(windowId, slot, rightClick, ClickType.PICKUP, player);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package de.skate702.craftingkeys.util;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
||||
import net.minecraft.inventory.container.Slot;
|
||||
|
||||
/**
|
||||
* This class provides methods to interact with the Mouse and key input.
|
||||
@@ -24,70 +23,18 @@ public class InputUtil {
|
||||
/**
|
||||
* Returns the Slot at the current Mouse Position. [FROM GUICONTAINER]
|
||||
*
|
||||
* @param guiContainer The (Inventory) Container to work with.
|
||||
* @param screen The (Inventory) Container to work with.
|
||||
* @return Returns the slot (or null)
|
||||
*/
|
||||
public static Slot getSlotAtMousePosition(GuiContainer guiContainer) {
|
||||
if (guiContainer != null) {
|
||||
Container container = guiContainer.inventorySlots;
|
||||
|
||||
int x = getMouseX(guiContainer);
|
||||
int y = getMouseY(guiContainer);
|
||||
for (int k = 0; k < container.inventorySlots.size(); k++) {
|
||||
Slot slot = (Slot) container.inventorySlots.get(k);
|
||||
if (getIsMouseOverSlot(guiContainer, slot, x, y)) {
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
public static Slot getSlotAtMousePosition(Screen screen) {
|
||||
if (screen instanceof ContainerScreen) {
|
||||
return ((ContainerScreen) screen).getSlotUnderMouse();
|
||||
} else {
|
||||
Logger.debug("getSlotAtMousePosition(gui)", "guiContainer == null");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns, if the mouse cursor is over a specified slot [FROM GUICONTAINER]
|
||||
*
|
||||
* @param guiContainer the GuiContainer to work with
|
||||
* @param slot The spcified slot
|
||||
* @param x The Mouse x-Position
|
||||
* @param y The Mouse y-Position
|
||||
* @return True, if the mouse is positioned over this slot. Otherwise false
|
||||
*/
|
||||
private static boolean getIsMouseOverSlot(GuiContainer guiContainer, Slot slot, int x, int y) {
|
||||
if (guiContainer != null) {
|
||||
|
||||
// Constants from Minecraft Source Code
|
||||
x -= (guiContainer.width - 176) / 2;
|
||||
y -= (guiContainer.height - 166) / 2;
|
||||
return x >= slot.xPos - 1 && x < slot.xPos + 16 + 1
|
||||
&& y >= slot.yPos - 1 && y < slot.yPos + 16 + 1;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a calculated Mouse Position for getSlotAtMousePosition().
|
||||
*
|
||||
* @param guiContainer the GuiContainer to work with
|
||||
* @return The relative Mouse-Position
|
||||
*/
|
||||
private static int getMouseX(GuiContainer guiContainer) {
|
||||
return (Mouse.getEventX() * guiContainer.width) / Util.client.displayWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a calculated Mouse Position for getSlotAtMousePosition().
|
||||
*
|
||||
* @param guiContainer the GuiContainer to work with
|
||||
* @return The relative Mouse-Position
|
||||
*/
|
||||
private static int getMouseY(GuiContainer guiContainer) {
|
||||
return guiContainer.height - (Mouse.getEventY() * guiContainer.height) / Util.client.displayHeight - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns, if the current KeyValue is the same
|
||||
*
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package de.skate702.craftingkeys.util;
|
||||
|
||||
|
||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
|
||||
/**
|
||||
* Provides basic utility methods. For input methods, look at InputUtil.
|
||||
@@ -14,7 +13,7 @@ public class Util {
|
||||
/**
|
||||
* Current Instance Client, used for a lot of operations.
|
||||
*/
|
||||
public static final Minecraft client = FMLClientHandler.instance().getClient();
|
||||
public static final Minecraft client = Minecraft.getInstance();
|
||||
/**
|
||||
* Only used by isFirstInWorldTick()
|
||||
*/
|
||||
@@ -65,7 +64,7 @@ public class Util {
|
||||
* @param lang_key key from lang-file
|
||||
*/
|
||||
public static void printMessage(String lang_key) {
|
||||
String translated = (new TextComponentTranslation(lang_key)).getUnformattedComponentText();
|
||||
String translated = new TranslationTextComponent(lang_key).getUnformattedComponentText();
|
||||
client.player.sendChatMessage(translated);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user