From c72b4cc6f2818c384a445967ebf0fc6a3a399bfb Mon Sep 17 00:00:00 2001 From: Patbox <39821509+Patbox@users.noreply.github.com> Date: Thu, 9 Nov 2023 23:25:02 +0100 Subject: [PATCH] Git gut --- .github/workflows/mkdocs-publish.yml | 2 +- MODS.md | 52 ++++++----- gradle.properties | 2 +- .../core/api/item/PolymerItemUtils.java | 32 +++++++ .../interfaces/ItemStackAwareNbtCompound.java | 13 --- .../impl/interfaces/TypeAwareNbtCompound.java | 16 ++++ .../core/mixin/item/ItemStackMixin.java | 12 +-- .../mixin/item/NbtCompoundFallbackMixin.java | 6 +- .../core/mixin/item/NbtCompoundMixin.java | 90 +++++++++++++------ .../core/mixin/item/NbtHelperMixin.java | 18 ++++ .../main/resources/polymer-core.mixins.json | 3 +- .../java/eu/pb4/polymertest/TestBlock.java | 2 +- .../java/eu/pb4/polymertest/TestEntity2.java | 11 +++ .../mixin/PistonBlockEntityMixin.java | 31 +++++++ .../src/testmod/resources/test.mixins.json | 1 + 15 files changed, 212 insertions(+), 79 deletions(-) delete mode 100644 polymer-core/src/main/java/eu/pb4/polymer/core/impl/interfaces/ItemStackAwareNbtCompound.java create mode 100644 polymer-core/src/main/java/eu/pb4/polymer/core/impl/interfaces/TypeAwareNbtCompound.java create mode 100644 polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/NbtHelperMixin.java create mode 100644 polymer-core/src/testmod/java/eu/pb4/polymertest/mixin/PistonBlockEntityMixin.java diff --git a/.github/workflows/mkdocs-publish.yml b/.github/workflows/mkdocs-publish.yml index 937f0c51..8b259b2a 100644 --- a/.github/workflows/mkdocs-publish.yml +++ b/.github/workflows/mkdocs-publish.yml @@ -21,5 +21,5 @@ jobs: git config --global user.name Docs deploy git config --global user.email docs@dummy.bot.com mike set-default latest - mike deploy --push --update-aliases 0.5.x latest + mike deploy --push --update-aliases 0.6.x latest diff --git a/MODS.md b/MODS.md index 644d7fbe..bd3f7fba 100644 --- a/MODS.md +++ b/MODS.md @@ -1,5 +1,5 @@ # Mods using Polymer -A list of server-side Fabric/Quilt mods using Polymer, ordered alphabetically. +A list of server-side Fabric or Quilt mods using Polymer, ordered alphabetically. *Some mods work best with Polymer's auto-generated resource pack: `/polymer generate-packs`* @@ -21,7 +21,7 @@ into itself from any connected hopper chain. - CurseForge: https://www.curseforge.com/minecraft/mc-mods/amazing-chest -## Biome Compass (1.19.2) +## Biome Compass (1.20.2 / latest) *Biome Compass* adds a compass that works like [Nature's Compass](https://www.curseforge.com/minecraft/mc-mods/natures-compass), but is completely server-side! ### Links: @@ -29,7 +29,7 @@ into itself from any connected hopper chain. - Modrinth: https://modrinth.com/mod/biome-compass -## Brewery (1.20.1 / latest) +## Brewery (1.20.2 / latest) *Brewery* allows you to create alcoholic and non-alcoholic drinks with cauldrons and barrels. Aside from a few that are built-in, you can add any number of custom drinks with their own recipes and functionality using datapacks. Additionally, this mod can work purely server side, allowing vanilla clients to join and use @@ -60,7 +60,7 @@ introducing support for some new features while adding new content. - Modrinth: https://modrinth.com/mod/dcdservback -## Eldritch Mobs (1.19.2) +## Eldritch Mobs (1.20.1) *Eldritch Mobs* is a port of [AtomicStryker's Infernal Mobs](https://www.curseforge.com/minecraft/mc-mods/atomicstrykers-infernal-mobs). This mod randomly imbues mobs in your world with powerful abilities that make them more challenging to fight. @@ -70,7 +70,7 @@ This mod randomly imbues mobs in your world with powerful abilities that make th - CurseForge: https://www.curseforge.com/minecraft/mc-mods/eldritch-mobs -## FabricAutoCrafter (1.20.1 / latest) +## FabricAutoCrafter (1.20.2 / latest) *FabricAutoCrafter* adds a new block, the AutoCrafter. It allows you to put items in the crafting table and get an output. Hoppers and droppers do interact with the table. @@ -89,7 +89,7 @@ Hoppers and droppers do interact with the table. - Modrinth: https://modrinth.com/mod/polymer-ports-waystones -## Fishing 101 (1.20.1 / latest) +## Fishing 101 (1.20.1) *Fishing 101* adds 23 new aquatic life forms to the game (items, not entities). ### Links: @@ -108,7 +108,7 @@ or turn content mods on and off one by one to nail down that pesky bug. - CurseForge: https://www.curseforge.com/minecraft/mc-mods/flashfreeze -## Get Off My Lawn ReServed (1.20.1 / latest) +## Get Off My Lawn ReServed (1.20.2 / latest) *Get Off My Lawn ReServed* is a take on the popular concept of player claims for Survival/Freebuild servers. This mod works fully server-side (no client mod required!) while being compatible with major Fabric modpacks. @@ -156,7 +156,7 @@ of the Illagers before it's too late? - CurseForge: https://www.curseforge.com/minecraft/mc-mods/interdimensional -## Jump Vader (1.20.1 / latest) +## Jump Vader (1.20.1) *Jump Vader* is a mod that lets you place "Jump Vader" blocks similar to the OpenBlocks mod's elevators. You simply place one above the other at any vertical distance, and jump/sneak on top of the block to go between the different heights. @@ -166,7 +166,7 @@ to go between the different heights. - Modrinth: https://modrinth.com/mod/jumpvader -## Labyrinth (1.20.1 / latest) +## Labyrinth (1.20.1) *Labyrinth* adds new weapons and a new custom crafting (forging) system! ### Links: @@ -175,7 +175,7 @@ to go between the different heights. - CurseForge: https://www.curseforge.com/minecraft/mc-mods/labyrinth -## LifeSteal (1.20.1 / latest) +## LifeSteal (1.20.2 / latest) *LifeSteal* is an implementation of [LifeSteal SMP](https://store.lifestealsmp.com). > We are a semi-vanilla Minecraft server with an additional feature where you can steal hearts from other players. > When you kill another player, you receive their heart while they lose a heart. @@ -187,7 +187,7 @@ to go between the different heights. - CurseForge: https://www.curseforge.com/minecraft/mc-mods/lifesteal -## Lightning Podoboo (1.20.1 / latest) +## Lightning Podoboo (1.20.2 / latest) *Lightning Podoboo* makes fire created by natural lightning cosmetic, meaning no blocks are destroyed from bad weather. Keep the `doFireTick` gamerule enabled without worrying about random fire destroying your builds or nearby trees! @@ -213,8 +213,7 @@ and a present threat. - Modrinth: https://modrinth.com/mod/nox - CurseForge: https://www.curseforge.com/minecraft/mc-mods/nox-a-mob-and-difficulty-overhaul - -## Nox: Renoxed (1.20.1 / latest) +## Nox: Renoxed (1.20.2 / latest) *Nox: Renoxed* is a continuation of *Nox* for Minecraft 1.20 and beyond. ### Links: @@ -239,8 +238,19 @@ that lets players access their ender chest from anywhere. - GitHub: https://github.com/NotNite/packy - Modrinth: https://modrinth.com/mod/packy +## PolyFactory (1.20.2 / latest) +Ever wanted to play with tech mods, but people you play with don't want to install them? +Or maybe you are making a server, but vanilla gameplay isn't enough? If so, this project will be ideal for you! + +PolyFactory is Fabric (and Quilt) server side modification powered by Polymer +which adds new mechanics, blocks and tools allowing for further automation, +processing and storage (or in simpler terms, it's a tech mod)! + +### Links: +- GitHub: https://github.com/patbox/polyfactory +- Modrinth: https://modrinth.com/mod/polyfactory -## Polysit (1.20.1 / latest) +## Polysit (1.20.2 / latest) *Polysit* allows you to right-click to sit on slabs or stairs. ### Links: @@ -248,7 +258,7 @@ that lets players access their ender chest from anywhere. - Modrinth: https://modrinth.com/mod/polysit -## Power Networks (1.20.1 / latest) +## Power Networks (1.20.2 / latest) *Power Networks* adds coils and wires that the player can use to build energy transfer networks. (does not include any energy producers or consumers) @@ -312,7 +322,7 @@ and various blocks to speed up breeding and curing. - CurseForge: https://www.curseforge.com/minecraft/mc-mods/simplevillagers -## Spice of Fabric (1.20.1 / latest) +## Spice of Fabric (1.20.2 / latest) With *Spice of Fabric,* as you eat food, the nutrition value of the different kinds of food will decrease, so you're forced to have a diverse diet. By default, the last 20 meals are considered when calculating the nutrition values and the drop in the nutrition @@ -337,7 +347,7 @@ for people who need vanilla physics) and adds multiple new minecarts with their - CurseForge: https://www.curseforge.com/minecraft/mc-mods/tatercart -## Trinkets (Polymer Port) (1.20 / latest) +## Trinkets (Polymer Port) (1.20.2 / latest) *Trinkets* is a data-driven accessory mod for Minecraft using Fabric. ### Links: @@ -345,7 +355,7 @@ for people who need vanilla physics) and adds multiple new minecarts with their - Modrinth: https://modrinth.com/mod/trinkets-polymer -## URLium (1.20.1 / latest) +## URLium (1.20.2 / latest) *URLium* transmits redstone and blockstate data over HTTP(S) to a configurable URL. Get data from the URLium Block, a Post Wand on any block, or Config Wand to turn Chests, Lecterns, and Signs into HTTP-reporting blocks! @@ -355,11 +365,11 @@ Chests, Lecterns, and Signs into HTTP-reporting blocks! ### Links: - Github: https://github.com/JacobMunoz/urlium_1_20_1_public -- Modirnth: https://modrinth.com/mod/urlium +- Modrinth: https://modrinth.com/mod/urlium - CurseForge: https://www.curseforge.com/minecraft/mc-mods/urlium -## Universal Graves (1.20.1 / latest) +## Universal Graves (1.20.2 / latest) *Universal Graves* is a simple, but really customizable grave/death chest mod! You can customize as you like, by modifying messages, blocks, and hologram texts, how long graves will be protected, whether items should be dropped after expiring, etc. @@ -370,7 +380,7 @@ how long graves will be protected, whether items should be dropped after expirin - CurseForge: https://www.curseforge.com/minecraft/mc-mods/universal-graves -## Universal Shops (1.20.1 / latest) +## Universal Shops (1.20.2 / latest) *Universal Shops* is a trade shop mod designed to be flexible and usable in many types of servers. It includes craftable Trade Shop blocks for players and Admin Trade Shop blocks for admins/map makers. Setup of both is the same. It also checks against Common Protection API to make sure players have access to source chests/containers. diff --git a/gradle.properties b/gradle.properties index 21c19b16..6edf3cd1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ fabric_version=0.89.1+1.20.2 maven_group = eu.pb4 -mod_version = 0.6.2 +mod_version = 0.6.3 minecraft_version_supported = ">=1.20.2-" diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/api/item/PolymerItemUtils.java b/polymer-core/src/main/java/eu/pb4/polymer/core/api/item/PolymerItemUtils.java index f4f5b114..4ffbbce4 100644 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/api/item/PolymerItemUtils.java +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/api/item/PolymerItemUtils.java @@ -245,6 +245,16 @@ public static boolean isPolymerServerItem(ItemStack itemStack, @Nullable ServerP } } + if (itemStack.getNbt().contains(BlockItem.BLOCK_ENTITY_TAG_KEY, NbtElement.COMPOUND_TYPE) + && itemStack.getNbt().getCompound(BlockItem.BLOCK_ENTITY_TAG_KEY).contains("Items", NbtElement.LIST_TYPE) + ) { + for (var itemNbt : itemStack.getNbt().getCompound(BlockItem.BLOCK_ENTITY_TAG_KEY).getList("Items", NbtElement.COMPOUND_TYPE)) { + if (isPolymerServerItem(ItemStack.fromNbt((NbtCompound) itemNbt), player)) { + return true; + } + } + } + if (CompatStatus.POLYMER_RESOURCE_PACK) { var display = itemStack.getSubNbt("display"); if (display != null && display.contains("color", NbtElement.INT_TYPE)) { @@ -434,6 +444,28 @@ public static ItemStack createItemStack(ItemStack itemStack, TooltipContext tool e.printStackTrace(); } } + + try { + if (out.getNbt().contains(BlockItem.BLOCK_ENTITY_TAG_KEY, NbtElement.COMPOUND_TYPE)) { + var blockEntity = out.getNbt().getCompound(BlockItem.BLOCK_ENTITY_TAG_KEY); + if (blockEntity.contains("Items")) { + var list = blockEntity.getList("Items", NbtElement.COMPOUND_TYPE); + for (var i = 0; i < list.size(); i++) { + var itemNbt = list.getCompound(i); + var base = new NbtCompound(); + var slot = itemNbt.get("Slot"); + if (slot != null) { + base.put("Slot", slot); + } + list.set(i, getPolymerItemStack(ItemStack.fromNbt(itemNbt), tooltipContext, player).writeNbt(base)); + } + } + } + } catch (Throwable e) { + if (PolymerImpl.LOG_MORE_ERRORS) { + e.printStackTrace(); + } + } } else { if (itemStack.hasGlint()) { var list = new NbtList(); diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/impl/interfaces/ItemStackAwareNbtCompound.java b/polymer-core/src/main/java/eu/pb4/polymer/core/impl/interfaces/ItemStackAwareNbtCompound.java deleted file mode 100644 index 8a70b516..00000000 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/impl/interfaces/ItemStackAwareNbtCompound.java +++ /dev/null @@ -1,13 +0,0 @@ -package eu.pb4.polymer.core.impl.interfaces; - -import net.minecraft.nbt.NbtByte; -import net.minecraft.nbt.NbtElement; - -public interface ItemStackAwareNbtCompound { - String MARKER_KEY = "$$polymer:itemstack"; - NbtElement MARKER_VALUE = NbtByte.of((byte) 1); - default void polymerCore$setItemStack(boolean bool) {}; - default boolean polymerCore$getItemStack() { - return false; - }; -} diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/impl/interfaces/TypeAwareNbtCompound.java b/polymer-core/src/main/java/eu/pb4/polymer/core/impl/interfaces/TypeAwareNbtCompound.java new file mode 100644 index 00000000..afb4b2e2 --- /dev/null +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/impl/interfaces/TypeAwareNbtCompound.java @@ -0,0 +1,16 @@ +package eu.pb4.polymer.core.impl.interfaces; + +import net.minecraft.nbt.NbtByte; +import net.minecraft.nbt.NbtElement; +import net.minecraft.nbt.NbtString; + +public interface TypeAwareNbtCompound { + String MARKER_KEY = "$$polymer:type"; + + NbtString STACK_TYPE = NbtString.of( "item_stack"); + NbtString STATE_TYPE = NbtString.of("block_state"); + default void polymerCore$setType(NbtString type) {}; + default NbtString polymerCore$getType() { + return null; + }; +} diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/ItemStackMixin.java b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/ItemStackMixin.java index e24f6745..f5be3cc1 100644 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/ItemStackMixin.java +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/ItemStackMixin.java @@ -1,21 +1,15 @@ package eu.pb4.polymer.core.mixin.item; -import com.llamalad7.mixinextras.injector.ModifyReturnValue; -import com.llamalad7.mixinextras.sugar.Local; -import eu.pb4.polymer.common.api.PolymerCommonUtils; import eu.pb4.polymer.core.api.item.PolymerItemUtils; import eu.pb4.polymer.core.api.utils.PolymerUtils; import eu.pb4.polymer.core.impl.PolymerImpl; -import eu.pb4.polymer.core.impl.PolymerImplUtils; -import eu.pb4.polymer.core.impl.interfaces.ItemStackAwareNbtCompound; +import eu.pb4.polymer.core.impl.interfaces.TypeAwareNbtCompound; import eu.pb4.polymer.core.impl.other.PolymerTooltipContext; import net.minecraft.client.item.TooltipContext; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; -import net.minecraft.registry.Registries; import net.minecraft.text.Text; -import net.minecraft.util.Identifier; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -30,7 +24,7 @@ public class ItemStackMixin { /*@ModifyReturnValue(method = "fromNbt(Lnet/minecraft/nbt/NbtCompound;)Lnet/minecraft/item/ItemStack;", at = @At("RETURN")) private static ItemStack polymerCore$swapToRealStack(ItemStack stack, @Local NbtCompound nbt) { - if (nbt.contains(ItemStackAwareNbtCompound.MARKER_KEY) && PolymerCommonUtils.isServerBound()) { + if (nbt.contains(TypeAwareNbtCompound.MARKER_KEY) && PolymerCommonUtils.isServerBound()) { return PolymerItemUtils.getRealItemStack(stack); } @@ -43,7 +37,7 @@ public class ItemStackMixin { var self = (ItemStack) (Object) this; var player = PolymerUtils.getPlayerContext(); if (PolymerItemUtils.isPolymerServerItem(self, player)) { - ((ItemStackAwareNbtCompound) nbt).polymerCore$setItemStack(true); + ((TypeAwareNbtCompound) nbt).polymerCore$setType(TypeAwareNbtCompound.STACK_TYPE); } } } diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/NbtCompoundFallbackMixin.java b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/NbtCompoundFallbackMixin.java index 6a249497..30be8738 100644 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/NbtCompoundFallbackMixin.java +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/NbtCompoundFallbackMixin.java @@ -1,12 +1,10 @@ package eu.pb4.polymer.core.mixin.item; -import eu.pb4.polymer.core.impl.interfaces.ItemStackAwareNbtCompound; -import net.minecraft.item.ItemStack; +import eu.pb4.polymer.core.impl.interfaces.TypeAwareNbtCompound; import net.minecraft.nbt.NbtCompound; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.Inject; @Mixin(NbtCompound.class) -public class NbtCompoundFallbackMixin implements ItemStackAwareNbtCompound { +public class NbtCompoundFallbackMixin implements TypeAwareNbtCompound { } diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/NbtCompoundMixin.java b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/NbtCompoundMixin.java index 93e25db4..41edbffd 100644 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/NbtCompoundMixin.java +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/NbtCompoundMixin.java @@ -4,54 +4,62 @@ import com.llamalad7.mixinextras.sugar.Share; import com.llamalad7.mixinextras.sugar.ref.LocalRef; import eu.pb4.polymer.common.api.PolymerCommonUtils; +import eu.pb4.polymer.core.api.block.PolymerBlockUtils; import eu.pb4.polymer.core.api.item.PolymerItemUtils; -import eu.pb4.polymer.core.impl.interfaces.ItemStackAwareNbtCompound; +import eu.pb4.polymer.core.impl.interfaces.TypeAwareNbtCompound; +import net.minecraft.block.BlockState; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtByte; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; +import net.minecraft.nbt.NbtHelper; import net.minecraft.nbt.NbtString; import net.minecraft.registry.Registries; -import org.spongepowered.asm.mixin.Final; +import net.minecraft.state.property.Property; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.io.DataOutput; import java.io.IOException; -import java.util.Map; +import java.util.Collection; @Mixin(NbtCompound.class) -public abstract class NbtCompoundMixin implements ItemStackAwareNbtCompound { +public abstract class NbtCompoundMixin implements TypeAwareNbtCompound { @Shadow private static void write(String key, NbtElement element, DataOutput output) throws IOException { } @Unique - private boolean polymerCore$stack; + private NbtString polymerCore$type; @Override - public void polymerCore$setItemStack(boolean value) { - this.polymerCore$stack = value; + public void polymerCore$setType(NbtString value) { + this.polymerCore$type = value; } @Override - public boolean polymerCore$getItemStack() { - return this.polymerCore$stack; + public NbtString polymerCore$getType() { + return this.polymerCore$type; } @Inject(method = "write(Ljava/io/DataOutput;)V", at = @At("HEAD")) - private void polymerCore$storePlayerContextedItemStack(DataOutput output, CallbackInfo ci, @Share("polymerCore:stack") LocalRef polymerStack) { - if (this.polymerCore$stack && PolymerCommonUtils.isServerNetworkingThread()) { + private void polymerCore$storePlayerContextedItemStack(DataOutput output, CallbackInfo ci, @Share("polymerCore:stack") LocalRef polymerStack) { + if (this.polymerCore$type != null && PolymerCommonUtils.isServerNetworkingThread()) { var player = PolymerCommonUtils.getPlayerContextNoClient(); - var stack = ItemStack.fromNbt((NbtCompound) (Object) this); - if (player != null && stack != null && !stack.isEmpty()) { - polymerStack.set(PolymerItemUtils.getPolymerItemStack(stack, player)); + if (this.polymerCore$type == TypeAwareNbtCompound.STACK_TYPE) { + var stack = ItemStack.fromNbt((NbtCompound) (Object) this); + if (player != null && stack != null && !stack.isEmpty()) { + polymerStack.set(PolymerItemUtils.getPolymerItemStack(stack, player)); + } + } else if (this.polymerCore$type == TypeAwareNbtCompound.STATE_TYPE) { + var stack = NbtHelper.toBlockState(Registries.BLOCK.getReadOnlyWrapper(), (NbtCompound) (Object) this); + if (player != null && stack != null && !stack.isAir()) { + polymerStack.set(PolymerBlockUtils.getPolymerBlockState(stack, player)); + } } } } @@ -60,25 +68,51 @@ private static void write(String key, NbtElement element, DataOutput output) thr method = "write(Ljava/io/DataOutput;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/NbtCompound;write(Ljava/lang/String;Lnet/minecraft/nbt/NbtElement;Ljava/io/DataOutput;)V") ) - private boolean polymerCore$ignoreIdAndTag(String key, NbtElement element, DataOutput output, @Share("polymerCore:stack") LocalRef polymerStack) { - if (this.polymerCore$stack && PolymerCommonUtils.isServerNetworkingThread()) { + private boolean polymerCore$ignoreIdAndTag(String key, NbtElement element, DataOutput output, @Share("polymerCore:stack") LocalRef polymerStack) { + if (this.polymerCore$type != null && PolymerCommonUtils.isServerNetworkingThread()) { var stack = polymerStack.get(); if (stack != null) { - return !key.equals("id") && !key.equals("tag"); + if (this.polymerCore$type == TypeAwareNbtCompound.STACK_TYPE) { + return !key.equals("id") && !key.equals("tag"); + + } else if (this.polymerCore$type == TypeAwareNbtCompound.STATE_TYPE) { + return !key.equals("Name") && !key.equals("Properties"); + } } } return true; } @Inject(method = "write(Ljava/io/DataOutput;)V", at = @At(value = "INVOKE", target = "Ljava/io/DataOutput;writeByte(I)V", ordinal = 0)) - private void polymerCore$writeNbtIfMissing(DataOutput output, CallbackInfo ci, @Share("polymerCore:stack") LocalRef polymerStack) throws IOException { - if (this.polymerCore$stack && PolymerCommonUtils.isServerNetworkingThread()) { - var stack = polymerStack.get(); - if (stack != null) { - write(MARKER_KEY, MARKER_VALUE, output); - write("id", NbtString.of(Registries.ITEM.getId(stack.getItem()).toString()), output); - if (stack.hasNbt()) { - write("tag", stack.getNbt(), output); + private void polymerCore$writeNbtIfMissing(DataOutput output, CallbackInfo ci, @Share("polymerCore:stack") LocalRef polymerStack) throws IOException { + if (this.polymerCore$type != null && PolymerCommonUtils.isServerNetworkingThread()) { + write(MARKER_KEY, this.polymerCore$type, output); + if (this.polymerCore$type == TypeAwareNbtCompound.STACK_TYPE) { + var stack = (ItemStack) polymerStack.get(); + if (stack != null) { + write("id", NbtString.of(Registries.ITEM.getId(stack.getItem()).toString()), output); + if (stack.hasNbt()) { + write("tag", stack.getNbt(), output); + } + } + } else if (this.polymerCore$type == TypeAwareNbtCompound.STATE_TYPE) { + var stack = (BlockState) polymerStack.get(); + if (stack != null) { + write("Name", NbtString.of(Registries.BLOCK.getId(stack.getBlock()).toString()), output); + //noinspection unchecked + var props = (Collection) (Object) stack.getBlock().getStateManager().getProperties(); + if (!props.isEmpty()) { + output.writeByte(NbtElement.COMPOUND_TYPE); + output.writeUTF("Properties"); + + for(var prop : props) { + output.writeByte(NbtElement.STRING_TYPE); + output.writeUTF(prop.getName()); + //noinspection unchecked + output.writeUTF(prop.name(stack.get(prop))); + } + output.writeByte(0); + } } } } @@ -86,6 +120,6 @@ private static void write(String key, NbtElement element, DataOutput output) thr @Inject(method = "copy()Lnet/minecraft/nbt/NbtCompound;", at = @At("RETURN")) private void polymerCore$copyStack(CallbackInfoReturnable cir) { - ((ItemStackAwareNbtCompound) cir.getReturnValue()).polymerCore$setItemStack(this.polymerCore$stack); + ((TypeAwareNbtCompound) cir.getReturnValue()).polymerCore$setType(this.polymerCore$type); } } diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/NbtHelperMixin.java b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/NbtHelperMixin.java new file mode 100644 index 00000000..50600968 --- /dev/null +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/NbtHelperMixin.java @@ -0,0 +1,18 @@ +package eu.pb4.polymer.core.mixin.item; + +import eu.pb4.polymer.core.impl.interfaces.TypeAwareNbtCompound; +import net.minecraft.block.BlockState; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.NbtHelper; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(NbtHelper.class) +public class NbtHelperMixin { + @Inject(method = "fromBlockState", at = @At("RETURN")) + private static void polymerCore$markNbt(BlockState state, CallbackInfoReturnable cir) { + //((TypeAwareNbtCompound) cir.getReturnValue()).polymerCore$setType(TypeAwareNbtCompound.STATE_TYPE); + } +} diff --git a/polymer-core/src/main/resources/polymer-core.mixins.json b/polymer-core/src/main/resources/polymer-core.mixins.json index 2e43f784..d1c9dbac 100644 --- a/polymer-core/src/main/resources/polymer-core.mixins.json +++ b/polymer-core/src/main/resources/polymer-core.mixins.json @@ -57,6 +57,7 @@ "item.MiningToolItemAccessor", "item.NbtCompoundFallbackMixin", "item.NbtCompoundMixin", + "item.NbtHelperMixin", "item.PlayerManagerMixin", "item.ServerPlayNetworkHandlerMixin", "item.StonecutterScreenHandlerMixin", @@ -80,7 +81,6 @@ "other.TagPacketSerializerMixin" ], "client": [ - "client.compat.emi_EmiScreenManager", "client.ClientPlayNetworkHandlerMixin", "client.CreativeInventoryScreenAccessor", "client.DebugHudMixin", @@ -92,6 +92,7 @@ "client.block.ChunkSectionMixin", "client.block.EmptyChunkMixin", "client.block.WorldChunkMixin", + "client.compat.emi_EmiScreenManager", "client.compat.emi_EmiStackMixin", "client.compat.emi_ItemEmiStackMixin", "client.compat.jei_StackHelperMixin", diff --git a/polymer-core/src/testmod/java/eu/pb4/polymertest/TestBlock.java b/polymer-core/src/testmod/java/eu/pb4/polymertest/TestBlock.java index 115a9863..1e58fe74 100644 --- a/polymer-core/src/testmod/java/eu/pb4/polymertest/TestBlock.java +++ b/polymer-core/src/testmod/java/eu/pb4/polymertest/TestBlock.java @@ -22,7 +22,7 @@ public TestBlock(Settings settings) { super(settings); } - private static final IntProperty TEST = IntProperty.of("test", 0, 1000); + private static final IntProperty TEST = IntProperty.of("test", 0, 10); @Nullable @Override diff --git a/polymer-core/src/testmod/java/eu/pb4/polymertest/TestEntity2.java b/polymer-core/src/testmod/java/eu/pb4/polymertest/TestEntity2.java index 804a17cc..47b6bab3 100644 --- a/polymer-core/src/testmod/java/eu/pb4/polymertest/TestEntity2.java +++ b/polymer-core/src/testmod/java/eu/pb4/polymertest/TestEntity2.java @@ -6,11 +6,14 @@ import com.mojang.datafixers.util.Pair; import eu.pb4.polymer.core.api.entity.PolymerEntity; import eu.pb4.polymer.core.api.entity.PolymerEntityUtils; +import net.minecraft.block.BlockState; +import net.minecraft.block.FluidBlock; import net.minecraft.entity.EntityPose; import net.minecraft.entity.EntityType; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.mob.CreeperEntity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.fluid.FluidState; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.network.packet.Packet; @@ -20,8 +23,11 @@ import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.BlockView; import net.minecraft.world.GameMode; import net.minecraft.world.World; +import net.minecraft.world.explosion.Explosion; import java.util.EnumSet; import java.util.List; @@ -45,6 +51,11 @@ public EntityType getPolymerEntityType(ServerPlayerEntity player) { return EntityType.PLAYER; } + @Override + public float getEffectiveExplosionResistance(Explosion explosion, BlockView world, BlockPos pos, BlockState blockState, FluidState fluidState, float max) { + return blockState.isAir() || blockState.getBlock() instanceof FluidBlock ? 0 : blockState.getBlock().getBlastResistance(); + } + @Override protected ActionResult interactMob(PlayerEntity player, Hand hand) { if (player.getStackInHand(hand).isOf(Items.STICK)) { diff --git a/polymer-core/src/testmod/java/eu/pb4/polymertest/mixin/PistonBlockEntityMixin.java b/polymer-core/src/testmod/java/eu/pb4/polymertest/mixin/PistonBlockEntityMixin.java new file mode 100644 index 00000000..4ced485f --- /dev/null +++ b/polymer-core/src/testmod/java/eu/pb4/polymertest/mixin/PistonBlockEntityMixin.java @@ -0,0 +1,31 @@ +package eu.pb4.polymertest.mixin; + +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.block.entity.BlockEntityType; +import net.minecraft.block.entity.PistonBlockEntity; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.network.listener.ClientPlayPacketListener; +import net.minecraft.network.packet.Packet; +import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket; +import net.minecraft.util.math.BlockPos; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(PistonBlockEntity.class) +public class PistonBlockEntityMixin extends BlockEntity { + public PistonBlockEntityMixin(BlockEntityType type, BlockPos pos, BlockState state) { + super(type, pos, state); + } + + @Nullable + @Override + public Packet toUpdatePacket() { + return BlockEntityUpdateS2CPacket.create(this); + } + + @Override + public NbtCompound toInitialChunkDataNbt() { + return this.createNbt(); + } +} diff --git a/polymer-core/src/testmod/resources/test.mixins.json b/polymer-core/src/testmod/resources/test.mixins.json index a9ecca58..4d58a713 100644 --- a/polymer-core/src/testmod/resources/test.mixins.json +++ b/polymer-core/src/testmod/resources/test.mixins.json @@ -11,6 +11,7 @@ "EntityAccessor", "ItemDisplayEntityAccessor", "OctavePerlinNoiseSamplerMixin", + "PistonBlockEntityMixin", "PlayerEntityMixin", "RedstoneLampMixin", "RideCommandMixin",