Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small QoL Bee Update #2458

Merged
merged 4 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package gregtech.integration.forestry.mutation;

import gregtech.api.unification.material.Material;

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.util.text.translation.I18n;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;

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 forestry.core.utils.Translator;

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 = I18n.translateToLocal("gregtech.mutation.block_of") + " " + material.getLocalizedName();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this, with the material name separate, you could have the lang entry as "Requires block of %s", and then just pass the material name into the lang call

String oredictName = "block" + capitalize(material.getName());

for (ItemStack ore : OreDictionary.getOres(oredictName)) {
Rundas01 marked this conversation as resolved.
Show resolved Hide resolved
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 Translator.translateToLocalFormatted("for.mutation.condition.resource", this.displayName);
Rundas01 marked this conversation as resolved.
Show resolved Hide resolved
}
}
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
Loading