Fixed check on unbreakable blocks for Crusher ritual, added event for items draining the SN
This commit is contained in:
parent
42afd64e30
commit
40a45be05e
|
@ -10,6 +10,7 @@ import WayofTime.alchemicalWizardry.api.harvest.HarvestRegistry;
|
|||
import WayofTime.alchemicalWizardry.api.items.ShapedBloodOrbRecipe;
|
||||
import WayofTime.alchemicalWizardry.api.items.ShapelessBloodOrbRecipe;
|
||||
import WayofTime.alchemicalWizardry.api.rituals.Rituals;
|
||||
import WayofTime.alchemicalWizardry.api.soulNetwork.ComplexNetworkHandler;
|
||||
import WayofTime.alchemicalWizardry.api.summoningRegistry.SummoningRegistry;
|
||||
import WayofTime.alchemicalWizardry.common.*;
|
||||
import WayofTime.alchemicalWizardry.common.alchemy.CombinedPotionRegistry;
|
||||
|
@ -67,8 +68,10 @@ import net.minecraftforge.fluids.FluidRegistry;
|
|||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import net.minecraftforge.oredict.RecipeSorter;
|
||||
import net.minecraftforge.oredict.RecipeSorter.Category;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import thaumcraft.api.ItemApi;
|
||||
import thaumcraft.api.ThaumcraftApi;
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
|
@ -274,6 +277,8 @@ public class AlchemicalWizardry
|
|||
|
||||
TEDemonPortal.loadBuildingList();
|
||||
|
||||
ComplexNetworkHandler.load();
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(new LifeBucketHandler());
|
||||
BloodMagicConfiguration.init(new File(event.getModConfigurationDirectory(), "AWWayofTime.cfg"));
|
||||
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package WayofTime.alchemicalWizardry.api.event;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
|
||||
@Cancelable
|
||||
public class ItemDrainNetworkEvent extends PlayerDrainNetworkEvent
|
||||
{
|
||||
public final ItemStack itemStack;
|
||||
public boolean shouldDamage; //If true, will damage regardless of if the network had enough inside it
|
||||
public float damageAmount; //Amount of damage that would incur if the network could not drain properly
|
||||
|
||||
/**
|
||||
* Set result to deny the action i.e. damage/drain anyways. Cancelling event prevents action without penalties
|
||||
*
|
||||
* @param player Player using the item
|
||||
* @param ownerNetwork Network that the item is tied to
|
||||
* @param itemStack Item used
|
||||
* @param drainAmount Original drain amount - change to alter cost
|
||||
*/
|
||||
public ItemDrainNetworkEvent(EntityPlayer player, String ownerNetwork, ItemStack itemStack, int drainAmount)
|
||||
{
|
||||
super(player, ownerNetwork, drainAmount);
|
||||
this.itemStack = itemStack;
|
||||
this.shouldDamage = false;
|
||||
this.damageAmount = (float)(drainAmount) / 100.0f;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package WayofTime.alchemicalWizardry.api.event;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
|
||||
@Cancelable
|
||||
public class PlayerDrainNetworkEvent extends SoulNetworkEvent
|
||||
{
|
||||
public final EntityPlayer player; //Player that activated the event
|
||||
public PlayerDrainNetworkEvent(EntityPlayer player, String ownerNetwork, int drainAmount)
|
||||
{
|
||||
super(ownerNetwork, drainAmount);
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public EntityPlayer getPlayer()
|
||||
{
|
||||
return player;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package WayofTime.alchemicalWizardry.api.event;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
|
||||
public class SoulNetworkEvent extends Event
|
||||
{
|
||||
public String ownerNetwork;
|
||||
public int drainAmount;
|
||||
|
||||
public SoulNetworkEvent(String ownerNetwork, int drainAmount)
|
||||
{
|
||||
super();
|
||||
this.ownerNetwork = ownerNetwork;
|
||||
this.drainAmount = drainAmount;
|
||||
}
|
||||
|
||||
public String getOwnerNetwork()
|
||||
{
|
||||
return this.ownerNetwork;
|
||||
}
|
||||
|
||||
public int getDrainAmount()
|
||||
{
|
||||
return this.drainAmount;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,129 @@
|
|||
package WayofTime.alchemicalWizardry.api.soulNetwork;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.World;
|
||||
import WayofTime.alchemicalWizardry.AlchemicalWizardry;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
|
||||
/**
|
||||
* Temporary class to hash-out how to create a network not completely tied to the player.
|
||||
*/
|
||||
public class ComplexNetworkHandler
|
||||
{
|
||||
public static String fileName = "config/BloodMagic/soulnetworkKeys";
|
||||
static HashMap<UUID, String> keyMap = new HashMap();
|
||||
public static UUID getUUIDFromPlayer(EntityPlayer player)
|
||||
{
|
||||
return player.getPersistentID();
|
||||
}
|
||||
|
||||
public static EntityPlayer getPlayerFromUUID(UUID uuid)
|
||||
{
|
||||
MinecraftServer server = MinecraftServer.getServer();
|
||||
GameProfile gameProfile;
|
||||
gameProfile = server.func_152358_ax().func_152652_a(uuid);
|
||||
String str = uuid.toString();
|
||||
//TODO ServerConfigurationManager d.createPlayerForUser
|
||||
UUID.fromString(str);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getKeyForPlayer(EntityPlayer player)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
public static UUID getUUIDForKey(String key)
|
||||
{
|
||||
// if (MinecraftServer.getServer() == null)
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// World world = MinecraftServer.getServer().worldServers[0];
|
||||
// UUIDKeyMap data = (UUIDKeyMap) world.loadItemData(UUIDKeyMap.class, key);
|
||||
//
|
||||
// if (data == null)
|
||||
// {
|
||||
// data = new UUIDKeyMap(key);
|
||||
// world.setItemData(key, data);
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String assignKeyToPlayer(EntityPlayer player)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
public static void save()
|
||||
{
|
||||
keyMap.put(new UUID(0, 0), "test");
|
||||
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
String json = gson.toJson(keyMap);
|
||||
AlchemicalWizardry.logger.info("Here, too!");
|
||||
Writer writer;
|
||||
try
|
||||
{
|
||||
writer = new FileWriter(fileName + ".json");
|
||||
writer.write(json);
|
||||
writer.close();
|
||||
} catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void load()
|
||||
{
|
||||
File save = new File(fileName + ".json");
|
||||
|
||||
if(save.canRead())
|
||||
{
|
||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
BufferedReader br;
|
||||
|
||||
try
|
||||
{
|
||||
br = new BufferedReader(new FileReader(save));
|
||||
HashMap schema = gson.fromJson(br, keyMap.getClass());
|
||||
|
||||
keyMap = schema;
|
||||
|
||||
if(keyMap != null)
|
||||
{
|
||||
for(Entry<UUID, String> entry : keyMap.entrySet())
|
||||
{
|
||||
System.out.println("" + entry.getValue() + " gave: "+ entry.getKey());
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
keyMap = null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package WayofTime.alchemicalWizardry.api.soulNetwork;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -9,8 +10,12 @@ import net.minecraft.potion.PotionEffect;
|
|||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import WayofTime.alchemicalWizardry.api.event.ItemDrainNetworkEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
|
||||
public class SoulNetworkHandler
|
||||
{
|
||||
|
@ -71,18 +76,38 @@ public class SoulNetworkHandler
|
|||
* @param ist Owned itemStack
|
||||
* @param player Player using the item
|
||||
* @param damageToBeDone
|
||||
* @return True if server-sided, false if client-sided
|
||||
* @return True if the action should be executed and false if it should not. Always returns false if client-sided.
|
||||
*/
|
||||
public static boolean syphonAndDamageFromNetwork(ItemStack ist, EntityPlayer player, int damageToBeDone)
|
||||
public static boolean syphonAndDamageFromNetwork(ItemStack ist, EntityPlayer player, int drain)
|
||||
{
|
||||
if (player.worldObj.isRemote)
|
||||
if (player.worldObj.isRemote)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ist.getTagCompound() != null && !(ist.getTagCompound().getString("ownerName").equals("")))
|
||||
{
|
||||
String ownerName = ist.getTagCompound().getString("ownerName");
|
||||
|
||||
ItemDrainNetworkEvent event = new ItemDrainNetworkEvent(player, ownerName, ist, drain);
|
||||
|
||||
if(MinecraftForge.EVENT_BUS.post(event))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int drainAmount = syphonFromNetwork(event.ownerNetwork, event.drainAmount);
|
||||
if(drainAmount == 0 || event.shouldDamage)
|
||||
{
|
||||
hurtPlayer(player, event.damageAmount);
|
||||
}
|
||||
|
||||
return (event.getResult() != Event.Result.DENY); //The event has been told to prevent the action but allow all repercussions of using the item.
|
||||
}
|
||||
|
||||
int amount = SoulNetworkHandler.syphonFromNetwork(ist, damageToBeDone);
|
||||
int amount = SoulNetworkHandler.syphonFromNetwork(ist, drain);
|
||||
|
||||
hurtPlayer(player, damageToBeDone - amount);
|
||||
hurtPlayer(player, drain - amount);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -238,6 +263,19 @@ public class SoulNetworkHandler
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void hurtPlayer(EntityPlayer user, float damage)
|
||||
{
|
||||
if (!user.capabilities.isCreativeMode)
|
||||
{
|
||||
user.setHealth((user.getHealth() - damage));
|
||||
|
||||
if (user.getHealth() <= 0.0005f)
|
||||
{
|
||||
user.onDeath(DamageSource.generic);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkAndSetItemOwner(ItemStack item, EntityPlayer player)
|
||||
{
|
||||
|
|
|
@ -375,8 +375,8 @@ public class BoundArmour extends ItemArmor implements IAlchemyGoggles, ISpecialA
|
|||
|
||||
if (!player.capabilities.isCreativeMode)
|
||||
{
|
||||
EnergyItems.syphonBatteries(itemStack, player, itemStack.getItemDamage() * 75);
|
||||
itemStack.setItemDamage(0);
|
||||
if( EnergyItems.syphonBatteries(itemStack, player, itemStack.getItemDamage() * 75))
|
||||
itemStack.setItemDamage(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -123,6 +123,11 @@ public class BoundAxe extends ItemAxe implements IBindable
|
|||
{
|
||||
return par1ItemStack;
|
||||
}
|
||||
|
||||
if(!EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, 10000))
|
||||
{
|
||||
return par1ItemStack;
|
||||
}
|
||||
|
||||
Vec3 blockVec = SpellHelper.getEntityBlockVector(par3EntityPlayer);
|
||||
int posX = (int) (blockVec.xCoord);
|
||||
|
@ -176,7 +181,7 @@ public class BoundAxe extends ItemAxe implements IBindable
|
|||
}
|
||||
}
|
||||
|
||||
EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, 10000);
|
||||
|
||||
return par1ItemStack;
|
||||
}
|
||||
|
||||
|
@ -198,7 +203,10 @@ public class BoundAxe extends ItemAxe implements IBindable
|
|||
{
|
||||
if (!par3EntityPlayer.capabilities.isCreativeMode)
|
||||
{
|
||||
EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, 20);
|
||||
if(!EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, 20))
|
||||
{
|
||||
this.setActivated(par1ItemStack, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -130,6 +130,11 @@ public class BoundPickaxe extends ItemPickaxe implements IBindable
|
|||
{
|
||||
return par1ItemStack;
|
||||
}
|
||||
|
||||
if(!EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, 10000))
|
||||
{
|
||||
return par1ItemStack;
|
||||
}
|
||||
|
||||
Vec3 blockVec = SpellHelper.getEntityBlockVector(par3EntityPlayer);
|
||||
int posX = (int) (blockVec.xCoord);
|
||||
|
@ -184,7 +189,6 @@ public class BoundPickaxe extends ItemPickaxe implements IBindable
|
|||
}
|
||||
}
|
||||
|
||||
EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, 10000);
|
||||
return par1ItemStack;
|
||||
}
|
||||
|
||||
|
@ -207,7 +211,10 @@ public class BoundPickaxe extends ItemPickaxe implements IBindable
|
|||
{
|
||||
if (!par3EntityPlayer.capabilities.isCreativeMode)
|
||||
{
|
||||
EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, 20);
|
||||
if(!EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, 20))
|
||||
{
|
||||
this.setActivated(par1ItemStack, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,9 @@ package WayofTime.alchemicalWizardry.common.items;
|
|||
import WayofTime.alchemicalWizardry.AlchemicalWizardry;
|
||||
import WayofTime.alchemicalWizardry.api.items.interfaces.IBindable;
|
||||
import WayofTime.alchemicalWizardry.common.spell.complex.effect.SpellHelper;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.Block;
|
||||
|
@ -127,6 +129,11 @@ public class BoundShovel extends ItemSpade implements IBindable
|
|||
{
|
||||
return par1ItemStack;
|
||||
}
|
||||
|
||||
if(!EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, 10000))
|
||||
{
|
||||
return par1ItemStack;
|
||||
}
|
||||
|
||||
Vec3 blockVec = SpellHelper.getEntityBlockVector(par3EntityPlayer);
|
||||
int posX = (int) (blockVec.xCoord);
|
||||
|
@ -181,7 +188,6 @@ public class BoundShovel extends ItemSpade implements IBindable
|
|||
}
|
||||
}
|
||||
|
||||
EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, 10000);
|
||||
return par1ItemStack;
|
||||
}
|
||||
|
||||
|
@ -203,7 +209,10 @@ public class BoundShovel extends ItemSpade implements IBindable
|
|||
{
|
||||
if (!par3EntityPlayer.capabilities.isCreativeMode)
|
||||
{
|
||||
EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, 20);
|
||||
if(!EnergyItems.syphonBatteries(par1ItemStack, par3EntityPlayer, 20))
|
||||
{
|
||||
this.setActivated(par1ItemStack, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ public class EnergyItems extends Item implements IBindable
|
|||
{
|
||||
if (!player.worldObj.isRemote)
|
||||
{
|
||||
return syphonAndDamageWhileInContainer(ist, player, damageToBeDone);
|
||||
return SoulNetworkHandler.syphonAndDamageFromNetwork(ist, player, damageToBeDone);
|
||||
} else
|
||||
{
|
||||
World world = player.worldObj;
|
||||
|
|
|
@ -109,6 +109,10 @@ public class RitualEffectCrushing extends RitualEffect
|
|||
{
|
||||
Block block = world.getBlock(x + i, y + j, z + k);
|
||||
int meta = world.getBlockMetadata(x + i, y + j, z + k);
|
||||
if(block.getBlockHardness(world, x + i, y + j, z + k) == -1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (block != null && !world.isAirBlock(x + i, y + j, z + k))
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue