-
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.
- Removed the Trade Cache and related APIs. - Persistent trades can no longer be rerolled, until they've been used. - Trade Factories now provide their persistence solely through getters, instead of being required to reimplement the whole caching logic. - Persistence data is now stored directly in the trades themselves, instead of inferred from brittle item components.
- Loading branch information
Showing
27 changed files
with
450 additions
and
429 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,6 +5,7 @@ | |
|
||
name: build | ||
on: | ||
- pull_request | ||
- workflow_call | ||
- workflow_dispatch | ||
|
||
|
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.8-SNAPSHOT' | ||
id 'fabric-loom' version '1.7-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
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
71 changes: 71 additions & 0 deletions
71
src/main/java/fr/estecka/shiftingwares/ShiftingTradeData.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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package fr.estecka.shiftingwares; | ||
|
||
import java.util.Optional; | ||
import org.jetbrains.annotations.Nullable; | ||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import net.minecraft.component.DataComponentTypes; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.village.TradeOffer; | ||
import net.minecraft.village.TradeOffers; | ||
import fr.estecka.shiftingwares.api.IShiftingTradeFactory; | ||
import fr.estecka.shiftingwares.duck.ITradeOfferDuck; | ||
|
||
public class ShiftingTradeData | ||
{ | ||
static public final Codec<ShiftingTradeData> CODEC = RecordCodecBuilder.create( | ||
instance -> instance.group( | ||
Identifier.CODEC.optionalFieldOf("tradeId").forGetter(data -> Optional.ofNullable(data.tradeId)), | ||
Codec.BOOL.fieldOf("isPersistent").orElse(false).forGetter(data -> data.isPersistent), | ||
Codec.BOOL.fieldOf("wasNeverUsed").orElse(true).forGetter(data -> data.wasNeverUsed) | ||
) | ||
.apply(instance, ShiftingTradeData::new) | ||
); | ||
|
||
public @Nullable Identifier tradeId = null; | ||
public boolean isPersistent = false; | ||
public boolean wasNeverUsed = true; | ||
|
||
public ShiftingTradeData(){}; | ||
|
||
public ShiftingTradeData(Optional<Identifier> tradeId, boolean isPersistent, boolean wasNeverUsed){ | ||
this.tradeId = tradeId.orElse(null); | ||
this.isPersistent = isPersistent; | ||
this.wasNeverUsed = wasNeverUsed; | ||
}; | ||
|
||
|
||
/** | ||
* Should be called immediately after a factory has produced a new trade. | ||
* It's possible for factories to wrap other factories; persistence should | ||
* be preserved down the line. | ||
* Here, trade ids are being preserved as much as possible, but this has no | ||
* use currently, since SW will not be able to identify the inner factories. | ||
*/ | ||
static public void FinalizeTrade(@Nullable TradeOffer offer, TradeOffers.Factory factory){ | ||
if (offer == null) | ||
return; | ||
|
||
IShiftingTradeFactory factoryData = IShiftingTradeFactory.Of(factory); | ||
ShiftingTradeData offerData = ITradeOfferDuck.Of(offer).shiftingwares$GetTradeData(); | ||
|
||
offerData.isPersistent |= factoryData.shiftingwares$IsItemPersistent(); | ||
|
||
Identifier factoryId = factoryData.shiftingwares$GetTradeId(); | ||
if (factoryId != null) | ||
offerData.tradeId = factoryId; | ||
|
||
ItemStack sellItem = offer.getSellItem(); | ||
if (!offerData.isPersistent && ShouldBePersistent(sellItem)){ | ||
offerData.isPersistent = true; | ||
ShiftingWares.LOGGER.error("A trade factory just produced a persistent item, but did not declare it as such: {} ({})", sellItem.getName().getString(), sellItem.getItem()); | ||
} | ||
else if (offerData.isPersistent && factoryId != null) | ||
ShiftingWares.LOGGER.info("Created new persistent trade: {}", factoryId); | ||
} | ||
|
||
static public boolean ShouldBePersistent(ItemStack stack){ | ||
return stack.contains(DataComponentTypes.MAP_ID); | ||
} | ||
} |
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
Oops, something went wrong.