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,271 @@
package wayoftime.bloodmagic.tile;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.fluid.Fluids;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.fluids.FluidAttributes;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction;
import net.minecraftforge.fluids.capability.IFluidHandlerItem;
import net.minecraftforge.fluids.capability.templates.FluidTank;
import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.registries.ObjectHolder;
import wayoftime.bloodmagic.api.impl.BloodMagicAPI;
import wayoftime.bloodmagic.api.impl.recipe.RecipeARC;
import wayoftime.bloodmagic.tile.contailer.ContainerAlchemicalReactionChamber;
import wayoftime.bloodmagic.util.Constants;
import wayoftime.bloodmagic.util.MultiSlotItemHandler;
public class TileAlchemicalReactionChamber extends TileInventory implements ITickableTileEntity, INamedContainerProvider
{
@ObjectHolder("bloodmagic:alchemicalreactionchamber")
public static TileEntityType<TileAlchemicalReactionChamber> TYPE;
public static final int ARC_TOOL_SLOT = 0;
public static final int OUTPUT_SLOT = 1;
public static final int NUM_OUTPUTS = 5;
public static final int INPUT_SLOT = 6;
public static final int INPUT_BUCKET_SLOT = 7;
public static final int OUTPUT_BUCKET_SLOT = 8;
public FluidTank inputTank = new FluidTank(FluidAttributes.BUCKET_VOLUME * 20);
public FluidTank outputTank = new FluidTank(FluidAttributes.BUCKET_VOLUME * 20);
public double currentProgress = 0;
public TileAlchemicalReactionChamber(TileEntityType<?> type)
{
super(type, 9, "alchemicalreactionchamber");
}
public TileAlchemicalReactionChamber()
{
this(TYPE);
}
@Override
public void deserialize(CompoundNBT tag)
{
super.deserialize(tag);
currentProgress = tag.getDouble(Constants.NBT.ARC_PROGRESS);
CompoundNBT inputTankTag = tag.getCompound("inputtank");
inputTank.readFromNBT(inputTankTag);
CompoundNBT outputTankTag = tag.getCompound("outputtank");
outputTank.readFromNBT(outputTankTag);
}
@Override
public CompoundNBT serialize(CompoundNBT tag)
{
super.serialize(tag);
tag.putDouble(Constants.NBT.ARC_PROGRESS, currentProgress);
CompoundNBT inputTankTag = new CompoundNBT();
inputTank.writeToNBT(inputTankTag);
tag.put("inputtank", inputTankTag);
CompoundNBT outputTankTag = new CompoundNBT();
outputTank.writeToNBT(outputTankTag);
tag.put("outputtank", outputTankTag);
return tag;
}
@Override
public void tick()
{
if (world.isRemote)
{
return;
}
if (world.getGameTime() % 20 == 0)
{
outputTank.fill(new FluidStack(Fluids.WATER, 100), FluidAction.EXECUTE);
}
ItemStack fullBucketStack = this.getStackInSlot(INPUT_BUCKET_SLOT);
ItemStack emptyBucketStack = this.getStackInSlot(OUTPUT_BUCKET_SLOT);
ItemStack[] outputInventory = new ItemStack[]
{ getStackInSlot(1), getStackInSlot(2), getStackInSlot(3), getStackInSlot(4), getStackInSlot(5) };
MultiSlotItemHandler outputSlotHandler = new MultiSlotItemHandler(outputInventory, 64);
if (!fullBucketStack.isEmpty() && inputTank.getSpace() >= 1000)
{
ItemStack testFullBucketStack = ItemHandlerHelper.copyStackWithSize(fullBucketStack, 1);
LazyOptional<IFluidHandlerItem> fluidHandlerWrapper = FluidUtil.getFluidHandler(testFullBucketStack);
if (fluidHandlerWrapper.isPresent())
{
IFluidHandlerItem fluidHandler = fluidHandlerWrapper.resolve().get();
FluidStack transferedStack = FluidUtil.tryFluidTransfer(inputTank, fluidHandler, 1000, false);
if (!transferedStack.isEmpty())
{
fluidHandler.drain(transferedStack, FluidAction.EXECUTE);
List<ItemStack> arrayList = new ArrayList<>();
arrayList.add(fluidHandler.getContainer());
if (outputSlotHandler.canTransferAllItemsToSlots(arrayList, true))
{
inputTank.fill(transferedStack, FluidAction.EXECUTE);
outputSlotHandler.canTransferAllItemsToSlots(arrayList, false);
if (fullBucketStack.getCount() > 1)
{
fullBucketStack.setCount(fullBucketStack.getCount() - 1);
} else
{
setInventorySlotContents(INPUT_BUCKET_SLOT, ItemStack.EMPTY);
}
}
}
}
}
if (!emptyBucketStack.isEmpty() && outputTank.getFluidAmount() >= 1000)
{
ItemStack testEmptyBucketStack = ItemHandlerHelper.copyStackWithSize(emptyBucketStack, 1);
LazyOptional<IFluidHandlerItem> fluidHandlerWrapper = FluidUtil.getFluidHandler(testEmptyBucketStack);
if (fluidHandlerWrapper.isPresent())
{
IFluidHandlerItem fluidHandler = fluidHandlerWrapper.resolve().get();
FluidStack transferedStack = FluidUtil.tryFluidTransfer(fluidHandler, outputTank, 1000, false);
if (!transferedStack.isEmpty())
{
fluidHandler.fill(transferedStack, FluidAction.EXECUTE);
List<ItemStack> arrayList = new ArrayList<>();
arrayList.add(fluidHandler.getContainer());
if (outputSlotHandler.canTransferAllItemsToSlots(arrayList, true))
{
outputTank.drain(transferedStack, FluidAction.EXECUTE);
outputSlotHandler.canTransferAllItemsToSlots(arrayList, false);
if (emptyBucketStack.getCount() > 1)
{
emptyBucketStack.setCount(emptyBucketStack.getCount() - 1);
} else
{
setInventorySlotContents(OUTPUT_BUCKET_SLOT, ItemStack.EMPTY);
}
}
}
}
}
ItemStack inputStack = this.getStackInSlot(INPUT_SLOT);
ItemStack toolStack = this.getStackInSlot(ARC_TOOL_SLOT);
RecipeARC recipe = BloodMagicAPI.INSTANCE.getRecipeRegistrar().getARC(world, inputStack, toolStack, inputTank.getFluid());
if (recipe != null && outputSlotHandler.canTransferAllItemsToSlots(recipe.getAllListedOutputs(), true))
{
// We have enough fluid (if applicable) and the theoretical outputs can fit.
}
for (int i = 0; i < NUM_OUTPUTS; i++)
{
this.setInventorySlotContents(OUTPUT_SLOT + i, outputSlotHandler.getStackInSlot(i));
}
// FluidUtil.tryEmptyContainer(container, fluidDestination, maxAmount, player, doDrain)
}
private boolean canCraft(RecipeARC recipe, MultiSlotItemHandler outputSlotHandler)
{
if (recipe == null)
return false;
if (outputSlotHandler.canTransferAllItemsToSlots(recipe.getAllListedOutputs(), true))
{
FluidStack outputStack = recipe.getFluidOutput();
return outputStack.isEmpty() ? true
: outputTank.fill(outputStack, FluidAction.SIMULATE) >= outputStack.getAmount();
}
return false;
}
public void craftItem(RecipeARC recipe, MultiSlotItemHandler outputSlotHandler)
{
if (this.canCraft(recipe, outputSlotHandler))
{
outputSlotHandler.canTransferAllItemsToSlots(recipe.getAllOutputs(world.rand), false);
outputTank.fill(recipe.getFluidOutput().copy(), FluidAction.EXECUTE);
consumeInventory();
}
}
public void consumeInventory()
{
ItemStack inputStack = getStackInSlot(INPUT_SLOT);
if (!inputStack.isEmpty())
{
if (inputStack.getItem().hasContainerItem(inputStack))
{
setInventorySlotContents(INPUT_SLOT, inputStack.getItem().getContainerItem(inputStack));
} else
{
inputStack.shrink(1);
if (inputStack.isEmpty())
{
setInventorySlotContents(INPUT_SLOT, ItemStack.EMPTY);
}
}
}
ItemStack toolStack = getStackInSlot(ARC_TOOL_SLOT);
if (!toolStack.isEmpty())
{
if (toolStack.isDamageable())
{
toolStack.setDamage(toolStack.getDamage() + 1);
if (toolStack.getDamage() >= toolStack.getMaxDamage())
{
setInventorySlotContents(ARC_TOOL_SLOT, ItemStack.EMPTY);
}
} else if (toolStack.getItem().hasContainerItem(toolStack))
{
setInventorySlotContents(ARC_TOOL_SLOT, toolStack.getItem().getContainerItem(inputStack));
} else
{
toolStack.shrink(1);
if (toolStack.isEmpty())
{
setInventorySlotContents(ARC_TOOL_SLOT, ItemStack.EMPTY);
}
}
}
}
@Override
public Container createMenu(int p_createMenu_1_, PlayerInventory p_createMenu_2_, PlayerEntity p_createMenu_3_)
{
assert world != null;
return new ContainerAlchemicalReactionChamber(this, p_createMenu_1_, p_createMenu_2_);
}
@Override
public ITextComponent getDisplayName()
{
return new StringTextComponent("Alchemical Reaction Chamber");
}
public double getProgressForGui()
{
return 0;
}
}

View file

@ -0,0 +1,152 @@
package wayoftime.bloodmagic.tile;
import net.minecraft.block.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
import net.minecraftforge.registries.ObjectHolder;
import wayoftime.bloodmagic.common.alchemyarray.AlchemyArrayEffect;
import wayoftime.bloodmagic.core.registry.AlchemyArrayRegistry;
import wayoftime.bloodmagic.util.Constants;
public class TileAlchemyArray extends TileInventory implements ITickableTileEntity
{
@ObjectHolder("bloodmagic:alchemyarray")
public static TileEntityType<TileAlchemyArray> TYPE;
public boolean isActive = false;
public int activeCounter = 0;
public Direction rotation = Direction.byHorizontalIndex(0);
public int rotateCooldown = 0;
private String key = "";
public AlchemyArrayEffect arrayEffect;
private boolean doDropIngredients = true;
public TileAlchemyArray(TileEntityType<?> type)
{
super(type, 2, "alchemyarray");
// this.bloodAltar = new BloodAltar(this);
}
public TileAlchemyArray()
{
this(TYPE);
}
@Override
public void deserialize(CompoundNBT tagCompound)
{
super.deserialize(tagCompound);
this.isActive = tagCompound.getBoolean("isActive");
this.activeCounter = tagCompound.getInt("activeCounter");
this.key = tagCompound.getString("stringKey");
if (!tagCompound.contains("doDropIngredients")) // Check if the array is old
{
this.doDropIngredients = true;
} else
{
this.doDropIngredients = tagCompound.getBoolean("doDropIngredients");
}
this.rotation = Direction.byHorizontalIndex(tagCompound.getInt(Constants.NBT.DIRECTION));
CompoundNBT arrayTag = tagCompound.getCompound("arrayTag");
// arrayEffect = AlchemyArrayRegistry.getEffect(world, this.getStackInSlot(0), this.getStackInSlot(1));
if (arrayEffect != null)
{
arrayEffect.readFromNBT(arrayTag);
}
}
@Override
public CompoundNBT serialize(CompoundNBT tagCompound)
{
super.serialize(tagCompound);
tagCompound.putBoolean("isActive", isActive);
tagCompound.putInt("activeCounter", activeCounter);
tagCompound.putString("stringKey", "".equals(key) ? "empty" : key.toString());
tagCompound.putBoolean("doDropIngredients", doDropIngredients);
tagCompound.putInt(Constants.NBT.DIRECTION, rotation.getHorizontalIndex());
CompoundNBT arrayTag = new CompoundNBT();
if (arrayEffect != null)
{
arrayEffect.writeToNBT(arrayTag);
}
tagCompound.put("arrayTag", arrayTag);
return tagCompound;
}
@Override
public void tick()
{
// System.out.println("Active counter: " + this.activeCounter);
if (isActive && attemptCraft())
{
activeCounter++;
} else
{
isActive = false;
doDropIngredients = true;
activeCounter = 0;
arrayEffect = null;
key = "empty";
}
if (rotateCooldown > 0)
rotateCooldown--;
}
public boolean attemptCraft()
{
if (arrayEffect != null)
{
isActive = true;
} else
{
AlchemyArrayEffect effect = AlchemyArrayRegistry.getEffect(world, this.getStackInSlot(0), this.getStackInSlot(1));
if (effect == null)
{
// key = effect.i
return false;
} else
{
arrayEffect = effect;
}
}
if (arrayEffect != null)
{
isActive = true;
if (arrayEffect.update(this, this.activeCounter))
{
this.decrStackSize(0, 1);
this.decrStackSize(1, 1);
this.getWorld().setBlockState(getPos(), Blocks.AIR.getDefaultState());
}
return true;
}
return false;
}
// @Override
public Direction getRotation()
{
return rotation;
}
public void setRotation(Direction rotation)
{
this.rotation = rotation;
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack itemstack)
{
return slot == 0 || slot == 1;
}
}

View file

@ -0,0 +1,227 @@
package wayoftime.bloodmagic.tile;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraftforge.registries.ObjectHolder;
import wayoftime.bloodmagic.altar.AltarTier;
import wayoftime.bloodmagic.altar.BloodAltar;
import wayoftime.bloodmagic.altar.IBloodAltar;
public class TileAltar extends TileInventory implements IBloodAltar, ITickableTileEntity
{
@ObjectHolder("bloodmagic:altar")
public static TileEntityType<TileAltar> TYPE;
private BloodAltar bloodAltar;
public TileAltar(TileEntityType<?> type)
{
super(type, 1, "altar");
this.bloodAltar = new BloodAltar(this);
}
public TileAltar()
{
this(TYPE);
}
@Override
public void deserialize(CompoundNBT tagCompound)
{
super.deserialize(tagCompound);
CompoundNBT altarTag = tagCompound.getCompound("bloodAltar");
this.bloodAltar.readFromNBT(altarTag);
}
@Override
public CompoundNBT serialize(CompoundNBT tagCompound)
{
super.serialize(tagCompound);
CompoundNBT altarTag = new CompoundNBT();
this.bloodAltar.writeToNBT(altarTag);
tagCompound.put("bloodAltar", altarTag);
return tagCompound;
}
@Override
public void tick()
{
bloodAltar.update();
}
@Override
public void sacrificialDaggerCall(int amount, boolean isSacrifice)
{
bloodAltar.sacrificialDaggerCall(amount, isSacrifice);
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack itemstack)
{
return slot == 0;
}
@Override
public int getCapacity()
{
return bloodAltar.getCapacity();
}
@Override
public int getCurrentBlood()
{
return bloodAltar.getCurrentBlood();
}
@Override
public AltarTier getTier()
{
return bloodAltar.getTier();
}
@Override
public int getProgress()
{
return bloodAltar.getProgress();
}
@Override
public float getSacrificeMultiplier()
{
return bloodAltar.getSacrificeMultiplier();
}
@Override
public float getSelfSacrificeMultiplier()
{
return bloodAltar.getSelfSacrificeMultiplier();
}
@Override
public float getOrbMultiplier()
{
return bloodAltar.getOrbMultiplier();
}
@Override
public float getDislocationMultiplier()
{
return bloodAltar.getDislocationMultiplier();
}
@Override
public float getConsumptionMultiplier()
{
return bloodAltar.getConsumptionMultiplier();
}
@Override
public float getConsumptionRate()
{
return bloodAltar.getConsumptionRate();
}
@Override
public int getLiquidRequired()
{
return bloodAltar.getLiquidRequired();
}
@Override
public int getBufferCapacity()
{
return bloodAltar.getBufferCapacity();
}
@Override
public void startCycle()
{
bloodAltar.startCycle();
}
@Override
public void checkTier()
{
bloodAltar.checkTier();
}
@Override
public void requestPauseAfterCrafting(int cooldown)
{
bloodAltar.requestPauseAfterCrafting(cooldown);
}
@Override
public boolean isActive()
{
return bloodAltar.isActive();
}
@Override
public int fillMainTank(int amount)
{
return bloodAltar.fillMainTank(amount);
}
@Override
public void setActive()
{
bloodAltar.setActive();
}
@Override
public int getChargingRate()
{
return bloodAltar.getChargingRate();
}
@Override
public int getTotalCharge()
{
return bloodAltar.getTotalCharge();
}
@Override
public int getChargingFrequency()
{
return bloodAltar.getChargingFrequency();
}
public AltarTier getCurrentTierDisplayed()
{
return bloodAltar.getCurrentTierDisplayed();
}
public boolean setCurrentTierDisplayed(AltarTier altarTier)
{
return bloodAltar.setCurrentTierDisplayed(altarTier);
}
// @Override
// public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable Direction facing)
// {
// if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY)
// {
// return true;
// }
//
// return super.hasCapability(capability, facing);
// }
//
// @SuppressWarnings("unchecked")
// @Override
// public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> capability, @Nullable Direction facing)
// {
// if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY)
// {
// return (T) bloodAltar;
// }
//
// return super.getCapability(capability, facing);
// }
}

