Skip to content

Commit

Permalink
Merge branch '1.20.4'
Browse files Browse the repository at this point in the history
* 1.20.4:
  compat with curios
  supress warnings
  Better trigger logic
  removed unused variable
  1.19.4
  1.19.3
  2.0.10

# Conflicts:
#	common/src/main/resources/assets/friendsandfoes/lang/ko_kr.json
  • Loading branch information
Faboslav committed Mar 15, 2024
2 parents 44e3b72 + 50ecc12 commit 55d0a55
Show file tree
Hide file tree
Showing 44 changed files with 637 additions and 191 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## 2.0.10

- Fixed crash related to rascal spawns in mineshafts
- Added anger particles to rascal to indicate that hitting it is not an option
- Added missing charm slot for curios
- Added missing translations for BetterF3 mod
- Improved trigger logic for totems
- Improved compatibility with the curios mod and other totems
- Improved compatibility with the trinkets mod and other totems
- Improved catalogue compatibility
- Updated translations

## 2.0.9

- Fixed Glare follow logic when tamed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.faboslav.friendsandfoes.events.lifecycle.RegisterReloadListenerEvent;
import com.faboslav.friendsandfoes.events.lifecycle.SetupEvent;
import com.faboslav.friendsandfoes.init.*;
import com.faboslav.friendsandfoes.modcompat.ModChecker;
import com.faboslav.friendsandfoes.network.MessageHandler;
import com.faboslav.friendsandfoes.network.packet.MoobloomVariantsSyncPacket;
import com.faboslav.friendsandfoes.platform.BiomeModifications;
Expand Down Expand Up @@ -40,6 +41,8 @@ public static Logger getLogger() {
}

