Friendly Modifiers

This commit is contained in:
mDiyo 2013-05-22 18:24:24 -07:00
parent d5c3d9e3ef
commit 5f6990edaf
14 changed files with 996 additions and 835 deletions

View File

@ -37,7 +37,7 @@ import cpw.mods.fml.common.registry.VillagerRegistry;
* @dependencies: IC2 API
*/
@Mod(modid = "TConstruct", name = "TConstruct", version = "1.5.1_1.3.dev.42", dependencies = "required-after:Forge@[7.7.1.675,)")
@Mod(modid = "TConstruct", name = "TConstruct", version = "1.5.1_1.3.dev.43", dependencies = "required-after:Forge@[7.7.1.675,)")
@NetworkMod(serverSideRequired = false, clientSideRequired = true, channels = { "TConstruct" }, packetHandler = mods.tinker.tconstruct.util.network.TPacketHandler.class)
public class TConstruct
{

View File

@ -16,6 +16,7 @@ import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.ILiquidTank;
import net.minecraftforge.liquids.ITankContainer;
import net.minecraftforge.liquids.LiquidEvent;
import net.minecraftforge.liquids.LiquidStack;
public class CastingBasinLogic extends InventoryLogic implements ILiquidTank, ITankContainer, ISidedInventory
@ -191,9 +192,28 @@ public class CastingBasinLogic extends InventoryLogic implements ILiquidTank, IT
}
@Override
public LiquidStack drain (int maxDrain, boolean doDrain) //Doesn't actually drain
public LiquidStack drain (int maxDrain, boolean doDrain)
{
return null;
if (liquid == null || liquid.itemID <= 0) return null;
if (liquid.amount <= 0) return null;
int used = maxDrain;
if (liquid.amount < used) used = liquid.amount;
if (doDrain)
{
liquid.amount -= used;
}
LiquidStack drained = new LiquidStack(liquid.itemID, used, liquid.itemMeta);
// Reset liquid if emptied
if (liquid.amount <= 0) liquid = null;
if (doDrain)
LiquidEvent.fireEvent(new LiquidEvent.LiquidDrainingEvent(drained, this.worldObj, this.xCoord, this.yCoord, this.zCoord, this));
return drained;
}
@Override
@ -221,13 +241,13 @@ public class CastingBasinLogic extends InventoryLogic implements ILiquidTank, IT
@Override
public LiquidStack drain (ForgeDirection from, int maxDrain, boolean doDrain)
{
return null;
return drain(0, maxDrain, doDrain);
}
@Override
public LiquidStack drain (int tankIndex, int maxDrain, boolean doDrain)
{
return null;
return drain(maxDrain, doDrain);
}
@Override
@ -347,22 +367,27 @@ public class CastingBasinLogic extends InventoryLogic implements ILiquidTank, IT
@Override
public int[] getAccessibleSlotsFromSide (int side)
{
if (side == 0)
return new int[] { 1 };
else
return new int[] { 0 };
return new int[] { 0, 1 };
}
@Override
public boolean canInsertItem (int i, ItemStack itemstack, int j)
public boolean canInsertItem (int slot, ItemStack itemstack, int side)
{
if (liquid != null)
return false;
if (slot == 0)
return true;
return false;
}
@Override
public boolean canExtractItem (int i, ItemStack itemstack, int j)
public boolean canExtractItem (int slot, ItemStack itemstack, int side)
{
if (slot == 1)
return true;
}
return false;
}
}

View File

