Skip to content

Commit

Permalink
Fixed subtitles, fixed rascal tasks, improved rascal loot tables
Browse files Browse the repository at this point in the history
  • Loading branch information
Faboslav committed Oct 11, 2023
1 parent fcb2eef commit cae4bf8
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 66 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.faboslav.friendsandfoes.entity.ai.brain;

import com.faboslav.friendsandfoes.entity.RascalEntity;
import com.faboslav.friendsandfoes.entity.ai.brain.task.rascal.RascalFindInteractionTargetTask;
import com.faboslav.friendsandfoes.entity.ai.brain.task.rascal.RascalWaitForPlayerTask;
import com.faboslav.friendsandfoes.init.FriendsAndFoesActivities;
import com.faboslav.friendsandfoes.init.FriendsAndFoesMemoryModuleTypes;
Expand Down Expand Up @@ -64,7 +65,7 @@ private static void addIdleActivities(Brain<RascalEntity> brain) {
brain.setTaskList(
Activity.IDLE,
ImmutableList.of(
Pair.of(0, FindInteractionTargetTask.create(EntityType.PLAYER, 8)),
Pair.of(0, RascalFindInteractionTargetTask.create(8)),
Pair.of(0, makeRandomWanderTask())
)
);
Expand Down Expand Up @@ -161,7 +162,9 @@ private static void runAwayFrom(RascalEntity rascal, LivingEntity target) {
MemoryModuleType.CANT_REACH_WALK_TARGET_SINCE,
FriendsAndFoesMemoryModuleTypes.RASCAL_NOD_COOLDOWN.get()
);
NOD_COOLDOWN_PROVIDER = TimeHelper.betweenSeconds(25, 30);
AVOID_MEMORY_DURATION = TimeHelper.betweenSeconds(20, 30);
//NOD_COOLDOWN_PROVIDER = TimeHelper.betweenSeconds(25, 30);
NOD_COOLDOWN_PROVIDER = TimeHelper.betweenSeconds(10, 11);
//AVOID_MEMORY_DURATION = TimeHelper.betweenSeconds(20, 30);
AVOID_MEMORY_DURATION = TimeHelper.betweenSeconds(5, 10);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.faboslav.friendsandfoes.entity.ai.brain.task.rascal;

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.task.Task;
import net.minecraft.entity.ai.brain.task.TaskTriggerer;
import net.minecraft.entity.player.PlayerEntity;

import java.util.Optional;

public final class RascalFindInteractionTargetTask
{
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;
}
};
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.faboslav.friendsandfoes.entity.pose.RascalEntityPose;
import com.faboslav.friendsandfoes.init.FriendsAndFoesCriteria;
import com.faboslav.friendsandfoes.init.FriendsAndFoesMemoryModuleTypes;
import com.faboslav.friendsandfoes.mixin.BundleItemAccessor;
import com.google.common.collect.ImmutableMap;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.minecraft.entity.LivingEntity;
Expand All @@ -14,7 +15,9 @@
import net.minecraft.entity.ai.brain.task.LookTargetUtil;
import net.minecraft.entity.ai.brain.task.MultiTickTask;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BundleItem;
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;
Expand All @@ -35,7 +38,7 @@ public final class RascalWaitForPlayerTask extends MultiTickTask<RascalEntity>
public RascalWaitForPlayerTask() {
super(ImmutableMap.of(
MemoryModuleType.NEAREST_VISIBLE_TARGETABLE_PLAYER, MemoryModuleState.REGISTERED,
MemoryModuleType.NEAREST_PLAYERS, MemoryModuleState.REGISTERED,
MemoryModuleType.INTERACTION_TARGET, MemoryModuleState.VALUE_PRESENT,
FriendsAndFoesMemoryModuleTypes.RASCAL_NOD_COOLDOWN.get(), MemoryModuleState.VALUE_ABSENT
), NOD_DURATION);
}
Expand Down Expand Up @@ -126,7 +129,9 @@ protected void keepRunning(ServerWorld world, RascalEntity rascal, long time) {
ObjectArrayList<ItemStack> rascalGoodRewards = rascalGoodItemsLootTable.generateLoot(lootContextParameterSet);

for (ItemStack rascalReward : rascalGoodRewards) {
LookTargetUtil.give(rascal, rascalReward, nearestTarget.getPos().add(0.0, 1.0, 0.0));
ItemStack bundleItemStack = Items.BUNDLE.getDefaultStack();
((BundleItemAccessor)bundleItemStack.getItem()).invokeAddToBundle(bundleItemStack, rascalReward);
LookTargetUtil.give(rascal, bundleItemStack, nearestTarget.getPos().add(0.0, 1.0, 0.0));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.faboslav.friendsandfoes.mixin;

import net.minecraft.item.BundleItem;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(BundleItem.class)
public interface BundleItemAccessor
{
@Invoker("addToBundle")
int invokeAddToBundle(
ItemStack bundle,
ItemStack stack
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
"friendsandfoes:entity/player/mirror_move1",
"friendsandfoes:entity/player/mirror_move2"
],
"subtitle": "subtitle.entity.friendsandfoes.moobloom.convert"
"subtitle": "subtitle.entity.friendsandfoes.player.mirror_move"
},
"entity.rascal.ambient": {
"sounds": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"rolls": 1,
"entries": [
{
"weight": 3,
"weight": 1,
"type": "minecraft:item",
"name": "minecraft:iron_pickaxe",
"functions": [
Expand All @@ -18,11 +18,6 @@
}
}
]
},
{
"weight": 1,
"type": "minecraft:item",
"name": "minecraft:bundle"
}
]
}
Expand Down
109 changes: 55 additions & 54 deletions common/src/main/resources/friendsandfoes-common.mixins.json
Original file line number Diff line number Diff line change
@@ -1,57 +1,58 @@
{
"required": true,
"package": "com.faboslav.friendsandfoes.mixin",
"compatibilityLevel": "JAVA_17",
"minVersion": "0.8",
"injectors": {
"defaultRequire": 1
},
"mixins": [
"AddCustomEntityPoseMixin",
"AxeItemMixin",
"BeeEntityAccessor",
"BeeEntityMixin",
"BeeEntityMoveToFlowerGoalMixin",
"BeeEntityMoveToHiveGoalMixin",
"BlazeEntityMixin",
"BlazeLivingEntityMixin",
"BlindTargetGoalFactory",
"CarvedPumpkinBlockMixin",
"ChickenEntityMixin",
"HoneycombItemMixin",
"IllusionerEntityMixin",
"IllusionerHostileEntityMixin",
"IllusionerRaiderEntityMixin",
"IllusionerSpellcastingIllagerEntityMixin",
"LightningEntityMixin",
"LightningRodBlockDegradableMixin",
"LightningRodBlockMixin",
"LimbAnimatorAccessor",
"PatrolSpawnerAccessor",
"PatrolSpawnerMixin",
"PlayerEntityMixin",
"PointOfInterestTypesMixin",
"RabbitEntityMixin",
"RaidMemberMixin",
"RaidMixin",
"ServerWorldAccessor",
"ServerWorldMixin",
"SnowballEntityMixin",
"SpawnRestrictionAccessor",
"StrongholdGeneratorMixin",
"StructurePoolAccessor",
"TemptGoalMixin",
"VillagerEntityMixin",
"VillagerHostilesSensorMixin",
"VillagerTaskListProviderMixin",
"ZombieHorseAbstractHorseEntityMixin",
"ZombieHorseAnimalEntityMixin",
"ZombieHorseEntityMixin"
],
"client": [
"ClientPlayNetworkHandlerMixin",
"EntityRenderDispatcherMixin",
"IllusionerEntityRendererMixin",
"ModelPartAccessor"
"required": true,
"package": "com.faboslav.friendsandfoes.mixin",
"compatibilityLevel": "JAVA_17",
"minVersion": "0.8",
"injectors": {
"defaultRequire": 1
},
"mixins": [
"AddCustomEntityPoseMixin",
"AxeItemMixin",
"BeeEntityAccessor",
"BeeEntityMixin",
"BeeEntityMoveToFlowerGoalMixin",
"BeeEntityMoveToHiveGoalMixin",
"BlazeEntityMixin",
"BlazeLivingEntityMixin",
"BlindTargetGoalFactory",
"BundleItemAccessor",
"CarvedPumpkinBlockMixin",
"ChickenEntityMixin",
"HoneycombItemMixin",
"IllusionerEntityMixin",
"IllusionerHostileEntityMixin",
"IllusionerRaiderEntityMixin",
"IllusionerSpellcastingIllagerEntityMixin",
"LightningEntityMixin",
"LightningRodBlockDegradableMixin",
"LightningRodBlockMixin",
"LimbAnimatorAccessor",
"PatrolSpawnerAccessor",
"PatrolSpawnerMixin",
"PlayerEntityMixin",
"PointOfInterestTypesMixin",
"RabbitEntityMixin",
"RaidMemberMixin",
"RaidMixin",
"ServerWorldAccessor",
"ServerWorldMixin",
"SnowballEntityMixin",
"SpawnRestrictionAccessor",
"StrongholdGeneratorMixin",
"StructurePoolAccessor",
"TemptGoalMixin",
"VillagerEntityMixin",
"VillagerHostilesSensorMixin",
"VillagerTaskListProviderMixin",
"ZombieHorseAbstractHorseEntityMixin",
"ZombieHorseAnimalEntityMixin",
"ZombieHorseEntityMixin"
],
"client": [
"ClientPlayNetworkHandlerMixin",
"EntityRenderDispatcherMixin",
"IllusionerEntityRendererMixin",
"ModelPartAccessor"
]
}

0 comments on commit cae4bf8

Please sign in to comment.