Attempt to fix 1.16.3 branch's issues on the repository
Added the original 'wayoftime' folder back, so see if that fixed the multiple folder issue.
This commit is contained in:
parent
6b4145a67c
commit
9fa68e86ae
224 changed files with 24047 additions and 0 deletions
79
src/main/java/wayoftime/bloodmagic/util/BMLog.java
Normal file
79
src/main/java/wayoftime/bloodmagic/util/BMLog.java
Normal file
|
@ -0,0 +1,79 @@
|
|||
package wayoftime.bloodmagic.util;
|
||||
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import wayoftime.bloodmagic.BloodMagic;
|
||||
|
||||
public enum BMLog
|
||||
{
|
||||
|
||||
DEFAULT(BloodMagic.MODID)
|
||||
{
|
||||
@Override
|
||||
boolean enabled()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
},
|
||||
DEBUG()
|
||||
{
|
||||
@Override
|
||||
boolean enabled()
|
||||
{
|
||||
return false;
|
||||
// return ConfigHandler.general.enableDebugLogging;
|
||||
}
|
||||
},
|
||||
API()
|
||||
{
|
||||
@Override
|
||||
boolean enabled()
|
||||
{
|
||||
return false;
|
||||
// return ConfigHandler.general.enableAPILogging;
|
||||
}
|
||||
},
|
||||
API_VERBOSE()
|
||||
{
|
||||
@Override
|
||||
boolean enabled()
|
||||
{
|
||||
return false;
|
||||
// return ConfigHandler.general.enableVerboseAPILogging;
|
||||
}
|
||||
},;
|
||||
|
||||
private final Logger logger;
|
||||
|
||||
BMLog(String logName)
|
||||
{
|
||||
logger = LogManager.getLogger(logName);
|
||||
}
|
||||
|
||||
BMLog()
|
||||
{
|
||||
logger = LogManager.getLogger(BloodMagic.MODID + "|" + WordUtils.capitalizeFully(name().replace("_", " ")));
|
||||
}
|
||||
|
||||
abstract boolean enabled();
|
||||
|
||||
public void info(String input, Object... args)
|
||||
{
|
||||
if (enabled())
|
||||
logger.info(input, args);
|
||||
}
|
||||
|
||||
public void error(String input, Object... args)
|
||||
{
|
||||
if (enabled())
|
||||
logger.error(input, args);
|
||||
}
|
||||
|
||||
public void warn(String input, Object... args)
|
||||
{
|
||||
if (enabled())
|
||||
logger.warn(input, args);
|
||||
}
|
||||
}
|
28
src/main/java/wayoftime/bloodmagic/util/BooleanResult.java
Normal file
28
src/main/java/wayoftime/bloodmagic/util/BooleanResult.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
package wayoftime.bloodmagic.util;
|
||||
|
||||
public class BooleanResult<T>
|
||||
{
|
||||
private final boolean result;
|
||||
private final T value;
|
||||
|
||||
private BooleanResult(boolean result, T value)
|
||||
{
|
||||
this.result = result;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public boolean isSuccess()
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
public T getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
public static <T> BooleanResult<T> newResult(boolean success, T value)
|
||||
{
|
||||
return new BooleanResult<>(success, value);
|
||||
}
|
||||
}
|
270
src/main/java/wayoftime/bloodmagic/util/ChatUtil.java
Normal file
270
src/main/java/wayoftime/bloodmagic/util/ChatUtil.java
Normal file
|
@ -0,0 +1,270 @@
|
|||
package wayoftime.bloodmagic.util;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.NewChatGui;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraftforge.fml.network.NetworkEvent.Context;
|
||||
import wayoftime.bloodmagic.BloodMagic;
|
||||
import wayoftime.bloodmagic.util.helper.TextHelper;
|
||||
|
||||
public class ChatUtil
|
||||
{
|
||||
private static final int DELETION_ID = 2525277;
|
||||
private static int lastAdded;
|
||||
public static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("###,###.##");
|
||||
|
||||
private static void sendNoSpamMessages(ITextComponent[] messages)
|
||||
{
|
||||
NewChatGui chat = Minecraft.getInstance().ingameGUI.getChatGUI();
|
||||
// Minecraft.getMinecraft().ingameGUI.getChatGUI();
|
||||
// for (int i = DELETION_ID + messages.length - 1; i <= lastAdded; i++)
|
||||
// {
|
||||
// chat.
|
||||
//// chat.deleteChatLine(i);
|
||||
// }
|
||||
for (int i = 0; i < messages.length; i++)
|
||||
{
|
||||
chat.printChatMessage(messages[i]);
|
||||
// chat.printChatMessageWithOptionalDeletion(messages[i], DELETION_ID + i);
|
||||
}
|
||||
lastAdded = DELETION_ID + messages.length - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a standard {@link TextComponentString} for the given {@link String} .
|
||||
*
|
||||
* @param s The string to wrap.
|
||||
* @return An {@link ITextComponent} containing the string.
|
||||
*/
|
||||
public static ITextComponent wrap(String s)
|
||||
{
|
||||
return new StringTextComponent(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #wrap(String)
|
||||
*/
|
||||
public static ITextComponent[] wrap(String... s)
|
||||
{
|
||||
ITextComponent[] ret = new ITextComponent[s.length];
|
||||
for (int i = 0; i < ret.length; i++)
|
||||
{
|
||||
ret[i] = wrap(s[i]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a translatable chat component for the given string and format args.
|
||||
*
|
||||
* @param s The string to format
|
||||
* @param args The args to apply to the format
|
||||
*/
|
||||
public static ITextComponent wrapFormatted(String s, Object... args)
|
||||
{
|
||||
return new TranslationTextComponent(s, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simply sends the passed lines to the player in a chat message.
|
||||
*
|
||||
* @param player The player to send the chat to
|
||||
* @param lines The lines to send
|
||||
*/
|
||||
public static void sendChat(PlayerEntity player, String... lines)
|
||||
{
|
||||
sendChat(player, wrap(lines));
|
||||
}
|
||||
|
||||
/**
|
||||
* Localizes the lines before sending them.
|
||||
*
|
||||
* @see #sendChat(EntityPlayer, String...)
|
||||
*/
|
||||
public static void sendChatUnloc(PlayerEntity player, String... unlocLines)
|
||||
{
|
||||
sendChat(player, TextHelper.localizeAll(unlocLines));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends all passed chat components to the player.
|
||||
*
|
||||
* @param player The player to send the chat lines to.
|
||||
* @param lines The {@link ITextComponent chat components} to send.yes
|
||||
*/
|
||||
public static void sendChat(PlayerEntity player, ITextComponent... lines)
|
||||
{
|
||||
for (ITextComponent c : lines)
|
||||
{
|
||||
// BloodMagic.packetHandler.send
|
||||
player.sendMessage(c, Util.DUMMY_UUID);
|
||||
// player.sendMessage(c);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Localizes the strings before sending them.
|
||||
*
|
||||
* @see #sendNoSpamClient(String...)
|
||||
*/
|
||||
public static void sendNoSpamClientUnloc(String... unlocLines)
|
||||
{
|
||||
sendNoSpamClient(TextHelper.localizeAll(unlocLines));
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as {@link #sendNoSpamClient(ITextComponent...)}, but wraps the Strings
|
||||
* automatically.
|
||||
*
|
||||
* @param lines The chat lines to send
|
||||
* @see #wrap(String)
|
||||
*/
|
||||
public static void sendNoSpamClient(String... lines)
|
||||
{
|
||||
sendNoSpamClient(wrap(lines));
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips the packet sending, unsafe to call on servers.
|
||||
*
|
||||
* @see #sendNoSpam(ServerPlayerEntity, ITextComponent...)
|
||||
*/
|
||||
public static void sendNoSpamClient(ITextComponent... lines)
|
||||
{
|
||||
sendNoSpamMessages(lines);
|
||||
}
|
||||
|
||||
/**
|
||||
* Localizes the strings before sending them.
|
||||
*
|
||||
* @see #sendNoSpam(EntityPlayer, String...)
|
||||
*/
|
||||
public static void sendNoSpamUnloc(PlayerEntity player, String... unlocLines)
|
||||
{
|
||||
sendNoSpam(player, TextHelper.localizeAll(unlocLines));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #wrap(String)
|
||||
* @see #sendNoSpam(EntityPlayer, ITextComponent...)
|
||||
*/
|
||||
public static void sendNoSpam(PlayerEntity player, String... lines)
|
||||
{
|
||||
sendNoSpam(player, wrap(lines));
|
||||
}
|
||||
|
||||
/**
|
||||
* First checks if the player is instanceof {@link ServerPlayerEntity} before
|
||||
* casting.
|
||||
*
|
||||
* @see #sendNoSpam(ServerPlayerEntity, ITextComponent...)
|
||||
*/
|
||||
public static void sendNoSpam(PlayerEntity player, ITextComponent... lines)
|
||||
{
|
||||
if (player instanceof ServerPlayerEntity)
|
||||
{
|
||||
sendNoSpam((ServerPlayerEntity) player, lines);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Localizes the strings before sending them.
|
||||
*
|
||||
* @see #sendNoSpam(ServerPlayerEntity, String...)
|
||||
*/
|
||||
public static void sendNoSpamUnloc(ServerPlayerEntity player, String... unlocLines)
|
||||
{
|
||||
sendNoSpam(player, TextHelper.localizeAll(unlocLines));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #wrap(String)
|
||||
* @see #sendNoSpam(ServerPlayerEntity, ITextComponent...)
|
||||
*/
|
||||
public static void sendNoSpam(ServerPlayerEntity player, String... lines)
|
||||
{
|
||||
sendNoSpam(player, wrap(lines));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a chat message to the client, deleting past messages also sent via this
|
||||
* method.
|
||||
* <p>
|
||||
* Credit to RWTema for the idea
|
||||
*
|
||||
* @param player The player to send the chat message to
|
||||
* @param lines The chat lines to send.
|
||||
*/
|
||||
public static void sendNoSpam(ServerPlayerEntity player, ITextComponent... lines)
|
||||
{
|
||||
if (lines.length > 0)
|
||||
BloodMagic.packetHandler.sendTo(new PacketNoSpamChat(lines), player);
|
||||
}
|
||||
|
||||
/**
|
||||
* @author tterrag1098
|
||||
* <p>
|
||||
* Ripped from EnderCore (and slightly altered)
|
||||
*/
|
||||
public static class PacketNoSpamChat
|
||||
{
|
||||
private ITextComponent[] chatLines;
|
||||
|
||||
public PacketNoSpamChat()
|
||||
{
|
||||
chatLines = new ITextComponent[0];
|
||||
}
|
||||
|
||||
private PacketNoSpamChat(ITextComponent... lines)
|
||||
{
|
||||
// this is guaranteed to be >1 length by accessing methods
|
||||
this.chatLines = lines;
|
||||
}
|
||||
|
||||
public static void encode(PacketNoSpamChat pkt, PacketBuffer buf)
|
||||
{
|
||||
buf.writeInt(pkt.chatLines.length);
|
||||
for (ITextComponent c : pkt.chatLines)
|
||||
{
|
||||
// ByteBufUtils.writeUTF8String(buf, ITextComponent.Serializer.componentToJson(c));
|
||||
buf.writeString(ITextComponent.Serializer.toJson(c));
|
||||
}
|
||||
}
|
||||
|
||||
public static PacketNoSpamChat decode(PacketBuffer buf)
|
||||
{
|
||||
PacketNoSpamChat pkt = new PacketNoSpamChat(new ITextComponent[buf.readInt()]);
|
||||
for (int i = 0; i < pkt.chatLines.length; i++)
|
||||
{
|
||||
// pkt.chatLines[i] = ITextComponent.Serializer.jsonToComponent(ByteBufUtils.readUTF8String(buf));
|
||||
pkt.chatLines[i] = ITextComponent.Serializer.getComponentFromJsonLenient(buf.readString());
|
||||
}
|
||||
return pkt;
|
||||
}
|
||||
|
||||
public static void handle(PacketNoSpamChat message, Supplier<Context> context)
|
||||
{
|
||||
context.get().enqueueWork(() -> sendNoSpamMessages(message.chatLines));
|
||||
context.get().setPacketHandled(true);
|
||||
}
|
||||
|
||||
// public static class Handler implements IMessageHandler<PacketNoSpamChat, IMessage>
|
||||
// {
|
||||
// @Override
|
||||
// public IMessage onMessage(final PacketNoSpamChat message, MessageContext ctx)
|
||||
// {
|
||||
// Minecraft.getMinecraft().addScheduledTask(() -> sendNoSpamMessages(message.chatLines));
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
180
src/main/java/wayoftime/bloodmagic/util/Constants.java
Normal file
180
src/main/java/wayoftime/bloodmagic/util/Constants.java
Normal file
|
@ -0,0 +1,180 @@
|
|||
package wayoftime.bloodmagic.util;
|
||||
|
||||
import wayoftime.bloodmagic.BloodMagic;
|
||||
|
||||
public class Constants
|
||||
{
|
||||
public static final String SPEED_RUNE = "speed_rune";
|
||||
|
||||
public static class NBT
|
||||
{
|
||||
public static final String OWNER_UUID = "ownerUUID";
|
||||
public static final String OWNER_NAME = "ownerNAME";
|
||||
public static final String USES = "uses";
|
||||
public static final String ACTIVATED = "activated";
|
||||
public static final String UNUSABLE = "unusable";
|
||||
public static final String SACRIFICE = "sacrifice";
|
||||
public static final String DIMENSION_ID = "dimensionId";
|
||||
public static final String X_COORD = "xCoord";
|
||||
public static final String Y_COORD = "yCoord";
|
||||
public static final String Z_COORD = "zCoord";
|
||||
public static final String PORTAL_LOCATION = "portalLocation";
|
||||
public static final String ORB_TIER = "orbTier";
|
||||
public static final String CURRENT_ESSENCE = "currentEssence";
|
||||
public static final String CURRENT_RITUAL = "currentRitual";
|
||||
public static final String CURRENT_RITUAL_TAG = "currentRitualTag";
|
||||
public static final String IS_RUNNING = "isRunning";
|
||||
public static final String IS_REDSTONED = "isStoned";
|
||||
public static final String RUNTIME = "runtime";
|
||||
public static final String DIRECTION = "direction";
|
||||
public static final String REAGENT_TANKS = "reagentTanks";
|
||||
public static final String CURRENT_INCENSE = "BM:CurrentIncense";
|
||||
public static final String MAX_INCENSE = "BM:MaxIncenseFromLastAltar";
|
||||
public static final String HAS_MAX_INCENSE = "BM:CurrentIsMaxIncense";
|
||||
public static final String CURRENT_PURITY = "BM:CurrentPurity";
|
||||
public static final String EMPTY = "Empty";
|
||||
public static final String OUTPUT_AMOUNT = "outputAmount";
|
||||
public static final String INPUT_AMOUNT = "inputAmount";
|
||||
public static final String STORED_LP = "storedLP";
|
||||
public static final String RITUAL_READER = "ritualReaderState";
|
||||
public static final String ITEMS = "Items";
|
||||
public static final String SLOT = "Slot";
|
||||
|
||||
public static final String ALTAR = "bloodAltar";
|
||||
public static final String ALTAR_TIER = "upgradeLevel";
|
||||
public static final String ALTAR_ACTIVE = "isActive";
|
||||
public static final String ALTAR_LIQUID_REQ = "liquidRequired";
|
||||
public static final String ALTAR_FILLABLE = "fillable";
|
||||
public static final String ALTAR_UPGRADED = "isUpgraded";
|
||||
public static final String ALTAR_CONSUMPTION_RATE = "consumptionRate";
|
||||
public static final String ALTAR_DRAIN_RATE = "drainRate";
|
||||
public static final String ALTAR_CONSUMPTION_MULTIPLIER = "consumptionMultiplier";
|
||||
public static final String ALTAR_EFFICIENCY_MULTIPLIER = "efficiencyMultiplier";
|
||||
public static final String ALTAR_SELF_SACRIFICE_MULTIPLIER = "selfSacrificeMultiplier";
|
||||
public static final String ALTAR_SACRIFICE_MULTIPLIER = "sacrificeMultiplier";
|
||||
public static final String ALTAR_CAPACITY_MULTIPLIER = "capacityMultiplier";
|
||||
public static final String ALTAR_ORB_CAPACITY_MULTIPLIER = "orbCapacityMultiplier";
|
||||
public static final String ALTAR_DISLOCATION_MULTIPLIER = "dislocationMultiplier";
|
||||
public static final String ALTAR_CAPACITY = "capacity";
|
||||
public static final String ALTAR_BUFFER_CAPACITY = "bufferCapacity";
|
||||
public static final String ALTAR_PROGRESS = "progress";
|
||||
public static final String ALTAR_IS_RESULT_BLOCK = "isResultBlock";
|
||||
public static final String ALTAR_LOCKDOWN_DURATION = "lockdownDuration";
|
||||
public static final String ALTAR_ACCELERATION_UPGRADES = "accelerationUpgrades";
|
||||
public static final String ALTAR_DEMON_BLOOD_DURATION = "demonBloodDuration";
|
||||
public static final String ALTAR_COOLDOWN_AFTER_CRAFTING = "cooldownAfterCrafting";
|
||||
public static final String ALTAR_TOTAL_CHARGE = "totalCharge";
|
||||
public static final String ALTAR_MAX_CHARGE = "maxCharge";
|
||||
public static final String ALTAR_CHARGE_RATE = "chargeRate";
|
||||
public static final String ALTAR_CHARGE_FREQUENCY = "chargeFrequency";
|
||||
public static final String ALTAR_CURRENT_TIER_DISPLAYED = "currentTierDisplayed";
|
||||
|
||||
public static final String ALTARMAKER_CURRENT_TIER = "currentTier";
|
||||
|
||||
public static final String PROJECTILE_TICKS_IN_AIR = "projectileTicksInAir";
|
||||
public static final String PROJECTILE_MAX_TICKS_IN_AIR = "projectileMaxTicksInAir";
|
||||
|
||||
public static final String TICKS_REMAINING = "ticksRemaining";
|
||||
public static final String CONTAINED_BLOCK_NAME = "containedBlockName";
|
||||
public static final String CONTAINED_BLOCK_META = "containedBlockMeta";
|
||||
public static final String CONTAINED_TILE_ENTITY = "containedTileEntity";
|
||||
|
||||
public static final String PREVIOUS_INPUT = "previousInput";
|
||||
|
||||
public static final String LIVING_ARMOUR = "livingArmour";
|
||||
|
||||
public static final String CHARGE_TIME = "chargeTime";
|
||||
public static final String HELD_DOWN = "heldDown";
|
||||
|
||||
public static final String UPGRADE_POISON_TIMER = "poisonTimer";
|
||||
public static final String UPGRADE_FIRE_TIMER = "fireTimer";
|
||||
|
||||
public static final String SOULS = "souls";
|
||||
public static final String SOUL_SWORD_DAMAGE = "soulSwordDamage";
|
||||
public static final String SOUL_SWORD_ACTIVE_DRAIN = "soulSwordActiveDrain";
|
||||
public static final String SOUL_SWORD_DROP = "soulSwordDrop";
|
||||
public static final String SOUL_SWORD_STATIC_DROP = "soulSwordStaticDrop";
|
||||
public static final String SOUL_SWORD_HEALTH = "soulSwordHealth";
|
||||
public static final String SOUL_SWORD_ATTACK_SPEED = "soulSwordAttackSpeed";
|
||||
public static final String SOUL_SWORD_SPEED = "soulSwordSpeed";
|
||||
public static final String SOUL_SWORD_DIG_SPEED = "soulSwordDigSpeed";
|
||||
public static final String WILL_TYPE = "demonWillType";
|
||||
|
||||
public static final String SOUL_FORGE_BURN = "burnTime";
|
||||
public static final String SOUL_FORGE_CONSUMED = "consumedSouls";
|
||||
|
||||
public static final String ARC_PROGRESS = "progress";
|
||||
|
||||
public static final String ROUTING_MASTER = "master";
|
||||
public static final String ROUTING_CONNECTION = "connections";
|
||||
public static final String ROUTING_PRIORITY = "prioritiesPeople";
|
||||
public static final String ROUTING_MASTER_GENERAL = "generalList";
|
||||
public static final String ROUTING_MASTER_INPUT = "inputList";
|
||||
public static final String ROUTING_MASTER_OUTPUT = "outputList";
|
||||
|
||||
public static final String GHOST_STACK_SIZE = "stackSize";
|
||||
|
||||
public static final String ITEM_INVENTORY = "itemInventory";
|
||||
|
||||
public static final String BLOCKPOS_CONNECTION = "connections";
|
||||
|
||||
public static final String CURRENT_SIGIL = "currentSigil";
|
||||
public static final String MOST_SIG = "mostSig";
|
||||
public static final String LEAST_SIG = "leastSig";
|
||||
public static final String COLOR = "color";
|
||||
|
||||
public static final String POTION_AUGMENT_LENGHT = "length:";
|
||||
public static final String POTION_AUGMENT_STRENGTH = "strength:";
|
||||
public static final String POTION_IMPURITY = "impurity";
|
||||
|
||||
public static final String TANK = "tank";
|
||||
|
||||
public static final String BREATH = "breath";
|
||||
}
|
||||
|
||||
public static class JSON
|
||||
{
|
||||
public static final String INPUT = "input";
|
||||
public static final String TOOL = "tool";
|
||||
public static final String BASEINPUT = "baseinput";
|
||||
public static final String ADDEDINPUT = "addedinput";
|
||||
public static final String ADDEDOUTPUT = "addedoutput";
|
||||
public static final String OUTPUT = "output";
|
||||
public static final String ITEM = "item";
|
||||
public static final String COUNT = "count";
|
||||
public static final String NBT = "nbt";
|
||||
public static final String TAG = "tag";
|
||||
public static final String TYPE = "type";
|
||||
public static final String TEXTURE = "texture";
|
||||
public static final String CONDITIONS = "conditions";
|
||||
public static final String CHANCE = "chance";
|
||||
public static final String FLUID = "fluid";
|
||||
public static final String AMOUNT = "amount";
|
||||
public static final String INPUT_FLUID = "inputfluid";
|
||||
public static final String OUTPUT_FLUID = "outputfluid";
|
||||
|
||||
public static final String ALTAR_TIER = Constants.NBT.ALTAR_TIER;
|
||||
public static final String ALTAR_SYPHON = "altarSyphon";
|
||||
public static final String ALTAR_CONSUMPTION_RATE = Constants.NBT.ALTAR_CONSUMPTION_RATE;
|
||||
public static final String ALTAR_DRAIN_RATE = Constants.NBT.ALTAR_DRAIN_RATE;
|
||||
|
||||
public static final String TARTARIC_DRAIN = "drain";
|
||||
public static final String TARTARIC_MINIMUM = "minimumDrain";
|
||||
}
|
||||
|
||||
public static class Compat
|
||||
{
|
||||
public static final String JEI_CATEGORY_ALTAR = "altar";
|
||||
public static final String JEI_CATEGORY_BINDING = "binding";
|
||||
public static final String JEI_CATEGORY_ALCHEMYARRAY = "alchemyarray";
|
||||
public static final String JEI_CATEGORY_SOULFORGE = "soulforge";
|
||||
public static final String JEI_CATEGORY_ALCHEMYTABLE = "alchemytable";
|
||||
public static final String JEI_CATEGORY_ARMOURDOWNGRADE = "armourdowngrade";
|
||||
|
||||
public static final String WAILA_CONFIG_ALTAR = BloodMagic.MODID + ".bloodaltar";
|
||||
public static final String WAILA_CONFIG_TELEPOSER = BloodMagic.MODID + ".teleposer";
|
||||
public static final String WAILA_CONFIG_RITUAL = BloodMagic.MODID + ".ritualController";
|
||||
public static final String WAILA_CONFIG_ARRAY = BloodMagic.MODID + ".array";
|
||||
public static final String WAILA_CONFIG_BLOOD_TANK = BloodMagic.MODID + ".bloodTank";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package wayoftime.bloodmagic.util;
|
||||
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
|
||||
public class DamageSourceBloodMagic extends DamageSource
|
||||
{
|
||||
public static final DamageSourceBloodMagic INSTANCE = new DamageSourceBloodMagic();
|
||||
|
||||
public DamageSourceBloodMagic()
|
||||
{
|
||||
super("bloodMagic");
|
||||
|
||||
setDamageBypassesArmor();
|
||||
setDamageIsAbsolute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDeathMessage(LivingEntity livingBase)
|
||||
{
|
||||
return new TranslationTextComponent("chat.bloodmagic.damageSource", livingBase.getName());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,295 @@
|
|||
package wayoftime.bloodmagic.util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
public class MultiSlotItemHandler implements IItemHandler
|
||||
{
|
||||
private ItemStack[] items;
|
||||
|
||||
private final int invLimit;
|
||||
|
||||
public MultiSlotItemHandler(int size, int invLimit)
|
||||
{
|
||||
items = new ItemStack[size];
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
items[i] = ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
this.invLimit = invLimit;
|
||||
}
|
||||
|
||||
public MultiSlotItemHandler(ItemStack[] items, int invLimit)
|
||||
{
|
||||
this.items = items;
|
||||
this.invLimit = invLimit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots()
|
||||
{
|
||||
return items.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot)
|
||||
{
|
||||
return items[slot];
|
||||
}
|
||||
|
||||
public boolean isItemValid(int slot, ItemStack stack)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setInventorySlotContents(int slot, ItemStack stack)
|
||||
{
|
||||
items[slot] = stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate)
|
||||
{
|
||||
if (stack.isEmpty())
|
||||
return ItemStack.EMPTY;
|
||||
|
||||
ItemStack stackInSlot = getStackInSlot(slot);
|
||||
|
||||
int m;
|
||||
if (!stackInSlot.isEmpty())
|
||||
{
|
||||
if (stackInSlot.getCount() >= Math.min(stackInSlot.getMaxStackSize(), getSlotLimit(slot)))
|
||||
return stack;
|
||||
|
||||
if (!ItemHandlerHelper.canItemStacksStack(stack, stackInSlot))
|
||||
return stack;
|
||||
|
||||
if (!isItemValid(slot, stack))
|
||||
return stack;
|
||||
|
||||
m = Math.min(stack.getMaxStackSize(), getSlotLimit(slot)) - stackInSlot.getCount();
|
||||
|
||||
if (stack.getCount() <= m)
|
||||
{
|
||||
if (!simulate)
|
||||
{
|
||||
ItemStack copy = stack.copy();
|
||||
copy.grow(stackInSlot.getCount());
|
||||
setInventorySlotContents(slot, copy);
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
} else
|
||||
{
|
||||
// copy the stack to not modify the original one
|
||||
stack = stack.copy();
|
||||
if (!simulate)
|
||||
{
|
||||
ItemStack copy = stack.split(m);
|
||||
copy.grow(stackInSlot.getCount());
|
||||
setInventorySlotContents(slot, copy);
|
||||
return stack;
|
||||
} else
|
||||
{
|
||||
stack.shrink(m);
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
if (!isItemValid(slot, stack))
|
||||
return stack;
|
||||
|
||||
m = Math.min(stack.getMaxStackSize(), getSlotLimit(slot));
|
||||
if (m < stack.getCount())
|
||||
{
|
||||
// copy the stack to not modify the original one
|
||||
stack = stack.copy();
|
||||
if (!simulate)
|
||||
{
|
||||
setInventorySlotContents(slot, stack.split(m));
|
||||
return stack;
|
||||
} else
|
||||
{
|
||||
stack.shrink(m);
|
||||
return stack;
|
||||
}
|
||||
} else
|
||||
{
|
||||
if (!simulate)
|
||||
{
|
||||
setInventorySlotContents(slot, stack);
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canTransferAllItemsToSlots(List<ItemStack> stackList, boolean simulate)
|
||||
{
|
||||
ItemStack[] copyList = new ItemStack[items.length];
|
||||
for (int i = 0; i < copyList.length; i++)
|
||||
{
|
||||
copyList[i] = items[i].copy();
|
||||
}
|
||||
|
||||
boolean hasStashedAll = true;
|
||||
|
||||
for (ItemStack stack : stackList)
|
||||
{
|
||||
if (stack.isEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
slots: for (int slot = 0; slot < copyList.length; slot++)
|
||||
{
|
||||
ItemStack stackInSlot = copyList[slot];
|
||||
|
||||
int m;
|
||||
if (!stackInSlot.isEmpty())
|
||||
{
|
||||
if (stackInSlot.getCount() >= Math.min(stackInSlot.getMaxStackSize(), getSlotLimit(slot)))
|
||||
continue;
|
||||
|
||||
if (!ItemHandlerHelper.canItemStacksStack(stack, stackInSlot))
|
||||
continue;
|
||||
|
||||
if (!isItemValid(slot, stack))
|
||||
continue;
|
||||
|
||||
m = Math.min(stack.getMaxStackSize(), getSlotLimit(slot)) - stackInSlot.getCount();
|
||||
|
||||
if (stack.getCount() <= m)
|
||||
{
|
||||
ItemStack copy = stack.copy();
|
||||
if (!simulate)
|
||||
{
|
||||
copy.grow(stackInSlot.getCount());
|
||||
copyList[slot] = copy;
|
||||
}
|
||||
stack = ItemStack.EMPTY;
|
||||
|
||||
break slots;
|
||||
} else
|
||||
{
|
||||
// copy the stack to not modify the original one
|
||||
stack = stack.copy();
|
||||
if (!simulate)
|
||||
{
|
||||
ItemStack copy = stack.split(m);
|
||||
copy.grow(stackInSlot.getCount());
|
||||
copyList[slot] = copy;
|
||||
} else
|
||||
{
|
||||
stack.shrink(m);
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
if (!isItemValid(slot, stack))
|
||||
continue;
|
||||
|
||||
m = Math.min(stack.getMaxStackSize(), getSlotLimit(slot));
|
||||
if (m < stack.getCount())
|
||||
{
|
||||
// copy the stack to not modify the original one
|
||||
stack = stack.copy();
|
||||
if (!simulate)
|
||||
{
|
||||
copyList[slot] = stack.split(m);
|
||||
} else
|
||||
{
|
||||
stack.shrink(m);
|
||||
}
|
||||
} else
|
||||
{
|
||||
if (!simulate)
|
||||
{
|
||||
copyList[slot] = stack;
|
||||
}
|
||||
|
||||
stack = ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!stack.isEmpty())
|
||||
{
|
||||
hasStashedAll = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!simulate)
|
||||
{
|
||||
items = copyList;
|
||||
}
|
||||
|
||||
return hasStashedAll;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate)
|
||||
{
|
||||
if (amount == 0)
|
||||
return ItemStack.EMPTY;
|
||||
|
||||
ItemStack stackInSlot = getStackInSlot(slot);
|
||||
|
||||
if (stackInSlot.isEmpty())
|
||||
return ItemStack.EMPTY;
|
||||
|
||||
if (simulate)
|
||||
{
|
||||
if (stackInSlot.getCount() < amount)
|
||||
{
|
||||
return stackInSlot.copy();
|
||||
} else
|
||||
{
|
||||
ItemStack copy = stackInSlot.copy();
|
||||
copy.setCount(amount);
|
||||
return copy;
|
||||
}
|
||||
} else
|
||||
{
|
||||
int m = Math.min(stackInSlot.getCount(), amount);
|
||||
|
||||
ItemStack decrStackSize = decrStackSize(slot, m);
|
||||
return decrStackSize;
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack decrStackSize(int slot, int amount)
|
||||
{
|
||||
if (!getStackInSlot(slot).isEmpty())
|
||||
{
|
||||
if (getStackInSlot(slot).getCount() <= amount)
|
||||
{
|
||||
ItemStack itemStack = getStackInSlot(slot);
|
||||
setInventorySlotContents(slot, ItemStack.EMPTY);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
ItemStack itemStack = getStackInSlot(slot).split(amount);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit(int slot)
|
||||
{
|
||||
return invLimit;
|
||||
}
|
||||
|
||||
}
|
448
src/main/java/wayoftime/bloodmagic/util/Utils.java
Normal file
448
src/main/java/wayoftime/bloodmagic/util/Utils.java
Normal file
|
@ -0,0 +1,448 @@
|
|||
package wayoftime.bloodmagic.util;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.FlowingFluidBlock;
|
||||
import net.minecraft.block.NetherPortalBlock;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.potion.Effects;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraft.util.SoundEvents;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.fluids.IFluidBlock;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import wayoftime.bloodmagic.tile.TileInventory;
|
||||
|
||||
public class Utils
|
||||
{
|
||||
/**
|
||||
* @param tile - The {@link TileInventory} to input the item to
|
||||
* @param player - The player to take the item from.
|
||||
* @return {@code true} if the ItemStack is inserted, {@code false} otherwise
|
||||
* @see #insertItemToTile(TileInventory, PlayerEntity, int)
|
||||
*/
|
||||
public static boolean insertItemToTile(TileInventory tile, PlayerEntity player)
|
||||
{
|
||||
return insertItemToTile(tile, player, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for inserting an ItemStack with a stacksize of 1 to a tile's inventory
|
||||
* at slot 0
|
||||
* <p/>
|
||||
* EG: Block Altar
|
||||
*
|
||||
* @param tile - The {@link TileInventory} to input the item to
|
||||
* @param player - The player to take the item from.
|
||||
* @param slot - The slot to attempt to insert to
|
||||
* @return {@code true} if the ItemStack is inserted, {@code false} otherwise
|
||||
*/
|
||||
public static boolean insertItemToTile(TileInventory tile, PlayerEntity player, int slot)
|
||||
{
|
||||
ItemStack slotStack = tile.getStackInSlot(slot);
|
||||
if (slotStack.isEmpty() && !player.getHeldItemMainhand().isEmpty())
|
||||
{
|
||||
ItemStack input = player.getHeldItemMainhand().copy();
|
||||
input.setCount(1);
|
||||
player.getHeldItemMainhand().shrink(1);
|
||||
tile.setInventorySlotContents(slot, input);
|
||||
return true;
|
||||
} else if (!slotStack.isEmpty() && player.getHeldItemMainhand().isEmpty())
|
||||
{
|
||||
ItemHandlerHelper.giveItemToPlayer(player, slotStack);
|
||||
tile.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String toFancyCasing(String input)
|
||||
{
|
||||
return String.valueOf(input.charAt(0)).toUpperCase(Locale.ENGLISH) + input.substring(1);
|
||||
}
|
||||
|
||||
public static boolean isImmuneToFireDamage(LivingEntity entity)
|
||||
{
|
||||
return entity.isImmuneToFire() || entity.isPotionActive(Effects.FIRE_RESISTANCE);
|
||||
}
|
||||
|
||||
public static boolean isBlockLiquid(BlockState state)
|
||||
{
|
||||
return (state instanceof IFluidBlock || state.getMaterial().isLiquid());
|
||||
}
|
||||
|
||||
public static boolean isFlowingLiquid(World world, BlockPos pos, BlockState state)
|
||||
{
|
||||
Block block = state.getBlock();
|
||||
return ((block instanceof IFluidBlock && Math.abs(((IFluidBlock) block).getFilledPercentage(world, pos)) == 1)
|
||||
|| (block instanceof FlowingFluidBlock
|
||||
&& !((FlowingFluidBlock) block).getFluidState(state).isSource()));
|
||||
}
|
||||
|
||||
public static boolean spawnStackAtBlock(World world, BlockPos pos, @Nullable Direction pushDirection, ItemStack stack)
|
||||
{
|
||||
BlockPos spawnPos = new BlockPos(pos);
|
||||
|
||||
double velX = 0;
|
||||
double velY = 0;
|
||||
double velZ = 0;
|
||||
double velocity = 0.15D;
|
||||
if (pushDirection != null)
|
||||
{
|
||||
spawnPos = spawnPos.offset(pushDirection);
|
||||
|
||||
switch (pushDirection)
|
||||
{
|
||||
case DOWN:
|
||||
{
|
||||
velY = -velocity;
|
||||
break;
|
||||
}
|
||||
case UP:
|
||||
{
|
||||
velY = velocity;
|
||||
break;
|
||||
}
|
||||
case NORTH:
|
||||
{
|
||||
velZ = -velocity;
|
||||
break;
|
||||
}
|
||||
case SOUTH:
|
||||
{
|
||||
velZ = velocity;
|
||||
break;
|
||||
}
|
||||
case WEST:
|
||||
{
|
||||
velX = -velocity;
|
||||
break;
|
||||
}
|
||||
case EAST:
|
||||
{
|
||||
velX = velocity;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double posX = spawnPos.getX() + 0.5;
|
||||
double posY = spawnPos.getY() + 0.5;
|
||||
double posZ = spawnPos.getZ() + 0.5;
|
||||
|
||||
ItemEntity entityItem = new ItemEntity(world, posX, posY, posZ, stack);
|
||||
entityItem.setMotion(velX, velY, velZ);
|
||||
|
||||
entityItem.setItem(stack);
|
||||
return world.addEntity(entityItem);
|
||||
}
|
||||
|
||||
public static boolean swapLocations(World initialWorld, BlockPos initialPos, World finalWorld, BlockPos finalPos)
|
||||
{
|
||||
return swapLocations(initialWorld, initialPos, finalWorld, finalPos, true);
|
||||
}
|
||||
|
||||
public static boolean swapLocations(World initialWorld, BlockPos initialPos, World finalWorld, BlockPos finalPos, boolean playSound)
|
||||
{
|
||||
TileEntity initialTile = initialWorld.getTileEntity(initialPos);
|
||||
TileEntity finalTile = finalWorld.getTileEntity(finalPos);
|
||||
CompoundNBT initialTag = new CompoundNBT();
|
||||
CompoundNBT finalTag = new CompoundNBT();
|
||||
if (initialTile != null)
|
||||
initialTile.write(initialTag);
|
||||
if (finalTile != null)
|
||||
finalTile.write(finalTag);
|
||||
|
||||
BlockState initialState = initialWorld.getBlockState(initialPos);
|
||||
BlockState finalState = finalWorld.getBlockState(finalPos);
|
||||
|
||||
if ((initialState.getBlock().equals(Blocks.AIR) && finalState.getBlock().equals(Blocks.AIR))
|
||||
|| initialState.getBlock() instanceof NetherPortalBlock
|
||||
|| finalState.getBlock() instanceof NetherPortalBlock)
|
||||
return false;
|
||||
|
||||
if (playSound)
|
||||
{
|
||||
initialWorld.playSound(initialPos.getX(), initialPos.getY(), initialPos.getZ(), SoundEvents.ENTITY_ENDERMAN_TELEPORT, SoundCategory.AMBIENT, 1.0F, 1.0F, false);
|
||||
finalWorld.playSound(finalPos.getX(), finalPos.getY(), finalPos.getZ(), SoundEvents.ENTITY_ENDERMAN_TELEPORT, SoundCategory.AMBIENT, 1.0F, 1.0F, false);
|
||||
}
|
||||
|
||||
// Finally, we get to do something! (CLEARING TILES)
|
||||
if (finalState.getBlock().hasTileEntity(finalState))
|
||||
finalWorld.removeTileEntity(finalPos);
|
||||
if (initialState.getBlock().hasTileEntity(initialState))
|
||||
initialWorld.removeTileEntity(initialPos);
|
||||
|
||||
// TILES CLEARED
|
||||
BlockState initialBlockState = initialWorld.getBlockState(initialPos);
|
||||
BlockState finalBlockState = finalWorld.getBlockState(finalPos);
|
||||
finalWorld.setBlockState(finalPos, initialBlockState, 3);
|
||||
|
||||
if (initialTile != null)
|
||||
{
|
||||
// TileEntity newTileInitial = TileEntity.create(finalWorld, initialTag);
|
||||
TileEntity newTileInitial = TileEntity.readTileEntity(finalBlockState, initialTag);
|
||||
|
||||
finalWorld.setTileEntity(finalPos, newTileInitial);
|
||||
// newTileInitial.setPos(finalPos);
|
||||
newTileInitial.setWorldAndPos(finalWorld, finalPos);
|
||||
}
|
||||
|
||||
initialWorld.setBlockState(initialPos, finalBlockState, 3);
|
||||
|
||||
if (finalTile != null)
|
||||
{
|
||||
// TileEntity newTileFinal = TileEntity.create(initialWorld, finalTag);
|
||||
TileEntity newTileFinal = TileEntity.readTileEntity(initialBlockState, finalTag);
|
||||
|
||||
initialWorld.setTileEntity(initialPos, newTileFinal);
|
||||
// newTileFinal.setPos(initialPos);
|
||||
newTileFinal.setWorldAndPos(initialWorld, initialPos);
|
||||
}
|
||||
|
||||
initialWorld.notifyNeighborsOfStateChange(initialPos, finalState.getBlock());
|
||||
finalWorld.notifyNeighborsOfStateChange(finalPos, initialState.getBlock());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static ItemStack insertStackIntoTile(ItemStack stack, TileEntity tile, Direction dir)
|
||||
{
|
||||
LazyOptional<IItemHandler> capability = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, dir);
|
||||
if (capability.isPresent())
|
||||
{
|
||||
IItemHandler handler = capability.resolve().get();
|
||||
|
||||
return insertStackIntoTile(stack, handler);
|
||||
} else if (tile instanceof IInventory)
|
||||
{
|
||||
return insertStackIntoInventory(stack, (IInventory) tile, dir);
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static ItemStack insertStackIntoTile(ItemStack stack, IItemHandler handler)
|
||||
{
|
||||
int numberOfSlots = handler.getSlots();
|
||||
|
||||
ItemStack copyStack = stack.copy();
|
||||
|
||||
for (int slot = 0; slot < numberOfSlots; slot++)
|
||||
{
|
||||
copyStack = handler.insertItem(slot, copyStack, false);
|
||||
if (copyStack.isEmpty())
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
return copyStack;
|
||||
}
|
||||
|
||||
public static int getNumberOfFreeSlots(TileEntity tile, Direction dir)
|
||||
{
|
||||
int slots = 0;
|
||||
|
||||
LazyOptional<IItemHandler> capability = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, dir);
|
||||
if (capability.isPresent())
|
||||
{
|
||||
IItemHandler handler = capability.resolve().get();
|
||||
|
||||
for (int i = 0; i < handler.getSlots(); i++)
|
||||
{
|
||||
if (handler.getStackInSlot(i).isEmpty())
|
||||
{
|
||||
slots++;
|
||||
}
|
||||
}
|
||||
} else if (tile instanceof IInventory)
|
||||
{
|
||||
for (int i = 0; i < ((IInventory) tile).getSizeInventory(); i++)
|
||||
{
|
||||
if (((IInventory) tile).getStackInSlot(i).isEmpty())
|
||||
{
|
||||
slots++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return slots;
|
||||
}
|
||||
|
||||
public static ItemStack insertStackIntoInventory(ItemStack stack, IInventory inventory, Direction dir)
|
||||
{
|
||||
if (stack.isEmpty())
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
boolean[] canBeInserted = new boolean[inventory.getSizeInventory()];
|
||||
|
||||
if (inventory instanceof ISidedInventory)
|
||||
{
|
||||
int[] array = ((ISidedInventory) inventory).getSlotsForFace(dir);
|
||||
for (int in : array)
|
||||
{
|
||||
canBeInserted[in] = inventory.isItemValidForSlot(in, stack)
|
||||
&& ((ISidedInventory) inventory).canInsertItem(in, stack, dir);
|
||||
}
|
||||
} else
|
||||
{
|
||||
for (int i = 0; i < canBeInserted.length; i++)
|
||||
{
|
||||
canBeInserted[i] = inventory.isItemValidForSlot(i, stack);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++)
|
||||
{
|
||||
if (!canBeInserted[i])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack[] combinedStacks = combineStacks(stack, inventory.getStackInSlot(i));
|
||||
stack = combinedStacks[0];
|
||||
inventory.setInventorySlotContents(i, combinedStacks[1]);
|
||||
|
||||
if (stack.isEmpty())
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static boolean canInsertStackFullyIntoInventory(ItemStack stack, IInventory inventory, Direction dir, boolean fillToLimit, int limit)
|
||||
{
|
||||
if (stack.isEmpty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int itemsLeft = stack.getCount();
|
||||
|
||||
boolean[] canBeInserted = new boolean[inventory.getSizeInventory()];
|
||||
|
||||
if (inventory instanceof ISidedInventory)
|
||||
{
|
||||
int[] array = ((ISidedInventory) inventory).getSlotsForFace(dir);
|
||||
for (int in : array)
|
||||
{
|
||||
canBeInserted[in] = inventory.isItemValidForSlot(in, stack)
|
||||
&& ((ISidedInventory) inventory).canInsertItem(in, stack, dir);
|
||||
}
|
||||
} else
|
||||
{
|
||||
for (int i = 0; i < canBeInserted.length; i++)
|
||||
{
|
||||
canBeInserted[i] = inventory.isItemValidForSlot(i, stack);
|
||||
}
|
||||
}
|
||||
|
||||
int numberMatching = 0;
|
||||
|
||||
if (fillToLimit)
|
||||
{
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++)
|
||||
{
|
||||
if (!canBeInserted[i])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack invStack = inventory.getStackInSlot(i);
|
||||
|
||||
if (!invStack.isEmpty() && ItemHandlerHelper.canItemStacksStack(stack, invStack))
|
||||
{
|
||||
numberMatching += invStack.getCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fillToLimit && limit < stack.getCount() + numberMatching)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++)
|
||||
{
|
||||
if (!canBeInserted[i])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack invStack = inventory.getStackInSlot(i);
|
||||
boolean canCombine = ItemHandlerHelper.canItemStacksStack(stack, invStack);
|
||||
if (canCombine)
|
||||
{
|
||||
if (invStack.isEmpty())
|
||||
{
|
||||
itemsLeft = 0;
|
||||
} else
|
||||
{
|
||||
itemsLeft -= (invStack.getMaxStackSize() - invStack.getCount());
|
||||
}
|
||||
}
|
||||
|
||||
if (itemsLeft <= 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stack1 Stack that is placed into a slot
|
||||
* @param stack2 Slot content that stack1 is placed into
|
||||
* @return Stacks after stacking
|
||||
*/
|
||||
public static ItemStack[] combineStacks(ItemStack stack1, ItemStack stack2)
|
||||
{
|
||||
ItemStack[] returned = new ItemStack[2];
|
||||
|
||||
if (ItemHandlerHelper.canItemStacksStack(stack1, stack2))
|
||||
{
|
||||
int transferedAmount = stack2.isEmpty() ? stack1.getCount()
|
||||
: Math.min(stack2.getMaxStackSize() - stack2.getCount(), stack1.getCount());
|
||||
if (transferedAmount > 0)
|
||||
{
|
||||
ItemStack copyStack = stack1.split(transferedAmount);
|
||||
if (stack2.isEmpty())
|
||||
{
|
||||
stack2 = copyStack;
|
||||
} else
|
||||
{
|
||||
stack2.grow(transferedAmount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
returned[0] = stack1;
|
||||
returned[1] = stack2;
|
||||
|
||||
return returned;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,479 @@
|
|||
package wayoftime.bloodmagic.util.handler.event;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.player.ClientPlayerEntity;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.renderer.ActiveRenderInfo;
|
||||
import net.minecraft.client.renderer.Atlases;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.texture.AtlasTexture;
|
||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.inventory.container.PlayerContainer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.util.text.IFormattableTextComponent;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.Style;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidTank;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import wayoftime.bloodmagic.BloodMagic;
|
||||
import wayoftime.bloodmagic.client.render.BloodMagicRenderer;
|
||||
import wayoftime.bloodmagic.client.render.BloodMagicRenderer.Model3D;
|
||||
import wayoftime.bloodmagic.client.render.RenderResizableCuboid;
|
||||
import wayoftime.bloodmagic.client.utils.BMRenderTypes;
|
||||
import wayoftime.bloodmagic.common.item.ItemRitualDiviner;
|
||||
import wayoftime.bloodmagic.ritual.Ritual;
|
||||
import wayoftime.bloodmagic.ritual.RitualComponent;
|
||||
import wayoftime.bloodmagic.tile.TileMasterRitualStone;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = BloodMagic.MODID, value = Dist.CLIENT)
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public class ClientHandler
|
||||
{
|
||||
public static final boolean SUPPRESS_ASSET_ERRORS = true;
|
||||
public static ResourceLocation ritualStoneBlank = BloodMagic.rl("block/ritualstone");;
|
||||
public static ResourceLocation ritualStoneWater = BloodMagic.rl("block/waterritualstone");;
|
||||
public static ResourceLocation ritualStoneFire = BloodMagic.rl("block/fireritualstone");;
|
||||
public static ResourceLocation ritualStoneEarth = BloodMagic.rl("block/earthritualstone");;
|
||||
public static ResourceLocation ritualStoneAir = BloodMagic.rl("block/airritualstone");;
|
||||
public static ResourceLocation ritualStoneDawn = BloodMagic.rl("block/dawnritualstone");;
|
||||
public static ResourceLocation ritualStoneDusk = BloodMagic.rl("block/duskritualstone");;
|
||||
public static TextureAtlasSprite blankBloodRune;
|
||||
public static TextureAtlasSprite stoneBrick;
|
||||
public static TextureAtlasSprite glowstone;
|
||||
// public static TextureAtlasSprite bloodStoneBrick;
|
||||
public static TextureAtlasSprite beacon;
|
||||
// public static TextureAtlasSprite crystalCluster;
|
||||
public static Minecraft minecraft = Minecraft.getInstance();
|
||||
private static TileMasterRitualStone mrsHoloTile;
|
||||
private static Ritual mrsHoloRitual;
|
||||
private static Direction mrsHoloDirection;
|
||||
private static boolean mrsHoloDisplay;
|
||||
|
||||
static HashMap<String, ResourceLocation> resourceMap = new HashMap<String, ResourceLocation>();
|
||||
|
||||
public static Minecraft mc()
|
||||
{
|
||||
return Minecraft.getInstance();
|
||||
}
|
||||
|
||||
public static void bindTexture(String path)
|
||||
{
|
||||
mc().getTextureManager().bindTexture(getResource(path));
|
||||
}
|
||||
|
||||
public static void bindAtlas()
|
||||
{
|
||||
mc().getTextureManager().bindTexture(PlayerContainer.LOCATION_BLOCKS_TEXTURE);
|
||||
}
|
||||
|
||||
public static ResourceLocation getResource(String path)
|
||||
{
|
||||
ResourceLocation rl = resourceMap.containsKey(path) ? resourceMap.get(path) : new ResourceLocation(path);
|
||||
if (!resourceMap.containsKey(path))
|
||||
resourceMap.put(path, rl);
|
||||
return rl;
|
||||
}
|
||||
|
||||
public static TextureAtlasSprite getSprite(ResourceLocation rl)
|
||||
{
|
||||
return mc().getModelManager().getAtlasTexture(PlayerContainer.LOCATION_BLOCKS_TEXTURE).getSprite(rl);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onTextureStitch(TextureStitchEvent.Pre event)
|
||||
{
|
||||
final String BLOCKS = "block/";
|
||||
|
||||
// ritualStoneBlank = Minecraft.getInstance().getAtlasSpriteGetter(AtlasTexture.LOCATION_BLOCKS_TEXTURE).apply(BloodMagic.rl(block//" + "blankrune"));
|
||||
//// ritualStoneBlank = forName(event.getMap(), "ritualstone", BLOCKS);
|
||||
// ritualStoneWater = forName(event.getMap(), "waterritualstone", BLOCKS);
|
||||
// ritualStoneFire = forName(event.getMap(), "fireritualstone", BLOCKS);
|
||||
// ritualStoneEarth = forName(event.getMap(), "earthritualstone", BLOCKS);
|
||||
// ritualStoneAir = forName(event.getMap(), "airritualstone", BLOCKS);
|
||||
// ritualStoneDawn = forName(event.getMap(), "lightritualstone", BLOCKS);
|
||||
// ritualStoneDusk = forName(event.getMap(), "duskritualstone", BLOCKS);
|
||||
|
||||
blankBloodRune = forName(event.getMap(), "blankrune", BLOCKS);
|
||||
stoneBrick = event.getMap().getSprite(new ResourceLocation("minecraft:block/stonebrick"));
|
||||
glowstone = event.getMap().getSprite(new ResourceLocation("minecraft:block/glowstone"));
|
||||
// bloodStoneBrick = forName(event.getMap(), "BloodStoneBrick", BLOCKS);
|
||||
beacon = event.getMap().getSprite(new ResourceLocation("minecraft:block/beacon"));
|
||||
// crystalCluster = forName(event.getMap(), "ShardCluster", BLOCKS);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void render(RenderWorldLastEvent event)
|
||||
{
|
||||
ClientPlayerEntity player = minecraft.player;
|
||||
World world = player.getEntityWorld();
|
||||
|
||||
if (mrsHoloTile != null)
|
||||
{
|
||||
if (world.getTileEntity(mrsHoloTile.getPos()) instanceof TileMasterRitualStone)
|
||||
{
|
||||
if (mrsHoloDisplay)
|
||||
{
|
||||
IRenderTypeBuffer.Impl buffers = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
|
||||
MatrixStack stack = event.getMatrixStack();
|
||||
renderRitualStones(stack, buffers, mrsHoloTile, event.getPartialTicks());
|
||||
RenderSystem.disableDepthTest();
|
||||
buffers.finish();
|
||||
} else
|
||||
ClientHandler.setRitualHoloToNull();
|
||||
} else
|
||||
{
|
||||
ClientHandler.setRitualHoloToNull();
|
||||
}
|
||||
}
|
||||
|
||||
if (minecraft.objectMouseOver == null || minecraft.objectMouseOver.getType() != RayTraceResult.Type.BLOCK)
|
||||
return;
|
||||
|
||||
TileEntity tileEntity = world.getTileEntity(((BlockRayTraceResult) minecraft.objectMouseOver).getPos());
|
||||
|
||||
if (tileEntity instanceof TileMasterRitualStone && !player.getHeldItemMainhand().isEmpty()
|
||||
&& player.getHeldItemMainhand().getItem() instanceof ItemRitualDiviner)
|
||||
{
|
||||
IRenderTypeBuffer.Impl buffers = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
|
||||
MatrixStack stack = event.getMatrixStack();
|
||||
renderRitualStones(stack, buffers, player, event.getPartialTicks());
|
||||
RenderSystem.disableDepthTest();
|
||||
buffers.finish();
|
||||
}
|
||||
}
|
||||
|
||||
private static TextureAtlasSprite forName(AtlasTexture textureMap, String name, String dir)
|
||||
{
|
||||
return textureMap.getSprite(new ResourceLocation(BloodMagic.MODID + dir + "/" + name));
|
||||
}
|
||||
|
||||
private static void renderRitualStones(MatrixStack stack, IRenderTypeBuffer renderer, ClientPlayerEntity player, float partialTicks)
|
||||
{
|
||||
ActiveRenderInfo activerenderinfo = Minecraft.getInstance().gameRenderer.getActiveRenderInfo();
|
||||
Vector3d eyePos = activerenderinfo.getProjectedView();
|
||||
IVertexBuilder buffer = renderer.getBuffer(Atlases.getTranslucentCullBlockType());
|
||||
World world = player.getEntityWorld();
|
||||
ItemRitualDiviner ritualDiviner = (ItemRitualDiviner) player.inventory.getCurrentItem().getItem();
|
||||
Direction direction = ritualDiviner.getDirection(player.inventory.getCurrentItem());
|
||||
Ritual ritual = BloodMagic.RITUAL_MANAGER.getRitual(ritualDiviner.getCurrentRitual(player.inventory.getCurrentItem()));
|
||||
|
||||
if (ritual == null)
|
||||
return;
|
||||
|
||||
BlockPos vec3, vX;
|
||||
vec3 = ((BlockRayTraceResult) minecraft.objectMouseOver).getPos();
|
||||
|
||||
List<RitualComponent> components = Lists.newArrayList();
|
||||
ritual.gatherComponents(components::add);
|
||||
for (RitualComponent ritualComponent : components)
|
||||
{
|
||||
stack.push();
|
||||
vX = vec3.add(ritualComponent.getOffset(direction));
|
||||
double minX = vX.getX() - eyePos.x;
|
||||
double minY = vX.getY() - eyePos.y;
|
||||
double minZ = vX.getZ() - eyePos.z;
|
||||
|
||||
stack.translate(minX, minY, minZ);
|
||||
|
||||
if (!world.getBlockState(vX).isOpaqueCube(world, vX))
|
||||
{
|
||||
ResourceLocation rl = null;
|
||||
|
||||
switch (ritualComponent.getRuneType())
|
||||
{
|
||||
case BLANK:
|
||||
rl = ritualStoneBlank;
|
||||
break;
|
||||
case WATER:
|
||||
rl = ritualStoneWater;
|
||||
break;
|
||||
case FIRE:
|
||||
rl = ritualStoneFire;
|
||||
break;
|
||||
case EARTH:
|
||||
rl = ritualStoneEarth;
|
||||
break;
|
||||
case AIR:
|
||||
rl = ritualStoneAir;
|
||||
break;
|
||||
case DAWN:
|
||||
rl = ritualStoneDawn;
|
||||
break;
|
||||
case DUSK:
|
||||
rl = ritualStoneDusk;
|
||||
break;
|
||||
}
|
||||
|
||||
Model3D model = getBlockModel(rl);
|
||||
|
||||
RenderResizableCuboid.INSTANCE.renderCube(model, stack, buffer, 0xDDFFFFFF, 0x00F000F0, OverlayTexture.NO_OVERLAY);
|
||||
}
|
||||
stack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
public static void renderRitualStones(MatrixStack stack, IRenderTypeBuffer renderer, TileMasterRitualStone masterRitualStone, float partialTicks)
|
||||
{
|
||||
ActiveRenderInfo activerenderinfo = Minecraft.getInstance().gameRenderer.getActiveRenderInfo();
|
||||
Vector3d eyePos = activerenderinfo.getProjectedView();
|
||||
IVertexBuilder buffer = renderer.getBuffer(Atlases.getTranslucentCullBlockType());
|
||||
ClientPlayerEntity player = minecraft.player;
|
||||
World world = player.getEntityWorld();
|
||||
Direction direction = mrsHoloDirection;
|
||||
Ritual ritual = mrsHoloRitual;
|
||||
|
||||
if (ritual == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BlockPos vec3, vX;
|
||||
vec3 = masterRitualStone.getPos();
|
||||
|
||||
List<RitualComponent> components = Lists.newArrayList();
|
||||
ritual.gatherComponents(components::add);
|
||||
for (RitualComponent ritualComponent : components)
|
||||
{
|
||||
stack.push();
|
||||
vX = vec3.add(ritualComponent.getOffset(direction));
|
||||
|
||||
double minX = vX.getX() - eyePos.x;
|
||||
double minY = vX.getY() - eyePos.y;
|
||||
double minZ = vX.getZ() - eyePos.z;
|
||||
|
||||
stack.translate(minX, minY, minZ);
|
||||
|
||||
if (!world.getBlockState(vX).isOpaqueCube(world, vX))
|
||||
{
|
||||
ResourceLocation rl = null;
|
||||
|
||||
switch (ritualComponent.getRuneType())
|
||||
{
|
||||
case BLANK:
|
||||
rl = ritualStoneBlank;
|
||||
break;
|
||||
case WATER:
|
||||
rl = ritualStoneWater;
|
||||
break;
|
||||
case FIRE:
|
||||
rl = ritualStoneFire;
|
||||
break;
|
||||
case EARTH:
|
||||
rl = ritualStoneEarth;
|
||||
break;
|
||||
case AIR:
|
||||
rl = ritualStoneAir;
|
||||
break;
|
||||
case DAWN:
|
||||
rl = ritualStoneDawn;
|
||||
break;
|
||||
case DUSK:
|
||||
rl = ritualStoneDusk;
|
||||
break;
|
||||
}
|
||||
|
||||
Model3D model = getBlockModel(rl);
|
||||
|
||||
RenderResizableCuboid.INSTANCE.renderCube(model, stack, buffer, 0xDDFFFFFF, 0x00F000F0, OverlayTexture.NO_OVERLAY);
|
||||
|
||||
// RenderFakeBlocks.drawFakeBlock(texture, minX, minY, minZ);
|
||||
}
|
||||
|
||||
stack.pop();
|
||||
}
|
||||
|
||||
// GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
private static Model3D getBlockModel(ResourceLocation rl)
|
||||
{
|
||||
Model3D model = new BloodMagicRenderer.Model3D();
|
||||
model.setTexture(Minecraft.getInstance().getAtlasSpriteGetter(AtlasTexture.LOCATION_BLOCKS_TEXTURE).apply(rl));
|
||||
model.minX = 0;
|
||||
model.minY = 0;
|
||||
model.minZ = 0;
|
||||
model.maxX = 1;
|
||||
model.maxY = 1;
|
||||
model.maxZ = 1;
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
public static void setRitualHolo(TileMasterRitualStone masterRitualStone, Ritual ritual, Direction direction, boolean displayed)
|
||||
{
|
||||
mrsHoloDisplay = displayed;
|
||||
mrsHoloTile = masterRitualStone;
|
||||
mrsHoloRitual = ritual;
|
||||
mrsHoloDirection = direction;
|
||||
}
|
||||
|
||||
public static void setRitualHoloToNull()
|
||||
{
|
||||
mrsHoloDisplay = false;
|
||||
mrsHoloTile = null;
|
||||
mrsHoloRitual = null;
|
||||
mrsHoloDirection = Direction.NORTH;
|
||||
}
|
||||
|
||||
public static void handleGuiTank(MatrixStack transform, IFluidTank tank, int x, int y, int w, int h, int oX, int oY, int oW, int oH, int mX, int mY, String originalTexture, List<ITextComponent> tooltip)
|
||||
{
|
||||
handleGuiTank(transform, tank.getFluid(), tank.getCapacity(), x, y, w, h, oX, oY, oW, oH, mX, mY, originalTexture, tooltip);
|
||||
}
|
||||
|
||||
public static void handleGuiTank(MatrixStack transform, FluidStack fluid, int capacity, int x, int y, int w, int h, int oX, int oY, int oW, int oH, int mX, int mY, String originalTexture, List<ITextComponent> tooltip)
|
||||
{
|
||||
if (tooltip == null)
|
||||
{
|
||||
transform.push();
|
||||
IRenderTypeBuffer.Impl buffer = IRenderTypeBuffer.getImpl(Tessellator.getInstance().getBuffer());
|
||||
if (fluid != null && fluid.getFluid() != null)
|
||||
{
|
||||
int fluidHeight = (int) (h * (fluid.getAmount() / (float) capacity));
|
||||
drawRepeatedFluidSpriteGui(buffer, transform, fluid, x, y + h - fluidHeight, w, fluidHeight);
|
||||
RenderSystem.color3f(1, 1, 1);
|
||||
}
|
||||
int xOff = (w - oW) / 2;
|
||||
int yOff = (h - oH) / 2;
|
||||
RenderType renderType = BMRenderTypes.getGui(new ResourceLocation(originalTexture));
|
||||
drawTexturedRect(buffer.getBuffer(renderType), transform, x + xOff, y + yOff, oW, oH, 256f, oX, oX
|
||||
+ oW, oY, oY + oH);
|
||||
buffer.finish(renderType);
|
||||
transform.pop();
|
||||
} else
|
||||
{
|
||||
if (mX >= x && mX < x + w && mY >= y && mY < y + h)
|
||||
addFluidTooltip(fluid, tooltip, capacity);
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawRepeatedFluidSpriteGui(IRenderTypeBuffer buffer, MatrixStack transform, FluidStack fluid, float x, float y, float w, float h)
|
||||
{
|
||||
RenderType renderType = BMRenderTypes.getGui(PlayerContainer.LOCATION_BLOCKS_TEXTURE);
|
||||
IVertexBuilder builder = buffer.getBuffer(renderType);
|
||||
drawRepeatedFluidSprite(builder, transform, fluid, x, y, w, h);
|
||||
}
|
||||
|
||||
public static void drawRepeatedFluidSprite(IVertexBuilder builder, MatrixStack transform, FluidStack fluid, float x, float y, float w, float h)
|
||||
{
|
||||
TextureAtlasSprite sprite = getSprite(fluid.getFluid().getAttributes().getStillTexture(fluid));
|
||||
int col = fluid.getFluid().getAttributes().getColor(fluid);
|
||||
int iW = sprite.getWidth();
|
||||
int iH = sprite.getHeight();
|
||||
if (iW > 0 && iH > 0)
|
||||
drawRepeatedSprite(builder, transform, x, y, w, h, iW, iH, sprite.getMinU(), sprite.getMaxU(), sprite.getMinV(), sprite.getMaxV(), (col >> 16
|
||||
& 255) / 255.0f, (col >> 8 & 255) / 255.0f, (col & 255) / 255.0f, 1);
|
||||
}
|
||||
|
||||
public static void drawRepeatedSprite(IVertexBuilder builder, MatrixStack transform, float x, float y, float w, float h, int iconWidth, int iconHeight, float uMin, float uMax, float vMin, float vMax, float r, float g, float b, float alpha)
|
||||
{
|
||||
int iterMaxW = (int) (w / iconWidth);
|
||||
int iterMaxH = (int) (h / iconHeight);
|
||||
float leftoverW = w % iconWidth;
|
||||
float leftoverH = h % iconHeight;
|
||||
float leftoverWf = leftoverW / (float) iconWidth;
|
||||
float leftoverHf = leftoverH / (float) iconHeight;
|
||||
float iconUDif = uMax - uMin;
|
||||
float iconVDif = vMax - vMin;
|
||||
for (int ww = 0; ww < iterMaxW; ww++)
|
||||
{
|
||||
for (int hh = 0; hh < iterMaxH; hh++) drawTexturedRect(builder, transform, x + ww * iconWidth, y
|
||||
+ hh * iconHeight, iconWidth, iconHeight, r, g, b, alpha, uMin, uMax, vMin, vMax);
|
||||
drawTexturedRect(builder, transform, x + ww * iconWidth, y
|
||||
+ iterMaxH * iconHeight, iconWidth, leftoverH, r, g, b, alpha, uMin, uMax, vMin, (vMin
|
||||
+ iconVDif * leftoverHf));
|
||||
}
|
||||
if (leftoverW > 0)
|
||||
{
|
||||
for (int hh = 0; hh < iterMaxH; hh++) drawTexturedRect(builder, transform, x + iterMaxW * iconWidth, y
|
||||
+ hh * iconHeight, leftoverW, iconHeight, r, g, b, alpha, uMin, (uMin
|
||||
+ iconUDif * leftoverWf), vMin, vMax);
|
||||
drawTexturedRect(builder, transform, x + iterMaxW * iconWidth, y
|
||||
+ iterMaxH * iconHeight, leftoverW, leftoverH, r, g, b, alpha, uMin, (uMin
|
||||
+ iconUDif * leftoverWf), vMin, (vMin + iconVDif * leftoverHf));
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawTexturedRect(IVertexBuilder builder, MatrixStack transform, float x, float y, float w, float h, float r, float g, float b, float alpha, float u0, float u1, float v0, float v1)
|
||||
{
|
||||
Matrix4f mat = transform.getLast().getMatrix();
|
||||
builder.pos(mat, x, y
|
||||
+ h, 0).color(r, g, b, alpha).tex(u0, v1).overlay(OverlayTexture.NO_OVERLAY).lightmap(0xf000f0).normal(1, 1, 1).endVertex();
|
||||
builder.pos(mat, x + w, y
|
||||
+ h, 0).color(r, g, b, alpha).tex(u1, v1).overlay(OverlayTexture.NO_OVERLAY).lightmap(15728880).normal(1, 1, 1).endVertex();
|
||||
builder.pos(mat, x
|
||||
+ w, y, 0).color(r, g, b, alpha).tex(u1, v0).overlay(OverlayTexture.NO_OVERLAY).lightmap(15728880).normal(1, 1, 1).endVertex();
|
||||
builder.pos(mat, x, y, 0).color(r, g, b, alpha).tex(u0, v0).overlay(OverlayTexture.NO_OVERLAY).lightmap(15728880).normal(1, 1, 1).endVertex();
|
||||
}
|
||||
|
||||
public static void drawTexturedRect(IVertexBuilder builder, MatrixStack transform, int x, int y, int w, int h, float picSize, int u0, int u1, int v0, int v1)
|
||||
{
|
||||
drawTexturedRect(builder, transform, x, y, w, h, 1, 1, 1, 1, u0 / picSize, u1 / picSize, v0 / picSize, v1
|
||||
/ picSize);
|
||||
}
|
||||
|
||||
public static void addFluidTooltip(FluidStack fluid, List<ITextComponent> tooltip, int tankCapacity)
|
||||
{
|
||||
if (!fluid.isEmpty())
|
||||
tooltip.add(applyFormat(fluid.getDisplayName(), fluid.getFluid().getAttributes().getRarity(fluid).color));
|
||||
else
|
||||
tooltip.add(new TranslationTextComponent("gui.bloodmagic.empty"));
|
||||
// if (fluid.getFluid() instanceof IEFluid)
|
||||
// ((IEFluid) fluid.getFluid()).addTooltipInfo(fluid, null, tooltip);
|
||||
|
||||
if (mc().gameSettings.advancedItemTooltips && !fluid.isEmpty())
|
||||
{
|
||||
if (!Screen.hasShiftDown())
|
||||
tooltip.add(new TranslationTextComponent("tooltip.bloodmagic.holdShiftForInfo"));
|
||||
else
|
||||
{
|
||||
// TODO translation keys
|
||||
tooltip.add(applyFormat(new StringTextComponent("Fluid Registry: " + fluid.getFluid().getRegistryName()), TextFormatting.DARK_GRAY));
|
||||
tooltip.add(applyFormat(new StringTextComponent("Density: " + fluid.getFluid().getAttributes().getDensity(fluid)), TextFormatting.DARK_GRAY));
|
||||
tooltip.add(applyFormat(new StringTextComponent("Temperature: " + fluid.getFluid().getAttributes().getTemperature(fluid)), TextFormatting.DARK_GRAY));
|
||||
tooltip.add(applyFormat(new StringTextComponent("Viscosity: " + fluid.getFluid().getAttributes().getViscosity(fluid)), TextFormatting.DARK_GRAY));
|
||||
tooltip.add(applyFormat(new StringTextComponent("NBT Data: " + fluid.getTag()), TextFormatting.DARK_GRAY));
|
||||
}
|
||||
}
|
||||
|
||||
if (tankCapacity > 0)
|
||||
tooltip.add(applyFormat(new StringTextComponent(fluid.getAmount() + "/" + tankCapacity + "mB"), TextFormatting.GRAY));
|
||||
else
|
||||
tooltip.add(applyFormat(new StringTextComponent(fluid.getAmount() + "mB"), TextFormatting.GRAY));
|
||||
}
|
||||
|
||||
public static IFormattableTextComponent applyFormat(ITextComponent component, TextFormatting... color)
|
||||
{
|
||||
Style style = component.getStyle();
|
||||
for (TextFormatting format : color) style = style.applyFormatting(format);
|
||||
return component.deepCopy().setStyle(style);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package wayoftime.bloodmagic.util.handler.event;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import wayoftime.bloodmagic.BloodMagic;
|
||||
import wayoftime.bloodmagic.core.data.Binding;
|
||||
import wayoftime.bloodmagic.core.data.SoulNetwork;
|
||||
import wayoftime.bloodmagic.event.ItemBindEvent;
|
||||
import wayoftime.bloodmagic.iface.IBindable;
|
||||
import wayoftime.bloodmagic.orb.BloodOrb;
|
||||
import wayoftime.bloodmagic.orb.IBloodOrb;
|
||||
import wayoftime.bloodmagic.util.helper.BindableHelper;
|
||||
import wayoftime.bloodmagic.util.helper.NetworkHelper;
|
||||
import wayoftime.bloodmagic.util.helper.PlayerHelper;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = BloodMagic.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public class GenericHandler
|
||||
{
|
||||
// Handles binding of IBindable's as well as setting a player's highest orb tier
|
||||
@SubscribeEvent
|
||||
public void onInteract(PlayerInteractEvent.RightClickItem event)
|
||||
{
|
||||
if (event.getWorld().isRemote)
|
||||
return;
|
||||
|
||||
PlayerEntity player = event.getPlayer();
|
||||
|
||||
if (PlayerHelper.isFakePlayer(player))
|
||||
return;
|
||||
|
||||
ItemStack held = event.getItemStack();
|
||||
if (!held.isEmpty() && held.getItem() instanceof IBindable)
|
||||
{ // Make sure it's bindable
|
||||
IBindable bindable = (IBindable) held.getItem();
|
||||
Binding binding = bindable.getBinding(held);
|
||||
if (binding == null)
|
||||
{ // If the binding is null, let's create one
|
||||
if (bindable.onBind(player, held))
|
||||
{
|
||||
ItemBindEvent toPost = new ItemBindEvent(player, held);
|
||||
if (MinecraftForge.EVENT_BUS.post(toPost)) // Allow cancellation of binding
|
||||
return;
|
||||
|
||||
BindableHelper.applyBinding(held, player); // Bind item to the player
|
||||
}
|
||||
// If the binding exists, we'll check if the player's name has changed since
|
||||
// they last used it and update that if so.
|
||||
} else if (binding.getOwnerId().equals(player.getGameProfile().getId())
|
||||
&& !binding.getOwnerName().equals(player.getGameProfile().getName()))
|
||||
{
|
||||
binding.setOwnerName(player.getGameProfile().getName());
|
||||
BindableHelper.applyBinding(held, binding);
|
||||
}
|
||||
}
|
||||
|
||||
if (!held.isEmpty() && held.getItem() instanceof IBloodOrb)
|
||||
{
|
||||
IBloodOrb bloodOrb = (IBloodOrb) held.getItem();
|
||||
SoulNetwork network = NetworkHelper.getSoulNetwork(player);
|
||||
|
||||
BloodOrb orb = bloodOrb.getOrb(held);
|
||||
if (orb == null)
|
||||
return;
|
||||
|
||||
if (orb.getTier() > network.getOrbTier())
|
||||
network.setOrbTier(orb.getTier());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,115 @@
|
|||
package wayoftime.bloodmagic.util.handler.event;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.MobEntity;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.potion.EffectInstance;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.world.Difficulty;
|
||||
import net.minecraftforge.event.entity.living.LivingDropsEvent;
|
||||
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import wayoftime.bloodmagic.BloodMagic;
|
||||
import wayoftime.bloodmagic.common.item.BloodMagicItems;
|
||||
import wayoftime.bloodmagic.potion.BloodMagicPotions;
|
||||
import wayoftime.bloodmagic.will.EnumDemonWillType;
|
||||
import wayoftime.bloodmagic.will.IDemonWill;
|
||||
import wayoftime.bloodmagic.will.IDemonWillWeapon;
|
||||
import wayoftime.bloodmagic.will.PlayerDemonWillHandler;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = BloodMagic.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public class WillHandler
|
||||
{
|
||||
private static final HashMap<Integer, Integer> SERVER_TICKS = new HashMap<>();
|
||||
|
||||
// Adds Will to player
|
||||
@SubscribeEvent
|
||||
public void onItemPickup(EntityItemPickupEvent event)
|
||||
{
|
||||
ItemStack stack = event.getItem().getItem();
|
||||
if (stack.getItem() instanceof IDemonWill)
|
||||
{
|
||||
PlayerEntity player = event.getPlayer();
|
||||
EnumDemonWillType pickupType = ((IDemonWill) stack.getItem()).getType(stack);
|
||||
ItemStack remainder = PlayerDemonWillHandler.addDemonWill(player, stack);
|
||||
|
||||
if (remainder == null || ((IDemonWill) stack.getItem()).getWill(pickupType, stack) < 0.0001
|
||||
|| PlayerDemonWillHandler.isDemonWillFull(pickupType, player))
|
||||
{
|
||||
stack.setCount(0);
|
||||
event.setResult(Event.Result.ALLOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @SubscribeEvent
|
||||
// public static void onEntityAttacked(LivingDeathEvent event)
|
||||
// {
|
||||
// if (event.getSource() instanceof EntityDamageSourceIndirect)
|
||||
// {
|
||||
// Entity sourceEntity = event.getSource().getImmediateSource();
|
||||
//
|
||||
// if (sourceEntity instanceof EntitySentientArrow)
|
||||
// {
|
||||
// ((EntitySentientArrow) sourceEntity).reimbursePlayer(event.getEntityLiving(), event.getEntityLiving().getMaxHealth());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// Add/Drop Demon Will for Player
|
||||
@SubscribeEvent
|
||||
public void onLivingDrops(LivingDropsEvent event)
|
||||
{
|
||||
LivingEntity attackedEntity = event.getEntityLiving();
|
||||
DamageSource source = event.getSource();
|
||||
Entity entity = source.getTrueSource();
|
||||
|
||||
if (attackedEntity.isPotionActive(BloodMagicPotions.SOUL_SNARE) && (attackedEntity instanceof MobEntity
|
||||
|| attackedEntity.getEntityWorld().getDifficulty() == Difficulty.PEACEFUL))
|
||||
{
|
||||
EffectInstance eff = attackedEntity.getActivePotionEffect(BloodMagicPotions.SOUL_SNARE);
|
||||
int lvl = eff.getAmplifier();
|
||||
|
||||
double amountOfSouls = attackedEntity.getEntityWorld().rand.nextDouble() * (lvl + 1) * (lvl + 1) * 4 + 1;
|
||||
ItemStack soulStack = ((IDemonWill) BloodMagicItems.MONSTER_SOUL_RAW.get()).createWill(amountOfSouls);
|
||||
event.getDrops().add(new ItemEntity(attackedEntity.getEntityWorld(), attackedEntity.getPosX(), attackedEntity.getPosY(), attackedEntity.getPosZ(), soulStack));
|
||||
}
|
||||
|
||||
if (entity != null && entity instanceof PlayerEntity)
|
||||
{
|
||||
PlayerEntity player = (PlayerEntity) entity;
|
||||
ItemStack heldStack = player.getHeldItemMainhand();
|
||||
if (heldStack.getItem() instanceof IDemonWillWeapon && !player.getEntityWorld().isRemote)
|
||||
{
|
||||
IDemonWillWeapon demonWillWeapon = (IDemonWillWeapon) heldStack.getItem();
|
||||
List<ItemStack> droppedSouls = demonWillWeapon.getRandomDemonWillDrop(attackedEntity, player, heldStack, event.getLootingLevel());
|
||||
if (!droppedSouls.isEmpty())
|
||||
{
|
||||
ItemStack remainder;
|
||||
for (ItemStack willStack : droppedSouls)
|
||||
{
|
||||
remainder = PlayerDemonWillHandler.addDemonWill(player, willStack);
|
||||
|
||||
if (!remainder.isEmpty())
|
||||
{
|
||||
EnumDemonWillType pickupType = ((IDemonWill) remainder.getItem()).getType(remainder);
|
||||
if (((IDemonWill) remainder.getItem()).getWill(pickupType, remainder) >= 0.0001)
|
||||
{
|
||||
event.getDrops().add(new ItemEntity(attackedEntity.getEntityWorld(), attackedEntity.getPosX(), attackedEntity.getPosY(), attackedEntity.getPosZ(), remainder));
|
||||
}
|
||||
}
|
||||
}
|
||||
player.container.detectAndSendChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package wayoftime.bloodmagic.util.helper;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import wayoftime.bloodmagic.core.data.Binding;
|
||||
import wayoftime.bloodmagic.event.ItemBindEvent;
|
||||
import wayoftime.bloodmagic.util.Constants;
|
||||
|
||||
public class BindableHelper
|
||||
{
|
||||
|
||||
public static void applyBinding(ItemStack stack, PlayerEntity player)
|
||||
{
|
||||
Binding binding = new Binding(player.getGameProfile().getId(), player.getGameProfile().getName());
|
||||
applyBinding(stack, binding);
|
||||
}
|
||||
|
||||
public static void applyBinding(ItemStack stack, Binding binding)
|
||||
{
|
||||
if (!stack.hasTag())
|
||||
stack.setTag(new CompoundNBT());
|
||||
|
||||
stack.getTag().put("binding", binding.serializeNBT());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Owner Name 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 setItemOwnerName(ItemStack stack, String ownerName)
|
||||
{
|
||||
stack = NBTHelper.checkNBT(stack);
|
||||
|
||||
stack.getTag().putString(Constants.NBT.OWNER_NAME, ownerName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Owner UUID of the item without checking if it is already bound. Also
|
||||
* bypasses {@link ItemBindEvent}.
|
||||
*
|
||||
* @param stack - The ItemStack to bind
|
||||
* @param ownerUUID - The UUID to bind the ItemStack to
|
||||
*/
|
||||
public static void setItemOwnerUUID(ItemStack stack, String ownerUUID)
|
||||
{
|
||||
stack = NBTHelper.checkNBT(stack);
|
||||
|
||||
stack.getTag().putString(Constants.NBT.OWNER_UUID, ownerUUID);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package wayoftime.bloodmagic.util.helper;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
|
||||
public class NBTHelper
|
||||
{
|
||||
public static ItemStack checkNBT(ItemStack stack)
|
||||
{
|
||||
if (stack.getTag() == null)
|
||||
stack.setTag(new CompoundNBT());
|
||||
|
||||
return stack;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,180 @@
|
|||
package wayoftime.bloodmagic.util.helper;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.storage.DimensionSavedDataManager;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
||||
import wayoftime.bloodmagic.core.data.BMWorldSavedData;
|
||||
import wayoftime.bloodmagic.core.data.Binding;
|
||||
import wayoftime.bloodmagic.core.data.SoulNetwork;
|
||||
import wayoftime.bloodmagic.core.data.SoulTicket;
|
||||
import wayoftime.bloodmagic.core.registry.OrbRegistry;
|
||||
import wayoftime.bloodmagic.event.SoulNetworkEvent;
|
||||
import wayoftime.bloodmagic.iface.IBindable;
|
||||
import wayoftime.bloodmagic.orb.BloodOrb;
|
||||
import wayoftime.bloodmagic.orb.IBloodOrb;
|
||||
|
||||
public class NetworkHelper
|
||||
{
|
||||
@Nullable
|
||||
private static BMWorldSavedData dataHandler;
|
||||
|
||||
/**
|
||||
* Gets the SoulNetwork for the player.
|
||||
*
|
||||
* @param uuid - The UUID of the SoulNetwork owner - this is UUID.toString().
|
||||
* @return - The SoulNetwork for the given name.
|
||||
*/
|
||||
public static SoulNetwork getSoulNetwork(String uuid)
|
||||
{
|
||||
if (dataHandler == null)
|
||||
{
|
||||
if (ServerLifecycleHooks.getCurrentServer() == null)
|
||||
return null;
|
||||
|
||||
DimensionSavedDataManager savedData = ServerLifecycleHooks.getCurrentServer().func_241755_D_().getSavedData();
|
||||
dataHandler = savedData.getOrCreate(() -> new BMWorldSavedData(), BMWorldSavedData.ID);
|
||||
}
|
||||
|
||||
return dataHandler.getNetwork(UUID.fromString(uuid));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param uuid - The Player's Mojang UUID
|
||||
* @see NetworkHelper#getSoulNetwork(String)
|
||||
*/
|
||||
public static SoulNetwork getSoulNetwork(UUID uuid)
|
||||
{
|
||||
return getSoulNetwork(uuid.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player - The Player
|
||||
* @see NetworkHelper#getSoulNetwork(String)
|
||||
*/
|
||||
public static SoulNetwork getSoulNetwork(PlayerEntity player)
|
||||
{
|
||||
return getSoulNetwork(PlayerHelper.getUUIDFromPlayer(player));
|
||||
}
|
||||
|
||||
public static SoulNetwork getSoulNetwork(Binding binding)
|
||||
{
|
||||
return getSoulNetwork(binding.getOwnerId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current orb tier of the SoulNetwork.
|
||||
*
|
||||
* @param soulNetwork - SoulNetwork to get the tier of.
|
||||
* @return - The Orb tier of the given SoulNetwork
|
||||
*/
|
||||
public static int getCurrentMaxOrb(SoulNetwork soulNetwork)
|
||||
{
|
||||
return soulNetwork.getOrbTier();
|
||||
}
|
||||
|
||||
public static int getMaximumForTier(int tier)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (tier > OrbRegistry.getTierMap().size() || tier < 0)
|
||||
return ret;
|
||||
|
||||
for (ItemStack orbStack : OrbRegistry.getOrbsForTier(tier))
|
||||
{
|
||||
BloodOrb orb = ((IBloodOrb) orbStack.getItem()).getOrb(orbStack);
|
||||
if (orb.getCapacity() > ret)
|
||||
ret = orb.getCapacity();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Syphon
|
||||
|
||||
/**
|
||||
* Syphons from the player and damages them if there was not enough stored LP.
|
||||
* <p>
|
||||
* Handles null-checking the player for you.
|
||||
*
|
||||
* @param soulNetwork - SoulNetwork to syphon from
|
||||
* @param user - User of the item.
|
||||
* @param toSyphon - Amount of LP to syphon
|
||||
* @return - Whether the action should be performed.
|
||||
* @deprecated Use {@link #getSoulNetwork(PlayerEntity)} and
|
||||
* {@link SoulNetwork#syphonAndDamage$(PlayerEntity, SoulTicket)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean syphonAndDamage(SoulNetwork soulNetwork, PlayerEntity user, int toSyphon)
|
||||
{
|
||||
|
||||
// if (soulNetwork.getNewOwner() == null)
|
||||
// {
|
||||
// soulNetwork.syphon(toSyphon);
|
||||
// return true;
|
||||
// }
|
||||
|
||||
return soulNetwork.syphonAndDamage(user, toSyphon);
|
||||
}
|
||||
|
||||
/**
|
||||
* Syphons a player from within a container.
|
||||
*
|
||||
* @param stack - ItemStack in the Container.
|
||||
* @param ticket - SoulTicket to syphon
|
||||
* @return - If the syphon was successful.
|
||||
*/
|
||||
public static boolean syphonFromContainer(ItemStack stack, SoulTicket ticket)
|
||||
{
|
||||
if (!(stack.getItem() instanceof IBindable))
|
||||
return false;
|
||||
|
||||
Binding binding = ((IBindable) stack.getItem()).getBinding(stack);
|
||||
if (binding == null)
|
||||
return false;
|
||||
|
||||
SoulNetwork network = getSoulNetwork(binding);
|
||||
SoulNetworkEvent.Syphon.Item event = new SoulNetworkEvent.Syphon.Item(network, ticket, stack);
|
||||
|
||||
return !MinecraftForge.EVENT_BUS.post(event) && network.syphon(event.getTicket(), true) >= ticket.getAmount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the ItemStack has a user to be syphoned from.
|
||||
*
|
||||
* @param stack - ItemStack to check
|
||||
* @param toSyphon - Amount of LP to syphon
|
||||
* @return - If syphoning is possible
|
||||
*/
|
||||
public static boolean canSyphonFromContainer(ItemStack stack, int toSyphon)
|
||||
{
|
||||
if (!(stack.getItem() instanceof IBindable))
|
||||
return false;
|
||||
|
||||
Binding binding = ((IBindable) stack.getItem()).getBinding(stack);
|
||||
if (binding == null)
|
||||
return false;
|
||||
|
||||
SoulNetwork network = getSoulNetwork(binding);
|
||||
return network.getCurrentEssence() >= toSyphon;
|
||||
}
|
||||
|
||||
// Set
|
||||
|
||||
/**
|
||||
* Sets the orb tier of the SoulNetwork to the given orb. Will not set if the
|
||||
* given tier is lower than the current tier.
|
||||
*
|
||||
* @param soulNetwork - SoulNetwork to set the orb tier of
|
||||
* @param maxOrb - Tier of orb to set to
|
||||
*/
|
||||
public static void setMaxOrb(SoulNetwork soulNetwork, int maxOrb)
|
||||
{
|
||||
soulNetwork.setOrbTier(Math.max(maxOrb, soulNetwork.getOrbTier()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package wayoftime.bloodmagic.util.helper;
|
||||
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class NumeralHelper
|
||||
{
|
||||
|
||||
private static final TreeMap<Integer, String> romanNumerals = new TreeMap<Integer, String>();
|
||||
|
||||
static
|
||||
{
|
||||
romanNumerals.put(1000, "M");
|
||||
romanNumerals.put(900, "CM");
|
||||
romanNumerals.put(500, "D");
|
||||
romanNumerals.put(400, "CD");
|
||||
romanNumerals.put(100, "C");
|
||||
romanNumerals.put(90, "XC");
|
||||
romanNumerals.put(50, "L");
|
||||
romanNumerals.put(40, "XL");
|
||||
romanNumerals.put(10, "X");
|
||||
romanNumerals.put(9, "IX");
|
||||
romanNumerals.put(5, "V");
|
||||
romanNumerals.put(4, "IV");
|
||||
romanNumerals.put(1, "I");
|
||||
}
|
||||
|
||||
public static String toRoman(int arabic)
|
||||
{
|
||||
int convert = romanNumerals.floorKey(arabic);
|
||||
if (arabic == convert)
|
||||
return romanNumerals.get(convert);
|
||||
|
||||
return romanNumerals.get(convert) + toRoman(arabic - convert);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
package wayoftime.bloodmagic.util.helper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraftforge.common.UsernameCache;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
||||
|
||||
public class PlayerHelper
|
||||
{
|
||||
/**
|
||||
* A list of all known fake players that do not extend FakePlayer.
|
||||
* <p>
|
||||
* Will be added to as needed.
|
||||
*/
|
||||
private static final ArrayList<String> knownFakePlayers = Lists.newArrayList();
|
||||
|
||||
public static PlayerEntity getPlayerFromId(UUID uuid)
|
||||
{
|
||||
// TODO: Need to find a reliable way to get whether the side is Client or Server
|
||||
// if (FMLCommonHandler.instance().)
|
||||
// return null;
|
||||
//
|
||||
// World w;
|
||||
// Dist d;
|
||||
//
|
||||
// if(ServerLifecycleHooks.getCurrentServer().get)
|
||||
|
||||
return ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayerByUUID(uuid);
|
||||
|
||||
// return FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUUID(uuid);
|
||||
}
|
||||
|
||||
public static PlayerEntity getPlayerFromUUID(UUID uuid)
|
||||
{
|
||||
return getPlayerFromId(uuid);
|
||||
}
|
||||
|
||||
public static UUID getUUIDFromPlayer(PlayerEntity player)
|
||||
{
|
||||
return player.getGameProfile().getId();
|
||||
}
|
||||
|
||||
public static String getUsernameFromUUID(UUID uuid)
|
||||
{
|
||||
return UsernameCache.getLastKnownUsername(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not the given player is an "actual" player
|
||||
*
|
||||
* @param player - The player in question
|
||||
* @return If the player is fake or not
|
||||
*/
|
||||
public static boolean isFakePlayer(PlayerEntity player)
|
||||
{
|
||||
return player instanceof FakePlayer
|
||||
|| (player != null && knownFakePlayers.contains(player.getClass().getCanonicalName()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,160 @@
|
|||
package wayoftime.bloodmagic.util.helper;
|
||||
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import wayoftime.bloodmagic.ConfigHandler;
|
||||
import wayoftime.bloodmagic.altar.IBloodAltar;
|
||||
import wayoftime.bloodmagic.event.SacrificeKnifeUsedEvent;
|
||||
|
||||
public class PlayerSacrificeHelper
|
||||
{
|
||||
public static float scalingOfSacrifice = 1f;
|
||||
public static int soulFrayDuration = 400;
|
||||
public static Potion soulFrayId;
|
||||
|
||||
public static double getPlayerIncense(PlayerEntity player)
|
||||
{
|
||||
return 0;
|
||||
// return IncenseHelper.getCurrentIncense(player);
|
||||
}
|
||||
|
||||
public static void setPlayerIncense(PlayerEntity player, double amount)
|
||||
{
|
||||
// IncenseHelper.setCurrentIncense(player, amount);
|
||||
}
|
||||
|
||||
public static boolean incrementIncense(PlayerEntity player, double min, double incenseAddition, double increment)
|
||||
{
|
||||
return true;
|
||||
// double amount = getPlayerIncense(player);
|
||||
// if (amount < min || amount >= incenseAddition)
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// amount = amount + Math.min(increment, incenseAddition - amount);
|
||||
// setPlayerIncense(player, amount);
|
||||
//
|
||||
// if (amount == incenseAddition)
|
||||
// {
|
||||
// IncenseHelper.setMaxIncense(player, incenseAddition);
|
||||
// }
|
||||
// // System.out.println("Amount of incense: " + amount + ", Increment: " +
|
||||
// // increment);
|
||||
//
|
||||
// return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sacrifices a player's health while the player is under the influence of
|
||||
* incense
|
||||
*
|
||||
* @param player - The player sacrificing
|
||||
* @return Whether or not the health sacrificing succeeded
|
||||
*/
|
||||
public static boolean sacrificePlayerHealth(PlayerEntity player)
|
||||
{
|
||||
// if (player.isPotionActive(soulFrayId))
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
double amount = getPlayerIncense(player);
|
||||
|
||||
if (amount >= 0)
|
||||
{
|
||||
float health = player.getHealth();
|
||||
float maxHealth = player.getMaxHealth();
|
||||
|
||||
if (health > maxHealth / 10.0)
|
||||
{
|
||||
float sacrificedHealth = health - maxHealth / 10.0f;
|
||||
int lpAdded = (int) (sacrificedHealth * ConfigHandler.values.sacrificialDaggerConversion
|
||||
* getModifier(amount));
|
||||
|
||||
IBloodAltar altar = getAltar(player.getEntityWorld(), player.getPosition());
|
||||
if (altar != null)
|
||||
{
|
||||
SacrificeKnifeUsedEvent evt = new SacrificeKnifeUsedEvent(player, true, true, (int) sacrificedHealth, lpAdded);
|
||||
if (MinecraftForge.EVENT_BUS.post(evt))
|
||||
return false;
|
||||
|
||||
altar.sacrificialDaggerCall(evt.lpAdded, false);
|
||||
altar.startCycle();
|
||||
|
||||
player.setHealth(maxHealth / 10.0f);
|
||||
setPlayerIncense(player, 0);
|
||||
// player.addPotionEffect(new PotionEffect(RegistrarBloodMagic.SOUL_FRAY, soulFrayDuration));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static double getModifier(double amount)
|
||||
{
|
||||
return 1 + amount * scalingOfSacrifice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the nearest {@link IBloodAltar} and attempts to fill it
|
||||
*
|
||||
* @param world - The world
|
||||
* @param sacrificingEntity - The entity having the sacrifice done on (can be
|
||||
* {@link PlayerEntity} for self-sacrifice)
|
||||
* @param amount - The amount of which the altar should be filled
|
||||
* @param isSacrifice - Whether this is a Sacrifice or a Self-Sacrifice
|
||||
* @return Whether the altar is found and (attempted) filled
|
||||
*/
|
||||
public static boolean findAndFillAltar(World world, LivingEntity sacrificingEntity, int amount, boolean isSacrifice)
|
||||
{
|
||||
IBloodAltar altarEntity = getAltar(world, sacrificingEntity.getPosition());
|
||||
|
||||
if (altarEntity == null)
|
||||
return false;
|
||||
|
||||
altarEntity.sacrificialDaggerCall(amount, isSacrifice);
|
||||
altarEntity.startCycle();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the nearest {@link IBloodAltar}
|
||||
*
|
||||
* @param world - The world
|
||||
* @param blockPos - The position of where the check should be in (in a 2 block
|
||||
* radius from this)
|
||||
* @return The nearest altar, if no altar is found, then this will return null
|
||||
*/
|
||||
public static IBloodAltar getAltar(World world, BlockPos blockPos)
|
||||
{
|
||||
TileEntity tileEntity;
|
||||
|
||||
for (int x = -2; x <= 2; x++)
|
||||
{
|
||||
for (int y = -2; y <= 1; y++)
|
||||
{
|
||||
for (int z = -2; z <= 2; z++)
|
||||
{
|
||||
tileEntity = world.getTileEntity(blockPos.add(x, y, z));
|
||||
|
||||
if (tileEntity instanceof IBloodAltar)
|
||||
{
|
||||
return (IBloodAltar) tileEntity;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
253
src/main/java/wayoftime/bloodmagic/util/helper/RitualHelper.java
Normal file
253
src/main/java/wayoftime/bloodmagic/util/helper/RitualHelper.java
Normal file
|
@ -0,0 +1,253 @@
|
|||
package wayoftime.bloodmagic.util.helper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.CapabilityInject;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import wayoftime.bloodmagic.BloodMagic;
|
||||
import wayoftime.bloodmagic.common.block.BlockRitualStone;
|
||||
import wayoftime.bloodmagic.common.block.BloodMagicBlocks;
|
||||
import wayoftime.bloodmagic.ritual.EnumRuneType;
|
||||
import wayoftime.bloodmagic.ritual.IRitualStone;
|
||||
import wayoftime.bloodmagic.ritual.IRitualStone.Tile;
|
||||
import wayoftime.bloodmagic.ritual.Ritual;
|
||||
import wayoftime.bloodmagic.ritual.RitualComponent;
|
||||
import wayoftime.bloodmagic.tile.TileMasterRitualStone;
|
||||
|
||||
public class RitualHelper
|
||||
{
|
||||
@CapabilityInject(IRitualStone.Tile.class)
|
||||
static Capability<IRitualStone.Tile> RUNE_CAPABILITY = null;
|
||||
|
||||
public static boolean canCrystalActivate(Ritual ritual, int crystalLevel)
|
||||
{
|
||||
return ritual.getCrystalLevel() <= crystalLevel
|
||||
&& BloodMagic.RITUAL_MANAGER.enabled(BloodMagic.RITUAL_MANAGER.getId(ritual), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the RitualRegistry to see if the configuration of the ritual stones in
|
||||
* the world is valid for the given Direction.
|
||||
*
|
||||
* @param world - The world
|
||||
* @param pos - Location of the MasterRitualStone
|
||||
* @return The ID of the valid ritual
|
||||
*/
|
||||
public static String getValidRitual(World world, BlockPos pos)
|
||||
{
|
||||
for (Ritual ritual : BloodMagic.RITUAL_MANAGER.getRituals())
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Direction direction = Direction.byHorizontalIndex(i);
|
||||
|
||||
if (checkValidRitual(world, pos, ritual, direction))
|
||||
return BloodMagic.RITUAL_MANAGER.getId(ritual);
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public static Direction getDirectionOfRitual(World world, BlockPos pos, Ritual ritual)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Direction direction = Direction.byHorizontalIndex(i);
|
||||
if (checkValidRitual(world, pos, ritual, direction))
|
||||
return direction;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean checkValidRitual(World world, BlockPos pos, Ritual ritual, Direction direction)
|
||||
{
|
||||
if (ritual == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
List<RitualComponent> components = Lists.newArrayList();
|
||||
ritual.gatherComponents(components::add);
|
||||
|
||||
for (RitualComponent component : components)
|
||||
{
|
||||
BlockPos newPos = pos.add(component.getOffset(direction));
|
||||
if (!isRuneType(world, newPos, component.getRuneType()))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isRuneType(World world, BlockPos pos, EnumRuneType type)
|
||||
{
|
||||
if (world == null)
|
||||
return false;
|
||||
Block block = world.getBlockState(pos).getBlock();
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
|
||||
if (block instanceof IRitualStone)
|
||||
return ((IRitualStone) block).isRuneType(world, pos, type);
|
||||
else if (tile instanceof IRitualStone.Tile)
|
||||
return ((IRitualStone.Tile) tile).isRuneType(type);
|
||||
else if (tile != null && tile.getCapability(RUNE_CAPABILITY, null).isPresent())
|
||||
return tile.getCapability(RUNE_CAPABILITY, null).resolve().get().isRuneType(type);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isRune(World world, BlockPos pos)
|
||||
{
|
||||
if (world == null)
|
||||
return false;
|
||||
Block block = world.getBlockState(pos).getBlock();
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
|
||||
if (block instanceof IRitualStone)
|
||||
return true;
|
||||
else if (tile instanceof IRitualStone.Tile)
|
||||
return true;
|
||||
else
|
||||
return tile != null && tile.getCapability(RUNE_CAPABILITY, null).isPresent();
|
||||
|
||||
}
|
||||
|
||||
public static void setRuneType(World world, BlockPos pos, EnumRuneType type)
|
||||
{
|
||||
if (world == null)
|
||||
return;
|
||||
BlockState state = world.getBlockState(pos);
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
|
||||
if (state.getBlock() instanceof IRitualStone)
|
||||
((IRitualStone) state.getBlock()).setRuneType(world, pos, type);
|
||||
else if (tile instanceof IRitualStone.Tile)
|
||||
((IRitualStone.Tile) tile).setRuneType(type);
|
||||
else
|
||||
{
|
||||
LazyOptional<Tile> cap = tile.getCapability(RUNE_CAPABILITY, null);
|
||||
if (cap.isPresent())
|
||||
{
|
||||
cap.resolve().get().setRuneType(type);
|
||||
world.notifyBlockUpdate(pos, state, state, 3);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean createRitual(World world, BlockPos pos, Direction direction, Ritual ritual, boolean safe)
|
||||
{
|
||||
|
||||
List<RitualComponent> components = Lists.newArrayList();
|
||||
ritual.gatherComponents(components::add);
|
||||
|
||||
if (abortConstruction(world, pos, direction, safe, components))
|
||||
return false;
|
||||
|
||||
BlockState mrs = BloodMagicBlocks.MASTER_RITUAL_STONE.get().getDefaultState();
|
||||
world.setBlockState(pos, mrs);
|
||||
|
||||
setRitualStones(direction, world, pos, components);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean abortConstruction(World world, BlockPos pos, Direction direction, boolean safe, List<RitualComponent> components)
|
||||
{
|
||||
// TODO: can be optimized to check only for the first and last component if
|
||||
// every ritual has those at the highest and lowest y-level respectivly.
|
||||
for (RitualComponent component : components)
|
||||
{
|
||||
BlockPos offset = component.getOffset(direction);
|
||||
BlockPos newPos = pos.add(offset);
|
||||
if (world.isOutsideBuildHeight(newPos) || (safe && !world.isAirBlock(newPos)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean repairRitualFromRuins(TileMasterRitualStone tile, boolean safe)
|
||||
{
|
||||
Ritual ritual = tile.getCurrentRitual();
|
||||
Direction direction;
|
||||
Pair<Ritual, Direction> pair;
|
||||
if (ritual == null)
|
||||
{
|
||||
pair = getRitualFromRuins(tile);
|
||||
ritual = pair.getKey();
|
||||
direction = pair.getValue();
|
||||
} else
|
||||
direction = tile.getDirection();
|
||||
|
||||
World world = tile.getWorld();
|
||||
BlockPos pos = tile.getPos();
|
||||
|
||||
List<RitualComponent> components = Lists.newArrayList();
|
||||
ritual.gatherComponents(components::add);
|
||||
|
||||
if (abortConstruction(world, pos, direction, safe, components))
|
||||
return false;
|
||||
|
||||
setRitualStones(direction, world, pos, components);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void setRitualStones(Direction direction, World world, BlockPos pos, List<RitualComponent> gatheredComponents)
|
||||
{
|
||||
for (RitualComponent component : gatheredComponents)
|
||||
{
|
||||
BlockPos offset = component.getOffset(direction);
|
||||
BlockPos newPos = pos.add(offset);
|
||||
((BlockRitualStone) BloodMagicBlocks.BLANK_RITUAL_STONE.get()).setRuneType(world, newPos, component.getRuneType());
|
||||
}
|
||||
}
|
||||
|
||||
public static Pair<Ritual, Direction> getRitualFromRuins(TileMasterRitualStone tile)
|
||||
{
|
||||
BlockPos pos = tile.getPos();
|
||||
World world = tile.getWorld();
|
||||
Ritual possibleRitual = tile.getCurrentRitual();
|
||||
Direction possibleDirection = tile.getDirection();
|
||||
int highestCount = 0;
|
||||
|
||||
if (possibleRitual == null || possibleDirection == null)
|
||||
for (Ritual ritual : BloodMagic.RITUAL_MANAGER.getRituals())
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Direction direction = Direction.byHorizontalIndex(i);
|
||||
List<RitualComponent> components = Lists.newArrayList();
|
||||
ritual.gatherComponents(components::add);
|
||||
int currentCount = 0;
|
||||
|
||||
for (RitualComponent component : components)
|
||||
{
|
||||
BlockPos newPos = pos.add(component.getOffset(direction));
|
||||
if (isRuneType(world, newPos, component.getRuneType()))
|
||||
currentCount += 1;
|
||||
}
|
||||
if (currentCount > highestCount)
|
||||
{
|
||||
highestCount = currentCount;
|
||||
possibleRitual = ritual;
|
||||
possibleDirection = direction;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return Pair.of(possibleRitual, possibleDirection);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package wayoftime.bloodmagic.util.helper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
|
||||
import net.minecraft.client.resources.I18n;
|
||||
|
||||
public class TextHelper
|
||||
{
|
||||
public static String getFormattedText(String string)
|
||||
{
|
||||
return string.replaceAll("&", "\u00A7");
|
||||
}
|
||||
|
||||
public static String localize(String input, Object... format)
|
||||
{
|
||||
return I18n.format(input, format);
|
||||
}
|
||||
|
||||
public static String localizeEffect(String input, Object... format)
|
||||
{
|
||||
return getFormattedText(localize(input, format));
|
||||
}
|
||||
|
||||
public static String[] localizeAll(String[] input)
|
||||
{
|
||||
String[] ret = new String[input.length];
|
||||
for (int i = 0; i < input.length; i++)
|
||||
ret[i] = localize(input[i]);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static String[] localizeAllEffect(String[] input)
|
||||
{
|
||||
String[] ret = new String[input.length];
|
||||
for (int i = 0; i < input.length; i++)
|
||||
ret[i] = localizeEffect(input[i]);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static ArrayList<String> localizeAll(List<String> input)
|
||||
{
|
||||
ArrayList<String> ret = new ArrayList<>(input.size());
|
||||
for (int i = 0; i < input.size(); i++)
|
||||
ret.add(i, localize(input.get(i)));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static ArrayList<String> localizeAllEffect(List<String> input)
|
||||
{
|
||||
ArrayList<String> ret = new ArrayList<>(input.size());
|
||||
for (int i = 0; i < input.size(); i++)
|
||||
ret.add(i, localizeEffect(input.get(i)));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static String[] cutLongString(String string, int characters)
|
||||
{
|
||||
return WordUtils.wrap(string, characters, "/cut", false).split("/cut");
|
||||
}
|
||||
|
||||
public static String[] cutLongString(String string)
|
||||
{
|
||||
return cutLongString(string, 30);
|
||||
}
|
||||
|
||||
public static boolean canTranslate(String key)
|
||||
{
|
||||
return I18n.hasKey(key);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue