Created some basic tool prefabs which includes support for energy & tool modes
This commit is contained in:
parent
15d96e3563
commit
8ca3070735
3 changed files with 300 additions and 74 deletions
|
@ -4,17 +4,13 @@ import java.awt.Color;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import resonantinduction.core.ResonantInduction;
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.creativetab.CreativeTabs;
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.EnumAction;
|
import net.minecraft.item.EnumAction;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.potion.Potion;
|
|
||||||
import net.minecraft.potion.PotionEffect;
|
|
||||||
import net.minecraft.util.DamageSource;
|
import net.minecraft.util.DamageSource;
|
||||||
import net.minecraft.util.EnumMovingObjectType;
|
import net.minecraft.util.EnumMovingObjectType;
|
||||||
import net.minecraft.util.MathHelper;
|
import net.minecraft.util.MathHelper;
|
||||||
|
@ -23,8 +19,9 @@ import net.minecraft.util.Vec3;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
import resonantinduction.core.ResonantInduction;
|
||||||
|
import resonantinduction.core.prefab.items.ItemEnergyTool;
|
||||||
import universalelectricity.api.UniversalClass;
|
import universalelectricity.api.UniversalClass;
|
||||||
import universalelectricity.api.item.ItemElectric;
|
|
||||||
import universalelectricity.api.vector.IVector3;
|
import universalelectricity.api.vector.IVector3;
|
||||||
import universalelectricity.api.vector.Vector3;
|
import universalelectricity.api.vector.Vector3;
|
||||||
import calclavia.api.resonantinduction.electrical.LaserEvent;
|
import calclavia.api.resonantinduction.electrical.LaserEvent;
|
||||||
|
@ -47,16 +44,18 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||||
*
|
*
|
||||||
* @author DarkGuardsman */
|
* @author DarkGuardsman */
|
||||||
@UniversalClass
|
@UniversalClass
|
||||||
public class ItemMiningLaser extends ItemElectric
|
public class ItemMiningLaser extends ItemEnergyTool
|
||||||
{
|
{
|
||||||
long batterySize = 500000;
|
/** Cost per tick of using the item */
|
||||||
float wattPerShot = 1;
|
float wattPerShot = 1;
|
||||||
|
/** Damage to entities hit by the laser */
|
||||||
float damageToEntities = 3.3f;
|
float damageToEntities = 3.3f;
|
||||||
|
/** Range of the laser ray trace */
|
||||||
int blockRange = 50;
|
int blockRange = 50;
|
||||||
int firingDelay = 5;
|
/** Time to break a single block */
|
||||||
int breakTime = 15;
|
int breakTime = 15;
|
||||||
boolean createLava = true, setFire = true;
|
|
||||||
|
|
||||||
|
/** Map of players and how long they have focused the laser on a single block */
|
||||||
HashMap<EntityPlayer, Pair<Vector3, Integer>> miningMap = new HashMap<EntityPlayer, Pair<Vector3, Integer>>();
|
HashMap<EntityPlayer, Pair<Vector3, Integer>> miningMap = new HashMap<EntityPlayer, Pair<Vector3, Integer>>();
|
||||||
|
|
||||||
public ItemMiningLaser(int id)
|
public ItemMiningLaser(int id)
|
||||||
|
@ -81,41 +80,23 @@ public class ItemMiningLaser extends ItemElectric
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate(ItemStack itemStack, World par2World, Entity entity, int par4, boolean par5)
|
public void onUpdate(ItemStack itemStack, World world, Entity entity, int slot, boolean currentHeldItem)
|
||||||
{
|
{
|
||||||
//Slow any entity that carries this down as a side effect of using heavy mining gear
|
//Remove player from mining map if he puts the laser gun away
|
||||||
if (entity instanceof EntityLivingBase)
|
if (!currentHeldItem && entity instanceof EntityPlayer && this.miningMap.containsKey(entity))
|
||||||
{
|
{
|
||||||
boolean flag = entity instanceof EntityPlayer && ((EntityPlayer) entity).capabilities.isCreativeMode;
|
this.miningMap.remove(entity);
|
||||||
|
|
||||||
if (!flag)
|
|
||||||
{
|
|
||||||
//((EntityLivingBase) entity).addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 5, 0));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//((EntityPlayer) entity).setItemInUse(itemStack, this.getMaxItemUseDuration(itemStack));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreated(ItemStack stack, World par2World, EntityPlayer entityPlayer)
|
|
||||||
{
|
|
||||||
this.setEnergy(stack, 0);
|
|
||||||
if (stack.getTagCompound() == null)
|
|
||||||
{
|
|
||||||
stack.setTagCompound(new NBTTagCompound());
|
|
||||||
}
|
|
||||||
if (entityPlayer != null)
|
|
||||||
{
|
|
||||||
stack.getTagCompound().setString("Creator", entityPlayer.username);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUsingItemTick(ItemStack stack, EntityPlayer player, int count)
|
public void onUsingItemTick(ItemStack stack, EntityPlayer player, int count)
|
||||||
{
|
{
|
||||||
|
//Small delay to prevent unwanted usage of the item
|
||||||
|
//TODO increase this delay to simulate warm up time
|
||||||
|
//TODO increase break time longer the laser has been running
|
||||||
|
//TODO match hardness of block for break time
|
||||||
|
//TODO add audio
|
||||||
if (count > 5)
|
if (count > 5)
|
||||||
{
|
{
|
||||||
Vec3 playerPosition = Vec3.createVectorHelper(player.posX, player.posY + player.getEyeHeight(), player.posZ);
|
Vec3 playerPosition = Vec3.createVectorHelper(player.posX, player.posY + player.getEyeHeight(), player.posZ);
|
||||||
|
@ -125,7 +106,6 @@ public class ItemMiningLaser extends ItemElectric
|
||||||
Vec3 playerViewOffset = Vec3.createVectorHelper(playerPosition.xCoord + playerLook.xCoord * blockRange, playerPosition.yCoord + playerLook.yCoord * blockRange, playerPosition.zCoord + playerLook.zCoord * blockRange);
|
Vec3 playerViewOffset = Vec3.createVectorHelper(playerPosition.xCoord + playerLook.xCoord * blockRange, playerPosition.yCoord + playerLook.yCoord * blockRange, playerPosition.zCoord + playerLook.zCoord * blockRange);
|
||||||
MovingObjectPosition hit = RayTraceHelper.do_rayTraceFromEntity(player, new Vector3().toVec3(), blockRange, true);
|
MovingObjectPosition hit = RayTraceHelper.do_rayTraceFromEntity(player, new Vector3().toVec3(), blockRange, true);
|
||||||
|
|
||||||
//TODO fix sound
|
|
||||||
if (hit != null)
|
if (hit != null)
|
||||||
{
|
{
|
||||||
LaserEvent event = new LaserEvent.LaserFiredPlayerEvent(player, hit, stack);
|
LaserEvent event = new LaserEvent.LaserFiredPlayerEvent(player, hit, stack);
|
||||||
|
@ -188,11 +168,18 @@ public class ItemMiningLaser extends ItemElectric
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack onItemRightClick(ItemStack itemStack, World par2World, EntityPlayer player)
|
public ItemStack onItemRightClick(ItemStack itemStack, World par2World, EntityPlayer player)
|
||||||
|
{
|
||||||
|
if (!player.isSneaking())
|
||||||
{
|
{
|
||||||
if (player.capabilities.isCreativeMode || this.getEnergy(itemStack) > this.wattPerShot)
|
if (player.capabilities.isCreativeMode || this.getEnergy(itemStack) > this.wattPerShot)
|
||||||
{
|
{
|
||||||
player.setItemInUse(itemStack, this.getMaxItemUseDuration(itemStack));
|
player.setItemInUse(itemStack, this.getMaxItemUseDuration(itemStack));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
return itemStack;
|
return itemStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,37 +197,4 @@ public class ItemMiningLaser extends ItemElectric
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack onEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
|
|
||||||
{
|
|
||||||
return par1ItemStack;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
|
||||||
@Override
|
|
||||||
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4)
|
|
||||||
{
|
|
||||||
super.addInformation(stack, player, list, par4);
|
|
||||||
if (stack.getTagCompound() == null)
|
|
||||||
{
|
|
||||||
stack.setTagCompound(new NBTTagCompound());
|
|
||||||
}
|
|
||||||
String creator = stack.getTagCompound().getString("Creator");
|
|
||||||
if (!creator.equalsIgnoreCase("creative") && creator != "")
|
|
||||||
{
|
|
||||||
list.add("Created by: " + creator);
|
|
||||||
}
|
|
||||||
else if (creator.equalsIgnoreCase("creative"))
|
|
||||||
{
|
|
||||||
list.add("Created by Magic Dwarfs");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getEnergyCapacity(ItemStack theItem)
|
|
||||||
{
|
|
||||||
return this.batterySize;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,181 @@
|
||||||
|
package resonantinduction.core.prefab.items;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import calclavia.lib.render.EnumColor;
|
||||||
|
import calclavia.lib.utility.LanguageUtility;
|
||||||
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import resonantinduction.electrical.battery.TileBattery;
|
||||||
|
import universalelectricity.api.CompatibilityModule;
|
||||||
|
import universalelectricity.api.UniversalElectricity;
|
||||||
|
import universalelectricity.api.energy.UnitDisplay;
|
||||||
|
import universalelectricity.api.energy.UnitDisplay.Unit;
|
||||||
|
import universalelectricity.api.item.IEnergyItem;
|
||||||
|
import universalelectricity.api.item.IVoltageItem;
|
||||||
|
|
||||||
|
/** Prefab for all eletric based tools
|
||||||
|
*
|
||||||
|
* @author DarkGurdsman */
|
||||||
|
public class ItemEnergyTool extends ItemTool implements IEnergyItem, IVoltageItem
|
||||||
|
{
|
||||||
|
protected long batterySize = 500000;
|
||||||
|
protected boolean hasTier = false;
|
||||||
|
protected boolean showEnergy = true;
|
||||||
|
|
||||||
|
public ItemEnergyTool(int id)
|
||||||
|
{
|
||||||
|
super(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public void addInformation(ItemStack itemStack, EntityPlayer entityPlayer, List list, boolean par4)
|
||||||
|
{
|
||||||
|
if (hasTier)
|
||||||
|
list.add(LanguageUtility.getLocal("tooltip.tier") + ": " + (getTier(itemStack) + 1));
|
||||||
|
|
||||||
|
if (showEnergy)
|
||||||
|
{
|
||||||
|
String color = "";
|
||||||
|
long joules = this.getEnergy(itemStack);
|
||||||
|
|
||||||
|
if (joules <= this.getEnergyCapacity(itemStack) / 3)
|
||||||
|
{
|
||||||
|
color = "\u00a74";
|
||||||
|
}
|
||||||
|
else if (joules > this.getEnergyCapacity(itemStack) * 2 / 3)
|
||||||
|
{
|
||||||
|
color = "\u00a72";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
color = "\u00a76";
|
||||||
|
}
|
||||||
|
itemStack.getItemDamageForDisplay();
|
||||||
|
list.add(LanguageUtility.getLocal("tooltip.battery.energy").replace("%0", color).replace("%1", EnumColor.GREY.toString()).replace("%v0", UnitDisplay.getDisplayShort(joules, Unit.JOULES)).replace("%v1", UnitDisplay.getDisplayShort(this.getEnergyCapacity(itemStack), Unit.JOULES)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreated(ItemStack itemStack, World world, EntityPlayer player)
|
||||||
|
{
|
||||||
|
super.onCreated(itemStack, world, player);
|
||||||
|
this.setEnergy(itemStack, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long recharge(ItemStack itemStack, long energy, boolean doReceive)
|
||||||
|
{
|
||||||
|
long rejectedElectricity = Math.max((this.getEnergy(itemStack) + energy) - this.getEnergyCapacity(itemStack), 0);
|
||||||
|
long energyToReceive = Math.min(energy - rejectedElectricity, getTransferRate(itemStack));
|
||||||
|
|
||||||
|
if (doReceive)
|
||||||
|
{
|
||||||
|
this.setEnergy(itemStack, this.getEnergy(itemStack) + energyToReceive);
|
||||||
|
}
|
||||||
|
|
||||||
|
return energyToReceive;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long discharge(ItemStack itemStack, long energy, boolean doTransfer)
|
||||||
|
{
|
||||||
|
long energyToExtract = Math.min(Math.min(this.getEnergy(itemStack), energy), getTransferRate(itemStack));
|
||||||
|
|
||||||
|
if (doTransfer)
|
||||||
|
{
|
||||||
|
this.setEnergy(itemStack, this.getEnergy(itemStack) - energyToExtract);
|
||||||
|
}
|
||||||
|
|
||||||
|
return energyToExtract;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getVoltage(ItemStack itemStack)
|
||||||
|
{
|
||||||
|
return UniversalElectricity.DEFAULT_VOLTAGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setEnergy(ItemStack itemStack, long joules)
|
||||||
|
{
|
||||||
|
if (itemStack.getTagCompound() == null)
|
||||||
|
{
|
||||||
|
itemStack.setTagCompound(new NBTTagCompound());
|
||||||
|
}
|
||||||
|
|
||||||
|
long electricityStored = Math.max(Math.min(joules, this.getEnergyCapacity(itemStack)), 0);
|
||||||
|
itemStack.getTagCompound().setLong("electricity", electricityStored);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTransfer(ItemStack itemStack)
|
||||||
|
{
|
||||||
|
return this.getEnergyCapacity(itemStack) - this.getEnergy(itemStack);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the energy stored in the item. Energy is stored using item NBT */
|
||||||
|
@Override
|
||||||
|
public long getEnergy(ItemStack itemStack)
|
||||||
|
{
|
||||||
|
if (itemStack.getTagCompound() == null)
|
||||||
|
{
|
||||||
|
itemStack.setTagCompound(new NBTTagCompound());
|
||||||
|
}
|
||||||
|
|
||||||
|
long energyStored = itemStack.getTagCompound().getLong("electricity");
|
||||||
|
return energyStored;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDisplayDamage(ItemStack stack)
|
||||||
|
{
|
||||||
|
return (int) (100 - ((double) this.getEnergy(stack) / (double) getEnergyCapacity(stack)) * 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getEnergyCapacity(ItemStack theItem)
|
||||||
|
{
|
||||||
|
return TileBattery.getEnergyForTier(getTier(theItem));
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTransferRate(ItemStack itemStack)
|
||||||
|
{
|
||||||
|
return this.getEnergyCapacity(itemStack) / 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack setTier(ItemStack itemStack, byte tier)
|
||||||
|
{
|
||||||
|
if (itemStack.getTagCompound() == null)
|
||||||
|
{
|
||||||
|
itemStack.setTagCompound(new NBTTagCompound());
|
||||||
|
}
|
||||||
|
|
||||||
|
itemStack.getTagCompound().setByte("tier", tier);
|
||||||
|
return itemStack;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte getTier(ItemStack itemStack)
|
||||||
|
{
|
||||||
|
if (itemStack.getTagCompound() == null)
|
||||||
|
{
|
||||||
|
itemStack.setTagCompound(new NBTTagCompound());
|
||||||
|
}
|
||||||
|
return itemStack.getTagCompound().getByte("tier");
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
|
||||||
|
{
|
||||||
|
for (byte tier = 0; tier <= TileBattery.MAX_TIER; tier++)
|
||||||
|
{
|
||||||
|
par3List.add(CompatibilityModule.getItemWithCharge(setTier(new ItemStack(this), tier), 0));
|
||||||
|
par3List.add(CompatibilityModule.getItemWithCharge(setTier(new ItemStack(this), tier), TileBattery.getEnergyForTier(tier)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,91 @@
|
||||||
|
package resonantinduction.core.prefab.items;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import calclavia.components.tool.ToolMode;
|
||||||
|
import calclavia.lib.utility.LanguageUtility;
|
||||||
|
import calclavia.lib.utility.nbt.NBTUtility;
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
|
/** Prefab for all tool based items
|
||||||
|
*
|
||||||
|
* @author Darkguardsman */
|
||||||
|
public class ItemTool extends Item
|
||||||
|
{
|
||||||
|
protected boolean hasModes = false;
|
||||||
|
protected String[] toolModes = new String[] { "Remove" };
|
||||||
|
|
||||||
|
public ItemTool(int par1)
|
||||||
|
{
|
||||||
|
super(par1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreated(ItemStack stack, World par2World, EntityPlayer entityPlayer)
|
||||||
|
{
|
||||||
|
//Save who crafted the tool
|
||||||
|
if (entityPlayer != null)
|
||||||
|
{
|
||||||
|
NBTUtility.getNBTTagCompound(stack).setString("Creator", entityPlayer.username);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
@Override
|
||||||
|
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4)
|
||||||
|
{
|
||||||
|
super.addInformation(stack, player, list, par4);
|
||||||
|
|
||||||
|
//Item creator
|
||||||
|
String creator = NBTUtility.getNBTTagCompound(stack).getString("Creator");
|
||||||
|
if (!creator.equalsIgnoreCase("creative") && creator != "")
|
||||||
|
{
|
||||||
|
list.add("Created by: " + creator);
|
||||||
|
}
|
||||||
|
else if (creator.equalsIgnoreCase("creative"))
|
||||||
|
{
|
||||||
|
list.add("Created by Magic Dwarfs");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player)
|
||||||
|
{
|
||||||
|
if (hasModes && toolModes != null && toolModes.length > 1)
|
||||||
|
{
|
||||||
|
//TODO replace with middle mouse wheel
|
||||||
|
//Changes the mod of the tool
|
||||||
|
if (player.isSneaking())
|
||||||
|
{
|
||||||
|
setMode(itemStack, (getMode(itemStack) + 1) % toolModes.length);
|
||||||
|
|
||||||
|
if (!world.isRemote)
|
||||||
|
player.addChatMessage("Set tool mode to: " + toolModes[getMode(itemStack)]);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return itemStack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldPassSneakingClickToBlock(World world, int x, int y, int z)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMode(ItemStack itemStack)
|
||||||
|
{
|
||||||
|
return NBTUtility.getNBTTagCompound(itemStack).getInteger("mode");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMode(ItemStack itemStack, int mode)
|
||||||
|
{
|
||||||
|
NBTUtility.getNBTTagCompound(itemStack).setInteger("mode", mode);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue