下面列出了怎么用net.minecraftforge.common.EnumPlantType的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable)
{
IBlockState plant = plantable.getPlant(world, pos.offset(direction));
net.minecraftforge.common.EnumPlantType plantType = plantable.getPlantType(world, pos.offset(direction));
if(plantType == EnumPlantType.Crop)
return true;
if(plantType == EnumPlantType.Plains)
return true;
if(plantable == TFCBlocks.Sapling)
return true;
return false;
}
@Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable)
{
IBlockState plant = plantable.getPlant(world, pos.offset(direction));
EnumPlantType plantType = plantable.getPlantType(world, pos.offset(direction));
VegType veg = (VegType)state.getValue(META_PROPERTY);
if(plant.getBlock() == this)
{
if(veg == VegType.DoubleGrassBottom && plant.getValue(META_PROPERTY) == VegType.DoubleGrassTop)
return true;
if(veg == VegType.DoubleGrassBottomLush && plant.getValue(META_PROPERTY) == VegType.DoubleGrassTopLush)
return true;
}
return false;
}
@Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable)
{
IBlockState plant = plantable.getPlant(world, pos.offset(direction));
net.minecraftforge.common.EnumPlantType plantType = plantable.getPlantType(world, pos.offset(direction));
if(plant.getBlock() == Blocks.SAPLING)
return false;//This may break some cross mod compatability but for now its needed to prevent vanilla and some pam trees from generating
if(plantType == EnumPlantType.Plains)
return true;
if(plant.getBlock() == TFCBlocks.VegDesert)
return true;
return false;
}
@Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable)
{
EnumPlantType type = plantable.getPlantType(world, pos.offset(direction));
EnumPlantType[] sustainedPlants = getContent().sustainedPlants.get(getSubtype(state)).orElse(null);
if (sustainedPlants != null)
{
return ArrayUtils.contains(sustainedPlants, type);
} else
{
return super.canSustainPlant(state, world, pos, direction, plantable);
}
}
@Override
public EnumPlantType deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
{
if (json.isJsonPrimitive())
{
JsonPrimitive primitive = json.getAsJsonPrimitive();
if (primitive.isString())
{
return EnumPlantType.getPlantType(json.getAsString());
}
}
throw new JsonParseException("Invalid plant type: " + json);
}
@Test
public void test()
{
Map<String, EnumPlantType> map = gson.fromJson("{ \"plant\": \"Crop\" }", new TypeToken<Map<String, EnumPlantType>>() {}.getType());
EnumPlantType plant = map.get("plant");
assertSame(EnumPlantType.Crop, plant);
}
public ItemSeedBase(String name, IBlockState plant) {
super();
this.setRegistryName("itemSeed" + StringUtils.capitalize(name));
this.setUnlocalizedName("itemSeed" + StringUtils.capitalize(name));
this.plant = plant;
this.name = name;
type = EnumPlantType.Plains;
GameRegistry.<Item>register(this);
}
@Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable)
{
IBlockState plant = plantable.getPlant(world, pos.offset(direction));
EnumPlantType plantType = plantable.getPlantType(world, pos.offset(direction));
if(plantable == TFCBlocks.Vegetation && (VegType)plant.getValue(BlockVegetation.META_PROPERTY) == VegType.Grass)
return true;
return false;
}
/*******************************************************************************
* 1. Content
*******************************************************************************/
@Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable)
{
IBlockState plant = plantable.getPlant(world, pos.offset(direction));
net.minecraftforge.common.EnumPlantType plantType = plantable.getPlantType(world, pos.offset(direction));
if(plantType == EnumPlantType.Plains)
return true;
return false;
}
@Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable)
{
IBlockState plant = plantable.getPlant(world, pos.offset(direction));
EnumPlantType plantType = plantable.getPlantType(world, pos.offset(direction));
DesertCactusType veg = (DesertCactusType)state.getValue(META_PROPERTY);
if(plant.getBlock() == this)
{
}
return false;
}
@Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable)
{
IBlockState plant = plantable.getPlant(world, pos.offset(direction));
EnumPlantType plantType = plantable.getPlantType(world, pos.offset(direction));
DesertVegType veg = (DesertVegType)state.getValue(META_PROPERTY);
if(plant.getBlock() == this)
{
if(veg == DesertVegType.DoubleGrassBottomSparse && plant.getValue(META_PROPERTY) == DesertVegType.DoubleGrassTopSparse)
return true;
}
return false;
}
@Override
public boolean canSustainPlant (IBlockAccess world, int x, int y, int z, ForgeDirection direction, IPlantable plantable) {
TileEntityGarden gardenTile = getTileEntity(world, x, y, z);
EnumPlantType plantType = plantable.getPlantType(world, x, y, z);
if (plantType == EnumPlantType.Crop)
return substrateSupportsCrops(gardenTile.getSubstrate());
return false;
}
@Override
public boolean canSustainPlant (IBlockAccess world, int x, int y, int z, ForgeDirection direction, IPlantable plantable) {
EnumPlantType plantType = plantable.getPlantType(world, x, y, z);
if (plantType == EnumPlantType.Crop)
return true;
return false;
}
@Override
public EnumPlantType getPlantType(IBlockAccess world, BlockPos pos)
{
return EnumPlantType.Crop;
}
@Override
public EnumPlantType getPlantType(IBlockAccess world, BlockPos pos)
{
return EnumPlantType.Crop;
}
@Override
public EnumPlantType getPlantType(IBlockAccess world, BlockPos pos)
{
return EnumPlantType.Crop;
}
@Override
public net.minecraftforge.common.EnumPlantType getPlantType(net.minecraft.world.IBlockAccess world, BlockPos pos) {
return EnumPlantType.Plains;
}
@Override
public net.minecraftforge.common.EnumPlantType getPlantType(net.minecraft.world.IBlockAccess world, BlockPos pos) {
return EnumPlantType.Plains;
}
@Override
public net.minecraftforge.common.EnumPlantType getPlantType(net.minecraft.world.IBlockAccess world, BlockPos pos) {
return EnumPlantType.Plains;
}
@Override
public net.minecraftforge.common.EnumPlantType getPlantType(net.minecraft.world.IBlockAccess world, BlockPos pos) {
return EnumPlantType.Plains;
}
@Override
public EnumPlantType getPlantType(IBlockAccess world, BlockPos pos) {
return EnumPlantType.Crop;
}
@Override
public EnumPlantType getPlantType(IBlockAccess world, BlockPos pos) {
return EnumPlantType.Crop;
}
@Override
public EnumPlantType getPlantType(IBlockAccess world, BlockPos pos) {
return EnumPlantType.Plains;
}
@Override
public EnumPlantType getPlantType(IBlockAccess world, BlockPos pos) {
return EnumPlantType.Plains;
}
@Override
public EnumPlantType getPlantType(IBlockAccess world, BlockPos pos) {
return EnumPlantType.Plains;
}
@Override
public net.minecraftforge.common.EnumPlantType getPlantType(net.minecraft.world.IBlockAccess world, BlockPos pos) {
return EnumPlantType.Plains;
}
@Override
public net.minecraftforge.common.EnumPlantType getPlantType(net.minecraft.world.IBlockAccess world, BlockPos pos) {
return EnumPlantType.Plains;
}
@Override
public net.minecraftforge.common.EnumPlantType getPlantType(net.minecraft.world.IBlockAccess world, BlockPos pos) {
return EnumPlantType.Plains;
}
@Override
public net.minecraftforge.common.EnumPlantType getPlantType(net.minecraft.world.IBlockAccess world, BlockPos pos) {
return EnumPlantType.Plains;
}
@Override
public net.minecraftforge.common.EnumPlantType getPlantType(net.minecraft.world.IBlockAccess world, BlockPos pos) {
return EnumPlantType.Plains;
}