Skip to content

Commit

Permalink
Fixes, reenable some mod compat code
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed May 5, 2024
1 parent 17f80a9 commit 0c47528
Show file tree
Hide file tree
Showing 26 changed files with 335 additions and 161 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ fabric_version=0.97.6+1.20.6

maven_group = eu.pb4

mod_version = 0.8.0-beta.8
mod_version = 0.8.0-pre.1

minecraft_version_supported = ">=1.20.5-"

packet_tweaker_version = 0.5.2+1.20.5

is_stable = false
is_stable = true
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import it.unimi.dsi.fastutil.objects.ObjectIterators;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BannerPattern;
import net.minecraft.component.type.MapIdComponent;
import net.minecraft.entity.Entity;
import net.minecraft.entity.damage.DamageScaling;
Expand Down Expand Up @@ -54,7 +55,6 @@
import net.minecraft.world.event.GameEvent;
import net.minecraft.world.tick.OrderedTick;
import net.minecraft.world.tick.QueryableTickScheduler;
import net.minecraft.world.tick.Tick;
import net.minecraft.world.tick.TickManager;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
Expand All @@ -74,10 +74,13 @@ public final class FakeWorld extends World implements LightSourceView {
public static final World INSTANCE_UNSAFE;
public static final World INSTANCE_REGULAR;
static final Scoreboard SCOREBOARD = new Scoreboard();
static final DynamicRegistryManager REGISTRY_MANAGER = new DynamicRegistryManager.Immutable() {
private FakeRegistry<DamageType> damageTypes = new FakeRegistry<>(RegistryKeys.DAMAGE_TYPE, new Identifier("polymer","fake_damage"),
new DamageType("", DamageScaling.NEVER, 0));

static final DynamicRegistryManager FALLBACK_REGISTRY_MANAGER = new DynamicRegistryManager.Immutable() {
private final FakeRegistry<DamageType> damageTypes = new FakeRegistry<>(RegistryKeys.DAMAGE_TYPE, new Identifier("polymer","fake_damage"),
new DamageType("", DamageScaling.NEVER, 0));
private final FakeRegistry<BannerPattern> bannerPatterns = new FakeRegistry<>(RegistryKeys.BANNER_PATTERN,
new Identifier("polymer","fake_pattern"),
new BannerPattern(new Identifier("polymer","fake_pattern"), ""));
@Override
public Optional<Registry> getOptional(RegistryKey key) {
var x = Registries.REGISTRIES.get(key);
Expand All @@ -87,6 +90,8 @@ public Optional<Registry> getOptional(RegistryKey key) {

if (RegistryKeys.DAMAGE_TYPE.equals(key)) {
return Optional.of(damageTypes);
} else if (RegistryKeys.BANNER_PATTERN.equals(key)) {
return Optional.of(bannerPatterns);
}

return Optional.empty();
Expand All @@ -97,7 +102,7 @@ public Stream<Entry<?>> streamAllRegistries() {
return Stream.empty();
}
};
static final RecipeManager RECIPE_MANAGER = new RecipeManager(REGISTRY_MANAGER);
static final RecipeManager RECIPE_MANAGER = new RecipeManager(FALLBACK_REGISTRY_MANAGER);
private static final FeatureSet FEATURES = FeatureFlags.FEATURE_MANAGER.getFeatureSet();
final ChunkManager chunkManager = new ChunkManager() {
private LightingProvider lightingProvider = null;
Expand Down Expand Up @@ -226,7 +231,7 @@ public int getTickCount() {
accessor.polymer$setBlockEntityTickers(new ArrayList<>());
accessor.polymer$setPendingBlockEntityTickers(new ArrayList<>());
try {
accessor.polymer$setDamageSources(new DamageSources(REGISTRY_MANAGER));
accessor.polymer$setDamageSources(new DamageSources(FALLBACK_REGISTRY_MANAGER));
} catch (Throwable e) {

}
Expand Down Expand Up @@ -261,7 +266,7 @@ public int getTickCount() {
private TickManager tickManager = new TickManager();

protected FakeWorld(MutableWorldProperties properties, RegistryKey<World> registryRef, RegistryEntry<DimensionType> dimensionType, Supplier<Profiler> profiler, boolean isClient, boolean debugWorld, long seed) {
super(properties, registryRef, REGISTRY_MANAGER, dimensionType, profiler, isClient, debugWorld, seed, 0);
super(properties, registryRef, FALLBACK_REGISTRY_MANAGER, dimensionType, profiler, isClient, debugWorld, seed, 0);
}

@Override
Expand Down Expand Up @@ -367,7 +372,7 @@ public void emitGameEvent(RegistryEntry<GameEvent> event, Vec3d emitterPos, Game
}
@Override
public DynamicRegistryManager getRegistryManager() {
return REGISTRY_MANAGER;
return FALLBACK_REGISTRY_MANAGER;
}

@Override
Expand Down
21 changes: 4 additions & 17 deletions polymer-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,11 @@ dependencies {
}


modCompileOnly /*modLocalRuntime*/("curse.maven:jade-324717:4328555")
modCompileOnly /*modLocalRuntime*/("mcp.mobius.waila:wthit:fabric-6.1.4")
//modCompileOnly('dev.lazurite:rayon-fabric:1.6.6')
//modLocalRuntime "dev.lazurite:rayon-fabric:1.6.6-fun3-perf"
modCompileOnly /*modLocalRuntime*/("maven.modrinth:jade:14.1.0+fabric")
modCompileOnly /*modLocalRuntime*/("mcp.mobius.waila:wthit:fabric-11.1.3")

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

//modCompileOnly "me.shedaniel:RoughlyEnoughItems-api-fabric:9.1.530"
modCompileOnly /*modLocalRuntime*/ ("me.shedaniel:RoughlyEnoughItems-fabric:12.0.645")
modCompileOnly /*modLocalRuntime*/("dev.emi:emi-fabric:1.0.19+1.20.1")
modCompileOnly /*modLocalRuntime*/ ("me.shedaniel:RoughlyEnoughItems-fabric:15.0.728")
modCompileOnly /*modLocalRuntime*/("dev.emi:emi-fabric:1.1.6+1.20.6")

//modCompileOnlyApi modLocalRuntime("mezz.jei:jei-1.19-common:11.0.0.206")
//modCompileOnlyApi modLocalRuntime("mezz.jei:jei-1.19-fabric:11.0.0.206")
Expand All @@ -73,13 +67,6 @@ dependencies {

modCompileOnly "xyz.nucleoid:disguiselib-fabric:1.2.2"

modCompileOnly("squeek.appleskin:appleskin-fabric:mc1.19-2.4.0:api") {
exclude(group: "com.terraformersmc")
exclude(group: "io.github.prospector")
exclude(group: "io.github.prospector")
exclude(group: "net.fabricmc")
}

modCompileOnly("xyz.nucleoid:server-translations-api:2.3.0+1.20.5-rc2")
//modLocalRuntime("xyz.nucleoid:server-translations-api:2.0.0-beta.2+1.19.4-pre2")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package eu.pb4.polymer.core.api.item;

import eu.pb4.polymer.core.api.utils.PolymerObject;
import eu.pb4.polymer.core.api.utils.PolymerSyncedObject;
import net.minecraft.server.network.ServerPlayerEntity;

public interface PolymerItemComponent {
public interface PolymerItemComponent extends PolymerObject {
default boolean canSyncRawToClient(ServerPlayerEntity player) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ public static ItemStack getRealItemStack(ItemStack itemStack, RegistryWrapper.Wr
*/
@Nullable
public static Identifier getPolymerIdentifier(ItemStack itemStack) {
var custom = itemStack.get(DataComponentTypes.CUSTOM_DATA);
return getPolymerIdentifier(itemStack.get(DataComponentTypes.CUSTOM_DATA));
}
public static Identifier getPolymerIdentifier(@Nullable NbtComponent custom) {

if (custom != null && custom.contains(POLYMER_STACK)) {
try {
Expand All @@ -182,6 +184,11 @@ public static Identifier getServerIdentifier(ItemStack itemStack) {
return getPolymerIdentifier(itemStack);
}

@Nullable
public static Identifier getServerIdentifier(@Nullable NbtComponent nbtData) {
return getPolymerIdentifier(nbtData);
}

public static boolean isPolymerServerItem(ItemStack itemStack) {
return isPolymerServerItem(itemStack, PolymerUtils.getPlayerContext());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package eu.pb4.polymer.core.api.other;

import eu.pb4.polymer.core.api.utils.PolymerSyncedObject;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.potion.Potion;
import net.minecraft.server.network.ServerPlayerEntity;
import org.jetbrains.annotations.Nullable;

public interface PolymerPotion extends PolymerSyncedObject<Potion> {
@Override
@Nullable
default Potion getPolymerReplacement(ServerPlayerEntity player) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package eu.pb4.polymer.core.api.other;

import eu.pb4.polymer.core.api.utils.PolymerSyncedObject;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.potion.Potion;
import net.minecraft.server.network.ServerPlayerEntity;
import org.jetbrains.annotations.Nullable;

public class SimplePolymerPotion extends Potion implements PolymerPotion {
public SimplePolymerPotion(StatusEffectInstance... effects) {
super((String)null, effects);
}

public SimplePolymerPotion(@Nullable String baseName, StatusEffectInstance... effects) {
super(baseName, effects);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@
import eu.pb4.polymer.core.impl.networking.PacketPatcher;
import eu.pb4.polymer.core.mixin.block.packet.ThreadedAnvilChunkStorageAccessor;
import eu.pb4.polymer.core.mixin.entity.ServerWorldAccessor;
import eu.pb4.polymer.rsm.api.RegistrySyncUtils;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.client.item.TooltipType;
import net.minecraft.component.DataComponentType;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.ProfileComponent;
import net.minecraft.entity.EntityType;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.s2c.play.InventoryS2CPacket;
import net.minecraft.potion.Potion;
import net.minecraft.registry.Registries;
import net.minecraft.resource.featuretoggle.FeatureFlag;
import net.minecraft.server.network.ServerCommonNetworkHandler;
import net.minecraft.server.network.ServerPlayNetworkHandler;
Expand Down Expand Up @@ -137,6 +141,10 @@ public static void reloadWorld(ServerPlayerEntity player) {
});
}

public static void markAsPolymer(DataComponentType<?>... types) {
PolymerItemUtils.markAsPolymer(types);
}

/**
* Resends inventory to player
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ private static int displayClientItem(CommandContext<ServerCommandSource> context
var stack = PolymerItemUtils.getPolymerItemStack(player.getMainHandStack(), context.getSource().getRegistryManager(), player).copy();
stack.remove(DataComponentTypes.CUSTOM_DATA);

context.getSource().sendFeedback(() -> (new NbtTextFormatter("")).apply(ItemStack.CODEC.encodeStart(RegistryOps.of(NbtOps.INSTANCE, context.getSource().getRegistryManager()), stack).result().get()), false);
context.getSource().sendFeedback(() -> (new NbtTextFormatter("")).apply(stack.encode(context.getSource().getRegistryManager())), false);

return 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
import eu.pb4.polymer.core.impl.client.interfaces.ClientItemGroupExtension;
import eu.pb4.polymer.networking.impl.client.ClientPacketRegistry;
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.component.DataComponentTypes;
import net.minecraft.component.type.NbtComponent;
import net.minecraft.item.*;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.registry.Registries;
Expand All @@ -24,7 +23,11 @@
@ApiStatus.Internal
public class CompatUtils {
public static boolean areSamePolymerType(ItemStack a, ItemStack b) {
return Objects.equals(getItemId(a), getItemId(b));
return Objects.equals(getItemId(a.getItem(), a.get(DataComponentTypes.CUSTOM_DATA)), getItemId(b.getItem(), b.get(DataComponentTypes.CUSTOM_DATA)));
}

public static boolean areSamePolymerType(Item ai, NbtComponent a, Item bi, NbtComponent b) {
return Objects.equals(getItemId(ai, a), getItemId(bi, b));
}

public static boolean areEqualItems(ItemStack a, ItemStack b) {
Expand All @@ -38,33 +41,40 @@ public static boolean areEqualItems(ItemStack a, ItemStack b) {

@Nullable
public static NbtCompound getBackingNbt(ItemStack stack) {
/*if (!stack.hasNbt()) {
if (!stack.contains(DataComponentTypes.CUSTOM_DATA)) {
return null;
}
var nbt = stack.getNbt();
var nbt = stack.get(DataComponentTypes.CUSTOM_DATA).getNbt();
if (PolymerItemUtils.getServerIdentifier(stack) == null) {
return nbt;
}

var maybeNbt = PolymerItemUtils.getPolymerNbt(stack);
var maybeNbt = nbt.getCompound(PolymerItemUtils.POLYMER_STACK).getCompound("components");

if (maybeNbt != null) {
return maybeNbt;
}
maybeNbt = nbt.getCompound("PolyMcOriginal");

return maybeNbt != null && maybeNbt.contains("tag", NbtElement.COMPOUND_TYPE) ? maybeNbt.getCompound("tag") : null;*/
return null;
return maybeNbt != null && maybeNbt.contains("tag", NbtElement.COMPOUND_TYPE) ? maybeNbt.getCompound("tag") : null;
}

public static boolean isServerSide(ItemStack stack) {
return PolymerItemUtils.getServerIdentifier(stack) != null;
}

public static boolean isServerSide(@Nullable NbtComponent component) {
return PolymerItemUtils.getServerIdentifier(component) != null;
}

@Nullable
public static Object getKey(ItemStack stack) {
var id = PolymerItemUtils.getServerIdentifier(stack);
return getKey(stack.get(DataComponentTypes.CUSTOM_DATA));
}
public static Object getKey(@Nullable NbtComponent component) {
var id = PolymerItemUtils.getServerIdentifier(component);
if (id == null) {
return stack.getItem();
return null;
}

if (InternalClientRegistry.ITEMS.contains(id)) {
Expand All @@ -74,11 +84,11 @@ public static Object getKey(ItemStack stack) {
return Registries.ITEM.get(id);
}

private static Identifier getItemId(ItemStack stack) {
var id = PolymerItemUtils.getServerIdentifier(stack);
private static Identifier getItemId(Item item, @Nullable NbtComponent nbtComponent) {
var id = PolymerItemUtils.getServerIdentifier(nbtComponent);

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

return id;
Expand Down Expand Up @@ -109,6 +119,10 @@ public static String getModName(ItemStack stack) {
return null;
}

public static Identifier getId(@Nullable NbtComponent nbt) {
return PolymerItemUtils.getServerIdentifier(nbt);
}

public record Key(Identifier identifier) {}
}

Loading

0 comments on commit 0c47528

Please sign in to comment.