Ritual work + Begin move of NetworkHelper (static) to SoulNetwork (instance)
This commit is contained in:
parent
afad5b0fd0
commit
46742a73d1
|
@ -30,9 +30,11 @@ public class SoulNetworkEvent extends Event {
|
||||||
public static class PlayerDrainNetworkEvent extends SoulNetworkEvent {
|
public static class PlayerDrainNetworkEvent extends SoulNetworkEvent {
|
||||||
|
|
||||||
public final EntityPlayer player;
|
public final EntityPlayer player;
|
||||||
|
public boolean shouldDamage; //If true, will damage regardless of if the network had enough inside it
|
||||||
|
|
||||||
public PlayerDrainNetworkEvent(EntityPlayer player, String ownerNetwork, int drainAmount) {
|
public PlayerDrainNetworkEvent(EntityPlayer player, String ownerNetwork, int drainAmount) {
|
||||||
super(ownerNetwork, drainAmount);
|
super(ownerNetwork, drainAmount);
|
||||||
|
this.shouldDamage = false;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +43,6 @@ public class SoulNetworkEvent extends Event {
|
||||||
public static class ItemDrainNetworkEvent extends PlayerDrainNetworkEvent {
|
public static class ItemDrainNetworkEvent extends PlayerDrainNetworkEvent {
|
||||||
|
|
||||||
public final ItemStack itemStack;
|
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
|
public float damageAmount; //Amount of damage that would incur if the network could not drain properly
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,7 +56,6 @@ public class SoulNetworkEvent extends Event {
|
||||||
public ItemDrainNetworkEvent(EntityPlayer player, String ownerNetwork, ItemStack itemStack, int drainAmount) {
|
public ItemDrainNetworkEvent(EntityPlayer player, String ownerNetwork, ItemStack itemStack, int drainAmount) {
|
||||||
super(player, ownerNetwork, drainAmount);
|
super(player, ownerNetwork, drainAmount);
|
||||||
this.itemStack = itemStack;
|
this.itemStack = itemStack;
|
||||||
this.shouldDamage = false;
|
|
||||||
this.damageAmount = (float)(drainAmount) / 100.0f;
|
this.damageAmount = (float)(drainAmount) / 100.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,17 @@
|
||||||
package WayofTime.alchemicalWizardry.api.network;
|
package WayofTime.alchemicalWizardry.api.network;
|
||||||
|
|
||||||
|
import WayofTime.alchemicalWizardry.api.AlchemicalWizardryAPI;
|
||||||
import WayofTime.alchemicalWizardry.api.NBTHolder;
|
import WayofTime.alchemicalWizardry.api.NBTHolder;
|
||||||
|
import WayofTime.alchemicalWizardry.api.event.SoulNetworkEvent;
|
||||||
|
import WayofTime.alchemicalWizardry.api.util.helper.PlayerHelper;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.WorldSavedData;
|
import net.minecraft.world.WorldSavedData;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
|
@ -12,12 +19,14 @@ public class SoulNetwork extends WorldSavedData {
|
||||||
|
|
||||||
private int currentEssence;
|
private int currentEssence;
|
||||||
private int maxOrb;
|
private int maxOrb;
|
||||||
|
private final EntityPlayer player;
|
||||||
|
|
||||||
public SoulNetwork(String name) {
|
public SoulNetwork(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
|
|
||||||
currentEssence = 0;
|
currentEssence = 0;
|
||||||
maxOrb = 0;
|
maxOrb = 0;
|
||||||
|
player = PlayerHelper.getPlayerFromUsername(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -31,4 +40,50 @@ public class SoulNetwork extends WorldSavedData {
|
||||||
nbttagcompound.setInteger(NBTHolder.NBT_CURRENTESSENCE, currentEssence);
|
nbttagcompound.setInteger(NBTHolder.NBT_CURRENTESSENCE, currentEssence);
|
||||||
nbttagcompound.setInteger(NBTHolder.NBT_MAXORB, maxOrb);
|
nbttagcompound.setInteger(NBTHolder.NBT_MAXORB, maxOrb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int syphon(int syphon) {
|
||||||
|
if (getCurrentEssence() >= syphon) {
|
||||||
|
setCurrentEssence(getCurrentEssence() - syphon);
|
||||||
|
markDirty();
|
||||||
|
return syphon;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean syphonAndDamage(int syphon) {
|
||||||
|
SoulNetworkEvent.PlayerDrainNetworkEvent event = new SoulNetworkEvent.PlayerDrainNetworkEvent(getPlayer(), mapName, syphon);
|
||||||
|
|
||||||
|
if (MinecraftForge.EVENT_BUS.post(event))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
int drain = syphon(event.syphon);
|
||||||
|
|
||||||
|
if (drain == 0 || event.shouldDamage)
|
||||||
|
hurtPlayer(event.syphon);
|
||||||
|
|
||||||
|
return event.getResult() != Event.Result.DENY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hurtPlayer(int syphon) {
|
||||||
|
if (syphon < 100 && syphon > 0) {
|
||||||
|
if (!player.capabilities.isCreativeMode) {
|
||||||
|
player.setHealth((player.getHealth() - 1));
|
||||||
|
|
||||||
|
if (player.getHealth() <= 0.0005f)
|
||||||
|
player.onDeath(AlchemicalWizardryAPI.getDamageSource());
|
||||||
|
}
|
||||||
|
} else if (syphon >= 100) {
|
||||||
|
if (!player.capabilities.isCreativeMode) {
|
||||||
|
for (int i = 0; i < ((syphon + 99) / 100); i++) {
|
||||||
|
player.setHealth((player.getHealth() - 1));
|
||||||
|
|
||||||
|
if (player.getHealth() <= 0.0005f) {
|
||||||
|
player.onDeath(AlchemicalWizardryAPI.getDamageSource());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import net.minecraft.world.World;
|
||||||
|
|
||||||
public interface IMasterRitualStone extends IImperfectRitualStone {
|
public interface IMasterRitualStone extends IImperfectRitualStone {
|
||||||
|
|
||||||
void performRitual(World world, BlockPos pos, String ritualID);
|
void performRitual(World world, BlockPos pos, Ritual ritual);
|
||||||
|
|
||||||
void setCooldown(int cooldown);
|
void setCooldown(int cooldown);
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,19 @@ import net.minecraftforge.fml.common.eventhandler.Event;
|
||||||
|
|
||||||
public class NetworkHelper {
|
public class NetworkHelper {
|
||||||
|
|
||||||
|
// Get
|
||||||
|
|
||||||
|
public static SoulNetwork getSoulNetwork(String ownerName, World world) {
|
||||||
|
SoulNetwork network = (SoulNetwork) world.getMapStorage().loadData(SoulNetwork.class, ownerName);
|
||||||
|
|
||||||
|
if (network == null) {
|
||||||
|
network = new SoulNetwork(ownerName);
|
||||||
|
world.getMapStorage().setData(ownerName, network);
|
||||||
|
}
|
||||||
|
|
||||||
|
return network;
|
||||||
|
}
|
||||||
|
|
||||||
// Syphon
|
// Syphon
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
package WayofTime.alchemicalWizardry.item;
|
||||||
|
|
||||||
|
import WayofTime.alchemicalWizardry.AlchemicalWizardry;
|
||||||
|
import WayofTime.alchemicalWizardry.util.helper.TextHelper;
|
||||||
|
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 java.util.List;
|
||||||
|
|
||||||
|
public class ItemActivationCrystal extends ItemBindable {
|
||||||
|
|
||||||
|
public static String[] names = { "weak", "awakened", "creative" };
|
||||||
|
|
||||||
|
public ItemActivationCrystal() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
setUnlocalizedName(AlchemicalWizardry.MODID + ".activationCrystal.");
|
||||||
|
setHasSubtypes(true);
|
||||||
|
setEnergyUsed(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUnlocalizedName(ItemStack stack) {
|
||||||
|
return super.getUnlocalizedName(stack) + names[stack.getItemDamage()];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void getSubItems(Item id, CreativeTabs creativeTab, List list) {
|
||||||
|
for (int i = 0; i < names.length; i++)
|
||||||
|
list.add(new ItemStack(id, 1, i));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void addInformation(ItemStack stack, EntityPlayer player, List tooltip, boolean advanced) {
|
||||||
|
tooltip.add(TextHelper.localize("tooltip.AlchemicalWizardry.activationCrystal." + names[stack.getItemDamage()]));
|
||||||
|
|
||||||
|
super.addInformation(stack, player, tooltip, advanced);
|
||||||
|
|
||||||
|
// if (stack.getItemDamage() == 1) {
|
||||||
|
// if (Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
|
||||||
|
// ItemStack[] recipe = AlchemyRecipeRegistry.getRecipeForItemStack(stack);
|
||||||
|
//
|
||||||
|
// if (recipe != null) {
|
||||||
|
// tooltip.add(TextHelper.getFormattedText(StatCollector.translateToLocal("tooltip.alchemy.recipe")));
|
||||||
|
//
|
||||||
|
// for (ItemStack item : recipe)
|
||||||
|
// if (item != null)
|
||||||
|
// tooltip.add(item.getDisplayName());
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// tooltip.add(TextHelper.getFormattedText(StatCollector.translateToLocal("tooltip.alchemy.pressShift")));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCrystalLevel(ItemStack stack) {
|
||||||
|
return stack.getItemDamage() > 1 ? Integer.MAX_VALUE : stack.getItemDamage() + 1;
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ import WayofTime.alchemicalWizardry.ConfigHandler;
|
||||||
import WayofTime.alchemicalWizardry.api.AlchemicalWizardryAPI;
|
import WayofTime.alchemicalWizardry.api.AlchemicalWizardryAPI;
|
||||||
import WayofTime.alchemicalWizardry.api.orb.BloodOrb;
|
import WayofTime.alchemicalWizardry.api.orb.BloodOrb;
|
||||||
import WayofTime.alchemicalWizardry.api.registry.OrbRegistry;
|
import WayofTime.alchemicalWizardry.api.registry.OrbRegistry;
|
||||||
|
import WayofTime.alchemicalWizardry.item.ItemActivationCrystal;
|
||||||
import WayofTime.alchemicalWizardry.item.ItemBloodOrb;
|
import WayofTime.alchemicalWizardry.item.ItemBloodOrb;
|
||||||
import WayofTime.alchemicalWizardry.item.ItemBucketEssence;
|
import WayofTime.alchemicalWizardry.item.ItemBucketEssence;
|
||||||
import WayofTime.alchemicalWizardry.item.sigil.ItemSigilDivination;
|
import WayofTime.alchemicalWizardry.item.sigil.ItemSigilDivination;
|
||||||
|
@ -24,6 +25,8 @@ public class ModItems {
|
||||||
|
|
||||||
public static Item bucketEssence;
|
public static Item bucketEssence;
|
||||||
|
|
||||||
|
public static Item activationCrystal;
|
||||||
|
|
||||||
public static Item sigilDivination;
|
public static Item sigilDivination;
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
|
@ -44,6 +47,8 @@ public class ModItems {
|
||||||
|
|
||||||
bucketEssence = registerItem(new ItemBucketEssence());
|
bucketEssence = registerItem(new ItemBucketEssence());
|
||||||
|
|
||||||
|
activationCrystal = registerItem(new ItemActivationCrystal());
|
||||||
|
|
||||||
sigilDivination = registerItem(new ItemSigilDivination());
|
sigilDivination = registerItem(new ItemSigilDivination());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,6 +65,9 @@ public class ModItems {
|
||||||
|
|
||||||
renderHelper.itemRender(bucketEssence);
|
renderHelper.itemRender(bucketEssence);
|
||||||
|
|
||||||
|
renderHelper.itemRender(activationCrystal, 0);
|
||||||
|
renderHelper.itemRender(activationCrystal, 1);
|
||||||
|
|
||||||
renderHelper.itemRender(sigilDivination);
|
renderHelper.itemRender(sigilDivination);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,33 @@
|
||||||
package WayofTime.alchemicalWizardry.tile;
|
package WayofTime.alchemicalWizardry.tile;
|
||||||
|
|
||||||
import WayofTime.alchemicalWizardry.api.NBTHolder;
|
import WayofTime.alchemicalWizardry.api.NBTHolder;
|
||||||
|
import WayofTime.alchemicalWizardry.api.event.RitualEvent;
|
||||||
|
import WayofTime.alchemicalWizardry.api.network.SoulNetwork;
|
||||||
import WayofTime.alchemicalWizardry.api.registry.RitualRegistry;
|
import WayofTime.alchemicalWizardry.api.registry.RitualRegistry;
|
||||||
import WayofTime.alchemicalWizardry.api.ritual.IMasterRitualStone;
|
import WayofTime.alchemicalWizardry.api.ritual.IMasterRitualStone;
|
||||||
import WayofTime.alchemicalWizardry.api.ritual.LocalRitualStorage;
|
import WayofTime.alchemicalWizardry.api.ritual.LocalRitualStorage;
|
||||||
import WayofTime.alchemicalWizardry.api.ritual.Ritual;
|
import WayofTime.alchemicalWizardry.api.ritual.Ritual;
|
||||||
|
import WayofTime.alchemicalWizardry.api.util.helper.NetworkHelper;
|
||||||
|
import WayofTime.alchemicalWizardry.item.ItemActivationCrystal;
|
||||||
|
import WayofTime.alchemicalWizardry.util.ChatUtil;
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.server.gui.IUpdatePlayerListBox;
|
import net.minecraft.server.gui.IUpdatePlayerListBox;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.BlockPos;
|
import net.minecraft.util.BlockPos;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class TileMasterRitualStone extends TileEntity implements IMasterRitualStone, IUpdatePlayerListBox {
|
public class TileMasterRitualStone extends TileEntity implements IMasterRitualStone, IUpdatePlayerListBox {
|
||||||
|
|
||||||
|
public static final int REFRESH_TIME = 0;
|
||||||
|
|
||||||
private String owner;
|
private String owner;
|
||||||
private boolean active;
|
private boolean active;
|
||||||
private int activeTime;
|
private int activeTime;
|
||||||
|
@ -47,9 +59,32 @@ public class TileMasterRitualStone extends TileEntity implements IMasterRitualSt
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void activateRitual(ItemStack activationCrystal, EntityPlayer activator) {
|
||||||
public void performRitual(World world, BlockPos pos, String ritualID) {
|
activationCrystal = NBTHolder.checkNBT(activationCrystal);
|
||||||
|
String crystalOwner = activationCrystal.getTagCompound().getString(NBTHolder.NBT_OWNER);
|
||||||
|
Ritual ritual = null;
|
||||||
|
|
||||||
|
if (!Strings.isNullOrEmpty(crystalOwner)) {
|
||||||
|
if (activationCrystal.getItem() instanceof ItemActivationCrystal) {
|
||||||
|
int crystalLevel = ((ItemActivationCrystal) activationCrystal.getItem()).getCrystalLevel(activationCrystal);
|
||||||
|
|
||||||
|
RitualEvent.RitualActivatedEvent event = new RitualEvent.RitualActivatedEvent(this, crystalOwner, ritual, activator, activationCrystal, crystalLevel);
|
||||||
|
|
||||||
|
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY) {
|
||||||
|
ChatUtil.sendNoSpamUnloc(activator, "chat.AlchemicalWizardry.ritual.prevent");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void performRitual(World world, BlockPos pos, Ritual ritual) {
|
||||||
|
if (ritual != null && RitualRegistry.ritualEnabled(ritual)) {
|
||||||
|
SoulNetwork network = NetworkHelper.getSoulNetwork(getOwner(), getWorld());
|
||||||
|
network.syphonAndDamage(ritual.getRefreshCost());
|
||||||
|
ritual.performEffect(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue