Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ After publishing, the action prepares the next development version and archives

## Unreleased

- Place a Villager Market (planks around an emerald block) and trade with every villager within 48 blocks, 16 up and 16 down. Offers are grouped by the villager's name, or by profession. Show All lists offers you cannot pay for. x1 buys once, and xN buys as many as you can pay for and the offer still has left.
- Under the trades, [available / max until lock] explains the two numbers on each offer.
- Selecting an offer shows its inputs beside the buy buttons, each with how many of that item you are carrying. Those slots cannot be clicked.
- Buying updates that carried count, and how many times you can still pay.
- Experience from a purchase appears on you. It no longer drops on the villager.
- The trade list shows a scrollbar when there are more offers than fit. Drag it, or use the mouse wheel.
- The Villager Market recipe appears in the recipe book once you have planks or an emerald block.
- The Villager Market is a barrel. Each side has a villager face standing one pixel out, with the nose one pixel farther, and an emerald in the middle of the top and the bottom.
- The market window uses the vanilla inventory frame, buttons, and trade arrows.
- Place a Villager Market (planks around an emerald block) and trade with every villager within 48 blocks, 16 up and 16 down. Offers are grouped by the villager's name, or by profession. Show All lists offers you cannot pay for. Turn it off and the button reads Available, listing only offers you can pay. x1 buys once, and xN buys as many as you can pay for and the offer still has left.

## 1.0.2

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import net.fabricmc.fabric.api.gametest.v1.GameTest;
import net.minecraft.gametest.framework.GameTestHelper;

public class FabricMarketGameTests {

Check warning on line 7 in fabric/src/main/java/net/modcrafters/minecraft/villagermarket/fabric/gametest/FabricMarketGameTests.java

View workflow job for this annotation

GitHub Actions / Minecraft 26.3 (Fabric + NeoForge)

use of default constructor, which does not provide a comment

Check warning on line 7 in fabric/src/main/java/net/modcrafters/minecraft/villagermarket/fabric/gametest/FabricMarketGameTests.java

View workflow job for this annotation

GitHub Actions / Minecraft 26.3 (Fabric + NeoForge)

no comment
@GameTest(structure = "minecraft:empty")
public void oneEmeraldBuysBread(GameTestHelper helper) {

Check warning on line 9 in fabric/src/main/java/net/modcrafters/minecraft/villagermarket/fabric/gametest/FabricMarketGameTests.java

View workflow job for this annotation

GitHub Actions / Minecraft 26.3 (Fabric + NeoForge)

no comment
MarketGameTests.oneEmeraldBuysBread(helper);
}

@GameTest(structure = "minecraft:empty")
public void componentsMustMatch(GameTestHelper helper) {

Check warning on line 14 in fabric/src/main/java/net/modcrafters/minecraft/villagermarket/fabric/gametest/FabricMarketGameTests.java

View workflow job for this annotation

GitHub Actions / Minecraft 26.3 (Fabric + NeoForge)

no comment
MarketGameTests.componentsMustMatch(helper);
}

Expand All @@ -21,7 +21,12 @@
}

@GameTest(structure = "minecraft:empty")
public void adjustedPriceIsWhatIsCharged(GameTestHelper helper) {

Check warning on line 24 in fabric/src/main/java/net/modcrafters/minecraft/villagermarket/fabric/gametest/FabricMarketGameTests.java

View workflow job for this annotation

GitHub Actions / Minecraft 26.3 (Fabric + NeoForge)

no comment
MarketGameTests.adjustedPriceIsWhatIsCharged(helper);
}

@GameTest(structure = "minecraft:empty")
public void experienceLandsOnThePlayer(GameTestHelper helper) {

Check warning on line 29 in fabric/src/main/java/net/modcrafters/minecraft/villagermarket/fabric/gametest/FabricMarketGameTests.java

View workflow job for this annotation

GitHub Actions / Minecraft 26.3 (Fabric + NeoForge)

no comment
MarketGameTests.experienceLandsOnThePlayer(helper);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,39 @@
// Hit testing and the Show All filter. Both screens draw this; neither one decides the rules.
public final class MarketScreenLogic {
public static final int WIDTH = 256;
public static final int HEIGHT = 209;
public static final int GROUP_X = 6;
public static final int GROUP_Y = 6;
public static final int HEIGHT = 180;
public static final int GROUP_X = 8;
public static final int GROUP_Y = 18;
public static final int GROUP_W = 88;
public static final int GROUP_H = 140;
public static final int GROUP_H = 120;
public static final int GROUP_ROW = 20;
public static final int OFFER_X = 100;
public static final int OFFER_Y = 6;
public static final int OFFER_W = 149;
public static final int OFFER_H = 165;
public static final int OFFER_ROW = 28;
public static final int SHOW_X = 5;
public static final int OFFER_Y = 18;
public static final int OFFER_W = 148;
public static final int OFFER_H = 120;
public static final int OFFER_ROW = 20;
public static final int COUNT_Y = OFFER_Y + OFFER_H + 2;
public static final int SHOW_X = 8;
public static final int SHOW_Y = 152;
public static final int SHOW_W = 90;
public static final int SHOW_W = 88;
public static final int SHOW_H = 20;
public static final int SELECTED_Y = 176;
public static final int ONCE_X = 156;
public static final int MAX_X = 196;
public static final int BUTTON_Y = 180;
public static final int BUTTON_W = 35;
public static final int BUTTON_H = 20;
public static final int ONCE_X = 164;
public static final int MAX_X = 208;
public static final int BUTTON_W = 40;
public static final int BUTTON_H = 16;
public static final int BUTTON_Y = SHOW_Y + (SHOW_H - BUTTON_H) / 2;
public static final int COST_SLOT = 18;
public static final int COST_Y = BUTTON_Y + (BUTTON_H - COST_SLOT) / 2;
public static final int BAR_W = 6;
public static final int BAR_X = WIDTH - 4 - BAR_W;

public boolean showAll = true;
public String selectedGroup = "";
public int groupScroll;
public int offerScroll;
public ListedOffer selected;
private boolean draggingBar;
private int barGrab;

public List<String> groups(List<ListedOffer> offers) {
LinkedHashSet<String> keys = new LinkedHashSet<>();
Expand All @@ -62,6 +69,69 @@ public List<ListedOffer> visible(List<ListedOffer> offers, Inventory inventory)
return shown;
}

public static int costSlotX(int index, boolean second) {
int slots = second ? 2 : 1;
return ONCE_X - 4 - slots * COST_SLOT + index * COST_SLOT;
}

public static int offerRows() {
return Math.max(1, OFFER_H / OFFER_ROW);
}

public static boolean offerBar(int count) {
return count > offerRows();
}

public static int offerWidth(int count) {
return offerBar(count) ? BAR_X - OFFER_X - 2 : OFFER_W;
}

public void fitOffer(int count) {
offerScroll = clamp(offerScroll, count - offerRows());
}

public int offerThumbY(int count) {
int thumb = offerThumbH(count);
int travel = Math.max(1, OFFER_H - thumb);
int max = Math.max(1, count - offerRows());
return OFFER_Y + offerScroll * travel / max;
}

public int offerThumbH(int count) {
return Math.max(BAR_W * 2, OFFER_H * offerRows() / Math.max(count, 1));
}

public boolean pressBar(int x, int y, int count) {
if (!offerBar(count) || !inside(x, y, BAR_X, OFFER_Y, BAR_W, OFFER_H)) {
return false;
}
draggingBar = true;
int thumbY = offerThumbY(count);
int thumbH = offerThumbH(count);
barGrab = y >= thumbY && y < thumbY + thumbH ? y - thumbY : thumbH / 2;
dragBar(y, count);
return true;
}

public void dragBar(int y, int count) {
if (!draggingBar || !offerBar(count)) {
return;
}
int thumb = offerThumbH(count);
int travel = Math.max(1, OFFER_H - thumb);
int max = Math.max(1, count - offerRows());
offerScroll = clamp(y - barGrab - OFFER_Y, travel);
offerScroll = offerScroll * max / travel;
}

public void releaseBar() {
draggingBar = false;
}

public int held(Inventory inventory, ItemStack cost) {
return count(inventory, cost);
}

public int affordable(ListedOffer offer, Inventory inventory) {
boolean hasSecond = !offer.costB().isEmpty();
return TradeMath.affordableUses(
Expand All @@ -83,7 +153,7 @@ public void onOffers(List<ListedOffer> offers) {
selected = null;
}

public Click click(double mouseX, double mouseY, int left, int top, int rowHeight, List<ListedOffer> offers, Inventory inventory) {
public Click click(double mouseX, double mouseY, int left, int top, List<ListedOffer> offers, Inventory inventory) {
int x = (int) mouseX - left;
int y = (int) mouseY - top;
if (inside(x, y, SHOW_X, SHOW_Y, SHOW_W, SHOW_H)) {
Expand All @@ -99,7 +169,7 @@ public Click click(double mouseX, double mouseY, int left, int top, int rowHeigh
}
}
if (inside(x, y, GROUP_X, GROUP_Y, GROUP_W, GROUP_H)) {
int index = groupScroll + (y - GROUP_Y) / rowHeight;
int index = groupScroll + (y - GROUP_Y) / GROUP_ROW;
List<String> groups = groups(offers);
if (index == 0) {
selectedGroup = "";
Expand All @@ -108,25 +178,28 @@ public Click click(double mouseX, double mouseY, int left, int top, int rowHeigh
}
return Click.GROUP;
}
if (inside(x, y, OFFER_X, OFFER_Y, OFFER_W, OFFER_H)) {
List<ListedOffer> shown = visible(offers, inventory);
fitOffer(shown.size());
if (pressBar(x, y, shown.size())) {
return Click.BAR;
}
if (inside(x, y, OFFER_X, OFFER_Y, offerWidth(shown.size()), OFFER_H)) {
int index = offerScroll + (y - OFFER_Y) / OFFER_ROW;
List<ListedOffer> shown = visible(offers, inventory);
selected = index >= 0 && index < shown.size() ? shown.get(index) : null;
return Click.OFFER;
}
return Click.NONE;
}

public void scroll(double mouseX, double mouseY, int left, int top, double delta, int rowHeight, int offerCount, int groupCount) {
public void scroll(double mouseX, double mouseY, int left, int top, double delta, int offerCount, int groupCount) {
int x = (int) mouseX - left;
int y = (int) mouseY - top;
int step = delta > 0 ? -1 : 1;
if (inside(x, y, GROUP_X, GROUP_Y, GROUP_W, GROUP_H)) {
int visible = Math.max(1, GROUP_H / rowHeight);
int visible = Math.max(1, GROUP_H / GROUP_ROW);
groupScroll = clamp(groupScroll + step, groupCount + 1 - visible);
} else if (inside(x, y, OFFER_X, OFFER_Y, OFFER_W, OFFER_H)) {
int visible = Math.max(1, OFFER_H / OFFER_ROW);
offerScroll = clamp(offerScroll + step, offerCount - visible);
} else if (inside(x, y, OFFER_X, OFFER_Y, BAR_X + BAR_W - OFFER_X, OFFER_H)) {
offerScroll = clamp(offerScroll + step, offerCount - offerRows());
}
}

Expand All @@ -149,6 +222,6 @@ private static int count(Inventory inventory, ItemStack cost) {
}

public enum Click {
NONE, TOGGLE, GROUP, OFFER, ONCE, MAX
NONE, TOGGLE, GROUP, OFFER, ONCE, MAX, BAR
}
}
Loading
Loading