From cf240a483ac4c1abf1208d38abb0c13b31f7c5e6 Mon Sep 17 00:00:00 2001 From: thedarkcolour <30441001+thedarkcolour@users.noreply.github.com> Date: Mon, 1 Jul 2024 19:51:00 -0700 Subject: [PATCH] Butterfly improvements + fix hitboxes --- src/main/java/forestry/Forestry.java | 2 -- .../api/lepidopterology/IEntityButterfly.java | 2 -- .../entities/AIButterflyBase.java | 2 +- .../entities/AIButterflyPollinate.java | 1 + .../entities/AIButterflyRest.java | 28 ++++++------------- .../entities/EntityButterfly.java | 27 ++++++++++++++---- .../features/LepidopterologyEntities.java | 7 +---- .../modules/features/FeatureEntityType.java | 4 +-- 8 files changed, 35 insertions(+), 38 deletions(-) diff --git a/src/main/java/forestry/Forestry.java b/src/main/java/forestry/Forestry.java index 5c5e95176..1fa4bb7b4 100755 --- a/src/main/java/forestry/Forestry.java +++ b/src/main/java/forestry/Forestry.java @@ -161,7 +161,6 @@ private void setup(FMLCommonSetupEvent event) { // Register event handler callSetupListeners(true); ModuleManager.getModuleHandler().runPreInit(); - //TODO put these here for now ModuleManager.getModuleHandler().runInit(); callSetupListeners(false); ModuleManager.getModuleHandler().runPostInit(); @@ -171,7 +170,6 @@ private void registerCapabilities(RegisterCapabilitiesEvent event) { ModuleManager.getModuleHandler().registerCapabilities(event::register); } - //TODO: Move to somewhere else private void callSetupListeners(boolean start) { for (IAllele allele : AlleleUtils.getAlleles()) { if (allele instanceof ISetupListener listener) { diff --git a/src/main/java/forestry/api/lepidopterology/IEntityButterfly.java b/src/main/java/forestry/api/lepidopterology/IEntityButterfly.java index 900ff7c3f..d90d96bdc 100644 --- a/src/main/java/forestry/api/lepidopterology/IEntityButterfly.java +++ b/src/main/java/forestry/api/lepidopterology/IEntityButterfly.java @@ -13,9 +13,7 @@ import forestry.api.lepidopterology.genetics.IButterfly; -//TODO - figure out how IAnimal works now, might want to make abstract and extend AnimalEntity public interface IEntityButterfly { - void changeExhaustion(int change); int getExhaustion(); diff --git a/src/main/java/forestry/lepidopterology/entities/AIButterflyBase.java b/src/main/java/forestry/lepidopterology/entities/AIButterflyBase.java index 62686fce8..ec02e7c0b 100755 --- a/src/main/java/forestry/lepidopterology/entities/AIButterflyBase.java +++ b/src/main/java/forestry/lepidopterology/entities/AIButterflyBase.java @@ -33,7 +33,7 @@ protected Vec3 getRandomDestination() { } Vec3 entityPos = entity.position(); - Vec3 randomTarget = DefaultRandomPos.getPosAway(entity, 16, 7, entityPos.add(new Vec3(0, 0, 1).yRot(entity.getYRot()))); + Vec3 randomTarget = DefaultRandomPos.getPosAway(entity, 16, 7, entityPos.add(new Vec3(0, -1, 1).yRot(entity.getYRot()))); if (randomTarget != null && validateDestination(randomTarget, false)) { return randomTarget; diff --git a/src/main/java/forestry/lepidopterology/entities/AIButterflyPollinate.java b/src/main/java/forestry/lepidopterology/entities/AIButterflyPollinate.java index 8da8c8285..7ea55d8f8 100755 --- a/src/main/java/forestry/lepidopterology/entities/AIButterflyPollinate.java +++ b/src/main/java/forestry/lepidopterology/entities/AIButterflyPollinate.java @@ -53,6 +53,7 @@ public void tick() { if (checkPollinatable != null) { if (entity.getPollen() == null) { entity.setPollen(checkPollinatable.getPollen()); + entity.changeExhaustion(-entity.getExhaustion()); } else if (checkPollinatable.canMateWith(entity.getPollen())) { IPollinatable realPollinatable = GeneticsUtil.getOrCreatePollinatable(null, entity.level, rest, false); if (realPollinatable != null) { diff --git a/src/main/java/forestry/lepidopterology/entities/AIButterflyRest.java b/src/main/java/forestry/lepidopterology/entities/AIButterflyRest.java index f03c11b33..6919d13e3 100755 --- a/src/main/java/forestry/lepidopterology/entities/AIButterflyRest.java +++ b/src/main/java/forestry/lepidopterology/entities/AIButterflyRest.java @@ -14,10 +14,7 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.FenceBlock; -import net.minecraft.world.level.block.FlowerBlock; import net.minecraft.world.level.block.BonemealableBlock; -import net.minecraft.world.level.block.WallBlock; import net.minecraft.world.level.material.Material; import net.minecraft.tags.BlockTags; import net.minecraft.core.Direction; @@ -26,8 +23,6 @@ import net.minecraftforge.common.IPlantable; -import net.minecraft.world.entity.ai.goal.Goal.Flag; - public class AIButterflyRest extends AIButterflyBase { public AIButterflyRest(EntityButterfly entity) { super(entity); @@ -94,36 +89,31 @@ private boolean canLand(BlockPos pos) { return false; } BlockState blockState = entity.level.getBlockState(pos); - if (!blockState.isAir()) { //TODO - // if (!block.isPassable(entity.world, pos)) { + if (!blockState.isAir()) { return false; } if (isPlant(blockState)) { return true; } - BlockState blockStateBelow = entity.level.getBlockState(pos.below()); - Block blockBelow = blockStateBelow.getBlock(); - return isRest(blockBelow) || blockStateBelow.is(BlockTags.LEAVES); + BlockState belowState = entity.level.getBlockState(pos.below()); + return isRest(belowState) || belowState.is(BlockTags.LEAVES); } - private static boolean isRest(Block block) { - if (block instanceof FenceBlock) { - return true; - } - return block instanceof WallBlock; + private static boolean isRest(BlockState state) { + return state.is(BlockTags.FENCES) || state.is(BlockTags.WALLS); } - private static boolean isPlant(BlockState blockState) { - Block block = blockState.getBlock(); - if (block instanceof FlowerBlock) { + private static boolean isPlant(BlockState state) { + Block block = state.getBlock(); + if (state.is(BlockTags.FLOWERS)) { return true; } else if (block instanceof IPlantable) { return true; } else if (block instanceof BonemealableBlock) { return true; } else { - return blockState.getMaterial() == Material.PLANT; + return state.getMaterial() == Material.PLANT; } } } diff --git a/src/main/java/forestry/lepidopterology/entities/EntityButterfly.java b/src/main/java/forestry/lepidopterology/entities/EntityButterfly.java index f1addffb9..343844fa8 100755 --- a/src/main/java/forestry/lepidopterology/entities/EntityButterfly.java +++ b/src/main/java/forestry/lepidopterology/entities/EntityButterfly.java @@ -40,7 +40,6 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.BonemealableBlock; import net.minecraft.world.level.block.FenceBlock; -import net.minecraft.world.level.block.FlowerBlock; import net.minecraft.world.level.block.WallBlock; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkAccess; @@ -55,6 +54,7 @@ import forestry.api.arboriculture.TreeManager; import forestry.api.arboriculture.genetics.EnumGermlingType; +import forestry.api.genetics.ICheckPollinatable; import forestry.api.lepidopterology.IEntityButterfly; import forestry.api.lepidopterology.ILepidopteristTracker; import forestry.api.lepidopterology.genetics.ButterflyChromosomes; @@ -64,6 +64,7 @@ import forestry.api.lepidopterology.genetics.IButterflyRoot; import forestry.core.config.Config; import forestry.core.data.ForestryTags; +import forestry.core.utils.GeneticsUtil; import forestry.core.utils.ItemStackUtil; import forestry.lepidopterology.ModuleLepidopterology; import forestry.lepidopterology.genetics.Butterfly; @@ -278,7 +279,7 @@ public float getWalkTargetValue(BlockPos pos) { } else { BlockState blockState = level.getBlockState(pos); Block block = blockState.getBlock(); - if (block instanceof FlowerBlock) { + if (blockState.is(BlockTags.FLOWERS)) { weight += 2.0f; } else if (block instanceof IPlantable) { weight += 1.5f; @@ -291,8 +292,20 @@ public float getWalkTargetValue(BlockPos pos) { BlockPos posBelow = pos.below(); BlockState blockStateBelow = level.getBlockState(posBelow); Block blockBelow = blockStateBelow.getBlock(); - if (blockStateBelow.is(BlockTags.LEAVES)) { - weight += 50f; + if (blockState.is(BlockTags.LEAVES)) { + boolean isSamePollen = false; + + if (this.pollen != null) { + ICheckPollinatable pollinatable = GeneticsUtil.getCheckPollinatable(level, posBelow); + if (pollinatable != null && pollinatable.getPollen().getIdentifier().equals(this.pollen.getIdentifier())) { + isSamePollen = true; + } + } + if (isSamePollen) { + weight -= 15.0f; + } else { + weight += 5.0f; + } } else if (blockBelow instanceof FenceBlock) { weight += 1.0f; } else if (blockBelow instanceof WallBlock) { @@ -505,7 +518,11 @@ public void tick() { } Vec3 motion = getDeltaMovement(); - setDeltaMovement(motion.x, motion.y * 0.6, motion.z); + if (state == EnumButterflyState.FLYING && flightTarget != null && flightTarget.y > position().y) { + setDeltaMovement(motion.x, motion.y * 0.6 + 0.15, motion.z); + } else { + setDeltaMovement(motion.x, motion.y * 0.6, motion.z); + } // Make sure we die if the butterfly hasn't rested in a long, long time. if (exhaustion > EXHAUSTION_CONSUMPTION && random.nextInt(20) == 0) { diff --git a/src/main/java/forestry/lepidopterology/features/LepidopterologyEntities.java b/src/main/java/forestry/lepidopterology/features/LepidopterologyEntities.java index 498fe066b..e86318ec9 100644 --- a/src/main/java/forestry/lepidopterology/features/LepidopterologyEntities.java +++ b/src/main/java/forestry/lepidopterology/features/LepidopterologyEntities.java @@ -14,10 +14,5 @@ public class LepidopterologyEntities { private static final IFeatureRegistry REGISTRY = ModFeatureRegistry.get(ModuleLepidopterology.class); - public static final FeatureEntityType BUTTERFLY = REGISTRY.entity(EntityButterfly::new, - MobCategory.CREATURE, "butterfly", (builder) -> builder.sized(1.0f, 0.4f), - Mob::createMobAttributes); - - private LepidopterologyEntities() { - } + public static final FeatureEntityType BUTTERFLY = REGISTRY.entity(EntityButterfly::new, MobCategory.CREATURE, "butterfly", builder -> builder.sized(0.5f, 0.25f), Mob::createMobAttributes); } diff --git a/src/main/java/forestry/modules/features/FeatureEntityType.java b/src/main/java/forestry/modules/features/FeatureEntityType.java index e16c331b5..a82c976f1 100644 --- a/src/main/java/forestry/modules/features/FeatureEntityType.java +++ b/src/main/java/forestry/modules/features/FeatureEntityType.java @@ -13,7 +13,6 @@ import net.minecraftforge.registries.RegistryObject; public class FeatureEntityType extends ModFeature implements IEntityTypeFeature { - protected final UnaryOperator> consumer; protected final Supplier attributes; protected final EntityType.EntityFactory factory; protected final MobCategory classification; @@ -21,11 +20,10 @@ public class FeatureEntityType extends ModFeature implements I public FeatureEntityType(IFeatureRegistry registry, String moduleID, String identifier, UnaryOperator> consumer, EntityType.EntityFactory factory, MobCategory classification, Supplier attributes) { super(moduleID, registry.getModId(), identifier); - this.consumer = consumer; this.factory = factory; this.attributes = attributes; this.classification = classification; - this.entityTypeObject = registry.getRegistry(Registry.ENTITY_TYPE_REGISTRY).register(identifier, () -> EntityType.Builder.of(factory, classification).build(this.modId + ":" + identifier)); + this.entityTypeObject = registry.getRegistry(Registry.ENTITY_TYPE_REGISTRY).register(identifier, () -> consumer.apply(EntityType.Builder.of(factory, classification)).build(this.modId + ":" + identifier)); } @Override