Skip to content

Commit

Permalink
Improve Movet
Browse files Browse the repository at this point in the history
  • Loading branch information
Killarexe committed Jul 19, 2024
1 parent cbf3751 commit 14f5703
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import net.killarexe.dimensional_expansion.DEMod;
import net.killarexe.dimensional_expansion.init.DEBlocks;
import net.killarexe.dimensional_expansion.init.DETags;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.HolderLookup.Provider;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.PackOutput;
import net.minecraft.data.tags.IntrinsicHolderTagsProvider;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.neoforged.neoforge.common.Tags;
import net.neoforged.neoforge.common.data.ExistingFileHelper;

Expand Down Expand Up @@ -174,5 +176,7 @@ protected void addTags(HolderLookup.Provider pProvider) {
DEBlocks.POTTED_PURPLEISH_CACTUS.get()
);
tag(BlockTags.DEAD_BUSH_MAY_PLACE_ON).add(DEBlocks.BLUE_SAND.get());
tag(DETags.SULFUR_STONE_ORE_REPLACEABLES).add(DEBlocks.SULFUR_STONE.get());
tag(DETags.END_STONE_ORE_REPLACEABLES).add(Blocks.END_STONE);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.killarexe.dimensional_expansion.common.entity;

import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.entity.EntityType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package net.killarexe.dimensional_expansion.common.entity;

import net.killarexe.dimensional_expansion.common.entity.goals.StealFoodGoal;
import net.killarexe.dimensional_expansion.common.entity.goals.TakeFoodGoal;
import net.killarexe.dimensional_expansion.init.DESoundEvents;
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.AgeableMob;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.ai.goal.FloatGoal;
Expand All @@ -23,16 +25,21 @@
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.ServerLevelAccessor;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class Mouvet extends Animal{

private static final EntityDataAccessor<ItemStack> CURRENT_ITEM = SynchedEntityData.defineId(Mouvet.class, EntityDataSerializers.ITEM_STACK);

public static final AttributeSupplier.Builder ATTRIBUTES = createMobAttributes()
.add(Attributes.MOVEMENT_SPEED, 0.75f)
.add(Attributes.JUMP_STRENGTH, 0.25f)
.add(Attributes.JUMP_STRENGTH, 0.5f)
.add(Attributes.MAX_HEALTH, 5.0f);

public Mouvet(EntityType<? extends Animal> pEntityType, Level pLevel) {
Expand All @@ -44,6 +51,7 @@ protected void registerGoals() {
this.goalSelector.addGoal(5, new RandomLookAroundGoal(this));
this.goalSelector.addGoal(4, new LookAtPlayerGoal(this, Mob.class, 10));
this.goalSelector.addGoal(3, new WaterAvoidingRandomStrollGoal(this, 1.0D));
this.goalSelector.addGoal(2, new TakeFoodGoal(this, 1.0F, 0.75F, 10));
this.goalSelector.addGoal(1, new PanicGoal(this, 1.075f));
this.goalSelector.addGoal(0, new FloatGoal(this));

Expand Down Expand Up @@ -94,6 +102,17 @@ protected void dropEquipment() {
super.dropEquipment();
}

@Override
public SpawnGroupData finalizeSpawn(ServerLevelAccessor pLevel, DifficultyInstance pDifficulty, MobSpawnType pSpawnType, @Nullable SpawnGroupData pSpawnGroupData) {
if (pLevel.getRandom().nextInt(500) <= 10) {
List<Item> foodItems = BuiltInRegistries.ITEM.stream().filter(item -> new ItemStack(item).get(DataComponents.FOOD) != null).toList();
if (!foodItems.isEmpty()) {
setCurrentItem(new ItemStack(foodItems.get(random.nextInt(foodItems.size() - 1))));
}
}
return super.finalizeSpawn(pLevel, pDifficulty, pSpawnType, pSpawnGroupData);
}

public ItemStack getCurrentItem() {
return entityData.get(CURRENT_ITEM);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package net.killarexe.dimensional_expansion.common.entity.goals;

import net.killarexe.dimensional_expansion.common.entity.Mouvet;
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.ai.goal.Goal;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.phys.AABB;

import java.util.List;
import java.util.Optional;

public class TakeFoodGoal extends Goal {

private final Mouvet mouvet;
private final float catchRange;
private final float moveSpeed;
private final int randomInterval;

private Optional<ItemEntity> targetItem;

public TakeFoodGoal(Mouvet mouvet, float catchRange, float moveSpeed, int randomInterval) {
this.mouvet = mouvet;
this.catchRange = catchRange;
this.randomInterval = randomInterval;
this.moveSpeed = moveSpeed;
this.targetItem = Optional.empty();
}

@Override
public boolean canUse() {
if (this.randomInterval > 0 && mouvet.getRandom().nextInt(this.randomInterval) != 0) {
return false;
}
findTarget();
return targetItem.filter(itemEntity -> itemEntity.getItem().get(DataComponents.FOOD) != null).isPresent() && !mouvet.getCurrentItem().isEmpty();
}

protected AABB getTargetSearchArea(double pTargetDistance) {
return mouvet.getBoundingBox().inflate(pTargetDistance, 4.0, pTargetDistance);
}

protected double getFollowDistance() {
return mouvet.getAttributeValue(Attributes.FOLLOW_RANGE);
}

protected void findTarget() {
List<ItemEntity> itemEntities = mouvet.level().getEntitiesOfClass(ItemEntity.class, this.getTargetSearchArea(getFollowDistance()), filter -> true);
if (itemEntities.isEmpty()){
targetItem = Optional.empty();
return;
}
targetItem = Optional.of(itemEntities.getFirst());
}

@Override
public void tick() {
if (mouvet.level().isClientSide) {
return;
}
if (targetItem.isPresent()) {
ItemEntity itemEntity = targetItem.get();
if(!(mouvet.position().distanceTo(itemEntity.position()) < catchRange)) {
mouvet.getNavigation().moveTo(itemEntity, moveSpeed);
return;
}
mouvet.setCurrentItem(itemEntity.getItem());
itemEntity.kill();
}
}

public void setTargetItem(ItemEntity entity) {
targetItem = Optional.ofNullable(entity);
}

@Override
public boolean canContinueToUse() {
return canUse();
}

@Override
public boolean requiresUpdateEveryTick() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@

public class DEBiomes {

public static final ResourceKey<Biome> PURPLEHEART_FOREST = registerBiome("purpleheart_forest", BiomeManager.BiomeType.WARM, 10, false);
public static final ResourceKey<Biome> BLUE_SAND_DESERT = registerBiome("blue_sand_desert", BiomeManager.BiomeType.DESERT, 10, false);
public static final ResourceKey<Biome> ORIGIN_DEADLAND = registerBiome("origin_deadland", BiomeManager.BiomeType.DESERT, 10, false);
public static final ResourceKey<Biome> ORIGIN_PLAINS = registerBiome("origin_plains", BiomeManager.BiomeType.WARM, 10, false);
public static final ResourceKey<Biome> PURPLEHEART_FOREST = registerBiome("purpleheart_forest", BiomeManager.BiomeType.WARM, 10);
public static final ResourceKey<Biome> BLUE_SAND_DESERT = registerBiome("blue_sand_desert", BiomeManager.BiomeType.DESERT, 10);
public static final ResourceKey<Biome> ORIGIN_DEADLAND = registerBiome("origin_deadland", BiomeManager.BiomeType.DESERT, 10);
public static final ResourceKey<Biome> ORIGIN_PLAINS = registerBiome("origin_plains", BiomeManager.BiomeType.WARM, 10);

private static ResourceKey<Biome> registerBiome(String name, BiomeManager.BiomeType type, int weight, boolean addToOverworld){
private static ResourceKey<Biome> registerBiome(String name, BiomeManager.BiomeType type, int weight){
ResourceKey<Biome> biome = ResourceKey.create(Registries.BIOME, DEMod.res(name));
BiomeManager.addBiome(type, new BiomeManager.BiomeEntry(biome, weight));
if(addToOverworld) {
BiomeManager.addAdditionalOverworldBiomes(biome);
}
return biome;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ private static void addItemsToCreativeTab(BuildCreativeModeTabContentsEvent even
}

public static void addItemsToCreativeTabs(BuildCreativeModeTabContentsEvent e) {
if(e.getTab() == MISC.get()) {
if (e.getTab() == MISC.get()) {
addItemsToCreativeTab(e, Tabs.MISC);
}else if(e.getTab() == BLOCKS.get()) {
} else if (e.getTab() == BLOCKS.get()) {
addItemsToCreativeTab(e, Tabs.BLOCKS);
}else if(e.getTab() == COMBAT.get()) {
} else if (e.getTab() == COMBAT.get()) {
addItemsToCreativeTab(e, Tabs.COMBAT);
}else if(e.getTab() == TOOLS.get()) {
} else if (e.getTab() == TOOLS.get()) {
addItemsToCreativeTab(e, Tabs.TOOLS);
}else if(e.getTab() == MOBS.get()) {
} else if (e.getTab() == MOBS.get()) {
addItemsToCreativeTab(e, Tabs.MOBS);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"sound": "dimensional_expansion:music.origin",
"min_delay": 12000,
"max_delay": 24000,
"replace_current_music": true
"replace_current_music": false
}
},
"spawners": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"sound": "dimensional_expansion:music.origin",
"min_delay": 12000,
"max_delay": 24000,
"replace_current_music": true
"replace_current_music": false
}
},
"spawners": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"sound": "dimensional_expansion:music.origin",
"min_delay": 12000,
"max_delay": 24000,
"replace_current_music": true
"replace_current_music": false
}
},
"spawners": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"sound": "dimensional_expansion:music.origin",
"min_delay": 12000,
"max_delay": 24000,
"replace_current_music": true
"replace_current_music": false
}
},
"spawners": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
"biomes": "#dimensional_expansion:has_structure/abandonned_portal",
"step": "surface_structures",
"spawn_overrides": {},
"terrain_adaptation": "beard_thin",
"start_pool": "dimensional_expansion:abandonned_portal",
"project_start_to_heightmap": "WORLD_SURFACE_WG",
"size": 6,
"start_height": {
"absolute": 0
},
"project_start_to_heightmap": "WORLD_SURFACE_WG",
"max_distance_from_center": 80,
"terrain_adaptation": "beard_thin",
"use_expansion_hack": false
"use_expansion_hack": false,
"liquid_settings": "apply_waterlogging"
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"type": "minecraft:jigsaw",
"biomes": "#dimensional_expansion:has_structure/origin_village_plains",
"max_distance_from_center": 80,
"project_start_to_heightmap": "WORLD_SURFACE_WG",
"size": 6,
"step": "surface_structures",
"spawn_overrides": {},
"terrain_adaptation": "beard_thin",
"start_pool": "dimensional_expansion:origin_village/origin_plains/town_centers",
"size": 6,
"start_height": {
"absolute": 0
},
"start_pool": "dimensional_expansion:origin_village/origin_plains/town_centers",
"step": "surface_structures",
"terrain_adaptation": "beard_thin",
"use_expansion_hack": true
}
"project_start_to_heightmap": "WORLD_SURFACE_WG",
"max_distance_from_center": 80,
"use_expansion_hack": true,
"liquid_settings": "apply_waterlogging"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"name": "dimensional_expansion:abandoned_portal",
"fallback": "minecraft:empty",
"elements": [
{
Expand All @@ -8,6 +7,7 @@
"element_type": "minecraft:single_pool_element",
"projection": "terrain_matching",
"location": "dimensional_expansion:abandonned_portal",
"override_liquid_settings": "apply_waterlogging",
"processors": "dimensional_expansion:abandonned_portal_degradation"
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
{
"fallback": "minecraft:empty",
"elements": [
{
"weight": 2,
"element": {
"element_type": "minecraft:legacy_single_pool_element",
"projection": "rigid",
"location": "dimensional_expansion:origin_village/origin_plains/plains_lamp_1",
"override_liquid_settings": "apply_waterlogging",
"processors": {
"processors": []
},
"projection": "rigid"
},
"weight": 2
}
}
},
{
"weight": 1,
"element": {
"element_type": "minecraft:feature_pool_element",
"feature": "dimensional_expansion:pile_savorleaf_placed",
"projection": "rigid"
},
"weight": 1
"projection": "rigid",
"feature": "dimensional_expansion:pile_savorleaf_placed"
}
},
{
"weight": 2,
"element": {
"element_type": "minecraft:empty_pool_element"
},
"weight": 2
}
}
],
"fallback": "minecraft:empty"
}
]
}

0 comments on commit 14f5703

Please sign in to comment.