Jump to content

[1.7.10][Deobfuscated] Custom Door


Nicba1010

Recommended Posts

So I've wanted to make a new door, with a code gui.

I have a problem obviously.

BlockBase:

package com.nicba1010.chem.block;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;

import com.nicba1010.chem.creativetab.ChemCreativeTabs;
import com.nicba1010.chem.reference.Reference;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockBase extends Block {
public BlockBase(Material material) {
	super(material);
	this.setCreativeTab(ChemCreativeTabs.CHEM_TAB);
}

public BlockBase() {
	this(Material.rock);
}

@Override
public String getUnlocalizedName() {
	return String.format("tile.%s%s", Reference.MOD_ID.toLowerCase() + ":",
			getUnwrappedUnlocalizedName(super.getUnlocalizedName()));
}

@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
	blockIcon = iconRegister.registerIcon(String.format("%s",
			getUnwrappedUnlocalizedName(this.getUnlocalizedName())));
}

protected String getUnwrappedUnlocalizedName(String unlocalizedName) {
	return unlocalizedName.substring(unlocalizedName.indexOf(".") + 1);
}
}

BlockContainerBase:

package com.nicba1010.chem.block;

import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

public abstract class BlockContainerBase extends BlockBase implements
	ITileEntityProvider {

protected BlockContainerBase(Material material) {
	super(material);
	this.isBlockContainer = true;
}

/**
 * Called whenever the block is added into the world. Args: world, x, y, z
 */
public void onBlockAdded(World world, int x,
		int y, int z) {
	super.onBlockAdded(world, x, y, z);
}

public void breakBlock(World world, int x, int y,
		int z, Block block, int p_149749_6_) {
	super.breakBlock(world, x, y, z,
			block, p_149749_6_);
	world.removeTileEntity(x, y, z);
}

public boolean onBlockEventReceived(World world, int x,
		int y, int z, int p_149696_5_, int p_149696_6_) {
	super.onBlockEventReceived(world, x, y,
			z, p_149696_5_, p_149696_6_);
	TileEntity tileentity = world.getTileEntity(x,
			y, z);
	return tileentity != null ? tileentity.receiveClientEvent(p_149696_5_,
			p_149696_6_) : false;
}
}

BlockCodeDoor:

package com.nicba1010.chem.block;

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.IconFlipped;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockCodeDoor extends BlockContainerBase {
@SideOnly(Side.CLIENT)
private IIcon[] field_150017_a;
@SideOnly(Side.CLIENT)
private IIcon[] field_150016_b;

public BlockCodeDoor(Material material) {
	super(material);
	float f = 0.5F;
	float f1 = 1.0F;
	this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f1, 0.5F + f);
}

/**
 * Gets the block's texture. Args: side, meta
 */
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int meta) {
	return this.field_150016_b[0];
}

@SideOnly(Side.CLIENT)
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
	if (side != 1 && side != 0) {
		int i1 = this.func_150012_g(world, x, y, z);
		int j1 = i1 & 3;
		boolean flag = (i1 & 4) != 0;
		boolean flag1 = false;
		boolean flag2 = (i1 &  != 0;

		if (flag) {
			if (j1 == 0 && side == 2) {
				flag1 = !flag1;
			} else if (j1 == 1 && side == 5) {
				flag1 = !flag1;
			} else if (j1 == 2 && side == 3) {
				flag1 = !flag1;
			} else if (j1 == 3 && side == 4) {
				flag1 = !flag1;
			}
		} else {
			if (j1 == 0 && side == 5) {
				flag1 = !flag1;
			} else if (j1 == 1 && side == 3) {
				flag1 = !flag1;
			} else if (j1 == 2 && side == 4) {
				flag1 = !flag1;
			} else if (j1 == 3 && side == 2) {
				flag1 = !flag1;
			}

			if ((i1 & 16) != 0) {
				flag1 = !flag1;
			}
		}

		return flag2 ? this.field_150017_a[flag1 ? 1 : 0]
				: this.field_150016_b[flag1 ? 1 : 0];
	} else {
		return this.field_150016_b[0];
	}
}

@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister p_149651_1_) {
	this.field_150017_a = new IIcon[2];
	this.field_150016_b = new IIcon[2];
	this.field_150017_a[0] = p_149651_1_.registerIcon(this.getTextureName()
			+ "_upper");
	this.field_150016_b[0] = p_149651_1_.registerIcon(this.getTextureName()
			+ "_lower");
	this.field_150017_a[1] = new IconFlipped(this.field_150017_a[0], true,
			false);
	this.field_150016_b[1] = new IconFlipped(this.field_150016_b[0], true,
			false);
}

/**
 * Is this block (a) opaque and (b) a full 1m cube? This determines whether
 * or not to render the shared face of two adjacent blocks and also whether
 * the player can attach torches, redstone wire, etc to this block.
 */
public boolean isOpaqueCube() {
	return false;
}

public boolean getBlocksMovement(IBlockAccess world, int x, int y, int z) {
	int l = this.func_150012_g(world, x, y, z);
	return (l & 4) != 0;
}

/**
 * If this block doesn't render as an ordinary block it will return False
 * (examples: signs, buttons, stairs, etc)
 */
public boolean renderAsNormalBlock() {
	return false;
}

/**
 * The type of render function that is called for this block
 */
public int getRenderType() {
	return 7;
}

/**
 * Returns the bounding box of the wired rectangular prism to render.
 */
@SideOnly(Side.CLIENT)
public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x,
		int y, int z) {
	this.setBlockBoundsBasedOnState(world, x, y, z);
	return super.getSelectedBoundingBoxFromPool(world, x, y, z);
}

/**
 * Returns a bounding box from the pool of bounding boxes (this means this
 * box can change after the pool has been cleared to be reused)
 */
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x,
		int y, int z) {
	this.setBlockBoundsBasedOnState(world, x, y, z);
	return super.getCollisionBoundingBoxFromPool(world, x, y, z);
}

/**
 * Updates the blocks bounds based on its current state. Args: world, x, y,
 * z
 */
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y,
		int z) {
	this.func_150011_b(this.func_150012_g(world, x, y, z));
}

public int func_150013_e(IBlockAccess world, int x, int y, int z) {
	return this.func_150012_g(world, x, y, z) & 3;
}

public boolean func_150015_f(IBlockAccess world, int x, int y, int z) {
	return (this.func_150012_g(world, x, y, z) & 4) != 0;
}

private void func_150011_b(int p_150011_1_) {
	float f = 0.1875F;
	this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 2.0F, 1.0F);
	int j = p_150011_1_ & 3;
	boolean flag = (p_150011_1_ & 4) != 0;
	boolean flag1 = (p_150011_1_ & 16) != 0;

	if (j == 0) {
		if (flag) {
			if (!flag1) {
				this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
			} else {
				this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
			}
		} else {
			this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
		}
	} else if (j == 1) {
		if (flag) {
			if (!flag1) {
				this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
			} else {
				this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
			}
		} else {
			this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
		}
	} else if (j == 2) {
		if (flag) {
			if (!flag1) {
				this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
			} else {
				this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
			}
		} else {
			this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
		}
	} else if (j == 3) {
		if (flag) {
			if (!flag1) {
				this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
			} else {
				this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
			}
		} else {
			this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
		}
	}
}

/**
 * Called when a player hits the block. Args: world, x, y, z, player
 */
public void onBlockClicked(World world, int x, int y, int z,
		EntityPlayer player) {
}

/**
 * Called upon block activation (right click on the block.)
 */
public boolean onBlockActivated(World world, int x, int y, int z,
		EntityPlayer player, int p_149727_6_, float p_149727_7_,
		float p_149727_8_, float p_149727_9_) {
	if (this.blockMaterial == Material.iron) {
		return false; // Allow items to interact with the door
	} else {
		int i1 = this.func_150012_g(world, x, y, z);
		int j1 = i1 & 7;
		j1 ^= 4;

		if ((i1 &  == 0) {
			world.setBlockMetadataWithNotify(x, y, z, j1, 2);
			world.markBlockRangeForRenderUpdate(x, y, z, x, y, z);
		} else {
			world.setBlockMetadataWithNotify(x, y - 1, z, j1, 2);
			world.markBlockRangeForRenderUpdate(x, y - 1, z, x, y, z);
		}

		world.playAuxSFXAtEntity(player, 1003, x, y, z, 0);
		return true;
	}
}

public void func_150014_a(World world, int x, int y, int z,
		boolean p_150014_5_) {
	int l = this.func_150012_g(world, x, y, z);
	boolean flag1 = (l & 4) != 0;

	if (flag1 != p_150014_5_) {
		int i1 = l & 7;
		i1 ^= 4;

		if ((l &  == 0) {
			world.setBlockMetadataWithNotify(x, y, z, i1, 2);
			world.markBlockRangeForRenderUpdate(x, y, z, x, y, z);
		} else {
			world.setBlockMetadataWithNotify(x, y - 1, z, i1, 2);
			world.markBlockRangeForRenderUpdate(x, y - 1, z, x, y, z);
		}

		world.playAuxSFXAtEntity((EntityPlayer) null, 1003, x, y, z, 0);
	}
}

/**
 * Lets the block know when one of its neighbor changes. Doesn't know which
 * neighbor changed (coordinates passed are their own) Args: x, y, z,
 * neighbor Block
 */
public void onNeighborBlockChange(World world, int x, int y, int z,
		Block neighbourBlock) {
	int l = world.getBlockMetadata(x, y, z);

	if ((l &  == 0) {
		boolean flag = false;

		if (world.getBlock(x, y + 1, z) != this) {
			world.setBlockToAir(x, y, z);
			flag = true;
		}

		if (!World.doesBlockHaveSolidTopSurface(world, x, y - 1, z)) {
			world.setBlockToAir(x, y, z);
			flag = true;

			if (world.getBlock(x, y + 1, z) == this) {
				world.setBlockToAir(x, y + 1, z);
			}
		}

		if (flag) {
			if (!world.isRemote) {
				this.dropBlockAsItem(world, x, y, z, l, 0);
			}
		} else {
			boolean flag1 = world.isBlockIndirectlyGettingPowered(x, y, z)
					|| world.isBlockIndirectlyGettingPowered(x, y + 1, z);

			if ((flag1 || neighbourBlock.canProvidePower())
					&& neighbourBlock != this) {
				this.func_150014_a(world, x, y, z, flag1);
			}
		}
	} else {
		if (world.getBlock(x, y - 1, z) != this) {
			world.setBlockToAir(x, y, z);
		}

		if (neighbourBlock != this) {
			this.onNeighborBlockChange(world, x, y - 1, z, neighbourBlock);
		}
	}
}

public Item getItemDropped(int p_149650_1_, Random p_149650_2_,
		int p_149650_3_) {
	return (p_149650_1_ &  != 0 ? null
			: (this.blockMaterial == Material.iron ? Items.iron_door
					: Items.wooden_door);
}

/**
 * Ray traces through the blocks collision from start vector to end vector
 * returning a ray trace hit. Args: world, x, y, z, startVec, endVec
 */
public MovingObjectPosition collisionRayTrace(World world, int x, int y,
		int z, Vec3 startVec, Vec3 endVec) {
	this.setBlockBoundsBasedOnState(world, x, y, z);
	return super.collisionRayTrace(world, x, y, z, startVec, endVec);
}

/**
 * Checks to see if its valid to put this block at the specified
 * coordinates. Args: world, x, y, z
 */
public boolean canPlaceBlockAt(World world, int x, int y, int z) {
	return y >= world.getHeight() - 1 ? false : World
			.doesBlockHaveSolidTopSurface(world, x, y - 1, z)
			&& super.canPlaceBlockAt(world, x, y, z)
			&& super.canPlaceBlockAt(world, x, y + 1, z);
}

/**
 * Returns the mobility information of the block, 0 = free, 1 = can't push
 * but can move over, 2 = total immobility and stop pistons
 */
public int getMobilityFlag() {
	return 1;
}

public int func_150012_g(IBlockAccess world, int x, int y, int z) {
	int l = world.getBlockMetadata(x, y, z);
	boolean flag = (l &  != 0;
	int i1;
	int j1;

	if (flag) {
		i1 = world.getBlockMetadata(x, y - 1, z);
		j1 = l;
	} else {
		i1 = l;
		j1 = world.getBlockMetadata(x, y + 1, z);
	}

	boolean flag1 = (j1 & 1) != 0;
	return i1 & 7 | (flag ? 8 : 0) | (flag1 ? 16 : 0);
}

/**
 * Gets an item for the block being called on. Args: world, x, y, z
 */
@SideOnly(Side.CLIENT)
public Item getItem(World world, int x, int y, int z) {
	return this.blockMaterial == Material.iron ? Items.iron_door
			: Items.wooden_door;
}

/**
 * Called when the block is attempted to be harvested
 */
public void onBlockHarvested(World world, int x, int y, int z,
		int p_149681_5_, EntityPlayer player) {
	if (player.capabilities.isCreativeMode && (p_149681_5_ &  != 0
			&& world.getBlock(x, y - 1, z) == this) {
		world.setBlockToAir(x, y - 1, z);
	}
}

@Override
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
	// TODO Auto-generated method stub
	return null;
}
}

So, the problem is that the block is displaying invisible, and does not have a 2 high bounding box;

P.S. I have no texture, but it should have that pretty (khm sarcasm) pink-black missing texture.

P.P.S. As you see I've taken my time to deobf the code so you can read it easier!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.