Skip to content

Commit

Permalink
Port?
Browse files Browse the repository at this point in the history
  • Loading branch information
Faboslav committed Oct 12, 2023
1 parent dbec69f commit 57816b9
Show file tree
Hide file tree
Showing 44 changed files with 256 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer;
import net.minecraft.predicate.entity.AdvancementEntityPredicateSerializer;
import net.minecraft.predicate.entity.EntityPredicate;
import net.minecraft.predicate.entity.LootContextPredicate;
import net.minecraft.predicate.entity.EntityPredicate.Extended;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;

Expand All @@ -26,10 +26,10 @@ public Identifier getId() {

public CompleteHideAndSeekGameCriterion.Conditions conditionsFromJson(
JsonObject jsonObject,
LootContextPredicate extended,
Extended extended,
AdvancementEntityPredicateDeserializer advancementEntityPredicateDeserializer
) {
LootContextPredicate extended2 = EntityPredicate.contextPredicateFromJson(jsonObject, "rascal", advancementEntityPredicateDeserializer);
Extended extended2 = Extended.getInJson(jsonObject, "rascal", advancementEntityPredicateDeserializer);

return new CompleteHideAndSeekGameCriterion.Conditions(extended, extended2);
}
Expand All @@ -43,19 +43,19 @@ public void trigger(ServerPlayerEntity player, RascalEntity entity) {

public static class Conditions extends AbstractCriterionConditions
{
private final LootContextPredicate entity;
private final Extended entity;

public Conditions(LootContextPredicate player, LootContextPredicate entity) {
public Conditions(Extended player, Extended entity) {
super(CompleteHideAndSeekGameCriterion.ID, player);
this.entity = entity;
}

public static CompleteHideAndSeekGameCriterion.Conditions any() {
return new CompleteHideAndSeekGameCriterion.Conditions(LootContextPredicate.EMPTY, LootContextPredicate.EMPTY);
return new CompleteHideAndSeekGameCriterion.Conditions(Extended.EMPTY, Extended.EMPTY);
}

public static CompleteHideAndSeekGameCriterion.Conditions create(EntityPredicate entity) {
return new CompleteHideAndSeekGameCriterion.Conditions(LootContextPredicate.EMPTY, EntityPredicate.asLootContextPredicate(entity));
return new CompleteHideAndSeekGameCriterion.Conditions(Extended.EMPTY, Extended.ofLegacy(entity));
}

public boolean matches(LootContext entityContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void setAngles(
float rodPivotY = defaultRodPivotY + AnimationMath.absSin(animationProgress, 1.0F, 0.25F);
this.animateModelPartYPositionBasedOnProgress(copperGolem, this.rod, rodPivotY, AnimationMath.absSin(animationProgress));
} else {
this.animateModelPartYPositionBasedOnTicks(copperGolem, this.rod, defaultRodPivotY, 10);
animateModelPartYPositionBasedOnTicks(copperGolem, this.rod, defaultRodPivotY, 10);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ private void animateHead(
ModelPartAnimator.setYRotation(this.root, AnimationMath.sin(animationProgress, 0.05F));
} else {
float targetPivotY = glare.isSitting() ? 3.0F:0.0F;
this.animateModelPartYPositionBasedOnTicks(glare, this.root, targetPivotY, 10);
animateModelPartYPositionBasedOnTicks(glare, this.root, targetPivotY, 10);
}
}

private void animateEyes(T glare) {
Vec2f targetEyesPositionOffset = glare.getTargetEyesPositionOffset();

this.animateModelPartPositionBasedOnTicks(
animateModelPartPositionBasedOnTicks(
glare,
this.eyes,
this.eyes.pivotX + targetEyesPositionOffset.x,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ public void setAngles(
) {
float targetX = AnimationMath.toRadians(5) + AnimationMath.toRadians(-65) * AnimationMath.absSin(animationProgress, 1.0F, 0.35F);
float delta = AnimationMath.absSin(animationProgress);
this.animateModelPartXRotationBasedOnProgress(mauler, this.upperJaw, targetX, delta);
this.animateModelPartXRotationBasedOnTicks(mauler, this.lowerJaw, AnimationMath.toRadians(-5), 10);
animateModelPartXRotationBasedOnProgress(mauler, this.upperJaw, targetX, delta);
animateModelPartXRotationBasedOnTicks(mauler, this.lowerJaw, AnimationMath.toRadians(-5), 10);
} else {
this.animateModelPartXRotationBasedOnTicks(mauler, this.upperJaw, 0.0F, 10);
this.animateModelPartXRotationBasedOnTicks(mauler, this.lowerJaw, 0.0F, 10);
animateModelPartXRotationBasedOnTicks(mauler, this.upperJaw, 0.0F, 10);
animateModelPartXRotationBasedOnTicks(mauler, this.lowerJaw, 0.0F, 10);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private void updateTargetEyesPositionOffset() {
}

this.setTargetEyesPositionOffset(
-0.5F + this.getRandom().nextFloat() * (0.5F - -0.5F),
-0.5F + this.getRandom().nextFloat(),
-0.4F + this.getRandom().nextFloat() * (0.4F - -0.4F)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
import net.minecraft.nbt.NbtCompound;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.registry.tag.StructureTags;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundEvent;
import net.minecraft.tag.StructureTags;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.random.Random;
Expand Down Expand Up @@ -100,9 +100,7 @@ public static boolean canSpawn(
return false;
}

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

return false;
Expand Down Expand Up @@ -373,7 +371,7 @@ protected void playStepSound(
) {
if (
this.isHidden()
|| state.isLiquid()
|| state.getMaterial().isLiquid()
) {
return;
}
Expand All @@ -382,7 +380,7 @@ protected void playStepSound(
}

public boolean isHidden() {
return this.getBrain().getOptionalRegisteredMemory(MemoryModuleType.AVOID_TARGET).orElse(null) instanceof PlayerEntity;
return this.getBrain().getOptionalMemory(MemoryModuleType.AVOID_TARGET).orElse(null) instanceof PlayerEntity;
}

public int getCaughtCount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
import net.minecraft.nbt.NbtCompound;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.tag.BlockTags;
import net.minecraft.util.ActionResult;
import net.minecraft.util.DyeColor;
import net.minecraft.util.Hand;
Expand Down Expand Up @@ -292,7 +292,7 @@ protected void playStepSound(
) {
if (
this.isInSleepingPose()
|| state.isLiquid()
|| state.getMaterial().isLiquid()
) {
return;
}
Expand Down Expand Up @@ -707,7 +707,7 @@ public boolean damage(
if (
attacker == null
|| attacker instanceof LightningEntity
|| source == this.getDamageSources().sweetBerryBush()
|| source == DamageSource.SWEET_BERRY_BUSH
) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private static void addIdleActivities(Brain<RascalEntity> brain) {
brain.setTaskList(
Activity.IDLE,
ImmutableList.of(
Pair.of(0, RascalFindInteractionTargetTask.create(6)),
Pair.of(0, new RascalFindInteractionTargetTask(6)),
Pair.of(0, makeRandomWanderTask())
)
);
Expand All @@ -88,7 +88,7 @@ private static void addAvoidActivities(Brain<RascalEntity> brain) {
Activity.AVOID,
10,
ImmutableList.of(
GoToRememberedPositionTask.createEntityBased(MemoryModuleType.AVOID_TARGET, 1.0F, 32, true)
GoToRememberedPositionTask.toEntity(MemoryModuleType.AVOID_TARGET, 1.0F, 32, true)
),
MemoryModuleType.AVOID_TARGET
);
Expand All @@ -107,7 +107,7 @@ public static void updateActivities(RascalEntity rascal) {
private static RandomTask<RascalEntity> makeRandomWanderTask() {
return new RandomTask(
ImmutableList.of(
Pair.of(StrollTask.create(0.6F), 2),
Pair.of(new StrollTask(0.6F), 2),
Pair.of(new WaitTask(30, 60), 1)
)
);
Expand All @@ -119,7 +119,7 @@ public static void setNodCooldown(RascalEntity rascal) {
}

public static boolean shouldRunAway(RascalEntity rascal) {
return rascal.getBrain().getOptionalRegisteredMemory(FriendsAndFoesMemoryModuleTypes.RASCAL_NOD_COOLDOWN.get()).isPresent();
return rascal.getBrain().getOptionalMemory(FriendsAndFoesMemoryModuleTypes.RASCAL_NOD_COOLDOWN.get()).isPresent();
}

public static void onCooldown(RascalEntity rascal) {
Expand All @@ -131,7 +131,7 @@ public static void onCooldown(RascalEntity rascal) {
return;
}

LivingEntity nearestTarget = rascal.getBrain().getOptionalRegisteredMemory(MemoryModuleType.INTERACTION_TARGET).orElse(null);
LivingEntity nearestTarget = rascal.getBrain().getOptionalMemory(MemoryModuleType.INTERACTION_TARGET).orElse(null);

if (nearestTarget == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,62 @@
package com.faboslav.friendsandfoes.entity.ai.brain.task.rascal;

import com.google.common.collect.ImmutableMap;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.brain.EntityLookTarget;
import net.minecraft.entity.ai.brain.MemoryModuleType;
import net.minecraft.entity.ai.brain.*;
import net.minecraft.entity.ai.brain.task.Task;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.world.ServerWorld;

import java.util.Optional;
import java.util.function.Predicate;

public final class RascalFindInteractionTargetTask
public class RascalFindInteractionTargetTask extends Task<LivingEntity>
{
public static Task<LivingEntity> create(int maxDistance) {
int squaredMaxDistance = maxDistance * maxDistance;
return TaskTriggerer.task((context) -> {
return context.group(context.queryMemoryOptional(MemoryModuleType.LOOK_TARGET), context.queryMemoryAbsent(MemoryModuleType.INTERACTION_TARGET), context.queryMemoryValue(MemoryModuleType.VISIBLE_MOBS)).apply(context, (lookTarget, interactionTarget, visibleMobs) -> {
return (world, entity, time) -> {
Optional<LivingEntity> optional = context.getValue(visibleMobs).findFirst((target) -> {
return target.squaredDistanceTo(entity) <= (double) squaredMaxDistance && target instanceof PlayerEntity && !target.isSpectator() && !((PlayerEntity) target).isCreative();
});

if (optional.isEmpty()) {
return false;
} else {
LivingEntity livingEntity = optional.get();
interactionTarget.remember(livingEntity);
lookTarget.remember(new EntityLookTarget(livingEntity, true));
return true;
}
};
private final int maxSquaredDistance;
private final Predicate<LivingEntity> predicate;
private final Predicate<LivingEntity> shouldRunPredicate;

public RascalFindInteractionTargetTask(
int maxDistance,
Predicate<LivingEntity> shouldRunPredicate,
Predicate<LivingEntity> predicate
) {
super(ImmutableMap.of(MemoryModuleType.LOOK_TARGET, MemoryModuleState.REGISTERED, MemoryModuleType.INTERACTION_TARGET, MemoryModuleState.VALUE_ABSENT, MemoryModuleType.VISIBLE_MOBS, MemoryModuleState.VALUE_PRESENT));
this.maxSquaredDistance = maxDistance * maxDistance;
this.predicate = predicate;
this.shouldRunPredicate = shouldRunPredicate;
}

public RascalFindInteractionTargetTask(int maxDistance) {
this(maxDistance, (livingEntity) -> {
return true;
}, (livingEntity) -> {
return true;
});
}

public boolean shouldRun(ServerWorld world, LivingEntity entity) {
return this.shouldRunPredicate.test(entity) && this.getVisibleMobs(entity).anyMatch(this::test);
}

public void run(ServerWorld world, LivingEntity entity, long time) {
super.run(world, entity, time);
Brain<?> brain = entity.getBrain();
brain.getOptionalMemory(MemoryModuleType.VISIBLE_MOBS).flatMap((livingTargetCache) -> {
return livingTargetCache.findFirst((target) -> {
return target.squaredDistanceTo(entity) <= (double) this.maxSquaredDistance && target instanceof PlayerEntity && !target.isSpectator() && !((PlayerEntity) target).isCreative();
});
}).ifPresent((target) -> {
brain.remember(MemoryModuleType.INTERACTION_TARGET, target);
brain.remember(MemoryModuleType.LOOK_TARGET, new EntityLookTarget(target, true));
});
}
}

private boolean test(LivingEntity entity) {
return EntityType.PLAYER.equals(entity.getType()) && this.predicate.test(entity);
}

private LivingTargetCache getVisibleMobs(LivingEntity entity) {
return entity.getBrain().getOptionalMemory(MemoryModuleType.VISIBLE_MOBS).get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@
import net.minecraft.entity.ai.brain.MemoryModuleState;
import net.minecraft.entity.ai.brain.MemoryModuleType;
import net.minecraft.entity.ai.brain.task.LookTargetUtil;
import net.minecraft.entity.ai.brain.task.MultiTickTask;
import net.minecraft.entity.ai.brain.task.Task;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.loot.LootManager;
import net.minecraft.loot.LootTable;
import net.minecraft.loot.context.LootContextParameterSet;
import net.minecraft.loot.context.LootContext;
import net.minecraft.loot.context.LootContextParameters;
import net.minecraft.loot.context.LootContextTypes;
import net.minecraft.registry.tag.StructureTags;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.tag.StructureTags;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.gen.StructureAccessor;

public final class RascalWaitForPlayerTask extends MultiTickTask<RascalEntity>
public final class RascalWaitForPlayerTask extends Task<RascalEntity>
{
private final static int NOD_DURATION = 90;
public final static float NOD_RANGE = 4F;
Expand All @@ -54,10 +54,10 @@ protected boolean shouldRun(ServerWorld world, RascalEntity rascal) {
return false;
}

LivingEntity nearestTarget = rascal.getBrain().getOptionalRegisteredMemory(MemoryModuleType.NEAREST_VISIBLE_TARGETABLE_PLAYER).orElse(null);
LivingEntity nearestTarget = rascal.getBrain().getOptionalMemory(MemoryModuleType.NEAREST_VISIBLE_TARGETABLE_PLAYER).orElse(null);

if (nearestTarget == null) {
nearestTarget = rascal.getBrain().getOptionalRegisteredMemory(MemoryModuleType.INTERACTION_TARGET).orElse(null);
nearestTarget = rascal.getBrain().getOptionalMemory(MemoryModuleType.INTERACTION_TARGET).orElse(null);
}

if (
Expand Down Expand Up @@ -124,12 +124,12 @@ protected void keepRunning(ServerWorld world, RascalEntity rascal, long time) {
LootManager lootManager = world.getServer().getLootManager();

if (lootManager != null) {
LootTable rascalGoodItemsLootTable = lootManager.getLootTable(
LootTable rascalGoodItemsLootTable = lootManager.getTable(
FriendsAndFoes.makeID("rewards/rascal_good_reward")
);
LootContextParameterSet lootContextParameterSet = new LootContextParameterSet.Builder(world)
.add(LootContextParameters.ORIGIN, targetPos)
.add(LootContextParameters.THIS_ENTITY, this.nearestTarget)
LootContext lootContextParameterSet = new LootContext.Builder(world)
.parameter(LootContextParameters.ORIGIN, targetPos)
.parameter(LootContextParameters.THIS_ENTITY, this.nearestTarget)
.build(LootContextTypes.GIFT);
ObjectArrayList<ItemStack> rascalGoodRewards = rascalGoodItemsLootTable.generateLoot(lootContextParameterSet);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected boolean shouldRun(ServerWorld world, WildfireEntity wildfire) {
|| ((PlayerEntity) attackTarget).isCreative()
)
)
|| wildfire.getSummonedBlazesCount() == wildfire.MAXIMUM_SUMMONED_BLAZES_COUNT
|| wildfire.getSummonedBlazesCount() == WildfireEntity.MAXIMUM_SUMMONED_BLAZES_COUNT
) {
WildfireBrain.setSummonBlazeCooldown(wildfire);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public final class FriendsAndFoesItems
ILLUSIONER_SPAWN_EGG = RegistryHelper.registerItem("illusioner_spawn_egg", () -> new SpawnEggItem(EntityType.ILLUSIONER, 0x603E5C, 0x888E8E, new Item.Settings().maxCount(64).group(ItemGroup.MISC)));
MAULER_SPAWN_EGG = RegistryHelper.registerItem("mauler_spawn_egg", () -> new SpawnEggItem(FriendsAndFoesEntityTypes.MAULER.get(), 0x534F25, 0x817B39, new Item.Settings().maxCount(64).group(ItemGroup.MISC)));
MOOBLOOM_SPAWN_EGG = RegistryHelper.registerItem("moobloom_spawn_egg", () -> new SpawnEggItem(FriendsAndFoesEntityTypes.MOOBLOOM.get(), 0xF7EDC1, 0xFACA00, new Item.Settings().maxCount(64).group(ItemGroup.MISC)));
RASCAL_SPAWN_EGG = RegistryHelper.registerSpawnEggItem("rascal_spawn_egg", FriendsAndFoesEntityTypes.RASCAL, 0x05736A, 0x8A521C, new Item.Settings().maxCount(64));
RASCAL_SPAWN_EGG = RegistryHelper.registerItem("rascal_spawn_egg", () -> new SpawnEggItem(FriendsAndFoesEntityTypes.RASCAL.get(), 0x05736A, 0x8A521C, new Item.Settings().maxCount(64).group(ItemGroup.MISC)));
TUFF_GOLEM_SPAWN_EGG = RegistryHelper.registerItem("tuff_golem_spawn_egg", () -> new SpawnEggItem(FriendsAndFoesEntityTypes.TUFF_GOLEM.get(), 0xA0A297, 0x5D5D52, new Item.Settings().maxCount(64).group(ItemGroup.MISC)));
WILDFIRE_SPAWN_EGG = RegistryHelper.registerItem("wildfire_spawn_egg", () -> new SpawnEggItem(FriendsAndFoesEntityTypes.WILDFIRE.get(), 0x6C3100, 0xFFD528, new Item.Settings().maxCount(64).group(ItemGroup.MISC)));
BUTTERCUP = RegistryHelper.registerItem("buttercup", () -> new BlockItem(FriendsAndFoesBlocks.BUTTERCUP.get(), new Item.Settings().group(ItemGroup.DECORATIONS).maxCount(64)));
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 57816b9

Please sign in to comment.