Skip to content

Commit

Permalink
Small QoL Bee Update (GregTechCEu#2458)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rundas01 authored Jun 2, 2024
1 parent f8c1a52 commit 00f3b4d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package gregtech.integration.forestry.mutation;

import gregtech.api.unification.OreDictUnifier;
import gregtech.api.unification.material.Material;
import gregtech.api.util.LocalizationUtils;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import forestry.api.apiculture.IBeeHousing;
import forestry.api.climate.IClimateProvider;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IGenome;
import forestry.api.genetics.IMutationCondition;
import forestry.core.tiles.TileUtil;

import java.util.HashSet;
import java.util.Set;

import static org.apache.commons.lang3.StringUtils.capitalize;

public class MaterialMutationCondition implements IMutationCondition {

private final Set<IBlockState> acceptedBlocks = new HashSet();
private final String displayName;

public MaterialMutationCondition(Material material) {
this.displayName = LocalizationUtils.format("gregtech.mutation.block_of", material.getLocalizedName());
String oredictName = "block" + capitalize(material.getName());

for (ItemStack ore : OreDictUnifier.getAllWithOreDictionaryName(oredictName)) {
if (!ore.isEmpty()) {
Item oreItem = ore.getItem();
Block oreBlock = Block.getBlockFromItem(oreItem);
if (oreBlock != Blocks.AIR) {
this.acceptedBlocks.addAll(oreBlock.getBlockState().getValidStates());
}
}
}
}

public float getChance(World world, BlockPos pos, IAllele allele0, IAllele allele1, IGenome genome0,
IGenome genome1, IClimateProvider climate) {
TileEntity tile;
do {
pos = pos.down();
tile = TileUtil.getTile(world, pos);
} while (tile instanceof IBeeHousing);

IBlockState blockState = world.getBlockState(pos);
return this.acceptedBlocks.contains(blockState) ? 1.0F : 0.0F;
}

public String getDescription() {
return LocalizationUtils.format("for.mutation.condition.resource", this.displayName);
}
}
3 changes: 3 additions & 0 deletions src/main/resources/assets/gregtech/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -6286,3 +6286,6 @@ gregtech.scanner.forestry.larvae=§oScanned Larvae
gregtech.scanner.forestry.serum=§oScanned Serum
gregtech.scanner.forestry.caterpillar=§oScanned Caterpillar
gregtech.scanner.forestry.pollen=§oScanned Pollen

# Mutation
gregtech.mutation.block_of=Block of %s

0 comments on commit 00f3b4d

Please sign in to comment.