Add Electric Treetap & Make sap go directly into inventory : From: 2aa69a1425eb8928d530c58e7c8a2495e71ea78f

This commit is contained in:
modmuss50 2016-11-05 16:33:27 +00:00
parent 9e47eb8cfe
commit dda189fbc6
No known key found for this signature in database
GPG key ID: 203A5ED4D3E48BEA
3 changed files with 136 additions and 28 deletions

View file

@ -18,13 +18,12 @@ import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.server.permission.PermissionAPI;
import net.minecraftforge.server.permission.context.BlockPosContext;
import reborncore.RebornCore; import reborncore.RebornCore;
import reborncore.common.util.RebornPermissions; import reborncore.common.powerSystem.PoweredItem;
import techreborn.client.TechRebornCreativeTabMisc; import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.init.ModSounds; import techreborn.init.ModSounds;
import techreborn.items.ItemParts; import techreborn.items.ItemParts;
import techreborn.items.tools.ItemElectricTreetap;
import techreborn.items.tools.ItemTreeTap; import techreborn.items.tools.ItemTreeTap;
import java.util.ArrayList; import java.util.ArrayList;
@ -150,11 +149,9 @@ public class BlockRubberLog extends Block implements ITexturedBlock {
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
super.onBlockActivated(worldIn, pos, state, playerIn, hand, heldItem, side, hitX, hitY, hitZ); super.onBlockActivated(worldIn, pos, state, playerIn, hand, heldItem, side, hitX, hitY, hitZ);
if(!PermissionAPI.hasPermission(playerIn.getGameProfile(), RebornPermissions.TAP_BLOCK, new BlockPosContext(playerIn, pos, worldIn.getBlockState(pos), side))){ ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
return false; if (stack != null)
} if ((stack.getItem() instanceof ItemElectricTreetap && PoweredItem.canUseEnergy(20, stack)) || stack.getItem() instanceof ItemTreeTap)
if (playerIn.getHeldItem(EnumHand.MAIN_HAND) != null
&& playerIn.getHeldItem(EnumHand.MAIN_HAND).getItem() instanceof ItemTreeTap)
if (state.getValue(HAS_SAP)) { if (state.getValue(HAS_SAP)) {
if (state.getValue(SAP_SIDE) == side) { if (state.getValue(SAP_SIDE) == side) {
worldIn.setBlockState(pos, worldIn.setBlockState(pos,
@ -163,17 +160,23 @@ public class BlockRubberLog extends Block implements ITexturedBlock {
pos.getZ(), ModSounds.extract, pos.getZ(), ModSounds.extract,
SoundCategory.BLOCKS, 0.6F, 1F); SoundCategory.BLOCKS, 0.6F, 1F);
if (!worldIn.isRemote) { if (!worldIn.isRemote) {
if (stack.getItem() instanceof ItemElectricTreetap) {
PoweredItem.useEnergy(20, stack);
} else {
playerIn.getHeldItem(EnumHand.MAIN_HAND).damageItem(1, playerIn);
}
if (!playerIn.inventory.addItemStackToInventory(ItemParts.getPartByName("rubberSap").copy())) {
Random rand = new Random(); Random rand = new Random();
BlockPos itemPos = pos.offset(side); BlockPos itemPos = pos.offset(side);
EntityItem item = new EntityItem(worldIn, itemPos.getX(), itemPos.getY(), itemPos.getZ(), EntityItem item = new EntityItem(worldIn, itemPos.getX(), itemPos.getY(), itemPos.getZ(),
ItemParts.getPartByName("rubberSap").copy()); ItemParts.getPartByName("rubberSap").copy());
float factor = 0.05F; float factor = 0.05F;
playerIn.getHeldItem(EnumHand.MAIN_HAND).damageItem(1, playerIn);
item.motionX = rand.nextGaussian() * factor; item.motionX = rand.nextGaussian() * factor;
item.motionY = rand.nextGaussian() * factor + 0.2F; item.motionY = rand.nextGaussian() * factor + 0.2F;
item.motionZ = rand.nextGaussian() * factor; item.motionZ = rand.nextGaussian() * factor;
worldIn.spawnEntityInWorld(item); worldIn.spawnEntityInWorld(item);
} }
}
return true; return true;
} }
} }

View file

@ -44,6 +44,7 @@ public class ModItems {
public static Item reBattery; public static Item reBattery;
public static Item treeTap; public static Item treeTap;
public static Item electricTreetap;
public static Item ironDrill; public static Item ironDrill;
public static Item diamondDrill; public static Item diamondDrill;
@ -162,6 +163,9 @@ public class ModItems {
treeTap = new ItemTreeTap(); treeTap = new ItemTreeTap();
registerItem(treeTap, "treetap"); registerItem(treeTap, "treetap");
electricTreetap = PoweredItem.createItem(ItemElectricTreetap.class);
registerItem(electricTreetap, "electricTreetap");
ironDrill = PoweredItem.createItem(ItemSteelDrill.class); ironDrill = PoweredItem.createItem(ItemSteelDrill.class);
registerItem(ironDrill, "irondrill"); registerItem(ironDrill, "irondrill");
diamondDrill = PoweredItem.createItem(ItemDiamondDrill.class); diamondDrill = PoweredItem.createItem(ItemDiamondDrill.class);

View file

@ -0,0 +1,101 @@
package techreborn.items.tools;
import me.modmuss50.jsonDestroyer.api.ITexturedItem;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import reborncore.RebornCore;
import reborncore.api.power.IEnergyItemInfo;
import reborncore.common.powerSystem.PoweredItem;
import techreborn.client.TechRebornCreativeTab;
import techreborn.lib.ModInfo;
import java.util.List;
/**
* Created by modmuss50 on 05/11/2016.
*/
public class ItemElectricTreetap extends Item implements IEnergyItemInfo, ITexturedItem {
public static final int maxCharge = 5120;
public static final int tier = 1;
public int cost = 20;
public ItemElectricTreetap() {
super();
setUnlocalizedName("techreborn.electric_treetap");
setCreativeTab(TechRebornCreativeTab.instance);
setMaxStackSize(1);
RebornCore.jsonDestroyer.registerObject(this);
}
@Override
public double getMaxPower(ItemStack stack) {
return maxCharge;
}
@Override
public boolean canAcceptEnergy(ItemStack stack) {
return true;
}
@Override
public boolean canProvideEnergy(ItemStack stack) {
return false;
}
@Override
public double getMaxTransfer(ItemStack stack) {
return 200;
}
@Override
public int getStackTier(ItemStack stack) {
return tier;
}
@Override
public double getDurabilityForDisplay(ItemStack stack) {
double charge = (PoweredItem.getEnergy(stack) / getMaxPower(stack));
return 1 - charge;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) {
ItemStack itemStack = new ItemStack(this, 1);
itemList.add(itemStack);
ItemStack charged = new ItemStack(this, 1);
PoweredItem.setEnergy(getMaxPower(charged), charged);
itemList.add(charged);
}
@Override
public boolean showDurabilityBar(ItemStack stack) {
return true;
}
@Override
public String getTextureName(int damage) {
return "techreborn:items/tool/electricTreetap";
}
@Override
public int getMaxMeta() {
return 1;
}
@Override
@SideOnly(Side.CLIENT)
public ModelResourceLocation getModel(ItemStack stack, EntityPlayer player,
int useRemaining) {
return new ModelResourceLocation(ModInfo.MOD_ID + ":" + getUnlocalizedName(stack).substring(5), "inventory");
}
}