mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-21 20:42:35 +00:00
Fix #1330 Fix resource checks for resources below an Alveary
This commit is contained in:
1 parent
e34b71c13e
commit
95135544e2
8 files changed
+72
-118
No files matched your search
@@ -5,12 +5,12 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.apiculture;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
|
||||
public interface IJubilanceFactory {
|
||||
/** The default Jubilance Provider is satisfied when the humidity and temperature are ideal for the bee. */
|
||||
IJubilanceProvider getDefault();
|
||||
|
||||
/** The Requires Resource Jubilance Provider is satisfied when a specific block is under the hive. */
|
||||
IJubilanceProvider getRequiresResource(Block block, int meta);
|
||||
IJubilanceProvider getRequiresResource(IBlockState... acceptedBlockStates);
|
||||
}
|
||||
@@ -5,13 +5,10 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.genetics;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
|
||||
import net.minecraftforge.common.BiomeDictionary;
|
||||
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraftforge.common.BiomeDictionary;
|
||||
|
||||
/** Set custom mutation requirements */
|
||||
public interface IMutationBuilder {
|
||||
@@ -46,7 +43,7 @@ public interface IMutationBuilder {
|
||||
IMutationBuilder requireNight();
|
||||
|
||||
/** Require a specific resource to be under the location of the mutation */
|
||||
IMutationBuilder requireResource(IBlockState requiredBlockState);
|
||||
IMutationBuilder requireResource(IBlockState... acceptedBlockStates);
|
||||
|
||||
IMutationBuilder requireResource(String oreDictName);
|
||||
|
||||
|
||||
@@ -10,10 +10,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.genetics;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
import forestry.api.apiculture.IJubilanceFactory;
|
||||
import forestry.api.apiculture.IJubilanceProvider;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
|
||||
public class JubilanceFactory implements IJubilanceFactory {
|
||||
@Override
|
||||
@@ -22,7 +21,7 @@ public class JubilanceFactory implements IJubilanceFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IJubilanceProvider getRequiresResource(Block block, int meta) {
|
||||
return new JubilanceRequiresResource(block, meta);
|
||||
public IJubilanceProvider getRequiresResource(IBlockState... acceptedBlockStates) {
|
||||
return new JubilanceRequiresResource(acceptedBlockStates);
|
||||
}
|
||||
}
|
||||
@@ -10,33 +10,40 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.genetics;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import forestry.api.apiculture.IAlleleBeeSpecies;
|
||||
import forestry.api.apiculture.IBeeGenome;
|
||||
import forestry.api.apiculture.IBeeHousing;
|
||||
import forestry.api.apiculture.IJubilanceProvider;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class JubilanceRequiresResource implements IJubilanceProvider {
|
||||
|
||||
private final ItemStack blockRequired;
|
||||
private final Set<IBlockState> acceptedBlockStates = new HashSet<>();
|
||||
|
||||
public JubilanceRequiresResource(Block block, int meta) {
|
||||
this.blockRequired = new ItemStack(block, meta);
|
||||
public JubilanceRequiresResource(IBlockState... acceptedBlockStates) {
|
||||
Collections.addAll(this.acceptedBlockStates, acceptedBlockStates);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJubilant(IAlleleBeeSpecies species, IBeeGenome genome, IBeeHousing housing) {
|
||||
World world = housing.getWorldObj();
|
||||
BlockPos housingCoords = housing.getCoordinates();
|
||||
BlockPos pos = housing.getCoordinates();
|
||||
|
||||
IBlockState state = world.getBlockState(housingCoords.down());
|
||||
return ItemStackUtil.equals(state, blockRequired);
|
||||
TileEntity tile;
|
||||
do {
|
||||
pos = pos.down();
|
||||
tile = world.getTileEntity(pos);
|
||||
} while (tile instanceof IBeeHousing && pos.getY() > 0);
|
||||
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
return this.acceptedBlockStates.contains(blockState);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,13 +14,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.BiomeDictionary;
|
||||
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.genetics.IAllele;
|
||||
@@ -29,6 +22,10 @@ import forestry.api.genetics.IGenome;
|
||||
import forestry.api.genetics.IMutation;
|
||||
import forestry.api.genetics.IMutationBuilder;
|
||||
import forestry.api.genetics.IMutationCondition;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.BiomeDictionary;
|
||||
|
||||
public abstract class Mutation implements IMutation, IMutationBuilder {
|
||||
|
||||
@@ -109,14 +106,14 @@ public abstract class Mutation implements IMutation, IMutationBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mutation requireResource(IBlockState blockState) {
|
||||
IMutationCondition mutationCondition = new MutationConditionRequiresResource(blockState);
|
||||
public Mutation requireResource(IBlockState... acceptedBlockStates) {
|
||||
IMutationCondition mutationCondition = new MutationConditionRequiresResource(acceptedBlockStates);
|
||||
return addMutationCondition(mutationCondition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mutation requireResource(String oreName) {
|
||||
IMutationCondition mutationCondition = new MutationConditionRequiresResourceOreDict(oreName);
|
||||
IMutationCondition mutationCondition = new MutationConditionRequiresResource(oreName);
|
||||
return addMutationCondition(mutationCondition);
|
||||
}
|
||||
|
||||
|
||||
+37
-12
@@ -10,38 +10,63 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.genetics.mutations;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import forestry.api.apiculture.IBeeHousing;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IGenome;
|
||||
import forestry.api.genetics.IMutationCondition;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.Translator;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
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 net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
public class MutationConditionRequiresResource implements IMutationCondition {
|
||||
|
||||
private final IBlockState requiredBlockState;
|
||||
private final Set<IBlockState> acceptedBlockStates = new HashSet<>();
|
||||
private final String displayName;
|
||||
|
||||
public MutationConditionRequiresResource(IBlockState requiredBlockState) {
|
||||
this.requiredBlockState = requiredBlockState;
|
||||
public MutationConditionRequiresResource(String oreDictName) {
|
||||
this.displayName = oreDictName;
|
||||
for (ItemStack ore : OreDictionary.getOres(oreDictName)) {
|
||||
if (ore != null) {
|
||||
Item oreItem = ore.getItem();
|
||||
if (oreItem != null) {
|
||||
Block oreBlock = Block.getBlockFromItem(oreItem);
|
||||
if (oreBlock != null) {
|
||||
this.acceptedBlockStates.addAll(oreBlock.getBlockState().getValidStates());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public MutationConditionRequiresResource(IBlockState... acceptedBlockStates) {
|
||||
Collections.addAll(this.acceptedBlockStates, acceptedBlockStates);
|
||||
this.displayName = acceptedBlockStates[0].getBlock().getLocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getChance(World world, BlockPos pos, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
|
||||
IBlockState blockState;
|
||||
TileEntity tile;
|
||||
do {
|
||||
pos = pos.down();
|
||||
blockState = world.getBlockState(pos);
|
||||
} while (blockState.getBlock() instanceof IBeeHousing);
|
||||
tile = world.getTileEntity(pos);
|
||||
} while (tile instanceof IBeeHousing);
|
||||
|
||||
return this.requiredBlockState == blockState ? 1 : 0;
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
return this.acceptedBlockStates.contains(blockState) ? 1 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return Translator.translateToLocalFormatted("for.mutation.condition.resource", requiredBlockState.getBlock().getLocalizedName());
|
||||
return Translator.translateToLocalFormatted("for.mutation.condition.resource", displayName);
|
||||
}
|
||||
}
|
||||
-71
@@ -1,71 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* 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.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
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.Translator;
|
||||
|
||||
public class MutationConditionRequiresResourceOreDict implements IMutationCondition {
|
||||
|
||||
private final int oreDictId;
|
||||
private final String displayName;
|
||||
|
||||
public MutationConditionRequiresResourceOreDict(String oreDictName) {
|
||||
this.oreDictId = OreDictionary.getOreID(oreDictName);
|
||||
|
||||
List<ItemStack> ores = OreDictionary.getOres(oreDictName);
|
||||
if (ores != null && !ores.isEmpty()) {
|
||||
this.displayName = ores.get(0).getDisplayName();
|
||||
} else {
|
||||
this.displayName = oreDictName;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getChance(World world, BlockPos pos, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
|
||||
Block block;
|
||||
int meta;
|
||||
int i = 1;
|
||||
do {
|
||||
BlockPos blockPos = new BlockPos(pos.getX(), pos.getY() - i, pos.getY());
|
||||
IBlockState blockState = world.getBlockState(blockPos);
|
||||
block = blockState.getBlock();
|
||||
meta = block.getMetaFromState(blockState);
|
||||
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 Translator.translateToLocalFormatted("for.mutation.condition.resource", displayName);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user