Created
August 19, 2016 00:10
-
-
Save StillManic/d9ff6dff1ad593496a2e67c01f3e6247 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"forge_marker": 1, | |
"defaults": { | |
"model": "transitmod:bench_metallic.obj", | |
"transform": "forge:default-block" | |
}, | |
"variants": { | |
"inventory": [{}], | |
"horizontals": { | |
"north": {}, | |
"south": {"y": 180}, | |
"west": {"y": 270}, | |
"east": {"y": 90} | |
}, | |
"wooden": { | |
"true": {"model": "transitmod:bench_wooden.obj"}, | |
"false": {} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net.minecraft.block.material.MapColor; | |
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.client.renderer.block.model.ModelResourceLocation; | |
import net.minecraft.creativetab.CreativeTabs; | |
import net.minecraft.entity.EntityLivingBase; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.init.Blocks; | |
import net.minecraft.item.Item; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.util.*; | |
import net.minecraft.util.math.BlockPos; | |
import net.minecraft.world.IBlockAccess; | |
import net.minecraft.world.World; | |
import net.minecraftforge.common.property.ExtendedBlockState; | |
import net.minecraftforge.common.property.IExtendedBlockState; | |
import net.minecraftforge.common.property.IUnlistedProperty; | |
import net.minecraftforge.fml.relauncher.Side; | |
import net.minecraftforge.fml.relauncher.SideOnly; | |
import org.bitbucket.transitauthority.transitmod.TransitMod; | |
import org.bitbucket.transitauthority.transitmod.multiblock.structures_new.StructureManagerNew; | |
import org.bitbucket.transitauthority.transitmod.util.OBJModel; | |
import java.util.List; | |
public class BlockBench extends BlockStructureMaster { | |
public static final PropertyBool WOODEN = PropertyBool.create("wooden"); | |
public static final BlockBench INSTANCE = new BlockBench(); | |
// public static final BlockBench INSTANCE_WOODEN = new BlockBench(true); | |
// public static final BlockBench INSTANCE_METALLIC = new BlockBench(false); | |
public static final ModelResourceLocation LOCATION = new ModelResourceLocation(TransitMod.MODID + ":bench", "inventory"); | |
private ExtendedBlockState state = new ExtendedBlockState(this, new IProperty[]{TransitBlocks.HORIZONTALS, WOODEN}, new IUnlistedProperty[]{OBJModel.OBJProperty.instance}); | |
public BlockBench() { | |
super(Material.IRON, "bench", new ResourceLocation(TransitMod.MODID, "bench"), TransitMod.tabTransit); | |
this.setDefaultState(this.blockState.getBaseState().withProperty(TransitBlocks.HORIZONTALS, EnumFacing.NORTH).withProperty(WOODEN, false)); | |
} | |
// public BlockBench(boolean wooden) { | |
// super(wooden ? Material.WOOD : Material.IRON, wooden ? "benchWooden" : "benchMetallic", new ResourceLocation(TransitMod.MODID, "bench"), TransitMod.tabTransit); | |
// this.setDefaultState(this.blockState.getBaseState().withProperty(TransitBlocks.HORIZONTALS, EnumFacing.NORTH).withProperty(WOODEN, wooden)); | |
// } | |
@Override | |
public int damageDropped(IBlockState state) { | |
return state.getValue(WOODEN) ? 1 : 0; | |
} | |
@Override | |
@SideOnly(Side.CLIENT) | |
public void getSubBlocks(Item item, CreativeTabs tab, List<ItemStack> list) { | |
list.add(new ItemStack(item., 1, 0)); //metallic | |
list.add(new ItemStack(item, 1, 1)); //wooden | |
} | |
@Override | |
public ItemStack createStackedBlock(IBlockState state) { | |
return new ItemStack(this, 1, state.getValue(WOODEN) ? 1 : 0); | |
} | |
@Override | |
public Material getMaterial(IBlockState state) { | |
return state.getValue(WOODEN) ? Material.WOOD : Material.IRON; | |
} | |
@Override | |
@SideOnly(Side.CLIENT) | |
public MapColor getMapColor(IBlockState state) { | |
return state.getValue(WOODEN) ? Material.WOOD.getMaterialMapColor() : Material.IRON.getMaterialMapColor(); | |
} | |
@Override | |
public BlockRenderLayer getBlockLayer() { | |
return BlockRenderLayer.CUTOUT; | |
} | |
@Override | |
public IBlockState withRotation(IBlockState state, Rotation rotation) { | |
return state.withProperty(TransitBlocks.HORIZONTALS, rotation.rotate(state.getValue(TransitBlocks.HORIZONTALS))); | |
} | |
@Override | |
public IBlockState withMirror(IBlockState state, Mirror mirror) { | |
return state.withProperty(TransitBlocks.HORIZONTALS, mirror.mirror(state.getValue(TransitBlocks.HORIZONTALS))); | |
} | |
@Override | |
public IBlockState onBlockPlaced(World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { | |
if (this.buildStructure(world, pos, placer.getHorizontalFacing())) | |
return this.getDefaultState().withProperty(TransitBlocks.HORIZONTALS, placer.getHorizontalFacing()).withProperty(WOODEN, meta == 1); | |
else return Blocks.AIR.getDefaultState(); | |
} | |
@Override | |
public void breakBlock(World world, BlockPos pos, IBlockState state) { | |
if (StructureManagerNew.INSTANCE.breakStructure(world, pos, pos)) world.setBlockToAir(pos); | |
} | |
@Override | |
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack stack, EnumFacing side, float hitX, float hitY, float hitZ) { | |
//TODO: implement sitting on bench! | |
return false; | |
} | |
@Override | |
public IBlockState getStateFromMeta(int meta) { | |
return this.getDefaultState().withProperty(TransitBlocks.HORIZONTALS, EnumFacing.getHorizontal(meta & 3)).withProperty(WOODEN, (meta & 4) == 0); | |
} | |
@Override | |
public int getMetaFromState(IBlockState state) { | |
int meta = state.getValue(WOODEN) ? 4 : 0; | |
meta |= state.getValue(TransitBlocks.HORIZONTALS).getHorizontalIndex(); | |
return meta; | |
} | |
@Override | |
public BlockStateContainer createBlockState() { | |
return new ExtendedBlockState(this, new IProperty[]{TransitBlocks.HORIZONTALS, WOODEN}, new IUnlistedProperty[]{OBJModel.OBJProperty.instance}); | |
} | |
@Override | |
public IBlockState getExtendedState(IBlockState state, IBlockAccess world, BlockPos pos) { | |
OBJModel.OBJState retState = new OBJModel.OBJState(); | |
//TODO: combine the bench models together? | |
// retState.showConfig(state.getValue(WOODEN) ? "wooden" : "metallic"); | |
return ((IExtendedBlockState) this.state.getBaseState()).withProperty(OBJModel.OBJProperty.instance, retState); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.common.collect.Lists; | |
import com.google.common.collect.Maps; | |
import net.minecraft.block.Block; | |
import net.minecraft.block.properties.IProperty; | |
import net.minecraft.block.properties.PropertyDirection; | |
import net.minecraft.block.properties.PropertyEnum; | |
import net.minecraft.block.state.IBlockState; | |
import net.minecraft.client.renderer.block.model.ModelResourceLocation; | |
import net.minecraft.client.renderer.block.statemap.StateMapperBase; | |
import net.minecraft.creativetab.CreativeTabs; | |
import net.minecraft.init.Blocks; | |
import net.minecraft.item.Item; | |
import net.minecraft.item.ItemBlock; | |
import net.minecraft.tileentity.TileEntity; | |
import net.minecraft.util.EnumFacing; | |
import net.minecraftforge.client.model.ModelLoader; | |
import net.minecraftforge.fml.client.registry.ClientRegistry; | |
import net.minecraftforge.fml.common.registry.GameRegistry; | |
import net.minecraftforge.fml.relauncher.Side; | |
import org.bitbucket.transitauthority.transitmod.TransitMod; | |
import org.bitbucket.transitauthority.transitmod.block.tileentity.TileEntityBusLift; | |
import org.bitbucket.transitauthority.transitmod.block.tileentity.TileEntityBusLiftPlatform; | |
import org.bitbucket.transitauthority.transitmod.block.tileentity.TileEntityGasLamp; | |
import org.bitbucket.transitauthority.transitmod.client.render.RenderBusLift; | |
import org.bitbucket.transitauthority.transitmod.client.render.RenderBusLiftPlatform; | |
import java.util.Map; | |
public class TransitBlocks { | |
public static final PropertyDirection HORIZONTALS = PropertyDirection.create("horizontals", EnumFacing.Plane.HORIZONTAL); | |
public static final PropertyDirection FACING = PropertyDirection.create("facing"); | |
public static final PropertyEnum<EnumFacing.Axis> AXES_H = PropertyEnum.create("axes_h", EnumFacing.Axis.class, Lists.newArrayList(EnumFacing.Axis.X, EnumFacing.Axis.Z)); | |
public static final PropertyEnum<EnumFacing.Axis> AXES = PropertyEnum.create("axes", EnumFacing.Axis.class); | |
public static void preInit(Side side) { | |
registerBlock(BlockBusLift.INSTANCE, getStandardItemBlock(BlockBusLift.INSTANCE), TileEntityBusLift.class); | |
registerBlock(BlockBusLiftPlatform.INSTANCE, TransitMod.isRunningInDev ? getStandardItemBlock(BlockBusLiftPlatform.INSTANCE) : null, TileEntityBusLiftPlatform.class); | |
registerBlock(BlockGasLamp.INSTANCE, getStandardItemBlock(BlockGasLamp.INSTANCE), TileEntityGasLamp.class); | |
registerBlock(BlockBench.INSTANCE, getStandardItemBlock(BlockBench.INSTANCE), null); | |
// registerBlock(BlockBench.INSTANCE_WOODEN, getStandardItemBlock(BlockBench.INSTANCE_WOODEN), null); | |
// registerBlock(BlockBench.INSTANCE_METALLIC, getStandardItemBlock(BlockBench.INSTANCE_METALLIC), null); | |
if (TransitMod.isRunningInDev) { | |
Blocks.COMMAND_BLOCK.setCreativeTab(CreativeTabs.REDSTONE); | |
Blocks.STRUCTURE_BLOCK.setCreativeTab(CreativeTabs.REDSTONE); | |
Blocks.STRUCTURE_VOID.setCreativeTab(CreativeTabs.REDSTONE); | |
} | |
if (side == Side.CLIENT) { | |
if (TransitMod.isRunningInDev) { | |
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(BlockBusLiftPlatform.INSTANCE), 0, BlockBusLiftPlatform.LOCATION); | |
} | |
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(BlockBusLift.INSTANCE), 0, BlockBusLift.LOCATION); | |
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(BlockGasLamp.INSTANCE), 0, BlockGasLamp.LOCATION); | |
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(BlockBench.INSTANCE), 0, BlockBench.LOCATION); | |
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(BlockBench.INSTANCE), 1, BlockBench.LOCATION); | |
ModelLoader.setCustomStateMapper(BlockBench.INSTANCE, (new StateMapperBase() { | |
@Override | |
protected ModelResourceLocation getModelResourceLocation(IBlockState state) { | |
Map<IProperty<?>, Comparable<?>> map = Maps.newLinkedHashMap(state.getProperties()); | |
return new ModelResourceLocation(TransitMod.MODID + ":bench", state.getValue(BlockBench.WOODEN) ? "inventory" : "wooden=true"); | |
} | |
})); | |
// ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(BlockBench.INSTANCE_WOODEN), 0, BlockBench.LOCATION); | |
// ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(BlockBench.INSTANCE_METALLIC), 0, BlockBench.LOCATION); | |
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityBusLift.class, new RenderBusLift()); | |
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityBusLiftPlatform.class, new RenderBusLiftPlatform()); | |
RenderBusLift.preInit(); | |
RenderBusLiftPlatform.preInit(); | |
} | |
} | |
public static void registerBlock(Block block, ItemBlock itemBlock, Class<? extends TileEntity> tileEntityClass) { | |
GameRegistry.register(block); | |
if (itemBlock != null) GameRegistry.register(itemBlock); | |
if (tileEntityClass != null) GameRegistry.registerTileEntity(tileEntityClass, block.getRegistryName().toString()); | |
} | |
public static ItemBlock getStandardItemBlock(Block block) { | |
return (ItemBlock) new ItemBlock(block).setRegistryName(block.getRegistryName()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment