Skip to content

Commit

Permalink
Fixed incompatibility with young mods
Browse files Browse the repository at this point in the history
  • Loading branch information
Faboslav committed Sep 9, 2022
1 parent 6ff9d4c commit 4416bf0
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 109 deletions.
6 changes: 3 additions & 3 deletions .github/versions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"1.19.2": "1.5.9",
"1.19.1": "1.5.9",
"1.19": "1.5.9",
"1.19.2": "1.5.10",
"1.19.1": "1.5.10",
"1.19": "1.5.10",
"1.18.2": "1.4.5",
"1.18.1": "1.2.5",
"1.18": "1.2.5"
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## mc1.19.2-1.5.10, September 09, 2022

- Fixed incompatibility with YOUNG mods

## mc1.19.2-1.5.9, August 30, 2022

- Fixed all spawning related issues (mob not spawning at all)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.faboslav.friendsandfoes.mixin.fabric;

import com.faboslav.friendsandfoes.FriendsAndFoes;
import com.faboslav.friendsandfoes.platform.CustomSpawnGroup;
import com.faboslav.friendsandfoes.platform.fabric.CustomSpawnGroupImpl;
import net.minecraft.entity.SpawnGroup;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.faboslav.friendsandfoes.mixin.fabric;

import com.faboslav.friendsandfoes.world.processor.StructureEntityProcessor;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnReason;
Expand Down Expand Up @@ -55,7 +56,7 @@ public final class StructureEntityProcessorMixin
target = "net/minecraft/structure/StructureTemplate.spawnEntities (Lnet/minecraft/world/ServerWorldAccess;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/BlockMirror;Lnet/minecraft/util/BlockRotation;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/BlockBox;Z)V"
)
)
private void processEntities(
private void friendsandfoes_processEntities(
ServerWorldAccess serverWorldAccess,
BlockPos structurePiecePos,
BlockPos structurePieceBottomCenterPos,
Expand All @@ -64,69 +65,71 @@ private void processEntities(
int flags,
CallbackInfoReturnable<Boolean> cir
) {
for (StructureEntityInfo entityInfo : processEntityInfos(
serverWorldAccess,
structurePiecePos,
structurePieceBottomCenterPos,
structurePlacementData,
this.entities
)) {
BlockPos blockPos = entityInfo.blockPos;

if (
structurePlacementData.getBoundingBox() != null
&& structurePlacementData.getBoundingBox().contains(blockPos) == false
) {
continue;
}

NbtCompound compoundTag = entityInfo.nbt.copy();
Vec3d vec3d = entityInfo.pos;

NbtList nbtList = new NbtList();
nbtList.add(NbtDouble.of(vec3d.getX()));
nbtList.add(NbtDouble.of(vec3d.getY()));
nbtList.add(NbtDouble.of(vec3d.getZ()));
compoundTag.put("Pos", nbtList);
compoundTag.remove("UUID");

getEntity(serverWorldAccess, compoundTag).ifPresent((entity) -> {
float f = entity.applyMirror(structurePlacementData.getMirror());
f += entity.getYaw() - entity.applyRotation(structurePlacementData.getRotation());
entity.refreshPositionAndAngles(
vec3d.getX(),
vec3d.getY(),
vec3d.getZ(),
f,
entity.getPitch()
);
if (structurePlacementData.shouldInitializeMobs() && entity instanceof MobEntity) {
((MobEntity) entity).initialize(
serverWorldAccess,
serverWorldAccess.getLocalDifficulty(
new BlockPos(vec3d)
),
SpawnReason.STRUCTURE,
null,
compoundTag
);
if (FabricLoader.getInstance().isModLoaded("yungsapi") == false) {
for (StructureEntityInfo entityInfo : processEntityInfos(
serverWorldAccess,
structurePiecePos,
structurePieceBottomCenterPos,
structurePlacementData,
this.entities
)) {
BlockPos blockPos = entityInfo.blockPos;

if (
structurePlacementData.getBoundingBox() != null
&& structurePlacementData.getBoundingBox().contains(blockPos) == false
) {
continue;
}

serverWorldAccess.spawnEntityAndPassengers(entity);
});
NbtCompound compoundTag = entityInfo.nbt.copy();
Vec3d vec3d = entityInfo.pos;

NbtList nbtList = new NbtList();
nbtList.add(NbtDouble.of(vec3d.getX()));
nbtList.add(NbtDouble.of(vec3d.getY()));
nbtList.add(NbtDouble.of(vec3d.getZ()));
compoundTag.put("Pos", nbtList);
compoundTag.remove("UUID");

getEntity(serverWorldAccess, compoundTag).ifPresent((entity) -> {
float f = entity.applyMirror(structurePlacementData.getMirror());
f += entity.getYaw() - entity.applyRotation(structurePlacementData.getRotation());
entity.refreshPositionAndAngles(
vec3d.getX(),
vec3d.getY(),
vec3d.getZ(),
f,
entity.getPitch()
);
if (structurePlacementData.shouldInitializeMobs() && entity instanceof MobEntity) {
((MobEntity) entity).initialize(
serverWorldAccess,
serverWorldAccess.getLocalDifficulty(
new BlockPos(vec3d)
),
SpawnReason.STRUCTURE,
null,
compoundTag
);
}

serverWorldAccess.spawnEntityAndPassengers(entity);
});
}
}
}

/**
* Cancel spawning entities.
* This behavior is recreated in {@link #processEntities}
* This behavior is recreated in {@link #friendsandfoes_processEntities}
*/
@Inject(
method = "spawnEntities",
at = @At(value = "HEAD"),
cancellable = true
)
private void cancelPlaceEntities(
private void friendsandfoes_cancelPlaceEntities(
ServerWorldAccess serverWorldAccess,
BlockPos structurePiecePos,
BlockMirror mirror,
Expand All @@ -136,7 +139,9 @@ private void cancelPlaceEntities(
boolean initializeMobs,
CallbackInfo ci
) {
ci.cancel();
if (FabricLoader.getInstance().isModLoaded("yungsapi") == false) {
ci.cancel();
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ org.gradle.configureondemand=false
# Mod
mod_name=Friends&Foes
mod_id=friendsandfoes
mod_version=1.5.9
mod_version=1.5.10
mod_author=Faboslav
mod_description=Adds all eliminated mobs from the minecraft mob votes along with the forgotten mobs like the Illusioner.
maven_group=com.faboslav.friendsandfoes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.faboslav.friendsandfoes.mixin.quilt;

import com.faboslav.friendsandfoes.FriendsAndFoes;
import com.faboslav.friendsandfoes.platform.CustomSpawnGroup;
import com.faboslav.friendsandfoes.platform.fabric.CustomSpawnGroupImpl;
import net.minecraft.entity.SpawnGroup;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.faboslav.friendsandfoes.mixin.quilt;

import com.faboslav.friendsandfoes.world.processor.StructureEntityProcessor;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnReason;
Expand Down Expand Up @@ -55,7 +56,7 @@ public final class StructureEntityProcessorMixin
target = "net/minecraft/structure/StructureTemplate.spawnEntities (Lnet/minecraft/world/ServerWorldAccess;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/BlockMirror;Lnet/minecraft/util/BlockRotation;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/BlockBox;Z)V"
)
)
private void processEntities(
private void friendsandfoes_processEntities(
ServerWorldAccess serverWorldAccess,
BlockPos structurePiecePos,
BlockPos structurePieceBottomCenterPos,
Expand All @@ -64,62 +65,64 @@ private void processEntities(
int flags,
CallbackInfoReturnable<Boolean> cir
) {
for (StructureEntityInfo entityInfo : processEntityInfos(
serverWorldAccess,
structurePiecePos,
structurePieceBottomCenterPos,
structurePlacementData,
this.entities
)) {
BlockPos blockPos = entityInfo.blockPos;

if (
structurePlacementData.getBoundingBox() != null
&& structurePlacementData.getBoundingBox().contains(blockPos) == false
) {
continue;
}

NbtCompound compoundTag = entityInfo.nbt.copy();
Vec3d vec3d = entityInfo.pos;

NbtList nbtList = new NbtList();
nbtList.add(NbtDouble.of(vec3d.getX()));
nbtList.add(NbtDouble.of(vec3d.getY()));
nbtList.add(NbtDouble.of(vec3d.getZ()));
compoundTag.put("Pos", nbtList);
compoundTag.remove("UUID");

getEntity(serverWorldAccess, compoundTag).ifPresent((entity) -> {
float f = entity.applyMirror(structurePlacementData.getMirror());
f += entity.getYaw() - entity.applyRotation(structurePlacementData.getRotation());
entity.refreshPositionAndAngles(
vec3d.getX(),
vec3d.getY(),
vec3d.getZ(),
f,
entity.getPitch()
);
if (structurePlacementData.shouldInitializeMobs() && entity instanceof MobEntity) {
((MobEntity) entity).initialize(
serverWorldAccess,
serverWorldAccess.getLocalDifficulty(
new BlockPos(vec3d)
),
SpawnReason.STRUCTURE,
null,
compoundTag
);
if (FabricLoader.getInstance().isModLoaded("yungsapi") == false) {
for (StructureEntityInfo entityInfo : processEntityInfos(
serverWorldAccess,
structurePiecePos,
structurePieceBottomCenterPos,
structurePlacementData,
this.entities
)) {
BlockPos blockPos = entityInfo.blockPos;

if (
structurePlacementData.getBoundingBox() != null
&& structurePlacementData.getBoundingBox().contains(blockPos) == false
) {
continue;
}

serverWorldAccess.spawnEntityAndPassengers(entity);
});
NbtCompound compoundTag = entityInfo.nbt.copy();
Vec3d vec3d = entityInfo.pos;

NbtList nbtList = new NbtList();
nbtList.add(NbtDouble.of(vec3d.getX()));
nbtList.add(NbtDouble.of(vec3d.getY()));
nbtList.add(NbtDouble.of(vec3d.getZ()));
compoundTag.put("Pos", nbtList);
compoundTag.remove("UUID");

getEntity(serverWorldAccess, compoundTag).ifPresent((entity) -> {
float f = entity.applyMirror(structurePlacementData.getMirror());
f += entity.getYaw() - entity.applyRotation(structurePlacementData.getRotation());
entity.refreshPositionAndAngles(
vec3d.getX(),
vec3d.getY(),
vec3d.getZ(),
f,
entity.getPitch()
);
if (structurePlacementData.shouldInitializeMobs() && entity instanceof MobEntity) {
((MobEntity) entity).initialize(
serverWorldAccess,
serverWorldAccess.getLocalDifficulty(
new BlockPos(vec3d)
),
SpawnReason.STRUCTURE,
null,
compoundTag
);
}

serverWorldAccess.spawnEntityAndPassengers(entity);
});
}
}
}

/**
* Cancel spawning entities.
* This behavior is recreated in {@link #processEntities}
* This behavior is recreated in {@link #friendsandfoes_processEntities}
*/
@Inject(
method = "spawnEntities",
Expand All @@ -136,7 +139,9 @@ private void cancelPlaceEntities(
boolean initializeMobs,
CallbackInfo ci
) {
ci.cancel();
if (FabricLoader.getInstance().isModLoaded("yungsapi") == false) {
ci.cancel();
}
}

/**
Expand Down

0 comments on commit 4416bf0

Please sign in to comment.