mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-14 01:04:12 +00:00
Generalized ItemSoilBlock to ItemTypedBlock
This commit is contained in:
1 parent
235ead5011
commit
7e6b68a504
5 files changed
+40
-25
No files matched your search
@@ -0,0 +1,5 @@
|
||||
package forestry.core;
|
||||
|
||||
public interface IItemTyped {
|
||||
public Enum getTypeFromMeta(int meta);
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import forestry.core.IItemTyped;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
@@ -45,7 +46,7 @@ import forestry.core.render.TextureManager;
|
||||
* @author
|
||||
*
|
||||
*/
|
||||
public class BlockSoil extends Block {
|
||||
public class BlockSoil extends Block implements IItemTyped {
|
||||
|
||||
public enum SoilType {
|
||||
HUMUS, BOG_EARTH, PEAT;
|
||||
@@ -222,7 +223,7 @@ public class BlockSoil extends Block {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static SoilType getTypeFromMeta(int meta) {
|
||||
public SoilType getTypeFromMeta(int meta) {
|
||||
int type = meta & 0x03;
|
||||
int maturity = meta >> 2;
|
||||
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package forestry.core.items;
|
||||
|
||||
import forestry.core.gadgets.BlockSoil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ItemSoilBlock extends ItemForestryBlock {
|
||||
|
||||
public ItemSoilBlock(Block block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack itemstack) {
|
||||
if (this.getBlock() instanceof BlockSoil) {
|
||||
BlockSoil.SoilType soilType = BlockSoil.getTypeFromMeta(itemstack.getItemDamage());
|
||||
return getBlock().getUnlocalizedName() + "." + soilType.ordinal();
|
||||
}
|
||||
return super.getUnlocalizedName(itemstack);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package forestry.core.items;
|
||||
|
||||
import forestry.core.IItemTyped;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* For blocks whose type depends on metadata.
|
||||
* This allows control over which localized name maps to which meta value.
|
||||
*/
|
||||
public class ItemTypedBlock extends ItemForestryBlock {
|
||||
|
||||
public ItemTypedBlock(Block block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack itemstack) {
|
||||
Block block = getBlock();
|
||||
if (block instanceof IItemTyped) {
|
||||
IItemTyped blockTyped = (IItemTyped)block;
|
||||
Enum type = blockTyped.getTypeFromMeta(itemstack.getItemDamage());
|
||||
if (type != null)
|
||||
return getBlock().getUnlocalizedName() + "." + type.ordinal();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
return super.getUnlocalizedName(itemstack);
|
||||
}
|
||||
}
|
||||
@@ -64,7 +64,7 @@ import forestry.core.items.ItemAssemblyKit;
|
||||
import forestry.core.items.ItemCrated;
|
||||
import forestry.core.items.ItemForestry;
|
||||
import forestry.core.items.ItemForestryBlock;
|
||||
import forestry.core.items.ItemSoilBlock;
|
||||
import forestry.core.items.ItemTypedBlock;
|
||||
import forestry.core.items.ItemForestryPickaxe;
|
||||
import forestry.core.items.ItemForestryShovel;
|
||||
import forestry.core.items.ItemFruit;
|
||||
@@ -112,7 +112,7 @@ public class PluginCore extends NativePlugin implements IFuelHandler {
|
||||
definitionEscritoire = ((BlockBase) ForestryBlock.core.block()).addDefinition(new MachineDefinition(Defaults.DEFINITION_ESCRITOIRE_META, "forestry.Escritoire", TileEscritoire.class,
|
||||
Proxies.render.getRenderEscritoire()));
|
||||
|
||||
ForestryBlock.soil.registerBlock(new BlockSoil(), ItemSoilBlock.class, "soil");
|
||||
ForestryBlock.soil.registerBlock(new BlockSoil(), ItemTypedBlock.class, "soil");
|
||||
ForestryBlock.soil.block().setHarvestLevel("shovel", 0, 0);
|
||||
ForestryBlock.soil.block().setHarvestLevel("shovel", 0, 1);
|
||||
|
||||
|
||||
Reference in new issue
Block a user