From 51bb8de2cbd643cf7074995c1bd77278e9d060cd Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Sat, 25 Dec 2021 14:49:47 +0300 Subject: [PATCH 1/5] Fixed teleportation target being incorrect when syncing while riding an entity Fixes #20 --- src/main/java/dev/kir/sync/mixin/ServerPlayerEntityMixin.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/dev/kir/sync/mixin/ServerPlayerEntityMixin.java b/src/main/java/dev/kir/sync/mixin/ServerPlayerEntityMixin.java index bfa0859..d1eb85a 100644 --- a/src/main/java/dev/kir/sync/mixin/ServerPlayerEntityMixin.java +++ b/src/main/java/dev/kir/sync/mixin/ServerPlayerEntityMixin.java @@ -174,6 +174,7 @@ public void apply(ShellState state) { return; } + this.stopRiding(); this.dropShoulderEntities(); this.extinguish(); this.setFrozenTicks(0); From 99adac6a9bbd49f9b26c9e35b35ccd233b769f6f Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Sat, 25 Dec 2021 15:00:48 +0300 Subject: [PATCH 2/5] Fixed death screen not being shown when sync fails --- .../dev/kir/sync/mixin/ClientPlayerEntityMixin.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/dev/kir/sync/mixin/ClientPlayerEntityMixin.java b/src/main/java/dev/kir/sync/mixin/ClientPlayerEntityMixin.java index 1ee2822..0ec2e14 100644 --- a/src/main/java/dev/kir/sync/mixin/ClientPlayerEntityMixin.java +++ b/src/main/java/dev/kir/sync/mixin/ClientPlayerEntityMixin.java @@ -97,11 +97,14 @@ private ClientPlayerEntityMixin(ClientWorld world, GameProfile profile) { @Override public void endSync(Identifier startWorld, BlockPos startPos, Direction startFacing, Identifier targetWorld, BlockPos targetPos, Direction targetFacing, @Nullable ShellState storedState) { ClientPlayerEntity player = (ClientPlayerEntity)(Object)this; + boolean syncFailed = Objects.equals(startPos, targetPos); - if (this.getHealth() <= 0) { - this.setHealth(0.01F); + if (!syncFailed) { + if (this.getHealth() <= 0) { + this.setHealth(0.01F); + } + this.deathTime = 0; } - this.deathTime = 0; float yaw = targetFacing.getOpposite().asRotation(); this.setYaw(yaw); @@ -118,8 +121,6 @@ public void endSync(Identifier startWorld, BlockPos startPos, Direction startFac PersistentCameraEntity.unset(this.client); HudController.restore(); DeathScreenController.restore(); - - boolean syncFailed = Objects.equals(startPos, targetPos); if (!syncFailed) { PlayerSyncEvents.STOP_SYNCING.invoker().onStopSyncing(this, startPos, storedState); } From 23195e1e1ff61ad72a42de8356f7dd5eda81648f Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Sun, 26 Dec 2021 11:43:19 +0300 Subject: [PATCH 3/5] Fix: breaking a shell container not by a player didn't work correctly Fixes #19 --- .../kir/sync/block/AbstractShellContainerBlock.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/dev/kir/sync/block/AbstractShellContainerBlock.java b/src/main/java/dev/kir/sync/block/AbstractShellContainerBlock.java index 2a204e9..e6d613a 100644 --- a/src/main/java/dev/kir/sync/block/AbstractShellContainerBlock.java +++ b/src/main/java/dev/kir/sync/block/AbstractShellContainerBlock.java @@ -130,9 +130,6 @@ public void onEntityCollision(BlockState state, World world, BlockPos pos, Entit public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) { boolean bottom = isBottom(state); BlockPos bottomPos = bottom ? pos : pos.down(); - if (world.getBlockEntity(bottomPos) instanceof AbstractShellContainerBlockEntity shellContainer) { - shellContainer.onBreak(world, bottomPos); - } if (!world.isClient && player.isCreative()) { if (!bottom) { BlockState blockState = world.getBlockState(bottomPos); @@ -145,6 +142,16 @@ public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity pl super.onBreak(world, pos, state, player); } + @Override + public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) { + if (!state.isOf(newState.getBlock())) { + if (isBottom(state) && world.getBlockEntity(pos) instanceof AbstractShellContainerBlockEntity shellContainer) { + shellContainer.onBreak(world, pos); + } + world.removeBlockEntity(pos); + } + } + @Override public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { if (ItemUtil.isWrench(player.getStackInHand(hand))) { From b2eed81677cbebe24a9961bd0ed434582f8a0a6a Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Sun, 26 Dec 2021 16:48:44 +0300 Subject: [PATCH 4/5] Added `Origins` support Closes #15 --- build.gradle | 23 +++- gradle.properties | 1 + .../sync/compat/origins/OriginsCompat.java | 15 +++ .../origins/OriginsShellStateComponent.java | 113 ++++++++++++++++++ src/main/resources/fabric.mod.json | 2 + 5 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 src/main/java/dev/kir/sync/compat/origins/OriginsCompat.java create mode 100644 src/main/java/dev/kir/sync/compat/origins/OriginsShellStateComponent.java diff --git a/build.gradle b/build.gradle index 480cbc8..e26c8c2 100644 --- a/build.gradle +++ b/build.gradle @@ -69,6 +69,25 @@ repositories { name = "CrowdinTranslate" url = "https://minecraft.guntram.de/maven/" } + maven { + name = "JitPack" + url = "https://jitpack.io" + content { + includeGroupByRegex "(io|com)\\.github\\..*" + } + } + maven { + url = "https://maven.jamieswhiteshirt.com/libs-release/" + content { + includeGroup "com.jamieswhiteshirt" + } + } + maven { + url = "https://maven.cafeteria.dev" + content { + includeGroup "net.adriantodt.fabricmc" + } + } } // To change the versions see the gradle.properties file @@ -89,6 +108,7 @@ dependencies { modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}" modImplementation "dev.emi:trinkets:${project.trinkets_version}" modImplementation "io.github.ladysnake:requiem-api:${project.requiem_version}" + modImplementation "com.github.apace100:origins-fabric:${project.origins_version}" // Minecraft 1.17 is slow as heck modRuntime("supercoder79:databreaker:${project.databreaker_version}") { @@ -107,7 +127,8 @@ processResources { "team_reborn_energy": project.tr_energy_version, "modmenu": ">=${project.modmenu_version}", "trinkets": ">=${project.trinkets_version}", - "requiem": ">=${project.requiem_version}" + "requiem": ">=${project.requiem_version}", + "origins": ">=${project.origins_version}", ] filesMatching("fabric.mod.json") { diff --git a/gradle.properties b/gradle.properties index 6d0dfeb..f462fab 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,6 +19,7 @@ cloth_version=6.1.48 modmenu_version=2.0.14 trinkets_version=3.0.4 requiem_version=2.0.0-alpha.12 +origins_version=1.1.4 smartrecipes_version=0.1.1+1.17 databreaker_version=0.2.7 crowdin_translate_version=1.3+1.17 \ No newline at end of file diff --git a/src/main/java/dev/kir/sync/compat/origins/OriginsCompat.java b/src/main/java/dev/kir/sync/compat/origins/OriginsCompat.java new file mode 100644 index 0000000..306a16f --- /dev/null +++ b/src/main/java/dev/kir/sync/compat/origins/OriginsCompat.java @@ -0,0 +1,15 @@ +package dev.kir.sync.compat.origins; + +import dev.kir.sync.api.shell.ShellStateComponentFactoryRegistry; +import dev.onyxstudios.cca.api.v3.entity.EntityComponentFactoryRegistry; +import dev.onyxstudios.cca.api.v3.entity.EntityComponentInitializer; +import net.fabricmc.loader.api.FabricLoader; + +public class OriginsCompat implements EntityComponentInitializer { + @Override + public void registerEntityComponentFactories(EntityComponentFactoryRegistry registry) { + if (FabricLoader.getInstance().isModLoaded("origins")) { + ShellStateComponentFactoryRegistry.getInstance().register(OriginsShellStateComponent::new, OriginsShellStateComponent::new); + } + } +} diff --git a/src/main/java/dev/kir/sync/compat/origins/OriginsShellStateComponent.java b/src/main/java/dev/kir/sync/compat/origins/OriginsShellStateComponent.java new file mode 100644 index 0000000..4fe32f3 --- /dev/null +++ b/src/main/java/dev/kir/sync/compat/origins/OriginsShellStateComponent.java @@ -0,0 +1,113 @@ +package dev.kir.sync.compat.origins; + +import dev.kir.sync.api.shell.ShellStateComponent; +import io.github.apace100.apoli.component.PowerHolderComponent; +import io.github.apace100.origins.component.OriginComponent; +import io.github.apace100.origins.networking.ModPackets; +import io.github.apace100.origins.origin.Origin; +import io.github.apace100.origins.origin.OriginLayer; +import io.github.apace100.origins.origin.OriginLayers; +import io.github.apace100.origins.registry.ModComponents; +import io.netty.buffer.Unpooled; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.NbtElement; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.server.network.ServerPlayerEntity; + +class OriginsShellStateComponent extends ShellStateComponent { + private final ServerPlayerEntity player; + private boolean activated; + private NbtCompound originComponentNbt; + private NbtCompound powerHolderComponentNbt; + + public OriginsShellStateComponent() { + this(null, false); + } + + public OriginsShellStateComponent(ServerPlayerEntity player) { + this(player, true); + } + + private OriginsShellStateComponent(ServerPlayerEntity player, boolean activated) { + this.player = player; + this.activated = activated; + } + + @Override + public String getId() { + return "origins"; + } + + public boolean isActivated() { + return this.activated; + } + + public NbtCompound getOriginComponentNbt() { + NbtCompound nbt = this.originComponentNbt; + if (this.player != null) { + nbt = new NbtCompound(); + ModComponents.ORIGIN.get(this.player).writeToNbt(nbt); + } + return nbt == null ? new NbtCompound() : nbt; + } + + public NbtCompound getPowerHolderComponentNbt() { + NbtCompound nbt = this.powerHolderComponentNbt; + if (this.player != null) { + nbt = new NbtCompound(); + PowerHolderComponent.KEY.get(this.player).writeToNbt(nbt); + } + return nbt == null ? new NbtCompound() : nbt; + } + + @Override + public void clone(ShellStateComponent component) { + OriginsShellStateComponent other = component.as(OriginsShellStateComponent.class); + if (other == null) { + return; + } + + this.originComponentNbt = other.getOriginComponentNbt(); + this.powerHolderComponentNbt = other.getPowerHolderComponentNbt(); + this.activated = other.isActivated(); + if (this.player == null) { + return; + } + + OriginComponent originComponent = ModComponents.ORIGIN.get(this.player); + if (this.activated) { + originComponent.readFromNbt(this.originComponentNbt); + PowerHolderComponent powerHolderComponent = PowerHolderComponent.KEY.get(this.player); + powerHolderComponent.readFromNbt(this.powerHolderComponentNbt); + originComponent.sync(); + } else { + for (OriginLayer layer : OriginLayers.getLayers()) { + if(layer.isEnabled()) { + originComponent.setOrigin(layer, Origin.EMPTY); + } + } + originComponent.checkAutoChoosingLayers(this.player, false); + originComponent.sync(); + PacketByteBuf data = new PacketByteBuf(Unpooled.buffer()); + data.writeBoolean(false); + ServerPlayNetworking.send(this.player, ModPackets.OPEN_ORIGIN_SCREEN, data); + this.activated = true; + } + } + + @Override + protected void readComponentNbt(NbtCompound nbt) { + this.originComponentNbt = nbt.contains("origins", NbtElement.COMPOUND_TYPE) ? nbt.getCompound("origins") : new NbtCompound(); + this.powerHolderComponentNbt = nbt.contains("powers", NbtElement.COMPOUND_TYPE) ? nbt.getCompound("powers") : new NbtCompound(); + this.activated = nbt.getBoolean("activated"); + } + + @Override + protected NbtCompound writeComponentNbt(NbtCompound nbt) { + nbt.put("origins", this.getOriginComponentNbt()); + nbt.put("powers", this.getPowerHolderComponentNbt()); + nbt.putBoolean("activated", this.isActivated()); + return nbt; + } +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index b346854..d578045 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -27,6 +27,7 @@ "dev.kir.sync.compat.modmenu.ModMenuCompat" ], "cardinal-components-entity": [ + "dev.kir.sync.compat.origins.OriginsCompat", "dev.kir.sync.compat.trinkets.TrinketsCompat" ] }, @@ -55,6 +56,7 @@ "suggests": { "modmenu": "${modmenu}", "trinkets": "${trinkets}", + "origins": "${origins}", "requiem": "${requiem}" } } From bc8378791b3749b60ce36d57214af85ba5a0f461 Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Sun, 26 Dec 2021 16:53:32 +0300 Subject: [PATCH 5/5] Bump version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index f462fab..8caca09 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ yarn_mappings=1.17.1+build.61 loader_version=0.11.3 # Mod Properties -mod_version=3.0 +mod_version=3.1 maven_group=dev.kir archives_base_name=sync