update to official mappings code
This commit is contained in:
@@ -51,55 +51,55 @@ public class CraftingKeys {
|
|||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onTick(TickEvent.ClientTickEvent tick) {
|
public void onTick(TickEvent.ClientTickEvent tick) {
|
||||||
|
|
||||||
Screen currentScreen = Util.client.currentScreen;
|
Screen currentScreen = Util.client.screen;
|
||||||
|
|
||||||
if (currentScreen != null) {
|
if (currentScreen != null) {
|
||||||
|
|
||||||
if (currentScreen instanceof CraftingScreen) {
|
if (currentScreen instanceof CraftingScreen) {
|
||||||
|
|
||||||
ContainerManager con = CraftingManager.getInstance(
|
ContainerManager con = CraftingManager.getInstance(
|
||||||
((CraftingScreen) currentScreen).getContainer());
|
((CraftingScreen) currentScreen).getMenu());
|
||||||
con.acceptKey();
|
con.acceptKey();
|
||||||
|
|
||||||
} else if (currentScreen instanceof InventoryScreen) {
|
} else if (currentScreen instanceof InventoryScreen) {
|
||||||
|
|
||||||
ContainerManager con = InventoryManager.getInstance(
|
ContainerManager con = InventoryManager.getInstance(
|
||||||
((InventoryScreen) currentScreen).getContainer());
|
((InventoryScreen) currentScreen).getMenu());
|
||||||
con.acceptKey();
|
con.acceptKey();
|
||||||
|
|
||||||
} else if (currentScreen instanceof MerchantScreen) {
|
} else if (currentScreen instanceof MerchantScreen) {
|
||||||
|
|
||||||
ContainerManager con = VillagerManager.getInstance(
|
ContainerManager con = VillagerManager.getInstance(
|
||||||
((MerchantScreen) currentScreen).getContainer());
|
((MerchantScreen) currentScreen).getMenu());
|
||||||
con.acceptKey();
|
con.acceptKey();
|
||||||
|
|
||||||
} else if (currentScreen instanceof FurnaceScreen) {
|
} else if (currentScreen instanceof FurnaceScreen) {
|
||||||
|
|
||||||
ContainerManager con = FurnaceManager.getInstance(
|
ContainerManager con = FurnaceManager.getInstance(
|
||||||
((FurnaceScreen) currentScreen).getContainer());
|
((FurnaceScreen) currentScreen).getMenu());
|
||||||
con.acceptKey();
|
con.acceptKey();
|
||||||
|
|
||||||
} else if (currentScreen instanceof DispenserScreen) {
|
} else if (currentScreen instanceof DispenserScreen) {
|
||||||
|
|
||||||
ContainerManager con = DispenserManager.getInstance(
|
ContainerManager con = DispenserManager.getInstance(
|
||||||
((DispenserScreen) currentScreen).getContainer());
|
((DispenserScreen) currentScreen).getMenu());
|
||||||
con.acceptKey();
|
con.acceptKey();
|
||||||
|
|
||||||
} else if (currentScreen instanceof BrewingStandScreen) {
|
} else if (currentScreen instanceof BrewingStandScreen) {
|
||||||
|
|
||||||
ContainerManager con = BrewingManager.getInstance(
|
ContainerManager con = BrewingManager.getInstance(
|
||||||
((BrewingStandScreen) currentScreen).getContainer());
|
((BrewingStandScreen) currentScreen).getMenu());
|
||||||
con.acceptKey();
|
con.acceptKey();
|
||||||
|
|
||||||
} else if (currentScreen instanceof EnchantmentScreen) {
|
} else if (currentScreen instanceof EnchantmentScreen) {
|
||||||
|
|
||||||
ContainerManager con = EnchantmentManager.getInstance(
|
ContainerManager con = EnchantmentManager.getInstance(
|
||||||
((EnchantmentScreen) currentScreen).getContainer());
|
((EnchantmentScreen) currentScreen).getMenu());
|
||||||
con.acceptKey();
|
con.acceptKey();
|
||||||
|
|
||||||
} else if (currentScreen instanceof AnvilScreen) {
|
} else if (currentScreen instanceof AnvilScreen) {
|
||||||
ContainerManager con = AnvilManager.getInstance(
|
ContainerManager con = AnvilManager.getInstance(
|
||||||
((AnvilScreen) currentScreen).getContainer());
|
((AnvilScreen) currentScreen).getMenu());
|
||||||
con.acceptKey();
|
con.acceptKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,12 +22,12 @@ public class Config {
|
|||||||
private static int keyLowerLeft = KeyEvent.VK_Z;
|
private static int keyLowerLeft = KeyEvent.VK_Z;
|
||||||
private static int keyLowerCenter = KeyEvent.VK_X;
|
private static int keyLowerCenter = KeyEvent.VK_X;
|
||||||
private static int keyLowerRight = KeyEvent.VK_C;
|
private static int keyLowerRight = KeyEvent.VK_C;
|
||||||
private static int keyStack = Minecraft.getInstance().gameSettings.keyBindSneak.getKey().getKeyCode();
|
private static int keyStack = Minecraft.getInstance().options.keyShift.getKey().getValue();
|
||||||
private static int keyInteract = Minecraft.getInstance().gameSettings.keyBindSprint.getKey().getKeyCode();
|
private static int keyInteract = Minecraft.getInstance().options.keySprint.getKey().getValue();
|
||||||
private static final int keyDrop = KeyEvent.VK_SPACE;
|
private static final int keyDrop = KeyEvent.VK_SPACE;
|
||||||
|
|
||||||
public static boolean isKeyDown(int keyCode) {
|
public static boolean isKeyDown(int keyCode) {
|
||||||
return InputMappings.isKeyDown(Minecraft.getInstance().getMainWindow().getHandle(), keyCode);
|
return InputMappings.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), keyCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isKeyTopLeftPressed() {
|
public static boolean isKeyTopLeftPressed() {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public abstract class ContainerManager {
|
|||||||
public void acceptKey() {
|
public void acceptKey() {
|
||||||
|
|
||||||
// Get hovered slot and goal slotIndex of pressed key (if pressed)
|
// Get hovered slot and goal slotIndex of pressed key (if pressed)
|
||||||
Slot currentHoveredSlot = InputUtil.getSlotAtMousePosition(Util.client.currentScreen);
|
Slot currentHoveredSlot = InputUtil.getSlotAtMousePosition(Util.client.screen);
|
||||||
int slotIndex = specificKeyToSlotIndex();
|
int slotIndex = specificKeyToSlotIndex();
|
||||||
|
|
||||||
// Handle accepted key
|
// Handle accepted key
|
||||||
@@ -61,7 +61,7 @@ public abstract class ContainerManager {
|
|||||||
!Util.isHoldingStack()) { // MOVE FROM SLOT
|
!Util.isHoldingStack()) { // MOVE FROM SLOT
|
||||||
|
|
||||||
Logger.info("acceptKey()", "Key for index " + slotIndex + " pressed.");
|
Logger.info("acceptKey()", "Key for index " + slotIndex + " pressed.");
|
||||||
onSpecificKeyPressed(currentHoveredSlot.slotNumber, slotIndex);
|
onSpecificKeyPressed(currentHoveredSlot.index, slotIndex);
|
||||||
|
|
||||||
|
|
||||||
} else if (Util.isHoldingStack()) { // MOVE FROM HAND
|
} else if (Util.isHoldingStack()) { // MOVE FROM HAND
|
||||||
@@ -98,7 +98,7 @@ public abstract class ContainerManager {
|
|||||||
// Handles Interaction with items held
|
// Handles Interaction with items held
|
||||||
// Stack up on hand if equal or small enough, else throw held stack away
|
// Stack up on hand if equal or small enough, else throw held stack away
|
||||||
if (Util.isHoldingStack() && getItemStack(getInteractionSlotIndex()) != null && (
|
if (Util.isHoldingStack() && getItemStack(getInteractionSlotIndex()) != null && (
|
||||||
!Util.getHeldStack().isItemEqual(getItemStack(getInteractionSlotIndex()))
|
!Util.getHeldStack().sameItem(getItemStack(getInteractionSlotIndex()))
|
||||||
|| Util.getHeldStack().getCount() + getItemStack(getInteractionSlotIndex()).getCount()
|
|| Util.getHeldStack().getCount() + getItemStack(getInteractionSlotIndex()).getCount()
|
||||||
> getItemStack(getInteractionSlotIndex()).getMaxStackSize())) {
|
> getItemStack(getInteractionSlotIndex()).getMaxStackSize())) {
|
||||||
moveStackToInventory(-1);
|
moveStackToInventory(-1);
|
||||||
@@ -159,32 +159,32 @@ public abstract class ContainerManager {
|
|||||||
void handleNumKey(Slot currentHoveredSlot) {
|
void handleNumKey(Slot currentHoveredSlot) {
|
||||||
|
|
||||||
// hotbar-slots are always the last 9 slots of the currently opened inventory
|
// hotbar-slots are always the last 9 slots of the currently opened inventory
|
||||||
int hotbarStartIndex = Util.client.player.openContainer.getInventory().size() - 9 - 1;
|
int hotbarStartIndex = Util.client.player.containerMenu.getItems().size() - 9 - 1;
|
||||||
|
|
||||||
if (Util.client.currentScreen instanceof InventoryScreen) {
|
if (Util.client.screen instanceof InventoryScreen) {
|
||||||
hotbarStartIndex -= 1;
|
hotbarStartIndex -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int inputdelta;
|
int inputdelta;
|
||||||
KeyBinding[] hotbar = Util.client.gameSettings.keyBindsHotbar;
|
KeyBinding[] hotbar = Util.client.options.keyHotbarSlots;
|
||||||
|
|
||||||
if (Config.isKeyDown(hotbar[0].getKey().getKeyCode())) {
|
if (Config.isKeyDown(hotbar[0].getKey().getValue())) {
|
||||||
inputdelta = 1;
|
inputdelta = 1;
|
||||||
} else if (Config.isKeyDown(hotbar[1].getKey().getKeyCode())) {
|
} else if (Config.isKeyDown(hotbar[1].getKey().getValue())) {
|
||||||
inputdelta = 2;
|
inputdelta = 2;
|
||||||
} else if (Config.isKeyDown(hotbar[2].getKey().getKeyCode())) {
|
} else if (Config.isKeyDown(hotbar[2].getKey().getValue())) {
|
||||||
inputdelta = 3;
|
inputdelta = 3;
|
||||||
} else if (Config.isKeyDown(hotbar[3].getKey().getKeyCode())) {
|
} else if (Config.isKeyDown(hotbar[3].getKey().getValue())) {
|
||||||
inputdelta = 4;
|
inputdelta = 4;
|
||||||
} else if (Config.isKeyDown(hotbar[4].getKey().getKeyCode())) {
|
} else if (Config.isKeyDown(hotbar[4].getKey().getValue())) {
|
||||||
inputdelta = 5;
|
inputdelta = 5;
|
||||||
} else if (Config.isKeyDown(hotbar[5].getKey().getKeyCode())) {
|
} else if (Config.isKeyDown(hotbar[5].getKey().getValue())) {
|
||||||
inputdelta = 6;
|
inputdelta = 6;
|
||||||
} else if (Config.isKeyDown(hotbar[6].getKey().getKeyCode())) {
|
} else if (Config.isKeyDown(hotbar[6].getKey().getValue())) {
|
||||||
inputdelta = 7;
|
inputdelta = 7;
|
||||||
} else if (Config.isKeyDown(hotbar[7].getKey().getKeyCode())) {
|
} else if (Config.isKeyDown(hotbar[7].getKey().getValue())) {
|
||||||
inputdelta = 8;
|
inputdelta = 8;
|
||||||
} else if (Config.isKeyDown(hotbar[8].getKey().getKeyCode())) {
|
} else if (Config.isKeyDown(hotbar[8].getKey().getValue())) {
|
||||||
inputdelta = 9;
|
inputdelta = 9;
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@@ -194,7 +194,7 @@ public abstract class ContainerManager {
|
|||||||
// if there could not be meant another stack at mouse position. cool logic!
|
// if there could not be meant another stack at mouse position. cool logic!
|
||||||
if (!Util.isHoldingStack()) {
|
if (!Util.isHoldingStack()) {
|
||||||
|
|
||||||
if (currentHoveredSlot == null || !currentHoveredSlot.getHasStack()) {
|
if (currentHoveredSlot == null || !currentHoveredSlot.hasItem()) {
|
||||||
Logger.info("handleNumKey()", "Trying output to hotbar speedup.");
|
Logger.info("handleNumKey()", "Trying output to hotbar speedup.");
|
||||||
onInteractionKeyPressed();
|
onInteractionKeyPressed();
|
||||||
}
|
}
|
||||||
@@ -306,13 +306,13 @@ public abstract class ContainerManager {
|
|||||||
int movedAmount = Math.min(amount, sourceSize);
|
int movedAmount = Math.min(amount, sourceSize);
|
||||||
|
|
||||||
// Clear goal slot (May fail on full inventory!); only available if not holdling
|
// Clear goal slot (May fail on full inventory!); only available if not holdling
|
||||||
if (destination != null && !source.isItemEqual(destination) && srcIndex >= 0) {
|
if (destination != null && !source.sameItem(destination) && srcIndex >= 0) {
|
||||||
moveStackToInventory(destIndex);
|
moveStackToInventory(destIndex);
|
||||||
destination = getItemStack(destIndex);
|
destination = getItemStack(destIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move some
|
// Move some
|
||||||
if (destination == null || source.isItemEqual(destination)) {
|
if (destination == null || source.sameItem(destination)) {
|
||||||
|
|
||||||
if (srcIndex >= 0) {
|
if (srcIndex >= 0) {
|
||||||
leftClick(srcIndex);
|
leftClick(srcIndex);
|
||||||
@@ -342,14 +342,14 @@ public abstract class ContainerManager {
|
|||||||
*/
|
*/
|
||||||
ItemStack getItemStack(int index) {
|
ItemStack getItemStack(int index) {
|
||||||
|
|
||||||
if (index >= 0 && index < container.inventorySlots.size()) {
|
if (index >= 0 && index < container.slots.size()) {
|
||||||
|
|
||||||
Slot slot = (Slot) (container.inventorySlots.get(index));
|
Slot slot = (Slot) (container.slots.get(index));
|
||||||
|
|
||||||
// NEW_1_11 No Null-Stacks anymore. Empty Stacks with air...
|
// NEW_1_11 No Null-Stacks anymore. Empty Stacks with air...
|
||||||
ItemStack returnStack = (slot == null) ? null : slot.getStack();
|
ItemStack returnStack = (slot == null) ? null : slot.getItem();
|
||||||
|
|
||||||
if(returnStack.getCount() == 0 && returnStack.getItem() == Item.getItemFromBlock(Blocks.AIR)) {
|
if(returnStack.getCount() == 0 && returnStack.getItem() == Item.byBlock(Blocks.AIR)) {
|
||||||
returnStack = null;
|
returnStack = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -425,12 +425,12 @@ public abstract class ContainerManager {
|
|||||||
private int calcInventoryDestination(ItemStack stackToMove) {
|
private int calcInventoryDestination(ItemStack stackToMove) {
|
||||||
|
|
||||||
// First run: Try to find a nice stack to put items on additionally
|
// First run: Try to find a nice stack to put items on additionally
|
||||||
for (int i = getInventoryStartIndex(); i < container.inventorySlots.size(); i++) {
|
for (int i = getInventoryStartIndex(); i < container.slots.size(); i++) {
|
||||||
|
|
||||||
ItemStack potentialGoalStack = getItemStack(i);
|
ItemStack potentialGoalStack = getItemStack(i);
|
||||||
|
|
||||||
if (potentialGoalStack != null && stackToMove != null) {
|
if (potentialGoalStack != null && stackToMove != null) {
|
||||||
if (potentialGoalStack.isItemEqual(stackToMove)) {
|
if (potentialGoalStack.sameItem(stackToMove)) {
|
||||||
if (potentialGoalStack.getCount() + stackToMove.getCount() <= stackToMove.getMaxStackSize()) {
|
if (potentialGoalStack.getCount() + stackToMove.getCount() <= stackToMove.getMaxStackSize()) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@@ -439,7 +439,7 @@ public abstract class ContainerManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Second run: Find a free slot
|
// Second run: Find a free slot
|
||||||
for (int i = getInventoryStartIndex(); i < container.inventorySlots.size(); i++) {
|
for (int i = getInventoryStartIndex(); i < container.slots.size(); i++) {
|
||||||
if (getItemStack(i) == null) {
|
if (getItemStack(i) == null) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@@ -493,7 +493,7 @@ public abstract class ContainerManager {
|
|||||||
|
|
||||||
int rightClickData = (rightClick) ? 1 : 0;
|
int rightClickData = (rightClick) ? 1 : 0;
|
||||||
|
|
||||||
CraftingKeys.proxy.sendSlotClick(Util.client.playerController, container.windowId, index,
|
CraftingKeys.proxy.sendSlotClick(Util.client.gameMode, container.containerId, index,
|
||||||
rightClickData, 0, Util.client.player);
|
rightClickData, 0, Util.client.player);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class CraftingKeysProxy {
|
|||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public void sendSlotClick(PlayerController controller, int windowId, int slot, int rightClick, @SuppressWarnings("SameParameterValue") int action,
|
public void sendSlotClick(PlayerController controller, int windowId, int slot, int rightClick, @SuppressWarnings("SameParameterValue") int action,
|
||||||
PlayerEntity player) {
|
PlayerEntity player) {
|
||||||
controller.windowClick(windowId, slot, rightClick, ClickType.PICKUP, player);
|
controller.handleInventoryMouseClick(windowId, slot, rightClick, ClickType.PICKUP, player);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,6 @@ public class LanguageLocalizer {
|
|||||||
* @return localized The localized String
|
* @return localized The localized String
|
||||||
*/
|
*/
|
||||||
public static String localize(String unloc) {
|
public static String localize(String unloc) {
|
||||||
return I18n.format(unloc);
|
return I18n.get(unloc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class Util {
|
|||||||
* @return A item stack
|
* @return A item stack
|
||||||
*/
|
*/
|
||||||
public static ItemStack getHeldStack() {
|
public static ItemStack getHeldStack() {
|
||||||
return client.player.inventory.getItemStack();
|
return client.player.inventory.getCarried();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -49,10 +49,10 @@ public class Util {
|
|||||||
* @return True, if this is the first tick
|
* @return True, if this is the first tick
|
||||||
*/
|
*/
|
||||||
public static boolean isFirstInWorldTick() {
|
public static boolean isFirstInWorldTick() {
|
||||||
if (firstInWorldTick && client.world != null) {
|
if (firstInWorldTick && client.level != null) {
|
||||||
firstInWorldTick = false;
|
firstInWorldTick = false;
|
||||||
return true;
|
return true;
|
||||||
} else if (client.world == null) {
|
} else if (client.level == null) {
|
||||||
firstInWorldTick = true;
|
firstInWorldTick = true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -64,8 +64,8 @@ public class Util {
|
|||||||
* @param lang_key key from lang-file
|
* @param lang_key key from lang-file
|
||||||
*/
|
*/
|
||||||
public static void printMessage(String lang_key) {
|
public static void printMessage(String lang_key) {
|
||||||
String translated = new TranslationTextComponent(lang_key).getUnformattedComponentText();
|
String translated = new TranslationTextComponent(lang_key).getContents();
|
||||||
client.player.sendChatMessage(translated);
|
client.player.chat(translated);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user