From 6b886e1ef2386f8c9200494331abb26f77318d2f Mon Sep 17 00:00:00 2001 From: Adubbz Date: Fri, 21 Apr 2017 21:26:33 +1000 Subject: [PATCH] Added bone segment blocks --- .../biomesoplenty/api/block/BOPBlocks.java | 1 + .../common/block/BlockBOPBoneSegment.java | 141 ++++++++++++++++++ .../biomesoplenty/common/init/ModBlocks.java | 3 +- .../blockstates/bone_segment.json | 13 ++ .../assets/biomesoplenty/lang/en_US.lang | 2 + .../models/block/medium_bone_segment.json | 21 +++ .../models/block/small_bone_segment.json | 21 +++ .../models/item/medium_bone_segment.json | 3 + .../models/item/small_bone_segment.json | 3 + 9 files changed, 207 insertions(+), 1 deletion(-) create mode 100644 src/main/java/biomesoplenty/common/block/BlockBOPBoneSegment.java create mode 100644 src/main/resources/assets/biomesoplenty/blockstates/bone_segment.json create mode 100644 src/main/resources/assets/biomesoplenty/models/block/medium_bone_segment.json create mode 100644 src/main/resources/assets/biomesoplenty/models/block/small_bone_segment.json create mode 100644 src/main/resources/assets/biomesoplenty/models/item/medium_bone_segment.json create mode 100644 src/main/resources/assets/biomesoplenty/models/item/small_bone_segment.json diff --git a/src/main/java/biomesoplenty/api/block/BOPBlocks.java b/src/main/java/biomesoplenty/api/block/BOPBlocks.java index 491ae9a56..94afbaf65 100644 --- a/src/main/java/biomesoplenty/api/block/BOPBlocks.java +++ b/src/main/java/biomesoplenty/api/block/BOPBlocks.java @@ -24,6 +24,7 @@ public class BOPBlocks public static Block mushroom; public static Block stone; public static Block biome_block; + public static Block bone_segment; public static Block flower_0; public static Block flower_1; diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPBoneSegment.java b/src/main/java/biomesoplenty/common/block/BlockBOPBoneSegment.java new file mode 100644 index 000000000..0b98623ef --- /dev/null +++ b/src/main/java/biomesoplenty/common/block/BlockBOPBoneSegment.java @@ -0,0 +1,141 @@ +/******************************************************************************* + * Copyright 2014-2017, the Biomes O' Plenty Team + * + * This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License. + * + * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/. + ******************************************************************************/ +package biomesoplenty.common.block; + +import biomesoplenty.common.item.ItemBOPBlock; +import net.minecraft.block.BlockRotatedPillar; +import net.minecraft.block.SoundType; +import net.minecraft.block.material.Material; +import net.minecraft.block.properties.IProperty; +import net.minecraft.block.properties.PropertyEnum; +import net.minecraft.block.state.BlockStateContainer; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.color.IBlockColor; +import net.minecraft.client.renderer.color.IItemColor; +import net.minecraft.item.ItemBlock; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.IStringSerializable; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IBlockAccess; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class BlockBOPBoneSegment extends BlockRotatedPillar implements IBOPBlock +{ + public static enum BoneType implements IStringSerializable + { + SMALL, MEDIUM; + @Override + public String getName() + { + return this.name().toLowerCase(); + } + @Override + public String toString() + { + return this.getName(); + } + }; + public static final PropertyEnum VARIANT = PropertyEnum.create("variant", BoneType.class); + @Override + protected BlockStateContainer createBlockState() {return new BlockStateContainer(this, new IProperty[] { VARIANT, AXIS });} + + // implement IBOPBlock + @Override + public Class getItemClass() { return ItemBOPBlock.class; } + @Override + public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; } + @Override + public IProperty[] getNonRenderingProperties() { return null; } + @Override + public String getStateName(IBlockState state) + { + return ((BoneType) state.getValue(VARIANT)).getName() + "_bone_segment"; + } + @Override + @SideOnly(Side.CLIENT) + public IBlockColor getBlockColor() { return null; } + @Override + @SideOnly(Side.CLIENT) + public IItemColor getItemColor() { return null; } + + public BlockBOPBoneSegment() + { + super(Material.ROCK); + + // set some defaults + this.setHardness(5.0F); + this.setResistance(10.0F); + this.setSoundType(SoundType.STONE); + this.setHarvestLevel("pickaxe", 0); + this.setDefaultState( this.blockState.getBaseState().withProperty(VARIANT, BoneType.SMALL)); + } + + @Override + public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess world, BlockPos pos) + { + double x1, y1 = 0.0D, z1, x2, y2 = 1.0D, z2; + + switch (state.getValue(VARIANT)) + { + case SMALL: + x1 = z1 = 0.25D; + x2 = z2 = 0.75D; + break; + case MEDIUM: default: + x1 = z1 = 0.125D; + x2 = z2 = 0.875D; + break; + } + + switch (state.getValue(AXIS)) + { + case Y: + return new AxisAlignedBB(x1, y1, z1, x2, y2, z2); + + case Z: + return new AxisAlignedBB(x1, z1, y1, x2, z2, y2); + + default: + return new AxisAlignedBB(y1, x1, z1, y2, x2, z2); + } + } + + @Override + public AxisAlignedBB getCollisionBoundingBox(IBlockState state, IBlockAccess world, BlockPos pos) + { + return getBoundingBox(state, world, pos); + } + + @Override + public boolean isOpaqueCube(IBlockState state) + { + return false; + } + + // map from state to meta and vice verca + @Override + public IBlockState getStateFromMeta(int meta) + { + return super.getStateFromMeta(meta).withProperty(VARIANT, BoneType.values()[meta & 3]); + } + + @Override + public int getMetaFromState(IBlockState state) + { + return super.getMetaFromState(state) | state.getValue(VARIANT).ordinal(); + } + + // our blocks usually drop their current state as opposed to a single 'default' state + @Override + public int damageDropped(IBlockState state) + { + return this.getMetaFromState(state.withProperty(AXIS, EnumFacing.Axis.X)); + } +} diff --git a/src/main/java/biomesoplenty/common/init/ModBlocks.java b/src/main/java/biomesoplenty/common/init/ModBlocks.java index 16432413b..4fb465502 100644 --- a/src/main/java/biomesoplenty/common/init/ModBlocks.java +++ b/src/main/java/biomesoplenty/common/init/ModBlocks.java @@ -84,6 +84,7 @@ public class ModBlocks hive = registerBlock( new BlockBOPHive(), "hive" ); honey_block = registerBlock( new BlockBOPHoney(), "honey_block" ); jelled_poison = registerBlock( new BlockBOPJelledPoison(), "jelled_poison" ); + bone_segment = registerBlock( new BlockBOPBoneSegment(), "bone_segment" ); //Material Blocks bamboo_thatching = registerBlock( (new BlockBOPGeneric(Material.WOOD, SoundType.WOOD)).setHardness(2.0F), "bamboo_thatching"); bamboo_thatching.setHarvestLevel("axe", 0); @@ -370,7 +371,7 @@ public class ModBlocks } catch (Exception e) { - throw new RuntimeException("An error occurred associating an item block during registration..."); + throw new RuntimeException("An error occurred associating an item block during registration...", e); } } diff --git a/src/main/resources/assets/biomesoplenty/blockstates/bone_segment.json b/src/main/resources/assets/biomesoplenty/blockstates/bone_segment.json new file mode 100644 index 000000000..6d13c4ef7 --- /dev/null +++ b/src/main/resources/assets/biomesoplenty/blockstates/bone_segment.json @@ -0,0 +1,13 @@ +{ + "variants": { + "axis=y,variant=small": { "model": "biomesoplenty:small_bone_segment" }, + "axis=z,variant=small": { "model": "biomesoplenty:small_bone_segment", "x": 90 }, + "axis=x,variant=small": { "model": "biomesoplenty:small_bone_segment", "x": 90, "y": 90 }, + "axis=none,variant=small": { "model": "biomesoplenty:small_bone_segment" }, + "axis=y,variant=medium": { "model": "biomesoplenty:medium_bone_segment" }, + "axis=z,variant=medium": { "model": "biomesoplenty:medium_bone_segment", "x": 90 }, + "axis=x,variant=medium": { "model": "biomesoplenty:medium_bone_segment", "x": 90, "y": 90 }, + "axis=none,variant=medium": { "model": "biomesoplenty:medium_bone_segment" } + } +} + diff --git a/src/main/resources/assets/biomesoplenty/lang/en_US.lang b/src/main/resources/assets/biomesoplenty/lang/en_US.lang index 270e5febb..2fd21fece 100644 --- a/src/main/resources/assets/biomesoplenty/lang/en_US.lang +++ b/src/main/resources/assets/biomesoplenty/lang/en_US.lang @@ -177,6 +177,8 @@ tile.ash_block.name=Ash Block tile.bamboo.name=Bamboo tile.bamboo_thatching.name=Bamboo Thatching tile.biome_block.name=Biome Essence Ore +tile.bone_segment.small_bone_segment.name=Small Bone Segment +tile.bone_segment.medium_bone_segment.name=Medium Bone Segment tile.cherry_fence.name=Cherry Fence tile.cherry_fence_gate.name=Cherry Fence Gate tile.cherry_wood_slab.name=Cherry Wood Slab diff --git a/src/main/resources/assets/biomesoplenty/models/block/medium_bone_segment.json b/src/main/resources/assets/biomesoplenty/models/block/medium_bone_segment.json new file mode 100644 index 000000000..b9ea0cad4 --- /dev/null +++ b/src/main/resources/assets/biomesoplenty/models/block/medium_bone_segment.json @@ -0,0 +1,21 @@ +{ + "parent": "block/block", + "textures": { + "end": "blocks/bone_block_top", + "side": "blocks/bone_block_side", + "particle": "blocks/bone_block_side" + }, + "elements": [ + { "from": [ 2, 0, 2 ], + "to": [ 14, 16, 14 ], + "faces": { + "down": { "uv": [ 4, 4, 12, 12 ], "texture": "#end", "cullface": "down" }, + "up": { "uv": [ 4, 4, 12, 12 ], "texture": "#end" }, + "north": { "uv": [ 2, 2, 14, 14 ], "texture": "#side", "cullface": "north" }, + "south": { "uv": [ 2, 2, 14, 14 ], "texture": "#side", "cullface": "south" }, + "west": { "uv": [ 2, 2, 14, 14 ], "texture": "#side", "cullface": "west" }, + "east": { "uv": [ 2, 2, 14, 14 ], "texture": "#side", "cullface": "east" } + } + } + ] +} diff --git a/src/main/resources/assets/biomesoplenty/models/block/small_bone_segment.json b/src/main/resources/assets/biomesoplenty/models/block/small_bone_segment.json new file mode 100644 index 000000000..fffe43e56 --- /dev/null +++ b/src/main/resources/assets/biomesoplenty/models/block/small_bone_segment.json @@ -0,0 +1,21 @@ +{ + "parent": "block/block", + "textures": { + "end": "blocks/bone_block_top", + "side": "blocks/bone_block_side", + "particle": "blocks/bone_block_side" + }, + "elements": [ + { "from": [ 4, 0, 4 ], + "to": [ 12, 16, 12 ], + "faces": { + "down": { "uv": [ 6, 6, 10, 10 ], "texture": "#end", "cullface": "down" }, + "up": { "uv": [ 6, 6, 10, 10 ], "texture": "#end" }, + "north": { "uv": [ 4, 4, 12, 12 ], "texture": "#side", "cullface": "north" }, + "south": { "uv": [ 4, 4, 12, 12 ], "texture": "#side", "cullface": "south" }, + "west": { "uv": [ 4, 4, 12, 12 ], "texture": "#side", "cullface": "west" }, + "east": { "uv": [ 4, 4, 12, 12 ], "texture": "#side", "cullface": "east" } + } + } + ] +} diff --git a/src/main/resources/assets/biomesoplenty/models/item/medium_bone_segment.json b/src/main/resources/assets/biomesoplenty/models/item/medium_bone_segment.json new file mode 100644 index 000000000..a9b32c505 --- /dev/null +++ b/src/main/resources/assets/biomesoplenty/models/item/medium_bone_segment.json @@ -0,0 +1,3 @@ +{ + "parent": "biomesoplenty:block/medium_bone_segment" +} \ No newline at end of file diff --git a/src/main/resources/assets/biomesoplenty/models/item/small_bone_segment.json b/src/main/resources/assets/biomesoplenty/models/item/small_bone_segment.json new file mode 100644 index 000000000..823138f21 --- /dev/null +++ b/src/main/resources/assets/biomesoplenty/models/item/small_bone_segment.json @@ -0,0 +1,3 @@ +{ + "parent": "biomesoplenty:block/small_bone_segment" +} \ No newline at end of file