Flatten more blocks

This commit is contained in:
Vincent Lee committed 2019-02-08 01:35:11 -06:00
1 parent ea41348ded
commit 0a9a3aa9a6
29 files changed
+478 -630

No files matched your search

@@ -15,10 +15,7 @@ import net.minecraft.block.BlockDoublePlant;
import net.minecraft.block.BlockFlower;
import net.minecraft.block.IGrowable;
import net.minecraft.block.SoundType;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.statemap.StateMap;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemStack;
@@ -27,7 +24,7 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.api.distmarker.Dist;
@@ -47,81 +44,17 @@ import vazkii.botania.common.lib.LibMisc;
import javax.annotation.Nonnull;
import java.util.Random;
public class BlockModFlower extends BlockFlower implements ILexiconable, IGrowable, IModelRegister {
private static final AxisAlignedBB AABB = new AxisAlignedBB(0.3, 0, 0.3, 0.8, 1, 0.8);
protected BlockModFlower() {
this(LibBlockNames.FLOWER);
}
protected BlockModFlower(String name) {
setTranslationKey(name);
setDefaultState(blockState.getBaseState().withProperty(BotaniaStateProps.COLOR, EnumDyeColor.WHITE).withProperty(type, EnumFlowerType.POPPY));
setRegistryName(new ResourceLocation(LibMisc.MOD_ID, name));
setHardness(0F);
setSoundType(SoundType.PLANT);
setTickRandomly(false);
setCreativeTab(registerInCreative() ? BotaniaCreativeTab.INSTANCE : null);
}
@Nonnull
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, @Nonnull IBlockAccess world, @Nonnull BlockPos pos) {
return AABB.offset(state.getOffset(world, pos));
}
@Nonnull
@Override
public BlockStateContainer createBlockState() {
return new BlockStateContainer(this, getTypeProperty(), BotaniaStateProps.COLOR);
}
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(BotaniaStateProps.COLOR).getMetadata();
}
@Nonnull
@Override
public IBlockState getStateFromMeta(int meta) {
if (meta >= EnumDyeColor.values().length) {
meta = 0;
}
return getDefaultState().withProperty(BotaniaStateProps.COLOR, EnumDyeColor.byMetadata(meta));
}
@Nonnull
@Override
public IBlockState getActualState(@Nonnull IBlockState state, IBlockAccess world, BlockPos pos) {
return state.withProperty(type, EnumFlowerType.POPPY);
}
@Nonnull
@Override
public EnumFlowerColor getBlockType() {
return EnumFlowerColor.RED;
}
public boolean registerInCreative() {
return true;
}
@Override
public void getSubBlocks(CreativeTabs tab, @Nonnull NonNullList<ItemStack> stacks) {
for(int i = 0; i < 16; i++)
stacks.add(new ItemStack(this, 1, i));
}
@Override
public int damageDropped(IBlockState state) {
return getMetaFromState(state);
public class BlockModFlower extends BlockFlower implements ILexiconable, IGrowable {
private final EnumDyeColor color;
protected BlockModFlower(EnumDyeColor color, Builder builder) {
super(builder);
this.color = color;
}
@OnlyIn(Dist.CLIENT)
@Override
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand) {
int hex = state.getValue(BotaniaStateProps.COLOR).getColorValue();
public void animateTick(IBlockState state, World world, BlockPos pos, Random rand) {
int hex = this.color.getColorValue();
int r = (hex & 0xFF0000) >> 16;
int g = (hex & 0xFF00) >> 8;
int b = hex & 0xFF;
@@ -140,8 +73,8 @@ public class BlockModFlower extends BlockFlower implements ILexiconable, IGrowab
}
@Override
public boolean canGrow(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state, boolean fuckifiknow) {
return world.isAirBlock(pos.up());
public boolean canGrow(@Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull IBlockState state, boolean fuckifiknow) {
return world.getBlockState(pos.up()).isAir(world, pos);
}
@Override
@@ -151,7 +84,7 @@ public class BlockModFlower extends BlockFlower implements ILexiconable, IGrowab
@Override
public void grow(@Nonnull World world, @Nonnull Random rand, @Nonnull BlockPos pos, @Nonnull IBlockState state) {
placeDoubleFlower(world, pos, state.getValue(BotaniaStateProps.COLOR), 1 | 2);
placeDoubleFlower(world, pos, color, 1 | 2);
}
public static void placeDoubleFlower(World world, BlockPos pos, EnumDyeColor color, int flags) {
@@ -159,11 +92,4 @@ public class BlockModFlower extends BlockFlower implements ILexiconable, IGrowab
world.setBlockState(pos, flower.getDefaultState().withProperty(color.getMetadata() >= 8 ? BotaniaStateProps.DOUBLEFLOWER_VARIANT_2 : BotaniaStateProps.DOUBLEFLOWER_VARIANT_1, color).withProperty(BlockDoublePlant.HALF, BlockDoublePlant.EnumBlockHalf.LOWER), flags);
world.setBlockState(pos.up(), flower.getDefaultState().withProperty(color.getMetadata() >= 8 ? BotaniaStateProps.DOUBLEFLOWER_VARIANT_2 : BotaniaStateProps.DOUBLEFLOWER_VARIANT_1, color).withProperty(BlockDoublePlant.HALF, BlockDoublePlant.EnumBlockHalf.UPPER), flags);
}
@OnlyIn(Dist.CLIENT)
@Override
public void registerModels() {
ModelLoader.setCustomStateMapper(this, new StateMap.Builder().ignore(getTypeProperty()).build());
ModelHandler.registerCustomItemblock(this, EnumDyeColor.values().length, i -> "flower_" + EnumDyeColor.byMetadata(i).getName());
}
}