More progress

This commit is contained in:
Nicholas Ignoffo 2017-01-01 21:43:34 -08:00
parent 00d6f8eb46
commit d80afb18f0
64 changed files with 410 additions and 976 deletions

View file

@ -8,6 +8,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
@ -51,14 +52,15 @@ public class ItemStackWrapper
this(blockStack.getBlock(), 1, blockStack.getMeta());
}
@Nullable
public static ItemStackWrapper getHolder(ItemStack stack)
{
if (stack == null)
if (stack.isEmpty())
{
return null;
}
return new ItemStackWrapper(stack.getItem(), stack.stackSize, stack.getItemDamage());
return new ItemStackWrapper(stack.getItem(), stack.getCount(), stack.getItemDamage());
}
public ItemStack toStack()

View file

@ -47,7 +47,7 @@ public class AlchemyArrayEffectCrafting extends AlchemyArrayEffect
EntityItem outputEntity = new EntityItem(tile.getWorld(), pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, output);
tile.getWorld().spawnEntityInWorld(outputEntity);
tile.getWorld().spawnEntity(outputEntity);
return true;
}

View file

@ -67,19 +67,19 @@ public class CompressionRegistry
for (int slot = 0; slot < itemHandler.getSlots(); slot++)
{
inventory[slot] = itemHandler.extractItem(slot, 64, true);
copyInventory[slot] = ItemStack.copyItemStack(inventory[slot]);
copyInventory[slot] = inventory[slot].copy();
}
for (CompressionHandler handler : compressionRegistry)
{
ItemStack stack = handler.compressInventory(copyInventory, world);
if (stack != null)
if (!stack.isEmpty())
{
for (int slot = 0; slot < itemHandler.getSlots(); slot++)
{
if (inventory[slot] != null && !ItemStack.areItemStacksEqual(inventory[slot], copyInventory[slot]))
{
itemHandler.extractItem(slot, inventory[slot].stackSize, false);
itemHandler.extractItem(slot, inventory[slot].getCount(), false);
if (copyInventory[slot] != null)
{
itemHandler.insertItem(slot, copyInventory[slot], false);
@ -92,7 +92,7 @@ public class CompressionRegistry
}
}
return Pair.of(null, false);
return Pair.of(ItemStack.EMPTY, false);
}
public static int getItemThreshold(ItemStack stack)
@ -110,6 +110,6 @@ public class CompressionRegistry
public static boolean areItemStacksEqual(ItemStack stack, ItemStack compressedStack)
{
return stack.isItemEqual(compressedStack) && (stack.getTagCompound() == null ? compressedStack.getTagCompound() == null : stack.getTagCompound().equals(compressedStack.getTagCompound()));
return stack.isItemEqual(compressedStack) && (stack.getTagCompound() == null ? !compressedStack.hasTagCompound() : stack.getTagCompound().equals(compressedStack.getTagCompound()));
}
}

View file

@ -29,24 +29,25 @@ public class ItemSigilToggleable extends ItemSigil implements IActivatable
@Override
public boolean getActivated(ItemStack stack)
{
return stack != null && NBTHelper.checkNBT(stack).getTagCompound().getBoolean(Constants.NBT.ACTIVATED);
return !stack.isEmpty() && NBTHelper.checkNBT(stack).getTagCompound().getBoolean(Constants.NBT.ACTIVATED);
}
@Override
public ItemStack setActivatedState(ItemStack stack, boolean activated)
{
if (stack != null)
if (!stack.isEmpty())
{
NBTHelper.checkNBT(stack).getTagCompound().setBoolean(Constants.NBT.ACTIVATED, activated);
return stack;
}
return null;
return stack;
}
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand)
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand)
{
ItemStack stack = player.getHeldItem(hand);
if (PlayerHelper.isFakePlayer(player))
return ActionResult.newResult(EnumActionResult.FAIL, stack);
@ -55,16 +56,16 @@ public class ItemSigilToggleable extends ItemSigil implements IActivatable
if (player.isSneaking())
setActivatedState(stack, !getActivated(stack));
if (getActivated(stack) && NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, getLpUsed()))
return super.onItemRightClick(stack, world, player, hand);
return super.onItemRightClick(world, player, hand);
}
return super.onItemRightClick(stack, world, player, hand);
return super.onItemRightClick(world, player, hand);
}
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
return (NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, getLpUsed()) && onSigilUse(stack, player, world, pos, side, hitX, hitY, hitZ)) ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
return (NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, getLpUsed()) && onSigilUse(player.getHeldItem(hand), player, world, pos, side, hitX, hitY, hitZ)) ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
}
public boolean onSigilUse(ItemStack itemStack, EntityPlayer player, World world, BlockPos blockPos, EnumFacing side, float hitX, float hitY, float hitZ)

View file

@ -1,206 +0,0 @@
package WayofTime.bloodmagic.api.network;
import WayofTime.bloodmagic.api.BloodMagicAPI;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.event.AddToNetworkEvent;
import WayofTime.bloodmagic.api.event.SoulNetworkEvent;
import WayofTime.bloodmagic.api.util.helper.PlayerHelper;
import com.google.common.base.Strings;
import lombok.Getter;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import net.minecraft.world.WorldSavedData;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.eventhandler.Event;
import javax.annotation.Nullable;
@Getter
@Deprecated
/**
* Deprecated in favor of new system in {@link WayofTime.bloodmagic.api.saving.BMWorldSavedData} and
* {@link WayofTime.bloodmagic.api.saving.SoulNetwork}
*/
public class SoulNetwork extends WorldSavedData
{
@Nullable
private final EntityPlayer player;
private int currentEssence;
private int orbTier;
public SoulNetwork(String name)
{
super(name);
currentEssence = 0;
orbTier = 0;
player = PlayerHelper.getPlayerFromUUID(name);
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound)
{
currentEssence = nbttagcompound.getInteger(Constants.NBT.CURRENT_ESSENCE);
orbTier = nbttagcompound.getInteger(Constants.NBT.ORB_TIER);
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound)
{
nbttagcompound.setInteger(Constants.NBT.CURRENT_ESSENCE, currentEssence);
nbttagcompound.setInteger(Constants.NBT.ORB_TIER, orbTier);
return nbttagcompound;
}
public int addLifeEssence(int toAdd, int maximum)
{
AddToNetworkEvent event = new AddToNetworkEvent(mapName, toAdd, maximum);
if (MinecraftForge.EVENT_BUS.post(event))
return 0;
if (FMLCommonHandler.instance().getMinecraftServerInstance() == null)
return 0;
World world = FMLCommonHandler.instance().getMinecraftServerInstance().worldServers[0];
SoulNetwork data = (SoulNetwork) world.loadItemData(SoulNetwork.class, event.ownerNetwork);
if (data == null)
{
data = new SoulNetwork(event.ownerNetwork);
world.setItemData(event.ownerNetwork, data);
}
int currEss = data.getCurrentEssence();
if (currEss >= event.maximum)
return 0;
int newEss = Math.min(event.maximum, currEss + event.addedAmount);
if (event.getResult() != Event.Result.DENY)
data.setCurrentEssence(newEss);
markDirty();
return newEss - currEss;
}
/**
* Used to syphon LP from the network
*
* @param syphon
* - The amount of LP to syphon
*
* @return The amount of LP syphoned
*/
public int syphon(int syphon)
{
if (getCurrentEssence() >= syphon)
{
setCurrentEssence(getCurrentEssence() - syphon);
return syphon;
}
return 0;
}
/**
* Syphons from the network of the owner. If not enough LP is found, it will
* instead take away from the user's health.
*
* Always returns false on the client side.
*
* @param user
* - The Player to syphon from
* @param toSyphon
* - The amount of LP to syphon
*
* @return - Whether the action should be performed.
*/
public boolean syphonAndDamage(EntityPlayer user, int toSyphon)
{
if (user != null)
{
if (user.worldObj.isRemote)
return false;
if (!Strings.isNullOrEmpty(mapName))
{
SoulNetworkEvent.ItemDrainNetworkEvent event = new SoulNetworkEvent.ItemDrainNetworkEvent(user, mapName, null, toSyphon);
if (MinecraftForge.EVENT_BUS.post(event))
return false;
int drainAmount = syphon(event.syphon);
if (drainAmount <= 0 || event.shouldDamage)
hurtPlayer(user, event.syphon);
return event.getResult() != Event.Result.DENY;
}
int amount = syphon(toSyphon);
hurtPlayer(user, toSyphon - amount);
return true;
}
return false;
}
public void hurtPlayer(EntityPlayer user, float syphon)
{
if (user != null)
{
if (syphon < 100 && syphon > 0)
{
if (!user.capabilities.isCreativeMode)
{
user.hurtResistantTime = 0;
user.attackEntityFrom(BloodMagicAPI.getDamageSource(), 1.0F);
}
} else if (syphon >= 100)
{
if (!user.capabilities.isCreativeMode)
{
for (int i = 0; i < ((syphon + 99) / 100); i++)
{
user.hurtResistantTime = 0;
user.attackEntityFrom(BloodMagicAPI.getDamageSource(), 1.0F);
}
}
}
}
}
public void causeNauseaToPlayer()
{
if (getPlayer() != null)
{
getPlayer().addPotionEffect(new PotionEffect(MobEffects.NAUSEA, 99));
}
}
public SoulNetwork setCurrentEssence(int currentEssence)
{
this.currentEssence = currentEssence;
markDirty();
return this;
}
public SoulNetwork setOrbTier(int orbTier)
{
this.orbTier = orbTier;
markDirty();
return this;
}
}