@ -3,7 +3,6 @@ package mods.tinker.tconstruct.blocks.logic;
import mods.tinker.tconstruct.TConstruct;
import mods.tinker.tconstruct.library.blocks.InventoryLogic;
import mods.tinker.tconstruct.library.crafting.CastingRecipe;
import mods.tinker.tconstruct.library.crafting.LiquidCasting;
import mods.tinker.tconstruct.library.util.IPattern;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
@ -17,6 +16,7 @@ import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.ILiquidTank;
import net.minecraftforge.liquids.ITankContainer;
import net.minecraftforge.liquids.LiquidEvent;
import net.minecraftforge.liquids.LiquidStack;
public class CastingTableLogic extends InventoryLogic implements ILiquidTank, ITankContainer, ISidedInventory
@ -192,9 +192,28 @@ public class CastingTableLogic extends InventoryLogic implements ILiquidTank, IT
}
@Override
public LiquidStack drain (int maxDrain, boolean doDrain) //Doesn't actually drain
public LiquidStack drain (int maxDrain, boolean doDrain)
{
return null;
if (liquid == null || liquid.itemID <= 0) return null;
if (liquid.amount <= 0) return null;
int used = maxDrain;
if (liquid.amount < used) used = liquid.amount;
if (doDrain)
{
liquid.amount -= used;
}
LiquidStack drained = new LiquidStack(liquid.itemID, used, liquid.itemMeta);
// Reset liquid if emptied
if (liquid.amount <= 0) liquid = null;
if (doDrain)
LiquidEvent.fireEvent(new LiquidEvent.LiquidDrainingEvent(drained, this.worldObj, this.xCoord, this.yCoord, this.zCoord, this));
return drained;
}
@Override
@ -222,13 +241,13 @@ public class CastingTableLogic extends InventoryLogic implements ILiquidTank, IT
@Override
public LiquidStack drain (ForgeDirection from, int maxDrain, boolean doDrain)
{
return null;
return drain(0, maxDrain, doDrain);
}
@Override
public LiquidStack drain (int tankIndex, int maxDrain, boolean doDrain)
{
return null;
return drain(maxDrain, doDrain);
}
@Override
@ -348,22 +367,28 @@ public class CastingTableLogic extends InventoryLogic implements ILiquidTank, IT
@Override
public int[] getAccessibleSlotsFromSide (int side)
{
if (side == 0)
return new int[] { 1 };
else
return new int[] { 0 };
return new int[] { 0, 1 };
}
@Override
public boolean canInsertItem (int i, ItemStack itemstack, int j)
public boolean canInsertItem (int slot, ItemStack itemstack, int side)
{
if (liquid != null)
return false;
if (slot == 0)
return true;
return false;
}
@Override
public boolean canExtractItem (int i, ItemStack itemstack, int j)
public boolean canExtractItem (int slot, ItemStack itemstack, int side)
{
if (slot == 1)
return true;
return false;
}
}

View File

@ -0,0 +1,9 @@
package mods.tinker.tconstruct.blocks.logic;
import net.minecraft.tileentity.TileEntity;
public class RedwireLogic extends TileEntity
{
byte facesUsed;
byte type;
}

View File

@ -540,6 +540,8 @@ public class TContent implements IFuelHandler
ItemStack silkyJewel = new ItemStack(materials, 1, 26);
tb.registerToolMod(new ModButtertouch(new ItemStack[] {silkyJewel}, 12));
TConstructRegistry.registerActiveToolMod(new TActiveOmniMod());
/* Smeltery */
ItemStack ingotcast = new ItemStack(metalPattern, 1, 0);
@ -609,7 +611,7 @@ public class TContent implements IFuelHandler
basinCasting.addCastingRecipe(new ItemStack(Block.obsidian), new LiquidStack(liquidMetalStill.blockID, TConstruct.ingotLiquidValue * 2, 11), null, true, 100);// obsidian
basinCasting.addCastingRecipe(new ItemStack(metalBlock, 1, 9), new LiquidStack(liquidMetalStill.blockID, TConstruct.ingotLiquidValue * 9, 12), null, true, 100); //steel
basinCasting.addCastingRecipe(new ItemStack(speedBlock, 1, 0), new LiquidStack(liquidMetalStill.blockID, TConstruct.ingotLiquidValue / 9, 3), new ItemStack(Block.gravel), true, 100); //steel
basinCasting.addCastingRecipe(new ItemStack(speedBlock, 1, 0), new LiquidStack(liquidMetalStill.blockID, TConstruct.ingotLiquidValue / 9, 3), new ItemStack(Block.gravel), true, 100); //brownstone
//Ore
Smeltery.addMelting(Block.oreIron, 0, 600, new LiquidStack(liquidMetalStill.blockID, TConstruct.ingotLiquidValue * 2, 0));

View File

