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

Commit c1e94a8

Browse files
committed
First port to Rift
1 parent bad87a2 commit c1e94a8

File tree

13 files changed

+242
-203
lines changed

13 files changed

+242
-203
lines changed

build.gradle

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,58 @@
11
buildscript {
22
repositories {
3-
jcenter()
4-
maven { url = "http://files.minecraftforge.net/maven" }
5-
}
3+
mavenCentral()
4+
maven { url 'https://www.jitpack.io' }
5+
maven { url 'https://files.minecraftforge.net/maven' }
6+
maven { url 'http://repo.spongepowered.org/maven' }
7+
}
68
dependencies {
7-
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
8-
}
9+
classpath 'com.github.Chocohead:ForgeGradle:moderniser-SNAPSHOT'
10+
classpath 'org.spongepowered:mixingradle:0.6-SNAPSHOT'
11+
}
912
}
10-
apply plugin: 'net.minecraftforge.gradle.forge'
11-
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
1213

14+
apply plugin: 'net.minecraftforge.gradle.tweaker-client'
15+
apply plugin: 'org.spongepowered.mixin'
16+
apply plugin: 'java'
1317

14-
version = "1.12-forge14.21.1.2387-1.2"
15-
group = "de.guntram.mcmod.easiervillagertrading" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
18+
group = "de.guntram.mcmod.easiervillagertrading"
19+
// group = "de.guntram.mcmod"
20+
version = "1.13.2-rift1.0.4.77-1.3beta1"
1621
archivesBaseName = "easiervillagertrading"
1722

18-
sourceCompatibility = targetCompatibility = "1.8" // Need this here so eclipse task generates correctly.
19-
compileJava {
20-
sourceCompatibility = targetCompatibility = "1.8"
21-
}
23+
sourceCompatibility = '1.8'
24+
targetCompatibility = '1.8'
2225

23-
minecraft {
24-
version = "1.12-14.21.1.2387"
25-
runDir = "run"
26-
27-
// the mappings can be changed at any time, and must be in the following format.
28-
// snapshot_YYYYMMDD snapshot are built nightly.
29-
// stable_# stables are built at the discretion of the MCP team.
30-
// Use non-default mappings at your own risk. they may not always work.
31-
// simply re-run your setup task after changing the mappings to update your workspace.
32-
mappings = "snapshot_20170624"
33-
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
26+
repositories {
27+
mavenCentral()
28+
maven { url 'https://www.dimdev.org/maven/' }
29+
maven { url 'https://www.jitpack.io' }
30+
maven { url "file:///home/gbl/SoftwareProjects/MyProjects/MinecraftMods/" }
31+
maven { url 'http://repo.strezz.org/artifactory/list/Strezz-Central' }
32+
maven { url "https://libraries.minecraft.net" }
3433
}
3534

3635
dependencies {
37-
// you may put jars on which you depend on in ./libs
38-
// or you may define them like so..
39-
//compile "some.group:artifact:version:classifier"
40-
//compile "some.group:artifact:version"
41-
42-
// real examples
43-
//compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env
44-
//compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env
36+
// implementation 'com.github.Chocohead:Rift:jitpack-SNAPSHOT:dev'
37+
implementation 'com.mojang:brigadier:1.0.15'
4538

46-
// the 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime.
47-
//provided 'com.mod-buildcraft:buildcraft:6.0.8:dev'
39+
implementation 'patchurl:Rift:1.0.4-SNAPSHOT:dev'
40+
implementation 'org.dimdev:mixin:0.7.11-SNAPSHOT'
41+
}
4842

49-
// the deobf configurations: 'deobfCompile' and 'deobfProvided' are the same as the normal compile and provided,
50-
// except that these dependencies get remapped to your current MCP mappings
51-
//deobfCompile 'com.mod-buildcraft:buildcraft:6.0.8:dev'
52-
//deobfProvided 'com.mod-buildcraft:buildcraft:6.0.8:dev'
5343

54-
// for more info...
55-
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
56-
// http://www.gradle.org/docs/current/userguide/dependency_management.html
44+
minecraft {
45+
version = "1.13.2"
46+
mappings = 'snapshot_20181130'
47+
runDir = "run"
48+
tweakClass = 'org.dimdev.riftloader.launch.RiftLoaderClientTweaker'
49+
replace "@VERSION@", project.version
50+
replaceIn "EasierVillagerTrading.java"
51+
}
5752

53+
mixin {
54+
defaultObfuscationEnv notch
55+
add sourceSets.main, 'mixins.easiervillagertrading.refmap.json'
5856
}
5957

6058
processResources {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package de.guntram.mcmod.debug;
7+
8+
import net.minecraft.nbt.INBTBase;
9+
import net.minecraft.nbt.NBTTagCompound;
10+
11+
/**
12+
*
13+
* @author gbl
14+
*/
15+
public class NBTdump {
16+
public static void dump(NBTTagCompound tag, int indent) {
17+
StringBuilder res;
18+
for (String s: tag.keySet()) {
19+
res=new StringBuilder();
20+
for (int i=0; i<indent; i++)
21+
res.append(" ");
22+
INBTBase elem = tag.get(s);
23+
if (elem.getId() == 8) {
24+
res.append(s).append(":").append(tag.getString(s));
25+
} else if (elem.getId() == 2) {
26+
res.append(s).append(":").append(tag.getShort(s));
27+
} else if (elem.getId() == 3) {
28+
res.append(s).append(":").append(tag.getInt(s));
29+
} else if (elem.getId() == 10) {
30+
res.append(s).append(": Compound");
31+
} else {
32+
res.append(s).append(": Type ").append(elem.getId());
33+
}
34+
System.out.println(res);
35+
if (elem.getId() == 10)
36+
dump(tag.getCompound(s), indent+1);
37+
}
38+
}
39+
}

src/main/java/de/guntram/mcmod/easiervillagertrading/BetterGuiMerchant.java

Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@
55
*/
66
package 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+
1010
import net.minecraft.client.gui.GuiMerchant;
1111
import net.minecraft.client.renderer.GlStateManager;
1212
import net.minecraft.client.renderer.RenderHelper;
1313
import net.minecraft.enchantment.Enchantment;
14+
import net.minecraft.entity.IMerchant;
1415
import net.minecraft.entity.player.InventoryPlayer;
1516
import net.minecraft.inventory.ClickType;
16-
import net.minecraft.item.Item;
1717
import net.minecraft.item.ItemEnchantedBook;
1818
import net.minecraft.item.ItemStack;
19+
import net.minecraft.nbt.NBTTagCompound;
1920
import net.minecraft.nbt.NBTTagList;
2021
import net.minecraft.util.ResourceLocation;
22+
import net.minecraft.util.registry.IRegistry;
2123
import net.minecraft.village.MerchantRecipe;
2224
import net.minecraft.village.MerchantRecipeList;
2325
import 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

Comments
 (0)