View file

@ -1,7 +0,0 @@
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package WayofTime.bloodmagic.api.network;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View file

@ -25,9 +25,9 @@ public class AlchemyTableCustomRecipe extends AlchemyTableRecipe
@Override
protected ItemStack getContainerItem(ItemStack stack)
{
if (stack == null)
if (stack.isEmpty())
{
return null;
return ItemStack.EMPTY;
}
ItemStack copyStack = stack.copy();
@ -42,10 +42,10 @@ public class AlchemyTableCustomRecipe extends AlchemyTableRecipe
return copyStack.getItem().getContainerItem(copyStack);
}
copyStack.stackSize--;
if (copyStack.stackSize <= 0)
copyStack.shrink(1);
if (copyStack.isEmpty())
{
return null;
return ItemStack.EMPTY;
}
return copyStack;

View file

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.google.common.collect.ImmutableList;
import lombok.Getter;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
@ -15,7 +16,7 @@ import net.minecraftforge.oredict.OreDictionary;
public class AlchemyTableRecipe
{
protected ItemStack output = null;
protected ArrayList<ItemStack> input = new ArrayList<ItemStack>();
protected ArrayList<Object> input = new ArrayList<Object>();
@Getter
protected int lpDrained;
@Getter
@ -103,13 +104,12 @@ public class AlchemyTableRecipe
if (slot != null)
{
boolean inRecipe = false;
Iterator<Object> req = required.iterator();
while (req.hasNext())
for (Object aRequired : required)
{
boolean match = false;
Object next = req.next();
Object next = aRequired;
if (next instanceof ItemStack)
{
@ -148,9 +148,9 @@ public class AlchemyTableRecipe
*
* @return The recipes input vales.
*/
public ArrayList<ItemStack> getInput()
public List<Object> getInput()
{
return this.input;
return ImmutableList.copyOf(input);
}
public ItemStack[] getRemainingItems(ItemStack[] inventory)
@ -166,9 +166,9 @@ public class AlchemyTableRecipe
protected ItemStack getContainerItem(ItemStack stack)
{
if (stack == null)
if (stack.isEmpty())
{
return null;
return ItemStack.EMPTY;
}
ItemStack copyStack = stack.copy();
@ -178,10 +178,10 @@ public class AlchemyTableRecipe
return copyStack.getItem().getContainerItem(copyStack);
}
copyStack.stackSize--;
if (copyStack.stackSize <= 0)
copyStack.shrink(1);
if (copyStack.isEmpty())
{
return null;
return ItemStack.EMPTY;
}
return copyStack;

View file

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.google.common.collect.ImmutableList;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@ -17,7 +18,7 @@ public class LivingArmourDowngradeRecipe
{
protected LivingArmourUpgrade upgrade = null;
protected ItemStack keyStack = null;
protected ArrayList<Object> input = new ArrayList<Object>();
protected List<Object> input = new ArrayList<Object>();
public LivingArmourDowngradeRecipe(LivingArmourUpgrade upgrade, ItemStack keyStack, Object... recipe)
{
@ -77,20 +78,17 @@ public class LivingArmourDowngradeRecipe
ArrayList<Object> required = new ArrayList<Object>(input);
for (int x = 0; x < checkedList.size(); x++)
for (ItemStack slot : checkedList)
{
ItemStack slot = checkedList.get(x);
if (slot != null)
{
boolean inRecipe = false;
Iterator<Object> req = required.iterator();
while (req.hasNext())
for (Object aRequired : required)
{
boolean match = false;
Object next = req.next();
Object next = aRequired;
if (next instanceof ItemStack)
{
@ -129,9 +127,9 @@ public class LivingArmourDowngradeRecipe
*
* @return The recipes input vales.
*/
public ArrayList<Object> getInput()
public List<Object> getInput()
{
return this.input;
return ImmutableList.copyOf(input);
}
public ItemStack getKey()
@ -144,14 +142,14 @@ public class LivingArmourDowngradeRecipe
for (int i = 0; i < inv.getSlots(); i++)
{
ItemStack stack = inv.getStackInSlot(i);
if (stack == null)
if (stack.isEmpty())
{
continue;
}
if (stack.getItem().hasContainerItem(stack))
{
inv.extractItem(i, stack.stackSize, false);
inv.extractItem(i, stack.getCount(), false);
inv.insertItem(i, stack.getItem().getContainerItem(stack), false);
} else
{
@ -162,9 +160,9 @@ public class LivingArmourDowngradeRecipe
protected ItemStack getContainerItem(ItemStack stack)
{
if (stack == null)
if (stack.isEmpty())
{
return null;
return ItemStack.EMPTY;
}
ItemStack copyStack = stack.copy();
@ -174,10 +172,10 @@ public class LivingArmourDowngradeRecipe
return copyStack.getItem().getContainerItem(copyStack);
}
copyStack.stackSize--;
if (copyStack.stackSize <= 0)
copyStack.shrink(1);
if (copyStack.isEmpty())
{
return null;
return ItemStack.EMPTY;
}
return copyStack;

View file

@ -7,6 +7,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.oredict.OreDictionary;
@ -242,7 +243,7 @@ public class ShapedBloodOrbRecipe implements IRecipe
// value of the item instead
if (target instanceof Integer)
{
if (slot != null && slot.getItem() instanceof IBloodOrb)
if (!slot.isEmpty() && slot.getItem() instanceof IBloodOrb)
{
IBloodOrb orb = (IBloodOrb) slot.getItem();
if (orb.getOrbLevel(slot.getItemDamage()) < (Integer) target)
@ -271,7 +272,7 @@ public class ShapedBloodOrbRecipe implements IRecipe
{
return false;
}
} else if (target == null && slot != null)
} else if (target == null && !slot.isEmpty())
{
return false;
}
@ -292,7 +293,7 @@ public class ShapedBloodOrbRecipe implements IRecipe
return this.input;
}
public ItemStack[] getRemainingItems(InventoryCrafting inv)
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
{
return ForgeHooks.defaultRecipeGetRemainingItems(inv);
}

View file

@ -7,7 +7,9 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.oredict.OreDictionary;
import java.util.ArrayList;
@ -83,7 +85,7 @@ public class ShapelessBloodOrbRecipe implements IRecipe
{
output = recipe.getRecipeOutput();
for (ItemStack ingred : ((List<ItemStack>) recipe.recipeItems))
for (ItemStack ingred : recipe.recipeItems)
{
Object finalObj = ingred;
for (Entry<ItemStack, String> replace : replacements.entrySet())
@ -126,7 +128,7 @@ public class ShapelessBloodOrbRecipe implements IRecipe
{
ItemStack slot = var1.getStackInSlot(x);
if (slot != null)
if (!slot.isEmpty())
{
boolean inRecipe = false;
Iterator<Object> req = required.iterator();
@ -187,17 +189,9 @@ public class ShapelessBloodOrbRecipe implements IRecipe
}
@Override
public ItemStack[] getRemainingItems(InventoryCrafting inv)
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
{
ItemStack[] aitemstack = new ItemStack[inv.getSizeInventory()];
for (int i = 0; i < aitemstack.length; ++i)
{
ItemStack itemstack = inv.getStackInSlot(i);
aitemstack[i] = net.minecraftforge.common.ForgeHooks.getContainerItem(itemstack);
}
return aitemstack;
return ForgeHooks.defaultRecipeGetRemainingItems(inv);
}
public int getTier()

View file

@ -78,7 +78,7 @@ public class SoulNetwork implements INBTSerializable<NBTTagCompound>
{
if (user != null)
{
if (user.worldObj.isRemote)
if (user.getEntityWorld().isRemote)
return false;
if (!Strings.isNullOrEmpty(playerId.toString()))

View file

@ -6,6 +6,7 @@ import WayofTime.bloodmagic.api.ritual.IRitualStone;
import WayofTime.bloodmagic.api.ritual.Ritual;
import WayofTime.bloodmagic.api.ritual.RitualComponent;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
@ -149,17 +150,17 @@ public class RitualHelper
{
if (world == null)
return;
Block block = world.getBlockState(pos).getBlock();
IBlockState state = world.getBlockState(pos);
TileEntity tile = world.getTileEntity(pos);
if (block instanceof IRitualStone)
((IRitualStone) block).setRuneType(world, pos, type);
if (state.getBlock() instanceof IRitualStone)
((IRitualStone) state.getBlock()).setRuneType(world, pos, type);
else if (tile instanceof IRitualStone.Tile)
((IRitualStone.Tile) tile).setRuneType(type);
else if (tile != null && tile.hasCapability(RUNE_CAPABILITY, null))
{
tile.getCapability(RUNE_CAPABILITY, null).setRuneType(type);
world.notifyBlockOfStateChange(pos, block);
world.notifyBlockUpdate(pos, state, state, 3);
}
}
}