-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: King Lemming <kinglemming@gmail.com>
- Loading branch information
1 parent
87e1838
commit 5d90508
Showing
9 changed files
with
324 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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
249 changes: 249 additions & 0 deletions
249
src/main/java/cofh/thermalfoundation/block/BlockStorageResource.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,249 @@ | ||
package cofh.thermalfoundation.block; | ||
|
||
import cofh.core.block.BlockCore; | ||
import cofh.core.render.IModelRegister; | ||
import cofh.core.util.core.IInitializer; | ||
import cofh.thermalfoundation.ThermalFoundation; | ||
import net.minecraft.block.SoundType; | ||
import net.minecraft.block.material.MapColor; | ||
import net.minecraft.block.material.Material; | ||
import net.minecraft.block.properties.PropertyEnum; | ||
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.Entity; | ||
import net.minecraft.init.Items; | ||
import net.minecraft.item.EnumRarity; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.IStringSerializable; | ||
import net.minecraft.util.NonNullList; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.Explosion; | ||
import net.minecraft.world.IBlockAccess; | ||
import net.minecraft.world.World; | ||
import net.minecraftforge.client.model.ModelLoader; | ||
import net.minecraftforge.fml.common.registry.ForgeRegistries; | ||
import net.minecraftforge.fml.relauncher.Side; | ||
import net.minecraftforge.fml.relauncher.SideOnly; | ||
|
||
import static cofh.core.util.helpers.ItemHelper.registerWithHandlers; | ||
import static cofh.core.util.helpers.RecipeHelper.addStorageRecipe; | ||
|
||
public class BlockStorageResource extends BlockCore implements IInitializer, IModelRegister { | ||
|
||
public static final PropertyEnum<Type> VARIANT = PropertyEnum.create("type", Type.class); | ||
|
||
public BlockStorageResource() { | ||
|
||
super(Material.ROCK, MapColor.BLACK, "thermalfoundation"); | ||
|
||
setUnlocalizedName("storage"); | ||
setCreativeTab(ThermalFoundation.tabCommon); | ||
|
||
setHardness(5.0F); | ||
setResistance(10.0F); | ||
setSoundType(SoundType.STONE); | ||
setDefaultState(getBlockState().getBaseState().withProperty(VARIANT, Type.CHARCOAL)); | ||
|
||
setHarvestLevel("pickaxe", 0); | ||
} | ||
|
||
@Override | ||
protected BlockStateContainer createBlockState() { | ||
|
||
return new BlockStateContainer(this, VARIANT); | ||
} | ||
|
||
@Override | ||
public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> items) { | ||
|
||
for (int i = 0; i < Type.METADATA_LOOKUP.length; i++) { | ||
items.add(new ItemStack(this, 1, i)); | ||
} | ||
} | ||
|
||
/* TYPE METHODS */ | ||
@Override | ||
public IBlockState getStateFromMeta(int meta) { | ||
|
||
return this.getDefaultState().withProperty(VARIANT, Type.byMetadata(meta)); | ||
} | ||
|
||
@Override | ||
public int getMetaFromState(IBlockState state) { | ||
|
||
return state.getValue(VARIANT).getMetadata(); | ||
} | ||
|
||
@Override | ||
public int damageDropped(IBlockState state) { | ||
|
||
return state.getValue(VARIANT).getMetadata(); | ||
} | ||
|
||
/* BLOCK METHODS */ | ||
@Override | ||
public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos) { | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos) { | ||
|
||
return state.getValue(VARIANT).getLight(); | ||
} | ||
|
||
@Override | ||
public float getBlockHardness(IBlockState state, World world, BlockPos pos) { | ||
|
||
return state.getValue(VARIANT).getHardness(); | ||
} | ||
|
||
@Override | ||
public float getExplosionResistance(World world, BlockPos pos, Entity exploder, Explosion explosion) { | ||
|
||
IBlockState state = world.getBlockState(pos); | ||
return state.getValue(VARIANT).getResistance(); | ||
} | ||
|
||
/* IModelRegister */ | ||
@Override | ||
@SideOnly (Side.CLIENT) | ||
public void registerModels() { | ||
|
||
for (int i = 0; i < Type.values().length; i++) { | ||
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), i, new ModelResourceLocation(modName + ":" + name + "_resource", "type=" + Type.byMetadata(i).getName())); | ||
} | ||
} | ||
|
||
/* IInitializer */ | ||
@Override | ||
public boolean initialize() { | ||
|
||
this.setRegistryName("storage_resource"); | ||
ForgeRegistries.BLOCKS.register(this); | ||
|
||
ItemBlockStorageResource itemBlock = new ItemBlockStorageResource(this); | ||
itemBlock.setRegistryName(this.getRegistryName()); | ||
ForgeRegistries.ITEMS.register(itemBlock); | ||
|
||
blockCharcoal = new ItemStack(this, 1, Type.CHARCOAL.getMetadata()); | ||
blockCoke = new ItemStack(this, 1, Type.COKE.getMetadata()); | ||
|
||
registerWithHandlers("blockCharcoal", blockCharcoal); | ||
registerWithHandlers("blockCoke", blockCoke); | ||
|
||
ThermalFoundation.proxy.addIModelRegister(this); | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public boolean register() { | ||
|
||
addStorageRecipe(blockCharcoal, new ItemStack(Items.COAL, 1, 1)); | ||
addStorageRecipe(blockCoke, "fuelCoke"); | ||
|
||
return true; | ||
} | ||
|
||
/* TYPE */ | ||
public enum Type implements IStringSerializable { | ||
|
||
// @formatter:off | ||
CHARCOAL(0, "charcoal"), | ||
COKE(1, "coke"); | ||
// @formatter: on | ||
|
||
private static final Type[] METADATA_LOOKUP = new Type[values().length]; | ||
private final int metadata; | ||
private final String name; | ||
private final int light; | ||
private final float hardness; | ||
private final float resistance; | ||
private final EnumRarity rarity; | ||
|
||
Type(int metadata, String name, int light, float hardness, float resistance, EnumRarity rarity) { | ||
|
||
this.metadata = metadata; | ||
this.name = name; | ||
this.light = light; | ||
this.hardness = hardness; | ||
this.resistance = resistance; | ||
this.rarity = rarity; | ||
} | ||
|
||
Type(int metadata, String name, int light, float hardness, float resistance) { | ||
|
||
this(metadata, name, light, hardness, resistance, EnumRarity.COMMON); | ||
} | ||
|
||
Type(int metadata, String name, float hardness, float resistance) { | ||
this(metadata, name, 0, hardness, resistance, EnumRarity.COMMON); | ||
} | ||
|
||
Type(int metadata, String name, int light) { | ||
|
||
this(metadata, name, light, 5.0F, 6.0F, EnumRarity.COMMON); | ||
} | ||
|
||
Type(int metadata, String name) { | ||
|
||
this(metadata, name, 0, 5.0F, 6.0F, EnumRarity.COMMON); | ||
} | ||
|
||
public int getMetadata() { | ||
return this.metadata; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
|
||
return this.name; | ||
} | ||
|
||
public int getLight() { | ||
|
||
return this.light; | ||
} | ||
|
||
public float getHardness() { | ||
|
||
return this.hardness; | ||
} | ||
|
||
public float getResistance() { | ||
|
||
return this.resistance; | ||
} | ||
|
||
public EnumRarity getRarity() { | ||
|
||
return this.rarity; | ||
} | ||
|
||
public static Type byMetadata(int metadata) { | ||
|
||
if (metadata < 0 || metadata >= METADATA_LOOKUP.length) { | ||
metadata = 0; | ||
} | ||
return METADATA_LOOKUP[metadata]; | ||
} | ||
|
||
static { | ||
for (Type type : values()) { | ||
METADATA_LOOKUP[type.getMetadata()] = type; | ||
} | ||
} | ||
} | ||
|
||
/* REFERENCES */ | ||
public static ItemStack blockCharcoal; | ||
public static ItemStack blockCoke; | ||
// TODO: Rosin/Tar? | ||
// TODO: Slags? | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/cofh/thermalfoundation/block/ItemBlockStorageResource.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package cofh.thermalfoundation.block; | ||
|
||
import cofh.core.block.ItemBlockCore; | ||
import cofh.core.util.helpers.ItemHelper; | ||
import cofh.thermalfoundation.block.BlockStorageResource.Type; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.item.EnumRarity; | ||
import net.minecraft.item.ItemStack; | ||
|
||
public class ItemBlockStorageResource extends ItemBlockCore { | ||
|
||
public ItemBlockStorageResource(Block block) { | ||
|
||
super(block); | ||
setHasSubtypes(true); | ||
setMaxDamage(0); | ||
} | ||
|
||
@Override | ||
public String getUnlocalizedName(ItemStack stack) { | ||
|
||
return "tile.thermalfoundation.storage." + Type.byMetadata(ItemHelper.getItemDamage(stack)).getName() + ".name"; | ||
} | ||
|
||
@Override | ||
public EnumRarity getRarity(ItemStack stack) { | ||
|
||
return Type.byMetadata(ItemHelper.getItemDamage(stack)).getRarity(); | ||
} | ||
|
||
} |
This file contains 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
21 changes: 21 additions & 0 deletions
21
src/main/resources/assets/thermalfoundation/blockstates/storage_resource.json
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"forge_marker": 1, | ||
"defaults": { | ||
"model": "cube_all", | ||
"transform": "forge:default-block" | ||
}, | ||
"variants": { | ||
"type": { | ||
"charcoal": { | ||
"textures": { | ||
"all": "thermalfoundation:blocks/storage/block_charcoal" | ||
} | ||
}, | ||
"coke": { | ||
"textures": { | ||
"all": "thermalfoundation:blocks/storage/block_coke" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains 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
Binary file added
BIN
+354 Bytes
...n/resources/assets/thermalfoundation/textures/blocks/storage/block_charcoal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+330 Bytes
src/main/resources/assets/thermalfoundation/textures/blocks/storage/block_coke.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+3 Bytes
(100%)
src/main/resources/assets/thermalfoundation/textures/items/material/fuel_coke.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.