Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.theviolentsquirrels.questsystem.block;
- import net.minecraft.block.Block;
- import net.minecraft.block.properties.PropertyBool;
- import net.minecraft.block.properties.PropertyEnum;
- import net.minecraft.block.state.BlockState;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.creativetab.CreativeTabs;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.util.*;
- import net.minecraft.world.IBlockAccess;
- import net.minecraft.world.World;
- import net.minecraftforge.fml.relauncher.Side;
- import net.minecraftforge.fml.relauncher.SideOnly;
- import net.theviolentsquirrels.questsystem.Main;
- import java.util.List;
- public class BlockWallCustom extends Block implements IMetaBlockName {
- public static final PropertyEnum<EnumType> VARIANT = PropertyEnum.create("variant", EnumType.class);
- public static final PropertyBool UP = PropertyBool.create("up");
- public static final PropertyBool NORTH = PropertyBool.create("north");
- public static final PropertyBool EAST = PropertyBool.create("east");
- public static final PropertyBool SOUTH = PropertyBool.create("south");
- public static final PropertyBool WEST = PropertyBool.create("west");
- public BlockWallCustom(String unlocalizedName, Block modelBlock) {
- super (modelBlock.getMaterial());
- this.setUnlocalizedName(unlocalizedName);
- this.setHardness(2.0f);
- this.setResistance(3.0f);
- this.setStepSound(modelBlock.stepSound);
- this.setCreativeTab(Main.tab);
- this.setDefaultState(this.blockState.getBaseState()
- .withProperty(VARIANT, EnumType.STONEBRICK)
- .withProperty(UP, false)
- .withProperty(NORTH, false)
- .withProperty(EAST, false)
- .withProperty(SOUTH, false)
- .withProperty(WEST, false));
- }
- @Override
- public String getMetadataName(ItemStack stack) {
- return (EnumType.META_LOOKUP[stack.getItemDamage()].getName());
- }
- @Override
- public ItemStack getPickBlock(MovingObjectPosition target, World world,
- BlockPos pos, EntityPlayer player) {
- return (new ItemStack(Item.getItemFromBlock(this), 1, this.getMetaFromState(world.getBlockState(pos))));
- }
- @Override
- public boolean isFullCube() {
- return (false);
- }
- @Override
- public boolean isPassable(IBlockAccess worldIn, BlockPos pos) {
- return (false);
- }
- @Override
- public boolean isOpaqueCube() {
- return (false);
- }
- public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos) {
- boolean flag = this.canConnectTo(worldIn, pos.north());
- boolean flag1 = this.canConnectTo(worldIn, pos.south());
- boolean flag2 = this.canConnectTo(worldIn, pos.west());
- boolean flag3 = this.canConnectTo(worldIn, pos.east());
- float f = 0.25F;
- float f1 = 0.75F;
- float f2 = 0.25F;
- float f3 = 0.75F;
- float f4 = 1.0F;
- if (flag) f2 = 0.0F;
- if (flag1) f3 = 1.0F;
- if (flag2) f = 0.0F;
- if (flag3) f1 = 1.0F;
- if (flag && flag1 && !flag2 && !flag3) {
- f4 = 0.8125F;
- f = 0.3125F;
- f1 = 0.6875F;
- } else if (!flag && !flag1 && flag2 && flag3) {
- f4 = 0.8125F;
- f2 = 0.3125F;
- f3 = 0.6875F;
- }
- this.setBlockBounds(f, 0.0F, f2, f1, f4, f3);
- }
- public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state) {
- this.setBlockBoundsBasedOnState(worldIn, pos);
- this.maxY = 1.5D;
- return (super.getCollisionBoundingBox(worldIn, pos, state));
- }
- /**
- * W.I.P !
- * @param worldIn
- * @param pos
- * @return
- */
- public boolean canConnectTo(IBlockAccess worldIn, BlockPos pos) {
- Block block = worldIn.getBlockState(pos).getBlock();
- /*return (block == Blocks.barrier ? false :
- (block != this && !(block instanceof BlockFenceGate) ? (block.blockMaterial.isOpaque() && block.isFullCube() ? block.blockMaterial != Material.gourd :
- false) :
- true));*/
- return (block == this);
- }
- @SideOnly(Side.CLIENT)
- @Override
- public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list) {
- for (EnumType enumType : EnumType.values()) {
- list.add(new ItemStack(itemIn, 1, enumType.getMetadata()));
- }
- }
- @Override
- public int damageDropped(IBlockState state) {
- return (state.getValue(VARIANT).getMetadata());
- }
- @SideOnly(Side.CLIENT)
- @Override
- public boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side) {
- return (side == EnumFacing.DOWN ? super.shouldSideBeRendered(worldIn, pos, side) : true);
- }
- @Override
- public IBlockState getStateFromMeta(int meta) {
- return (this.getDefaultState().withProperty(VARIANT, EnumType.byMetadata(meta)));
- }
- @Override
- public int getMetaFromState(IBlockState state) {
- return (state.getValue(VARIANT).getMetadata());
- }
- public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
- return (state
- .withProperty(UP, !worldIn.isAirBlock(pos.up()))
- .withProperty(NORTH, this.canConnectTo(worldIn, pos.north()))
- .withProperty(EAST, this.canConnectTo(worldIn, pos.east()))
- .withProperty(SOUTH, this.canConnectTo(worldIn, pos.south()))
- .withProperty(WEST, this.canConnectTo(worldIn, pos.west())));
- }
- @Override
- protected BlockState createBlockState() {
- return (new BlockState(this, VARIANT, UP, NORTH, EAST, SOUTH, WEST));
- }
- public enum EnumType implements IStringSerializable {
- STONEBRICK(0, "stonebrick"),
- NETHER_BRICK(1, "nether_brick");
- private static final EnumType[] META_LOOKUP = new EnumType[values().length];
- private final int meta;
- private final String name;
- EnumType(int meta, String name) {
- this.meta = meta;
- this.name = name;
- }
- public int getMetadata() {
- return (this.meta);
- }
- public String toString() {
- return (this.name);
- }
- public static EnumType byMetadata(int meta) {
- if (meta < 0 || meta >= META_LOOKUP.length) meta = 0;
- return (META_LOOKUP[meta]);
- }
- public String getName() {
- return (this.name);
- }
- static {
- for (EnumType enumType : values()) {
- META_LOOKUP[enumType.getMetadata()] = enumType;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement