Skip to content

Commit

Permalink
1.20.2 Port (#8)
Browse files Browse the repository at this point in the history
- Replaced the loot function's Serializer with a Codec
- Added painting to the Wandering Trader's rebalanced trade pool
- Added missing credits
  • Loading branch information
Estecka authored Sep 22, 2023
1 parent b483a7d commit 3defe55
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 49 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
# against bad commits.

name: build
on: [pull_request, push]
on:
push:
tags:
- '*'

jobs:
build:
Expand Down
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
# Invariable-Paintings
# Invariable Paintings

Turns paintings into collectibles, by making them harder to obtain, and have the paintings in you inventory remember which variant they are.
## Overview
Turns paintings into collectibles.

## Changes
When a painting is broken, the dropped item will remember which variant it was, and will only ever allow this variant to be placed. Those variant-locked items are the same as the ones available in the vanilla creative menu, so no new item type was added to the game.

Paintings are no longer craftable and must be obtained through other means, such as trading, fishing and chest loots.


## All Changes
### Server-side
- When a painting is broken, the dropped item will remember which variant it was. Those variant-locked items are the same as the ones available in the vanilla creative menu; the vanilla variantless painting still exists in the code, but is no longer obtainable in survival. If you were to obtain one, it would still drop a variant-locked item after being placed and broken.
- Paintings can no longer be crafted, but can be acquired through other means.
- Wandering Traders may sell paintings as their last trades. Master shepherd will sell variant-locked paintings instead of the variantless one. (This will not retroactively apply to existing master shepherds).
- Broken paintings drop a variant-locked item instead of variantless ones.
- Placement of variant-locked paintings in tight spaces is more forgiving.
- Paintings are no longer craftables.
- Wandering Traders and Master Shepherds can sell variant-locked paintings. Shepherds no longer sell variantless paintings. (This will not retroactively apply to existing master shepherds).
- _(Requires [Patched](https://modrinth.com/mod/patched))_ Paintings will be added to several loot tables: fishing, monster-rooms, buried treasures, shipwrecks, woodland mansions, pillager outposts, and stronghold libraries.
The drop rate for these loots was chosen aphazardly, and is subject to be rebalanced.
- Added a new function `lock_variant_randomly`, which can applied to painting items in loot tables.

### Client-side
- Fixes a vanilla bug whereby using variant-locked items in too small a space would consume the item without placing the painting.
- _(Requires [CIT Resewn](https://modrinth.com/mod/cit-resewn))_ Makes the vanilla painting items have a unique texture for each variant.
- Fixes a vanilla bug whereby using variant-locked items in too small a space would consume the item without placing the painting. A warning message is shown instead.
- _(Requires [CIT Resewn](https://modrinth.com/mod/cit-resewn))_ Provides unique inventory icon for every vanilla variant. Icons for modded variants can be provided via a resource pack. (See the sources for examples, and CIT resewn for documentation.)
- Makes the painting tooltip a bit more compact, and display the painting's title in the item name.


## Compatibility
Any other mods that add new paintings in accordance with the vanilla system should be compatible, and their paintings should be available in the loot and trade pools.

This will not work properly with mods such as [Custom Paintings](https://modrinth.com/mod/custom-paintings-mod) or [Client Paintings](https://modrinth.com/mod/client-paintings), which bypass the vanilla variant system and implement their own.
On the other hand, mods that add new paintings in accordance with the vanilla system should not pose any problem, and their paintings should be available in the loot and trade pools.
Mods that bypass the vanilla system and implement their own, like _Custom Paintings_ or _Client Paintings_, will prevent InvarPaint from working properly. [More Canvases v2](https://modrinth.com/mod/more-canvases) is their equivalent that respects the vanilla variant system.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
plugins {
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'fabric-loom' version '1.3-SNAPSHOT'
id 'maven-publish'
}

version = project.mod_version
version = "${project.mod_version}+${project.minecraft_version}"
group = project.maven_group

repositories {
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.1
loader_version=0.14.21
minecraft_version=1.20.2
yarn_mappings=1.20.2+build.1
loader_version=0.14.22

#Fabric api
fabric_version=0.83.1+1.20.1
fabric_version=0.89.1+1.20.2

# Mod Properties
mod_version = 1.2.0+1.20.1
maven_group = tk.estecka
mod_version = 1.2.1
maven_group = tk.estecka.invarpaint
archives_base_name = invariable-paintings
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
package tk.estecka.invarpaint;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;

import java.util.List;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.condition.LootCondition;
import net.minecraft.loot.condition.LootConditionTypes;
import net.minecraft.loot.context.LootContext;
import net.minecraft.loot.function.ConditionalLootFunction;
import net.minecraft.loot.function.LootFunctionType;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import net.minecraft.util.dynamic.Codecs;

public class LockVariantRandomlyLootFunction
extends ConditionalLootFunction
{
static public class Serializer
extends ConditionalLootFunction.Serializer<LockVariantRandomlyLootFunction>
{
@Override
public LockVariantRandomlyLootFunction fromJson(JsonObject json, JsonDeserializationContext ctx, LootCondition[] conditions){
return new LockVariantRandomlyLootFunction(conditions);
}
static public final Codec<LockVariantRandomlyLootFunction> CODEC;

static {
CODEC = RecordCodecBuilder.create(instance -> {
return instance.group(Codecs.createStrictOptionalFieldCodec(LootConditionTypes.CODEC.listOf(), "conditions", List.of()).forGetter(conditionalLootFunction -> conditionalLootFunction.conditions)).apply(instance, LockVariantRandomlyLootFunction::new);
});
}

static public final LootFunctionType TYPE = Registry.register(
Registries.LOOT_FUNCTION_TYPE,
new Identifier("lock_variant_randomly"),
new LootFunctionType(new LockVariantRandomlyLootFunction.Serializer())
new LootFunctionType(CODEC)
);

static public void RegisterFunction(){
// Loads the class and initializes static variables
};

public LockVariantRandomlyLootFunction(LootCondition[] conditions){
public LockVariantRandomlyLootFunction(List<LootCondition> conditions){
super(conditions);
}

Expand Down
25 changes: 11 additions & 14 deletions src/main/java/tk/estecka/invarpaint/SellPaintingFactory.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package tk.estecka.invarpaint;

import java.util.List;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.Nullable;

import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import net.fabricmc.fabric.api.object.builder.v1.trade.TradeOfferHelper;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.math.random.Random;
import net.minecraft.village.TradeOffer;
import net.minecraft.village.TradeOffers;
import net.minecraft.village.TradeOffers.Factory;
import net.minecraft.village.VillagerProfession;

public class SellPaintingFactory implements TradeOffers.Factory
Expand All @@ -20,20 +23,14 @@ public class SellPaintingFactory implements TradeOffers.Factory
public static final int MASTER_LVL = 5;

public static void RegisterPaintings(){
Int2ObjectMap<TradeOffers.Factory[]> shepherd = TradeOffers.PROFESSION_TO_LEVELED_TRADE.get(VillagerProfession.SHEPHERD);
Int2ObjectMap<TradeOffers.Factory[]> wanderer = TradeOffers.WANDERING_TRADER_TRADES;

InvariablePaintings.LOGGER.info("Replacing villager trades");

//This line assumes that variantless paintings are the only trade available for master Shepherds, and overwrites them.
InvariablePaintings.LOGGER.info("Adding locked paintings to trade pools");

//This assumes that variantless painting is the only master trade available to Shepherds, and overwrites it.
Int2ObjectMap<Factory[]> shepherd = TradeOffers.PROFESSION_TO_LEVELED_TRADE.get(VillagerProfession.SHEPHERD);
shepherd.get(MASTER_LVL)[0] = new SellPaintingFactory();

TradeOffers.Factory[] old = wanderer.get(APPRENTICE_LVL);
TradeOffers.Factory[] neo = new TradeOffers.Factory[old.length+1];
for (int i=0; i<old.length; i++)
neo[i] = old[i];
neo[old.length] = new SellPaintingFactory();
wanderer.put(APPRENTICE_LVL, neo);

TradeOfferHelper.registerWanderingTraderOffers(APPRENTICE_LVL, list->list.add(new SellPaintingFactory()));
TradeOfferHelper.registerRebalancedWanderingTraderOffers(builder->builder.addOffersToPool(TradeOfferHelper.WanderingTraderOffersBuilder.SELL_SPECIAL_ITEMS_POOL, new SellPaintingFactory()));
}

@Override
Expand Down
9 changes: 5 additions & 4 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"version": "${version}",

"name": "Invariable Paintings",
"description": "Painting variant are no longer random, turning them into collectibles.",
"description": "Turns paintings into collectibles. They are harder to obtain, and remember which variant they are when dropped.",
"authors": [
"Estecka"
"Estecka",
"Andrew Grant"
],
"contact": {
"homepage": "https://modrinth.com/mod/invariable-paintings",
Expand All @@ -27,9 +28,9 @@
],

"depends": {
"fabricloader": ">=0.14.21",
"fabricloader": ">=0.14.22",
"fabric-api": "*",
"minecraft": "~1.20.1",
"minecraft": "~1.20.2",
"java": ">=17"
},
"suggests": {
Expand Down

0 comments on commit 3defe55

Please sign in to comment.