Skip to content

Commit

Permalink
Update viewer mod compat, copy more nbt tags, fix dependencies for ne…
Browse files Browse the repository at this point in the history
…wer loom
  • Loading branch information
Patbox committed Feb 22, 2023
1 parent a1735c4 commit 7c352b2
Show file tree
Hide file tree
Showing 21 changed files with 106 additions and 115 deletions.
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ subprojects {
}

dependencies {
include(project(":polymer-autohost"))
include(project(":polymer-core"))
include(project(":polymer-common"))
include(project(":polymer-resource-pack"))
include(project(":polymer-blocks"))
api include(project(":polymer-autohost"))
api include(project(":polymer-core"))
api include(project(":polymer-common"))
api include(project(":polymer-resource-pack"))
api include(project(":polymer-blocks"))
//include(project(":polymer-client-extensions"))
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fabric_version=0.72.0+1.19.3

maven_group = eu.pb4

mod_version = 0.3.9
mod_version = 0.3.10

minecraft_version_supported = ">=1.19.3-beta.3"

Expand Down
24 changes: 12 additions & 12 deletions polymer-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ dependencies {
modCompileOnly('com.github.TheEpicBlock:PolyMc:5.1.0')


modCompileOnly /*modLocalRuntime*/("curse.maven:jade-324717:4160727")
modCompileOnly "mcp.mobius.waila:wthit:fabric-5.1.3"
modCompileOnly /*modLocalRuntime*/("curse.maven:jade-324717:4328555")
modCompileOnly modLocalRuntime("mcp.mobius.waila:wthit:fabric-6.1.4")

//modCompileOnly "me.shedaniel:RoughlyEnoughItems-api-fabric:9.1.530"
modCompileOnly "me.shedaniel:RoughlyEnoughItems-fabric:10.0.581"
modCompileOnly /*modLocalRuntime*/("dev.emi:emi:0.5.3+1.19.3")
modCompileOnly /*modLocalRuntime*/ ("me.shedaniel:RoughlyEnoughItems-fabric:10.0.592")
modCompileOnly /*modLocalRuntime*/("dev.emi:emi:0.6.6+1.19.3")

//modCompileOnlyApi modLocalRuntime("mezz.jei:jei-1.19-common:11.0.0.206")
//modCompileOnlyApi modLocalRuntime("mezz.jei:jei-1.19-fabric:11.0.0.206")
modCompileOnly /*modRuntimeOnly*/("curse.maven:jei-238222:3928387")
modCompileOnly /*modRuntimeOnly*/("maven.modrinth:jei:12.2.0.17")

//modCompileOnly ("mcjty.theoneprobe:theoneprobe-fabric:1.18.2-5.0.9")
//modRuntimeOnly ("mcjty.theoneprobe:theoneprobe-fabric:1.18.2-5.0.9")
Expand All @@ -73,20 +73,20 @@ dependencies {
exclude(group: "net.fabricmc")
}

modCompileOnly("fr.catcore:server-translations-api:1.4.18+1.19.2")
modLocalRuntime("fr.catcore:server-translations-api:1.4.18+1.19.2")
modCompileOnly("fr.catcore:server-translations-api:1.4.19+1.19.3")
modLocalRuntime("fr.catcore:server-translations-api:1.4.19+1.19.3")

modCompileOnly 'com.github.iPortalTeam.ImmersivePortalsMod:imm_ptl_core:v2.4.2-mc1.19.3'
modCompileOnly 'com.github.iPortalTeam.ImmersivePortalsMod:q_misc_util:v2.4.2-mc1.19.3'
modCompileOnly 'com.github.iPortalTeam.ImmersivePortalsMod:imm_ptl_core:v2.5.1-mc1.19.3'
modCompileOnly 'com.github.iPortalTeam.ImmersivePortalsMod:q_misc_util:v2.5.1-mc1.19.3'

// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them.

testmodImplementation sourceSets.main.output

implementation include(project(path: ':polymer-reg-sync-manipulator', configuration: 'namedElements'))
implementation project(path: ':polymer-common', configuration: 'namedElements')
implementation include(project(path: ':polymer-networking', configuration: 'namedElements'))
api include(project(path: ':polymer-reg-sync-manipulator', configuration: 'namedElements'))
api project(path: ':polymer-common', configuration: 'namedElements')
api include(project(path: ':polymer-networking', configuration: 'namedElements'))

compileOnly (project(path: ':polymer-resource-pack', configuration: 'namedElements'))
localRuntime (project(path: ':polymer-resource-pack', configuration: 'namedElements'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public final class PolymerItemUtils {
* You can also return new ItemStack, however please keep previous nbt so other modifications aren't removed if not needed!
*/
public static final FunctionEvent<ItemModificationEventHandler, ItemStack> ITEM_MODIFICATION_EVENT = new FunctionEvent<>();
private static final String[] NBT_TO_COPY = { "CanDestroy", "CanPlaceOn", BlockItem.BLOCK_ENTITY_TAG_KEY,
CompassItem.LODESTONE_DIMENSION_KEY, CompassItem.LODESTONE_POS_KEY, CompassItem.LODESTONE_TRACKED_KEY,
};

private PolymerItemUtils() {
}
Expand Down Expand Up @@ -374,33 +377,22 @@ public static ItemStack createItemStack(ItemStack itemStack, TooltipContext tool
}

if (itemStack.getItem() instanceof PotionItem) {
if (!out.getOrCreateNbt().contains("CustomPotionColor")) {
out.getOrCreateNbt().putInt("CustomPotionColor", PotionUtil.getColor(itemStack));
}
}

NbtElement canDestroy = itemStack.getNbt().get("CanDestroy");

if (canDestroy != null) {
out.getNbt().put("CanDestroy", canDestroy);
out.getOrCreateNbt().putInt("CustomPotionColor", PotionUtil.getColor(itemStack));
}

NbtElement canPlaceOn = itemStack.getNbt().get("CanPlaceOn");
for (var i = 0; i < NBT_TO_COPY.length; i++) {
var key = NBT_TO_COPY[i];
var tag = itemStack.getNbt().get(key);

if (canPlaceOn != null) {
out.getNbt().put("CanPlaceOn", canPlaceOn);
if (tag != null) {
out.getNbt().put(key, tag);
}
}

if (CrossbowItem.isCharged(itemStack)) {
CrossbowItem.setCharged(out, true);
}

var beTag = itemStack.getNbt().get(BlockItem.BLOCK_ENTITY_TAG_KEY);

if (beTag != null) {
out.getNbt().put(BlockItem.BLOCK_ENTITY_TAG_KEY, beTag);
}

try {
if (itemStack.getNbt().contains("ChargedProjectiles", NbtElement.LIST_TYPE)) {
var outList = new NbtList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import net.minecraft.util.Identifier;
import net.minecraft.util.collection.IndexedIterable;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
import java.util.Map;
import java.util.Set;

@ApiStatus.NonExtendable
public interface PolymerRegistry<T> extends IndexedIterable<T> {
@Nullable
T get(Identifier identifier);
Expand All @@ -29,4 +31,6 @@ public interface PolymerRegistry<T> extends IndexedIterable<T> {
Collection<Identifier> getTagsOf(T entry);

int size();

boolean contains(Identifier id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,6 @@ public static PolymerTooltipContext getTooltipContext(ServerPlayerEntity player)
return player != null && player.networkHandler instanceof PolymerNetworkHandlerExtension h && h.polymer$advancedTooltip() ? PolymerTooltipContext.ADVANCED : PolymerTooltipContext.BASIC;
}

public static boolean areSamePolymerType(ItemStack a, ItemStack b) {
return Objects.equals(PolymerItemUtils.getServerIdentifier(a), PolymerItemUtils.getServerIdentifier(b));
}

public static boolean isServerSideSyncableEntry(Registry reg, Object obj) {
return PolymerUtils.isServerOnly(obj) || (PolymerImpl.SYNC_MODDED_ENTRIES_POLYMC && !reg.getId(obj).getNamespace().equals("minecraft"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.impl.itemgroup.ItemGroupHelper;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
Expand Down Expand Up @@ -416,6 +417,7 @@ public static void register() {
}

public static String getModName(Identifier id) {
return "Server (" + id.getNamespace() + ")";
var container = FabricLoader.getInstance().getModContainer(id.getNamespace());
return container.isPresent() ? container.get().getMetadata().getName() : (id.getNamespace() + "*");
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
package eu.pb4.polymer.core.impl.client.compat;

import eu.pb4.polymer.core.api.client.PolymerClientUtils;
import eu.pb4.polymer.core.api.item.PolymerItemUtils;
import eu.pb4.polymer.core.impl.PolymerImpl;
import eu.pb4.polymer.core.impl.client.InternalClientRegistry;
import eu.pb4.polymer.core.impl.client.interfaces.ClientItemGroupExtension;
import net.minecraft.client.MinecraftClient;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemGroups;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemStackSet;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.ApiStatus;

import java.util.Objects;
import java.util.function.Consumer;

@ApiStatus.Internal
public class CompatUtils {
public static boolean areSamePolymerType(ItemStack a, ItemStack b) {
return Objects.equals(getItemId(a), getItemId(b));
}

private static Identifier getItemId(ItemStack stack) {
var id = PolymerItemUtils.getServerIdentifier(stack);

if (id == null) {
return stack.getItem().getRegistryEntry().registryKey().getValue();
}

return id;
}


public static void iterateItems(Consumer<ItemStack> consumer) {
var stacks = ItemStackSet.create();

Expand Down Expand Up @@ -44,5 +63,13 @@ public static void registerReload(Runnable runnable) {
});
}
}

public static String getModName(ItemStack stack) {
var id = PolymerItemUtils.getServerIdentifier(stack);
if (id != null) {
return InternalClientRegistry.getModName(id);
}
return null;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public void registerClient(IWailaClientRegistration registrar) {
if (PolymerImpl.IS_CLIENT) {
registrar.registerBlockComponent(BlockOverride.INSTANCE, Block.class);
registrar.registerEntityComponent(EntityOverride.INSTANCE, Entity.class);

registrar.addItemModNameCallback(CompatUtils::getModName);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
import eu.pb4.polymer.core.api.item.PolymerItemUtils;
import eu.pb4.polymer.core.impl.PolymerImpl;
import eu.pb4.polymer.core.impl.PolymerImplUtils;
import me.shedaniel.rei.RoughlyEnoughItemsCore;
import me.shedaniel.rei.RoughlyEnoughItemsCoreClient;
import me.shedaniel.rei.api.client.REIRuntime;
import me.shedaniel.rei.api.client.plugins.REIClientPlugin;
import me.shedaniel.rei.api.client.registry.entry.EntryRegistry;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.entry.comparison.EntryComparator;
import me.shedaniel.rei.api.common.entry.comparison.ItemComparatorRegistry;
import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes;
import me.shedaniel.rei.impl.client.REIRuntimeImpl;
import me.shedaniel.rei.impl.init.RoughlyEnoughItemsInitializer;
import net.minecraft.item.ItemStack;

import java.util.function.Predicate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,41 +50,13 @@ private static class OtherOverrides implements IEventListener {

@Override
public @Nullable String getHoveredItemModName(ItemStack stack, IPluginConfig config) {
if (PolymerItemUtils.isPolymerServerItem(stack) || !ClientUtils.isClientThread()) {
return null;
}

var id = PolymerItemUtils.getServerIdentifier(stack);

if (id != null) {
String modName = null;
var regBlock = Registries.ITEM.get(id);
if (regBlock != null) {
modName = IModInfo.get(regBlock).getName();
}

if (modName == null || modName.isEmpty() || (modName.equals("Minecraft") && !id.getNamespace().equals("minecraft"))) {
modName = InternalClientRegistry.getModName(id);
}

return modName;
}
return null;
return CompatUtils.getModName(stack);
}
}

private static class BlockOverride implements IBlockComponentProvider {
public static final BlockOverride INSTANCE = new BlockOverride();

@Override
public @Nullable BlockState getOverride(IBlockAccessor accessor, IPluginConfig config) {
var block = InternalClientRegistry.getBlockAt(accessor.getPosition());
if (block != ClientPolymerBlock.NONE_STATE) {
return Blocks.STONE.getDefaultState();
}
return null;
}

@Override
public ITooltipComponent getIcon(IBlockAccessor accessor, IPluginConfig config) {
var block = InternalClientRegistry.getBlockAt(accessor.getPosition());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public int size() {
return this.entryMap.size();
}

@Override
public boolean contains(Identifier id) {
return this.entryMap.containsKey(id);
}

public void set(Identifier identifier, int rawId, T entry) {
this.entryMap.put(identifier, entry);
this.identifierMap.put(entry, identifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dev.emi.emi.api.stack.Comparison;
import dev.emi.emi.api.stack.EmiStack;
import eu.pb4.polymer.core.impl.PolymerImplUtils;
import eu.pb4.polymer.core.impl.client.compat.CompatUtils;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
Expand All @@ -18,14 +19,14 @@ public abstract class emi_EmiStackMixin {

@Inject(method = "isEqual(Ldev/emi/emi/api/stack/EmiStack;)Z", at = @At("HEAD"), cancellable = true, remap = false, require = 0)
private void polymer$areEqual(EmiStack stack, CallbackInfoReturnable<Boolean> cir) {
if (!PolymerImplUtils.areSamePolymerType(stack.getItemStack(), this.getItemStack())) {
if (!CompatUtils.areSamePolymerType(stack.getItemStack(), this.getItemStack())) {
cir.setReturnValue(false);
}
}

@Inject(method = "isEqual(Ldev/emi/emi/api/stack/EmiStack;Ldev/emi/emi/api/stack/Comparison;)Z", at = @At("HEAD"), cancellable = true, remap = false, require = 0)
private void polymer$areEqual2(EmiStack stack, Comparison comparison, CallbackInfoReturnable<Boolean> cir) {
if (!PolymerImplUtils.areSamePolymerType(stack.getItemStack(), this.getItemStack())) {
if (!CompatUtils.areSamePolymerType(stack.getItemStack(), this.getItemStack())) {
cir.setReturnValue(false);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package eu.pb4.polymer.core.mixin.client.compat;

import eu.pb4.polymer.core.api.item.PolymerItemUtils;
import mezz.jei.common.util.StackHelper;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Pseudo
@Mixin(StackHelper.class)
public class jei_StackHelperMixin {
@Inject(method = "getRegistryNameForStack", at = @At("HEAD"), cancellable = true, remap = false, require = 0)
private static void polymer$changeId(ItemStack stack, CallbackInfoReturnable<String> cir) {
var id = PolymerItemUtils.getServerIdentifier(stack);
if (id != null) {
cir.setReturnValue(id.toString());
}
}
}

This file was deleted.

Loading

0 comments on commit 7c352b2

Please sign in to comment.