Rubber plank stairs and slab

This commit is contained in:
modmuss50 2018-06-08 21:05:56 +01:00
parent 169fa646fb
commit 60c8527f6d
No known key found for this signature in database
GPG key ID: 773D17BE8BF49C82
7 changed files with 311 additions and 0 deletions

View file

@ -0,0 +1,150 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2018 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package techreborn.blocks;
import net.minecraft.block.Block;
import net.minecraft.block.BlockSlab;
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.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import prospector.shootingstar.ShootingStar;
import prospector.shootingstar.model.ModelCompound;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.lib.ModInfo;
import java.util.Random;
//Thanks @Prospector you saved me me some time :)
public abstract class BlockRubberPlankSlab extends BlockSlab {
public static final PropertyEnum<Variant> VARIANT = PropertyEnum.create("variant", BlockRubberPlankSlab.Variant.class);
public final String name;
public Block halfslab;
public BlockRubberPlankSlab(String name) {
super(Material.WOOD, Material.WOOD.getMaterialMapColor());
this.name = name;
IBlockState iblockstate = this.blockState.getBaseState();
if (!this.isDouble()) {
iblockstate = iblockstate.withProperty(HALF, EnumBlockHalf.BOTTOM);
halfslab = this;
}
setCreativeTab(TechRebornCreativeTabMisc.instance);
setHarvestLevel("axe", 0);
setHardness(2.0F);
setResistance(15);
setSoundType(SoundType.WOOD);
this.setDefaultState(iblockstate.withProperty(VARIANT, BlockRubberPlankSlab.Variant.DEFAULT));
useNeighborBrightness = true;
ShootingStar.registerModel(new ModelCompound(ModInfo.MOD_ID, this));
}
@Override
public boolean isFlammable(IBlockAccess world, BlockPos pos, EnumFacing face) {
return true;
}
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
return Item.getItemFromBlock(halfslab);
}
public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) {
return new ItemStack(halfslab);
}
public IBlockState getStateFromMeta(int meta) {
IBlockState iblockstate = this.getDefaultState().withProperty(VARIANT, BlockRubberPlankSlab.Variant.DEFAULT);
if (!this.isDouble()) {
iblockstate = iblockstate.withProperty(HALF, (meta & 8) == 0 ? EnumBlockHalf.BOTTOM : EnumBlockHalf.TOP);
}
return iblockstate;
}
public int getMetaFromState(IBlockState state) {
int i = 0;
if (!this.isDouble() && state.getValue(HALF) == EnumBlockHalf.TOP) {
i |= 8;
}
return i;
}
protected BlockStateContainer createBlockState() {
return this.isDouble() ? new BlockStateContainer(this, new IProperty[] { VARIANT }) : new BlockStateContainer(this, new IProperty[] { HALF, VARIANT });
}
public String getUnlocalizedName(int meta) {
return super.getUnlocalizedName();
}
public IProperty<?> getVariantProperty() {
return VARIANT;
}
public Comparable<?> getTypeForItem(ItemStack stack) {
return BlockRubberPlankSlab.Variant.DEFAULT;
}
public static enum Variant implements IStringSerializable {
DEFAULT;
public String getName() {
return "default";
}
}
public static class BlockDouble extends BlockRubberPlankSlab {
public BlockDouble(String name, Block half) {
super(name);
this.halfslab = half;
}
public boolean isDouble() {
return true;
}
}
public static class BlockHalf extends BlockRubberPlankSlab {
public BlockHalf(String name) {
super(name);
}
public boolean isDouble() {
return false;
}
}
}

View file

@ -0,0 +1,42 @@
/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2018 TechReborn
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package techreborn.blocks;
import net.minecraft.block.BlockStairs;
import net.minecraft.block.state.IBlockState;
import prospector.shootingstar.ShootingStar;
import prospector.shootingstar.model.ModelCompound;
import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.lib.ModInfo;
public class BlockRubberPlankStair extends BlockStairs {
public BlockRubberPlankStair(IBlockState modelState, String name) {
super(modelState);
setCreativeTab(TechRebornCreativeTabMisc.instance);
useNeighborBrightness = true;
ShootingStar.registerModel(new ModelCompound(ModInfo.MOD_ID, this));
}
}

View file

@ -25,8 +25,10 @@
package techreborn.init;
import net.minecraft.block.Block;
import net.minecraft.block.BlockSlab;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemSlab;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.oredict.OreDictionary;
@ -120,6 +122,9 @@ public class ModBlocks {
public static Block NUKE;
public static Block RUBBER_LOG;
public static Block RUBBER_LOG_SLAB_HALF;
public static Block RUBBER_LOG_SLAB_DOUBLE;
public static Block RUBBER_LOG_STAIR;
public static Block RUBBER_LEAVES;
public static Block RUBBER_SAPLING;
public static Block RUBBER_PLANKS;
@ -296,6 +301,15 @@ public class ModBlocks {
RUBBER_PLANKS = new BlockRubberPlank();
registerBlock(RUBBER_PLANKS, "rubber_planks");
RUBBER_LOG_SLAB_HALF = new BlockRubberPlankSlab.BlockHalf("rubber_log");
registerBlockNoItem(RUBBER_LOG_SLAB_HALF, "rubber_plank_slab");
RUBBER_LOG_SLAB_DOUBLE = new BlockRubberPlankSlab.BlockDouble("rubber_plank", RUBBER_LOG_SLAB_HALF);
registerBlock(RUBBER_LOG_SLAB_DOUBLE, new ItemSlab(RUBBER_LOG_SLAB_HALF, (BlockSlab) RUBBER_LOG_SLAB_HALF, (BlockSlab) RUBBER_LOG_SLAB_DOUBLE) , "rubber_plank_double_slab");
RUBBER_LOG_STAIR = new BlockRubberPlankStair(RUBBER_LOG.getDefaultState(), "rubber_plank");
registerBlock(RUBBER_LOG_STAIR, "rubber_plank_stair");
RUBBER_LEAVES = new BlockRubberLeaves();
registerBlock(RUBBER_LEAVES, "rubber_leaves");
@ -395,6 +409,18 @@ public class ModBlocks {
RebornRegistry.registerBlock(block, itemclass, new ResourceLocation(ModInfo.MOD_ID, name));
}
public static void registerBlock(Block block, ItemBlock itemBlock, String name) {
name = name.toLowerCase();
block.setUnlocalizedName(ModInfo.MOD_ID + ":" + name);
RebornRegistry.registerBlock(block, itemBlock, new ResourceLocation(ModInfo.MOD_ID, name));
}
public static void registerBlockNoItem(Block block, String name) {
name = name.toLowerCase();
block.setUnlocalizedName(ModInfo.MOD_ID + ":" + name);
RebornRegistry.registerBlockNoItem(block, new ResourceLocation(ModInfo.MOD_ID, name));
}
/**
* Register ores and ore blocks
*/
@ -442,6 +468,7 @@ public class ModBlocks {
OreUtil.registerOre("logWood", new ItemStack(RUBBER_LOG, 1, OreDictionary.WILDCARD_VALUE));
OreUtil.registerOre("logRubber", new ItemStack(RUBBER_LOG, 1, OreDictionary.WILDCARD_VALUE));
OreUtil.registerOre("plankWood", new ItemStack(RUBBER_PLANKS, 1, OreDictionary.WILDCARD_VALUE));
OreUtil.registerOre("slabWood", new ItemStack(RUBBER_LOG_SLAB_HALF, 1, OreDictionary.WILDCARD_VALUE));
OreUtil.registerOre("plankRubber", new ItemStack(RUBBER_PLANKS, 1, OreDictionary.WILDCARD_VALUE));
OreUtil.registerOre("treeLeaves", new ItemStack(RUBBER_LEAVES, 1, OreDictionary.WILDCARD_VALUE));
OreUtil.registerOre("leavesRubber", new ItemStack(RUBBER_LEAVES, 1, OreDictionary.WILDCARD_VALUE));