Skip to content

Commit

Permalink
feat(porting): port CustomMapItem related stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Sep 29, 2024
1 parent c40d38f commit 1197439
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 77 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
package io.github.fabricators_of_create.porting_lib.item;

import net.minecraft.core.component.DataComponents;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.saveddata.maps.MapId;
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;

import javax.annotation.Nullable;

import static net.minecraft.world.item.MapItem.getSavedData;

public interface CustomMapItem {
@Nullable
default MapItemSavedData getCustomMapData(ItemStack itemStack, Level level) {
MapId mapId = itemStack.get(DataComponents.MAP_ID);
return getSavedData(mapId, level);
}
}
public interface CustomMapItem {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.fabricators_of_create.porting_lib.mixin.client;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.mojang.blaze3d.vertex.PoseStack;

import io.github.fabricators_of_create.porting_lib.item.CustomMapItem;
Expand All @@ -13,12 +15,9 @@

import net.minecraft.world.item.ItemStack;

import net.minecraft.world.level.saveddata.maps.MapItemSavedData;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArgs;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

@Mixin(ItemFrameRenderer.class)
Expand All @@ -27,38 +26,13 @@ protected ItemFrameRendererMixin(Context context) {
super(context);
}

// @ModifyArgs( TODO: PORT
// method = "render(Lnet/minecraft/world/entity/decoration/ItemFrame;FFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V",
// at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;is(Lnet/minecraft/world/item/Item;)Z")
// )
// private void port_lib$customMapsAreMaps(Args args, T entity, float entityYaw, float partialTicks, PoseStack matrixStack, MultiBufferSource buffer, int packedLight) {
// ItemStack stack = entity.getItem();
// Item item = stack.getItem();
// if (item instanceof CustomMapItem) {
// args.set(0, item);
// }
// }

@ModifyArgs(
@WrapOperation(
method = "getFrameModelResourceLoc",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;is(Lnet/minecraft/world/item/Item;)Z")
)
private void port_lib$customMapsAreMaps2(Args args, T entity, ItemStack stack) {
Item item = stack.getItem();
if (item instanceof CustomMapItem) {
args.set(0, item);
}
}

@ModifyVariable(
method = "render(Lnet/minecraft/world/entity/decoration/ItemFrame;FFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V",
at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/item/MapItem;getSavedData(Lnet/minecraft/world/level/saveddata/maps/MapId;Lnet/minecraft/world/level/Level;)Lnet/minecraft/world/level/saveddata/maps/MapItemSavedData;")
)
private MapItemSavedData port_lib$getCorrectMapData(MapItemSavedData original, T entity, float entityYaw, float partialTicks, PoseStack matrixStack, MultiBufferSource buffer, int packedLight) {
ItemStack stack = entity.getItem();
if (stack.getItem() instanceof CustomMapItem custom) {
return custom.getCustomMapData(stack, entity.level());
}
return original;
private boolean port_lib$customMapsAreMaps(ItemStack instance, Item item, Operation<Boolean> original) {
if (item instanceof CustomMapItem)
return true;
return original.call(instance, item);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"common.LivingEntityMixin",
"common.MainMixin",
"common.MapDecorationMixin",
"common.MapItemMixin",
"common.MushroomCowMixin",
"common.PiglinAiMixin",
"common.PistonMovingBlockEntityMixin",
Expand Down

0 comments on commit 1197439

Please sign in to comment.