mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-21 04:22:32 +00:00
Add mutation condition requireResource(String oreDictName)
This commit is contained in:
1 parent
8df8404a84
commit
a4dd450ff8
4 files changed
+84
-3
No files matched your search
@@ -111,6 +111,12 @@ public abstract class Mutation implements IMutationCustom {
|
||||
return addMutationCondition(mutationCondition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mutation requireResource(String oreName) {
|
||||
IMutationCondition mutationCondition = new MutationConditionRequiresResourceOreDict(oreName);
|
||||
return addMutationCondition(mutationCondition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mutation addMutationCondition(IMutationCondition mutationCondition) {
|
||||
mutationConditions.add(mutationCondition);
|
||||
|
||||
+10
-2
@@ -14,6 +14,7 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.apiculture.IBeeHousing;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IGenome;
|
||||
import forestry.api.genetics.IMutationCondition;
|
||||
@@ -30,8 +31,15 @@ public class MutationConditionRequiresResource implements IMutationCondition {
|
||||
|
||||
@Override
|
||||
public float getChance(World world, int x, int y, int z, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
|
||||
Block block = world.getBlock(x, y - 1, z);
|
||||
int meta = world.getBlockMetadata(x, y - 1, z);
|
||||
Block block;
|
||||
int meta;
|
||||
int i = 1;
|
||||
do {
|
||||
block = world.getBlock(x, y - i, z);
|
||||
meta = world.getBlockMetadata(x, y - i, z);
|
||||
i++;
|
||||
} while (block instanceof IBeeHousing);
|
||||
|
||||
return ItemStackUtil.equals(block, meta, blockRequired) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.genetics.mutations;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import forestry.api.apiculture.IBeeHousing;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IGenome;
|
||||
import forestry.api.genetics.IMutationCondition;
|
||||
import forestry.core.utils.StringUtil;
|
||||
|
||||
public class MutationConditionRequiresResourceOreDict implements IMutationCondition {
|
||||
|
||||
private final int oreDictId;
|
||||
private final String displayName;
|
||||
|
||||
public MutationConditionRequiresResourceOreDict(String oreDictName) {
|
||||
this.oreDictId = OreDictionary.getOreID(oreDictName);
|
||||
|
||||
ArrayList<ItemStack> ores = OreDictionary.getOres(oreDictName);
|
||||
if (ores != null && 0 < ores.size()) {
|
||||
this.displayName = ores.get(0).getDisplayName();
|
||||
} else {
|
||||
this.displayName = oreDictName;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getChance(World world, int x, int y, int z, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
|
||||
Block block;
|
||||
int meta;
|
||||
int i = 1;
|
||||
do {
|
||||
block = world.getBlock(x, y - i, z);
|
||||
meta = world.getBlockMetadata(x, y - i, z);
|
||||
i++;
|
||||
} while (block instanceof IBeeHousing);
|
||||
|
||||
int[] oreIds = OreDictionary.getOreIDs(new ItemStack(block, 1, meta));
|
||||
for (int oreId : oreIds) {
|
||||
if (oreId == this.oreDictId) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return StringUtil.localizeAndFormat("mutation.condition.resource", displayName);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user