Added IC2 support for the wrench
This commit is contained in:
parent
c4abc14d7e
commit
8d3e2bff68
2 changed files with 91 additions and 1 deletions
61
APIs/ic2/api/tile/IWrenchable.java
Normal file
61
APIs/ic2/api/tile/IWrenchable.java
Normal file
|
@ -0,0 +1,61 @@
|
|||
package ic2.api.tile;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Allows a tile entity to make use of the wrench's removal and rotation functions.
|
||||
*/
|
||||
public interface IWrenchable {
|
||||
/**
|
||||
* Determine if the wrench can be used to set the block's facing.
|
||||
* Called before wrenchCanRemove().
|
||||
*
|
||||
* @param entityPlayer player using the wrench, may be null
|
||||
* @param side block's side the wrench was clicked on
|
||||
* @return Whether the wrenching was done and the wrench should be damaged
|
||||
*/
|
||||
boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side);
|
||||
|
||||
/**
|
||||
* Get the block's facing.
|
||||
*
|
||||
* @return Block facing
|
||||
*/
|
||||
short getFacing();
|
||||
|
||||
/**
|
||||
* Set the block's facing
|
||||
*
|
||||
* @param facing facing to set the block to
|
||||
*/
|
||||
void setFacing(short facing);
|
||||
|
||||
/**
|
||||
* Determine if the wrench can be used to remove the block.
|
||||
* Called if wrenchSetFacing fails.
|
||||
*
|
||||
* @param entityPlayer player using the wrench, may be null
|
||||
* @return Whether the wrenching was done and the wrench should be damaged
|
||||
*/
|
||||
boolean wrenchCanRemove(EntityPlayer entityPlayer);
|
||||
|
||||
/**
|
||||
* Determine the probability to drop the block as it is.
|
||||
* The first entry in getBlockDropped will be replaced by blockid:meta if the drop is successful.
|
||||
*
|
||||
* @return Probability from 0 to 1
|
||||
*/
|
||||
float getWrenchDropRate();
|
||||
|
||||
/**
|
||||
* Determine the item the block will drop when the wrenching is successful.
|
||||
*
|
||||
* The ItemStack will be copied before creating the EntityItem.
|
||||
*
|
||||
* @param entityPlayer player using the wrench, may be null
|
||||
* @return ItemStack to drop, may be null
|
||||
*/
|
||||
ItemStack getWrenchDrop(EntityPlayer entityPlayer);
|
||||
}
|
||||
|
|
@ -1,9 +1,12 @@
|
|||
package com.builtbroken.assemblyline.item;
|
||||
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
import ic2.api.tile.IWrenchable;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.Configuration;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
@ -13,6 +16,7 @@ import buildcraft.api.tools.IToolWrench;
|
|||
import com.builtbroken.assemblyline.AssemblyLine;
|
||||
import com.builtbroken.minecraft.DarkCore;
|
||||
import com.builtbroken.minecraft.IExtraInfo.IExtraItemInfo;
|
||||
import com.builtbroken.minecraft.helpers.DarksHelper;
|
||||
import com.builtbroken.minecraft.prefab.ItemBasic;
|
||||
|
||||
public class ItemWrench extends ItemBasic implements IToolWrench, IExtraItemInfo
|
||||
|
@ -31,11 +35,36 @@ public class ItemWrench extends ItemBasic implements IToolWrench, IExtraItemInfo
|
|||
@Override
|
||||
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (Block.blocksList[world.getBlockId(x, y, z)].rotateBlock(world, x, y, z, ForgeDirection.getOrientation(side)))
|
||||
TileEntity tile = world.getBlockTileEntity(x, y, z);
|
||||
Block block = Block.blocksList[world.getBlockId(x, y, z)];
|
||||
if (block != null && block.rotateBlock(world, x, y, z, ForgeDirection.getOrientation(side)))
|
||||
{
|
||||
this.wrenchUsed(player, x, y, z);
|
||||
return true;
|
||||
}
|
||||
if (tile instanceof IWrenchable && ((IWrenchable) tile).wrenchCanSetFacing(player, side))
|
||||
{
|
||||
ForgeDirection direction = ForgeDirection.getOrientation(side);
|
||||
short setSide = 0;
|
||||
if (player.isSneaking())
|
||||
{
|
||||
direction = direction.getOpposite();
|
||||
}
|
||||
setSide = (short) direction.ordinal();
|
||||
if (setSide != ((IWrenchable) tile).getFacing())
|
||||
{
|
||||
((IWrenchable) tile).setFacing(setSide);
|
||||
}
|
||||
else if (((IWrenchable) tile).wrenchCanRemove(player))
|
||||
{
|
||||
ItemStack output = ((IWrenchable) tile).getWrenchDrop(player);
|
||||
if(output != null)
|
||||
{
|
||||
world.setBlockToAir(x, y, z);
|
||||
DarksHelper.dropItemStack(world, new Vector3(x,y,z), output, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue