From 641dea32ac0b3d69ba55679426e8949205f5134e Mon Sep 17 00:00:00 2001 From: mezz Date: Thu, 28 Apr 2016 23:46:27 -0700 Subject: [PATCH] Fix #1145 blocks missing localization --- lang | 2 +- .../apiculture/blocks/BlockCandle.java | 13 ++---- .../blocks/BlockTreeContainer.java | 5 --- .../core/blocks/BlockRegistryCore.java | 3 +- .../core/blocks/BlockResourceOre.java | 10 ++++- .../core/blocks/BlockResourceStorage.java | 8 +++- .../java/forestry/core/blocks/BlockSoil.java | 27 +++++++++--- .../core/items/ItemBlockForestry.java | 16 +++---- .../forestry/core/items/ItemBlockTyped.java | 42 ------------------- .../forestry/farming/blocks/BlockFarm.java | 9 +--- .../farming/blocks/BlockMushroom.java | 17 ++++---- .../farming/blocks/BlockRegistryFarming.java | 4 +- .../java/forestry/farming/logic/CropPeat.java | 2 +- .../farming/logic/FarmLogicArboreal.java | 2 +- .../forestry/farming/logic/FarmLogicPeat.java | 4 +- .../greenhouse/blocks/BlockGreenhouse.java | 13 ++---- 16 files changed, 73 insertions(+), 104 deletions(-) delete mode 100644 src/main/java/forestry/core/items/ItemBlockTyped.java diff --git a/lang b/lang index 0a32e7bbb..ea85d2460 160000 --- a/lang +++ b/lang @@ -1 +1 @@ -Subproject commit 0a32e7bbb19da28358102a759a59267f4e826b5e +Subproject commit ea85d246017d4d138294235c9f22982363452cb7 diff --git a/src/main/java/forestry/apiculture/blocks/BlockCandle.java b/src/main/java/forestry/apiculture/blocks/BlockCandle.java index b6723afa4..6c300b55b 100644 --- a/src/main/java/forestry/apiculture/blocks/BlockCandle.java +++ b/src/main/java/forestry/apiculture/blocks/BlockCandle.java @@ -22,6 +22,7 @@ import java.util.Random; import java.util.Set; import net.minecraft.block.BlockTorch; +import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; @@ -51,13 +52,13 @@ import forestry.api.core.Tabs; import forestry.apiculture.tiles.TileCandle; import forestry.core.utils.ItemStackUtil; -public class BlockCandle extends BlockTorch implements IItemModelRegister { +public class BlockCandle extends BlockTorch implements IItemModelRegister, ITileEntityProvider { private static final ImmutableMap colours; public static final Set lightingItems; public static final String colourTagName = "colour"; - private static final PropertyEnum STATE = PropertyEnum.create("state", State.class); + private static final PropertyEnum STATE = PropertyEnum.create("state", State.class); private enum State implements IStringSerializable { ON, OFF; @@ -96,7 +97,6 @@ public class BlockCandle extends BlockTorch implements IItemModelRegister { } public BlockCandle() { - super(); this.setHardness(0.0F); this.setStepSound(soundTypeWood); setCreativeTab(Tabs.tabApiculture); @@ -117,12 +117,7 @@ public class BlockCandle extends BlockTorch implements IItemModelRegister { } @Override - public boolean hasTileEntity(IBlockState state) { - return true; - } - - @Override - public TileEntity createTileEntity(World world, IBlockState state) { + public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileCandle(); } diff --git a/src/main/java/forestry/arboriculture/blocks/BlockTreeContainer.java b/src/main/java/forestry/arboriculture/blocks/BlockTreeContainer.java index b09ed213d..03d5972ae 100644 --- a/src/main/java/forestry/arboriculture/blocks/BlockTreeContainer.java +++ b/src/main/java/forestry/arboriculture/blocks/BlockTreeContainer.java @@ -43,11 +43,6 @@ public abstract class BlockTreeContainer extends BlockContainer { ((TileTreeContainer) tile).onBlockTick(); } - @Override - public boolean hasTileEntity(IBlockState state) { - return true; - } - @Override public int getRenderType() { return 3; diff --git a/src/main/java/forestry/core/blocks/BlockRegistryCore.java b/src/main/java/forestry/core/blocks/BlockRegistryCore.java index fb3cb29f4..e7d94be84 100644 --- a/src/main/java/forestry/core/blocks/BlockRegistryCore.java +++ b/src/main/java/forestry/core/blocks/BlockRegistryCore.java @@ -15,7 +15,6 @@ import net.minecraft.init.Blocks; import net.minecraftforge.oredict.OreDictionary; import forestry.core.items.ItemBlockForestry; -import forestry.core.items.ItemBlockTyped; public class BlockRegistryCore extends BlockRegistry { public final BlockCore core; @@ -26,7 +25,7 @@ public class BlockRegistryCore extends BlockRegistry { public BlockRegistryCore() { core = registerBlock(new BlockCore(), ItemBlockForestry.class, "core"); - soil = registerBlock(new BlockSoil(), ItemBlockTyped.class, "soil"); + soil = registerBlock(new BlockSoil(), ItemBlockForestry.class, "soil"); soil.setHarvestLevel("shovel", 0, soil.getStateFromMeta(0)); soil.setHarvestLevel("shovel", 0, soil.getStateFromMeta(1)); diff --git a/src/main/java/forestry/core/blocks/BlockResourceOre.java b/src/main/java/forestry/core/blocks/BlockResourceOre.java index b84f21729..044dfff96 100644 --- a/src/main/java/forestry/core/blocks/BlockResourceOre.java +++ b/src/main/java/forestry/core/blocks/BlockResourceOre.java @@ -35,7 +35,7 @@ import forestry.api.core.IModelManager; import forestry.core.CreativeTabForestry; import forestry.core.PluginCore; -public class BlockResourceOre extends Block implements IItemModelRegister { +public class BlockResourceOre extends Block implements IItemModelRegister, IBlockWithMeta { public static final PropertyEnum ORE_RESOURCES = PropertyEnum.create("resource", EnumResourceType.class, new Predicate(){ @Override public boolean apply(EnumResourceType input) { @@ -77,7 +77,7 @@ public class BlockResourceOre extends Block implements IItemModelRegister { @Override public List getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { - ArrayList drops = new ArrayList(); + List drops = new ArrayList<>(); EnumResourceType metadata = state.getValue(ORE_RESOURCES); if (metadata == EnumResourceType.APATITE) { @@ -126,4 +126,10 @@ public class BlockResourceOre extends Block implements IItemModelRegister { public ItemStack get(EnumResourceType type, int amount) { return new ItemStack(this, amount, type.getMeta()); } + + @Override + public String getNameFromMeta(int meta) { + EnumResourceType resourceType = getStateFromMeta(meta).getValue(ORE_RESOURCES); + return resourceType.getName(); + } } diff --git a/src/main/java/forestry/core/blocks/BlockResourceStorage.java b/src/main/java/forestry/core/blocks/BlockResourceStorage.java index c422aefe1..7e4b541b6 100644 --- a/src/main/java/forestry/core/blocks/BlockResourceStorage.java +++ b/src/main/java/forestry/core/blocks/BlockResourceStorage.java @@ -16,7 +16,7 @@ import forestry.api.core.IItemModelRegister; import forestry.api.core.IModelManager; import forestry.core.CreativeTabForestry; -public class BlockResourceStorage extends Block implements IItemModelRegister { +public class BlockResourceStorage extends Block implements IItemModelRegister, IBlockWithMeta { public static final PropertyEnum STORAGE_RESOURCES = PropertyEnum.create("resource", EnumResourceType.class); public BlockResourceStorage() { @@ -65,4 +65,10 @@ public class BlockResourceStorage extends Block implements IItemModelRegister { public ItemStack get(EnumResourceType type) { return new ItemStack(this, 1, type.getMeta()); } + + @Override + public String getNameFromMeta(int meta) { + EnumResourceType resourceType = getStateFromMeta(meta).getValue(STORAGE_RESOURCES); + return resourceType.getName(); + } } diff --git a/src/main/java/forestry/core/blocks/BlockSoil.java b/src/main/java/forestry/core/blocks/BlockSoil.java index 4a76c88e9..4ef82f9e4 100644 --- a/src/main/java/forestry/core/blocks/BlockSoil.java +++ b/src/main/java/forestry/core/blocks/BlockSoil.java @@ -10,9 +10,9 @@ ******************************************************************************/ package forestry.core.blocks; +import javax.annotation.Nonnull; import java.util.ArrayList; import java.util.List; -import java.util.Locale; import java.util.Random; import net.minecraft.block.Block; @@ -47,15 +47,25 @@ import forestry.core.utils.BlockUtil; /** * Humus, bog earth, peat */ -public class BlockSoil extends Block implements IItemTyped, IItemModelRegister { +public class BlockSoil extends Block implements IItemModelRegister, IBlockWithMeta { private static final PropertyEnum SOIL = PropertyEnum.create("soil", SoilType.class); public enum SoilType implements IStringSerializable { - HUMUS, BOG_EARTH, PEAT; + HUMUS("humus"), + BOG_EARTH("bog.earth"), + PEAT("peat"); + + @Nonnull + private final String name; + + SoilType(@Nonnull String name) { + this.name = name; + } + @Nonnull @Override public String getName() { - return name().toLowerCase(Locale.ENGLISH); + return name; } } @@ -239,8 +249,7 @@ public class BlockSoil extends Block implements IItemTyped, IItemModelRegister { return false; } - @Override - public SoilType getTypeFromMeta(int meta) { + public static SoilType getTypeFromMeta(int meta) { int type = meta & 0x03; int maturity = meta >> 2; @@ -270,6 +279,12 @@ public class BlockSoil extends Block implements IItemTyped, IItemModelRegister { manager.registerItemModel(item, 2, "soil/peat"); } + @Override + public String getNameFromMeta(int meta) { + SoilType type = getTypeFromMeta(meta); + return type.getName(); + } + public ItemStack get(SoilType soilType, int amount) { return new ItemStack(this, amount, soilType.ordinal()); } diff --git a/src/main/java/forestry/core/items/ItemBlockForestry.java b/src/main/java/forestry/core/items/ItemBlockForestry.java index 7801c0ef8..7fa739f61 100644 --- a/src/main/java/forestry/core/items/ItemBlockForestry.java +++ b/src/main/java/forestry/core/items/ItemBlockForestry.java @@ -57,15 +57,17 @@ public class ItemBlockForestry extends ItemBlock { public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState) { boolean placed = super.placeBlockAt(stack, player, world, pos, side, hitX, hitY, hitZ, newState); - TileForestry tile = TileUtil.getTile(world, pos, TileForestry.class); + if (block.hasTileEntity(newState)) { + TileForestry tile = TileUtil.getTile(world, pos, TileForestry.class); - if (tile != null) { - if (stack.getItem() instanceof ItemBlockNBT && stack.hasTagCompound()) { - tile.readFromNBT(stack.getTagCompound()); - tile.setPos(pos); + if (tile != null) { + if (stack.getItem() instanceof ItemBlockNBT && stack.hasTagCompound()) { + tile.readFromNBT(stack.getTagCompound()); + tile.setPos(pos); + } + + tile.rotateAfterPlacement(player, side); } - - tile.rotateAfterPlacement(player, side); } return placed; diff --git a/src/main/java/forestry/core/items/ItemBlockTyped.java b/src/main/java/forestry/core/items/ItemBlockTyped.java deleted file mode 100644 index 2c74d8579..000000000 --- a/src/main/java/forestry/core/items/ItemBlockTyped.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.core.items; - -import net.minecraft.block.Block; -import net.minecraft.item.ItemStack; - -import forestry.core.blocks.IItemTyped; - -/** - * For blocks whose type depends on metadata. - * This allows control over which localized name maps to which meta value. - */ -public class ItemBlockTyped extends ItemBlockForestry { - - public ItemBlockTyped(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); - } -} diff --git a/src/main/java/forestry/farming/blocks/BlockFarm.java b/src/main/java/forestry/farming/blocks/BlockFarm.java index 1c9a97a1b..f60b186c9 100644 --- a/src/main/java/forestry/farming/blocks/BlockFarm.java +++ b/src/main/java/forestry/farming/blocks/BlockFarm.java @@ -165,8 +165,8 @@ public class BlockFarm extends BlockStructure { } @Override - public TileEntity createTileEntity(World world, IBlockState state) { - switch (getMetaFromState(state)) { + public TileEntity createNewTileEntity(World world, int meta) { + switch (meta) { case 2: return new TileFarmGearbox(); case 3: @@ -180,11 +180,6 @@ public class BlockFarm extends BlockStructure { } } - @Override - public TileEntity createNewTileEntity(World world, int meta) { - return createTileEntity(world, getStateFromMeta(meta)); - } - /* MODELS */ @Override @SideOnly(Side.CLIENT) diff --git a/src/main/java/forestry/farming/blocks/BlockMushroom.java b/src/main/java/forestry/farming/blocks/BlockMushroom.java index 1d407f3e8..7a26d5d58 100644 --- a/src/main/java/forestry/farming/blocks/BlockMushroom.java +++ b/src/main/java/forestry/farming/blocks/BlockMushroom.java @@ -36,13 +36,13 @@ import net.minecraftforge.fml.relauncher.SideOnly; import forestry.api.core.IItemModelRegister; import forestry.api.core.IModelManager; -import forestry.core.blocks.IItemTyped; +import forestry.core.blocks.IBlockWithMeta; import forestry.core.config.Constants; import forestry.core.utils.BlockUtil; -public class BlockMushroom extends BlockBush implements IItemTyped, IItemModelRegister, IGrowable { +public class BlockMushroom extends BlockBush implements IItemModelRegister, IGrowable, IBlockWithMeta { - public static final PropertyEnum MUSHROOM = PropertyEnum.create("mushroom", MushroomType.class); + public static final PropertyEnum MUSHROOM = PropertyEnum.create("mushroom", MushroomType.class); public enum MushroomType implements IStringSerializable { BROWN, RED; @@ -57,7 +57,6 @@ public class BlockMushroom extends BlockBush implements IItemTyped, IItemModelRe private final ItemStack[] drops; public BlockMushroom() { - super(); setHardness(0.0f); this.generators = new WorldGenerator[]{new WorldGenBigMushroom(Blocks.brown_mushroom_block), new WorldGenBigMushroom(Blocks.red_mushroom_block)}; this.drops = new ItemStack[]{new ItemStack(Blocks.brown_mushroom), new ItemStack(Blocks.red_mushroom)}; @@ -73,7 +72,7 @@ public class BlockMushroom extends BlockBush implements IItemTyped, IItemModelRe @Override public int getMetaFromState(IBlockState state) { - return ((MushroomType) state.getValue(MUSHROOM)).ordinal(); + return state.getValue(MUSHROOM).ordinal(); } @Override @@ -147,8 +146,7 @@ public class BlockMushroom extends BlockBush implements IItemTyped, IItemModelRe this.generateTree(worldIn, pos, state, rand); } - @Override - public MushroomType getTypeFromMeta(int meta) { + public static MushroomType getTypeFromMeta(int meta) { meta %= MushroomType.values().length; return MushroomType.values()[meta]; } @@ -183,4 +181,9 @@ public class BlockMushroom extends BlockBush implements IItemTyped, IItemModelRe this.grow(worldIn, pos, state, rand); } + @Override + public String getNameFromMeta(int meta) { + MushroomType type = getTypeFromMeta(meta); + return type.getName(); + } } diff --git a/src/main/java/forestry/farming/blocks/BlockRegistryFarming.java b/src/main/java/forestry/farming/blocks/BlockRegistryFarming.java index 7f8fcaa80..82f53006e 100644 --- a/src/main/java/forestry/farming/blocks/BlockRegistryFarming.java +++ b/src/main/java/forestry/farming/blocks/BlockRegistryFarming.java @@ -11,7 +11,7 @@ package forestry.farming.blocks; import forestry.core.blocks.BlockRegistry; -import forestry.core.items.ItemBlockTyped; +import forestry.core.items.ItemBlockForestry; import forestry.farming.items.ItemBlockFarm; public class BlockRegistryFarming extends BlockRegistry { @@ -19,7 +19,7 @@ public class BlockRegistryFarming extends BlockRegistry { public final BlockFarm farm; public BlockRegistryFarming() { - mushroom = registerBlock(new BlockMushroom(), ItemBlockTyped.class, "mushroom"); + mushroom = registerBlock(new BlockMushroom(), ItemBlockForestry.class, "mushroom"); farm = registerBlock(new BlockFarm(), ItemBlockFarm.class, "ffarm"); } } diff --git a/src/main/java/forestry/farming/logic/CropPeat.java b/src/main/java/forestry/farming/logic/CropPeat.java index 6e0202579..c0e45430f 100755 --- a/src/main/java/forestry/farming/logic/CropPeat.java +++ b/src/main/java/forestry/farming/logic/CropPeat.java @@ -38,7 +38,7 @@ public class CropPeat extends Crop { } BlockSoil blockSoil = (BlockSoil) block; - BlockSoil.SoilType soilType = blockSoil.getTypeFromMeta(getBlockMeta(pos)); + BlockSoil.SoilType soilType = BlockSoil.getTypeFromMeta(getBlockMeta(pos)); return soilType == BlockSoil.SoilType.PEAT; } diff --git a/src/main/java/forestry/farming/logic/FarmLogicArboreal.java b/src/main/java/forestry/farming/logic/FarmLogicArboreal.java index 69e216f0c..1cc937d20 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicArboreal.java +++ b/src/main/java/forestry/farming/logic/FarmLogicArboreal.java @@ -60,7 +60,7 @@ public class FarmLogicArboreal extends FarmLogicHomogeneous { return false; } BlockSoil blockSoil = (BlockSoil) block; - return blockSoil.getTypeFromMeta(soil.getItemDamage()) == BlockSoil.SoilType.HUMUS; + return BlockSoil.getTypeFromMeta(soil.getItemDamage()) == BlockSoil.SoilType.HUMUS; } @Override diff --git a/src/main/java/forestry/farming/logic/FarmLogicPeat.java b/src/main/java/forestry/farming/logic/FarmLogicPeat.java index 1356c38c3..f817bd694 100755 --- a/src/main/java/forestry/farming/logic/FarmLogicPeat.java +++ b/src/main/java/forestry/farming/logic/FarmLogicPeat.java @@ -48,7 +48,7 @@ public class FarmLogicPeat extends FarmLogicWatered { return false; } BlockSoil blockSoil = (BlockSoil) block; - BlockSoil.SoilType soilType = blockSoil.getTypeFromMeta(itemStack.getItemDamage()); + BlockSoil.SoilType soilType = BlockSoil.getTypeFromMeta(itemStack.getItemDamage()); return soilType == BlockSoil.SoilType.BOG_EARTH || soilType == BlockSoil.SoilType.PEAT; } @@ -95,7 +95,7 @@ public class FarmLogicPeat extends FarmLogicWatered { } BlockSoil blockSoil = (BlockSoil) block; - BlockSoil.SoilType soilType = blockSoil.getTypeFromMeta(occupant.getItemDamage()); + BlockSoil.SoilType soilType = BlockSoil.getTypeFromMeta(occupant.getItemDamage()); if (soilType == BlockSoil.SoilType.PEAT) { crops.push(new CropPeat(world, position)); diff --git a/src/main/java/forestry/greenhouse/blocks/BlockGreenhouse.java b/src/main/java/forestry/greenhouse/blocks/BlockGreenhouse.java index fc1ab010f..65d4258d6 100644 --- a/src/main/java/forestry/greenhouse/blocks/BlockGreenhouse.java +++ b/src/main/java/forestry/greenhouse/blocks/BlockGreenhouse.java @@ -10,12 +10,11 @@ ******************************************************************************/ package forestry.greenhouse.blocks; +import javax.annotation.Nonnull; import java.util.EnumMap; import java.util.List; import java.util.Map; -import javax.annotation.Nonnull; - import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; @@ -42,6 +41,7 @@ import net.minecraftforge.common.property.IUnlistedProperty; import net.minecraftforge.common.property.Properties; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; + import forestry.api.core.ForestryAPI; import forestry.api.core.ICamouflagedBlock; import forestry.api.core.IModelManager; @@ -66,7 +66,7 @@ import forestry.plugins.ForestryPluginUids; public abstract class BlockGreenhouse extends BlockStructure { - public static final PropertyEnum STATE = PropertyEnum.create("state", State.class); + public static final PropertyEnum STATE = PropertyEnum.create("state", State.class); public static enum State implements IStringSerializable { ON, OFF; @@ -188,7 +188,7 @@ public abstract class BlockGreenhouse extends BlockStructure { } @Override - public TileEntity createTileEntity(World world, IBlockState state) { + public TileEntity createNewTileEntity(World world, int meta) { BlockGreenhouseType type = getGreenhouseType(); switch (type) { case GEARBOX: @@ -216,11 +216,6 @@ public abstract class BlockGreenhouse extends BlockStructure { return new TileGreenhousePlain(); } } - - @Override - public TileEntity createNewTileEntity(World world, int meta) { - return createTileEntity(world, getStateFromMeta(meta)); - } @Override public int colorMultiplier(IBlockAccess world, BlockPos pos, int renderPass) {