Skip to content

Commit

Permalink
Butterfly improvements + fix hitboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
thedarkcolour committed Jul 2, 2024
1 parent 0535a2c commit cf240a4
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 38 deletions.
2 changes: 0 additions & 2 deletions src/main/java/forestry/Forestry.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,5 @@
public class LepidopterologyEntities {
private static final IFeatureRegistry REGISTRY = ModFeatureRegistry.get(ModuleLepidopterology.class);

public static final FeatureEntityType<EntityButterfly> BUTTERFLY = REGISTRY.entity(EntityButterfly::new,
MobCategory.CREATURE, "butterfly", (builder) -> builder.sized(1.0f, 0.4f),
Mob::createMobAttributes);

private LepidopterologyEntities() {
}
public static final FeatureEntityType<EntityButterfly> BUTTERFLY = REGISTRY.entity(EntityButterfly::new, MobCategory.CREATURE, "butterfly", builder -> builder.sized(0.5f, 0.25f), Mob::createMobAttributes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,17 @@
import net.minecraftforge.registries.RegistryObject;

public class FeatureEntityType<T extends Entity> extends ModFeature implements IEntityTypeFeature<T> {
protected final UnaryOperator<EntityType.Builder<T>> consumer;
protected final Supplier<AttributeSupplier.Builder> attributes;
protected final EntityType.EntityFactory<T> factory;
protected final MobCategory classification;
private final RegistryObject<EntityType<T>> entityTypeObject;

public FeatureEntityType(IFeatureRegistry registry, String moduleID, String identifier, UnaryOperator<EntityType.Builder<T>> consumer, EntityType.EntityFactory<T> factory, MobCategory classification, Supplier<AttributeSupplier.Builder> 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
Expand Down

0 comments on commit cf240a4

Please sign in to comment.