View file

@ -0,0 +1,317 @@
package wayoftime.bloodmagic.tile;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.inventory.ItemStackHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
import net.minecraft.util.NonNullList;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.InvWrapper;
import net.minecraftforge.items.wrapper.SidedInvWrapper;
import wayoftime.bloodmagic.tile.base.TileBase;
public class TileInventory extends TileBase implements IInventory
{
protected int[] syncedSlots = new int[0];
protected NonNullList<ItemStack> inventory;
LazyOptional<IItemHandler> handlerDown;
LazyOptional<IItemHandler> handlerUp;
LazyOptional<IItemHandler> handlerNorth;
LazyOptional<IItemHandler> handlerSouth;
LazyOptional<IItemHandler> handlerWest;
LazyOptional<IItemHandler> handlerEast;
private int size;
// IInventory
private String name;
public TileInventory(TileEntityType<?> type, int size, String name)
{
super(type);
this.inventory = NonNullList.withSize(size, ItemStack.EMPTY);
this.size = size;
this.name = name;
initializeItemHandlers();
}
protected boolean isSyncedSlot(int slot)
{
for (int s : this.syncedSlots)
{
if (s == slot)
{
return true;
}
}
return false;
}
@Override
public void deserialize(CompoundNBT tagCompound)
{
super.deserialize(tagCompound);
this.inventory = NonNullList.withSize(this.getSizeInventory(), ItemStack.EMPTY);
ItemStackHelper.loadAllItems(tagCompound, this.inventory);
// ListNBT tags = tagCompound.getList("Items", 10);
// inventory = NonNullList.withSize(size, ItemStack.EMPTY);
//
//
//
// for (int i = 0; i < tags.size(); i++)
// {
// if (!isSyncedSlot(i))
// {
// CompoundNBT data = tags.getCompoundTagAt(i);
// byte j = data.getByte("Slot");
//
// if (j >= 0 && j < inventory.size())
// {
// inventory.set(j, new ItemStack(data)); // No matter how much an i looks like a j, it is not one.
// // They are drastically different characters and cause
// // drastically different things to happen. Apparently I
// // didn't know this at one point. - TehNut
// }
// }
// }
}
@Override
public CompoundNBT serialize(CompoundNBT tagCompound)
{
super.serialize(tagCompound);
ItemStackHelper.saveAllItems(tagCompound, this.inventory);
// NBTTagList tags = new NBTTagList();
//
// for (int i = 0; i < inventory.size(); i++)
// {
// if ((!inventory.get(i).isEmpty()) && !isSyncedSlot(i))
// {
// CompoundNBT data = new CompoundNBT();
// data.putByte("Slot", (byte) i);
// inventory.get(i).write(data);
// tags.appendTag(data);
// }
// }
//
// tagCompound.setTag("Items", tags);
return tagCompound;
}
public void dropItems()
{
InventoryHelper.dropInventoryItems(getWorld(), getPos(), this);
}
@Override
public int getSizeInventory()
{
return size;
}
@Override
public ItemStack getStackInSlot(int index)
{
return inventory.get(index);
}
@Override
public ItemStack decrStackSize(int index, int count)
{
if (!getStackInSlot(index).isEmpty())
{
if (!getWorld().isRemote)
getWorld().notifyBlockUpdate(getPos(), getWorld().getBlockState(getPos()), getWorld().getBlockState(getPos()), 3);
if (getStackInSlot(index).getCount() <= count)
{
ItemStack itemStack = inventory.get(index);
inventory.set(index, ItemStack.EMPTY);
markDirty();
return itemStack;
}
ItemStack itemStack = inventory.get(index).split(count);
markDirty();
return itemStack;
}
return ItemStack.EMPTY;
}
@Override
public ItemStack removeStackFromSlot(int slot)
{
if (!inventory.get(slot).isEmpty())
{
ItemStack itemStack = inventory.get(slot);
setInventorySlotContents(slot, ItemStack.EMPTY);
return itemStack;
}
return ItemStack.EMPTY;
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack)
{
inventory.set(slot, stack);
if (!stack.isEmpty() && stack.getCount() > getInventoryStackLimit())
stack.setCount(getInventoryStackLimit());
markDirty();
if (!getWorld().isRemote)
getWorld().notifyBlockUpdate(getPos(), getWorld().getBlockState(getPos()), getWorld().getBlockState(getPos()), 3);
}
@Override
public int getInventoryStackLimit()
{
return 64;
}
@Override
public void openInventory(PlayerEntity player)
{
}
@Override
public void closeInventory(PlayerEntity player)
{
}
@Override
public boolean isItemValidForSlot(int index, ItemStack stack)
{
return true;
}
// IWorldNameable
// @Override
// public int getField(int id)
// {
// return 0;
// }
//
// @Override
// public void setField(int id, int value)
// {
//
// }
//
// @Override
// public int getFieldCount()
// {
// return 0;
// }
@Override
public void clear()
{
this.inventory = NonNullList.withSize(size, ItemStack.EMPTY);
}
@Override
public boolean isEmpty()
{
for (ItemStack stack : inventory) if (!stack.isEmpty())
return false;
return true;
}
@Override
public boolean isUsableByPlayer(PlayerEntity player)
{
return true;
}
// @Override
// public String getName()
// {
// return TextHelper.localize("tile.bloodmagic." + name + ".name");
// }
//
// @Override
// public boolean hasCustomName()
// {
// return true;
// }
//
// @Override
// public ITextComponent getDisplayName()
// {
// return new TextComponentString(getName());
// }
protected void initializeItemHandlers()
{
if (this instanceof ISidedInventory)
{
handlerDown = LazyOptional.of(() -> new SidedInvWrapper((ISidedInventory) this, Direction.DOWN));
handlerUp = LazyOptional.of(() -> new SidedInvWrapper((ISidedInventory) this, Direction.UP));
handlerNorth = LazyOptional.of(() -> new SidedInvWrapper((ISidedInventory) this, Direction.NORTH));
handlerSouth = LazyOptional.of(() -> new SidedInvWrapper((ISidedInventory) this, Direction.SOUTH));
handlerWest = LazyOptional.of(() -> new SidedInvWrapper((ISidedInventory) this, Direction.WEST));
handlerEast = LazyOptional.of(() -> new SidedInvWrapper((ISidedInventory) this, Direction.EAST));
} else
{
handlerDown = LazyOptional.of(() -> new InvWrapper(this));
handlerUp = handlerDown;
handlerNorth = handlerDown;
handlerSouth = handlerDown;
handlerWest = handlerDown;
handlerEast = handlerDown;
}
}
@SuppressWarnings("unchecked")
@Override
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> capability, @Nullable Direction facing)
{
if (facing != null && capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
{
switch (facing)
{
case DOWN:
return handlerDown.cast();
case EAST:
return handlerEast.cast();
case NORTH:
return handlerNorth.cast();
case SOUTH:
return handlerSouth.cast();
case UP:
return handlerUp.cast();
case WEST:
return handlerWest.cast();
}
} else if (facing == null && capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
{
return handlerDown.cast();
}
return super.getCapability(capability, facing);
}
// @Override
// public boolean hasCapability(Capability<?> capability, Direction facing)
// {
// return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
// }
}

View file

@ -0,0 +1,566 @@
package wayoftime.bloodmagic.tile;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.annotation.Nullable;
import com.google.common.base.Strings;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.registries.ObjectHolder;
import wayoftime.bloodmagic.BloodMagic;
import wayoftime.bloodmagic.common.item.ItemActivationCrystal;
import wayoftime.bloodmagic.core.data.Binding;
import wayoftime.bloodmagic.core.data.SoulNetwork;
import wayoftime.bloodmagic.demonaura.WorldDemonWillHandler;
import wayoftime.bloodmagic.event.RitualEvent;
import wayoftime.bloodmagic.iface.IBindable;
import wayoftime.bloodmagic.ritual.AreaDescriptor;
import wayoftime.bloodmagic.ritual.EnumReaderBoundaries;
import wayoftime.bloodmagic.ritual.IMasterRitualStone;
import wayoftime.bloodmagic.ritual.Ritual;
import wayoftime.bloodmagic.tile.base.TileTicking;
import wayoftime.bloodmagic.util.ChatUtil;
import wayoftime.bloodmagic.util.Constants;
import wayoftime.bloodmagic.util.helper.BindableHelper;
import wayoftime.bloodmagic.util.helper.NBTHelper;
import wayoftime.bloodmagic.util.helper.NetworkHelper;
import wayoftime.bloodmagic.util.helper.PlayerHelper;
import wayoftime.bloodmagic.util.helper.RitualHelper;
import wayoftime.bloodmagic.will.DemonWillHolder;
import wayoftime.bloodmagic.will.EnumDemonWillType;
public class TileMasterRitualStone extends TileTicking implements IMasterRitualStone
{
@ObjectHolder("bloodmagic:masterritualstone")
public static TileEntityType<TileMasterRitualStone> TYPE;
protected final Map<String, AreaDescriptor> modableRangeMap = new HashMap<>();
private UUID owner;
private SoulNetwork cachedNetwork;
private boolean active;
private boolean redstoned;
private int activeTime;
private int cooldown;
private Ritual currentRitual;
private Direction direction = Direction.NORTH;
private boolean inverted;
private List<EnumDemonWillType> currentActiveWillConfig = new ArrayList<>();
public TileMasterRitualStone(TileEntityType<?> type)
{
super(type);
}
public TileMasterRitualStone()
{
this(TYPE);
}
@Override
public void onUpdate()
{
if (getWorld().isRemote)
return;
if (isPowered() && isActive())
{
active = false;
redstoned = true;
stopRitual(Ritual.BreakType.REDSTONE);
return;
}
if (!isActive() && !isPowered() && isRedstoned() && getCurrentRitual() != null)
{
active = true;
ItemStack crystalStack = NBTHelper.checkNBT(ItemActivationCrystal.CrystalType.getStack(getCurrentRitual().getCrystalLevel()));
BindableHelper.applyBinding(crystalStack, new Binding(owner, PlayerHelper.getUsernameFromUUID(owner)));
activateRitual(crystalStack, null, getCurrentRitual());
redstoned = false;
}
if (getCurrentRitual() != null && isActive())
{
if (activeTime % getCurrentRitual().getRefreshTime() == 0)
performRitual(getWorld(), getPos());
activeTime++;
}
}
@Override
public void deserialize(CompoundNBT tag)
{
owner = tag.hasUniqueId("owner") ? tag.getUniqueId("owner") : null;
if (owner != null)
cachedNetwork = NetworkHelper.getSoulNetwork(owner);
currentRitual = BloodMagic.RITUAL_MANAGER.getRitual(tag.getString(Constants.NBT.CURRENT_RITUAL));
if (currentRitual != null)
{
CompoundNBT ritualTag = tag.getCompound(Constants.NBT.CURRENT_RITUAL_TAG);
if (!ritualTag.isEmpty())
{
currentRitual.readFromNBT(ritualTag);
}
}
active = tag.getBoolean(Constants.NBT.IS_RUNNING);
activeTime = tag.getInt(Constants.NBT.RUNTIME);
direction = Direction.values()[tag.getInt(Constants.NBT.DIRECTION)];
redstoned = tag.getBoolean(Constants.NBT.IS_REDSTONED);
for (EnumDemonWillType type : EnumDemonWillType.values())
{
if (tag.getBoolean("EnumWill" + type))
{
currentActiveWillConfig.add(type);
}
}
}
@Override
public CompoundNBT serialize(CompoundNBT tag)
{
String ritualId = BloodMagic.RITUAL_MANAGER.getId(getCurrentRitual());
if (owner != null)
tag.putUniqueId("owner", owner);
tag.putString(Constants.NBT.CURRENT_RITUAL, Strings.isNullOrEmpty(ritualId) ? "" : ritualId);
if (currentRitual != null)
{
CompoundNBT ritualTag = new CompoundNBT();
currentRitual.writeToNBT(ritualTag);
tag.put(Constants.NBT.CURRENT_RITUAL_TAG, ritualTag);
}
tag.putBoolean(Constants.NBT.IS_RUNNING, isActive());
tag.putInt(Constants.NBT.RUNTIME, getActiveTime());
tag.putInt(Constants.NBT.DIRECTION, direction.getIndex());
tag.putBoolean(Constants.NBT.IS_REDSTONED, redstoned);
for (EnumDemonWillType type : currentActiveWillConfig)
{
tag.putBoolean("EnumWill" + type, true);
}
return tag;
}
@Override
public boolean activateRitual(ItemStack activationCrystal, @Nullable PlayerEntity activator, Ritual ritual)
{
if (PlayerHelper.isFakePlayer(activator))
return false;
Binding binding = ((IBindable) activationCrystal.getItem()).getBinding(activationCrystal);
if (binding != null && ritual != null)
{
if (activationCrystal.getItem() instanceof ItemActivationCrystal)
{
int crystalLevel = ((ItemActivationCrystal) activationCrystal.getItem()).getCrystalLevel(activationCrystal);
if (RitualHelper.canCrystalActivate(ritual, crystalLevel))
{
if (!getWorld().isRemote)
{
SoulNetwork network = NetworkHelper.getSoulNetwork(binding);
if (!isRedstoned() && network.getCurrentEssence() < ritual.getActivationCost()
&& (activator != null && !activator.isCreative()))
{
activator.sendStatusMessage(new TranslationTextComponent("chat.bloodmagic.ritual.weak"), true);
return false;
}
if (currentRitual != null)
currentRitual.stopRitual(this, Ritual.BreakType.ACTIVATE);
RitualEvent.RitualActivatedEvent event = new RitualEvent.RitualActivatedEvent(this, binding.getOwnerId(), ritual, activator, activationCrystal, crystalLevel);
if (MinecraftForge.EVENT_BUS.post(event))
{
if (activator != null)
activator.sendStatusMessage(new TranslationTextComponent("chat.bloodmagic.ritual.prevent"), true);
return false;
}
if (ritual.activateRitual(this, activator, binding.getOwnerId()))
{
if (!isRedstoned() && (activator != null && !activator.isCreative()))
network.syphon(ticket(ritual.getActivationCost()));
if (activator != null)
activator.sendStatusMessage(new TranslationTextComponent("chat.bloodmagic.ritual.activate"), true);
this.active = true;
this.owner = binding.getOwnerId();
this.cachedNetwork = network;
this.currentRitual = ritual;
if (!checkBlockRanges(ritual.getModableRangeMap()))
addBlockRanges(ritual.getModableRangeMap());
notifyUpdate();
return true;
}
}
notifyUpdate();
return true;
}
}
} else
{
if (activator != null)
activator.sendStatusMessage(new TranslationTextComponent("chat.bloodmagic.ritual.notvalid"), true);
}
return false;
}
@Override
public void performRitual(World world, BlockPos pos)
{
if (!world.isRemote && getCurrentRitual() != null
&& BloodMagic.RITUAL_MANAGER.enabled(BloodMagic.RITUAL_MANAGER.getId(currentRitual), false))
{
if (RitualHelper.checkValidRitual(getWorld(), getPos(), currentRitual, getDirection()))
{
Ritual ritual = getCurrentRitual();
RitualEvent.RitualRunEvent event = new RitualEvent.RitualRunEvent(this, getOwner(), ritual);
if (MinecraftForge.EVENT_BUS.post(event))
return;
if (!checkBlockRanges(getCurrentRitual().getModableRangeMap()))
addBlockRanges(getCurrentRitual().getModableRangeMap());
getCurrentRitual().performRitual(this);
} else
{
stopRitual(Ritual.BreakType.BREAK_STONE);
}
}
}
@Override
public void stopRitual(Ritual.BreakType breakType)
{
if (!getWorld().isRemote && getCurrentRitual() != null)
{
RitualEvent.RitualStopEvent event = new RitualEvent.RitualStopEvent(this, getOwner(), getCurrentRitual(), breakType);
if (MinecraftForge.EVENT_BUS.post(event))
return;
getCurrentRitual().stopRitual(this, breakType);
if (breakType != Ritual.BreakType.REDSTONE)
{
this.currentRitual = null;
this.active = false;
this.activeTime = 0;
}
notifyUpdate();
}
}
@Override
public int getCooldown()
{
return cooldown;
}
@Override
public void setCooldown(int cooldown)
{
this.cooldown = cooldown;
}
@Override
public Direction getDirection()
{
return direction;
}
public void setDirection(Direction direction)
{
this.direction = direction;
}
@Override
public boolean areTanksEmpty()
{
return false;
}
@Override
public int getRunningTime()
{
return activeTime;
}
@Override
public UUID getOwner()
{
return owner;
}
public void setOwner(UUID owner)
{
this.owner = owner;
}
@Override
public SoulNetwork getOwnerNetwork()
{
return cachedNetwork;
}
@Override
public World getWorld()
{
return super.getWorld();
}
@Override
public BlockPos getPos()
{
return super.getPos();
}
@Override
public World getWorldObj()
{
return getWorld();
}
@Override
public BlockPos getBlockPos()
{
return getPos();
}
@Override
public String getNextBlockRange(String range)
{
if (this.currentRitual != null)
{
return this.currentRitual.getNextBlockRange(range);
}
return "";
}
@Override
public void provideInformationOfRitualToPlayer(PlayerEntity player)
{
if (this.currentRitual != null)
{
ChatUtil.sendNoSpam(player, this.currentRitual.provideInformationOfRitualToPlayer(player));
}
}
@Override
public void provideInformationOfRangeToPlayer(PlayerEntity player, String range)
{
if (this.currentRitual != null && this.currentRitual.getListOfRanges().contains(range))
{
ChatUtil.sendNoSpam(player, this.currentRitual.provideInformationOfRangeToPlayer(player, range));
}
}
@Override
public void setActiveWillConfig(PlayerEntity player, List<EnumDemonWillType> typeList)
{
this.currentActiveWillConfig = typeList;
}
@Override
public EnumReaderBoundaries setBlockRangeByBounds(PlayerEntity player, String range, BlockPos offset1, BlockPos offset2)
{
AreaDescriptor descriptor = this.getBlockRange(range);
DemonWillHolder holder = WorldDemonWillHandler.getWillHolder(world, getBlockPos());
EnumReaderBoundaries modificationType = currentRitual.canBlockRangeBeModified(range, descriptor, this, offset1, offset2, holder);
if (modificationType == EnumReaderBoundaries.SUCCESS)
descriptor.modifyAreaByBlockPositions(offset1, offset2);
return modificationType;
}
@Override
public List<EnumDemonWillType> getActiveWillConfig()
{
return new ArrayList<>(currentActiveWillConfig);
}
@Override
public void provideInformationOfWillConfigToPlayer(PlayerEntity player, List<EnumDemonWillType> typeList)
{
// There is probably an easier way to make expanded chat messages
if (typeList.size() >= 1)
{
Object[] translations = new TranslationTextComponent[typeList.size()];
StringBuilder constructedString = new StringBuilder("%s");
for (int i = 1; i < typeList.size(); i++)
{
constructedString.append(", %s");
}
for (int i = 0; i < typeList.size(); i++)
{
translations[i] = new TranslationTextComponent("tooltip.bloodmagic.currentBaseType." + typeList.get(i).name.toLowerCase());
}
ChatUtil.sendNoSpam(player, new TranslationTextComponent("ritual.bloodmagic.willConfig.set", new TranslationTextComponent(constructedString.toString(), translations)));
} else
{
ChatUtil.sendNoSpam(player, new TranslationTextComponent("ritual.bloodmagic.willConfig.void"));
}
}
public boolean isPowered()
{
if (inverted)
return !getWorld().isBlockPowered(getPos());
return getWorld().isBlockPowered(getPos());
}
public SoulNetwork getCachedNetwork()
{
return cachedNetwork;
}
public void setCachedNetwork(SoulNetwork cachedNetwork)
{
this.cachedNetwork = cachedNetwork;
}
public boolean isActive()
{
return active;
}
@Override
public void setActive(boolean active)
{
this.active = active;
}
public boolean isRedstoned()
{
return redstoned;
}
public void setRedstoned(boolean redstoned)
{
this.redstoned = redstoned;
}
public int getActiveTime()
{
return activeTime;
}
public void setActiveTime(int activeTime)
{
this.activeTime = activeTime;
}
public Ritual getCurrentRitual()
{
return currentRitual;
}
public void setCurrentRitual(Ritual currentRitual)
{
this.currentRitual = currentRitual;
}
public boolean isInverted()
{
return inverted;
}
public void setInverted(boolean inverted)
{
this.inverted = inverted;
}
public List<EnumDemonWillType> getCurrentActiveWillConfig()
{
return currentActiveWillConfig;
}
public void setCurrentActiveWillConfig(List<EnumDemonWillType> currentActiveWillConfig)
{
this.currentActiveWillConfig = currentActiveWillConfig;
}
/**
* Used to grab the range of a ritual for a given effect.
*
* @param range - Range that needs to be pulled.
* @return -
*/
public AreaDescriptor getBlockRange(String range)
{
if (modableRangeMap.containsKey(range))
{
return modableRangeMap.get(range);
}
return null;
}
@Override
public void addBlockRange(String range, AreaDescriptor defaultRange)
{
modableRangeMap.putIfAbsent(range, defaultRange.copy());
}
@Override
public void addBlockRanges(Map<String, AreaDescriptor> blockRanges)
{
for (Map.Entry<String, AreaDescriptor> entry : blockRanges.entrySet())
{
modableRangeMap.putIfAbsent(entry.getKey(), entry.getValue().copy());
}
}
@Override
public void setBlockRange(String range, AreaDescriptor defaultRange)
{
modableRangeMap.put(range, defaultRange.copy());
}
@Override
public void setBlockRanges(Map<String, AreaDescriptor> blockRanges)
{
for (Map.Entry<String, AreaDescriptor> entry : blockRanges.entrySet())
{
modableRangeMap.put(entry.getKey(), entry.getValue().copy());
}
}
public boolean checkBlockRanges(Map<String, AreaDescriptor> blockRanges)
{
for (Map.Entry<String, AreaDescriptor> entry : blockRanges.entrySet())
{
if (modableRangeMap.get(entry.getKey()) == null)
return false;
}
return true;
}
}

View file

@ -0,0 +1,379 @@
package wayoftime.bloodmagic.tile;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.IIntArray;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.registries.ObjectHolder;
import wayoftime.bloodmagic.api.event.BloodMagicCraftedEvent;
import wayoftime.bloodmagic.api.impl.BloodMagicAPI;
import wayoftime.bloodmagic.api.impl.recipe.RecipeTartaricForge;
import wayoftime.bloodmagic.tile.contailer.ContainerSoulForge;
import wayoftime.bloodmagic.util.Constants;
import wayoftime.bloodmagic.will.EnumDemonWillType;
import wayoftime.bloodmagic.will.IDemonWill;
import wayoftime.bloodmagic.will.IDemonWillConduit;
import wayoftime.bloodmagic.will.IDemonWillGem;
public class TileSoulForge extends TileInventory
implements ITickableTileEntity, INamedContainerProvider, IDemonWillConduit
{
@ObjectHolder("bloodmagic:soulforge")
public static TileEntityType<TileSoulForge> TYPE;
public static final int ticksRequired = 100;
public static final double worldWillTransferRate = 1;
public static final int soulSlot = 4;
public static final int outputSlot = 5;
// Input slots are from 0 to 3.
public int burnTime = 0;
public TileSoulForge(TileEntityType<?> type)
{
super(type, 6, "soulforge");
}
public TileSoulForge()
{
this(TYPE);
}
@Override
public void deserialize(CompoundNBT tag)
{
super.deserialize(tag);
burnTime = tag.getInt(Constants.NBT.SOUL_FORGE_BURN);
}
@Override
public CompoundNBT serialize(CompoundNBT tag)
{
super.serialize(tag);
tag.putInt(Constants.NBT.SOUL_FORGE_BURN, burnTime);
return tag;
}
public final IIntArray TileData = new IIntArray()
{
@Override
public int get(int index)
{
switch (index)
{
case 0:
return burnTime;
case 1:
return ticksRequired;
case 2:
return 0;
default:
throw new IllegalArgumentException("Invalid index: " + index);
}
}
@Override
public void set(int index, int value)
{
throw new IllegalStateException("Cannot set values through IIntArray");
}
@Override
public int size()
{
return 3;
}
};
@Override
public void tick()
{
if (!hasSoulGemOrSoul())
{
burnTime = 0;
return;
}
double soulsInGem = getWill(EnumDemonWillType.DEFAULT);
List<ItemStack> inputList = new ArrayList<>();
for (int i = 0; i < 4; i++) if (!getStackInSlot(i).isEmpty())
inputList.add(getStackInSlot(i));
RecipeTartaricForge recipe = BloodMagicAPI.INSTANCE.getRecipeRegistrar().getTartaricForge(world, inputList);
if (recipe != null && (soulsInGem >= recipe.getMinimumSouls() || burnTime > 0))
{
if (canCraft(recipe))
{
burnTime++;
if (burnTime == ticksRequired)
{
if (!getWorld().isRemote)
{
double requiredSouls = recipe.getSoulDrain();
if (requiredSouls > 0)
{
if (!getWorld().isRemote && soulsInGem >= recipe.getMinimumSouls())
{
consumeSouls(EnumDemonWillType.DEFAULT, requiredSouls);
}
}
if (!getWorld().isRemote && soulsInGem >= recipe.getMinimumSouls())
craftItem(recipe);
}
burnTime = 0;
} else if (burnTime > ticksRequired + 10)
{
burnTime = 0;
}
} else
{
burnTime = 0;
}
} else
{
burnTime = 0;
}
}
private boolean canCraft(RecipeTartaricForge recipe)
{
if (recipe == null)
return false;
ItemStack currentOutputStack = getStackInSlot(outputSlot);
if (recipe.getOutput().isEmpty())
return false;
if (currentOutputStack.isEmpty())
return true;
if (!currentOutputStack.isItemEqual(recipe.getOutput()))
return false;
int result = currentOutputStack.getCount() + recipe.getOutput().getCount();
return result <= getInventoryStackLimit() && result <= currentOutputStack.getMaxStackSize();
}
public void craftItem(RecipeTartaricForge recipe)
{
if (this.canCraft(recipe))
{
ItemStack currentOutputStack = getStackInSlot(outputSlot);
List<ItemStack> inputList = new ArrayList<>();
for (int i = 0; i < 4; i++) if (!getStackInSlot(i).isEmpty())
inputList.add(getStackInSlot(i).copy());
BloodMagicCraftedEvent.SoulForge event = new BloodMagicCraftedEvent.SoulForge(recipe.getOutput().copy(), inputList.toArray(new ItemStack[0]));
MinecraftForge.EVENT_BUS.post(event);
if (currentOutputStack.isEmpty())
{
setInventorySlotContents(outputSlot, event.getOutput());
} else if (ItemHandlerHelper.canItemStacksStack(currentOutputStack, event.getOutput()))
{
currentOutputStack.grow(event.getOutput().getCount());
}
consumeInventory();
}
}
@Override
public Container createMenu(int p_createMenu_1_, PlayerInventory p_createMenu_2_, PlayerEntity p_createMenu_3_)
{
assert world != null;
return new ContainerSoulForge(this, TileData, p_createMenu_1_, p_createMenu_2_);
}
@Override
public ITextComponent getDisplayName()
{
return new StringTextComponent("Hellfire Forge");
}
public boolean hasSoulGemOrSoul()
{
ItemStack soulStack = getStackInSlot(soulSlot);
if (!soulStack.isEmpty())
{
if (soulStack.getItem() instanceof IDemonWill || soulStack.getItem() instanceof IDemonWillGem)
{
return true;
}
}
return false;
}
public double getProgressForGui()
{
return ((double) burnTime) / ticksRequired;
}
public double getWill(EnumDemonWillType type)
{
ItemStack soulStack = getStackInSlot(soulSlot);
if (soulStack != null)
{
if (soulStack.getItem() instanceof IDemonWill
&& ((IDemonWill) soulStack.getItem()).getType(soulStack) == type)
{
IDemonWill soul = (IDemonWill) soulStack.getItem();
return soul.getWill(type, soulStack);
}
if (soulStack.getItem() instanceof IDemonWillGem)
{
IDemonWillGem soul = (IDemonWillGem) soulStack.getItem();
return soul.getWill(type, soulStack);
}
}
return 0;
}
public double consumeSouls(EnumDemonWillType type, double requested)
{
ItemStack soulStack = getStackInSlot(soulSlot);
if (soulStack != null)
{
if (soulStack.getItem() instanceof IDemonWill
&& ((IDemonWill) soulStack.getItem()).getType(soulStack) == type)
{
IDemonWill soul = (IDemonWill) soulStack.getItem();
double souls = soul.drainWill(type, soulStack, requested);
if (soul.getWill(type, soulStack) <= 0)
{
setInventorySlotContents(soulSlot, ItemStack.EMPTY);
}
return souls;
}
if (soulStack.getItem() instanceof IDemonWillGem)
{
IDemonWillGem soul = (IDemonWillGem) soulStack.getItem();
return soul.drainWill(type, soulStack, requested, true);
}
}
return 0;
}
public void consumeInventory()
{
for (int i = 0; i < 4; i++)
{
ItemStack inputStack = getStackInSlot(i);
if (!inputStack.isEmpty())
{
if (inputStack.getItem().hasContainerItem(inputStack))
{
setInventorySlotContents(i, inputStack.getItem().getContainerItem(inputStack));
continue;
}
inputStack.shrink(1);
if (inputStack.isEmpty())
{
setInventorySlotContents(i, ItemStack.EMPTY);
}
}
}
}
@Override
public int getWeight()
{
return 50;
}
@Override
public double fillDemonWill(EnumDemonWillType type, double amount, boolean doFill)
{
if (amount <= 0)
{
return 0;
}
if (!canFill(type))
{
return 0;
}
ItemStack stack = this.getStackInSlot(soulSlot);
if (stack.isEmpty() || !(stack.getItem() instanceof IDemonWillGem))
{
return 0;
}
IDemonWillGem willGem = (IDemonWillGem) stack.getItem();
return willGem.fillWill(type, stack, amount, doFill);
}
@Override
public double drainDemonWill(EnumDemonWillType type, double amount, boolean doDrain)
{
ItemStack stack = this.getStackInSlot(soulSlot);
if (stack.isEmpty() || !(stack.getItem() instanceof IDemonWillGem))
{
return 0;
}
IDemonWillGem willGem = (IDemonWillGem) stack.getItem();
double drained = amount;
double current = willGem.getWill(type, stack);
if (current < drained)
{
drained = current;
}
if (doDrain)
{
drained = willGem.drainWill(type, stack, drained, true);
}
return drained;
}
@Override
public boolean canFill(EnumDemonWillType type)
{
return true;
}
@Override
public boolean canDrain(EnumDemonWillType type)
{
return true;
}
@Override
public double getCurrentWill(EnumDemonWillType type)
{
return 0;
}
}

View file

@ -0,0 +1,138 @@
package wayoftime.bloodmagic.tile.base;
import net.minecraft.block.BlockState;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SUpdateTileEntityPacket;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
/**
* Base tile class.
* <p>
* Handles data syncing and core data writing/reading.
*/
public abstract class TileBase extends TileEntity
{
public TileBase(TileEntityType<?> type)
{
super(type);
}
/**
* read method
*/
@Override
public final void read(BlockState state, CompoundNBT compound)
{
super.read(state, compound);
deserializeBase(compound);
deserialize(compound);
}
@Override
public final CompoundNBT write(CompoundNBT compound)
{
super.write(compound);
serializeBase(compound);
return serialize(compound);
}
/**
* Called by {@link #func_230337_a_(BlockState, CompoundNBT)}
* <p>
* Internal data (such as coordinates) are handled for you. Just read the data
* you need.
*
* @param tagCompound - The tag compound to read from
*/
public void deserialize(CompoundNBT tagCompound)
{
}
/**
* Package private method for reading base data from the tag compound.
*
* @param tagCompound - The tag compound to read from
* @see TileTicking
*/
void deserializeBase(CompoundNBT tagCompound)
{
}
/**
* Called by {@link #writeToNBT(CompoundNBT)}
* <p>
* Internal data (such as coordinates) are handled for you. Just read the data
* you need.
*
* @param tagCompound - The tag compound to write to.
* @return the modified tag compound
*/
public CompoundNBT serialize(CompoundNBT tagCompound)
{
return tagCompound;
}
/**
* Package private method for writing base data to the tag compound.
*
* @param tagCompound - The tag compound to write to.
* @return the modified tag compound
* @see TileTicking
*/
CompoundNBT serializeBase(CompoundNBT tagCompound)
{
return tagCompound;
}
public void notifyUpdate()
{
BlockState state = getWorld().getBlockState(getPos());
getWorld().notifyBlockUpdate(getPos(), state, state, 3);
}
// // Data syncing
//
// @Override
// public boolean shouldRefresh(World world, BlockPos pos, BlockState oldState, BlockState newState)
// {
// return oldState.getBlock() != newState.getBlock();
// }
@Override
public final SUpdateTileEntityPacket getUpdatePacket()
{
return new SUpdateTileEntityPacket(getPos(), -999, getUpdateTag());
}
// @Override
// public void handleUpdateTag(BlockState state, CompoundNBT tag)
// {
// read(state, tag);
// }
@Override
@OnlyIn(Dist.CLIENT)
public final void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt)
{
super.onDataPacket(net, pkt);
handleUpdateTag(getBlockState(), pkt.getNbtCompound());
}
@Override
public final CompoundNBT getUpdateTag()
{
return write(new CompoundNBT());
}
@Override
public final void handleUpdateTag(BlockState state, CompoundNBT tag)
{
read(state, tag);
}
}

