Skip to content

Commit

Permalink
Merge branch '1.17.x/stable' into '1.18.x/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Kir-Antipov committed Dec 26, 2021
2 parents 3580bfd + bc83787 commit ed60022
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 10 deletions.
23 changes: 22 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,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
Expand All @@ -85,6 +104,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}"
}

processResources {
Expand All @@ -98,7 +118,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") {
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ yarn_mappings=1.18+build.1
loader_version=0.12.0

# Mod Properties
mod_version=3.0
mod_version=3.1
maven_group=dev.kir
archives_base_name=sync

Expand All @@ -19,5 +19,6 @@ cloth_version=6.1.48
modmenu_version=3.0.1
trinkets_version=3.1.0
requiem_version=2.0.0-beta.3
origins_version=1.1.4
smartrecipes_version=0.2.0+1.18
crowdin_translate_version=1.4+1.18
13 changes: 10 additions & 3 deletions src/main/java/dev/kir/sync/block/AbstractShellContainerBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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))) {
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/dev/kir/sync/compat/origins/OriginsCompat.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
11 changes: 6 additions & 5 deletions src/main/java/dev/kir/sync/mixin/ClientPlayerEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ public void apply(ShellState state) {
return;
}

this.stopRiding();
this.dropShoulderEntities();
this.extinguish();
this.setFrozenTicks(0);
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
Expand Down Expand Up @@ -55,6 +56,7 @@
"suggests": {
"modmenu": "${modmenu}",
"trinkets": "${trinkets}",
"origins": "${origins}",
"requiem": "${requiem}"
}
}

0 comments on commit ed60022

Please sign in to comment.