mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-19 11:49:37 +00:00
More blocks
This commit is contained in:
1 parent
5f736bbe99
commit
a219aad6ee
5 files changed
+42
-236
No files matched your search
@@ -12,6 +12,8 @@ package vazkii.botania.common.block;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.block.BlockDoublePlant;
|
||||
import net.minecraft.block.BlockTallFlower;
|
||||
import net.minecraft.block.IGrowable;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
@@ -31,10 +33,14 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.IWorld;
|
||||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraft.world.IWorldReaderBase;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.common.IShearable;
|
||||
import vazkii.botania.api.lexicon.ILexiconable;
|
||||
import vazkii.botania.api.lexicon.LexiconEntry;
|
||||
import vazkii.botania.api.state.BotaniaStateProps;
|
||||
@@ -51,101 +57,39 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class BlockModDoubleFlower extends BlockDoublePlant implements ILexiconable, IModelRegister {
|
||||
private static final int COUNT = 8;
|
||||
public class BlockModDoubleFlower extends BlockTallFlower implements ILexiconable, IShearable {
|
||||
private final EnumDyeColor color;
|
||||
|
||||
private final boolean second;
|
||||
|
||||
public BlockModDoubleFlower(boolean second) {
|
||||
this.second = second;
|
||||
setHardness(0.0F);
|
||||
setSoundType(SoundType.PLANT);
|
||||
String name = LibBlockNames.DOUBLE_FLOWER + (second ? 2 : 1);
|
||||
setDefaultState(pickDefaultState());
|
||||
setRegistryName(new ResourceLocation(LibMisc.MOD_ID, name));
|
||||
setTranslationKey(name);
|
||||
setHardness(0F);
|
||||
setTickRandomly(false);
|
||||
setCreativeTab(BotaniaCreativeTab.INSTANCE);
|
||||
public BlockModDoubleFlower(EnumDyeColor color, Builder builder) {
|
||||
super(builder);
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public abstract BlockStateContainer createBlockState();
|
||||
|
||||
protected abstract IBlockState pickDefaultState();
|
||||
|
||||
@Override
|
||||
public abstract int getMetaFromState(IBlockState state);
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public abstract IBlockState getStateFromMeta(int meta);
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Item getItemDropped(IBlockState state, @Nonnull Random rand, int fortune) {
|
||||
public Item getItemDropped(IBlockState state, @Nonnull World world, @Nonnull BlockPos pos, int fortune) {
|
||||
return Items.AIR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int damageDropped(IBlockState state) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canGrow(@Nonnull World world, @Nonnull BlockPos pos, IBlockState state, boolean fuckifiknow) {
|
||||
public boolean canGrow(@Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull IBlockState state, boolean fuckifiknow) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// todo 1.13 re-evaluate shearability of these
|
||||
@Override
|
||||
public boolean canHarvestBlock(IBlockReader world, @Nonnull BlockPos pos, @Nonnull EntityPlayer player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockHarvested(World world, BlockPos pos, IBlockState state, @Nonnull EntityPlayer player) {
|
||||
if(state.get(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER) {
|
||||
if(world.getBlockState(pos.down()).getBlock() == this) {
|
||||
if (!player.capabilities.isCreativeMode) {
|
||||
// IBlockState iblockstate = worldIn.getBlockState(pos.down());
|
||||
// BlockDoublePlant.EnumPlantType blockdoubleplant$enumplanttype = (BlockDoublePlant.EnumPlantType) iblockstate.get(VARIANT);
|
||||
|
||||
//if (blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.FERN && blockdoubleplant$enumplanttype != BlockDoublePlant.EnumPlantType.GRASS) {
|
||||
// worldIn.destroyBlock(pos.down(), true);
|
||||
//} else if (!world.isRemote) {
|
||||
// if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.SHEARS) {
|
||||
// this.onHarvest(worldIn, pos, iblockstate, player);
|
||||
// world.setBlockToAir(pos.down());
|
||||
// } else {
|
||||
// world.destroyBlock(pos.down(), true);
|
||||
// }
|
||||
//} else {
|
||||
world.setBlockToAir(pos.down());
|
||||
//}
|
||||
} else {
|
||||
world.setBlockToAir(pos.down());
|
||||
}
|
||||
}
|
||||
} else if(player.capabilities.isCreativeMode && world.getBlockState(pos.up()).getBlock() == this)
|
||||
world.setBlockState(pos.up(), Blocks.AIR.getDefaultState(), 2);
|
||||
player.addStat(StatList.getBlockStats(this));
|
||||
//super.onBlockHarvested(p_149681_1_, p_149681_2_, p_149681_3_, p_149681_4_, p_149681_5_, p_149681_6_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShearable(ItemStack item, IBlockReader world, @Nonnull BlockPos pos) {
|
||||
public boolean isShearable(@Nonnull ItemStack item, IWorldReader world, BlockPos pos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<ItemStack> onSheared(ItemStack item, IBlockReader world, @Nonnull BlockPos pos, int fortune) {
|
||||
public List<ItemStack> onSheared(@Nonnull ItemStack item, IWorld world, @Nonnull BlockPos pos, int fortune) {
|
||||
ArrayList<ItemStack> ret = new ArrayList<>();
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
IBlockState stateBelow = world.getBlockState(pos.down());
|
||||
@@ -161,17 +105,10 @@ public abstract class BlockModDoubleFlower extends BlockDoublePlant implements I
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubBlocks(CreativeTabs tab, @Nonnull NonNullList<ItemStack> stacks) {
|
||||
for(int i = 0; i < COUNT; ++i)
|
||||
stacks.add(new ItemStack(this, 1, i));
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand) {
|
||||
state = getActualState(state, world, pos);
|
||||
int hex = state.get(second ? BotaniaStateProps.DOUBLEFLOWER_VARIANT_2 : BotaniaStateProps.DOUBLEFLOWER_VARIANT_1).getColorValue();
|
||||
public void animateTick(IBlockState state, World world, BlockPos pos, Random rand) {
|
||||
int hex = color.getColorValue();
|
||||
int r = (hex & 0xFF0000) >> 16;
|
||||
int g = (hex & 0xFF00) >> 8;
|
||||
int b = hex & 0xFF;
|
||||
@@ -185,34 +122,4 @@ public abstract class BlockModDoubleFlower extends BlockDoublePlant implements I
|
||||
public LexiconEntry getEntry(World world, BlockPos pos, EntityPlayer player, ItemStack lexicon) {
|
||||
return LexiconData.flowers;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IBlockState getActualState(IBlockState state, @Nonnull IBlockReader worldIn, @Nonnull BlockPos pos) {
|
||||
if (state.get(HALF) == BlockDoublePlant.EnumBlockHalf.UPPER) {
|
||||
IBlockState iblockstate = worldIn.getBlockState(pos.down());
|
||||
|
||||
if (iblockstate.getBlock() == this) {
|
||||
PropertyEnum<EnumDyeColor> prop = second ? BotaniaStateProps.DOUBLEFLOWER_VARIANT_2 : BotaniaStateProps.DOUBLEFLOWER_VARIANT_1;
|
||||
state = state.with(prop, iblockstate.get(prop));
|
||||
}
|
||||
}
|
||||
|
||||
return state.with(VARIANT, EnumPlantType.SUNFLOWER).with(FACING, EnumFacing.SOUTH);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getPickBlock(@Nonnull IBlockState state, RayTraceResult target, @Nonnull World world, @Nonnull BlockPos pos, EntityPlayer player) {
|
||||
state = state.getBlock().getActualState(state, world, pos);
|
||||
PropertyEnum<EnumDyeColor> prop = second ? BotaniaStateProps.DOUBLEFLOWER_VARIANT_2 : BotaniaStateProps.DOUBLEFLOWER_VARIANT_1;
|
||||
return new ItemStack(Item.getItemFromBlock(state.getBlock()), 1, state.get(prop).ordinal() - (second ? 8 : 0));
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
@Override
|
||||
public void registerModels() {
|
||||
ModelLoader.setCustomStateMapper(this, new StateMap.Builder().ignore(BlockDoublePlant.VARIANT, BlockDoublePlant.FACING).build());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user