From 11527b3a22a59c9d08a9b796c9f64a9f01056a57 Mon Sep 17 00:00:00 2001 From: Prospector Date: Mon, 12 Jun 2017 10:25:29 -0700 Subject: [PATCH] Fix cable models --- .../techreborn/blocks/cable/BlockCable.java | 20 +- .../techreborn/client/RegisterItemJsons.java | 39 +++- .../assets/techreborn/blockstates/cable.json | 174 ------------------ .../techreborn/blockstates/cable_inv.json | 44 ++++- .../techreborn/blockstates/cable_thick.json | 83 +++++++++ .../techreborn/blockstates/cable_thin.json | 25 +-- .../assets/techreborn/lang/en_us.lang | 16 +- .../assets/techreborn/models/block/cable.json | 37 ++-- .../models/block/cable_connection.json | 4 +- .../models/block/cable_connection_alt.json | 4 +- .../block/cable_connection_alt_thin.json | 4 +- .../models/block/cable_connection_thin.json | 4 +- 12 files changed, 219 insertions(+), 235 deletions(-) delete mode 100644 src/main/resources/assets/techreborn/blockstates/cable.json create mode 100644 src/main/resources/assets/techreborn/blockstates/cable_thick.json diff --git a/src/main/java/techreborn/blocks/cable/BlockCable.java b/src/main/java/techreborn/blocks/cable/BlockCable.java index 17019e4e5..8c6743229 100644 --- a/src/main/java/techreborn/blocks/cable/BlockCable.java +++ b/src/main/java/techreborn/blocks/cable/BlockCable.java @@ -36,10 +36,7 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumBlockRenderType; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.EnumHand; -import net.minecraft.util.NonNullList; +import net.minecraft.util.*; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; @@ -91,7 +88,7 @@ public class BlockCable extends BlockContainer { @Override public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) { - return new ItemStack(this, 1, 0); + return state.getValue(TYPE).getStack(); } @Override @@ -104,6 +101,19 @@ public class BlockCable extends BlockContainer { return false; } + @Override + public BlockRenderLayer getBlockLayer() { + return BlockRenderLayer.CUTOUT; + } + + @Override + public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) { + if (blockState.getValue(TYPE) == EnumCableType.GLASSFIBER) + return false; + else + return true; + } + @Override public boolean isFullBlock(IBlockState state) { return false; diff --git a/src/main/java/techreborn/client/RegisterItemJsons.java b/src/main/java/techreborn/client/RegisterItemJsons.java index 22288b66b..b4e6a3a98 100644 --- a/src/main/java/techreborn/client/RegisterItemJsons.java +++ b/src/main/java/techreborn/client/RegisterItemJsons.java @@ -24,8 +24,12 @@ package techreborn.client; +import com.google.common.collect.Maps; import net.minecraft.block.Block; +import net.minecraft.block.properties.IProperty; +import net.minecraft.block.state.IBlockState; import net.minecraft.client.renderer.block.model.ModelResourceLocation; +import net.minecraft.client.renderer.block.statemap.DefaultStateMapper; import net.minecraft.item.Item; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.model.ModelLoader; @@ -33,12 +37,15 @@ import techreborn.blocks.BlockOre; import techreborn.blocks.BlockOre2; import techreborn.blocks.BlockStorage; import techreborn.blocks.BlockStorage2; +import techreborn.blocks.cable.BlockCable; import techreborn.blocks.cable.EnumCableType; import techreborn.config.ConfigTechReborn; import techreborn.init.ModBlocks; import techreborn.init.ModItems; import techreborn.items.*; +import java.util.Map; + public class RegisterItemJsons { public static void registerModels() { registerItems(); @@ -179,8 +186,33 @@ public class RegisterItemJsons { } for (EnumCableType cableType : EnumCableType.values()) { - registerBlockstate(ModBlocks.CABLE, cableType.ordinal(), "inv_" + cableType.getName().toLowerCase()); + registerBlockstateMultiItem(Item.getItemFromBlock(ModBlocks.CABLE), cableType.ordinal(), cableType.getName().toLowerCase(), "cable_inv"); } + + ModelLoader.setCustomStateMapper(ModBlocks.CABLE, new DefaultStateMapper() { + @Override + protected ModelResourceLocation getModelResourceLocation(IBlockState state) { + Map, Comparable> map = Maps., Comparable>newLinkedHashMap(state.getProperties()); + if (state.getValue(BlockCable.TYPE).ordinal() <= 4) { + return new ModelResourceLocation(new ResourceLocation(ModBlocks.CABLE.getRegistryName().getResourceDomain(), ModBlocks.CABLE.getRegistryName().getResourcePath()) + "_thin", this.getPropertyString(map)); + } + return new ModelResourceLocation(new ResourceLocation(ModBlocks.CABLE.getRegistryName().getResourceDomain(), ModBlocks.CABLE.getRegistryName().getResourcePath()) + "_thick", this.getPropertyString(map)); + } + }); + } + + public static void setBlockStateMapper(Block block, String path, IProperty... ignoredProperties) { + final String slash = !path.isEmpty() ? "/" : ""; + ModelLoader.setCustomStateMapper(block, new DefaultStateMapper() { + @Override + protected ModelResourceLocation getModelResourceLocation(IBlockState state) { + Map, Comparable> map = Maps., Comparable>newLinkedHashMap(state.getProperties()); + for (IProperty iproperty : ignoredProperties) { + map.remove(iproperty); + } + return new ModelResourceLocation(new ResourceLocation(block.getRegistryName().getResourceDomain(), path + slash + block.getRegistryName().getResourcePath()), this.getPropertyString(map)); + } + }); } private static void registerBlocks() { @@ -225,4 +257,9 @@ public class RegisterItemJsons { ResourceLocation loc = new ResourceLocation("techreborn", path); ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(loc, "type=" + variantName)); } + + private static void registerBlockstateMultiItem(Item item, int meta, String variantName, String path) { + ResourceLocation loc = new ResourceLocation("techreborn", path); + ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(loc, "type=" + variantName)); + } } diff --git a/src/main/resources/assets/techreborn/blockstates/cable.json b/src/main/resources/assets/techreborn/blockstates/cable.json deleted file mode 100644 index bfbf5891a..000000000 --- a/src/main/resources/assets/techreborn/blockstates/cable.json +++ /dev/null @@ -1,174 +0,0 @@ -{ - "forge_marker": 1, - "defaults": { - "transform": "forge:default-block", - "model": "techreborn:cable_thin", - "textures": { - "cable": "techreborn:block/blocks/cables/copper_cable", - "particle": "techreborn:block/blocks/cables/copper_cable" - } - }, - "variants": { - "inventory": [ - { - "transform": "forge:default-block", - "model": "techreborn:cable", - "textures": { - "cable": "techreborn:blocks/cables/copper_cable" - } - } - ], - "down": { - "true": { - "submodel": { - "pipeDown": { - "model": "techreborn:cable_connection_alt_thin", - "x": 270 - } - } - }, - "false": { - } - }, - "east": { - "true": { - "submodel": "techreborn:cable_connection_thin", - "y": 90 - }, - "false": { - } - }, - "north": { - "true": { - "submodel": "techreborn:cable_connection_thin" - }, - "false": { - } - }, - "south": { - "true": { - "submodel": "techreborn:cable_connection_alt_thin" - }, - "false": { - } - }, - "up": { - "true": { - "submodel": { - "pipeUp": { - "model": "techreborn:cable_connection_thin", - "x": 270 - } - } - }, - "false": { - } - }, - "west": { - "true": { - "submodel": "techreborn:cable_connection_alt_thin", - "y": 90 - }, - "false": { - } - }, - "type": { - "copper": { - "textures": { - "cable": "techreborn:blocks/cables/copper_cable" - } - }, - "tin": { - "textures": { - "cable": "techreborn:blocks/cables/tin_cable" - } - }, - "gold": { - "textures": { - "cable": "techreborn:blocks/cables/gold_cable" - } - }, - "hv": { - "textures": { - "cable": "techreborn:blocks/cables/hv_cable" - } - }, - "glassfiber": { - "textures": { - "cable": "techreborn:blocks/cables/glass_fiber_cable" - } - }, - "insulatedcopper": { - "textures": { - "cable": "techreborn:blocks/cables/copper_insulated_cable" - } - }, - "insulatedgold": { - "textures": { - "cable": "techreborn:blocks/cables/gold_insulated_cable" - } - }, - "insulatedhv": { - "textures": { - "cable": "techreborn:blocks/cables/hv_insulated_cable" - } - }, - "inv_copper": { - "transform": "forge:default-block", - "model": "techreborn:cable", - "textures": { - "cable": "techreborn:blocks/cables/copper_cable" - } - }, - "inv_tin": { - "transform": "forge:default-block", - "model": "techreborn:cable", - "textures": { - "cable": "techreborn:blocks/cables/tin_cable" - } - }, - "inv_gold": { - "transform": "forge:default-block", - "model": "techreborn:cable", - "textures": { - "cable": "techreborn:blocks/cables/gold_cable" - } - }, - "inv_hv": { - "transform": "forge:default-block", - "model": "techreborn:cable", - "textures": { - "cable": "techreborn:blocks/cables/hv_cable" - } - }, - "inv_glassfiber": { - "transform": "forge:default-block", - "model": "techreborn:cable", - "textures": { - "cable": "techreborn:blocks/cables/glass_fiber_cable" - } - }, - "inv_insulatedcopper": { - "transform": "forge:default-block", - "model": "techreborn:cable", - "textures": { - "cable": "techreborn:blocks/cables/copper_insulated_cable" - } - }, - "inv_insulatedgold": { - "transform": "forge:default-block", - "model": "techreborn:cable", - "textures": { - "cable": "techreborn:blocks/cables/gold_insulated_cable" - } - }, - "inv_insulatedhv": { - "transform": "forge:default-block", - "model": "techreborn:cable", - "textures": { - "cable": "techreborn:blocks/cables/hv_insulated_cable" - } - } - } - } -} diff --git a/src/main/resources/assets/techreborn/blockstates/cable_inv.json b/src/main/resources/assets/techreborn/blockstates/cable_inv.json index 87b569956..d7955e96d 100644 --- a/src/main/resources/assets/techreborn/blockstates/cable_inv.json +++ b/src/main/resources/assets/techreborn/blockstates/cable_inv.json @@ -1,17 +1,51 @@ { "forge_marker": 1, "defaults": { - "transform": "forge:default-block", + "transform": "forge:default-item", "model": "techreborn:item" }, "variants": { - "copper": [ - { - "transform": "forge:default-item", + "type": { + "copper": { "textures": { "texture": "techreborn:items/cables/copper" } + }, + "tin": { + "textures": { + "texture": "techreborn:items/cables/tin" + } + }, + "gold": { + "textures": { + "texture": "techreborn:items/cables/gold" + } + }, + "hv": { + "textures": { + "texture": "techreborn:items/cables/hv" + } + }, + "glassfiber": { + "textures": { + "texture": "techreborn:items/cables/glassfiber" + } + }, + "insulatedcopper": { + "textures": { + "texture": "techreborn:items/cables/insulatedcopper" + } + }, + "insulatedgold": { + "textures": { + "texture": "techreborn:items/cables/insulatedgold" + } + }, + "insulatedhv": { + "textures": { + "texture": "techreborn:items/cables/insulatedhv" + } } - ] + } } } diff --git a/src/main/resources/assets/techreborn/blockstates/cable_thick.json b/src/main/resources/assets/techreborn/blockstates/cable_thick.json new file mode 100644 index 000000000..77e24ebaa --- /dev/null +++ b/src/main/resources/assets/techreborn/blockstates/cable_thick.json @@ -0,0 +1,83 @@ +{ + "forge_marker": 1, + "defaults": { + "transform": "forge:default-block", + "model": "techreborn:cable", + "textures": { + "particle": "#cable" + } + }, + "variants": { + "down": { + "true": { + "submodel": { + "pipeDown": { + "model": "techreborn:cable_connection_alt", + "x": 270 + } + } + }, + "false": { + } + }, + "east": { + "true": { + "submodel": "techreborn:cable_connection", + "y": 90 + }, + "false": { + } + }, + "north": { + "true": { + "submodel": "techreborn:cable_connection" + }, + "false": { + } + }, + "south": { + "true": { + "submodel": "techreborn:cable_connection_alt" + }, + "false": { + } + }, + "up": { + "true": { + "submodel": { + "pipeUp": { + "model": "techreborn:cable_connection", + "x": 270 + } + } + }, + "false": { + } + }, + "west": { + "true": { + "submodel": "techreborn:cable_connection_alt", + "y": 90 + }, + "false": { + } + }, + "type": { + "insulatedcopper": { + "textures": { + "cable": "techreborn:blocks/cables/copper_insulated_cable" + } + }, + "insulatedgold": { + "textures": { + "cable": "techreborn:blocks/cables/gold_insulated_cable" + } + }, + "insulatedhv": { + "textures": { + "cable": "techreborn:blocks/cables/hv_insulated_cable" + } + } + } + } +} diff --git a/src/main/resources/assets/techreborn/blockstates/cable_thin.json b/src/main/resources/assets/techreborn/blockstates/cable_thin.json index 8b08da797..99d741bf6 100644 --- a/src/main/resources/assets/techreborn/blockstates/cable_thin.json +++ b/src/main/resources/assets/techreborn/blockstates/cable_thin.json @@ -4,11 +4,19 @@ "transform": "forge:default-block", "model": "techreborn:cable_thin", "textures": { - "cable": "techreborn:block/cable", "particle": "#cable" } }, "variants": { + "inventory": [ + { + "transform": "forge:default-block", + "model": "techreborn:cable", + "textures": { + "cable": "techreborn:blocks/cables/copper_cable" + } + } + ], "down": { "true": { "submodel": { @@ -88,21 +96,6 @@ "textures": { "cable": "techreborn:blocks/cables/glass_fiber_cable" } - }, - "insulatedcopper": { - "textures": { - "cable": "techreborn:blocks/cables/copper_insulated_cable" - } - }, - "insulatedgold": { - "textures": { - "cable": "techreborn:blocks/cables/gold_insulated_cable" - } - }, - "insulatedhv": { - "textures": { - "cable": "techreborn:blocks/cables/hv_insulated_cable" - } } } } diff --git a/src/main/resources/assets/techreborn/lang/en_us.lang b/src/main/resources/assets/techreborn/lang/en_us.lang index 055d8f249..bffc9ec8d 100644 --- a/src/main/resources/assets/techreborn/lang/en_us.lang +++ b/src/main/resources/assets/techreborn/lang/en_us.lang @@ -293,14 +293,14 @@ item.techreborn.dust.diorite.name=Diorite Dust item.techreborn.dust.granite.name=Granite Dust item.techreborn.wrench.name=Wrench -item.techreborn.cable.COPPER.name=Copper Cable -item.techreborn.cable.TIN.name=Tin Cable -item.techreborn.cable.GOLD.name=Gold Cable -item.techreborn.cable.HV.name=HV Cable -item.techreborn.cable.GLASSFIBER.name=Glass Fiber Cable -item.techreborn.cable.ICOPPER.name=Insulated Copper Cable -item.techreborn.cable.IGOLD.name=Insulated Gold Cable -item.techreborn.cable.IHV.name=Insulated HV Cable +tile.techreborn.cable.copper.name=Copper Cable +tile.techreborn.cable.tin.name=Tin Cable +tile.techreborn.cable.gold.name=Gold Cable +tile.techreborn.cable.hv.name=HV Cable +tile.techreborn.cable.glassfiber.name=Glass Fiber Cable +tile.techreborn.cable.insulatedcopper.name=Insulated Copper Cable +tile.techreborn.cable.insulatedgold.name=Insulated Gold Cable +tile.techreborn.cable.insulatedhv.name=Insulated HV Cable item.techreborn.scrapbox.name=Scrap Box item.techreborn.part.carbon_mesh.name=Carbon Mesh item.techreborn.part.carbon_fiber.name=Carbon Fiber diff --git a/src/main/resources/assets/techreborn/models/block/cable.json b/src/main/resources/assets/techreborn/models/block/cable.json index bd6a5052f..3dbecec3a 100644 --- a/src/main/resources/assets/techreborn/models/block/cable.json +++ b/src/main/resources/assets/techreborn/models/block/cable.json @@ -1,20 +1,21 @@ { - "credit": "Made with Blockbench, a free, modern block model editor by JannisX11", - "textures": {"0": "textures/#cable"}, - "elements": [ - { - "name": "Cable", - "from": [6, 6, 6], - "to": [10, 10, 10], - "shade": true, - "faces": { - "north": {"uv": [1, 1, 5, 5], "texture": "#0"}, - "east": {"uv": [1, 1, 5, 5], "texture": "#0"}, - "south": {"uv": [1, 1, 5, 5], "texture": "#0"}, - "west": {"uv": [1, 1, 5, 5], "texture": "#0"}, - "up": {"uv": [1, 1, 5, 5], "texture": "#0"}, - "down": {"uv": [1, 1, 5, 5], "texture": "#0"} - } - } - ] + "__comment": "Model generated using MrCrayfish's Model Creator (http://mrcrayfish.com/modelcreator/)", + "textures": { + "0": "#cable" + }, + "elements": [ + { + "name": "Cable", + "from": [ 5.0, 5.0, 5.0 ], + "to": [ 11.0, 11.0, 11.0 ], + "faces": { + "north": { "texture": "#0", "uv": [ 0.0, 0.0, 6.0, 6.0 ] }, + "east": { "texture": "#0", "uv": [ 0.0, 0.0, 6.0, 6.0 ] }, + "south": { "texture": "#0", "uv": [ 0.0, 0.0, 6.0, 6.0 ] }, + "west": { "texture": "#0", "uv": [ 0.0, 0.0, 6.0, 6.0 ] }, + "up": { "texture": "#0", "uv": [ 0.0, 0.0, 6.0, 6.0 ] }, + "down": { "texture": "#0", "uv": [ 0.0, 0.0, 6.0, 6.0 ] } + } + } + ] } \ No newline at end of file diff --git a/src/main/resources/assets/techreborn/models/block/cable_connection.json b/src/main/resources/assets/techreborn/models/block/cable_connection.json index 24a420436..f68853dc5 100644 --- a/src/main/resources/assets/techreborn/models/block/cable_connection.json +++ b/src/main/resources/assets/techreborn/models/block/cable_connection.json @@ -9,9 +9,9 @@ "from": [ 5.0, 5.0, 0.0 ], "to": [ 11.0, 11.0, 5.0 ], "faces": { - "north": { "texture": "#-1", "uv": [ 0.0, 0.0, 6.0, 6.0 ], "cullface": "north" }, + "north": { "texture": "#0", "uv": [ 0.0, 0.0, 6.0, 6.0 ], "cullface": "north" }, "east": { "texture": "#0", "uv": [ 0.0, 6.0, 5.0, 12.0 ] }, - "south": { "texture": "#-1", "uv": [ 0.0, 0.0, 6.0, 6.0 ], "cullface": "south" }, + "south": { "texture": "#0", "uv": [ 0.0, 0.0, 6.0, 6.0 ], "cullface": "south" }, "west": { "texture": "#0", "uv": [ 0.0, 6.0, 5.0, 12.0 ] }, "up": { "texture": "#0", "uv": [ 0.0, 6.0, 5.0, 12.0 ], "rotation": 90 }, "down": { "texture": "#0", "uv": [ 0.0, 6.0, 5.0, 12.0 ], "rotation": 90 } diff --git a/src/main/resources/assets/techreborn/models/block/cable_connection_alt.json b/src/main/resources/assets/techreborn/models/block/cable_connection_alt.json index cf7c94742..091fc6899 100644 --- a/src/main/resources/assets/techreborn/models/block/cable_connection_alt.json +++ b/src/main/resources/assets/techreborn/models/block/cable_connection_alt.json @@ -18,7 +18,7 @@ ], "faces": { "north": { - "texture": "#-1", + "texture": "#0", "uv": [ 0.0, 0.0, @@ -37,7 +37,7 @@ ] }, "south": { - "texture": "#-1", + "texture": "#0", "uv": [ 0.0, 0.0, diff --git a/src/main/resources/assets/techreborn/models/block/cable_connection_alt_thin.json b/src/main/resources/assets/techreborn/models/block/cable_connection_alt_thin.json index 85fe8563c..84102db99 100644 --- a/src/main/resources/assets/techreborn/models/block/cable_connection_alt_thin.json +++ b/src/main/resources/assets/techreborn/models/block/cable_connection_alt_thin.json @@ -10,13 +10,13 @@ "faces": { "north": { "uv": [1, 1, 5, 5], - "texture": "#-1", + "texture": "#0", "cullface": "north" }, "east": {"uv": [1, 7, 7, 11], "texture": "#0"}, "south": { "uv": [1, 1, 5, 5], - "texture": "#-1", + "texture": "#0", "cullface": "south" }, "west": {"uv": [1, 7, 7, 11], "texture": "#0"}, diff --git a/src/main/resources/assets/techreborn/models/block/cable_connection_thin.json b/src/main/resources/assets/techreborn/models/block/cable_connection_thin.json index 23e938e67..02734344d 100644 --- a/src/main/resources/assets/techreborn/models/block/cable_connection_thin.json +++ b/src/main/resources/assets/techreborn/models/block/cable_connection_thin.json @@ -10,13 +10,13 @@ "faces": { "north": { "uv": [1, 1, 5, 5], - "texture": "#-1", + "texture": "#0", "cullface": "north" }, "east": {"uv": [0, 7, 6, 11], "texture": "#0"}, "south": { "uv": [1, 1, 5, 5], - "texture": "#-1", + "texture": "#0", "cullface": "south" }, "west": {"uv": [0, 7, 6, 11], "texture": "#0"},