View file

@ -0,0 +1,71 @@
package wayoftime.bloodmagic.tile.base;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.ITickableTileEntity;
import net.minecraft.tileentity.TileEntityType;
/**
* Base class for tiles that tick. Allows disabling the ticking
* programmatically.
*/
// TODO - Move implementations that depend on existed ticks to new methods from here.
public abstract class TileTicking extends TileBase implements ITickableTileEntity
{
private int ticksExisted;
private boolean shouldTick = true;
public TileTicking(TileEntityType<?> type)
{
super(type);
}
@Override
public final void tick()
{
if (shouldTick())
{
ticksExisted++;
onUpdate();
}
}
@Override
void deserializeBase(CompoundNBT tagCompound)
{
this.ticksExisted = tagCompound.getInt("ticksExisted");
this.shouldTick = tagCompound.getBoolean("shouldTick");
}
@Override
CompoundNBT serializeBase(CompoundNBT tagCompound)
{
tagCompound.putInt("ticksExisted", getTicksExisted());
tagCompound.putBoolean("shouldTick", shouldTick());
return tagCompound;
}
/**
* Called every tick that {@link #shouldTick()} is true.
*/
public abstract void onUpdate();
public int getTicksExisted()
{
return ticksExisted;
}
public void resetLifetime()
{
ticksExisted = 0;
}
public boolean shouldTick()
{
return shouldTick;
}
public void setShouldTick(boolean shouldTick)
{
this.shouldTick = shouldTick;
}
}

