Skip to content

Commit

Permalink
Modify painting name and tooltips, and create unique textures for eac…
Browse files Browse the repository at this point in the history
…h painting item (#3)

* add unique painting item textures as an optional resource pack

* modify painting item name and tooltips

* Updated readme. Version up.

---------

Co-authored-by: Estecka <[email protected]>
  • Loading branch information
Andrew6rant and Estecka authored Jun 21, 2023
1 parent f53f794 commit abb92c3
Show file tree
Hide file tree
Showing 67 changed files with 234 additions and 30 deletions.
37 changes: 12 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,21 @@ Turns paintings into collectibles, by making them harder to obtain, and have the

## Changes

- When a painting is broken, the dropped item will remember which variant it was; those are the same as the paintings 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.
- Fixes a vanilla bug whereby using variant-locked items in too small a space would consume the item without placing the painting.
### 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.
- Master Sheperds and Wandering Traders may sell paintings as their last trades.
Master sheperd sell variant-locked paintings instead of the variantless one. (This will not retroactively apply to existing master sheperds).
- If using the mod [Patched](https://modrinth.com/mod/patched), paintings will also 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 hapazardly, and is subject to be rebalanced.
- Added a new loot function to be used in loot tables, which randomizes a painting's variant:
```json
{
"type": "item",
"name": "minecraft:painting",
"functions": [
{
"function": "lock_variant_randomly"
}
]
}
```
- 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).
- _(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.
- Makes the painting tooltip a bit more compact, and display the painting's title in the item name.


## Compatibility

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.

## Versions

- Minecraft 1.20.1
- Fabric Loader 0.14.21 or above
- Fabric API 0.83.1 or above
- Optionally: Patched 1.1.0 or above
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ loader_version=0.14.21
fabric_version=0.83.1+1.20.1

# Mod Properties
mod_version = 1.1.0+1.20.1
mod_version = 1.2.0+1.20.1
maven_group = tk.estecka
archives_base_name = invariable-paintings
92 changes: 89 additions & 3 deletions src/main/java/tk/estecka/invarpaint/mixin/DecorationItemMixin.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,58 @@
package tk.estecka.invarpaint.mixin;

import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.decoration.AbstractDecorationEntity;
import net.minecraft.entity.decoration.painting.PaintingEntity;
import net.minecraft.entity.decoration.painting.PaintingVariant;
import net.minecraft.item.DecorationItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.registry.Registries;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.text.TextContent;
import net.minecraft.text.TranslatableTextContent;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import tk.estecka.invarpaint.InvariablePaintings;
import tk.estecka.invarpaint.PaintStackCreator;

import java.util.List;
import java.util.Optional;

import java.util.concurrent.atomic.AtomicReference;

@Mixin(DecorationItem.class)
public class DecorationItemMixin {
public class DecorationItemMixin extends Item {

@Mutable
@Final
@Shadow
private final EntityType<? extends AbstractDecorationEntity> entityType;

private ItemStack itemStack;

@Inject(
public DecorationItemMixin(Settings settings, EntityType<? extends AbstractDecorationEntity> entityType) {
super(settings);
this.entityType = entityType;
}


@Inject(
method = "useOnBlock(Lnet/minecraft/item/ItemUsageContext;)Lnet/minecraft/util/ActionResult;",
at = @At(
value = "INVOKE",
Expand Down Expand Up @@ -62,4 +88,64 @@ private Optional<PaintingEntity> filterPlacedPainting(World world, BlockPos pos,
return PaintingEntity.placePainting(world, pos, facing);
}
}

@Inject(
method = "appendTooltip(Lnet/minecraft/item/ItemStack;Lnet/minecraft/world/World;Ljava/util/List;Lnet/minecraft/client/item/TooltipContext;)V",
at = @At(
value = "TAIL"
)
)
public void condenseTooltip(ItemStack stack, World world, List<Text> tooltip, TooltipContext context, CallbackInfo ci) {
if (this.entityType == EntityType.PAINTING) {
AtomicReference<Text> atmAuthor = new AtomicReference<Text>(null);
AtomicReference<Text> atmSize = new AtomicReference<Text>(null);
tooltip.removeIf(text -> {
TextContent textContent = text.getContent();
if (textContent instanceof TranslatableTextContent) {
String key = ((TranslatableTextContent) textContent).getKey();
if (key.equals("painting.random"))
return true;
else if (key.startsWith("painting.") && key.endsWith(".title"))
return true;
else if (key.startsWith("painting.") && key.endsWith(".author")){
atmAuthor.set(text);
return true;
}
else if (key.equals("painting.dimensions")){
atmSize.set(text);
return true;
}
}
return false;
});

if (PaintStackCreator.GetVariantId(stack) == null)
tooltip.add(Text.translatable("painting.random").formatted(Formatting.GRAY));
else {
Text author=atmAuthor.get(), size=atmSize.get();
MutableText authorLine = Text.empty();
if (size!=null)
authorLine.append(size);
if (size!=null && author!=null)
authorLine.append(" ");
if (author!=null)
authorLine.append(author);
tooltip.add(authorLine);
}
}
}

@Override
public Text getName(ItemStack stack) {
if (this.entityType == EntityType.PAINTING) {
String variantId = PaintStackCreator.GetVariantId(stack);
if (variantId != null) {
return Text.translatable(this.getTranslationKey(stack)) // I could just use translatable variables,
.append(Text.literal(" (") // but this way is compatible with other languages
.append(Text.translatable("painting."+variantId.replace(":",".")+".title")
.append(")")).formatted(Formatting.YELLOW));
}
}
return super.getName();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/alban.png
nbt.EntityTag.variant=minecraft:alban
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/aztec.png
nbt.EntityTag.variant=minecraft:aztec
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/aztec2.png
nbt.EntityTag.variant=minecraft:aztec2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/bomb.png
nbt.EntityTag.variant=minecraft:bomb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/burning_skull.png
nbt.EntityTag.variant=minecraft:burning_skull
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/bust.png
nbt.EntityTag.variant=minecraft:bust
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/courbet.png
nbt.EntityTag.variant=minecraft:courbet
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/creebet.png
nbt.EntityTag.variant=minecraft:creebet
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type=item
items=painting
texture=minecraft:item/painting.png
nbt.EntityTag.variant=pattern:*
weight=-1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/donkey_kong.png
nbt.EntityTag.variant=minecraft:donkey_kong
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/earth.png
nbt.EntityTag.variant=minecraft:earth
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/fighters.png
nbt.EntityTag.variant=minecraft:fighters
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/fire.png
nbt.EntityTag.variant=minecraft:fire
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/graham.png
nbt.EntityTag.variant=minecraft:graham
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/kebab.png
nbt.EntityTag.variant=minecraft:kebab
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/match.png
nbt.EntityTag.variant=minecraft:match
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/pigscene.png
nbt.EntityTag.variant=minecraft:pigscene
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/plant.png
nbt.EntityTag.variant=minecraft:plant
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/pointer.png
nbt.EntityTag.variant=minecraft:pointer
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/pool.png
nbt.EntityTag.variant=minecraft:pool
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type=item
items=painting
texture=minecraft:item/random.png
# nbt.EntityTag=exists:false is unfortunately not in CIT Resewn
weight=-2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/sea.png
nbt.EntityTag.variant=minecraft:sea
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/skeleton.png
nbt.EntityTag.variant=minecraft:skeleton
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/skull_and_roses.png
nbt.EntityTag.variant=minecraft:skull_and_roses
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/stage.png
nbt.EntityTag.variant=minecraft:stage
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/sunset.png
nbt.EntityTag.variant=minecraft:sunset
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/void.png
nbt.EntityTag.variant=minecraft:void
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/wanderer.png
nbt.EntityTag.variant=minecraft:wanderer
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/wasteland.png
nbt.EntityTag.variant=minecraft:wasteland
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/water.png
nbt.EntityTag.variant=minecraft:water
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/wind.png
nbt.EntityTag.variant=minecraft:wind
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type=item
items=painting
texture=minecraft:item/wither.png
nbt.EntityTag.variant=minecraft:wither
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"java": ">=17"
},
"suggests": {
"patched": ">=1.20-1.1.0"
"patched": ">=1.20-1.1.0",
"cit-resewn": "~1.1.3+1.20"
}
}

0 comments on commit abb92c3

Please sign in to comment.