From 68834b9a6c8bfdde43d3a40ead90aa2026fb59fa Mon Sep 17 00:00:00 2001 From: Patbox <39821509+Patbox@users.noreply.github.com> Date: Tue, 23 Nov 2021 10:59:51 +0100 Subject: [PATCH] 0.2.0-beta.1 --- gradle.properties | 2 +- .../main/java/eu/pb4/polymer/PolymerMod.java | 6 +-- .../java/eu/pb4/polymer/PolymerUtils.java | 2 - .../polymer/api/block/PolymerBlockUtils.java | 6 +-- .../polymer/api/block/PolymerHeadBlock.java | 14 +----- .../api/client/PolymerClientUtils.java | 10 ++-- .../api/entity/PolymerEntityUtils.java | 7 ++- .../polymer/api/item/PolymerItemGroup.java | 10 ++-- .../api/networking/PolymerSyncUtils.java | 9 ++-- .../api/resourcepack/PolymerArmorModel.java | 3 ++ .../api/resourcepack/PolymerModelData.java | 3 ++ .../api/resourcepack/PolymerRPUtils.java | 9 ++-- .../pb4/polymer/api/utils/PolymerUtils.java | 50 ++++++++++++++++--- .../networking/PolymerServerProtocol.java | 4 +- .../eu/pb4/polymer/impl/package-info.java | 2 + .../java/eu/pb4/polymertest/TestMod.java | 2 +- 16 files changed, 84 insertions(+), 55 deletions(-) diff --git a/gradle.properties b/gradle.properties index d37a1a01..4cf95ef4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,7 +11,7 @@ loader_version=0.12.5 fabric_version=0.42.6+1.18 # Mod Properties - mod_version = 0.2.0-alpha.5 + mod_version = 0.2.0-beta.1 maven_group = eu.pb4 archives_base_name = polymer diff --git a/legacy/src/main/java/eu/pb4/polymer/PolymerMod.java b/legacy/src/main/java/eu/pb4/polymer/PolymerMod.java index a682b35f..d6195915 100644 --- a/legacy/src/main/java/eu/pb4/polymer/PolymerMod.java +++ b/legacy/src/main/java/eu/pb4/polymer/PolymerMod.java @@ -1,14 +1,12 @@ package eu.pb4.polymer; import eu.pb4.polymer.block.BlockHelper; +import eu.pb4.polymer.impl.PolymerImpl; import eu.pb4.polymer.impl.compat.CompatStatus; import net.fabricmc.api.ModInitializer; -import net.fabricmc.loader.api.FabricLoader; - import net.minecraft.util.Identifier; -import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.ApiStatus; @@ -17,7 +15,7 @@ public class PolymerMod implements ModInitializer { public static final boolean POLYMC_COMPAT = CompatStatus.POLYMC; - public static final Logger LOGGER = LogManager.getLogger("Polymer (Legacy)"); + public static final Logger LOGGER = PolymerImpl.LOGGER; @Override public void onInitialize() { diff --git a/legacy/src/main/java/eu/pb4/polymer/PolymerUtils.java b/legacy/src/main/java/eu/pb4/polymer/PolymerUtils.java index 424564cf..e9957232 100644 --- a/legacy/src/main/java/eu/pb4/polymer/PolymerUtils.java +++ b/legacy/src/main/java/eu/pb4/polymer/PolymerUtils.java @@ -1,8 +1,6 @@ package eu.pb4.polymer; import eu.pb4.polymer.api.block.PolymerBlockUtils; -import net.fabricmc.api.EnvType; -import net.fabricmc.loader.api.FabricLoader; import net.minecraft.network.Packet; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; diff --git a/src/main/java/eu/pb4/polymer/api/block/PolymerBlockUtils.java b/src/main/java/eu/pb4/polymer/api/block/PolymerBlockUtils.java index 045cf684..d3bea13d 100644 --- a/src/main/java/eu/pb4/polymer/api/block/PolymerBlockUtils.java +++ b/src/main/java/eu/pb4/polymer/api/block/PolymerBlockUtils.java @@ -1,7 +1,6 @@ package eu.pb4.polymer.api.block; import eu.pb4.polymer.api.utils.events.BooleanEvent; -import eu.pb4.polymer.impl.interfaces.PolymerBlockPosStorage; import it.unimi.dsi.fastutil.objects.Object2BooleanMap; import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap; import net.minecraft.block.Block; @@ -11,15 +10,16 @@ import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkSectionPos; -import net.minecraft.world.chunk.WorldChunk; import java.util.Arrays; -import java.util.Collection; import java.util.HashSet; import java.util.function.BiPredicate; import java.util.function.Predicate; public final class PolymerBlockUtils { + private PolymerBlockUtils() { + } + public static final int NESTED_DEFAULT_DISTANCE = 32; public static final int BLOCK_STATE_OFFSET = Integer.MAX_VALUE / 64; diff --git a/src/main/java/eu/pb4/polymer/api/block/PolymerHeadBlock.java b/src/main/java/eu/pb4/polymer/api/block/PolymerHeadBlock.java index 94b76181..86dcda88 100644 --- a/src/main/java/eu/pb4/polymer/api/block/PolymerHeadBlock.java +++ b/src/main/java/eu/pb4/polymer/api/block/PolymerHeadBlock.java @@ -1,5 +1,6 @@ package eu.pb4.polymer.api.block; +import eu.pb4.polymer.api.utils.PolymerUtils; import eu.pb4.polymer.mixin.block.BlockEntityUpdateS2CPacketAccessor; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -32,18 +33,7 @@ default Block getPolymerBlock() { * @return NbtCompound representing client-side */ default NbtCompound getPolymerHeadSkullOwner(BlockState state) { - NbtCompound skullOwner = new NbtCompound(); - NbtCompound properties = new NbtCompound(); - NbtCompound data = new NbtCompound(); - NbtList textures = new NbtList(); - textures.add(data); - - data.putString("Value", ((PolymerHeadBlock) state.getBlock()).getPolymerSkinValue(state)); - properties.put("textures", textures); - skullOwner.put("Properties", properties); - skullOwner.putIntArray("Id", new int[] { 0, 0, 0, 0 }); - - return skullOwner; + return PolymerUtils.createSkullOwner(((PolymerHeadBlock) state.getBlock()).getPolymerSkinValue(state)); } /** diff --git a/src/main/java/eu/pb4/polymer/api/client/PolymerClientUtils.java b/src/main/java/eu/pb4/polymer/api/client/PolymerClientUtils.java index 3c34cc57..b910b65b 100644 --- a/src/main/java/eu/pb4/polymer/api/client/PolymerClientUtils.java +++ b/src/main/java/eu/pb4/polymer/api/client/PolymerClientUtils.java @@ -2,8 +2,6 @@ import eu.pb4.polymer.api.client.registry.ClientPolymerBlock; import eu.pb4.polymer.api.client.registry.ClientPolymerEntityType; -import eu.pb4.polymer.api.client.registry.ClientPolymerItem; -import eu.pb4.polymer.api.utils.events.BooleanEvent; import eu.pb4.polymer.api.utils.events.SimpleEvent; import eu.pb4.polymer.impl.client.InternalClientRegistry; import eu.pb4.polymer.impl.client.interfaces.ClientEntityExtension; @@ -11,21 +9,19 @@ import net.minecraft.util.math.BlockPos; import org.jetbrains.annotations.Nullable; -import java.util.List; -import java.util.function.BiConsumer; -import java.util.function.Consumer; - /** * General utilities while dealing with client side integrations */ public final class PolymerClientUtils { + private PolymerClientUtils() { + } + public static final SimpleEvent ON_HANDSHAKE = new SimpleEvent<>(); public static final SimpleEvent ON_CLEAR = new SimpleEvent<>(); public static final SimpleEvent ON_SYNC_STARTED = new SimpleEvent<>(); public static final SimpleEvent ON_SYNC_FINISHED = new SimpleEvent<>(); public static final SimpleEvent ON_SEARCH_REBUILD = new SimpleEvent<>(); - @Nullable public static ClientPolymerBlock.State getPolymerStateAt(BlockPos pos) { return InternalClientRegistry.getBlockAt(pos); } diff --git a/src/main/java/eu/pb4/polymer/api/entity/PolymerEntityUtils.java b/src/main/java/eu/pb4/polymer/api/entity/PolymerEntityUtils.java index 347aa7f9..c89e6eec 100644 --- a/src/main/java/eu/pb4/polymer/api/entity/PolymerEntityUtils.java +++ b/src/main/java/eu/pb4/polymer/api/entity/PolymerEntityUtils.java @@ -1,8 +1,8 @@ package eu.pb4.polymer.api.entity; +import eu.pb4.polymer.impl.other.InternalEntityHelpers; import eu.pb4.polymer.mixin.entity.EntityAccessor; import eu.pb4.polymer.mixin.entity.PlayerSpawnS2CPacketAccessor; -import eu.pb4.polymer.impl.other.InternalEntityHelpers; import io.netty.util.internal.shaded.org.jctools.util.UnsafeAccess; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; @@ -15,7 +15,10 @@ import java.util.List; import java.util.UUID; -public class PolymerEntityUtils { +public final class PolymerEntityUtils { + private PolymerEntityUtils() { + } + private static final HashSet> ENTITY_IDENTIFIERS = new HashSet<>(); /** diff --git a/src/main/java/eu/pb4/polymer/api/item/PolymerItemGroup.java b/src/main/java/eu/pb4/polymer/api/item/PolymerItemGroup.java index 3a3d9974..7c916a1b 100644 --- a/src/main/java/eu/pb4/polymer/api/item/PolymerItemGroup.java +++ b/src/main/java/eu/pb4/polymer/api/item/PolymerItemGroup.java @@ -26,7 +26,7 @@ public final class PolymerItemGroup extends ItemGroup implements PolymerObject { /** * Even called on synchronization of PolymerItemGroups */ - public static final SimpleEvent LIST_EVENT = new SimpleEvent<>(); + public static final SimpleEvent LIST_EVENT = new SimpleEvent<>(); public static List items = new ArrayList<>(); private final Text name; private final Identifier identifier; @@ -94,12 +94,12 @@ public boolean shouldSyncWithPolymerClient(ServerPlayerEntity player) { } @FunctionalInterface - public interface ItemGroupListEventListener { - void onItemGroupSync(ServerPlayerEntity player, ItemGroupSyncer helper); + public interface ItemGroupEventListener { + void onItemGroupSync(ServerPlayerEntity player, ItemGroupListBuilder builder); } - public interface ItemGroupSyncer { - void send(PolymerItemGroup group); + public interface ItemGroupListBuilder { + void add(PolymerItemGroup group); void remove(PolymerItemGroup group); } diff --git a/src/main/java/eu/pb4/polymer/api/networking/PolymerSyncUtils.java b/src/main/java/eu/pb4/polymer/api/networking/PolymerSyncUtils.java index 63a6daf2..0e5462e8 100644 --- a/src/main/java/eu/pb4/polymer/api/networking/PolymerSyncUtils.java +++ b/src/main/java/eu/pb4/polymer/api/networking/PolymerSyncUtils.java @@ -3,17 +3,14 @@ import eu.pb4.polymer.api.item.PolymerItemGroup; import eu.pb4.polymer.impl.interfaces.PolymerNetworkHandlerExtension; import eu.pb4.polymer.impl.networking.PacketUtils; -import eu.pb4.polymer.impl.networking.PolymerServerProtocolHandler; -import eu.pb4.polymer.impl.networking.ServerPackets; import eu.pb4.polymer.impl.networking.PolymerServerProtocol; -import net.minecraft.network.PacketByteBuf; +import eu.pb4.polymer.impl.networking.ServerPackets; import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; import net.minecraft.server.network.ServerPlayNetworkHandler; -import net.minecraft.util.Identifier; -import org.jetbrains.annotations.ApiStatus; public final class PolymerSyncUtils { - private PolymerSyncUtils(){}; + private PolymerSyncUtils() { + } /** * Resends synchronization packets to player if their client supports that diff --git a/src/main/java/eu/pb4/polymer/api/resourcepack/PolymerArmorModel.java b/src/main/java/eu/pb4/polymer/api/resourcepack/PolymerArmorModel.java index 0d3a604c..257b61cc 100644 --- a/src/main/java/eu/pb4/polymer/api/resourcepack/PolymerArmorModel.java +++ b/src/main/java/eu/pb4/polymer/api/resourcepack/PolymerArmorModel.java @@ -2,4 +2,7 @@ import net.minecraft.util.Identifier; +/** + * Represents information about armor texture + */ public record PolymerArmorModel(int value, Identifier modelPath) {} diff --git a/src/main/java/eu/pb4/polymer/api/resourcepack/PolymerModelData.java b/src/main/java/eu/pb4/polymer/api/resourcepack/PolymerModelData.java index d9973c3c..92a5a4c9 100644 --- a/src/main/java/eu/pb4/polymer/api/resourcepack/PolymerModelData.java +++ b/src/main/java/eu/pb4/polymer/api/resourcepack/PolymerModelData.java @@ -3,4 +3,7 @@ import net.minecraft.item.Item; import net.minecraft.util.Identifier; +/** + * Represents information about CustomModelData of item + */ public record PolymerModelData(Item item, int value, Identifier modelPath) {} diff --git a/src/main/java/eu/pb4/polymer/api/resourcepack/PolymerRPUtils.java b/src/main/java/eu/pb4/polymer/api/resourcepack/PolymerRPUtils.java index 93c23e09..37491cba 100644 --- a/src/main/java/eu/pb4/polymer/api/resourcepack/PolymerRPUtils.java +++ b/src/main/java/eu/pb4/polymer/api/resourcepack/PolymerRPUtils.java @@ -2,7 +2,6 @@ import eu.pb4.polymer.api.utils.events.SimpleEvent; import eu.pb4.polymer.impl.PolymerImpl; -import eu.pb4.polymer.impl.PolymerMod; import eu.pb4.polymer.impl.client.ClientUtils; import eu.pb4.polymer.impl.compat.CompatStatus; import eu.pb4.polymer.impl.interfaces.PolymerNetworkHandlerExtension; @@ -24,7 +23,10 @@ /** * Utilities allowing creation of single, polymer mod compatible resource pack */ -public class PolymerRPUtils { +public final class PolymerRPUtils { + private PolymerRPUtils() { + } + public static final SimpleEvent> RESOURCE_PACK_CREATION_EVENT = new SimpleEvent<>(); private static final Object2ObjectMap> ITEMS = new Object2ObjectArrayMap<>(); private static final Set MOD_IDS = new HashSet<>(); @@ -53,10 +55,11 @@ public static PolymerModelData requestModel(Item vanillaItem, Identifier modelPa cmdInfoList.add(cmdInfo); return cmdInfo; } + /** * This method can be used to register custom model data for items * - * @param modelPath Path to model in resource pack + * @param modelPath Path to model in resource pack * @return PolymerArmorModel with data about this model */ public static PolymerArmorModel requestArmor(Identifier modelPath) { diff --git a/src/main/java/eu/pb4/polymer/api/utils/PolymerUtils.java b/src/main/java/eu/pb4/polymer/api/utils/PolymerUtils.java index 9e4ffc7f..a38a0ef0 100644 --- a/src/main/java/eu/pb4/polymer/api/utils/PolymerUtils.java +++ b/src/main/java/eu/pb4/polymer/api/utils/PolymerUtils.java @@ -3,13 +3,15 @@ import eu.pb4.polymer.api.item.PolymerItemGroup; import eu.pb4.polymer.api.networking.PolymerSyncUtils; import eu.pb4.polymer.impl.InternalServerRegistry; -import eu.pb4.polymer.impl.interfaces.PolymerNetworkHandlerExtension; import eu.pb4.polymer.impl.client.ClientUtils; +import eu.pb4.polymer.impl.interfaces.PolymerNetworkHandlerExtension; import eu.pb4.polymer.mixin.block.packet.ThreadedAnvilChunkStorageAccessor; import eu.pb4.polymer.mixin.entity.ServerWorldAccessor; import net.fabricmc.api.EnvType; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.item.TooltipContext; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.NbtList; import net.minecraft.network.Packet; import net.minecraft.network.packet.s2c.play.InventoryS2CPacket; import net.minecraft.server.network.ServerPlayNetworkHandler; @@ -23,7 +25,10 @@ /** * General use case utils that can be useful in multiple situations */ -public class PolymerUtils { +public final class PolymerUtils { + private PolymerUtils() { + } + public static final String ID = "polymer"; /** @@ -72,8 +77,9 @@ public static boolean isOnPlayerNetworking() { /** * Schedules a packet sending - * @param handler used for packet sending - * @param packet sent packet + * + * @param handler used for packet sending + * @param packet sent packet * @param duration time (in ticks) waited before packet is send */ public static void schedulePacket(ServerPlayNetworkHandler handler, Packet packet, int duration) { @@ -92,16 +98,25 @@ public static void reloadWorld(ServerPlayerEntity player) { tracker.stopTracking(player); tracker.updateTrackedStatus(player); } - }; + } + /** + * Resends inventory to player + */ public static void reloadInventory(ServerPlayerEntity player) { player.networkHandler.sendPacket(new InventoryS2CPacket(0, 0, player.playerScreenHandler.getStacks(), player.playerScreenHandler.getCursorStack())); } + /** + * Returns current TooltipContext of player, + */ public static TooltipContext getTooltipContext(@Nullable ServerPlayerEntity player) { return player != null && player.networkHandler instanceof PolymerNetworkHandlerExtension h && h.polymer_advancedTooltip() ? TooltipContext.Default.ADVANCED : TooltipContext.Default.NORMAL; } + /** + * Returns list of ItemGroups accessible by player + */ public static List getItemGroups(ServerPlayerEntity player) { var list = new ArrayList(); @@ -111,9 +126,9 @@ public static List getItemGroups(ServerPlayerEntity player) { } } - var sync = new PolymerItemGroup.ItemGroupSyncer() { + var sync = new PolymerItemGroup.ItemGroupListBuilder() { @Override - public void send(PolymerItemGroup group) { + public void add(PolymerItemGroup group) { list.add(group); } @@ -127,4 +142,25 @@ public void remove(PolymerItemGroup group) { return list; } + + /** + * Creates SkullOwner NbtCompound from provided skin value + * + * @param value Skin value + * @return NbtCompound representing SkullOwner + */ + public static NbtCompound createSkullOwner(String value) { + NbtCompound skullOwner = new NbtCompound(); + NbtCompound properties = new NbtCompound(); + NbtCompound data = new NbtCompound(); + NbtList textures = new NbtList(); + textures.add(data); + + data.putString("Value", value); + properties.put("textures", textures); + skullOwner.put("Properties", properties); + skullOwner.putIntArray("Id", new int[]{0, 0, 0, 0}); + + return skullOwner; + } } diff --git a/src/main/java/eu/pb4/polymer/impl/networking/PolymerServerProtocol.java b/src/main/java/eu/pb4/polymer/impl/networking/PolymerServerProtocol.java index d44bedcd..91f768dd 100644 --- a/src/main/java/eu/pb4/polymer/impl/networking/PolymerServerProtocol.java +++ b/src/main/java/eu/pb4/polymer/impl/networking/PolymerServerProtocol.java @@ -239,9 +239,9 @@ public static void sendCreativeSyncPackets(ServerPlayNetworkHandler handler) { } } - var sync = new PolymerItemGroup.ItemGroupSyncer() { + var sync = new PolymerItemGroup.ItemGroupListBuilder() { @Override - public void send(PolymerItemGroup group) { + public void add(PolymerItemGroup group) { list.add(group); } diff --git a/src/main/java/eu/pb4/polymer/impl/package-info.java b/src/main/java/eu/pb4/polymer/impl/package-info.java index f1f088d4..c88ac037 100644 --- a/src/main/java/eu/pb4/polymer/impl/package-info.java +++ b/src/main/java/eu/pb4/polymer/impl/package-info.java @@ -1,5 +1,7 @@ /** * Internal use only! + * + * If you call anything in this package, it might break in any patch and minor release */ @ApiStatus.Internal package eu.pb4.polymer.impl; diff --git a/src/testmod/java/eu/pb4/polymertest/TestMod.java b/src/testmod/java/eu/pb4/polymertest/TestMod.java index 9d5a8ab4..10eb0e37 100644 --- a/src/testmod/java/eu/pb4/polymertest/TestMod.java +++ b/src/testmod/java/eu/pb4/polymertest/TestMod.java @@ -244,7 +244,7 @@ public void onInitialize() { PolymerItemGroup.LIST_EVENT.register((p, s) -> { if (atomicBoolean.get()) { - s.send(ITEM_GROUP_2); + s.add(ITEM_GROUP_2); } });