View file

@ -0,0 +1,198 @@
package wayoftime.bloodmagic.tile.contailer;
import java.util.Optional;
import javax.annotation.Nullable;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil;
import wayoftime.bloodmagic.common.block.BloodMagicBlocks;
import wayoftime.bloodmagic.common.tags.BloodMagicTags;
import wayoftime.bloodmagic.tile.TileAlchemicalReactionChamber;
public class ContainerAlchemicalReactionChamber extends Container
{
public final TileAlchemicalReactionChamber tileARC;
// public ContainerSoulForge(InventoryPlayer inventoryPlayer, IInventory tileARC)
// {
// this.tileARC = tileARC;
//
// }
public ContainerAlchemicalReactionChamber(int windowId, PlayerInventory playerInventory, PacketBuffer extraData)
{
this((TileAlchemicalReactionChamber) playerInventory.player.world.getTileEntity(extraData.readBlockPos()), windowId, playerInventory);
}
public ContainerAlchemicalReactionChamber(@Nullable TileAlchemicalReactionChamber tile, int windowId, PlayerInventory playerInventory)
{
super(BloodMagicBlocks.ARC_CONTAINER.get(), windowId);
this.tileARC = tile;
this.setup(playerInventory, tile);
}
public void setup(PlayerInventory inventory, IInventory tileARC)
{
this.addSlot(new SlotARCTool(tileARC, TileAlchemicalReactionChamber.ARC_TOOL_SLOT, 35, 51));
for (int i = 0; i < TileAlchemicalReactionChamber.NUM_OUTPUTS; i++)
{
this.addSlot(new SlotOutput(tileARC, TileAlchemicalReactionChamber.OUTPUT_SLOT + i, 116, 15 + i * 18));
}
this.addSlot(new Slot(tileARC, TileAlchemicalReactionChamber.INPUT_SLOT, 71, 15));
this.addSlot(new SlotBucket(tileARC, TileAlchemicalReactionChamber.INPUT_BUCKET_SLOT, 8, 15, true));
this.addSlot(new SlotBucket(tileARC, TileAlchemicalReactionChamber.OUTPUT_BUCKET_SLOT, 152, 87, false));
// this.addSlot(new SlotSoul(tileARC, TileSoulForge.soulSlot, 152, 51));
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 9; j++)
{
addSlot(new Slot(inventory, j + i * 9 + 9, 8 + j * 18, 123 + i * 18));
}
}
for (int i = 0; i < 9; i++)
{
addSlot(new Slot(inventory, i, 8 + i * 18, 181));
}
}
@Override
public ItemStack transferStackInSlot(PlayerEntity playerIn, int index)
{
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.inventorySlots.get(index);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if ((index >= 1 && index < 1 + 5) || (index == 7 || index == 8))// Attempting to transfer from output slots
// or bucket slots
{
if (!this.mergeItemStack(itemstack1, 9, 9 + 36, true))
{
return ItemStack.EMPTY;
}
slot.onSlotChange(itemstack1, itemstack);
} else if (index > 9) // Attempting to transfer from main inventory
{
if (itemstack1.getItem().isIn(BloodMagicTags.ARC_TOOL)) // Try the tool slot first
{
if (!this.mergeItemStack(itemstack1, 0, 1, false))
{
return ItemStack.EMPTY;
}
} else if (isBucket(itemstack1, true)) // If it's a full bucket, transfer to tank filler slot.
{
if (!this.mergeItemStack(itemstack1, 7, 8, false))
{
return ItemStack.EMPTY;
}
} else if (isBucket(itemstack1, false)) // If it's an empty bucket, transfer to tank emptier slot.
{
if (!this.mergeItemStack(itemstack1, 8, 9, false))
{
return ItemStack.EMPTY;
}
} else if (!this.mergeItemStack(itemstack1, 6, 7, false))
{
return ItemStack.EMPTY;
}
} else if (!this.mergeItemStack(itemstack1, 9, 45, false)) // Attempting to transfer from input slots
{
return ItemStack.EMPTY;
}
if (itemstack1.getCount() == 0)
{
slot.putStack(ItemStack.EMPTY);
} else
{
slot.onSlotChanged();
}
if (itemstack1.getCount() == itemstack.getCount())
{
return ItemStack.EMPTY;
}
slot.onTake(playerIn, itemstack1);
}
return itemstack;
}
@Override
public boolean canInteractWith(PlayerEntity playerIn)
{
return this.tileARC.isUsableByPlayer(playerIn);
}
private class SlotARCTool extends Slot
{
public SlotARCTool(IInventory inventory, int slotIndex, int x, int y)
{
super(inventory, slotIndex, x, y);
}
@Override
public boolean isItemValid(ItemStack itemStack)
{
return itemStack.getItem().isIn(BloodMagicTags.ARC_TOOL);
}
}
private class SlotBucket extends Slot
{
private final boolean needsFullBucket;
public SlotBucket(IInventory inventory, int slotIndex, int x, int y, boolean needsFullBucket)
{
super(inventory, slotIndex, x, y);
this.needsFullBucket = needsFullBucket;
}
@Override
public boolean isItemValid(ItemStack itemStack)
{
Optional<FluidStack> fluidStackOptional = FluidUtil.getFluidContained(itemStack);
return fluidStackOptional.isPresent() && ((needsFullBucket && !fluidStackOptional.get().isEmpty())
|| (!needsFullBucket && fluidStackOptional.get().isEmpty()));
}
}
private static boolean isBucket(ItemStack stack, boolean requiredFull)
{
Optional<FluidStack> fluidStackOptional = FluidUtil.getFluidContained(stack);
return fluidStackOptional.isPresent() && ((requiredFull && !fluidStackOptional.get().isEmpty())
|| (!requiredFull && fluidStackOptional.get().isEmpty()));
}
private class SlotOutput extends Slot
{
public SlotOutput(IInventory inventory, int slotIndex, int x, int y)
{
super(inventory, slotIndex, x, y);
}
@Override
public boolean isItemValid(ItemStack stack)
{
return false;
}
}
}

View file

@ -0,0 +1,154 @@
package wayoftime.bloodmagic.tile.contailer;
import javax.annotation.Nullable;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.IIntArray;
import net.minecraft.util.IntArray;
import wayoftime.bloodmagic.common.block.BloodMagicBlocks;
import wayoftime.bloodmagic.tile.TileSoulForge;
import wayoftime.bloodmagic.will.IDemonWill;
import wayoftime.bloodmagic.will.IDemonWillGem;
public class ContainerSoulForge extends Container
{
public final IInventory tileForge;
public final IIntArray data;
// public ContainerSoulForge(InventoryPlayer inventoryPlayer, IInventory tileForge)
// {
// this.tileForge = tileForge;
//
// }
public ContainerSoulForge(int windowId, PlayerInventory playerInventory, PacketBuffer extraData)
{
this((TileSoulForge) playerInventory.player.world.getTileEntity(extraData.readBlockPos()), new IntArray(5), windowId, playerInventory);
}
public ContainerSoulForge(@Nullable TileSoulForge tile, IIntArray data, int windowId, PlayerInventory playerInventory)
{
super(BloodMagicBlocks.SOUL_FORGE_CONTAINER.get(), windowId);
this.tileForge = tile;
this.setup(playerInventory, tile);
this.data = data;
}
public void setup(PlayerInventory inventory, IInventory tileForge)
{
this.addSlot(new Slot(tileForge, 0, 8, 15));
this.addSlot(new Slot(tileForge, 1, 80, 15));
this.addSlot(new Slot(tileForge, 2, 8, 87));
this.addSlot(new Slot(tileForge, 3, 80, 87));
this.addSlot(new SlotSoul(tileForge, TileSoulForge.soulSlot, 152, 51));
this.addSlot(new SlotOutput(tileForge, TileSoulForge.outputSlot, 44, 51));
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 9; j++)
{
addSlot(new Slot(inventory, j + i * 9 + 9, 8 + j * 18, 123 + i * 18));
}
}
for (int i = 0; i < 9; i++)
{
addSlot(new Slot(inventory, i, 8 + i * 18, 181));
}
}
@Override
public ItemStack transferStackInSlot(PlayerEntity playerIn, int index)
{
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.inventorySlots.get(index);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (index == 5)
{
if (!this.mergeItemStack(itemstack1, 6, 6 + 36, true))
{
return ItemStack.EMPTY;
}
slot.onSlotChange(itemstack1, itemstack);
} else if (index > 5)
{
if (itemstack1.getItem() instanceof IDemonWill || itemstack1.getItem() instanceof IDemonWillGem)
{
if (!this.mergeItemStack(itemstack1, 4, 5, false))
{
return ItemStack.EMPTY;
}
} else if (!this.mergeItemStack(itemstack1, 0, 4, false))
{
return ItemStack.EMPTY;
}
} else if (!this.mergeItemStack(itemstack1, 6, 42, false))
{
return ItemStack.EMPTY;
}
if (itemstack1.getCount() == 0)
{
slot.putStack(ItemStack.EMPTY);
} else
{
slot.onSlotChanged();
}
if (itemstack1.getCount() == itemstack.getCount())
{
return ItemStack.EMPTY;
}
slot.onTake(playerIn, itemstack1);
}
return itemstack;
}
@Override
public boolean canInteractWith(PlayerEntity playerIn)
{
return this.tileForge.isUsableByPlayer(playerIn);
}
private class SlotSoul extends Slot
{
public SlotSoul(IInventory inventory, int slotIndex, int x, int y)
{
super(inventory, slotIndex, x, y);
}
@Override
public boolean isItemValid(ItemStack itemStack)
{
return itemStack.getItem() instanceof IDemonWillGem || itemStack.getItem() instanceof IDemonWill;
}
}
private class SlotOutput extends Slot
{
public SlotOutput(IInventory inventory, int slotIndex, int x, int y)
{
super(inventory, slotIndex, x, y);
}
@Override
public boolean isItemValid(ItemStack stack)
{
return false;
}
}
}