Skip to content

Commit

Permalink
Fixes and some api extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Oct 26, 2024
1 parent 69c0c5f commit 08ec14b
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 43 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ org.gradle.jvmargs=-Xmx4G
# Fabric Properties
# check these on https://fabricmc.net/use

minecraft_version=1.21.2
yarn_mappings=1.21.2+build.1
minecraft_version=1.21.3
yarn_mappings=1.21.3+build.1
loader_version=0.16.7

# Fabric API
fabric_version=0.106.0+1.21.2
fabric_version=0.106.1+1.21.3

maven_group = eu.pb4

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private PolymerCommonUtils() {}

public static final SimpleEvent<ResourcePackChangeCallback> ON_RESOURCE_PACK_STATUS_CHANGE = new SimpleEvent<>();
private static Path cachedClientPath;
private final static String SAFE_CLIENT_SHA1 = "0e9a07b9bb3390602f977073aa12884a4ce12431";
private final static String SAFE_CLIENT_SHA1 = "6f67d19b4467240639cb2c368ffd4b94ba889705";
private final static String SAFE_CLIENT_URL = "https://piston-data.mojang.com/v1/objects/" + SAFE_CLIENT_SHA1 + "/client.jar";
private static Path cachedClientJarRoot;

Expand Down Expand Up @@ -209,12 +209,23 @@ public static boolean hasResourcePack(@Nullable ServerPlayerEntity player, UUID
|| (CommonImpl.IS_CLIENT && ClientUtils.isResourcePackLoaded());
}

public static boolean hasResourcePack(ServerCommonNetworkHandler handler, UUID uuid) {
return CommonImpl.FORCE_RESOURCEPACK_ENABLED_STATE
|| (((CommonClientConnectionExt) ((CommonNetworkHandlerExt) handler).polymerCommon$getConnection()).polymerCommon$hasResourcePack(uuid))
|| (CommonImpl.IS_CLIENT && ClientUtils.isResourcePackLoaded());
}

public static boolean hasResourcePack(ClientConnection connection, UUID uuid) {
return CommonImpl.FORCE_RESOURCEPACK_ENABLED_STATE
|| ((CommonClientConnectionExt) connection).polymerCommon$hasResourcePack(uuid)
|| (CommonImpl.IS_CLIENT && ClientUtils.isResourcePackLoaded());
}

public static boolean hasResourcePack(PacketContext context, UUID uuid) {
return CommonImpl.FORCE_RESOURCEPACK_ENABLED_STATE
|| context.getClientConnection() != null && hasResourcePack(context.getClientConnection(), uuid);
}

public static boolean isServerBound() {
if (CommonImpl.IS_CLIENT) {
return ClientUtils.isSingleplayer();
Expand Down
2 changes: 1 addition & 1 deletion polymer-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ dependencies {
modCompileOnly /*modLocalRuntime*/("maven.modrinth:jade:14.1.0+fabric")
modCompileOnly /*modLocalRuntime*/("mcp.mobius.waila:wthit:fabric-11.2.0")

modCompileOnly /*modLocalRuntime*/ ("me.shedaniel:RoughlyEnoughItems-fabric:16.0.744")
modCompileOnly /*modLocalRuntime*/ ("me.shedaniel:RoughlyEnoughItems-fabric:17.0.789")
modCompileOnly /*modLocalRuntime*/("dev.emi:emi-fabric:1.1.6+1.20.6")

//modCompileOnlyApi modLocalRuntime("mezz.jei:jei-1.19-common:11.0.0.206")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ public interface PolymerItem extends PolymerSyncedObject<Item> {
*/
Item getPolymerItem(ItemStack itemStack, PacketContext context);

@Nullable
default Identifier getPolymerItemModel(ItemStack stack, PacketContext context) {
return stack.get(DataComponentTypes.ITEM_MODEL);
}

/**
* Method used for creation of client-side ItemStack
*
Expand All @@ -54,7 +49,33 @@ default ItemStack getPolymerItemStack(ItemStack itemStack, TooltipType tooltipTy
}

/**
* This method allows to modify tooltip text
* Method used for selecting model to use. Invoked within PolymerItemUtils#createItemStack / default stack creation
* before polymer-specific modifications
*
* @param stack Server-side ItemStack, used as reference
* @param context Player for which it's send
* @return Identifier targetting item model or null to fallback to base item one
*/
@Nullable
default Identifier getPolymerItemModel(ItemStack stack, PacketContext context) {
return stack.get(DataComponentTypes.ITEM_MODEL);
}

/**
* Method used for creation of client-side ItemStack.
* Invoked within PolymerItemUtils#createItemStack / default stack creation before polymer-specific modifications.
* For modifying after polymer, you should override {@link PolymerItem#getPolymerItemStack(ItemStack, TooltipType, PacketContext)}.
*
* @param out Client-side ItemStack, sent to the player (and one that should be modified)
* @param stack Server-side ItemStack, used as reference
* @param context Player for which it's send
*/
default void modifyBasePolymerItemStack(ItemStack out, ItemStack stack, PacketContext context) {
}


/**
* This method allows to modify tooltip text. Invoked within PolymerItemUtils#createItemStack / default stack creation
* If you just want to add your own one, use {@link Item#appendTooltip(ItemStack, Item.TooltipContext, List, TooltipType)}
*
* @param tooltip Current tooltip text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ public final class PolymerItemUtils {
HideableTooltip.of(DataComponentTypes.UNBREAKABLE, UnbreakableComponent::withShowInTooltip),
HideableTooltip.of(DataComponentTypes.CAN_BREAK, BlockPredicatesChecker::withShowInTooltip),
HideableTooltip.of(DataComponentTypes.CAN_PLACE_ON, BlockPredicatesChecker::withShowInTooltip),
HideableTooltip.of(DataComponentTypes.JUKEBOX_PLAYABLE, JukeboxPlayableComponent::withShowInTooltip)
HideableTooltip.of(DataComponentTypes.JUKEBOX_PLAYABLE, JukeboxPlayableComponent::withShowInTooltip),
HideableTooltip.of(DataComponentTypes.DYED_COLOR, DyedColorComponent::withShowInTooltip)
);

private PolymerItemUtils() {
Expand Down Expand Up @@ -379,6 +380,11 @@ public static ItemStack createItemStack(ItemStack itemStack, TooltipType tooltip
out.set((ComponentType) key, (Object) itemStack.get(key));
}
}

if (itemStack.getItem() instanceof PolymerItem polymerItem) {
polymerItem.modifyBasePolymerItemStack(out, itemStack, context);
}

var lookup = context.getRegistryWrapperLookup();

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,6 @@ private static void update(EntryRegistry registry) {
e.printStackTrace();
}
}
@Override
public void registerItemComparators(ItemComparatorRegistry registry) {
try {
//registry.registerGlobal(ITEM_STACK_ENTRY_COMPARATOR);
} catch (Throwable e) {
e.printStackTrace();
}
}

@Override
public void registerEntries(EntryRegistry registry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,27 @@ public static <T> CustomPayload.Id<PolymerGenericListPayload<T>> registerList(Id
register(SYNC_FINISHED, PolymerSyncFinishedS2CPayload::new, 6);
register(SYNC_CLEAR, PolymerSyncClearS2CPayload::new, 6);

SYNC_BLOCK_ID = registerList(SYNC_BLOCK, PolymerBlockEntry.CODEC,8);
SYNC_BLOCKSTATE_ID = registerList(SYNC_BLOCKSTATE, PolymerBlockStateEntry.CODEC, 8);
SYNC_ITEM_ID = registerList(SYNC_ITEM, PolymerItemEntry.CODEC, 8);
SYNC_ENTITY_ID = registerList(SYNC_ENTITY, PolymerEntityEntry.CODEC,8);
SYNC_TAGS_ID = registerList(SYNC_TAGS, PolymerTagEntry.CODEC, 8);
DEBUG_VALIDATE_STATES_ID = registerList(DEBUG_VALIDATE_STATES, DebugBlockStateEntry.CODEC, 6);

SYNC_FLUID_ID = registerList(SYNC_FLUID, IdValueEntry.CODEC, 8);
SYNC_VILLAGER_PROFESSION_ID = registerList(SYNC_VILLAGER_PROFESSION, IdValueEntry.CODEC, 8);
SYNC_BLOCK_ENTITY_ID = registerList(SYNC_BLOCK_ENTITY, IdValueEntry.CODEC, 8);
SYNC_STATUS_EFFECT_ID = registerList(SYNC_STATUS_EFFECT, IdValueEntry.CODEC, 8);


register(SYNC_ITEM_GROUP_DEFINE, PolymerItemGroupDefineS2CPayload.CODEC,8);
register(SYNC_ITEM_GROUP_CONTENTS_CLEAR, PolymerItemGroupContentClearS2CPayload.CODEC, 8);
register(SYNC_ITEM_GROUP_REMOVE, PolymerItemGroupRemoveS2CPayload.CODEC,8);
register(SYNC_ITEM_GROUP_CONTENTS_ADD, PolymerItemGroupContentAddS2CPayload.CODEC,8);
register(SYNC_ITEM_GROUP_APPLY_UPDATE, PolymerItemGroupApplyUpdateS2CPayload::new, 8);

register(WORLD_SET_BLOCK_UPDATE, PolymerBlockUpdateS2CPayload.CODEC,8);
register(WORLD_CHUNK_SECTION_UPDATE, PolymerSectionUpdateS2CPayload.CODEC, 8);
register(WORLD_ENTITY, PolymerEntityS2CPayload.CODEC, 8);
SYNC_BLOCK_ID = registerList(SYNC_BLOCK, PolymerBlockEntry.CODEC,9);
SYNC_BLOCKSTATE_ID = registerList(SYNC_BLOCKSTATE, PolymerBlockStateEntry.CODEC, 9);
SYNC_ITEM_ID = registerList(SYNC_ITEM, PolymerItemEntry.CODEC, 9);
SYNC_ENTITY_ID = registerList(SYNC_ENTITY, PolymerEntityEntry.CODEC,9);
SYNC_TAGS_ID = registerList(SYNC_TAGS, PolymerTagEntry.CODEC, 9);
DEBUG_VALIDATE_STATES_ID = registerList(DEBUG_VALIDATE_STATES, DebugBlockStateEntry.CODEC, 9);

SYNC_FLUID_ID = registerList(SYNC_FLUID, IdValueEntry.CODEC, 9);
SYNC_VILLAGER_PROFESSION_ID = registerList(SYNC_VILLAGER_PROFESSION, IdValueEntry.CODEC, 9);
SYNC_BLOCK_ENTITY_ID = registerList(SYNC_BLOCK_ENTITY, IdValueEntry.CODEC, 9);
SYNC_STATUS_EFFECT_ID = registerList(SYNC_STATUS_EFFECT, IdValueEntry.CODEC, 9);


register(SYNC_ITEM_GROUP_DEFINE, PolymerItemGroupDefineS2CPayload.CODEC,9);
register(SYNC_ITEM_GROUP_CONTENTS_CLEAR, PolymerItemGroupContentClearS2CPayload.CODEC, 9);
register(SYNC_ITEM_GROUP_REMOVE, PolymerItemGroupRemoveS2CPayload.CODEC,9);
register(SYNC_ITEM_GROUP_CONTENTS_ADD, PolymerItemGroupContentAddS2CPayload.CODEC,9);
register(SYNC_ITEM_GROUP_APPLY_UPDATE, PolymerItemGroupApplyUpdateS2CPayload::new, 9);

register(WORLD_SET_BLOCK_UPDATE, PolymerBlockUpdateS2CPayload.CODEC,9);
register(WORLD_CHUNK_SECTION_UPDATE, PolymerSectionUpdateS2CPayload.CODEC, 9);
register(WORLD_ENTITY, PolymerEntityS2CPayload.CODEC, 9);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import eu.pb4.polymer.resourcepack.api.metadata.PackMcMeta;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.item.Item;
import net.minecraft.server.network.ServerCommonNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;
import xyz.nucleoid.packettweaker.PacketContext;

import java.nio.file.FileSystems;
import java.nio.file.Files;
Expand Down Expand Up @@ -79,6 +81,10 @@ public static boolean addBridgedModelsFolder(Identifier modelFolderId) {
return INSTANCE.addBridgedModelsFolder(modelFolderId);
}

public static boolean addBridgedModelsFolder(Identifier... modelFolderId) {
return INSTANCE.addBridgedModelsFolder(modelFolderId);
}

public static Identifier getBridgedModelId(Identifier model) {
if (model.getPath().startsWith("item/")) {
return model.withPath(model.getPath().substring("item/".length()));
Expand All @@ -87,6 +93,10 @@ public static Identifier getBridgedModelId(Identifier model) {
return model.withPrefixedPath("-/");
}

public static Identifier bridgeModel(Identifier model) {
return getBridgedModelId(model);
}

/**
* Allows to check if player has selected server side resoucepack installed
* However it's impossible to check if it's polymer one or not
Expand All @@ -98,6 +108,30 @@ public static boolean hasPack(@Nullable ServerPlayerEntity player, UUID uuid) {
return PolymerCommonUtils.hasResourcePack(player, uuid);
}

/**
* Allows to check if player has selected server side resoucepack installed
* However it's impossible to check if it's polymer one or not
*
* @param context Player to check
* @return True if player has a server resourcepack
*/
public static boolean hasPack(PacketContext context, UUID uuid) {
return PolymerCommonUtils.hasResourcePack(context, uuid);
}


/**
* Allows to check if player has selected server side resoucepack installed
* However it's impossible to check if it's polymer one or not
*
* @param handler Player to check
* @return True if player has a server resourcepack
*/
public static boolean hasPack(ServerCommonNetworkHandler handler, UUID uuid) {
return PolymerCommonUtils.hasResourcePack(handler, uuid);
}


/**
* Allows to check if player has selected server side resoucepack installed
* However it's impossible to check if it's polymer one or not
Expand All @@ -109,6 +143,27 @@ public static boolean hasMainPack(@Nullable ServerPlayerEntity player) {
return hasPack(player, getMainUuid());
}

/**
* Allows to check if player has selected server side resoucepack installed
* However it's impossible to check if it's polymer one or not
*
* @param context Player to check
* @return True if player has a server resourcepack
*/
public static boolean hasMainPack(PacketContext context) {
return hasPack(context, getMainUuid());
}
/**
* Allows to check if player has selected server side resoucepack installed
* However it's impossible to check if it's polymer one or not
*
* @param handler Player to check
* @return True if player has a server resourcepack
*/
public static boolean hasMainPack(ServerCommonNetworkHandler handler) {
return hasPack(handler, getMainUuid());
}

public static Path getMainPath() {
return PolymerResourcePackImpl.DEFAULT_PATH;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,15 @@ public boolean addBridgedModelsFolder(Identifier modelFolderId) {
if (modelFolderId.getPath().equals("item") || modelFolderId.getPath().startsWith("item/")) {
return false;
}
return this.bridgedModels.add(modelFolderId);
return this.bridgedModels.add(modelFolderId.getPath().endsWith("/") ? modelFolderId.withPath(x -> x.substring(0, x.length() - 1)) : modelFolderId);
}

public boolean addBridgedModelsFolder(Identifier... modelFolderId) {
var b = true;
for (var model : modelFolderId) {
b &= addBridgedModelsFolder(model);
}
return b;
}

/**
Expand Down

0 comments on commit 08ec14b

Please sign in to comment.