Skip to content
This repository was archived by the owner on Jun 23, 2024. It is now read-only.

Commit

Permalink
updated to mc 1.12 / forge 2375; made some stuff configurable, better…
Browse files Browse the repository at this point in the history
… focus handling
gbl committed Jun 27, 2017
1 parent 0244121 commit 62a899a
Showing 9 changed files with 105 additions and 27 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ apply plugin: 'net.minecraftforge.gradle.forge'
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.


version = "1.12-forge14.21.0.2375-1.0"
version = "1.12-forge14.21.0.2375-1.1"
group = "de.guntram.mcmod.easiercrafting" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "easiercrafting"

Original file line number Diff line number Diff line change
@@ -12,7 +12,9 @@ public class ConfigurationHandler {
private Configuration config;
private String configFileName;

private boolean autoFocusSearch;
private int autoUpdateRecipeTimer;
private boolean allowRecipeBook;

public static ConfigurationHandler getInstance() {
if (instance==null)
@@ -36,11 +38,9 @@ public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) {
}

private void loadConfig() {
// allowUpload=config.getBoolean("Allow Upload", Configuration.CATEGORY_CLIENT, allowUpload, "Allow Upload to central database");
// allowDownload=config.getBoolean("Allow Download", Configuration.CATEGORY_CLIENT, allowDownload, "Allow Download from central database (only if Upload is enabled as well)");
// saveEveryXMinutes=config.getInt("Save every X minutes", Configuration.CATEGORY_CLIENT, 1, 1, 60, "How often sign data will be saved locally");
// uploadEveryXMinutes=config.getInt("Upload every X minutes", Configuration.CATEGORY_CLIENT, 5, 5, 60, "How often sign data will be uploaded");
autoUpdateRecipeTimer=config.getInt("Auto update recipe timer", Configuration.CATEGORY_CLIENT, 5, 0, 300, "Update recipe list after this many seconds after last click");
autoFocusSearch=config.getBoolean("Auto focus search text", Configuration.CATEGORY_CLIENT, false, "Automatically focus the search box when opening craft GUI");
allowRecipeBook=config.getBoolean("Allow MC internal recipe book", Configuration.CATEGORY_CLIENT, true, "Allow opening the MC internal recipe book (since 1.12)");

if (config.hasChanged())
config.save();
@@ -57,4 +57,12 @@ public static String getConfigFileName() {
public static int getAutoUpdateRecipeTimer() {
return getInstance().autoUpdateRecipeTimer;
}

public static boolean getAutoFocusSearch() {
return getInstance().autoFocusSearch;
}

public static boolean getAllowMinecraftRecipeBook() {
return getInstance().allowRecipeBook;
}
}
Original file line number Diff line number Diff line change
@@ -9,13 +9,14 @@
@Mod(modid = EasierCrafting.MODID,
version = EasierCrafting.VERSION,
clientSideOnly = true,
guiFactory = "de.guntram.mcmod.easiercrafting.GuiFactory",
acceptedMinecraftVersions = "[1.12]"
)

public class EasierCrafting
{
static final String MODID="easiercrafting";
static final String VERSION="1.0";
static final String VERSION="1.1";
@EventHandler
public void init(FMLInitializationEvent event)
{
Original file line number Diff line number Diff line change
@@ -12,6 +12,13 @@ class ExtendedGuiCrafting extends GuiCrafting {
public ExtendedGuiCrafting(InventoryPlayer playerInv, World worldIn) {
super(playerInv, worldIn);
}

@Override
public void initGui() {
super.initGui();
if (!ConfigurationHandler.getAllowMinecraftRecipeBook())
this.buttonList.clear();
}

void setRecipeBook(RecipeBook recipeBook) {
this.recipeBook=recipeBook;
@@ -26,14 +33,16 @@ protected void drawGuiContainerForegroundLayer(final int mouseX, final int mouse
@Override
protected void mouseClicked(final int mouseX, final int mouseY, final int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
recipeBook.mouseClicked(mouseX, mouseY, mouseButton);
recipeBook.mouseClicked(mouseX, mouseY, mouseButton, guiLeft, guiTop);
}

@Override
public void keyTyped(char c, int i) throws IOException {
if (c==27)
super.keyTyped(c, i);
else if (recipeBook.keyTyped(c, i))
;
else
recipeBook.keyTyped(c, i);
super.keyTyped(c, i);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.guntram.mcmod.easiercrafting;

import java.io.IOException;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraft.entity.player.EntityPlayer;

@@ -11,6 +12,13 @@ public class ExtendedGuiInventory extends GuiInventory {
public ExtendedGuiInventory(EntityPlayer player) {
super(player);
}

@Override
public void initGui() {
super.initGui();
if (!ConfigurationHandler.getAllowMinecraftRecipeBook())
this.buttonList.clear();
}

void setRecipeBook(RecipeBook recipeBook) {
this.recipeBook=recipeBook;
@@ -25,14 +33,16 @@ protected void drawGuiContainerForegroundLayer(final int mouseX, final int mouse
@Override
protected void mouseClicked(final int mouseX, final int mouseY, final int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
recipeBook.mouseClicked(mouseX, mouseY, mouseButton);
recipeBook.mouseClicked(mouseX, mouseY, mouseButton, guiLeft, guiTop);
}

@Override
public void keyTyped(char c, int i) throws IOException {
if (c==27)
super.keyTyped(c, i);
else if (recipeBook.keyTyped(c, i))
;
else
recipeBook.keyTyped(c, i);
super.keyTyped(c, i);
}
}
16 changes: 16 additions & 0 deletions src/main/java/de/guntram/mcmod/easiercrafting/GuiConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package de.guntram.mcmod.easiercrafting;

import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.common.config.ConfigElement;
import static net.minecraftforge.common.config.Configuration.CATEGORY_CLIENT;

public class GuiConfig extends net.minecraftforge.fml.client.config.GuiConfig {
public GuiConfig(GuiScreen parent) {
super(parent,
new ConfigElement(ConfigurationHandler.getConfig().getCategory(CATEGORY_CLIENT)).getChildElements(),
EasierCrafting.MODID,
false,
false,
"Easier Crafting configuration");
}
}
28 changes: 28 additions & 0 deletions src/main/java/de/guntram/mcmod/easiercrafting/GuiFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package de.guntram.mcmod.easiercrafting;

import java.util.Set;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.fml.client.IModGuiFactory;

public class GuiFactory implements IModGuiFactory {

@Override
public boolean hasConfigGui() {
return true;
}

@Override
public void initialize(final Minecraft minecraftInstance) {
}

@Override
public GuiScreen createConfigGui(GuiScreen parentScreen) {
return new GuiConfig(parentScreen);
}

@Override
public Set<IModGuiFactory.RuntimeOptionCategoryElement> runtimeGuiCategories() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -34,8 +34,8 @@ public void guiOpenEvent(GuiOpenEvent event) {
egi.setRecipeBook(new RecipeBook(egi, 1, 2, 0, 9));
event.setGui(egi);
} else {
if (event.getGui() != null)
System.out.println("opened "+event.getGui().getClass().getCanonicalName());
// if (event.getGui() != null)
// System.out.println("opened "+event.getGui().getClass().getCanonicalName());
}
}
}
36 changes: 21 additions & 15 deletions src/main/java/de/guntram/mcmod/easiercrafting/RecipeBook.java
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
@@ -78,7 +77,7 @@ void drawRecipeList(FontRenderer fontRenderer, RenderItem itemRenderer,
// We can't do this in the constructor as we don't yet know various stuff there.
if (pattern==null) {
pattern=new GuiTextField(1, fontRenderer, xOffset, 0, 150, 20);
pattern.setFocused(true);
pattern.setFocused(ConfigurationHandler.getAutoFocusSearch());
}

if (recipeUpdateTime!=0 && System.currentTimeMillis() > recipeUpdateTime) {
@@ -348,10 +347,11 @@ class InputCount {
int items;
}

public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
// don't do this, have the pattern in focus all the time
// if (pattern!=null)
// pattern.mouseClicked(mouseX, mouseY, mouseButton);
public void mouseClicked(int mouseX, int mouseY, int mouseButton, int guiLeft, int guiTop) {
if (pattern!=null) {
//System.out.println("x="+(mouseX-guiLeft)+", y="+(mouseY-guiTop)+"; patternx="+pattern.x+", patterny="+pattern.y);
pattern.mouseClicked(mouseX-guiLeft, mouseY-guiTop, mouseButton);
}

// we assume the mouse is clicked where it was when we updated the screen last ...
if (underMouse==null)
@@ -416,21 +416,22 @@ public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
maxCraftableStacks=1;
}

//System.out.println("Crafting "+maxCraftableStacks+" items");
int rowadjust=0;
for (int craftslot=0; craftslot<recipeInput.size(); craftslot++) {
int remaining=maxCraftableStacks;
Ingredient ingr=recipeInput.get(craftslot);
// if (ingr==null)
// continue;
for (int slot=0; remaining>0 && slot<36; slot++) {
Slot invitem=container.inventorySlots.getSlot(slot+firstInventorySlotNo);
ItemStack slotcontent=invitem.getStack();
if (canActAsIngredient(ingr, slotcontent)) {
// TODO: && (isempty(craftslot) || ismergeable(slot,craftslot))
transfer(slot+firstInventorySlotNo, craftslot+firstCraftSlot, remaining);
transfer(slot+firstInventorySlotNo, craftslot+firstCraftSlot+rowadjust, remaining);
remaining=maxCraftableStacks-container.inventorySlots.getSlot(craftslot+firstCraftSlot).getStack().getCount();
}
}
if (underMouse instanceof ShapedRecipes && ((craftslot+1)%((ShapedRecipes)underMouse).recipeWidth)==0) {
rowadjust+=gridSize-((ShapedRecipes)underMouse).recipeWidth;
}
}

if (mouseButton==0) {
@@ -439,11 +440,17 @@ public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
}
}

public void keyTyped(char c, int i) throws IOException {
if (c=='\r' || c=='\n')
public boolean keyTyped(char c, int i) throws IOException {
if (c=='\r' || c=='\n') {
updatePatternMatch();
else //tif (pattern.isFocused())
pattern.setFocused(false);
return true;
} else if (pattern.isFocused()) {
pattern.textboxKeyTyped(c, i);
return true;
} else {
return false;
}
}


@@ -491,8 +498,7 @@ private void transfer(int from, int to, int amount) {

private void slotClick(int slot, int mouseButton, ClickType clickType) {
Minecraft mc=Minecraft.getMinecraft();
System.out.println("Clicking slot "+slot+" "+(mouseButton==0 ? "left" : "right")+" type:"+clickType.toString());
// System.out.println("Clicking slot "+slot+" "+(mouseButton==0 ? "left" : "right")+" type:"+clickType.toString());
mc.playerController.windowClick(mc.player.openContainer.windowId, slot, mouseButton, clickType, mc.player);
}

}

0 comments on commit 62a899a

Please sign in to comment.