@ -0,0 +1,57 @@
package mods.tinker.tconstruct.library;
import mods.tinker.tconstruct.library.tools.ToolCore;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public class ActiveToolMod
{
/* Updating */
public void updateTool (ToolCore tool, ItemStack stack, World world, Entity entity)
{
}
/* Harvesting */
public boolean beforeBlockBreak (ToolCore tool, ItemStack stack, int x, int y, int z, EntityPlayer player)
{
return false;
}
public boolean afterBlockBreak()
{
return false;
}
/* Attacking */
public int baseAttackDamage(int earlyModDamage, int damage, ToolCore tool, ItemStack stack, EntityPlayer player, Entity entity)
{
return 0;
}
//Calculated after sprinting and enchant bonuses
public float knockback(float modKnockback, float currentKnockback, ToolCore tool, ItemStack stack, EntityPlayer player, Entity entity)
{
return 0f;
}
public int attackDamage(int modDamage, int currentDamage, ToolCore tool, ItemStack stack, EntityPlayer player, Entity entity)
{
return 0;
}
public void lateAttackEntity()
{
}
/* Damage tool */
public boolean damageTool(ItemStack stack, int damage, EntityLiving entity)
{
return false;
}
}

View File

@ -3,6 +3,7 @@ package mods.tinker.tconstruct.library;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import mods.tinker.tconstruct.library.crafting.Detailing;
import mods.tinker.tconstruct.library.crafting.LiquidCasting;
@ -23,9 +24,12 @@ public class TConstructRegistry
public static HashMap<Integer, ToolMaterial> toolMaterials = new HashMap<Integer, ToolMaterial>(40);
public static HashMap<String, ToolMaterial> toolMaterialStrings = new HashMap<String, ToolMaterial>(40);
public static LinkedList<ActiveToolMod> activeModifiers = new LinkedList<ActiveToolMod>();
public static TabTools toolTab;
public static TabTools materialTab;
public static TabTools blockTab;
@Deprecated
public static Item toolRod;
//Tools
@ -132,4 +136,9 @@ public class TConstructRegistry
return null;
}
}
public static void registerActiveToolMod(ActiveToolMod mod)
{
activeModifiers.add(mod);
}
}

View File

