-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge tag '1.1.0+1.20.1' into 1.20.2
- Loading branch information
Showing
17 changed files
with
250 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,8 @@ | |
|
||
name: build | ||
on: | ||
push: | ||
tags: | ||
- '*' | ||
- workflow_call | ||
- workflow_dispatch | ||
|
||
jobs: | ||
build: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: release | ||
on: | ||
push: | ||
tags: | ||
- '*' | ||
|
||
jobs: | ||
build: | ||
uses: ./.github/workflows/build.yml | ||
release: | ||
needs: [ build ] | ||
runs-on: ubuntu-22.04 | ||
permissions: | ||
contents: write | ||
steps: | ||
- name: Download artifacts | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: Artifacts | ||
path: ./ | ||
- name: Draft release | ||
uses: ncipollo/[email protected] | ||
with: | ||
artifacts: ./*.jar | ||
artifactErrorsFailBuild: true | ||
draft: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
plugins { | ||
id 'fabric-loom' version '1.3-SNAPSHOT' | ||
id 'fabric-loom' version '1.4-SNAPSHOT' | ||
id 'maven-publish' | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# v1 | ||
## 1.0 | ||
### 1.0.0 | ||
Initial release | ||
### 1.0.1 | ||
- Fixed a crash that would occur after a Cartographer failed to generate a map trade in a world that generates no structure. | ||
### 1.0.2 | ||
**This version contains a critical bug and should not be used** | ||
- Force cartographers remember the maps they generated, and always resell it. | ||
### 1.0.3 | ||
**This version contains a critical bug and should not be used** | ||
- Introduced placeholder trades. Fixes cartographers having trouble generating high-level trades in worlds with no structures. | ||
### 1.0.4 | ||
- Fixes mapping issue affecting 1.0.2 and 1.0.3 | ||
### 1.0.5 | ||
- The level of each trade slot is evaluated more accurately for every job. | ||
|
||
## 1.1 | ||
- Added a gamerules that allows cartographers to regenerate maps that have been sold at least once. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 1 addition & 5 deletions
6
src/main/java/tk/estecka/shiftingwares/IVillagerEntityDuck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,6 @@ | ||
package tk.estecka.shiftingwares; | ||
|
||
import java.util.Optional; | ||
import net.minecraft.item.ItemStack; | ||
|
||
public interface IVillagerEntityDuck | ||
{ | ||
Optional<ItemStack> GetCachedMap(String key); | ||
void AddCachedMap(String key, ItemStack mapItem); | ||
MapTradesCache shiftingwares$GetTradeCache(); | ||
} |
154 changes: 121 additions & 33 deletions
154
src/main/java/tk/estecka/shiftingwares/MapTradesCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,154 @@ | ||
package tk.estecka.shiftingwares; | ||
|
||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import net.minecraft.entity.passive.VillagerEntity; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import org.jetbrains.annotations.Nullable; | ||
import net.minecraft.item.FilledMapItem; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.nbt.NbtElement; | ||
import net.minecraft.nbt.NbtList; | ||
import net.minecraft.nbt.NbtString; | ||
import net.minecraft.text.TextContent; | ||
import net.minecraft.text.TranslatableTextContent; | ||
import net.minecraft.village.TradeOffer; | ||
import net.minecraft.village.TradeOfferList; | ||
|
||
public class MapTradesCache | ||
{ | ||
static public final int DATA_FORMAT = 1; | ||
static public final String FORMAT_KEY = "shifting-wares:data_format"; | ||
static public final String MAPID_CACHE = "shifting-wares:created_maps"; | ||
static public final String SOLD_ITEMS = "shifting-wares:sold_items"; | ||
|
||
static public void FillCacheFromTrades(VillagerEntity villager){ | ||
IVillagerEntityDuck villagerMixin = (IVillagerEntityDuck)villager; | ||
TradeOfferList offers = villager.getOffers(); | ||
for (int i=0; i<offers.size(); ++i) | ||
private final Map<String, ItemStack> cachedItems = new HashMap<String,ItemStack>(); | ||
private final Set<String> soldItems = new HashSet<>(); | ||
|
||
/** | ||
* @return null if the item needs not or cannot be cached. | ||
*/ | ||
@Nullable | ||
static public String FindCacheKey(ItemStack item){ | ||
if (!item.isOf(Items.FILLED_MAP)) | ||
return null; | ||
|
||
if (!item.hasCustomName()){ | ||
ShiftingWares.LOGGER.error("Unable to identify map#{} with no name:\n{}", FilledMapItem.getMapId(item), item); | ||
return null; | ||
} | ||
|
||
TextContent fullName = item.getName().getContent(); | ||
String key; | ||
if (fullName instanceof TranslatableTextContent translatable) | ||
key = translatable.getKey(); | ||
else { | ||
ShiftingWares.LOGGER.error("Map#{} name is not a translation key: {} {}", FilledMapItem.getMapId(item), fullName.getClass(), fullName); | ||
key = item.getName().getString(); | ||
} | ||
|
||
return key; | ||
} | ||
|
||
public Optional<ItemStack> GetCachedMap(String key){ | ||
if (this.cachedItems.containsKey(key)) | ||
return Optional.of(this.cachedItems.get(key)); | ||
else | ||
return Optional.empty(); | ||
} | ||
|
||
public void AddCachedMap(String key, ItemStack mapItem){ | ||
Integer neoId=FilledMapItem.getMapId(mapItem); | ||
if (!cachedItems.containsKey(key)) | ||
ShiftingWares.LOGGER.info("New map trade: #{} @ {}", neoId, key); | ||
else | ||
{ | ||
ItemStack sellItem = offers.get(i).getSellItem(); | ||
if (!sellItem.isOf(Items.FILLED_MAP)) | ||
continue; | ||
Integer oldId=FilledMapItem.getMapId(cachedItems.get(key)); | ||
if (soldItems.contains(key)) | ||
ShiftingWares.LOGGER.info("New map trade #{}->#{} @ {}", oldId, neoId, key); | ||
else if (Objects.equals(neoId, oldId)) | ||
ShiftingWares.LOGGER.warn("Updating existing map trade #{} @ {}", neoId, key); | ||
else | ||
ShiftingWares.LOGGER.error("Overwriting existing map trade: #{}->#{} @ {}", oldId, neoId, key); | ||
} | ||
|
||
cachedItems.put(key, mapItem); | ||
soldItems.remove(key); | ||
} | ||
|
||
public boolean HasSold(String key){ | ||
return soldItems.contains(key); | ||
} | ||
|
||
if (!sellItem.hasCustomName()){ | ||
ShiftingWares.LOGGER.error("Unable to identify map#{} with no name in slot {} of {}\n{}", FilledMapItem.getMapId(sellItem), i, villager, sellItem); | ||
/** | ||
* 1. Scans the trade list for maps that might not have been cached. | ||
* This is only really useful the first time a villager is loaded after | ||
* installing the mod. The rest of the time, it's paranoid safeguard. | ||
* | ||
* 2. Detects maps that have been sold at least once, and marks them as | ||
* potentially re-rollable. | ||
*/ | ||
public void FillCacheFromTrades(TradeOfferList offers){ | ||
for (TradeOffer offer : offers) | ||
{ | ||
ItemStack sellItem = offer.getSellItem(); | ||
String cacheKey = FindCacheKey(sellItem); | ||
if (cacheKey == null) | ||
continue; | ||
} | ||
|
||
TextContent fullName = sellItem.getName().getContent(); | ||
String nameKey; | ||
if (fullName instanceof TranslatableTextContent) | ||
nameKey = ((TranslatableTextContent)fullName).getKey(); | ||
else { | ||
ShiftingWares.LOGGER.error("Map name is not a translatation key: {}", fullName); | ||
nameKey = sellItem.getName().getString(); | ||
if (offer.hasBeenUsed()) { | ||
this.soldItems.add(cacheKey); | ||
ShiftingWares.LOGGER.info("Marked map as sold: #{} @ {}", FilledMapItem.getMapId(sellItem), cacheKey); | ||
} | ||
|
||
var oldItem = villagerMixin.GetCachedMap(nameKey); | ||
var oldItem = this.GetCachedMap(cacheKey); | ||
if (oldItem.isEmpty() || !ItemStack.areEqual(sellItem, oldItem.get())){ | ||
ShiftingWares.LOGGER.warn("Caught a map trade that wasn't properly cached: #{} @ {}", FilledMapItem.getMapId(sellItem), villagerMixin); | ||
villagerMixin.AddCachedMap(nameKey, sellItem); | ||
ShiftingWares.LOGGER.warn("Caught a map trade that wasn't properly cached: #{} @ {}", FilledMapItem.getMapId(sellItem), cacheKey); | ||
this.AddCachedMap(cacheKey, sellItem); | ||
} | ||
} | ||
} | ||
|
||
static public Map<String,ItemStack> ReadMapCacheFromNbt(NbtCompound nbt, Map<String, ItemStack> map){ | ||
NbtCompound nbtmap = nbt.getCompound(MAPID_CACHE); | ||
if (nbtmap == null) | ||
return map; | ||
|
||
for (String key : nbtmap.getKeys()) | ||
map.put(key, ItemStack.fromNbt(nbtmap.getCompound(key))); | ||
return map; | ||
/******************************************************************************/ | ||
/* # Serialization */ | ||
/******************************************************************************/ | ||
|
||
public void ReadMapCacheFromNbt(NbtCompound nbt){ | ||
NbtCompound nbtcache = nbt.getCompound(MAPID_CACHE); | ||
NbtList nbtsold = nbt.getList(SOLD_ITEMS, NbtElement.STRING_TYPE); | ||
|
||
if (nbtcache != null) | ||
for (String key : nbtcache.getKeys()){ | ||
ItemStack item = ItemStack.fromNbt(nbtcache.getCompound(key)); | ||
this.cachedItems.put(key, item); | ||
} | ||
|
||
if (nbtsold != null) | ||
for (int i=0; i<nbtsold.size(); ++i){ | ||
String key = nbtsold.getString(i); | ||
this.soldItems.add(key); | ||
} | ||
} | ||
|
||
static public NbtCompound WriteMapCacheToNbt(NbtCompound nbt, Map<String, ItemStack> map){ | ||
NbtCompound nbtmap = new NbtCompound(); | ||
for (var pair : map.entrySet()) | ||
nbtmap.put(pair.getKey(), pair.getValue().writeNbt(new NbtCompound())); | ||
public NbtCompound WriteMapCacheToNbt(NbtCompound nbt){ | ||
NbtCompound nbtcache = new NbtCompound(); | ||
NbtList nbtsold = new NbtList(); | ||
|
||
for (var pair : this.cachedItems.entrySet()) | ||
nbtcache.put(pair.getKey(), pair.getValue().writeNbt(new NbtCompound())); | ||
for (String key : this.soldItems) | ||
nbtsold.add(NbtString.of(key)); | ||
|
||
nbt.putInt(FORMAT_KEY, DATA_FORMAT); | ||
if (!nbtcache.isEmpty()) nbt.put(MAPID_CACHE, nbtcache); | ||
if (!nbtsold.isEmpty() ) nbt.put(SOLD_ITEMS, nbtsold); | ||
|
||
nbt.put(MAPID_CACHE, nbtmap); | ||
return nbt; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.