Add tiny shrub log

This commit is contained in:
Nedelosk committed 2017-04-09 21:26:40 +02:00
1 parent 11c40fa158
commit 3919edcc3e
12 files changed
+555 -41

No files matched your search

@@ -0,0 +1,251 @@
package binnie.extratrees.block.wood;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
import binnie.Constants;
import binnie.core.models.DefaultStateMapper;
import binnie.extratrees.block.EnumShrubLog;
import forestry.api.arboriculture.IWoodType;
import forestry.api.arboriculture.WoodBlockKind;
import forestry.api.core.IItemModelRegister;
import forestry.api.core.IModelManager;
import forestry.api.core.IStateMapperRegister;
import forestry.apiculture.blocks.BlockAlveary;
import forestry.arboriculture.IWoodTyped;
import forestry.greenhouse.blocks.BlockGreenhouseDoor;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.state.pattern.BlockStateMatcher;
import net.minecraft.client.renderer.RenderItem;
import net.minecraft.client.renderer.block.statemap.BlockStateMapper;
import net.minecraft.client.renderer.block.statemap.StateMap;
import net.minecraft.entity.Entity;
import net.minecraft.item.Item;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Mirror;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockShrubLog extends Block implements IWoodTyped, IStateMapperRegister, IItemModelRegister {
public static final PropertyBool FIREPROOF = PropertyBool.create("fireproof");
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");
protected static final AxisAlignedBB[] BOUNDING_BOXES = new AxisAlignedBB[] {
new AxisAlignedBB(0.375D, 0.0D, 0.375D, 0.625D, 1.0D, 0.625D),
new AxisAlignedBB(0.375D, 0.0D, 0.375D, 0.625D, 1.0D, 1.0D),
new AxisAlignedBB(0.0D, 0.0D, 0.375D, 0.625D, 1.0D, 0.625D),
new AxisAlignedBB(0.0D, 0.0D, 0.375D, 0.625D, 1.0D, 1.0D),
new AxisAlignedBB(0.375D, 0.0D, 0.0D, 0.625D, 1.0D, 0.625D),
new AxisAlignedBB(0.375D, 0.0D, 0.0D, 0.625D, 1.0D, 1.0D),
new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.625D, 1.0D, 0.625D),
new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.625D, 1.0D, 1.0D),
new AxisAlignedBB(0.375D, 0.0D, 0.375D, 1.0D, 1.0D, 0.625D),
new AxisAlignedBB(0.375D, 0.0D, 0.375D, 1.0D, 1.0D, 1.0D),
new AxisAlignedBB(0.0D, 0.0D, 0.375D, 1.0D, 1.0D, 0.625D),
new AxisAlignedBB(0.0D, 0.0D, 0.375D, 1.0D, 1.0D, 1.0D),
new AxisAlignedBB(0.375D, 0.0D, 0.0D, 1.0D, 1.0D, 0.625D),
new AxisAlignedBB(0.375D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D),
new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.625D),
new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D) };
public static final AxisAlignedBB PILLAR_AABB = new AxisAlignedBB(0.375D, 0.0D, 0.375D, 0.625D, 1.5D, 0.625D);
public static final AxisAlignedBB SOUTH_AABB = new AxisAlignedBB(0.375D, 0.0D, 0.625D, 0.625D, 1.5D, 1.0D);
public static final AxisAlignedBB WEST_AABB = new AxisAlignedBB(0.0D, 0.0D, 0.375D, 0.375D, 1.5D, 0.625D);
public static final AxisAlignedBB NORTH_AABB = new AxisAlignedBB(0.375D, 0.0D, 0.0D, 0.625D, 1.5D, 0.375D);
public static final AxisAlignedBB EAST_AABB = new AxisAlignedBB(0.625D, 0.0D, 0.375D, 1.0D, 1.5D, 0.625D);
public BlockShrubLog() {
super(Material.WOOD);
this.setDefaultState(this.blockState.getBaseState()
.withProperty(NORTH, false)
.withProperty(EAST, false)
.withProperty(SOUTH, false)
.withProperty(WEST, false)
.withProperty(FIREPROOF, false));
setRegistryName(new ResourceLocation(Constants.EXTRA_TREES_MOD_ID, "shrub_log"));
setUnlocalizedName("shrub_log");
setSoundType(SoundType.WOOD);
}
@Override
public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox,
List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn, boolean p_185477_7_) {
if (!p_185477_7_) {
state = state.getActualState(worldIn, pos);
}
addCollisionBoxToList(pos, entityBox, collidingBoxes, PILLAR_AABB);
if (state.getValue(NORTH)) {
addCollisionBoxToList(pos, entityBox, collidingBoxes, NORTH_AABB);
}
if (state.getValue(EAST)) {
addCollisionBoxToList(pos, entityBox, collidingBoxes, EAST_AABB);
}
if (state.getValue(SOUTH)) {
addCollisionBoxToList(pos, entityBox, collidingBoxes, SOUTH_AABB);
}
if (state.getValue(WEST)) {
addCollisionBoxToList(pos, entityBox, collidingBoxes, WEST_AABB);
}
}
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
state = this.getActualState(state, source, pos);
return BOUNDING_BOXES[getBoundingBoxIdx(state)];
}
private static int getBoundingBoxIdx(IBlockState state) {
int i = 0;
if (state.getValue(NORTH)) {
i |= 1 << EnumFacing.NORTH.getHorizontalIndex();
}
if (state.getValue(EAST)) {
i |= 1 << EnumFacing.EAST.getHorizontalIndex();
}
if (state.getValue(SOUTH)) {
i |= 1 << EnumFacing.SOUTH.getHorizontalIndex();
}
if (state.getValue(WEST)) {
i |= 1 << EnumFacing.WEST.getHorizontalIndex();
}
return i;
}
@Override
public boolean isOpaqueCube(IBlockState state) {
return false;
}
@Override
public boolean isFullCube(IBlockState state) {
return false;
}
@Override
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos,
EnumFacing side) {
return true;
}
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(FIREPROOF) ? 1 : 0;
}
@Override
public IBlockState getStateFromMeta(int meta) {
return getDefaultState().withProperty(FIREPROOF, meta == 1);
}
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
return state.withProperty(NORTH, canFenceConnectTo(worldIn, pos, EnumFacing.NORTH))
.withProperty(EAST, canFenceConnectTo(worldIn, pos, EnumFacing.EAST))
.withProperty(SOUTH, canFenceConnectTo(worldIn, pos, EnumFacing.SOUTH))
.withProperty(WEST, canFenceConnectTo(worldIn, pos, EnumFacing.WEST));
}
private boolean canFenceConnectTo(IBlockAccess world, BlockPos pos, EnumFacing facing) {
IBlockState blockState = world.getBlockState(pos.offset(facing));
Block block = blockState.getBlock();
return block.isLeaves(blockState, world, pos);
}
@Override
public IBlockState withRotation(IBlockState state, Rotation rot) {
switch (rot) {
case CLOCKWISE_180:
return state.withProperty(NORTH, state.getValue(SOUTH)).withProperty(EAST, state.getValue(WEST))
.withProperty(SOUTH, state.getValue(NORTH)).withProperty(WEST, state.getValue(EAST));
case COUNTERCLOCKWISE_90:
return state.withProperty(NORTH, state.getValue(EAST)).withProperty(EAST, state.getValue(SOUTH))
.withProperty(SOUTH, state.getValue(WEST)).withProperty(WEST, state.getValue(NORTH));
case CLOCKWISE_90:
return state.withProperty(NORTH, state.getValue(WEST)).withProperty(EAST, state.getValue(NORTH))
.withProperty(SOUTH, state.getValue(EAST)).withProperty(WEST, state.getValue(SOUTH));
default:
return state;
}
}
@Override
public IBlockState withMirror(IBlockState state, Mirror mirrorIn) {
switch (mirrorIn) {
case LEFT_RIGHT:
return state.withProperty(NORTH, state.getValue(SOUTH)).withProperty(SOUTH, state.getValue(NORTH));
case FRONT_BACK:
return state.withProperty(EAST, state.getValue(WEST)).withProperty(WEST, state.getValue(EAST));
default:
return super.withMirror(state, mirrorIn);
}
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, new IProperty[] { NORTH, EAST, WEST, SOUTH, FIREPROOF });
}
@Override
public WoodBlockKind getBlockKind() {
return WoodBlockKind.LOG;
}
@SideOnly(Side.CLIENT)
@Override
public void registerStateMapper() {
ModelLoader.setCustomStateMapper(this, new StateMap.Builder().ignore(FIREPROOF).build());
}
@SideOnly(Side.CLIENT)
@Override
public void registerModel(Item item, IModelManager manager) {
manager.registerItemModel(item, 0, "shrub_trunk");
manager.registerItemModel(item, 1, "shrub_trunk");
}
//TODO: Add meta to forestry api
@Override
public boolean isFireproof() {
return false;
}
@Override
public IWoodType getWoodType(int meta) {
return EnumShrubLog.INSTANCE;
}
@Override
public Collection<? extends IWoodType> getWoodTypes() {
return Collections.singletonList(EnumShrubLog.INSTANCE);
}
}