-
Notifications
You must be signed in to change notification settings - Fork 181
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
bruberu
merged 4 commits into
GregTechCEu:master
from
Rundas01:materialmutationcondition
Jun 2, 2024
Merged
Small QoL Bee Update #2458
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
src/main/java/gregtech/integration/forestry/mutation/MaterialMutationCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
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
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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