Added wrench
This commit is contained in:
parent
e3c71248a4
commit
9507c92d94
4 changed files with 90 additions and 2 deletions
|
@ -80,6 +80,7 @@ public class ModItems {
|
||||||
public static Item diamondChainsaw;
|
public static Item diamondChainsaw;
|
||||||
public static Item advancedChainsaw;
|
public static Item advancedChainsaw;
|
||||||
public static Item hammer;
|
public static Item hammer;
|
||||||
|
public static Item wrench;
|
||||||
|
|
||||||
public static Item upgrades;
|
public static Item upgrades;
|
||||||
|
|
||||||
|
@ -151,6 +152,9 @@ public class ModItems {
|
||||||
hammer = new ItemHammer(100);
|
hammer = new ItemHammer(100);
|
||||||
GameRegistry.registerItem(hammer, "hammer");
|
GameRegistry.registerItem(hammer, "hammer");
|
||||||
|
|
||||||
|
wrench = new ItemWrench();
|
||||||
|
GameRegistry.registerItem(wrench, "wrench");
|
||||||
|
|
||||||
// upgrades = new ItemUpgrade();
|
// upgrades = new ItemUpgrade();
|
||||||
// GameRegistry.registerItem(upgrades, "upgrades");
|
// GameRegistry.registerItem(upgrades, "upgrades");
|
||||||
|
|
||||||
|
|
83
src/main/java/techreborn/items/tools/ItemWrench.java
Normal file
83
src/main/java/techreborn/items/tools/ItemWrench.java
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
package techreborn.items.tools;
|
||||||
|
|
||||||
|
import ic2.api.tile.IWrenchable;
|
||||||
|
import net.minecraft.entity.item.EntityItem;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.BlockPos;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import techreborn.client.TechRebornCreativeTabMisc;
|
||||||
|
import techreborn.items.ItemTextureBase;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mark on 26/02/2016.
|
||||||
|
*/
|
||||||
|
public class ItemWrench extends ItemTextureBase {
|
||||||
|
|
||||||
|
public ItemWrench() {
|
||||||
|
setCreativeTab(TechRebornCreativeTabMisc.instance);
|
||||||
|
setUnlocalizedName("techreborn.wrench");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
|
||||||
|
if(world.isAirBlock(pos) || !player.isSneaking()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
TileEntity tile = world.getTileEntity(pos);
|
||||||
|
if(tile == null){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(tile instanceof IWrenchable){
|
||||||
|
if(((IWrenchable) tile).wrenchCanRemove(player)){
|
||||||
|
ItemStack itemStack = ((IWrenchable) tile).getWrenchDrop(player);
|
||||||
|
if(itemStack == null){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Random rand = new Random();
|
||||||
|
|
||||||
|
float dX = rand.nextFloat() * 0.8F + 0.1F;
|
||||||
|
float dY = rand.nextFloat() * 0.8F + 0.1F;
|
||||||
|
float dZ = rand.nextFloat() * 0.8F + 0.1F;
|
||||||
|
|
||||||
|
EntityItem entityItem = new EntityItem(world, pos.getX() + dX, pos.getY() + dY, pos.getZ() + dZ, itemStack.copy());
|
||||||
|
|
||||||
|
if (itemStack.hasTagCompound()) {
|
||||||
|
entityItem.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
|
||||||
|
}
|
||||||
|
|
||||||
|
float factor = 0.05F;
|
||||||
|
entityItem.motionX = rand.nextGaussian() * factor;
|
||||||
|
entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
|
||||||
|
entityItem.motionZ = rand.nextGaussian() * factor;
|
||||||
|
|
||||||
|
|
||||||
|
world.playSoundAtEntity(player, "techreborn:block_dismantle", 0.8F, 1F);
|
||||||
|
if(!world.isRemote){
|
||||||
|
world.spawnEntityInWorld(entityItem);
|
||||||
|
world.setBlockState(pos, Blocks.air.getDefaultState(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTextureName(int damage) {
|
||||||
|
return "techreborn:items/tool/wrench";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxMeta() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
{
|
{
|
||||||
"sap_extract": { "category": "block", "sounds":["sap_extract"] }
|
"sap_extract": { "category": "block", "sounds":["sap_extract"] },
|
||||||
|
"block_dismantle": { "category": "block", "sounds":["block_dismantle"] }
|
||||||
}
|
}
|
BIN
src/main/resources/assets/techreborn/sounds/block_dismantle.ogg
Normal file
BIN
src/main/resources/assets/techreborn/sounds/block_dismantle.ogg
Normal file
Binary file not shown.
Loading…
Reference in a new issue