Progress on BlockDimWall and its respective ItemBlock.

This commit is contained in:
zangamj 2016-06-24 16:43:59 -04:00
parent 3c94804241
commit 8e6626e46a
19 changed files with 143 additions and 80 deletions

View file

@ -5,6 +5,7 @@ import java.util.List;
import com.zixiken.dimdoors.items.*; import com.zixiken.dimdoors.items.*;
import com.zixiken.dimdoors.network.DimDoorsNetwork; import com.zixiken.dimdoors.network.DimDoorsNetwork;
import com.zixiken.dimdoors.render.BlockRenderManager;
import com.zixiken.dimdoors.schematic.BlockRotator; import com.zixiken.dimdoors.schematic.BlockRotator;
import com.zixiken.dimdoors.blocks.TransientDoor; import com.zixiken.dimdoors.blocks.TransientDoor;
import com.zixiken.dimdoors.commands.CommandListDungeons; import com.zixiken.dimdoors.commands.CommandListDungeons;
@ -226,6 +227,8 @@ public class DimDoors {
proxy.registerSidedHooks(); proxy.registerSidedHooks();
DimDoorsNetwork.init(); DimDoorsNetwork.init();
BlockRenderManager.addModelVariants();
} }
@Mod.EventHandler @Mod.EventHandler
@ -267,6 +270,8 @@ public class DimDoors {
// Register loot chests // Register loot chests
DDLoot.registerInfo(properties); DDLoot.registerInfo(properties);
MinecraftForge.EVENT_BUS.register(new ConnectionHandler()); MinecraftForge.EVENT_BUS.register(new ConnectionHandler());
BlockRenderManager.registerBlockRenderers();
} }
@Mod.EventHandler @Mod.EventHandler

View file

@ -7,21 +7,28 @@ import com.zixiken.dimdoors.DimDoors;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer; import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World; import net.minecraft.world.World;
import com.zixiken.dimdoors.client.PrivatePocketRender; import com.zixiken.dimdoors.client.PrivatePocketRender;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockDimWall extends Block { public class BlockDimWall extends Block {
public static final String ID = "blockDimWall"; public static final String ID = "blockDimWall";
public static final PropertyInteger TYPE = PropertyInteger.create("type", 0, 2);
private static final float SUPER_HIGH_HARDNESS = 10000000000000F; private static final float SUPER_HIGH_HARDNESS = 10000000000000F;
private static final float SUPER_EXPLOSION_RESISTANCE = 18000000F; private static final float SUPER_EXPLOSION_RESISTANCE = 18000000F;
private IIcon[] blockIcon = new IIcon[3];
public BlockDimWall() { public BlockDimWall() {
super(Material.iron); super(Material.iron);
@ -29,32 +36,32 @@ public class BlockDimWall extends Block {
setLightLevel(1.0F); setLightLevel(1.0F);
setHardness(0.1F); setHardness(0.1F);
setUnlocalizedName(ID); setUnlocalizedName(ID);
setDefaultState(blockState.getBaseState().withProperty(TYPE, 0));
} }
@Override @Override
public float getBlockHardness(World world, int x, int y, int z) public IBlockState getStateFromMeta(int meta) {
{ if(meta >= 0 && meta <= 2) return getDefaultState().withProperty(TYPE, meta);
if (world.getBlockMetadata(x, y, z) != 1) else return getDefaultState();
{
return this.blockHardness;
}
else
{
return SUPER_HIGH_HARDNESS;
}
} }
@Override @Override
public float getExplosionResistance(Entity entity, World world, int x, int y, int z, double explosionX, double explosionY, double explosionZ) public int getMetaFromState(IBlockState state) {return state.getValue(TYPE);}
{
@Override
protected BlockState createBlockState() {return new BlockState(this, TYPE);}
@Override
public float getBlockHardness(World world, int x, int y, int z) {
if (world.getBlockMetadata(x, y, z) != 1) return this.blockHardness;
else return SUPER_HIGH_HARDNESS;
}
@Override
public float getExplosionResistance(Entity entity, World world, int x, int y, int z, double explosionX, double explosionY, double explosionZ) {
if (world.getBlockMetadata(x, y, z) != 1) if (world.getBlockMetadata(x, y, z) != 1)
{
return super.getExplosionResistance(entity, world, x, y, z, explosionX, explosionY, explosionZ); return super.getExplosionResistance(entity, world, x, y, z, explosionX, explosionY, explosionZ);
} else return SUPER_EXPLOSION_RESISTANCE;
else
{
return SUPER_EXPLOSION_RESISTANCE;
}
} }
public int getRenderType() public int getRenderType()
@ -63,57 +70,30 @@ public class BlockDimWall extends Block {
} }
@Override @Override
public void registerBlockIcons(IIconRegister par1IconRegister) public int damageDropped(IBlockState state) {
{ int metadata = state.getValue(TYPE);
this.blockIcon[0] = par1IconRegister.registerIcon(DimDoors.modid + ":" + this.getUnlocalizedName());
this.blockIcon[1] = par1IconRegister.registerIcon(DimDoors.modid + ":" + this.getUnlocalizedName() + "Perm");
this.blockIcon[2] = par1IconRegister.registerIcon(DimDoors.modid + ":" + this.getUnlocalizedName() + "Personal");
}
@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(int par1, int par2)
{
switch(par2)
{
case 0:
return blockIcon[0];
case 1:
return blockIcon[1];
case 2:
return blockIcon[2];
default:
return blockIcon[0];
}
}
@Override
public int damageDropped(int metadata)
{
//Return 0 to avoid dropping Ancient Fabric even if the player somehow manages to break it //Return 0 to avoid dropping Ancient Fabric even if the player somehow manages to break it
return metadata == 1 ? 0 : metadata; return metadata == 1 ? 0 : metadata;
} }
@Override @Override
@SuppressWarnings({ "rawtypes", "unchecked" })
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void getSubBlocks(Item unknown, CreativeTabs tab, List subItems) public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> subItems) {
{
for (int ix = 0; ix < 3; ix++) for (int ix = 0; ix < 3; ix++)
{ subItems.add(new ItemStack(itemIn, 1, ix));
subItems.add(new ItemStack(this, 1, ix));
}
} }
@Override @Override
public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5) {} public boolean canSilkHarvest(World world, BlockPos pos, IBlockState state, EntityPlayer player)
@Override
protected boolean canSilkHarvest()
{ {
return true; return true;
} }
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, BlockPos pos, EntityPlayer player) {
return new ItemStack(Item.getItemFromBlock(this), 1, getMetaFromState(world.getBlockState(pos)));
}
@Override @Override
public int quantityDropped(Random par1Random) public int quantityDropped(Random par1Random)
{ {
@ -124,8 +104,7 @@ public class BlockDimWall extends Block {
* replaces the block clicked with the held block, instead of placing the block on top of it. Shift click to disable. * replaces the block clicked with the held block, instead of placing the block on top of it. Shift click to disable.
*/ */
@Override @Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) {
{
//Check if the metadata value is 0 -- we don't want the user to replace Ancient Fabric //Check if the metadata value is 0 -- we don't want the user to replace Ancient Fabric
if (entityPlayer.getCurrentEquippedItem() != null && world.getBlockMetadata(x, y, z) != 1) if (entityPlayer.getCurrentEquippedItem() != null && world.getBlockMetadata(x, y, z) != 1)
{ {

View file

@ -2,25 +2,18 @@ package com.zixiken.dimdoors.items;
import com.zixiken.dimdoors.DimDoors; import com.zixiken.dimdoors.DimDoors;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
public class ItemBlockDimWall extends ItemBlock public class ItemBlockDimWall extends ItemBlock {
{ private final static String[] subNames = {"", "Perm" , "Personal"};
private final static String[] subNames = {"tile.blockDimWall", "tile.blockAncientWall" , "tile.blockAlteredWall"};
public ItemBlockDimWall(Block block) public ItemBlockDimWall(Block block) {
{
super(block); super(block);
this.setCreativeTab(DimDoors.dimDoorsCreativeTab); setCreativeTab(DimDoors.dimDoorsCreativeTab);
setMaxDamage(0);
setHasSubtypes(true); setHasSubtypes(true);
} }
@Override
public void registerIcons(IIconRegister par1IconRegister)
{
this.itemIcon = par1IconRegister.registerIcon(DimDoors.modid + ":" + this.getUnlocalizedName().replace("tile.", ""));
}
@Override @Override
public int getMetadata (int damageValue) public int getMetadata (int damageValue)
@ -28,8 +21,7 @@ public class ItemBlockDimWall extends ItemBlock
return damageValue; return damageValue;
} }
public String getUnlocalizedName(ItemStack par1ItemStack) public String getUnlocalizedName(ItemStack stack) {
{ return super.getUnlocalizedName() + subNames[this.getDamage(stack)];
return subNames[this.getDamage(par1ItemStack)];
} }
} }

View file

@ -0,0 +1,38 @@
package com.zixiken.dimdoors.render;
import com.zixiken.dimdoors.DimDoors;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
public class BlockRenderManager {
private static final String ID = DimDoors.MODID;
public static void registerBlockRenderers() {
register(DimDoors.blockDimWall);
register(DimDoors.blockDimWall, 1, "Perm");
register(DimDoors.blockDimWall, 2, "Personal");
}
public static void addModelVariants() {
ModelBakery.registerItemVariants(Item.getItemFromBlock(DimDoors.blockDimWall),
new ResourceLocation(ID + ":blockDimWall"),
new ResourceLocation(ID + ":blockDimWallPerm"),
new ResourceLocation(ID + ":blockDimWallPersonal"));
}
private static void register(Block block) {
Minecraft.getMinecraft().getRenderItem().getItemModelMesher()
.register(Item.getItemFromBlock(block), 0,
new ModelResourceLocation(ID + ':' + block.getUnlocalizedName().substring(5)));
}
private static void register(Block block, int meta, String name) {
Minecraft.getMinecraft().getRenderItem().getItemModelMesher()
.register(Item.getItemFromBlock(block), meta, new ModelResourceLocation(ID + ':' +
block.getUnlocalizedName().substring(5) + name, "inventory"));
}
}

View file

@ -0,0 +1,7 @@
{
"variants": {
"type=0": { "model": "dimdoors:blockDimWall" },
"type=1": { "model": "dimdoors:blockDimWallPerm" },
"type=2": { "model": "dimdoors:blockDimWallPersonal" }
}
}

View file

@ -0,0 +1,4 @@
{
"parent": "block/cube_all",
"textures": { "all": "dimdoors:blocks/blockDimWall" }
}

View file

@ -0,0 +1,4 @@
{
"parent": "block/cube_all",
"textures": { "all": "dimdoors:blocks/blockDimWallPerm" }
}

View file

@ -0,0 +1,4 @@
{
"parent": "block/cube_all",
"textures": { "all": "dimdoors:blocks/blockDimWallPersonal" }
}

View file

@ -0,0 +1,10 @@
{
"parent": "dimdoors:block/blockDimWall",
"display": {
"thirdperson": {
"rotation": [ 10, -45, 170 ],
"translation": [ 0, 1.5, -2.75 ],
"scale": [ 0.375, 0.375, 0.375 ]
}
}
}

View file

@ -0,0 +1,10 @@
{
"parent": "dimdoors:block/blockDimWallPerm",
"display": {
"thirdperson": {
"rotation": [ 10, -45, 170 ],
"translation": [ 0, 1.5, -2.75 ],
"scale": [ 0.375, 0.375, 0.375 ]
}
}
}

View file

@ -0,0 +1,10 @@
{
"parent": "dimdoors:block/blockDimWallPersonal",
"display": {
"thirdperson": {
"rotation": [ 10, -45, 170 ],
"translation": [ 0, 1.5, -2.75 ],
"scale": [ 0.375, 0.375, 0.375 ]
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB