Skip to content

Commit

Permalink
Address Issue starfish-studios#23 , add Diet integration, comment out…
Browse files Browse the repository at this point in the history
… Boar finder
  • Loading branch information
KedisPL committed Jan 15, 2025
1 parent 6ef666e commit d24fa25
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.starfish_studios.naturalist.common.entity.core.ai.navigation;


import net.minecraft.core.BlockPos;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
Expand All @@ -11,6 +10,7 @@
import net.minecraft.world.level.pathfinder.Path;
import net.minecraft.world.level.pathfinder.PathFinder;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -33,7 +33,7 @@ public PatchedPath(Path original) {
}

@Override
public Vec3 getEntityPosAtNode(Entity entity, int index) {
public @NotNull Vec3 getEntityPosAtNode(Entity entity, int index) {
Node point = this.getNode(index);
double d0 = point.x + Mth.floor(entity.getBbWidth() + 1.0F) * 0.5D;
double d1 = point.y;
Expand All @@ -42,7 +42,7 @@ public Vec3 getEntityPosAtNode(Entity entity, int index) {
}

private static List<Node> copyPathPoints(Path original) {
List<Node> points = new ArrayList();
List<Node> points = new ArrayList<>();
for (int i = 0; i < original.getNodeCount(); i++) {
points.add(original.getNode(i));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,43 @@
import com.starfish_studios.naturalist.registry.NaturalistEntityTypes;
import com.starfish_studios.naturalist.registry.forge.NaturalistBiomeModifiers;
import com.starfish_studios.naturalist.registry.forge.NaturalistConfigForge;
import net.minecraft.util.Tuple;
import net.minecraft.world.entity.animal.AbstractFish;
import net.minecraft.world.entity.animal.horse.AbstractHorse;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.food.FoodProperties;
import net.minecraft.world.food.Foods;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.EntityAttributeCreationEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.InterModComms;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLPaths;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import org.apache.commons.lang3.tuple.Triple;

import java.util.Collections;
import java.util.List;
import java.util.function.BiFunction;

@Mod(Naturalist.MOD_ID)
public class NaturalistForge {

public NaturalistForge() {
Naturalist.init();


FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueue);

ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, NaturalistConfigForge.COMMON_CONFIG, "naturalist.toml");
NaturalistConfigForge.loadConfig(NaturalistConfigForge.COMMON_CONFIG, FMLPaths.CONFIGDIR.get().resolve("naturalist.toml").toString());

Expand All @@ -47,6 +65,30 @@ public NaturalistForge() {
MinecraftForge.EVENT_BUS.register(this);
}

public void enqueue(InterModEnqueueEvent event) {
if (ModList.get().isLoaded("diet")) {
dietIntegration(NaturalistRegistry.DUCK.get(), Foods.CHICKEN);
dietIntegration(NaturalistRegistry.COOKED_DUCK.get(), Foods.COOKED_CHICKEN);
dietIntegration(NaturalistRegistry.VENISON.get(), Foods.BEEF);
dietIntegration(NaturalistRegistry.COOKED_VENISON.get(), Foods.COOKED_BEEF);
dietIntegration(NaturalistRegistry.LIZARD_TAIL.get(), NaturalistRegistry.LIZARD_TAIL.get().getFoodProperties());
dietIntegration(NaturalistRegistry.COOKED_LIZARD_TAIL.get(), NaturalistRegistry.COOKED_LIZARD_TAIL.get().getFoodProperties());
dietIntegration(NaturalistRegistry.CATFISH.get(), Foods.SALMON);
dietIntegration(NaturalistRegistry.COOKED_CATFISH.get(), Foods.COOKED_SALMON);
dietIntegration(NaturalistRegistry.BASS.get(), Foods.COD);
dietIntegration(NaturalistRegistry.COOKED_BASS.get(), Foods.COOKED_COD);
}
}

public static void dietIntegration(Item item, FoodProperties food) {
InterModComms.sendTo("diet", "item",
() -> new Tuple<Item, BiFunction<Player, ItemStack, Triple<List<ItemStack>, Integer, Float>>>(
item,
(player, stack) -> new ImmutableTriple<>(Collections.singletonList(stack), food.getNutrition(), food.getSaturationModifier())
)
);
}

private void setup(final FMLCommonSetupEvent event) {
event.enqueueWork(() -> {
Naturalist.registerBrewingRecipes();
Expand Down Expand Up @@ -103,4 +145,4 @@ private void createAttributes(EntityAttributeCreationEvent event) {
// event.put(NaturalistEntityTypes.TERMITE.get(), Termite.createAttributes().build());
}

}
}

0 comments on commit d24fa25

Please sign in to comment.