TechReborn/src/main/java/techreborn/blocks/BlockMachineFrame.java

97 lines
3.4 KiB
Java
Raw Normal View History

/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2017 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 com.google.common.base.CaseFormat;
import net.minecraft.block.material.Material;
2015-11-26 22:48:30 +01:00
import net.minecraft.block.properties.PropertyInteger;
2016-03-13 17:08:30 +01:00
import net.minecraft.block.state.BlockStateContainer;
2015-11-23 20:51:40 +01:00
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
2015-11-23 20:19:18 +01:00
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2015-11-26 22:48:30 +01:00
import reborncore.common.BaseBlock;
import techreborn.client.TechRebornCreativeTab;
import techreborn.init.ModBlocks;
2016-05-01 05:01:10 +02:00
import java.security.InvalidParameterException;
2016-12-05 11:17:39 +01:00
public class BlockMachineFrame extends BaseBlock {
2016-10-08 21:46:16 +02:00
public static final String[] types = new String[] { "machine", "advancedMachine", "highlyAdvancedMachine" };
public static final PropertyInteger METADATA = PropertyInteger.create("type", 0, types.length - 1);
2016-03-25 10:47:34 +01:00
2016-10-08 21:46:16 +02:00
public BlockMachineFrame(Material material) {
super(material);
setUnlocalizedName("techreborn.machineFrame");
setCreativeTab(TechRebornCreativeTab.instance);
setHardness(1f);
this.setDefaultState(this.getDefaultState().withProperty(METADATA, 0));
}
2016-03-25 10:47:34 +01:00
2016-10-08 21:46:16 +02:00
public static ItemStack getFrameByName(String name, int count) {
name = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name);
2016-10-08 21:46:16 +02:00
for (int i = 0; i < types.length; i++) {
if (types[i].equalsIgnoreCase(name)) {
return new ItemStack(ModBlocks.MACHINE_FRAMES, count, i);
2016-10-08 21:46:16 +02:00
}
}
throw new InvalidParameterException("The part " + name + " could not be found.");
}
2016-03-25 10:47:34 +01:00
public static ItemStack getFrameByName(String name) {
return getFrameByName(name, 1);
}
2016-10-08 21:46:16 +02:00
@Override
@SideOnly(Side.CLIENT)
2017-06-11 22:22:07 +02:00
public void getSubBlocks(CreativeTabs creativeTabs, NonNullList<ItemStack> list) {
2016-10-08 21:46:16 +02:00
for (int meta = 0; meta < types.length; meta++) {
2017-06-11 22:22:07 +02:00
list.add(new ItemStack(this, 1, meta));
2016-10-08 21:46:16 +02:00
}
}
2016-03-25 10:47:34 +01:00
2016-10-08 21:46:16 +02:00
@Override
public int damageDropped(IBlockState state) {
return getMetaFromState(state);
}
2016-03-25 10:47:34 +01:00
2016-10-08 21:46:16 +02:00
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(METADATA);
}
2016-03-25 10:47:34 +01:00
2016-10-08 21:46:16 +02:00
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, METADATA);
}
2016-03-25 10:47:34 +01:00
2016-10-08 21:46:16 +02:00
@Override
public IBlockState getStateFromMeta(int meta) {
return this.getDefaultState().withProperty(METADATA, meta);
}
2016-03-25 10:47:34 +01:00
}