mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-18 11:19:28 +00:00
Make bees particles animate to pollinate nearby flowers
This commit is contained in:
1 parent
64ed04e09b
commit
2c7d56f308
12 files changed
+227
-61
No files matched your search
@@ -11,23 +11,20 @@ import forestry.api.genetics.IEffectData;
|
||||
public interface IAlleleBeeEffect extends IAlleleEffect {
|
||||
|
||||
/**
|
||||
* Called by apiaries to cause an effect in the world.
|
||||
* Called by apiaries to cause an effect in the world. (server)
|
||||
*
|
||||
* @param genome
|
||||
* Genome of the bee queen causing this effect
|
||||
* @param storedData
|
||||
* Object containing the stored effect data for the apiary/hive the bee is in.
|
||||
* @param genome Genome of the bee queen causing this effect
|
||||
* @param storedData Object containing the stored effect data for the apiary/hive the bee is in.
|
||||
* @param housing {@link IBeeHousing} the bee currently resides in.
|
||||
* @return storedData, may have been manipulated.
|
||||
*/
|
||||
IEffectData doEffect(IBeeGenome genome, IEffectData storedData, IBeeHousing housing);
|
||||
|
||||
/**
|
||||
* Is called to produce bee effects.
|
||||
* Is called to produce visual bee effects. (client)
|
||||
*
|
||||
* @param genome
|
||||
* @param storedData
|
||||
* Object containing the stored effect data for the apiary/hive the bee is in.
|
||||
* @param genome Genome of the bee queen causing this effect
|
||||
* @param storedData Object containing the stored effect data for the apiary/hive the bee is in.
|
||||
* @param housing {@link IBeeHousing} the bee currently resides in.
|
||||
* @return storedData, may have been manipulated.
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,11 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.apiculture;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import forestry.api.core.INbtReadable;
|
||||
import forestry.api.core.INbtWritable;
|
||||
@@ -60,4 +64,10 @@ public interface IBeekeepingLogic extends INbtWritable, INbtReadable {
|
||||
*/
|
||||
void doBeeFX();
|
||||
|
||||
/**
|
||||
* Used by bee fx to direct bees to nearby flowers.
|
||||
* These positions are synced to the client from the server.
|
||||
*/
|
||||
@Nonnull
|
||||
List<BlockPos> getFlowerPositions();
|
||||
}
|
||||
@@ -5,6 +5,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.genetics;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
@@ -58,9 +61,14 @@ public interface IFlowerRegistry {
|
||||
boolean growFlower(String flowerType, World world, IIndividual individual, BlockPos pos);
|
||||
|
||||
/**
|
||||
* @return the coordinates of a nearby accepted flower or null if there is none.
|
||||
* @param beeHousing The bee housing that will help determine the size of the area to check.
|
||||
* @param bee The bee that will help determine the size of the area to check.
|
||||
* @param flowerType See {@link forestry.api.apiculture.FlowerManager}.FlowerTypeXXX
|
||||
* @param maxFlowers the largest number of flowers to check for before returning. Use 1 if you only need 1.
|
||||
* @return the coordinates of nearby accepted flowers, with size from 0 to maxFlowers.
|
||||
*/
|
||||
BlockPos getAcceptedFlowerCoordinates(IBeeHousing beeHousing, IBee bee, String flowerType);
|
||||
@Nonnull
|
||||
List<BlockPos> getAcceptedFlowerCoordinates(IBeeHousing beeHousing, IBee bee, String flowerType, int maxFlowers);
|
||||
|
||||
/**
|
||||
* Checks a single coordinate to see if it is an accepted flower.
|
||||
|
||||
@@ -10,10 +10,12 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
|
||||
@@ -23,6 +25,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.apiculture.BeeManager;
|
||||
@@ -130,6 +133,7 @@ public class BeekeepingLogic implements IBeekeepingLogic, IStreamable {
|
||||
data.writeBoolean(active);
|
||||
if (active) {
|
||||
data.writeItemStack(queenStack);
|
||||
hasFlowersCache.writeData(data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,6 +144,7 @@ public class BeekeepingLogic implements IBeekeepingLogic, IStreamable {
|
||||
if (active) {
|
||||
queenStack = data.readItemStack();
|
||||
queen = BeeManager.beeRoot.getMember(queenStack);
|
||||
hasFlowersCache.readData(data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,10 +210,15 @@ public class BeekeepingLogic implements IBeekeepingLogic, IStreamable {
|
||||
}
|
||||
|
||||
boolean hasFlowers = hasFlowersCache.hasFlowers(queen, housing);
|
||||
boolean flowerCacheNeedsSync = hasFlowersCache.needsSync();
|
||||
errorLogic.setCondition(!hasFlowers, EnumErrorCode.NO_FLOWER);
|
||||
|
||||
boolean canWork = !errorLogic.hasErrors();
|
||||
setActive(canWork);
|
||||
if (active != canWork) {
|
||||
setActive(canWork);
|
||||
} else if (flowerCacheNeedsSync) {
|
||||
syncToClient();
|
||||
}
|
||||
return canWork;
|
||||
}
|
||||
|
||||
@@ -470,6 +480,12 @@ public class BeekeepingLogic implements IBeekeepingLogic, IStreamable {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public List<BlockPos> getFlowerPositions() {
|
||||
return hasFlowersCache.getFlowerCoords();
|
||||
}
|
||||
|
||||
private static class QueenCanWorkCache {
|
||||
private static final int ticksPerCheckQueenCanWork = 10;
|
||||
|
||||
|
||||
@@ -10,8 +10,13 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import forestry.api.apiculture.IBeekeepingLogic;
|
||||
|
||||
@@ -57,6 +62,12 @@ public class FakeBeekeepingLogic implements IBeekeepingLogic {
|
||||
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<BlockPos> getFlowerPositions() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
|
||||
|
||||
@@ -10,6 +10,11 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -25,23 +30,32 @@ import forestry.api.apiculture.IBeeModifier;
|
||||
import forestry.api.core.INbtReadable;
|
||||
import forestry.api.core.INbtWritable;
|
||||
import forestry.api.genetics.IFlowerProvider;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IStreamable;
|
||||
import forestry.core.utils.VectUtil;
|
||||
|
||||
public class HasFlowersCache implements INbtWritable, INbtReadable {
|
||||
public class HasFlowersCache implements INbtWritable, INbtReadable, IStreamable {
|
||||
private static final String nbtKey = "hasFlowerCache";
|
||||
private static final String nbtKeyFlowers = "flowers";
|
||||
private static final String nbtKeyCooldown = "cooldown";
|
||||
|
||||
private static final Random random = new Random();
|
||||
private static final int flowerCheckInterval = 128;
|
||||
|
||||
private final int flowerCheckTime = random.nextInt(flowerCheckInterval);
|
||||
private BlockPos flowerCoords = null;
|
||||
@Nonnull
|
||||
private List<BlockPos> flowerCoords = new ArrayList<>();
|
||||
private int cooldown = 0;
|
||||
|
||||
private boolean needsSync = false;
|
||||
|
||||
public boolean hasFlowers(IBee queen, IBeeHousing beeHousing) {
|
||||
IFlowerProvider flowerProvider = queen.getGenome().getFlowerProvider();
|
||||
String flowerType = flowerProvider.getFlowerType();
|
||||
World world = beeHousing.getWorldObj();
|
||||
|
||||
if (flowerCoords != null) {
|
||||
if (!flowerCoords.isEmpty()) {
|
||||
if (world.getTotalWorldTime() % flowerCheckInterval != flowerCheckTime) {
|
||||
return true;
|
||||
}
|
||||
@@ -55,25 +69,40 @@ public class HasFlowersCache implements INbtWritable, INbtReadable {
|
||||
BlockPos min = VectUtil.scale(area, -0.5f).add(housingCoords);
|
||||
BlockPos max = VectUtil.scale(area, 0.5f).add(housingCoords);
|
||||
|
||||
if (isFlowerValid(world, flowerType, min, max)) {
|
||||
return true;
|
||||
} else {
|
||||
flowerCoords = null;
|
||||
cooldown = 0;
|
||||
for (BlockPos flowerPos : flowerCoords) {
|
||||
if (!isFlowerValid(world, flowerPos, flowerType, min, max)) {
|
||||
cooldown = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cooldown <= 0) {
|
||||
flowerCoords = FlowerManager.flowerRegistry.getAcceptedFlowerCoordinates(beeHousing, queen, flowerType);
|
||||
List<BlockPos> newFlowerCoords = FlowerManager.flowerRegistry.getAcceptedFlowerCoordinates(beeHousing, queen, flowerType, 5);
|
||||
cooldown = PluginApiculture.ticksPerBeeWorkCycle;
|
||||
if (!flowerCoords.equals(newFlowerCoords)) {
|
||||
flowerCoords = newFlowerCoords;
|
||||
needsSync = true;
|
||||
}
|
||||
} else {
|
||||
cooldown--;
|
||||
}
|
||||
|
||||
return flowerCoords != null;
|
||||
return !flowerCoords.isEmpty();
|
||||
}
|
||||
|
||||
private boolean isFlowerValid(World world, String flowerType, BlockPos min, BlockPos max) {
|
||||
public boolean needsSync() {
|
||||
boolean returnVal = needsSync;
|
||||
needsSync = false;
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public List<BlockPos> getFlowerCoords() {
|
||||
return Collections.unmodifiableList(flowerCoords);
|
||||
}
|
||||
|
||||
private static boolean isFlowerValid(World world, BlockPos flowerCoords, String flowerType, BlockPos min, BlockPos max) {
|
||||
if (!isFlowerCoordInRange(flowerCoords, min, max)) {
|
||||
return false;
|
||||
}
|
||||
@@ -91,26 +120,65 @@ public class HasFlowersCache implements INbtWritable, INbtReadable {
|
||||
}
|
||||
|
||||
NBTTagCompound hasFlowerCacheNBT = nbttagcompound.getCompoundTag(nbtKey);
|
||||
if (hasFlowerCacheNBT.hasKey("flowerX")) {
|
||||
int x = hasFlowerCacheNBT.getInteger("flowerX");
|
||||
int y = hasFlowerCacheNBT.getInteger("flowerY");
|
||||
int z = hasFlowerCacheNBT.getInteger("flowerZ");
|
||||
flowerCoords = new BlockPos(x, y, z);
|
||||
|
||||
if (hasFlowerCacheNBT.hasKey(nbtKeyFlowers)) {
|
||||
int[] flowersList = hasFlowerCacheNBT.getIntArray(nbtKeyFlowers);
|
||||
if (flowersList != null && flowersList.length % 3 == 0) {
|
||||
int flowerCount = flowersList.length / 3;
|
||||
for (int i = 0; i < flowerCount; i++) {
|
||||
BlockPos flowerPos = new BlockPos(flowersList[i], flowersList[i + 1], flowersList[i + 2]);
|
||||
flowerCoords.add(flowerPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cooldown = hasFlowerCacheNBT.getInteger("cooldown");
|
||||
cooldown = hasFlowerCacheNBT.getInteger(nbtKeyCooldown);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
NBTTagCompound hasFlowerCacheNBT = new NBTTagCompound();
|
||||
if (flowerCoords != null) {
|
||||
hasFlowerCacheNBT.setInteger("flowerX", flowerCoords.getX());
|
||||
hasFlowerCacheNBT.setInteger("flowerY", flowerCoords.getY());
|
||||
hasFlowerCacheNBT.setInteger("flowerZ", flowerCoords.getZ());
|
||||
|
||||
if (!flowerCoords.isEmpty()) {
|
||||
int[] flowersList = new int[flowerCoords.size() * 3];
|
||||
int i = 0;
|
||||
for (BlockPos flowerPos : flowerCoords) {
|
||||
flowersList[i] = flowerPos.getX();
|
||||
flowersList[i + 1] = flowerPos.getY();
|
||||
flowersList[i + 2] = flowerPos.getZ();
|
||||
i++;
|
||||
}
|
||||
|
||||
hasFlowerCacheNBT.setIntArray(nbtKeyFlowers, flowersList);
|
||||
}
|
||||
hasFlowerCacheNBT.setInteger("cooldown", cooldown);
|
||||
|
||||
hasFlowerCacheNBT.setInteger(nbtKeyCooldown, cooldown);
|
||||
|
||||
nbttagcompound.setTag(nbtKey, hasFlowerCacheNBT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
int size = flowerCoords.size();
|
||||
data.writeVarInt(size);
|
||||
if (size > 0) {
|
||||
for (BlockPos pos : flowerCoords) {
|
||||
data.writeVarInt(pos.getX());
|
||||
data.writeVarInt(pos.getY());
|
||||
data.writeVarInt(pos.getZ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
flowerCoords.clear();
|
||||
|
||||
int size = data.readVarInt();
|
||||
while (size > 0) {
|
||||
BlockPos pos = new BlockPos(data.readVarInt(), data.readVarInt(), data.readVarInt());
|
||||
flowerCoords.add(pos);
|
||||
size--;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraft.world.chunk.IChunkGenerator;
|
||||
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.common.BiomeDictionary;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
@@ -65,9 +66,9 @@ import forestry.apiculture.blocks.BlockRegistryApiculture;
|
||||
import forestry.apiculture.blocks.BlockTypeApiculture;
|
||||
import forestry.apiculture.blocks.BlockTypeApicultureTesr;
|
||||
import forestry.apiculture.commands.CommandBee;
|
||||
import forestry.apiculture.entities.EntityFXBee;
|
||||
import forestry.apiculture.entities.EntityMinecartApiary;
|
||||
import forestry.apiculture.entities.EntityMinecartBeehouse;
|
||||
import forestry.apiculture.entities.ParticleBee;
|
||||
import forestry.apiculture.flowers.Flower;
|
||||
import forestry.apiculture.flowers.FlowerRegistry;
|
||||
import forestry.apiculture.genetics.BeeBranchDefinition;
|
||||
@@ -948,7 +949,7 @@ public class PluginApiculture extends BlankForestryPlugin {
|
||||
for (int i = 0; i < EntityFXSnow.sprites.length; i++) {
|
||||
EntityFXSnow.sprites[i] = event.getMap().registerSprite(new ResourceLocation("forestry:entity/particles/snow." + (i + 1)));
|
||||
}
|
||||
EntityFXBee.beeSprite = event.getMap().registerSprite(new ResourceLocation("forestry:entity/particles/swarm_bee"));
|
||||
ParticleBee.beeSprite = event.getMap().registerSprite(new ResourceLocation("forestry:entity/particles/swarm_bee"));
|
||||
}
|
||||
|
||||
private static class EndFlowerAcceptableRule implements IFlowerAcceptableRule {
|
||||
|
||||
+38
-6
@@ -14,20 +14,29 @@ import net.minecraft.client.particle.EntityFX;
|
||||
import net.minecraft.client.renderer.VertexBuffer;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class EntityFXBee extends EntityFX {
|
||||
public class ParticleBee extends EntityFX {
|
||||
private final double originX;
|
||||
private final double originY;
|
||||
private final double originZ;
|
||||
private final BlockPos destination;
|
||||
|
||||
public static TextureAtlasSprite beeSprite;
|
||||
|
||||
public EntityFXBee(World world, double x, double y, double z, int color) {
|
||||
public ParticleBee(World world, double x, double y, double z, int color, BlockPos destination) {
|
||||
super(world, x, y, z, 0.0D, 0.0D, 0.0D);
|
||||
setParticleTexture(beeSprite);
|
||||
this.originX = x;
|
||||
this.originY = y;
|
||||
this.originZ = z;
|
||||
|
||||
this.destination = destination;
|
||||
this.motionX = (destination.getX() + 0.5 - this.posX) * 0.015;
|
||||
this.motionY = (destination.getY() + 0.5 - this.posY) * 0.015;
|
||||
this.motionZ = (destination.getZ() + 0.5 - this.posZ) * 0.015;
|
||||
|
||||
particleRed = (color >> 16 & 255) / 255.0F;
|
||||
particleGreen = (color >> 8 & 255) / 255.0F;
|
||||
particleBlue = (color & 255) / 255.0F;
|
||||
@@ -52,18 +61,34 @@ public class EntityFXBee extends EntityFX {
|
||||
this.moveEntity(this.motionX, this.motionY, this.motionZ);
|
||||
|
||||
if (this.particleAge == this.particleMaxAge / 2) {
|
||||
this.motionX = (this.originX - this.posX) * 0.04;
|
||||
this.motionZ = (this.originZ - this.posZ) * 0.04;
|
||||
this.motionX = (this.originX - this.posX) * 0.03;
|
||||
this.motionY = (this.originY - this.posY) * 0.03;
|
||||
this.motionZ = (this.originZ - this.posZ) * 0.03;
|
||||
}
|
||||
|
||||
if (this.particleAge < this.particleMaxAge / 4 || this.particleAge > this.particleMaxAge * 3 / 4) {
|
||||
if (this.particleAge < this.particleMaxAge * 0.25) {
|
||||
// venture out
|
||||
this.motionX *= 0.92 + 0.2D * rand.nextFloat();
|
||||
this.motionY = (this.motionY + 0.2 * (-0.5 + rand.nextFloat())) / 2;
|
||||
this.motionZ *= 0.92 + 0.2D * rand.nextFloat();
|
||||
} else {
|
||||
} else if (this.particleAge < this.particleMaxAge * 0.5) {
|
||||
// get to flower destination
|
||||
this.motionX = (destination.getX() + 0.5 - this.posX) * 0.03;
|
||||
this.motionY = (destination.getY() + 0.5 - this.posY) * 0.03;
|
||||
this.motionY = (this.motionY + 0.2 * (-0.5 + rand.nextFloat())) / 2;
|
||||
this.motionZ = (destination.getZ() + 0.5 - this.posZ) * 0.03;
|
||||
} else if (this.particleAge < this.particleMaxAge * 0.75) {
|
||||
// venture back
|
||||
this.motionX *= 0.95;
|
||||
this.motionY = (this.originY - this.posY) * 0.03;
|
||||
this.motionY = (this.motionY + 0.2 * (-0.5 + rand.nextFloat())) / 2;
|
||||
this.motionZ *= 0.95;
|
||||
} else {
|
||||
// get to origin
|
||||
this.motionX = (this.originX - this.posX) * 0.03;
|
||||
this.motionY = (this.originY - this.posY) * 0.03;
|
||||
this.motionY = (this.motionY + 0.2 * (-0.5 + rand.nextFloat())) / 2;
|
||||
this.motionZ = (this.originZ - this.posZ) * 0.03;
|
||||
}
|
||||
|
||||
if (this.particleAge++ >= this.particleMaxAge) {
|
||||
@@ -99,6 +124,13 @@ public class EntityFXBee extends EntityFX {
|
||||
worldRendererIn.pos(f11 + rotationX * f10 - rotationXY * f10, f12 - rotationZ * f10, f13 + rotationYZ * f10 - rotationXZ * f10).tex(minU, maxV).color(particleRed, particleGreen, particleBlue, 1.0F).lightmap(j, k).endVertex();
|
||||
}
|
||||
|
||||
// avoid calculating collisions for bees, it is too much processing
|
||||
@Override
|
||||
public void moveEntity(double x, double y, double z) {
|
||||
this.setEntityBoundingBox(this.getEntityBoundingBox().offset(x, y, z));
|
||||
this.resetPositionToBB();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFXLayer() {
|
||||
return 1;
|
||||
@@ -15,9 +15,12 @@ import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
@@ -140,9 +143,10 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getAcceptedFlowerCoordinates(IBeeHousing beeHousing, IBee bee, String flowerType) {
|
||||
@Nonnull
|
||||
public List<BlockPos> getAcceptedFlowerCoordinates(IBeeHousing beeHousing, IBee bee, String flowerType, int maxFlowers) {
|
||||
if (!this.registeredFlowers.containsKey(flowerType)) {
|
||||
return null;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
Set<IFlowerAcceptableRule> acceptableRules = this.registeredRules.get(flowerType);
|
||||
@@ -156,19 +160,26 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe
|
||||
BlockPos minPos = beeHousing.getCoordinates().add(-area.getX() / 2, -area.getY() / 2, -area.getZ() / 2);
|
||||
BlockPos maxPos = minPos.add(area);
|
||||
|
||||
for (BlockPos posBlock : BlockPos.getAllInBoxMutable(minPos, maxPos)) {
|
||||
List<BlockPos> flowerCoords = new ArrayList<>();
|
||||
for (BlockPos.MutableBlockPos posBlock : BlockPos.getAllInBoxMutable(minPos, maxPos)) {
|
||||
for (IFlowerAcceptableRule acceptableRule : acceptableRules) {
|
||||
if (acceptableRule.isAcceptableFlower(flowerType, world, posBlock)) {
|
||||
return posBlock;
|
||||
flowerCoords.add(posBlock.toImmutable());
|
||||
if (flowerCoords.size() >= maxFlowers) {
|
||||
return flowerCoords;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isAcceptedFlower(flowerType, acceptedBlocks, acceptedFlowers, world, posBlock)) {
|
||||
return posBlock;
|
||||
if (isAcceptedFlower(acceptedBlocks, acceptedFlowers, world, posBlock)) {
|
||||
flowerCoords.add(posBlock.toImmutable());
|
||||
if (flowerCoords.size() >= maxFlowers) {
|
||||
return flowerCoords;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return flowerCoords;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -187,10 +198,10 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe
|
||||
Set<Block> acceptedBlocks = this.registeredBlocks.get(flowerType);
|
||||
Set<Flower> acceptedFlowers = this.registeredFlowers.get(flowerType);
|
||||
|
||||
return isAcceptedFlower(flowerType, acceptedBlocks, acceptedFlowers, world, pos);
|
||||
return isAcceptedFlower(acceptedBlocks, acceptedFlowers, world, pos);
|
||||
}
|
||||
|
||||
private static boolean isAcceptedFlower(String flowerType, Set<Block> acceptedBlocks, Set<Flower> acceptedFlowers, World world, BlockPos pos) {
|
||||
private static boolean isAcceptedFlower(Set<Block> acceptedBlocks, Set<Flower> acceptedFlowers, World world, BlockPos pos) {
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
Block block = blockState.getBlock();
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import forestry.api.apiculture.IAlleleBeeEffect;
|
||||
import forestry.api.apiculture.IBeeGenome;
|
||||
import forestry.api.apiculture.IBeeHousing;
|
||||
import forestry.api.apiculture.IBeeModifier;
|
||||
import forestry.api.apiculture.IBeekeepingLogic;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IEffectData;
|
||||
import forestry.core.config.Constants;
|
||||
@@ -104,8 +105,12 @@ public abstract class AlleleEffect extends AlleleCategorized implements IAlleleB
|
||||
|
||||
@Override
|
||||
public IEffectData doFX(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) {
|
||||
Vec3d beeFXCoordinates = housing.getBeeFXCoordinates();
|
||||
Proxies.render.addBeeHiveFX(housing.getWorldObj(), beeFXCoordinates.xCoord, beeFXCoordinates.yCoord, beeFXCoordinates.zCoord, genome.getPrimary().getSpriteColour(0));
|
||||
Vec3d origin = housing.getBeeFXCoordinates();
|
||||
IBeekeepingLogic beekeepingLogic = housing.getBeekeepingLogic();
|
||||
List<BlockPos> flowerPositions = beekeepingLogic.getFlowerPositions();
|
||||
|
||||
int beeColor = genome.getPrimary().getSpriteColour(0);
|
||||
Proxies.render.addBeeHiveFX(housing.getWorldObj(), origin.xCoord, origin.yCoord, origin.zCoord, beeColor, flowerPositions);
|
||||
return storedData;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,9 @@ package forestry.core.proxy;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.block.statemap.IStateMapper;
|
||||
@@ -112,7 +114,7 @@ public class ProxyRender {
|
||||
|
||||
/* FX */
|
||||
|
||||
public void addBeeHiveFX(World world, double x, double y, double z, int color) {
|
||||
public void addBeeHiveFX(@Nonnull World world, double x, double y, double z, int color, @Nonnull List<BlockPos> flowerPositions) {
|
||||
}
|
||||
|
||||
public void addEntityHoneyDustFX(World world, double x, double y, double z) {
|
||||
|
||||
@@ -10,10 +10,11 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.proxy;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -38,7 +39,8 @@ import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.common.animation.ITimeValue;
|
||||
import net.minecraftforge.common.model.animation.IAnimationStateMachine;
|
||||
import forestry.apiculture.entities.EntityFXBee;
|
||||
|
||||
import forestry.apiculture.entities.ParticleBee;
|
||||
import forestry.apiculture.render.TextureHabitatLocator;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.config.Constants;
|
||||
@@ -186,14 +188,17 @@ public class ProxyRenderClient extends ProxyRender {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBeeHiveFX(World world, double x, double y, double z, int color) {
|
||||
public void addBeeHiveFX(@Nonnull World world, double x, double y, double z, int color, @Nonnull List<BlockPos> flowerPositions) {
|
||||
if (!shouldSpawnParticle(world)) {
|
||||
return;
|
||||
}
|
||||
|
||||
EntityFX fx = new EntityFXBee(world, x, y, z, color);
|
||||
EffectRenderer effectRenderer = Minecraft.getMinecraft().effectRenderer;
|
||||
effectRenderer.addEffect(fx);
|
||||
if (!flowerPositions.isEmpty()) {
|
||||
BlockPos destination = flowerPositions.get(world.rand.nextInt(flowerPositions.size()));
|
||||
EntityFX particle = new ParticleBee(world, x, y, z, color, destination);
|
||||
EffectRenderer effectRenderer = Minecraft.getMinecraft().effectRenderer;
|
||||
effectRenderer.addEffect(particle);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user