mirror of
https://github.com/GTNewHorizons/MagicBees.git
synced 2026-11-14 01:04:21 +00:00
Implement acceleratable empowering effect
This commit is contained in:
2 files changed
+91
-17
No files matched your search
@@ -1,9 +1,14 @@
|
||||
package magicbees.bees.allele.effect;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import gregtech.api.interfaces.IAlleleBeeAcceleratableEffect;
|
||||
import magicbees.bees.AlleleEffect;
|
||||
import magicbees.bees.BeeManager;
|
||||
import magicbees.main.Config;
|
||||
import magicbees.main.utils.BlockUtil;
|
||||
import magicbees.main.utils.compat.thaumcraft.NodeHelper;
|
||||
|
||||
@@ -14,8 +19,15 @@ import forestry.api.apiculture.IBeeGenome;
|
||||
import forestry.api.apiculture.IBeeHousing;
|
||||
import forestry.api.apiculture.IBeeModifier;
|
||||
import forestry.api.genetics.IEffectData;
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
import thaumcraft.api.aspects.AspectList;
|
||||
import thaumcraft.api.nodes.INode;
|
||||
|
||||
public class AlleleEffectEmpowering extends AlleleEffect {
|
||||
import static magicbees.main.utils.compat.thaumcraft.NodeHelper.getWeightedRandomAspect;
|
||||
import static magicbees.main.utils.compat.thaumcraft.NodeHelper.updateNode;
|
||||
|
||||
@Optional.Interface(iface = "gregtech.api.interfaces.IAlleleBeeAcceleratableEffect", modid = "gregtech")
|
||||
public class AlleleEffectEmpowering extends AlleleEffect implements IAlleleBeeAcceleratableEffect {
|
||||
|
||||
public AlleleEffectEmpowering(String id, boolean isDominant) {
|
||||
super(id, isDominant, 200);
|
||||
@@ -24,7 +36,7 @@ public class AlleleEffectEmpowering extends AlleleEffect {
|
||||
|
||||
@Override
|
||||
public IEffectData validateStorage(IEffectData storedData) {
|
||||
if (storedData == null || !(storedData instanceof magicbees.bees.allele.effect.EffectData)) {
|
||||
if (!(storedData instanceof EffectData)) {
|
||||
storedData = new magicbees.bees.allele.effect.EffectData(1, 0, 0);
|
||||
}
|
||||
return storedData;
|
||||
@@ -37,7 +49,7 @@ public class AlleleEffectEmpowering extends AlleleEffect {
|
||||
IBeeModifier beeModifier = BeeManager.beeRoot.createBeeHousingModifier(housing);
|
||||
int range = Math.max((int)Math.ceil(genome.getTerritory()[0] * beeModifier.getTerritoryModifier(genome, 1f)), 1);
|
||||
List<Chunk> chunks = BlockUtil.getChunksInSearchRange(world, coords.posX, coords.posZ, range);
|
||||
|
||||
|
||||
if (NodeHelper.growNodeInRange(chunks, world, coords.posX, coords.posY, coords.posZ, range)) {
|
||||
storedData.setInteger(0, storedData.getInteger(0) - throttle);
|
||||
}
|
||||
@@ -45,4 +57,66 @@ public class AlleleEffectEmpowering extends AlleleEffect {
|
||||
return storedData;
|
||||
}
|
||||
|
||||
@Optional.Method(modid = "gregtech")
|
||||
@Override
|
||||
public IEffectData doEffectAccelerated(IBeeGenome genome, IEffectData storedData, IBeeHousing housing, float did) {
|
||||
storedData.setInteger(0, 0);
|
||||
World world = housing.getWorld();
|
||||
ChunkCoordinates coords = housing.getCoordinates();
|
||||
IBeeModifier beeModifier = BeeManager.beeRoot.createBeeHousingModifier(housing);
|
||||
int range = Math.max((int)Math.ceil(genome.getTerritory()[0] * beeModifier.getTerritoryModifier(genome, 1f)), 1);
|
||||
List<Chunk> chunks = BlockUtil.getChunksInSearchRange(world, coords.posX, coords.posZ, range);
|
||||
|
||||
int idid = (int)did;
|
||||
|
||||
List<INode> nodes = new ArrayList<>();
|
||||
Collections.shuffle(chunks);
|
||||
for(Chunk chunk : chunks) {
|
||||
List<INode> l = NodeHelper.findNodesInChunkWithinRange(chunk, coords.posX, coords.posY, coords.posZ, range);
|
||||
nodes.addAll(l);
|
||||
idid -= l.size();
|
||||
if(idid <= 0)
|
||||
{
|
||||
while(idid < 0)
|
||||
{
|
||||
nodes.remove(0);
|
||||
idid++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(nodes.isEmpty())
|
||||
return storedData;
|
||||
|
||||
did /= (float) nodes.size();
|
||||
if(did < 1f)
|
||||
did = 1f;
|
||||
|
||||
|
||||
for(INode node : nodes){
|
||||
AspectList aspectsBase = node.getAspectsBase();
|
||||
int randBase = Math.max(aspectsBase.visSize(), 1);
|
||||
if (world.rand.nextInt(randBase) < 120) {
|
||||
Aspect aspectToAdd;
|
||||
int rollAttempts = 0;
|
||||
do {
|
||||
aspectToAdd = getWeightedRandomAspect(world.rand);
|
||||
++rollAttempts;
|
||||
}
|
||||
while (aspectsBase.getAmount(aspectToAdd) > (Config.thaumcraftNodeMaxSize -1) && rollAttempts < 20);
|
||||
|
||||
if (20 <= rollAttempts) {
|
||||
continue;
|
||||
}
|
||||
|
||||
short amount = (short)(1 + world.rand.nextInt((int)(2f * did)));
|
||||
aspectsBase.add(aspectToAdd, amount);
|
||||
node.getAspects().add(aspectToAdd, amount);
|
||||
updateNode(node, world);
|
||||
}
|
||||
}
|
||||
|
||||
return storedData;
|
||||
}
|
||||
}
|
||||
@@ -20,9 +20,9 @@ import thaumcraft.api.nodes.NodeModifier;
|
||||
import thaumcraft.api.nodes.NodeType;
|
||||
|
||||
public class NodeHelper {
|
||||
|
||||
|
||||
private static Map<NodeType, Float> conversionChances;
|
||||
|
||||
|
||||
static {
|
||||
conversionChances = new HashMap<NodeType,Float>();
|
||||
conversionChances.put(NodeType.NORMAL, 0.075f);
|
||||
@@ -48,10 +48,10 @@ public class NodeHelper {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<INode> findNodesInChunkWithinRange(Chunk chunk, int x, int y, int z, int range) {
|
||||
List<INode> nodes = new ArrayList<INode>();
|
||||
@@ -68,7 +68,7 @@ public class NodeHelper {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return nodes;
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ public class NodeHelper {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static boolean growNodeInRange(List<Chunk> chunks, World world, int xCoord, int yCoord, int zCoord, int range) {
|
||||
Collections.shuffle(chunks);
|
||||
int attemptedNodes = 0;
|
||||
@@ -117,11 +117,11 @@ public class NodeHelper {
|
||||
++rollAttempts;
|
||||
}
|
||||
while (aspectsBase.getAmount(aspectToAdd) > (Config.thaumcraftNodeMaxSize -1) && rollAttempts < 20);
|
||||
|
||||
|
||||
if (20 <= rollAttempts) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
short amount = (short)(1 + world.rand.nextInt(2));
|
||||
aspectsBase.add(aspectToAdd, amount);
|
||||
node.getAspects().add(aspectToAdd, amount);
|
||||
@@ -165,7 +165,7 @@ public class NodeHelper {
|
||||
}
|
||||
return aspectToAdd;
|
||||
}
|
||||
|
||||
|
||||
public static boolean repairNodeInRange(List<Chunk> chunks, World world, int xCoord, int yCoord, int zCoord, int range) {
|
||||
Collections.shuffle(chunks);
|
||||
for (Chunk chunk : chunks) {
|
||||
@@ -195,7 +195,7 @@ public class NodeHelper {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (nodeChanged) {
|
||||
updateNode(node, world);
|
||||
return true;
|
||||
@@ -204,8 +204,8 @@ public class NodeHelper {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void updateNode(INode nearestNode, World world) {
|
||||
|
||||
public static void updateNode(INode nearestNode, World world) {
|
||||
if (nearestNode instanceof TileEntity) {
|
||||
TileEntity tile = (TileEntity)nearestNode;
|
||||
tile.markDirty();
|
||||
@@ -227,7 +227,7 @@ public class NodeHelper {
|
||||
else if (nodeType == NodeType.NORMAL) {
|
||||
convertNodeToType(node, world, targetType);
|
||||
}
|
||||
|
||||
|
||||
if (nodeChanged) {
|
||||
updateNode(node, world);
|
||||
return true;
|
||||
@@ -236,7 +236,7 @@ public class NodeHelper {
|
||||
}
|
||||
return attemptedNodes < 10;
|
||||
}
|
||||
|
||||
|
||||
public static boolean convertNodeToType(INode node, World world, NodeType type) {
|
||||
if (world.rand.nextFloat() < conversionChances.get(type)) {
|
||||
node.setNodeType(type);
|
||||
|
||||
Reference in new issue
Block a user