Skip to content

Commit

Permalink
Backport 1.1.0 to Minecraft 1.19.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Estecka committed Jun 20, 2023
2 parents 6e281a1 + f53f794 commit a2fa93c
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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.
- 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).
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_mappings=1.19.4+build.2
loader_version=0.14.19

# Mod Properties
mod_version = 1.0.0+1.19.4
mod_version = 1.1.0+1.19.4
maven_group = tk.estecka
archives_base_name = invariable-paintings

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/tk/estecka/invarpaint/PaintStackCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,16 @@ static public ItemStack CreateVariant(String variantId){
return SetVariant(new ItemStack(Items.PAINTING), variantId);
}

static public String GetVariantId(ItemStack stack){
NbtCompound nbt = stack.getNbt();
if (nbt == null || !nbt.contains(ENTITY_TAG, NbtCompound.COMPOUND_TYPE))
return null;

NbtCompound entityTag = nbt.getCompound(ENTITY_TAG);
if (!entityTag.contains(VARIANT_TAG, NbtCompound.STRING_TYPE))
return null;

return entityTag.getString(VARIANT_TAG);
}

}
65 changes: 65 additions & 0 deletions src/main/java/tk/estecka/invarpaint/mixin/DecorationItemMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package tk.estecka.invarpaint.mixin;

import net.minecraft.entity.decoration.painting.PaintingEntity;
import net.minecraft.entity.decoration.painting.PaintingVariant;
import net.minecraft.item.DecorationItem;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.registry.Registries;
import net.minecraft.util.ActionResult;
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.Mixin;
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.CallbackInfoReturnable;
import tk.estecka.invarpaint.InvariablePaintings;
import tk.estecka.invarpaint.PaintStackCreator;

import java.util.Optional;


@Mixin(DecorationItem.class)
public class DecorationItemMixin {
private ItemStack itemStack;

@Inject(
method = "useOnBlock(Lnet/minecraft/item/ItemUsageContext;)Lnet/minecraft/util/ActionResult;",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/entity/decoration/painting/PaintingEntity;placePainting(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/Direction;)Ljava/util/Optional;",
shift = At.Shift.BEFORE
)
)
private void captureItemStack(ItemUsageContext context, CallbackInfoReturnable<ActionResult> cir) {
itemStack = context.getStack();
}

@Redirect(
method = "useOnBlock(Lnet/minecraft/item/ItemUsageContext;)Lnet/minecraft/util/ActionResult;",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/entity/decoration/painting/PaintingEntity;placePainting(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/Direction;)Ljava/util/Optional;"
)
)
private Optional<PaintingEntity> filterPlacedPainting(World world, BlockPos pos, Direction facing) {
String variantId = PaintStackCreator.GetVariantId(this.itemStack);
PaintingVariant itemVariant = (variantId==null) ? null : Registries.PAINTING_VARIANT.get(new Identifier(variantId));

if (itemVariant != null) {
PaintingEntity entity = new PaintingEntity(world, pos, facing, Registries.PAINTING_VARIANT.getEntry(itemVariant));
if (entity.canStayAttached())
return Optional.of(entity);
else
return Optional.empty();
}
else {
if (variantId != null)
InvariablePaintings.LOGGER.warn("Unknown painting id: {}", variantId);
return PaintingEntity.placePainting(world, pos, facing);
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/invarpaint.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"package": "tk.estecka.invarpaint.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"DecorationItemMixin",
"PaintingDropLocker"
],
"injectors": {
Expand Down

0 comments on commit a2fa93c

Please sign in to comment.