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:
WayofTime 2020-10-29 15:50:03 -04:00
parent 6b4145a67c
commit 9fa68e86ae
224 changed files with 24047 additions and 0 deletions

View file

@ -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);
}
}

View file

@ -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;
}
}

View file

@ -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()));
}
}

View file

@ -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);
}
}

View file

@ -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()));
}
}

View file

@ -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;
}
}

View 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);
}
}

View file

@ -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);
}
}