use of net.minecraftforge.energy.IEnergyStorage in project Overloaded by CJ-MC-Mods.
the class ItemMultiTool method addInformation.
@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) {
IEnergyStorage handler = stack.getCapability(ENERGY, null);
tooltip.add(String.format("Energy Stored: %d", handler.getEnergyStored()));
super.addInformation(stack, playerIn, tooltip, advanced);
}
use of net.minecraftforge.energy.IEnergyStorage in project Overloaded by CJ-MC-Mods.
the class ItemMultiTool method rightClickWithItem.
public void rightClickWithItem(@Nonnull World worldIn, @Nonnull EntityPlayerMP player, @Nonnull BlockPos pos, @Nonnull EnumFacing sideHit, float hitX, float hitY, float hitZ) {
ItemStack multiTool = player.getHeldItemMainhand();
if (multiTool.getItem() != this) {
return;
}
NBTTagCompound tagCompound = multiTool.getTagCompound();
if (tagCompound == null || !tagCompound.hasKey("Item")) {
player.sendStatusMessage(new TextComponentString("No block type selected to place."), true);
return;
}
NBTTagCompound itemTag = tagCompound.getCompoundTag("Item");
ItemStack blockStack = new ItemStack(itemTag);
if (!(blockStack.getItem() instanceof ItemBlock)) {
player.sendStatusMessage(new TextComponentString("No valid block type selected to place."), true);
return;
}
IEnergyStorage energy = multiTool.getCapability(ENERGY, null);
Vec3i sideVector = sideHit.getDirectionVec();
BlockPos.MutableBlockPos newPosition = new BlockPos.MutableBlockPos(pos.add(sideVector));
if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
return;
if (player.isSneaking()) {
BlockPos playerPos = player.getPosition();
switch(sideHit) {
case UP:
while (newPosition.getY() < playerPos.getY()) {
newPosition.move(sideHit);
if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
break;
}
break;
case DOWN:
while (newPosition.getY() > playerPos.getY()) {
newPosition.move(sideHit);
if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
break;
}
break;
case NORTH:
while (newPosition.getZ() > playerPos.getZ()) {
newPosition.move(sideHit);
if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
break;
}
break;
case SOUTH:
while (newPosition.getZ() < playerPos.getZ()) {
newPosition.move(sideHit);
if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
break;
}
break;
case EAST:
while (newPosition.getX() < playerPos.getX()) {
newPosition.move(sideHit);
if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
break;
}
break;
case WEST:
while (newPosition.getX() > playerPos.getX()) {
newPosition.move(sideHit);
if (!placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ))
break;
}
break;
}
}
}
use of net.minecraftforge.energy.IEnergyStorage in project Overloaded by CJ-MC-Mods.
the class ItemMultiTool method onBlockDestroyed.
// @Override
// public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, EntityPlayer player) {
// return true;
// }
@Override
public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving) {
IEnergyStorage storage = stack.getCapability(ENERGY, null);
if (storage != null) {
int efficiency = EnchantmentHelper.getEnchantmentLevel(Enchantments.EFFICIENCY, stack);
int unbreaking = EnchantmentHelper.getEnchantmentLevel(Enchantments.UNBREAKING, stack);
float breakCost = getBreakCost(worldIn.getBlockState(pos).getBlockHardness(worldIn, pos), efficiency, unbreaking, entityLiving == null ? 10 : getDistance(entityLiving, pos));
storage.extractEnergy((int) Math.min(Integer.MAX_VALUE, breakCost), false);
}
return super.onBlockDestroyed(stack, worldIn, state, pos, entityLiving);
}
use of net.minecraftforge.energy.IEnergyStorage in project Overloaded by CJ-MC-Mods.
the class ItemMultiTool method leftClickOnBlockServer.
public void leftClickOnBlockServer(@Nonnull World world, @Nonnull EntityPlayerMP player, @Nonnull BlockPos pos) {
ItemStack itemStack = player.getHeldItem(EnumHand.MAIN_HAND);
if (itemStack.getItem() != this || world.isAirBlock(pos)) {
return;
}
player.setActiveHand(EnumHand.MAIN_HAND);
if (player.isSneaking()) {
NBTTagCompound tag = itemStack.getTagCompound();
if (tag == null) {
tag = new NBTTagCompound();
}
IBlockState state = world.getBlockState(pos);
Item item = Item.getItemFromBlock(state.getBlock());
ItemStack stackToPlace = new ItemStack(item, 1, state.getBlock().damageDropped(state));
NBTTagCompound blockTag = new NBTTagCompound();
stackToPlace.writeToNBT(blockTag);
tag.setTag("Item", blockTag);
itemStack.setTagCompound(tag);
ITextComponent component = stackToPlace.getTextComponent();
player.sendStatusMessage(new TextComponentString("Bound tool to ").appendSibling(component), true);
} else {
IEnergyStorage energy = itemStack.getCapability(ENERGY, null);
int efficiency = EnchantmentHelper.getEnchantmentLevel(Enchantments.EFFICIENCY, itemStack);
int unbreaking = EnchantmentHelper.getEnchantmentLevel(Enchantments.UNBREAKING, itemStack);
switch(breakAndUseEnergy(world, pos, energy, player, efficiency, unbreaking)) {
case FAIL_REMOVE:
player.sendStatusMessage(new TextComponentString("Unable to break block, reason unknown"), true);
break;
case FAIL_ENERGY:
player.sendStatusMessage(new TextComponentString("Unable to break block, not enough energy"), true);
break;
case FAIL_UNBREAKABLE:
player.sendStatusMessage(new TextComponentString("Block is unbreakable"), true);
break;
case SUCCESS:
break;
}
}
}
use of net.minecraftforge.energy.IEnergyStorage in project Overloaded by CJ-MC-Mods.
the class TileCreativeGeneratorFE method update.
/**
* Like the old updateEntity(), except more generic.
*/
@Override
public void update() {
if (getWorld().isRemote)
return;
BlockPos pos = this.getPos();
for (EnumFacing facing : EnumFacing.values()) {
TileEntity te = world.getTileEntity(pos.add(facing.getDirectionVec()));
if (te == null)
continue;
IEnergyStorage storage = te.getCapability(ENERGY, facing.getOpposite());
if (storage == null)
continue;
storage.receiveEnergy(Integer.MAX_VALUE, false);
}
}
Aggregations