@ -7,6 +7,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.Random;
import mods.tinker.tconstruct.library.ActiveToolMod;
import mods.tinker.tconstruct.library.TConstructRegistry;
import mods.tinker.tconstruct.library.util.PiercingEntityDamage;
import net.minecraft.block.Block;
import net.minecraft.enchantment.EnchantmentHelper;
@ -50,7 +52,7 @@ public class AbilityHelper
if (random.nextInt(10) < 10 - durability)
{
damageTool(stack, 1, tags, player, false, true);
damageTool(stack, 1, tags, player, false);
}
return true;
@ -68,8 +70,15 @@ public class AbilityHelper
boolean broken = toolTags.getBoolean("Broken");
int durability = tags.getCompoundTag("InfiTool").getInteger("Damage");
float shoddy = tags.getCompoundTag("InfiTool").getFloat("Shoddy");
float damageModifier = -shoddy * durability / 100f;
float stonebound = tags.getCompoundTag("InfiTool").getFloat("Shoddy");
float stoneboundDamage = -stonebound * durability / 100f;
int earlyModDamage = 0;
for (ActiveToolMod mod : TConstructRegistry.activeModifiers)
{
earlyModDamage = mod.baseAttackDamage(earlyModDamage, damage, tool, stack, player, entity);
}
damage += earlyModDamage;
if (player.isPotionActive(Potion.damageBoost))
{
@ -90,7 +99,7 @@ public class AbilityHelper
knockback += EnchantmentHelper.getKnockbackModifier(player, (EntityLiving) entity);
}
damage += damageModifier;
damage += stoneboundDamage;
if (player.isSprinting())
{
@ -103,6 +112,20 @@ public class AbilityHelper
}
}
float modKnockback = 0f;
for (ActiveToolMod mod : TConstructRegistry.activeModifiers)
{
modKnockback = mod.knockback(modKnockback, knockback, tool, stack, player, entity);
}
knockback += modKnockback;
int modDamage = 0;
for (ActiveToolMod mod : TConstructRegistry.activeModifiers)
{
modDamage = mod.attackDamage(modDamage, damage, tool, stack, player, entity);
}
damage += modDamage;
if (damage > 0 || enchantDamage > 0)
{
boolean criticalHit = player.fallDistance > 0.0F && !player.onGround && !player.isOnLadder() && !player.isInWater() && !player.isPotionActive(Potion.blindness)
@ -249,36 +272,39 @@ public class AbilityHelper
public static void damageTool (ItemStack stack, int dam, EntityLiving entity, boolean ignoreCharge)
{
NBTTagCompound tags = stack.getTagCompound();
damageTool(stack, dam, tags, entity, ignoreCharge, true);
damageTool(stack, dam, tags, entity, ignoreCharge);
}
public static void healTool (ItemStack stack, int dam, EntityLiving entity, boolean ignoreCharge, boolean updateDamageBar)
public static void healTool (ItemStack stack, int dam, EntityLiving entity, boolean ignoreCharge)
{
NBTTagCompound tags = stack.getTagCompound();
damageTool(stack, -dam, tags, entity, ignoreCharge, updateDamageBar);
damageTool(stack, -dam, tags, entity, ignoreCharge);
}
public static void damageTool (ItemStack stack, int dam, NBTTagCompound tags, EntityLiving entity, boolean ignoreCharge, boolean updateDamageBar)
public static void damageTool (ItemStack stack, int dam, NBTTagCompound tags, EntityLiving entity, boolean ignoreCharge)
{
if (entity instanceof EntityPlayer && ((EntityPlayer) entity).capabilities.isCreativeMode)
return;
if (ignoreCharge || !damageElectricTool(stack, tags, entity))
{
for (ActiveToolMod mod : TConstructRegistry.activeModifiers)
{
if (mod.damageTool(stack, dam, entity));
return;
}
int damage = tags.getCompoundTag("InfiTool").getInteger("Damage");
int damageTrue = damage + dam;
int maxDamage = tags.getCompoundTag("InfiTool").getInteger("TotalDurability");
if (damageTrue <= 0)
{
tags.getCompoundTag("InfiTool").setInteger("Damage", 0);
if (updateDamageBar)
stack.setItemDamage(0);
}
else if (damageTrue > maxDamage)
{
breakTool(stack, tags, entity);
if (updateDamageBar)
stack.setItemDamage(0);
}
@ -287,7 +313,7 @@ public class AbilityHelper
tags.getCompoundTag("InfiTool").setInteger("Damage", damage + dam);
int toolDamage = (damage * 100 / maxDamage) + 1;
int stackDamage = stack.getItemDamage();
if (updateDamageBar && toolDamage != stackDamage)
if (toolDamage != stackDamage)
{
stack.setItemDamage((damage * 100 / maxDamage) + 1);
}

View File

@ -1,5 +1,7 @@
package mods.tinker.tconstruct.library.tools;
import mods.tinker.tconstruct.library.ActiveToolMod;
import mods.tinker.tconstruct.library.TConstructRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.enchantment.Enchantment;
@ -43,58 +45,14 @@ public abstract class DualHarvestTool extends HarvestTool
if (hlvl <= tags.getInteger("HarvestLevel") && shlvl <= tags.getInteger("HarvestLevel2"))
{
if (tags.getBoolean("Lava") && block.quantityDropped(meta, 0, random) != 0)
boolean cancelHarvest = false;
for (ActiveToolMod mod : TConstructRegistry.activeModifiers)
{
ItemStack smeltStack = new ItemStack(block.idDropped(block.blockID, random, 0), 1, block.damageDropped(meta));
if (smeltStack.itemID < 0 || smeltStack.itemID >= 32000 || smeltStack.getItem() == null)
return false;
ItemStack result = FurnaceRecipes.smelting().getSmeltingResult(smeltStack);
if (result != null)
{
world.setBlockToAir(x, y, z);
if (!player.capabilities.isCreativeMode)
onBlockDestroyed(stack, world, bID, x, y, z, player);
if (!world.isRemote)
{
ItemStack spawnme = result.copy();
if (!(result.getItem() instanceof ItemBlock))
{
int loot = EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack);
if (loot > 0)
{
spawnme.stackSize *= (random.nextInt(loot + 1) + 1);
if (mod.beforeBlockBreak(this, stack, x, y, z, player));
cancelHarvest = true;
}
}
EntityItem entityitem = new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, spawnme);
entityitem.delayBeforeCanPickup = 10;
world.spawnEntityInWorld(entityitem);
world.playAuxSFX(2001, x, y, z, bID + (meta << 12));
}
for (int i = 0; i < 6; i++)
{
float f = (float) x + random.nextFloat();
float f1 = (float) y + random.nextFloat();
float f2 = (float) z + random.nextFloat();
float f3 = 0.52F;
float f4 = random.nextFloat() * 0.6F - 0.3F;
world.spawnParticle("smoke", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
world.spawnParticle("smoke", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
world.spawnParticle("smoke", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D);
world.spawnParticle("smoke", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D);
}
return true;
}
}
return false;
return cancelHarvest;
}
else
{

View File

@ -1,6 +1,8 @@
package mods.tinker.tconstruct.library.tools;
import mods.tinker.tconstruct.common.TContent;
import mods.tinker.tconstruct.library.ActiveToolMod;
import mods.tinker.tconstruct.library.TConstructRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.enchantment.Enchantment;
@ -27,9 +29,7 @@ public abstract class HarvestTool extends ToolCore
@Override
public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPlayer player)
{
TContent.modL.midStreamModify(stack);
return super.onBlockStartBreak(stack, x, y, z, player);
/*NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
World world = player.worldObj;
int bID = player.worldObj.getBlockId(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
@ -40,38 +40,13 @@ public abstract class HarvestTool extends ToolCore
if (hlvl <= tags.getInteger("HarvestLevel"))
{
if (tags.getBoolean("Lava") && block.quantityDropped(meta, 0, random) != 0)
boolean cancelHarvest = false;
for (ActiveToolMod mod : TConstructRegistry.activeModifiers)
{
ItemStack smeltStack = new ItemStack(block.idDropped(block.blockID, random, 0), 1, block.damageDropped(meta));
if (smeltStack.itemID < 0 || smeltStack.itemID >= 32000 || smeltStack.getItem() == null)
return false;
ItemStack result = FurnaceRecipes.smelting().getSmeltingResult(smeltStack);
if (result != null)
{
world.setBlockToAir(x, y, z);
if (!player.capabilities.isCreativeMode)
onBlockDestroyed(stack, world, bID, x, y, z, player);
if (!world.isRemote)
{
ItemStack spawnme = result.copy();
if (!(result.getItem() instanceof ItemBlock))
{
int loot = EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack);
if (loot > 0)
{
spawnme.stackSize *= (random.nextInt(loot + 1) + 1);
if (mod.beforeBlockBreak(this, stack, x, y, z, player))
cancelHarvest = true;
}
}
EntityItem entityitem = new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, spawnme);
entityitem.delayBeforeCanPickup = 10;
world.spawnEntityInWorld(entityitem);
world.playAuxSFX(2001, x, y, z, bID + (meta << 12));
}
return true;
}
}
return false;
return cancelHarvest;
}
else
{
@ -81,7 +56,7 @@ public abstract class HarvestTool extends ToolCore
if (!world.isRemote)
world.playAuxSFX(2001, x, y, z, bID + (meta << 12));
return true;
}*/
}
}
@Override

View File

@ -9,6 +9,7 @@ import java.util.List;
import java.util.Map;
import java.util.Random;
import mods.tinker.tconstruct.library.ActiveToolMod;
import mods.tinker.tconstruct.library.TConstructRegistry;
import mods.tinker.tconstruct.library.crafting.ToolBuilder;
import net.minecraft.block.Block;
@ -47,9 +48,10 @@ import cpw.mods.fml.relauncher.SideOnly;
* Others:
* Accessory: Base and tag, above head. Sword guards, binding, etc
* Effects: Render tag, top layer. Fancy effects like moss or diamond edge.
* Render order: Handle > Head > Accessory > Effect1 > Effect2 > Effect3
* Render order: Handle > Head > Accessory > Effect1 > Effect2 > Effect3 > etc
* Unbreaking: Reinforced in-game, 10% chance to not use durability per level
* Shoddy/Spiny: Mines faster or slower and does less or more attack.
* Stonebound: Mines faster as the tool takes damage, but has less attack
* Spiny: Opposite of stonebound
*
* Modifiers have their own tags.
* @see ToolMod
@ -464,18 +466,9 @@ public abstract class ToolCore extends Item implements ICustomElectricItem, IBox
public void onUpdate (ItemStack stack, World world, Entity entity, int par4, boolean par5)
{
if (!world.isRemote && entity instanceof EntityLiving && !((EntityLiving) entity).isSwingInProgress)
for (ActiveToolMod mod : TConstructRegistry.activeModifiers)
{
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
if (tags.hasKey("Moss"))
{
int chance = tags.getInteger("Moss");
int check = world.canBlockSeeTheSky((int) entity.posX, (int) entity.posY, (int) entity.posZ) ? 750 : 1500;
if (random.nextInt(check) < chance)
{
AbilityHelper.healTool(stack, 1, (EntityLiving) entity, true, false);
}
}
mod.updateTool(this, stack, world, entity);
}
}
@ -488,72 +481,20 @@ public abstract class ToolCore extends Item implements ICustomElectricItem, IBox
@Override
public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPlayer player)
{
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
World world = player.worldObj;
int bID = player.worldObj.getBlockId(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
Block block = Block.blocksList[bID];
if (block == null || bID < 1 || bID > 4095)
return false;
if (tags.getBoolean("Lava") && block.quantityDropped(meta, 0, random) != 0)
boolean cancelHarvest = false;
for (ActiveToolMod mod : TConstructRegistry.activeModifiers)
{
ItemStack smeltStack = new ItemStack(block.idDropped(meta, random, 0), 1, block.damageDropped(meta));
if (smeltStack.itemID < 0 || smeltStack.itemID >= 32000 || smeltStack.getItem() == null)
return false;
ItemStack result = FurnaceRecipes.smelting().getSmeltingResult(smeltStack);
if (result != null)
{
world.setBlockToAir(x, y, z);
if (!player.capabilities.isCreativeMode)
onBlockDestroyed(stack, world, bID, x, y, z, player);
if (!world.isRemote)
{
ItemStack spawnme = result.copy();
if (!(result.getItem() instanceof ItemBlock))
{
int loot = EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack);
if (loot > 0)
{
spawnme.stackSize *= (random.nextInt(loot + 1) + 1);
}
}
EntityItem entityitem = new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, spawnme);
entityitem.delayBeforeCanPickup = 10;
world.spawnEntityInWorld(entityitem);
world.playAuxSFX(2001, x, y, z, bID + (meta << 12));
}
for (int i = 0; i < 6; i++)
{
float f = (float) x + random.nextFloat();
float f1 = (float) y + random.nextFloat();
float f2 = (float) z + random.nextFloat();
float f3 = 0.52F;
float f4 = random.nextFloat() * 0.6F - 0.3F;
world.spawnParticle("smoke", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
world.spawnParticle("smoke", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
world.spawnParticle("smoke", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D);
world.spawnParticle("smoke", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D);
}
return true;
}
if (mod.beforeBlockBreak(this, stack, x, y, z, player));
cancelHarvest = true;
}
return false;
return cancelHarvest;
}
@Override
public boolean onBlockDestroyed (ItemStack itemstack, World world, int bID, int x, int y, int z, EntityLiving player)
public boolean onBlockDestroyed (ItemStack itemstack, World world, int blockID, int x, int y, int z, EntityLiving player)
{
return AbilityHelper.onBlockChanged(itemstack, world, bID, x, y, z, player, random);
return AbilityHelper.onBlockChanged(itemstack, world, blockID, x, y, z, player, random);
}
@Override

View File

@ -98,12 +98,12 @@ public abstract class Weapon extends ToolCore
return 1;
}
@Override
/*@Override
public boolean onLeftClickEntity (ItemStack stack, EntityPlayer player, Entity entity)
{
TContent.modL.midStreamModify(stack);
return super.onLeftClickEntity(stack, player, entity);
}
}*/
@Override
public String[] toolCategories()

View File

@ -0,0 +1,128 @@
package mods.tinker.tconstruct.modifiers;
import java.util.Random;
import mods.tinker.tconstruct.common.TContent;
import mods.tinker.tconstruct.library.ActiveToolMod;
import mods.tinker.tconstruct.library.tools.AbilityHelper;
import mods.tinker.tconstruct.library.tools.HarvestTool;
import mods.tinker.tconstruct.library.tools.ToolCore;
import mods.tinker.tconstruct.library.tools.Weapon;
import net.minecraft.block.Block;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
public class TActiveOmniMod extends ActiveToolMod
{
Random random = new Random();
/* Updating */
@Override
public void updateTool (ToolCore tool, ItemStack stack, World world, Entity entity)
{
if (!world.isRemote && entity instanceof EntityLiving && !((EntityLiving) entity).isSwingInProgress)
{
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
if (tags.hasKey("Moss"))
{
int chance = tags.getInteger("Moss");
int check = world.canBlockSeeTheSky((int) entity.posX, (int) entity.posY, (int) entity.posZ) ? 750 : 1500;
if (random.nextInt(check) < chance)
{
AbilityHelper.healTool(stack, 1, (EntityLiving) entity, true);
}
}
}
}
/* Harvesting */
@Override
public boolean beforeBlockBreak (ToolCore tool, ItemStack stack, int x, int y, int z, EntityPlayer player)
{
if (player.capabilities.isCreativeMode)
return false;
if (tool instanceof HarvestTool)
TContent.modL.midStreamModify(stack);
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
World world = player.worldObj;
int bID = player.worldObj.getBlockId(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
Block block = Block.blocksList[bID];
if (block == null || bID < 1 || bID > 4095)
return false;
if (tags.getBoolean("Lava") && block.quantityDropped(meta, 0, random) != 0)
{
ItemStack smeltStack = new ItemStack(block.idDropped(meta, random, 0), 1, block.damageDropped(meta));
if (smeltStack.itemID < 0 || smeltStack.itemID >= 32000 || smeltStack.getItem() == null)
return false;
ItemStack result = FurnaceRecipes.smelting().getSmeltingResult(smeltStack);
if (result != null)
{
world.setBlockToAir(x, y, z);
if (!player.capabilities.isCreativeMode)
tool.onBlockDestroyed(stack, world, bID, x, y, z, player);
if (!world.isRemote)
{
ItemStack spawnme = result.copy();
if (!(result.getItem() instanceof ItemBlock))
{
int loot = EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack);
if (loot > 0)
{
spawnme.stackSize *= (random.nextInt(loot + 1) + 1);
}
}
EntityItem entityitem = new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, spawnme);
entityitem.delayBeforeCanPickup = 10;
world.spawnEntityInWorld(entityitem);
world.playAuxSFX(2001, x, y, z, bID + (meta << 12));
}
for (int i = 0; i < 6; i++)
{
float f = (float) x + random.nextFloat();
float f1 = (float) y + random.nextFloat();
float f2 = (float) z + random.nextFloat();
float f3 = 0.52F;
float f4 = random.nextFloat() * 0.6F - 0.3F;
world.spawnParticle("smoke", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", f - f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
world.spawnParticle("smoke", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", f + f3, f1, f2 + f4, 0.0D, 0.0D, 0.0D);
world.spawnParticle("smoke", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", f + f4, f1, f2 - f3, 0.0D, 0.0D, 0.0D);
world.spawnParticle("smoke", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", f + f4, f1, f2 + f3, 0.0D, 0.0D, 0.0D);
}
return true;
}
}
return false;
}
/* Attacking */
@Override
public int baseAttackDamage (int earlyModDamage, int damage, ToolCore tool, ItemStack stack, EntityPlayer player, Entity entity)
{
if (tool instanceof Weapon)
TContent.modL.midStreamModify(stack);
return 0;
}
}

View File

@ -1,26 +1,19 @@
package mods.tinker.tconstruct.util.player;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import mods.tinker.tconstruct.client.TProxyClient;
import mods.tinker.tconstruct.common.TContent;
import mods.tinker.tconstruct.library.tools.AbilityHelper;
import mods.tinker.tconstruct.util.PHConstruct;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EnumEntitySize;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.living.LivingFallEvent;
import net.minecraftforge.event.entity.player.ArrowLooseEvent;
import net.minecraftforge.event.entity.player.PlayerDropsEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.IPlayerTracker;
@ -72,18 +65,31 @@ public class TPlayerHandler implements IPlayerTracker
@Override
public void onPlayerLogout (EntityPlayer entityplayer)
{
if (entityplayer != null)
{
getPlayerStats(entityplayer.username).armor.saveToNBT(entityplayer);
playerStats.remove(entityplayer.username);
}
savePlayerStats(entityplayer, true);
}
@Override
public void onPlayerChangedDimension (EntityPlayer entityplayer)
{
//Nothing?
savePlayerStats(entityplayer, false);
}
void savePlayerStats (EntityPlayer player, boolean clean)
{
if (player != null)
{
TPlayerStats stats = getPlayerStats(player.username);
if (stats != null)
{
stats.armor.saveToNBT(player);
if (clean)
playerStats.remove(player.username);
}
else //Revalidate all players
{
}
}
}
@Override