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

Commit

Permalink
Version 1.1.0:
Browse files Browse the repository at this point in the history
Just Enough Items compatibility: show trades list to the left if JEI is loaded

Left/Right and left pixel offset can be set in config
  • Loading branch information
gbl committed Apr 11, 2017
1 parent d5696db commit 191fde2
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.01"
version = "1.1.0"
group = "de.guntram.mcmod.easiervillagertrading" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "easiervillagertrading"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
public class BetterGuiMerchant extends GuiMerchant {

private final int addXSize=0;
private int xBase=0;
private final ItemStack tradeOK, tradeNOK;
private final int lineHeight=18;
private final int titleDistance=20;
Expand All @@ -38,7 +38,13 @@ public class BetterGuiMerchant extends GuiMerchant {

BetterGuiMerchant (InventoryPlayer inv, GuiMerchant template, World world) {
super(inv, template.getMerchant(), world);
this.xSize+=addXSize;
if (ConfigurationHandler.showLeft()) {
xBase=-ConfigurationHandler.leftPixelOffset();
if (xBase==0)
xBase=-this.getXSize();
}
else
xBase=this.getXSize()+5;
tradeOK=new ItemStack(Item.getItemById(351), 1, 2);
tradeNOK=new ItemStack(Item.getItemById(351), 1, 1);
}
Expand All @@ -63,7 +69,7 @@ protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
return;
int topAdjust=getTopAdjust(trades.size());
String s = trades.size()+" trades";
this.fontRenderer.drawString(s, this.xSize-addXSize+5, -topAdjust, 0xff00ff);
this.fontRenderer.drawString(s, xBase, -topAdjust, 0xff00ff);
// First draw all items, then all tooltips. This is extra effort,
// but we don't want any items in front of any tooltips.
RenderHelper.enableStandardItemLighting();
Expand All @@ -73,9 +79,9 @@ protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
ItemStack i1=trade.getItemToBuy();
ItemStack i2=trade.hasSecondItemToBuy() ? trade.getSecondItemToBuy() : null;
ItemStack o1=trade.getItemToSell();
drawItem(i1, this.xSize-addXSize+5+firstBuyItemXpos, i*lineHeight-topAdjust+titleDistance);
drawItem(i2, this.xSize-addXSize+5+secondBuyItemXpos, i*lineHeight-topAdjust+titleDistance);
drawItem(o1, this.xSize-addXSize+5+sellItemXpos, i*lineHeight-topAdjust+titleDistance);
drawItem(i1, xBase+firstBuyItemXpos, i*lineHeight-topAdjust+titleDistance);
drawItem(i2, xBase+secondBuyItemXpos, i*lineHeight-topAdjust+titleDistance);
drawItem(o1, xBase+sellItemXpos, i*lineHeight-topAdjust+titleDistance);

NBTTagList enchantments;

Expand All @@ -100,19 +106,22 @@ protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
enchants.append(enchant.getTranslatedName(k));
}
}
fontRenderer.drawString(enchants.toString(), this.xSize-addXSize+textXpos, i*lineHeight-topAdjust+24, 0xffff00);
String shownEnchants=enchants.toString();
if (xBase<0)
shownEnchants=fontRenderer.trimStringToWidth(shownEnchants, -xBase-textXpos-5);
fontRenderer.drawString(shownEnchants, xBase+textXpos, i*lineHeight-topAdjust+24, 0xffff00);
}
drawItem(trade.isRecipeDisabled() ? tradeNOK : tradeOK, xSize-addXSize+5+okNokXpos, i*lineHeight-topAdjust+titleDistance);
drawItem(trade.isRecipeDisabled() ? tradeNOK : tradeOK, xBase+okNokXpos, i*lineHeight-topAdjust+titleDistance);
}
RenderHelper.disableStandardItemLighting();
for (int i=0; i<trades.size(); i++) {
MerchantRecipe trade=trades.get(i);
ItemStack i1=trade.getItemToBuy();
ItemStack i2=trade.hasSecondItemToBuy() ? trade.getSecondItemToBuy() : null;
ItemStack o1=trade.getItemToSell();
drawTooltip(i1, this.xSize-addXSize+5+firstBuyItemXpos, i*lineHeight-topAdjust+titleDistance, mouseX, mouseY);
drawTooltip(i2, this.xSize-addXSize+5+secondBuyItemXpos, i*lineHeight-topAdjust+titleDistance, mouseX, mouseY);
drawTooltip(o1, this.xSize-addXSize+5+sellItemXpos, i*lineHeight-topAdjust+titleDistance, mouseX, mouseY);
drawTooltip(i1, xBase+firstBuyItemXpos, i*lineHeight-topAdjust+titleDistance, mouseX, mouseY);
drawTooltip(i2, xBase+secondBuyItemXpos, i*lineHeight-topAdjust+titleDistance, mouseX, mouseY);
drawTooltip(o1, xBase+sellItemXpos, i*lineHeight-topAdjust+titleDistance, mouseX, mouseY);
}
}

Expand Down Expand Up @@ -143,8 +152,8 @@ private void drawTooltip(ItemStack stack, int x, int y, int mousex, int mousey)
protected void mouseClicked(final int mouseX, final int mouseY, final int mouseButton) throws IOException {
// System.out.println("click at "+mouseX+"/"+mouseY);
if (mouseButton==0
&& (mouseX - this.guiLeft) > this.xSize-addXSize
&& (mouseX - this.guiLeft) < this.xSize-addXSize+textXpos
&& (mouseX - this.guiLeft) >= xBase
&& (mouseX - this.guiLeft) <= xBase+textXpos
) {
MerchantRecipeList trades=getMerchant().getRecipes(null);
if (trades==null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package de.guntram.mcmod.easiervillagertrading;

import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import java.io.File;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.Loader;

public class ConfigurationHandler {

private static ConfigurationHandler instance;

private Configuration config;
private String configFileName;
private boolean showLeft;
private int leftPixelOffset;

public static ConfigurationHandler getInstance() {
if (instance==null)
instance=new ConfigurationHandler();
return instance;
}

public void load(final File configFile) {
if (config == null) {
config = new Configuration(configFile);
configFileName=configFile.getPath();
loadConfig();
}
}

@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) {
// System.out.println("OnConfigChanged for "+event.getModID());
if (event.getModID().equalsIgnoreCase(EasierVillagerTrading.MODID)) {
loadConfig();
}
}

private void loadConfig() {
showLeft=config.getBoolean("Trades list left", Configuration.CATEGORY_CLIENT,
Loader.isModLoaded("jei"),
"Show trades list to the left, for Just Enough Items compatibility");
leftPixelOffset=config.getInt("Trades left pixel offset", Configuration.CATEGORY_CLIENT,
0, 0, Integer.MAX_VALUE,
"How many pixels left of the GUI the trades list will be shown. Use 0 for auto detect. "+
"Only used if Trades list left is true.");
if (config.hasChanged())
config.save();
}

public static Configuration getConfig() {
return getInstance().config;
}

public static String getConfigFileName() {
return getInstance().configFileName;
}

public static boolean showLeft() { return getInstance().showLeft; }
public static int leftPixelOffset() { return getInstance().leftPixelOffset; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,32 @@
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

@Mod(
modid = EasierVillagerTrading.MODID,
version = EasierVillagerTrading.VERSION,
clientSideOnly = true,
guiFactory = "de.guntram.mcmod.easiervillagertrading.GuiFactory",
acceptedMinecraftVersions = "[1.11.2]",
dependencies = "after:jei"
)

@Mod(modid = EasierVillagerTrading.MODID, version = EasierVillagerTrading.VERSION)
public class EasierVillagerTrading {

public static final String MODID = "easiervillagertrading";
public static final String VERSION = "1.01";
public static final String VERSION = "1.1.0";

@EventHandler
public void init(FMLInitializationEvent event)
{
MinecraftForge.EVENT_BUS.register(OpenTradeEventHandler.getInstance());
}

@EventHandler
public void preInit(final FMLPreInitializationEvent event) {
ConfigurationHandler confHandler = ConfigurationHandler.getInstance();
confHandler.load(event.getSuggestedConfigurationFile());
MinecraftForge.EVENT_BUS.register(confHandler);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package de.guntram.mcmod.easiervillagertrading;

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(),
EasierVillagerTrading.MODID,
false,
false,
"Easier Villager Trading configuration");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package de.guntram.mcmod.easiervillagertrading;

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 void initialize(final Minecraft minecraftInstance) {
}

@Override
public Class<? extends GuiScreen> mainConfigGuiClass() {
return de.guntram.mcmod.easiervillagertrading.GuiConfig.class;
}

@Override
public Set<IModGuiFactory.RuntimeOptionCategoryElement> runtimeGuiCategories() {
return null;
}

@Override
public IModGuiFactory.RuntimeOptionGuiHandler getHandlerFor(final IModGuiFactory.RuntimeOptionCategoryElement element) {
return null;
}
}

0 comments on commit 191fde2

Please sign in to comment.