public static void init() {
ModChecker.setupModCompat();

FriendsAndFoesActivities.init();
FriendsAndFoesBlockSetTypes.init();
FriendsAndFoesBlocks.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RotationAxis;

@Environment(EnvType.CLIENT)
public class PlayerIllusionDeadmau5FeatureRenderer extends FeatureRenderer<PlayerIllusionEntity, PlayerIllusionEntityModel<PlayerIllusionEntity>>
@Environment(value = EnvType.CLIENT)
public final class PlayerIllusionDeadmau5FeatureRenderer extends FeatureRenderer<PlayerIllusionEntity, PlayerIllusionEntityModel<PlayerIllusionEntity>>
{
public PlayerIllusionDeadmau5FeatureRenderer(FeatureRendererContext<PlayerIllusionEntity, PlayerIllusionEntityModel<PlayerIllusionEntity>> arg) {
super(arg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.faboslav.friendsandfoes.client.render.entity.feature.PlayerIllusionHeldItemFeatureRenderer;
import com.faboslav.friendsandfoes.client.render.entity.model.PlayerIllusionEntityModel;
import com.faboslav.friendsandfoes.entity.PlayerIllusionEntity;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.model.ModelPart;
import net.minecraft.client.render.OverlayTexture;
import net.minecraft.client.render.RenderLayer;
Expand All @@ -30,6 +32,7 @@
import net.minecraft.util.math.RotationAxis;
import net.minecraft.util.math.Vec3d;

@Environment(value = EnvType.CLIENT)
public final class PlayerIllusionEntityRenderer extends MobEntityRenderer<PlayerIllusionEntity, PlayerIllusionEntityModel<PlayerIllusionEntity>>
{
public PlayerIllusionEntityRenderer(EntityRendererFactory.Context ctx, boolean slim) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,13 @@ private void setVariant(MoobloomVariant variant) {
}

public MoobloomVariant getVariant() {
return MoobloomVariantManager.MOOBLOOM_VARIANT_MANAGER.getMoobloomVariantByName(this.dataTracker.get(VARIANT));
MoobloomVariant moobloomVariant = MoobloomVariantManager.MOOBLOOM_VARIANT_MANAGER.getMoobloomVariantByName(this.dataTracker.get(VARIANT));

if (moobloomVariant == null) {
moobloomVariant = MoobloomVariantManager.MOOBLOOM_VARIANT_MANAGER.getDefaultMoobloomVariant();
}

return moobloomVariant;
}

static {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.faboslav.friendsandfoes.entity;

import com.faboslav.friendsandfoes.init.FriendsAndFoesSoundEvents;
import com.faboslav.friendsandfoes.util.client.PlayerProvider;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.client.render.entity.PlayerModelPart;
import net.minecraft.client.util.DefaultSkinHelper;
Expand Down Expand Up @@ -113,10 +115,12 @@ public boolean damage(
return true;
}

@Environment(EnvType.CLIENT)
public boolean isPartVisible(PlayerModelPart modelPart) {
return (this.getDataTracker().get(PLAYER_MODEL_PARTS) & modelPart.getBitFlag()) == modelPart.getBitFlag();
}

@Environment(EnvType.CLIENT)
public SkinTextures getSkinTextures() {
PlayerListEntry playerListEntry = this.getPlayerListEntry();

Expand All @@ -133,10 +137,12 @@ public SkinTextures getSkinTextures() {
return DefaultSkinHelper.getSkinTextures(uuid);
}

@Environment(EnvType.CLIENT)
public Vec3d lerpVelocity(float tickDelta) {
return Vec3d.ZERO.lerp(this.getVelocity(), tickDelta);
}

@Environment(EnvType.CLIENT)
@Nullable
private PlayerListEntry getPlayerListEntry() {
if (this.playerListEntry == null) {
Expand All @@ -146,7 +152,7 @@ private PlayerListEntry getPlayerListEntry() {
uuid = this.getUuid();
}

this.playerListEntry = PlayerProvider.getClientPlayerListEntry(uuid);
this.playerListEntry = MinecraftClient.getInstance().getNetworkHandler().getPlayerListEntry(uuid);
}

return this.playerListEntry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,22 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.tag.StructureTags;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.LocalDifficulty;
import net.minecraft.world.ServerWorldAccess;
import net.minecraft.world.World;
import net.minecraft.world.gen.StructureAccessor;
import net.minecraft.world.gen.structure.Structure;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

public final class RascalEntity extends PassiveEntity implements AnimatedEntity
{
Expand Down Expand Up @@ -86,27 +88,26 @@ public static boolean canSpawn(
) {
if (spawnReason == SpawnReason.NATURAL) {
ServerWorld serverWorld = serverWorldAccess.toServerWorld();
Registry<Structure> structureRegistry = serverWorldAccess.getRegistryManager().get(RegistryKeys.STRUCTURE);
StructureAccessor structureAccessor = serverWorld.getStructureAccessor();

if (structureAccessor.getStructureContaining(
blockPos,
StructureTags.MINESHAFT
).hasChildren() == false) {
if (
blockPos.getY() > 63
|| serverWorldAccess.isSkyVisible(blockPos)
) {
return false;
}

List<LivingEntity> nearbyRascals = serverWorld.getEntitiesByClass(LivingEntity.class, new Box(blockPos).expand(32.0F), (livingEntity) -> {
return livingEntity instanceof RascalEntity || livingEntity instanceof PlayerEntity;
});

if (nearbyRascals.isEmpty() == false) {
return false;
for (RegistryEntry<Structure> structure : structureRegistry.getOrCreateEntryList(StructureTags.MINESHAFT)) {
if (structureAccessor.getStructureAt(blockPos, structure.value()).hasChildren()) {
return true;
}
}

return blockPos.getY() < 63 && serverWorldAccess.isSkyVisible(blockPos) == false;
return false;
}

return false;
return true;
}

@Override
Expand Down Expand Up @@ -305,6 +306,7 @@ public boolean damage(
this.playHurtSound(source);
this.playDisappearSound();
this.spawnCloudParticles();
this.spawnAngerParticles();
this.discard();

return false;
Expand Down Expand Up @@ -425,6 +427,10 @@ public void spawnCloudParticles() {
ParticleSpawner.spawnParticles(this, ParticleTypes.CLOUD, 16, 0.1D);
}

public void spawnAngerParticles() {
ParticleSpawner.spawnParticles(this, ParticleTypes.ANGRY_VILLAGER, 16, 0.1D);
}

static {
POSE_TICKS = DataTracker.registerData(RascalEntity.class, TrackedDataHandlerRegistry.INTEGER);
CAUGHT_COUNT = DataTracker.registerData(RascalEntity.class, TrackedDataHandlerRegistry.INTEGER);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.faboslav.friendsandfoes.events.lifecycle;

import com.faboslav.friendsandfoes.events.base.EventHandler;

import java.util.function.Consumer;

/**
* Event related is code based on The Bumblezone/Resourceful Lib mods with permissions from the authors
*
* @author TelepathicGrunt
* <a href="https://github.com/TelepathicGrunt/Bumblezone">https://github.com/TelepathicGrunt/Bumblezone</a>
* @author ThatGravyBoat
* <a href="https://github.com/Team-Resourceful/ResourcefulLib">https://github.com/Team-Resourceful/ResourcefulLib</a>
*/
public record ClientSetupEvent(Consumer<Runnable> enqueue)
{

public static final EventHandler<ClientSetupEvent> EVENT = new EventHandler<>();

public void enqueueWork(Runnable runnable) {
enqueue.accept(runnable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import com.faboslav.friendsandfoes.init.FriendsAndFoesEntityTypes;
import com.faboslav.friendsandfoes.init.FriendsAndFoesItems;
import com.faboslav.friendsandfoes.init.FriendsAndFoesSoundEvents;
import com.faboslav.friendsandfoes.modcompat.ModChecker;
import com.faboslav.friendsandfoes.modcompat.ModCompat;
import com.faboslav.friendsandfoes.network.packet.TotemEffectPacket;
import com.faboslav.friendsandfoes.platform.TotemHelper;
import com.faboslav.friendsandfoes.tag.FriendsAndFoesTags;
import net.minecraft.advancement.criterion.Criteria;
import net.minecraft.entity.Entity;
Expand All @@ -14,10 +15,12 @@
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.TargetPredicate;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.damage.DamageTypes;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.particle.DefaultParticleType;
import net.minecraft.particle.ParticleTypes;
Expand All @@ -38,7 +41,9 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;

@Mixin(PlayerEntity.class)
Expand Down Expand Up @@ -105,28 +110,27 @@ private void friendsandfoes_updateWildfireCrown() {
}

@Inject(
at = @At("HEAD"),
at = @At("TAIL"),
method = "damage",
cancellable = true
)
public void friendsandfoes_tryUseTotems(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) {
if (this.getHealth() <= this.getMaxHealth() / 2.0F) {
PlayerEntityMixin entity = this;

ItemStack offhandItemStack = entity.getStackInHand(Hand.OFF_HAND);
ItemStack mainhandItemStack = entity.getStackInHand(Hand.MAIN_HAND);
ItemStack moddedSlotItemStack = TotemHelper.getTotemFromModdedSlots(((PlayerEntity) (Object) entity), PlayerEntityMixin::isTotem);

@Nullable
ItemStack totemItemStack = null;

if (isTotem(mainhandItemStack)) {
totemItemStack = mainhandItemStack;
} else if (isTotem(offhandItemStack)) {
totemItemStack = offhandItemStack;
} else if (moddedSlotItemStack != null) {
totemItemStack = moddedSlotItemStack;
}
PlayerEntityMixin entity = this;
PlayerEntity player = (PlayerEntity) (Object) this;

if (
player.isAlive()
&& source.isOf(DamageTypes.IN_FIRE) == false
&& source.isOf(DamageTypes.ON_FIRE) == false
&& source.isOf(DamageTypes.FALL) == false
&& source.isOf(DamageTypes.FALLING_BLOCK) == false
&& source.getAttacker() != null
&& this.getHealth() <= this.getMaxHealth() / 2.0F
) {
ItemStack totemItemStack = friendsandfoes_getTotem(
friendsandfoes_getTotemFromHands(player),
friendsandfoes_getTotemFromCustomEquipmentSlots(player)
);

if (totemItemStack != null) {
if ((Object) this instanceof ServerPlayerEntity) {
Expand All @@ -141,24 +145,55 @@ public void friendsandfoes_tryUseTotems(DamageSource source, float amount, Callb
Criteria.USED_TOTEM.trigger(serverPlayerEntity, totemItemStack);
}

Item totemItem = totemItemStack.getItem();
this.clearStatusEffects();
TotemEffectPacket.sendToClient(((PlayerEntity) (Object) entity), totemItemStack);
totemItemStack.decrement(1);

if (totemItemStack.getItem() == FriendsAndFoesItems.TOTEM_OF_FREEZING.get()) {
if (totemItem == FriendsAndFoesItems.TOTEM_OF_FREEZING.get()) {
this.friendsandfoes_freezeEntities();
this.addStatusEffect(new StatusEffectInstance(StatusEffects.SPEED, POSITIVE_EFFECT_TICKS, 1));
} else if (totemItemStack.getItem() == FriendsAndFoesItems.TOTEM_OF_ILLUSION.get()) {
} else if (totemItem == FriendsAndFoesItems.TOTEM_OF_ILLUSION.get()) {
this.friendsandfoes_createIllusions();
}

TotemEffectPacket.sendToClient(((PlayerEntity) (Object) entity), totemItemStack);
totemItemStack.decrement(1);

cir.setReturnValue(true);
}
}
}

private static boolean isTotem(ItemStack itemStack) {
@Nullable
private static ItemStack friendsandfoes_getTotem(ItemStack... itemStacks) {
return Arrays.stream(itemStacks).filter(Objects::nonNull).toList().stream().findFirst().orElse(null);
}

@Nullable
private static ItemStack friendsandfoes_getTotemFromHands(PlayerEntity player) {
for (Hand hand : Hand.values()) {
ItemStack itemStack = player.getStackInHand(hand);

if (friendsandfoes_isTotem(itemStack)) {
return itemStack;
}
}

return null;
}

@Nullable
private static ItemStack friendsandfoes_getTotemFromCustomEquipmentSlots(PlayerEntity player) {
for (ModCompat compat : ModChecker.CUSTOM_EQUIPMENT_SLOTS_COMPATS) {
ItemStack itemStack = compat.getEquippedItemFromCustomSlots(player, PlayerEntityMixin::friendsandfoes_isTotem);

if (itemStack != null) {
return itemStack;
}
}

return null;
}

private static boolean friendsandfoes_isTotem(ItemStack itemStack) {
return itemStack.isIn(FriendsAndFoesTags.TOTEMS);
}

Expand Down
Loading

0 comments on commit 55d0a55

Please sign in to comment.