Refactor everything to WayofTime.bloodmagic.*
This commit is contained in:
parent
46742a73d1
commit
096ba02450
771 changed files with 566 additions and 573 deletions
28
src/main/java/WayofTime/bloodmagic/api/BlockStack.java
Normal file
28
src/main/java/WayofTime/bloodmagic/api/BlockStack.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
package WayofTime.bloodmagic.api;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraftforge.fml.common.registry.GameData;
|
||||
|
||||
@Getter
|
||||
@EqualsAndHashCode
|
||||
public class BlockStack {
|
||||
|
||||
private final Block block;
|
||||
private final int meta;
|
||||
|
||||
public BlockStack(Block block, int meta) {
|
||||
this.block = block;
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
public BlockStack(Block block) {
|
||||
this(block, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return GameData.getBlockRegistry().getNameForObject(block) + ":" + meta;
|
||||
}
|
||||
}
|
26
src/main/java/WayofTime/bloodmagic/api/BloodMagicAPI.java
Normal file
26
src/main/java/WayofTime/bloodmagic/api/BloodMagicAPI.java
Normal file
|
@ -0,0 +1,26 @@
|
|||
package WayofTime.bloodmagic.api;
|
||||
|
||||
import WayofTime.bloodmagic.api.util.helper.LogHelper;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
||||
public class BloodMagicAPI {
|
||||
|
||||
@Getter @Setter
|
||||
private static boolean loggingEnabled;
|
||||
|
||||
@Getter
|
||||
private static LogHelper logger = new LogHelper("BloodMagic|API");
|
||||
|
||||
@Getter
|
||||
private static DamageSource damageSource = new DamageSourceBloodMagic();
|
||||
|
||||
@Getter @Setter
|
||||
private static Item orbItem;
|
||||
|
||||
@Getter @Setter
|
||||
private static Fluid lifeEssence;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package WayofTime.bloodmagic.api;
|
||||
|
||||
import net.minecraft.util.DamageSource;
|
||||
|
||||
public class DamageSourceBloodMagic extends DamageSource {
|
||||
|
||||
public DamageSourceBloodMagic() {
|
||||
super("bloodMagic");
|
||||
|
||||
setDamageBypassesArmor();
|
||||
}
|
||||
}
|
29
src/main/java/WayofTime/bloodmagic/api/NBTHolder.java
Normal file
29
src/main/java/WayofTime/bloodmagic/api/NBTHolder.java
Normal file
|
@ -0,0 +1,29 @@
|
|||
package WayofTime.bloodmagic.api;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class NBTHolder {
|
||||
|
||||
public static final String NBT_OWNER = "ownerName";
|
||||
public static final String NBT_USES = "uses";
|
||||
public static final String NBT_UNUSABLE = "unusable";
|
||||
public static final String NBT_SACRIFICE = "sacrifice";
|
||||
public static final String NBT_DIMID = "dimensionId";
|
||||
public static final String NBT_COORDX = "xCoord";
|
||||
public static final String NBT_COORDY = "yCoord";
|
||||
public static final String NBT_COORDZ = "zCoord";
|
||||
public static final String NBT_MAXORB = "maxOrb";
|
||||
public static final String NBT_CURRENTESSENCE = "currentEssence";
|
||||
public static final String NBT_CURRENTRITUAL = "currentRitual";
|
||||
public static final String NBT_RUNNING = "isRunning";
|
||||
public static final String NBT_RUNTIME = "runtime";
|
||||
public static final String NBT_REAGENTTANK = "reagentTanks";
|
||||
|
||||
public static ItemStack checkNBT(ItemStack stack) {
|
||||
if (stack.getTagCompound() == null)
|
||||
stack.setTagCompound(new NBTTagCompound());
|
||||
|
||||
return stack;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package WayofTime.bloodmagic.api.altar;
|
||||
|
||||
import WayofTime.bloodmagic.api.BlockStack;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.BlockPos;
|
||||
|
||||
/**
|
||||
* Used for building the altar structure.
|
||||
*/
|
||||
@Getter
|
||||
public class AltarComponent {
|
||||
|
||||
private BlockPos offset;
|
||||
private BlockStack blockStack;
|
||||
private boolean bloodRune;
|
||||
private boolean upgradeSlot;
|
||||
|
||||
/**
|
||||
* @param offset - The position in the world relative to the MasterRitualStone
|
||||
* @param blockStack - The block and meta combination expected
|
||||
*/
|
||||
public AltarComponent(BlockPos offset, BlockStack blockStack) {
|
||||
this.offset = offset;
|
||||
this.blockStack = blockStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Non-meta based variant for ease of use.
|
||||
*/
|
||||
public AltarComponent(BlockPos offset, Block block) {
|
||||
this(offset, new BlockStack(block));
|
||||
}
|
||||
|
||||
/**
|
||||
* Use for setting a location at which there must be a block, but the type
|
||||
* of block does not matter.
|
||||
*/
|
||||
public AltarComponent(BlockPos offset) {
|
||||
this(offset, new BlockStack(Blocks.air));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the location to a Blood Rune. This does not mean that the location
|
||||
* can be used as an upgrade.
|
||||
*
|
||||
* @return the current instance for further use.
|
||||
*/
|
||||
public AltarComponent setBloodRune() {
|
||||
this.bloodRune = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the location to an upgrade slot.
|
||||
*
|
||||
* @return the current instance for further use.
|
||||
*/
|
||||
public AltarComponent setUpgradeSlot() {
|
||||
this.upgradeSlot = true;
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package WayofTime.bloodmagic.api.altar;
|
||||
|
||||
import lombok.Getter;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@Getter
|
||||
public class AltarRecipe {
|
||||
|
||||
public final int minTier, syphon, consumeRate, drainRate;
|
||||
public final boolean useTag;
|
||||
public final ItemStack input, output;
|
||||
|
||||
/**
|
||||
* Allows creation of a recipe for the {@link WayofTime.bloodmagic.block.BlockAltar} / {@link WayofTime.bloodmagic.tile.TileAltar}.
|
||||
* The output ItemStack is allowed to be null as some recipes do not contain an output. (Blood Orbs)
|
||||
*
|
||||
* @param input - The input ItemStack
|
||||
* @param output - The ItemStack obtained from the recipe
|
||||
* @param minTier - The minimum tier of Altar required
|
||||
* @param syphon - The amount of LP to syphon from the Altar
|
||||
* @param consumeRate - The rate at which LP is consumed during crafting
|
||||
* @param drainRate - The rate at which LP is drained during crafting
|
||||
* @param useTag -
|
||||
*/
|
||||
public AltarRecipe(ItemStack input, @Nullable ItemStack output, int minTier, int syphon, int consumeRate, int drainRate, boolean useTag) {
|
||||
this.input = input;
|
||||
this.output = output;
|
||||
this.minTier = minTier;
|
||||
this.syphon = syphon;
|
||||
this.consumeRate = consumeRate;
|
||||
this.drainRate = drainRate;
|
||||
this.useTag = useTag;
|
||||
}
|
||||
|
||||
public AltarRecipe(ItemStack input, ItemStack output, int minTier, int syphon, int consumeRate, int drainRate) {
|
||||
this(input, output, minTier, syphon, consumeRate, drainRate, false);
|
||||
}
|
||||
|
||||
public AltarRecipe (ItemStack input, int minTier, int consumeRate, int drainRate) {
|
||||
this(input, null, minTier, 0, consumeRate, drainRate);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package WayofTime.bloodmagic.api.altar;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class AltarUpgrade {
|
||||
|
||||
private int speedCount;
|
||||
|
||||
public AltarUpgrade() {
|
||||
|
||||
}
|
||||
|
||||
// Adders
|
||||
|
||||
public AltarUpgrade addSpeed() {
|
||||
speedCount++;
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package WayofTime.bloodmagic.api.altar;
|
||||
|
||||
public enum EnumAltarComponent {
|
||||
|
||||
GLOWSTONE,
|
||||
BLOODSTONE,
|
||||
BEACON,
|
||||
BLOODRUNE,
|
||||
CRYSTAL
|
||||
}
|
135
src/main/java/WayofTime/bloodmagic/api/altar/EnumAltarTier.java
Normal file
135
src/main/java/WayofTime/bloodmagic/api/altar/EnumAltarTier.java
Normal file
|
@ -0,0 +1,135 @@
|
|||
package WayofTime.bloodmagic.api.altar;
|
||||
|
||||
import WayofTime.bloodmagic.api.BlockStack;
|
||||
import WayofTime.bloodmagic.registry.ModBlocks;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.BlockPos;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Getter
|
||||
public enum EnumAltarTier {
|
||||
ONE(),
|
||||
TWO() {
|
||||
@Override
|
||||
public void buildComponents() {
|
||||
altarComponents.add(new AltarComponent(new BlockPos(-1, -1, -1), ModBlocks.rune).setBloodRune());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(0, -1, -1), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(1, -1, -1), ModBlocks.rune).setBloodRune());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(-1, -1, 0), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(1, -1, 0), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(-1, -1, 1), ModBlocks.rune).setBloodRune());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(0, -1, 1), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(1, -1, 1), ModBlocks.rune).setBloodRune());
|
||||
}
|
||||
},
|
||||
THREE() {
|
||||
@Override
|
||||
public void buildComponents() {
|
||||
altarComponents.addAll(TWO.getAltarComponents());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(-1, -1, -1), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(0, -1, -1), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(1, -1, -1), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(-1, -1, 0), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(1, -1, 0), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(-1, -1, 1), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(0, -1, 1), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(1, -1, 1), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(-3, -1, -3)));
|
||||
altarComponents.add(new AltarComponent(new BlockPos(-3, 0, -3)));
|
||||
altarComponents.add(new AltarComponent(new BlockPos(3, -1, -3)));
|
||||
altarComponents.add(new AltarComponent(new BlockPos(3, 0, -3)));
|
||||
altarComponents.add(new AltarComponent(new BlockPos(-3, -1, 3)));
|
||||
altarComponents.add(new AltarComponent(new BlockPos(-3, 0, 3)));
|
||||
altarComponents.add(new AltarComponent(new BlockPos(3, -1, 3)));
|
||||
altarComponents.add(new AltarComponent(new BlockPos(3, 0, 3)));
|
||||
altarComponents.add(new AltarComponent(new BlockPos(-3, 1, -3), Blocks.glowstone));
|
||||
altarComponents.add(new AltarComponent(new BlockPos(3, 1, -3), Blocks.glowstone));
|
||||
altarComponents.add(new AltarComponent(new BlockPos(-3, 1, 3), Blocks.glowstone));
|
||||
altarComponents.add(new AltarComponent(new BlockPos(3, 1, 3), Blocks.glowstone));
|
||||
|
||||
for (int i = -2; i <= 2; i++) {
|
||||
altarComponents.add(new AltarComponent(new BlockPos(3, -2, i), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(-3, -2, i), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(i, -2, 3), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(i, -2, -3), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
}
|
||||
}
|
||||
},
|
||||
FOUR() {
|
||||
@Override
|
||||
public void buildComponents() {
|
||||
altarComponents.addAll(THREE.getAltarComponents());
|
||||
|
||||
for (int i = -3; i <= 3; i++) {
|
||||
altarComponents.add(new AltarComponent(new BlockPos(5, -3, i), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(-5, -3, i), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(i, -3, 5), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(i, -3, -5), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
}
|
||||
|
||||
for (int i = -2; i <= 1; i++) {
|
||||
altarComponents.add(new AltarComponent(new BlockPos(5, i, 5)));
|
||||
altarComponents.add(new AltarComponent(new BlockPos(5, i, -5)));
|
||||
altarComponents.add(new AltarComponent(new BlockPos(-5, i, -5)));
|
||||
altarComponents.add(new AltarComponent(new BlockPos(-5, i, 5)));
|
||||
}
|
||||
|
||||
altarComponents.add(new AltarComponent(new BlockPos(5, 2, 5), new BlockStack(ModBlocks.bloodStone, 1)));
|
||||
altarComponents.add(new AltarComponent(new BlockPos(5, 2, -5), new BlockStack(ModBlocks.bloodStone, 1)));
|
||||
altarComponents.add(new AltarComponent(new BlockPos(-5, 2, -5), new BlockStack(ModBlocks.bloodStone, 1)));
|
||||
altarComponents.add(new AltarComponent(new BlockPos(-5, 2, 5), new BlockStack(ModBlocks.bloodStone, 1)));
|
||||
}
|
||||
},
|
||||
FIVE() {
|
||||
@Override
|
||||
public void buildComponents() {
|
||||
altarComponents.addAll(FOUR.getAltarComponents());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(-8, -3, 8), Blocks.beacon));
|
||||
altarComponents.add(new AltarComponent(new BlockPos(-8, -3, -8), Blocks.beacon));
|
||||
altarComponents.add(new AltarComponent(new BlockPos(8, -3, -8), Blocks.beacon));
|
||||
altarComponents.add(new AltarComponent(new BlockPos(8, -3, 8), Blocks.beacon));
|
||||
|
||||
for (int i = -6; i <= 6; i++) {
|
||||
altarComponents.add(new AltarComponent(new BlockPos(8, -4, i), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(-8, -4, i), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(i, -4, 8), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(i, -4, -8), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
}
|
||||
}
|
||||
},
|
||||
SIX() {
|
||||
@Override
|
||||
public void buildComponents() {
|
||||
altarComponents.addAll(FIVE.getAltarComponents());
|
||||
|
||||
for(int i = -4; i <= 2; i++) {
|
||||
altarComponents.add(new AltarComponent(new BlockPos(11, i, 11)));
|
||||
altarComponents.add(new AltarComponent(new BlockPos(-11, i, -11)));
|
||||
altarComponents.add(new AltarComponent(new BlockPos(11, i, -11)));
|
||||
altarComponents.add(new AltarComponent(new BlockPos(-11, i, 11)));
|
||||
}
|
||||
|
||||
altarComponents.add(new AltarComponent(new BlockPos(11, 3, 11), ModBlocks.crystal));
|
||||
altarComponents.add(new AltarComponent(new BlockPos(-11, 3, -11), ModBlocks.crystal));
|
||||
altarComponents.add(new AltarComponent(new BlockPos(11, 3, -11), ModBlocks.crystal));
|
||||
altarComponents.add(new AltarComponent(new BlockPos(-11, 3, 11), ModBlocks.crystal));
|
||||
|
||||
for (int i = -9; i <= 9; i++) {
|
||||
altarComponents.add(new AltarComponent(new BlockPos(11, -5, i), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(-11, -5, i), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(i, -5, 11), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
altarComponents.add(new AltarComponent(new BlockPos(i, -5, -11), ModBlocks.rune).setUpgradeSlot().setBloodRune());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static final int MAXTIERS = values().length;
|
||||
|
||||
ArrayList<AltarComponent> altarComponents = new ArrayList<AltarComponent>();
|
||||
|
||||
public void buildComponents() {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package WayofTime.bloodmagic.api.altar;
|
||||
|
||||
public interface IAltarComponent {
|
||||
|
||||
EnumAltarComponent getType(int meta);
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package WayofTime.bloodmagic.api.altar;
|
||||
|
||||
public interface IBloodAltar {
|
||||
|
||||
int getCapacity();
|
||||
|
||||
int getCurrentBlood();
|
||||
|
||||
int getTier();
|
||||
|
||||
int getProgress();
|
||||
|
||||
float getSacrificeMultiplier();
|
||||
|
||||
float getSelfSacrificeMultiplier();
|
||||
|
||||
float getOrbMultiplier();
|
||||
|
||||
float getDislocationMultiplier();
|
||||
|
||||
int getBufferCapacity();
|
||||
|
||||
void sacrificialDaggerCall(int amount, boolean b);
|
||||
|
||||
void startCycle();
|
||||
|
||||
/**
|
||||
* Will set the altar to initiate a cooldown cycle after it crafts before starting to craft again, giving the user time to interact with the altar.
|
||||
* This can only be set while the altar is not active.
|
||||
*
|
||||
* @param cooldown - How long the cooldown should last
|
||||
*/
|
||||
void requestPauseAfterCrafting(int cooldown);
|
||||
|
||||
void addToDemonBloodDuration(int dur);
|
||||
|
||||
boolean hasDemonBlood();
|
||||
|
||||
void decrementDemonBlood();
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package WayofTime.bloodmagic.api.event;
|
||||
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
|
||||
public class AddToNetworkEvent extends Event {
|
||||
|
||||
public String ownerNetwork;
|
||||
public int addedAmount;
|
||||
public int maximum;
|
||||
|
||||
/**
|
||||
* This event is called whenever the network is added to. If cancelled, no LP will be drained from the source. If result is set to Result.DENY,
|
||||
* the LP will still be drained but the soul network will not be added to.
|
||||
*
|
||||
* @param ownerNetwork Key used for the soul network
|
||||
* @param addedAmount Amount added
|
||||
* @param maximum Ceiling that the network can add to
|
||||
*/
|
||||
public AddToNetworkEvent(String ownerNetwork, int addedAmount, int maximum) {
|
||||
this.ownerNetwork = ownerNetwork;
|
||||
this.addedAmount = addedAmount;
|
||||
this.maximum = maximum;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package WayofTime.bloodmagic.api.event;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
|
||||
@Cancelable
|
||||
public class ItemBindEvent extends Event {
|
||||
|
||||
public final EntityPlayer player;
|
||||
public String key;
|
||||
public ItemStack itemStack;
|
||||
|
||||
public ItemBindEvent(EntityPlayer player, String key, ItemStack itemStack) {
|
||||
super();
|
||||
this.player = player;
|
||||
this.key = key;
|
||||
this.itemStack = itemStack;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
package WayofTime.bloodmagic.api.event;
|
||||
|
||||
import WayofTime.bloodmagic.api.ritual.IMasterRitualStone;
|
||||
import WayofTime.bloodmagic.api.ritual.Ritual;
|
||||
import WayofTime.bloodmagic.api.ritual.imperfect.IImperfectRitualStone;
|
||||
import WayofTime.bloodmagic.api.ritual.imperfect.ImperfectRitual;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
|
||||
public class RitualEvent extends Event {
|
||||
|
||||
public final IMasterRitualStone mrs;
|
||||
public final String ownerName;
|
||||
public final Ritual ritual;
|
||||
|
||||
private RitualEvent(IMasterRitualStone mrs, String ownerName, Ritual ritual) {
|
||||
this.mrs = mrs;
|
||||
this.ownerName = ownerName;
|
||||
this.ritual = ritual;
|
||||
}
|
||||
|
||||
/**
|
||||
* This event is called when a ritual is activated. If cancelled, it will not activate.
|
||||
*
|
||||
* {@link WayofTime.bloodmagic.api.util.helper.RitualHelper#activate(IMasterRitualStone, Ritual, EntityPlayer)}
|
||||
*/
|
||||
@Cancelable
|
||||
public static class RitualActivatedEvent extends RitualEvent {
|
||||
public final EntityPlayer player;
|
||||
public final ItemStack crystalStack;
|
||||
public int crystalTier;
|
||||
|
||||
public RitualActivatedEvent(IMasterRitualStone mrs, String owner, Ritual ritual, EntityPlayer player, ItemStack activationCrystal, int crystalTier) {
|
||||
super(mrs, owner, ritual);
|
||||
|
||||
this.player = player;
|
||||
this.crystalStack = activationCrystal;
|
||||
this.crystalTier = crystalTier;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This event is called when a Ritual effect is performed. If cancelled, the effect will not happen.
|
||||
*
|
||||
* {@link WayofTime.bloodmagic.api.util.helper.RitualHelper#perform(IMasterRitualStone, Ritual)}
|
||||
*/
|
||||
@Cancelable
|
||||
public static class RitualRunEvent extends RitualEvent {
|
||||
|
||||
public RitualRunEvent(IMasterRitualStone mrs, String owner, Ritual ritual) {
|
||||
super(mrs, owner, ritual);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This event is called when a Ritual is stopped by a {@link Ritual.BreakType}.
|
||||
*
|
||||
* {@link WayofTime.bloodmagic.api.util.helper.RitualHelper#stop(IMasterRitualStone, Ritual, Ritual.BreakType)}
|
||||
*/
|
||||
public static class RitualStopEvent extends RitualEvent {
|
||||
|
||||
public final Ritual.BreakType method;
|
||||
|
||||
public RitualStopEvent(IMasterRitualStone mrs, String owner, Ritual ritual, Ritual.BreakType method) {
|
||||
super(mrs, owner, ritual);
|
||||
|
||||
this.method = method;
|
||||
}
|
||||
}
|
||||
|
||||
@Cancelable
|
||||
public static class ImperfectRitualActivatedEvent extends Event {
|
||||
|
||||
public final IImperfectRitualStone ims;
|
||||
public final String ownerName;
|
||||
public final ImperfectRitual imperfectRitual;
|
||||
|
||||
public ImperfectRitualActivatedEvent(IImperfectRitualStone ims, String ownerName, ImperfectRitual imperfectRitual) {
|
||||
this.ims = ims;
|
||||
this.ownerName = ownerName;
|
||||
this.imperfectRitual = imperfectRitual;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package WayofTime.bloodmagic.api.event;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
|
||||
public class SoulNetworkEvent extends Event {
|
||||
|
||||
public String ownerName;
|
||||
public int syphon;
|
||||
|
||||
public SoulNetworkEvent(String ownerName, int syphon) {
|
||||
this.ownerName = ownerName;
|
||||
this.syphon = syphon;
|
||||
}
|
||||
|
||||
@Cancelable
|
||||
public static class ItemDrainInContainerEvent extends SoulNetworkEvent {
|
||||
|
||||
public ItemStack stack;
|
||||
|
||||
public ItemDrainInContainerEvent(ItemStack stack, String ownerName, int syphon) {
|
||||
super(ownerName, syphon);
|
||||
this.stack = stack;
|
||||
}
|
||||
}
|
||||
|
||||
@Cancelable
|
||||
public static class PlayerDrainNetworkEvent extends SoulNetworkEvent {
|
||||
|
||||
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) {
|
||||
super(ownerNetwork, drainAmount);
|
||||
this.shouldDamage = false;
|
||||
this.player = player;
|
||||
}
|
||||
}
|
||||
|
||||
@Cancelable
|
||||
public static class ItemDrainNetworkEvent extends PlayerDrainNetworkEvent {
|
||||
|
||||
public final ItemStack itemStack;
|
||||
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.damageAmount = (float)(drainAmount) / 100.0f;
|
||||
}
|
||||
}
|
||||
}
|
17
src/main/java/WayofTime/bloodmagic/api/iface/IBindable.java
Normal file
17
src/main/java/WayofTime/bloodmagic/api/iface/IBindable.java
Normal file
|
@ -0,0 +1,17 @@
|
|||
package WayofTime.bloodmagic.api.iface;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Implement this interface on any Item that can be bound to a player.
|
||||
*/
|
||||
public interface IBindable {
|
||||
|
||||
/**
|
||||
* Called when the player attempts to bind the item.
|
||||
*
|
||||
* If false, binding fails.
|
||||
*/
|
||||
boolean onBind(EntityPlayer player, ItemStack stack);
|
||||
}
|
4
src/main/java/WayofTime/bloodmagic/api/iface/ISigil.java
Normal file
4
src/main/java/WayofTime/bloodmagic/api/iface/ISigil.java
Normal file
|
@ -0,0 +1,4 @@
|
|||
package WayofTime.bloodmagic.api.iface;
|
||||
|
||||
public interface ISigil {
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
package WayofTime.bloodmagic.api.network;
|
||||
|
||||
import WayofTime.bloodmagic.api.BloodMagicAPI;
|
||||
import WayofTime.bloodmagic.api.NBTHolder;
|
||||
import WayofTime.bloodmagic.api.event.SoulNetworkEvent;
|
||||
import WayofTime.bloodmagic.api.util.helper.PlayerHelper;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.WorldSavedData;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class SoulNetwork extends WorldSavedData {
|
||||
|
||||
private int currentEssence;
|
||||
private int maxOrb;
|
||||
private final EntityPlayer player;
|
||||
|
||||
public SoulNetwork(String name) {
|
||||
super(name);
|
||||
|
||||
currentEssence = 0;
|
||||
maxOrb = 0;
|
||||
player = PlayerHelper.getPlayerFromUsername(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
currentEssence = nbttagcompound.getInteger(NBTHolder.NBT_CURRENTESSENCE);
|
||||
maxOrb = nbttagcompound.getInteger(NBTHolder.NBT_MAXORB);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
nbttagcompound.setInteger(NBTHolder.NBT_CURRENTESSENCE, currentEssence);
|
||||
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(BloodMagicAPI.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(BloodMagicAPI.getDamageSource());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
69
src/main/java/WayofTime/bloodmagic/api/orb/BloodOrb.java
Normal file
69
src/main/java/WayofTime/bloodmagic/api/orb/BloodOrb.java
Normal file
|
@ -0,0 +1,69 @@
|
|||
package WayofTime.bloodmagic.api.orb;
|
||||
|
||||
import WayofTime.bloodmagic.api.registry.OrbRegistry;
|
||||
|
||||
/**
|
||||
* Base object for all Blood Orbs. Makes Orb creation quite a bit easier.
|
||||
*
|
||||
* Just create a new BloodOrb instance then register it with {@link OrbRegistry#registerOrb(BloodOrb)}
|
||||
* This will allow the use of just one item ID for all orbs. If an addon dev needs more control over the intricacies
|
||||
* of their orb (custom right clicking, renderers, etc), they can just create their own item as normal.
|
||||
*
|
||||
*/
|
||||
public class BloodOrb {
|
||||
|
||||
private String name;
|
||||
private int tier;
|
||||
private int capacity;
|
||||
private String owner = "BloodMagic";
|
||||
|
||||
/**
|
||||
* A base object for BloodOrbs. A bit cleaner than the
|
||||
* old way through EnergyItems.
|
||||
*
|
||||
* @param name - A name for the Orb. Gets put into an unlocalized name.
|
||||
* @param tier - The tier of the Orb.
|
||||
* @param capacity - The max amount of LP the Orb can store.
|
||||
*/
|
||||
public BloodOrb(String name, int tier, int capacity) {
|
||||
this.name = name;
|
||||
this.tier = tier;
|
||||
this.capacity = capacity;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getTier() {
|
||||
return tier;
|
||||
}
|
||||
|
||||
public int getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
public String getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* For setting the MODID of the mod that creates the Orb. Not required, but preferred.
|
||||
*
|
||||
* @return - The BloodOrb object for further use.
|
||||
*/
|
||||
public BloodOrb setOwner(String owner) {
|
||||
this.owner = owner;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BloodOrb{" +
|
||||
"name='" + name + '\'' +
|
||||
", tier=" + tier +
|
||||
", capacity=" + capacity +
|
||||
", owner=" + owner +
|
||||
'}';
|
||||
}
|
||||
}
|
10
src/main/java/WayofTime/bloodmagic/api/orb/IBloodOrb.java
Normal file
10
src/main/java/WayofTime/bloodmagic/api/orb/IBloodOrb.java
Normal file
|
@ -0,0 +1,10 @@
|
|||
package WayofTime.bloodmagic.api.orb;
|
||||
|
||||
public interface IBloodOrb {
|
||||
|
||||
BloodOrb getOrb(int meta);
|
||||
|
||||
int getMaxEssence(int meta);
|
||||
|
||||
int getOrbLevel(int meta);
|
||||
}
|
4
src/main/java/WayofTime/bloodmagic/api/package-info.java
Normal file
4
src/main/java/WayofTime/bloodmagic/api/package-info.java
Normal file
|
@ -0,0 +1,4 @@
|
|||
@API(owner = "BloodMagic", provides = "BloodMagic|API", apiVersion = "@VERSION@")
|
||||
package WayofTime.bloodmagic.api;
|
||||
|
||||
import net.minecraftforge.fml.common.API;
|
|
@ -0,0 +1,25 @@
|
|||
package WayofTime.bloodmagic.api.registry;
|
||||
|
||||
import WayofTime.bloodmagic.api.BloodMagicAPI;
|
||||
import WayofTime.bloodmagic.api.altar.AltarRecipe;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class AltarRecipeRegistry {
|
||||
|
||||
@Getter
|
||||
private static BiMap<ItemStack, AltarRecipe> recipes = HashBiMap.create();
|
||||
|
||||
public static void registerRecipe(AltarRecipe recipe) {
|
||||
if (!recipes.containsValue(recipe))
|
||||
recipes.put(recipe.input, recipe);
|
||||
else
|
||||
BloodMagicAPI.getLogger().error("Error adding recipe for " + recipe.input.getDisplayName() + (recipe.output == null ? "" : " -> " + recipe.output.getDisplayName()) + ". Recipe already exists.");
|
||||
}
|
||||
|
||||
public static AltarRecipe getRecipeForInput(ItemStack input) {
|
||||
return recipes.get(input);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package WayofTime.bloodmagic.api.registry;
|
||||
|
||||
import WayofTime.bloodmagic.api.BloodMagicAPI;
|
||||
import WayofTime.bloodmagic.api.ritual.imperfect.ImperfectRitual;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ImperfectRitualRegistry {
|
||||
|
||||
public static final BiMap<ImperfectRitual, Boolean> enabledRituals = HashBiMap.create();
|
||||
private static final BiMap<String, ImperfectRitual> registry = HashBiMap.create();
|
||||
|
||||
/**
|
||||
* The safe way to register a new Ritual.
|
||||
*
|
||||
* @param imperfectRitual - The imperfect ritual to register.
|
||||
* @param id - The ID for the imperfect ritual. Cannot be duplicated.
|
||||
*/
|
||||
public static void registerRitual(ImperfectRitual imperfectRitual, String id) {
|
||||
if (imperfectRitual != null) {
|
||||
if (registry.containsKey(id))
|
||||
BloodMagicAPI.getLogger().error("Duplicate imperfect ritual id: " + id);
|
||||
else
|
||||
registry.put(id, imperfectRitual);
|
||||
}
|
||||
}
|
||||
|
||||
public static ImperfectRitual getRitualForId(String id) {
|
||||
return registry.get(id);
|
||||
}
|
||||
|
||||
public static String getIdForRitual(ImperfectRitual imperfectRitual) {
|
||||
return registry.inverse().get(imperfectRitual);
|
||||
}
|
||||
|
||||
public static boolean isMapEmpty() {
|
||||
return registry.isEmpty();
|
||||
}
|
||||
|
||||
public static int getMapSize() {
|
||||
return registry.size();
|
||||
}
|
||||
|
||||
public static boolean ritualEnabled(ImperfectRitual imperfectRitual) {
|
||||
return enabledRituals.get(imperfectRitual);
|
||||
}
|
||||
|
||||
public static BiMap<String, ImperfectRitual> getRegistry() {
|
||||
return HashBiMap.create(registry);
|
||||
}
|
||||
|
||||
public static ArrayList<String> getIds() {
|
||||
return new ArrayList<String>(registry.keySet());
|
||||
}
|
||||
|
||||
public static ArrayList<ImperfectRitual> getRituals() {
|
||||
return new ArrayList<ImperfectRitual>(registry.values());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package WayofTime.bloodmagic.api.registry;
|
||||
|
||||
import WayofTime.bloodmagic.api.BloodMagicAPI;
|
||||
import WayofTime.bloodmagic.api.orb.BloodOrb;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is only for those who wish to add a basic {@link BloodOrb}. If you need custom handling,
|
||||
* you will need your own item class.
|
||||
*/
|
||||
public class OrbRegistry {
|
||||
|
||||
@Getter
|
||||
private static List<BloodOrb> orbs = new ArrayList<BloodOrb>();
|
||||
|
||||
public static void registerOrb(BloodOrb orb) {
|
||||
if (!orbs.contains(orb))
|
||||
orbs.add(orb);
|
||||
else
|
||||
BloodMagicAPI.getLogger().error("Error adding orb: " + orb.toString() + ". Orb already exists!");
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void registerOrbTexture(BloodOrb orb, String resourceLocation) {
|
||||
int meta = getIndexOf(orb);
|
||||
|
||||
ModelBakery.addVariantName(BloodMagicAPI.getOrbItem(), resourceLocation);
|
||||
ModelLoader.setCustomModelResourceLocation(BloodMagicAPI.getOrbItem(), meta, new ModelResourceLocation(resourceLocation, "inventory"));
|
||||
}
|
||||
|
||||
public static BloodOrb getOrb(int index) {
|
||||
return orbs.get(index);
|
||||
}
|
||||
|
||||
public static int getIndexOf(BloodOrb orb) {
|
||||
return orbs.indexOf(orb);
|
||||
}
|
||||
|
||||
public static boolean isEmpty() {
|
||||
return orbs.isEmpty();
|
||||
}
|
||||
|
||||
public static int getSize() {
|
||||
return orbs.size();
|
||||
}
|
||||
|
||||
public static ItemStack getOrbStack(BloodOrb orb) {
|
||||
return new ItemStack(BloodMagicAPI.getOrbItem(), 1, getIndexOf(orb));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package WayofTime.bloodmagic.api.registry;
|
||||
|
||||
import WayofTime.bloodmagic.api.BloodMagicAPI;
|
||||
import WayofTime.bloodmagic.api.ritual.Ritual;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RitualRegistry {
|
||||
|
||||
public static final BiMap<Ritual, Boolean> enabledRituals = HashBiMap.create();
|
||||
private static final BiMap<String, Ritual> registry = HashBiMap.create();
|
||||
|
||||
/**
|
||||
* The safe way to register a new Ritual.
|
||||
*
|
||||
* @param ritual - The ritual to register.
|
||||
* @param id - The ID for the ritual. Cannot be duplicated.
|
||||
*/
|
||||
public static void registerRitual(Ritual ritual, String id) {
|
||||
if (ritual != null) {
|
||||
if (registry.containsKey(id))
|
||||
BloodMagicAPI.getLogger().error("Duplicate ritual id: " + id);
|
||||
else
|
||||
registry.put(id, ritual);
|
||||
}
|
||||
}
|
||||
|
||||
public static Ritual getRitualForId(String id) {
|
||||
return registry.get(id);
|
||||
}
|
||||
|
||||
public static String getIdForRitual(Ritual ritual) {
|
||||
return registry.inverse().get(ritual);
|
||||
}
|
||||
|
||||
public static boolean isMapEmpty() {
|
||||
return registry.isEmpty();
|
||||
}
|
||||
|
||||
public static int getMapSize() {
|
||||
return registry.size();
|
||||
}
|
||||
|
||||
public static boolean ritualEnabled(Ritual ritual) {
|
||||
return enabledRituals.get(ritual);
|
||||
}
|
||||
|
||||
public static BiMap<String, Ritual> getRegistry() {
|
||||
return HashBiMap.create(registry);
|
||||
}
|
||||
|
||||
public static ArrayList<String> getIds() {
|
||||
return new ArrayList<String>(registry.keySet());
|
||||
}
|
||||
|
||||
public static ArrayList<Ritual> getRituals() {
|
||||
return new ArrayList<Ritual>(registry.values());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package WayofTime.bloodmagic.api.ritual;
|
||||
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public enum EnumRuneType implements IStringSerializable {
|
||||
|
||||
BLANK,
|
||||
WATER,
|
||||
FIRE,
|
||||
EARTH,
|
||||
AIR,
|
||||
DUSK,
|
||||
DAWN;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name().toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.toString();
|
||||
}
|
||||
|
||||
public static EnumRuneType byMetadata(int meta) {
|
||||
if (meta < 0 || meta >= values().length)
|
||||
meta = 0;
|
||||
|
||||
return values()[meta];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package WayofTime.bloodmagic.api.ritual;
|
||||
|
||||
import WayofTime.bloodmagic.api.ritual.imperfect.IImperfectRitualStone;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IMasterRitualStone extends IImperfectRitualStone {
|
||||
|
||||
void performRitual(World world, BlockPos pos, Ritual ritual);
|
||||
|
||||
void setCooldown(int cooldown);
|
||||
|
||||
int getCooldown();
|
||||
|
||||
void setActive(boolean active);
|
||||
|
||||
EnumFacing getDirection();
|
||||
|
||||
NBTTagCompound getCustomRitualTag();
|
||||
|
||||
void setCustomRitualTag(NBTTagCompound tag);
|
||||
|
||||
boolean areTanksEmpty();
|
||||
|
||||
int getRunningTime();
|
||||
|
||||
LocalRitualStorage getLocalStorage();
|
||||
|
||||
void setLocalStorage(LocalRitualStorage storage);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package WayofTime.bloodmagic.api.ritual;
|
||||
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IRitualStone {
|
||||
|
||||
boolean isRuneType(World world, BlockPos pos, int meta, EnumRuneType runeType);
|
||||
|
||||
interface Tile {
|
||||
boolean isRuneType(EnumRuneType runeType);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package WayofTime.bloodmagic.api.ritual;
|
||||
|
||||
import WayofTime.bloodmagic.api.NBTHolder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.BlockPos;
|
||||
|
||||
/**
|
||||
* This class is used to pass ritual-specific data into the RitualEffect from the containing Master Ritual Stone. This is basically used as auxiliary storage,
|
||||
* for when simply storing to NBT becomes... difficult.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class LocalRitualStorage {
|
||||
|
||||
private BlockPos pos;
|
||||
|
||||
public void writeToNBT(NBTTagCompound tagCompound) {
|
||||
tagCompound.setInteger(NBTHolder.NBT_COORDX, pos.getX());
|
||||
tagCompound.setInteger(NBTHolder.NBT_COORDY, pos.getY());
|
||||
tagCompound.setInteger(NBTHolder.NBT_COORDZ, pos.getZ());
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound tagCompound) {
|
||||
this.pos = new BlockPos(tagCompound.getInteger(NBTHolder.NBT_COORDX), tagCompound.getInteger(NBTHolder.NBT_COORDY), tagCompound.getInteger(NBTHolder.NBT_COORDZ));
|
||||
}
|
||||
}
|
72
src/main/java/WayofTime/bloodmagic/api/ritual/Ritual.java
Normal file
72
src/main/java/WayofTime/bloodmagic/api/ritual/Ritual.java
Normal file
|
@ -0,0 +1,72 @@
|
|||
package WayofTime.bloodmagic.api.ritual;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.BlockPos;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public abstract class Ritual {
|
||||
|
||||
private final String name;
|
||||
private final int crystalLevel;
|
||||
private final int activationCost;
|
||||
private final RitualRenderer renderer;
|
||||
|
||||
public final ArrayList<RitualComponent> ritualComponents = new ArrayList<RitualComponent>();
|
||||
|
||||
public Ritual(String name, int crystalLevel, int activationCost) {
|
||||
this(name, crystalLevel, activationCost, null);
|
||||
}
|
||||
|
||||
public abstract boolean startRitual(IMasterRitualStone masterRitualStone, EntityPlayer player);
|
||||
|
||||
public abstract void performEffect(IMasterRitualStone masterRitualStone);
|
||||
|
||||
public abstract void onRitualBroken(IMasterRitualStone masterRitualStone, Ritual.BreakType breakType);
|
||||
|
||||
public abstract int getRefreshCost();
|
||||
|
||||
public abstract ArrayList<RitualComponent> getComponents();
|
||||
|
||||
public LocalRitualStorage getNewLocalStorage() {
|
||||
return new LocalRitualStorage();
|
||||
}
|
||||
|
||||
public void addOffsetRunes(ArrayList<RitualComponent> components, int offset1, int offset2, int y, EnumRuneType rune) {
|
||||
components.add(new RitualComponent(new BlockPos(offset1, y, offset2), rune));
|
||||
components.add(new RitualComponent(new BlockPos(offset2, y, offset1), rune));
|
||||
components.add(new RitualComponent(new BlockPos(offset1, y, -offset2), rune));
|
||||
components.add(new RitualComponent(new BlockPos(-offset2, y, offset1), rune));
|
||||
components.add(new RitualComponent(new BlockPos(-offset1, y, offset2), rune));
|
||||
components.add(new RitualComponent(new BlockPos(offset2, y, -offset1), rune));
|
||||
components.add(new RitualComponent(new BlockPos(-offset1, y, -offset2), rune));
|
||||
components.add(new RitualComponent(new BlockPos(-offset2, y, -offset1), rune));
|
||||
}
|
||||
|
||||
public void addCornerRunes(ArrayList<RitualComponent> components, int offset, int y, EnumRuneType rune) {
|
||||
components.add(new RitualComponent(new BlockPos(offset, y, offset), rune));
|
||||
components.add(new RitualComponent(new BlockPos(offset, y, -offset), rune));
|
||||
components.add(new RitualComponent(new BlockPos(-offset, y, -offset), rune));
|
||||
components.add(new RitualComponent(new BlockPos(-offset, y, offset), rune));
|
||||
}
|
||||
|
||||
public void addParallelRunes(ArrayList<RitualComponent> components, int offset, int y, EnumRuneType rune) {
|
||||
components.add(new RitualComponent(new BlockPos(offset, y, 0), rune));
|
||||
components.add(new RitualComponent(new BlockPos(-offset, y, 0), rune));
|
||||
components.add(new RitualComponent(new BlockPos(0, y, -offset), rune));
|
||||
components.add(new RitualComponent(new BlockPos(0, y, offset), rune));
|
||||
}
|
||||
|
||||
public enum BreakType {
|
||||
REDSTONE,
|
||||
BREAK_MRS,
|
||||
BREAK_STONE,
|
||||
ACTIVATE,
|
||||
DEACTIVATE,
|
||||
EXPLOSION,
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package WayofTime.bloodmagic.api.ritual;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public class RitualComponent {
|
||||
|
||||
private final BlockPos offset;
|
||||
private final EnumRuneType runeType;
|
||||
|
||||
public int getX(EnumFacing direction) {
|
||||
switch (direction) {
|
||||
case EAST:
|
||||
return -this.getOffset().getZ();
|
||||
case SOUTH:
|
||||
return -this.getOffset().getX();
|
||||
case WEST:
|
||||
return this.getOffset().getZ();
|
||||
default:
|
||||
return this.getOffset().getX();
|
||||
}
|
||||
}
|
||||
|
||||
public int getZ(EnumFacing direction) {
|
||||
switch (direction) {
|
||||
case EAST:
|
||||
return this.getOffset().getX();
|
||||
case SOUTH:
|
||||
return -this.getOffset().getZ();
|
||||
case WEST:
|
||||
return -this.getOffset().getX();
|
||||
default:
|
||||
return this.getOffset().getZ();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package WayofTime.bloodmagic.api.ritual;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public abstract class RitualRenderer {
|
||||
|
||||
public abstract void renderAt(IMasterRitualStone masterRitualStone, double x, double y, double z);
|
||||
|
||||
protected void bindTexture(ResourceLocation resourceLocation) {
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(resourceLocation);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package WayofTime.bloodmagic.api.ritual.imperfect;
|
||||
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IImperfectRitualStone {
|
||||
|
||||
String getOwner();
|
||||
|
||||
World getWorld();
|
||||
|
||||
BlockPos getPos();
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package WayofTime.bloodmagic.api.ritual.imperfect;
|
||||
|
||||
import WayofTime.bloodmagic.api.BlockStack;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public abstract class ImperfectRitual {
|
||||
|
||||
private final BlockStack requiredBlock;
|
||||
private final int activationCost;
|
||||
private final boolean lightshow;
|
||||
|
||||
public ImperfectRitual(BlockStack requiredBlock, int activationCost) {
|
||||
this(requiredBlock, activationCost, false);
|
||||
}
|
||||
|
||||
public abstract boolean onActivate(IImperfectRitualStone imperfectRitualStone, EntityPlayer player);
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package WayofTime.bloodmagic.api.util.helper;
|
||||
|
||||
import WayofTime.bloodmagic.api.NBTHolder;
|
||||
import WayofTime.bloodmagic.api.event.ItemBindEvent;
|
||||
import WayofTime.bloodmagic.api.iface.IBindable;
|
||||
import com.google.common.base.Strings;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
public class BindableHelper {
|
||||
|
||||
/**
|
||||
* Bind an item to a player. Handles checking if the player was an instanceof
|
||||
* {@link net.minecraftforge.common.util.FakePlayer} or other type of Fake Player.
|
||||
*
|
||||
* @param stack - The ItemStack to bind
|
||||
* @param player - The Player to bind the ItemStack to
|
||||
* @return - Whether binding was successful
|
||||
*/
|
||||
public static boolean checkAndSetItemOwner(ItemStack stack, EntityPlayer player) {
|
||||
return !PlayerHelper.isFakePlayer(player) && checkAndSetItemOwner(stack, player.getGameProfile().getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind an item to a username.
|
||||
*
|
||||
* Requires the Item contained in the ItemStack to be an instanceof {@link IBindable}
|
||||
*
|
||||
* Fires {@link ItemBindEvent}.
|
||||
*
|
||||
* @param stack - The ItemStack to bind
|
||||
* @param ownerName - The username to bind the ItemStack to
|
||||
* @return - Whether the binding was successful
|
||||
*/
|
||||
public static boolean checkAndSetItemOwner(ItemStack stack, String ownerName) {
|
||||
stack = NBTHolder.checkNBT(stack);
|
||||
|
||||
if (!(stack.getItem() instanceof IBindable))
|
||||
return false;
|
||||
|
||||
if (Strings.isNullOrEmpty(stack.getTagCompound().getString(NBTHolder.NBT_OWNER))) {
|
||||
MinecraftForge.EVENT_BUS.post(new ItemBindEvent(PlayerHelper.getPlayerFromUsername(ownerName), ownerName, stack));
|
||||
((IBindable) stack.getItem()).onBind(PlayerHelper.getPlayerFromUsername(ownerName), stack);
|
||||
stack.getTagCompound().setString(NBTHolder.NBT_OWNER, ownerName);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Owner of the item without checking if it is already bound.
|
||||
* Also bypasses {@link ItemBindEvent}.
|
||||
*
|
||||
* @param stack - The ItemStack to bind
|
||||
* @param ownerName - The username to bind the ItemStack to
|
||||
*/
|
||||
public static void setItemOwner(ItemStack stack, String ownerName) {
|
||||
stack = NBTHolder.checkNBT(stack);
|
||||
|
||||
stack.getTagCompound().setString(NBTHolder.NBT_OWNER, ownerName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to safely obtain the username of the ItemStack's owner
|
||||
*
|
||||
* @param stack - The ItemStack to check the owner of
|
||||
* @return - The username of the ItemStack's owner
|
||||
*/
|
||||
public static String getOwnerName(ItemStack stack) {
|
||||
stack = NBTHolder.checkNBT(stack);
|
||||
|
||||
return stack.getTagCompound().getString(NBTHolder.NBT_OWNER);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package WayofTime.bloodmagic.api.util.helper;
|
||||
|
||||
import WayofTime.bloodmagic.api.BloodMagicAPI;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class LogHelper {
|
||||
|
||||
private Logger logger;
|
||||
|
||||
public LogHelper(String logger) {
|
||||
this.logger = LogManager.getLogger(logger);
|
||||
}
|
||||
|
||||
public void info(Object info) {
|
||||
if (BloodMagicAPI.isLoggingEnabled())
|
||||
logger.info(info);
|
||||
}
|
||||
|
||||
public void error(Object error) {
|
||||
if (BloodMagicAPI.isLoggingEnabled())
|
||||
logger.info(error);
|
||||
}
|
||||
|
||||
public void debug(Object debug) {
|
||||
if (BloodMagicAPI.isLoggingEnabled())
|
||||
logger.info(debug);
|
||||
}
|
||||
|
||||
public void fatal(Object fatal) {
|
||||
logger.fatal(fatal);
|
||||
}
|
||||
|
||||
public Logger getLogger() {
|
||||
return logger;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,232 @@
|
|||
package WayofTime.bloodmagic.api.util.helper;
|
||||
|
||||
import WayofTime.bloodmagic.api.BloodMagicAPI;
|
||||
import WayofTime.bloodmagic.api.NBTHolder;
|
||||
import WayofTime.bloodmagic.api.event.AddToNetworkEvent;
|
||||
import WayofTime.bloodmagic.api.event.SoulNetworkEvent;
|
||||
import WayofTime.bloodmagic.api.network.SoulNetwork;
|
||||
import com.google.common.base.Strings;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
|
||||
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
|
||||
|
||||
/**
|
||||
* Master method used to syphon from the player's network, and will damage them accordingly if they do not have enough LP.
|
||||
* Does not drain on the client side.
|
||||
*
|
||||
* @param stack Owned itemStack
|
||||
* @param player Player using the item
|
||||
* @param syphon
|
||||
* @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 stack, EntityPlayer player, int syphon) {
|
||||
if (player.worldObj.isRemote)
|
||||
return false;
|
||||
|
||||
stack = NBTHolder.checkNBT(stack);
|
||||
String ownerName = stack.getTagCompound().getString(NBTHolder.NBT_OWNER);
|
||||
|
||||
if (!Strings.isNullOrEmpty(ownerName)) {
|
||||
SoulNetworkEvent.ItemDrainNetworkEvent event = new SoulNetworkEvent.ItemDrainNetworkEvent(player, ownerName, stack, syphon);
|
||||
|
||||
if(MinecraftForge.EVENT_BUS.post(event))
|
||||
return false;
|
||||
|
||||
int drainAmount = syphonFromNetwork(event.ownerName, event.syphon);
|
||||
|
||||
if(drainAmount == 0 || event.shouldDamage)
|
||||
hurtPlayer(player, event.syphon);
|
||||
|
||||
//The event has been told to prevent the action but allow all repercussions of using the item.
|
||||
return event.getResult() != Event.Result.DENY;
|
||||
}
|
||||
|
||||
int amount = NetworkHelper.syphonFromNetwork(stack, syphon);
|
||||
|
||||
hurtPlayer(player, syphon - amount);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean syphonFromNetworkWhileInContainer(ItemStack stack, int syphon) {
|
||||
stack = NBTHolder.checkNBT(stack);
|
||||
String ownerName = stack.getTagCompound().getString(NBTHolder.NBT_OWNER);
|
||||
|
||||
if (Strings.isNullOrEmpty(ownerName))
|
||||
return false;
|
||||
|
||||
SoulNetworkEvent.ItemDrainInContainerEvent event = new SoulNetworkEvent.ItemDrainInContainerEvent(stack, ownerName, syphon);
|
||||
|
||||
if(MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
|
||||
return false;
|
||||
|
||||
return syphonFromNetwork(event.ownerName, event.syphon) >= syphon;
|
||||
}
|
||||
|
||||
public static int syphonFromNetwork(ItemStack stack, int syphon) {
|
||||
stack = NBTHolder.checkNBT(stack);
|
||||
String ownerName = stack.getTagCompound().getString(NBTHolder.NBT_OWNER);
|
||||
if (!Strings.isNullOrEmpty(ownerName))
|
||||
return syphonFromNetwork(ownerName, syphon);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static int syphonFromNetwork(String ownerName, int syphon) {
|
||||
if (MinecraftServer.getServer() == null)
|
||||
return 0;
|
||||
|
||||
World world = MinecraftServer.getServer().worldServers[0];
|
||||
SoulNetwork network = (SoulNetwork) world.loadItemData(SoulNetwork.class, ownerName);
|
||||
|
||||
if (network == null) {
|
||||
network = new SoulNetwork(ownerName);
|
||||
world.setItemData(ownerName, network);
|
||||
}
|
||||
|
||||
if (network.getCurrentEssence() >= syphon) {
|
||||
network.setCurrentEssence(network.getCurrentEssence() - syphon);
|
||||
network.markDirty();
|
||||
return syphon;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Add
|
||||
|
||||
/**
|
||||
* A method to add to an owner's network up to a maximum value.
|
||||
*
|
||||
* @return amount added to the network
|
||||
*/
|
||||
public static int addCurrentEssenceToMaximum(String ownerName, int addedEssence, int maximum) {
|
||||
AddToNetworkEvent event = new AddToNetworkEvent(ownerName, addedEssence, maximum);
|
||||
|
||||
if(MinecraftForge.EVENT_BUS.post(event))
|
||||
return 0;
|
||||
|
||||
if (MinecraftServer.getServer() == null)
|
||||
return 0;
|
||||
|
||||
World world = MinecraftServer.getServer().worldServers[0];
|
||||
SoulNetwork data = (SoulNetwork) world.loadItemData(SoulNetwork.class, event.ownerNetwork);
|
||||
|
||||
if (data == null) {
|
||||
data = new SoulNetwork(event.ownerNetwork);
|
||||
world.setItemData(event.ownerNetwork, data);
|
||||
}
|
||||
|
||||
int currEss = data.getCurrentEssence();
|
||||
|
||||
if (currEss >= event.maximum)
|
||||
return 0;
|
||||
|
||||
int newEss = Math.min(event.maximum, currEss + event.addedAmount);
|
||||
if(event.getResult() != Event.Result.DENY)
|
||||
data.setCurrentEssence(newEss);
|
||||
|
||||
return newEss - currEss;
|
||||
}
|
||||
|
||||
// Get
|
||||
|
||||
public static int getCurrentEssence(String ownerName) {
|
||||
if (MinecraftServer.getServer() == null)
|
||||
return 0;
|
||||
|
||||
World world = MinecraftServer.getServer().worldServers[0];
|
||||
SoulNetwork network = (SoulNetwork) world.loadItemData(SoulNetwork.class, ownerName);
|
||||
|
||||
if (network == null) {
|
||||
network = new SoulNetwork(ownerName);
|
||||
world.setItemData(ownerName, network);
|
||||
}
|
||||
|
||||
return network.getCurrentEssence();
|
||||
}
|
||||
|
||||
// Do damage
|
||||
|
||||
public static void hurtPlayer(EntityPlayer user, int energySyphoned) {
|
||||
if (energySyphoned < 100 && energySyphoned > 0) {
|
||||
if (!user.capabilities.isCreativeMode) {
|
||||
user.setHealth((user.getHealth() - 1));
|
||||
|
||||
if (user.getHealth() <= 0.0005f)
|
||||
user.onDeath(BloodMagicAPI.getDamageSource());
|
||||
}
|
||||
} else if (energySyphoned >= 100) {
|
||||
if (!user.capabilities.isCreativeMode) {
|
||||
for (int i = 0; i < ((energySyphoned + 99) / 100); i++) {
|
||||
user.setHealth((user.getHealth() - 1));
|
||||
|
||||
if (user.getHealth() <= 0.0005f) {
|
||||
user.onDeath(BloodMagicAPI.getDamageSource());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void hurtPlayer(EntityPlayer user, float damage) {
|
||||
if (!user.capabilities.isCreativeMode) {
|
||||
user.setHealth((user.getHealth() - damage));
|
||||
|
||||
if (user.getHealth() <= 0.0005f)
|
||||
user.onDeath(BloodMagicAPI.getDamageSource());
|
||||
}
|
||||
}
|
||||
|
||||
public static void setMaxOrbToMax(String ownerName, int maxOrb) {
|
||||
if (MinecraftServer.getServer() == null)
|
||||
return;
|
||||
|
||||
World world = MinecraftServer.getServer().worldServers[0];
|
||||
SoulNetwork network = (SoulNetwork) world.loadItemData(SoulNetwork.class, ownerName);
|
||||
|
||||
if (network == null) {
|
||||
network = new SoulNetwork(ownerName);
|
||||
world.setItemData(ownerName, network);
|
||||
}
|
||||
|
||||
network.setMaxOrb(Math.max(maxOrb, network.getMaxOrb()));
|
||||
network.markDirty();
|
||||
}
|
||||
|
||||
public static int getCurrentMaxOrb(String ownerName) {
|
||||
if (MinecraftServer.getServer() == null)
|
||||
return 0;
|
||||
|
||||
World world = MinecraftServer.getServer().worldServers[0];
|
||||
SoulNetwork network = (SoulNetwork) world.loadItemData(SoulNetwork.class, ownerName);
|
||||
|
||||
if (network == null) {
|
||||
network = new SoulNetwork(ownerName);
|
||||
world.setItemData(ownerName, network);
|
||||
}
|
||||
|
||||
return network.getMaxOrb();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package WayofTime.bloodmagic.api.util.helper;
|
||||
|
||||
import WayofTime.bloodmagic.api.NBTHolder;
|
||||
import com.google.common.base.Strings;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class PlayerHelper {
|
||||
|
||||
private static final Pattern FAKE_PLAYER_PATTERN = Pattern.compile("^(?:\\[.*\\])|(?:ComputerCraft)$");
|
||||
|
||||
public static String getUsernameFromPlayer(EntityPlayer player) {
|
||||
return player.getGameProfile().getName();
|
||||
}
|
||||
|
||||
public static EntityPlayer getPlayerFromUsername(String username) {
|
||||
if (MinecraftServer.getServer() == null)
|
||||
return null;
|
||||
|
||||
return MinecraftServer.getServer().getConfigurationManager().getPlayerByUsername(username);
|
||||
}
|
||||
|
||||
public static UUID getUUIDFromPlayer(EntityPlayer player) {
|
||||
return player.getGameProfile().getId();
|
||||
}
|
||||
|
||||
public static boolean isFakePlayer(EntityPlayer player) {
|
||||
return player instanceof FakePlayer || FAKE_PLAYER_PATTERN.matcher(getUsernameFromPlayer(player)).matches();
|
||||
}
|
||||
|
||||
public static void causeNauseaToPlayer(ItemStack stack) {
|
||||
stack = NBTHolder.checkNBT(stack);
|
||||
|
||||
if (!Strings.isNullOrEmpty(stack.getTagCompound().getString(NBTHolder.NBT_OWNER)))
|
||||
causeNauseaToPlayer(stack.getTagCompound().getString(NBTHolder.NBT_OWNER));
|
||||
}
|
||||
|
||||
public static void causeNauseaToPlayer(String ownerName) {
|
||||
EntityPlayer player = getPlayerFromUsername(ownerName);
|
||||
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
player.addPotionEffect(new PotionEffect(Potion.confusion.id, 80));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,131 @@
|
|||
package WayofTime.bloodmagic.api.util.helper;
|
||||
|
||||
import WayofTime.bloodmagic.api.event.RitualEvent;
|
||||
import WayofTime.bloodmagic.api.registry.RitualRegistry;
|
||||
import WayofTime.bloodmagic.api.ritual.IMasterRitualStone;
|
||||
import WayofTime.bloodmagic.api.ritual.Ritual;
|
||||
import WayofTime.bloodmagic.api.ritual.imperfect.IImperfectRitualStone;
|
||||
import WayofTime.bloodmagic.api.ritual.imperfect.ImperfectRitual;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
import sun.misc.Launcher;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
||||
public class RitualHelper {
|
||||
|
||||
public static boolean canCrystalActivate(Ritual ritual, int crystalLevel) {
|
||||
return ritual.getCrystalLevel() <= crystalLevel && RitualRegistry.ritualEnabled(ritual);
|
||||
}
|
||||
|
||||
public static String getNextRitualKey(String currentKey) {
|
||||
int currentIndex = RitualRegistry.getIds().indexOf(currentKey);
|
||||
int nextIndex = RitualRegistry.getRituals().listIterator(currentIndex).nextIndex();
|
||||
|
||||
return RitualRegistry.getIds().get(nextIndex);
|
||||
}
|
||||
|
||||
public static String getPrevRitualKey(String currentKey) {
|
||||
int currentIndex = RitualRegistry.getIds().indexOf(currentKey);
|
||||
int previousIndex = RitualRegistry.getIds().listIterator(currentIndex).previousIndex();
|
||||
|
||||
return RitualRegistry.getIds().get(previousIndex);
|
||||
}
|
||||
|
||||
public static boolean activate(IMasterRitualStone masterRitualStone, Ritual ritual, EntityPlayer player) {
|
||||
String owner = masterRitualStone.getOwner();
|
||||
|
||||
RitualEvent.RitualActivatedEvent event = new RitualEvent.RitualActivatedEvent(masterRitualStone, owner, ritual, player, player.getHeldItem(), player.getHeldItem().getItemDamage());
|
||||
|
||||
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
|
||||
return false;
|
||||
|
||||
return RitualRegistry.ritualEnabled(ritual) && ritual.startRitual(masterRitualStone, player);
|
||||
}
|
||||
|
||||
public static void perform(IMasterRitualStone masterRitualStone, Ritual ritual) {
|
||||
String owner = masterRitualStone.getOwner();
|
||||
|
||||
RitualEvent.RitualRunEvent event = new RitualEvent.RitualRunEvent(masterRitualStone, owner, ritual);
|
||||
|
||||
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
|
||||
return;
|
||||
|
||||
if (RitualRegistry.ritualEnabled(ritual))
|
||||
ritual.performEffect(masterRitualStone);
|
||||
}
|
||||
|
||||
public static void stop(IMasterRitualStone masterRitualStone, Ritual ritual, Ritual.BreakType breakType) {
|
||||
String owner = masterRitualStone.getOwner();
|
||||
|
||||
RitualEvent.RitualStopEvent event = new RitualEvent.RitualStopEvent(masterRitualStone, owner, ritual, breakType);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
|
||||
ritual.onRitualBroken(masterRitualStone, breakType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds your Ritual to the {@link RitualRegistry#enabledRituals} Map.
|
||||
* This is used to determine whether your effect is enabled or not.
|
||||
*
|
||||
* The config option will be created as {@code B:ClassName=true} with a comment of
|
||||
* {@code Enables the ClassName ritual}.
|
||||
*
|
||||
* Should be safe to modify at any point.
|
||||
*
|
||||
* @param config - Your mod's Forge {@link Configuration} object.
|
||||
* @param packageName - The package your Rituals are located in.
|
||||
* @param category - The config category to write to.
|
||||
*/
|
||||
public static void checkRituals(Configuration config, String packageName, String category) {
|
||||
String name = packageName;
|
||||
if (!name.startsWith("/"))
|
||||
name = "/" + name;
|
||||
|
||||
name = name.replace('.', '/');
|
||||
URL url = Launcher.class.getResource(name);
|
||||
File directory = new File(url.getFile());
|
||||
|
||||
if (directory.exists()) {
|
||||
String[] files = directory.list();
|
||||
|
||||
for (String file : files) {
|
||||
if (file.endsWith(".class")) {
|
||||
String className = file.substring(0, file.length() - 6);
|
||||
|
||||
try {
|
||||
Object o = Class.forName(packageName + "." + className).newInstance();
|
||||
|
||||
if (o instanceof Ritual)
|
||||
RitualRegistry.enabledRituals.put((Ritual) o, config.get(category, className, true).getBoolean());
|
||||
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Imperfect {
|
||||
|
||||
public static boolean activate(IImperfectRitualStone imperfectRitualStone, ImperfectRitual imperfectRitual, EntityPlayer player) {
|
||||
String owner = imperfectRitualStone.getOwner();
|
||||
|
||||
RitualEvent.ImperfectRitualActivatedEvent event = new RitualEvent.ImperfectRitualActivatedEvent(imperfectRitualStone, owner, imperfectRitual);
|
||||
|
||||
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
|
||||
return false;
|
||||
|
||||
|
||||
return imperfectRitual.onActivate(imperfectRitualStone, player);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue