55 */
66package de .guntram .mcmod .easiervillagertrading ;
77
8- import java . io . IOException ;
9- import net . minecraft . client . gui . GuiButton ;
8+ import de . guntram . mcmod . debug . NBTdump ;
9+
1010import net .minecraft .client .gui .GuiMerchant ;
1111import net .minecraft .client .renderer .GlStateManager ;
1212import net .minecraft .client .renderer .RenderHelper ;
1313import net .minecraft .enchantment .Enchantment ;
14+ import net .minecraft .entity .IMerchant ;
1415import net .minecraft .entity .player .InventoryPlayer ;
1516import net .minecraft .inventory .ClickType ;
16- import net .minecraft .item .Item ;
1717import net .minecraft .item .ItemEnchantedBook ;
1818import net .minecraft .item .ItemStack ;
19+ import net .minecraft .nbt .NBTTagCompound ;
1920import net .minecraft .nbt .NBTTagList ;
2021import net .minecraft .util .ResourceLocation ;
22+ import net .minecraft .util .registry .IRegistry ;
2123import net .minecraft .village .MerchantRecipe ;
2224import net .minecraft .village .MerchantRecipeList ;
2325import net .minecraft .world .World ;
@@ -37,40 +39,38 @@ public class BetterGuiMerchant extends GuiMerchant {
3739 private final int sellItemXpos =60 ;
3840 private final int textXpos =85 ;
3941 private static final ResourceLocation icons =new ResourceLocation (EasierVillagerTrading .MODID , "textures/icons.png" );
42+
43+ private int frames ; //DEBUG
4044
41- BetterGuiMerchant (InventoryPlayer inv , GuiMerchant template , World world ) {
42- super (inv , template . getMerchant () , world );
45+ public BetterGuiMerchant (InventoryPlayer inv , IMerchant merchant , World world ) {
46+ super (inv , merchant , world );
4347 if (ConfigurationHandler .showLeft ()) {
4448 xBase =-ConfigurationHandler .leftPixelOffset ();
4549 if (xBase ==0 )
46- xBase =-this .getXSize () ;
50+ xBase =-this .xSize ;
4751 }
48- else
49- xBase =this .getXSize ()+5 ;
50- System .out .println ("icons=" +icons );
51- }
52-
53- @ Override
54- protected void drawGuiContainerBackgroundLayer (float partialTicks , int mouseX , int mouseY ) {
55- super .drawGuiContainerBackgroundLayer (partialTicks , mouseX , mouseY );
56- }
57-
58- @ Override
59- public void drawScreen (int mouseX , int mouseY , float partialTicks ) {
60- super .drawScreen (mouseX , mouseY , partialTicks );
61-
52+ else {
53+ xBase =this .xSize +5 ;
54+ }
55+ frames =0 ; //DEBUG
6256 }
6357
6458 @ Override
6559 protected void drawGuiContainerForegroundLayer (int mouseX , int mouseY )
6660 {
61+ if (++frames %300 ==0 ) {
62+ System .out .println ("drawForegroundLayer" );
63+ }
6764 super .drawGuiContainerForegroundLayer (mouseX , mouseY );
6865 MerchantRecipeList trades =getMerchant ().getRecipes (null );
6966 if (trades ==null )
7067 return ;
7168 int topAdjust =getTopAdjust (trades .size ());
7269 String s = trades .size ()+" trades" ;
7370 this .fontRenderer .drawString (s , xBase , -topAdjust , 0xff00ff );
71+ if (++frames %300 ==0 ) { // DEBUG
72+ System .out .println ("drawing " +s +" at " +xBase +"/" +(-topAdjust )); //DEBUG
73+ } //DEBUG
7474 // First draw all items, then all tooltips. This is extra effort,
7575 // but we don't want any items in front of any tooltips.
7676
@@ -80,6 +80,9 @@ protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
8080 ItemStack i1 =trade .getItemToBuy ();
8181 ItemStack i2 =trade .hasSecondItemToBuy () ? trade .getSecondItemToBuy () : null ;
8282 ItemStack o1 =trade .getItemToSell ();
83+ if (frames %300 ==0 ) { //DEBUG
84+ System .out .println ("drawing items at " +(xBase +firstBuyItemXpos )+ "/" +(i *lineHeight -topAdjust +titleDistance )); //DEBUG
85+ } //DEBUG
8386 drawItem (i1 , xBase +firstBuyItemXpos , i *lineHeight -topAdjust +titleDistance );
8487 drawItem (i2 , xBase +secondBuyItemXpos , i *lineHeight -topAdjust +titleDistance );
8588 drawItem (o1 , xBase +sellItemXpos , i *lineHeight -topAdjust +titleDistance );
@@ -94,28 +97,36 @@ protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
9497 if (enchantments != null )
9598 {
9699 StringBuilder enchants =new StringBuilder ();
97- for (int t = 0 ; t < enchantments .tagCount (); ++t )
100+ for (int t = 0 ; t < enchantments .size (); ++t )
98101 {
99- int j = enchantments .getCompoundTagAt (t ).getShort ("id" );
100- int k = enchantments .getCompoundTagAt (t ).getShort ("lvl" );
101-
102- Enchantment enchant = Enchantment .getEnchantmentByID (j );
102+ NBTTagCompound singleTag = enchantments .getCompound (t );
103+ if (frames %300 ==0 ) {
104+ NBTdump .dump (singleTag , 0 );
105+ }
106+ String name = enchantments .getCompound (t ).getString ("id" );
107+ int level = enchantments .getCompound (t ).getShort ("lvl" );
108+
109+ Enchantment enchant = IRegistry .ENCHANTMENT .get (new ResourceLocation (name ));
103110 if (enchant != null )
104111 {
105112 if (t >0 )
106113 enchants .append (", " );
107- enchants .append (enchant .getTranslatedName ( k ));
114+ enchants .append (enchant .func_200305_d ( level ). getFormattedText ( ));
108115 }
109116 }
110117 String shownEnchants =enchants .toString ();
111118 if (xBase <0 )
112119 shownEnchants =fontRenderer .trimStringToWidth (shownEnchants , -xBase -textXpos -5 );
120+
121+ if (frames %300 ==0 ) { //DEBUG
122+ System .out .println ("Enchant" +shownEnchants +" at " +(xBase +firstBuyItemXpos )+ "/" +(i *lineHeight -topAdjust +titleDistance )); //DEBUG
123+ } //DEBUG
113124 fontRenderer .drawString (shownEnchants , xBase +textXpos , i *lineHeight -topAdjust +24 , 0xffff00 );
114125 }
115126 }
116127 RenderHelper .disableStandardItemLighting ();
117128
118- GlStateManager .color (1f , 1f , 1f , 1f ); // needed so items don't get a text color overlay
129+ GlStateManager .color4f (1f , 1f , 1f , 1f ); // needed so items don't get a text color overlay
119130 GlStateManager .enableBlend ();
120131 this .mc .getTextureManager ().bindTexture (icons ); // arrows; use standard item lighting for them so we need a separate loop
121132 for (int i =0 ; i <trades .size (); i ++) {
@@ -168,37 +179,47 @@ private void drawTooltip(ItemStack stack, int x, int y, int mousex, int mousey)
168179 }
169180
170181 @ Override
171- protected void mouseClicked (final int mouseX , final int mouseY , final int mouseButton ) throws IOException {
182+ public boolean mouseClicked (double mouseX , double mouseY , final int mouseButton ) {
172183 // System.out.println("click at "+mouseX+"/"+mouseY);
173184 if (mouseButton ==0
174185 && (mouseX - this .guiLeft ) >= xBase
175186 && (mouseX - this .guiLeft ) <= xBase +textXpos
176187 ) {
177188 MerchantRecipeList trades =getMerchant ().getRecipes (null );
178189 if (trades ==null )
179- return ;
190+ return false ;
180191 int numTrades =trades .size ();
181192 int topAdjust =getTopAdjust (numTrades );
182- int tradeIndex =(mouseY +topAdjust -this .guiTop -titleDistance )/lineHeight ;
193+ int tradeIndex =(( int ) mouseY +topAdjust -this .guiTop -titleDistance )/lineHeight ;
183194 if (tradeIndex >=0 && tradeIndex <numTrades ) {
184195 // System.out.println("tradeIndex="+tradeIndex+", numTrades="+numTrades);
185- GuiButton myNextButton = this .buttonList .get (0 );
186- GuiButton myPrevButton = this .buttonList .get (1 );
196+ // *** This should be doable with :
197+ this .selectedMerchantRecipe = tradeIndex ;
198+ this .func_195391_j ();
199+ // *** need to look into Access Transformers
200+
201+ /*
202+ This is the old way of doing it when we can't select the recipe directly
203+ GuiButton myNextButton = this.buttons.get(0);
204+ GuiButton myPrevButton = this.buttons.get(1);
187205 for (int i=0; i<numTrades; i++)
188206 this.actionPerformed(myPrevButton);
189207 for (int i=0; i<tradeIndex; i++)
190208 this.actionPerformed(myNextButton);
209+ */
191210 MerchantRecipe recipe =trades .get (tradeIndex );
192211 if (!recipe .isRecipeDisabled ()
193212 && inputSlotsAreEmpty ()
194213 && hasEnoughItemsInInventory (recipe )
195214 && canReceiveOutput (recipe .getItemToSell ())) {
196215 transact (recipe );
197216 }
217+ return true ;
198218 }
199219 } else {
200- super .mouseClicked (mouseX , mouseY , mouseButton );
220+ return super .mouseClicked (mouseX , mouseY , mouseButton );
201221 }
222+ return false ;
202223 }
203224
204225 private boolean inputSlotsAreEmpty () {
@@ -308,7 +329,7 @@ private boolean areItemStacksMergable(ItemStack a, ItemStack b) {
308329 if (a ==null || b ==null )
309330 return false ;
310331 if (a .getItem () == b .getItem ()
311- && (!a .getHasSubtypes () || a .getItemDamage ()==b .getItemDamage ())
332+ && (!a .isDamageable () || a .getDamage ()==b .getDamage ())
312333 && ItemStack .areItemStackTagsEqual (a , b ))
313334 return true ;
314335 return false ;
0 commit comments