Run formatter

This commit is contained in:
Nicholas Ignoffo 2017-08-15 21:30:48 -07:00
parent 61c44a831b
commit 08258fd6ef
606 changed files with 13464 additions and 22975 deletions

View file

@ -1,40 +1,36 @@
package WayofTime.bloodmagic.tile;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.alchemyCrafting.AlchemyArrayEffect;
import WayofTime.bloodmagic.api.iface.IAlchemyArray;
import WayofTime.bloodmagic.api.registry.AlchemyArrayRecipeRegistry;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.alchemyCrafting.AlchemyArrayEffect;
import WayofTime.bloodmagic.api.iface.IAlchemyArray;
import WayofTime.bloodmagic.api.registry.AlchemyArrayRecipeRegistry;
public class TileAlchemyArray extends TileInventory implements ITickable, IAlchemyArray
{
public class TileAlchemyArray extends TileInventory implements ITickable, IAlchemyArray {
public boolean isActive = false;
public int activeCounter = 0;
public EnumFacing rotation = EnumFacing.HORIZONTALS[0];;
public EnumFacing rotation = EnumFacing.HORIZONTALS[0];
;
private String key = "empty";
private AlchemyArrayEffect arrayEffect;
public TileAlchemyArray()
{
public TileAlchemyArray() {
super(2, "alchemyArray");
}
public void onEntityCollidedWithBlock(IBlockState state, Entity entity)
{
if (arrayEffect != null)
{
public void onEntityCollidedWithBlock(IBlockState state, Entity entity) {
if (arrayEffect != null) {
arrayEffect.onEntityCollidedWithBlock(this, getWorld(), pos, state, entity);
}
}
@Override
public void deserialize(NBTTagCompound tagCompound)
{
public void deserialize(NBTTagCompound tagCompound) {
super.deserialize(tagCompound);
this.isActive = tagCompound.getBoolean("isActive");
this.activeCounter = tagCompound.getInteger("activeCounter");
@ -43,15 +39,13 @@ public class TileAlchemyArray extends TileInventory implements ITickable, IAlche
NBTTagCompound arrayTag = tagCompound.getCompoundTag("arrayTag");
arrayEffect = AlchemyArrayRecipeRegistry.getAlchemyArrayEffect(key);
if (arrayEffect != null)
{
if (arrayEffect != null) {
arrayEffect.readFromNBT(arrayTag);
}
}
@Override
public NBTTagCompound serialize(NBTTagCompound tagCompound)
{
public NBTTagCompound serialize(NBTTagCompound tagCompound) {
super.serialize(tagCompound);
tagCompound.setBoolean("isActive", isActive);
tagCompound.setInteger("activeCounter", activeCounter);
@ -59,8 +53,7 @@ public class TileAlchemyArray extends TileInventory implements ITickable, IAlche
tagCompound.setInteger(Constants.NBT.DIRECTION, rotation.getHorizontalIndex());
NBTTagCompound arrayTag = new NBTTagCompound();
if (arrayEffect != null)
{
if (arrayEffect != null) {
arrayEffect.writeToNBT(arrayTag);
}
tagCompound.setTag("arrayTag", arrayTag);
@ -69,19 +62,15 @@ public class TileAlchemyArray extends TileInventory implements ITickable, IAlche
}
@Override
public int getInventoryStackLimit()
{
public int getInventoryStackLimit() {
return 1;
}
@Override
public void update()
{
if (isActive && attemptCraft())
{
public void update() {
if (isActive && attemptCraft()) {
activeCounter++;
} else
{
} else {
isActive = false;
activeCounter = 0;
arrayEffect = null;
@ -93,49 +82,38 @@ public class TileAlchemyArray extends TileInventory implements ITickable, IAlche
* This occurs when the block is destroyed.
*/
@Override
public void dropItems()
{
public void dropItems() {
super.dropItems();
if (arrayEffect != null)
{
if (arrayEffect != null) {
}
}
public boolean attemptCraft()
{
public boolean attemptCraft() {
AlchemyArrayEffect effect = AlchemyArrayRecipeRegistry.getAlchemyArrayEffect(this.getStackInSlot(0), this.getStackInSlot(1));
if (effect != null)
{
if (arrayEffect == null)
{
if (effect != null) {
if (arrayEffect == null) {
arrayEffect = effect;
key = effect.getKey();
} else
{
} else {
String effectKey = effect.getKey();
if (effectKey.equals(key))
{
if (effectKey.equals(key)) {
//Good! Moving on.
} else
{
} else {
//Something has changed, therefore we have to move our stuffs.
//TODO: Add an AlchemyArrayEffect.onBreak(); ?
arrayEffect = effect;
key = effect.getKey();
}
}
} else
{
} else {
return false;
}
if (arrayEffect != null)
{
if (arrayEffect != null) {
isActive = true;
if (arrayEffect.update(this, this.activeCounter))
{
if (arrayEffect.update(this, this.activeCounter)) {
this.decrStackSize(0, 1);
this.decrStackSize(1, 1);
this.getWorld().setBlockToAir(getPos());

View file

@ -1,9 +1,13 @@
package WayofTime.bloodmagic.tile;
import java.util.ArrayList;
import java.util.List;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.orb.BloodOrb;
import WayofTime.bloodmagic.api.orb.IBloodOrb;
import WayofTime.bloodmagic.api.recipe.AlchemyTableRecipe;
import WayofTime.bloodmagic.api.registry.AlchemyTableRecipeRegistry;
import WayofTime.bloodmagic.api.saving.SoulNetwork;
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
import com.google.common.base.Strings;
import net.minecraft.block.state.IBlockState;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
@ -16,17 +20,11 @@ import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.items.wrapper.SidedInvWrapper;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.saving.SoulNetwork;
import WayofTime.bloodmagic.api.orb.IBloodOrb;
import WayofTime.bloodmagic.api.recipe.AlchemyTableRecipe;
import WayofTime.bloodmagic.api.registry.AlchemyTableRecipeRegistry;
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
import com.google.common.base.Strings;
import java.util.ArrayList;
import java.util.List;
public class TileAlchemyTable extends TileInventory implements ISidedInventory, ITickable
{
public class TileAlchemyTable extends TileInventory implements ISidedInventory, ITickable {
public static final int orbSlot = 6;
public static final int toolSlot = 7;
public static final int outputSlot = 8;
@ -37,26 +35,22 @@ public class TileAlchemyTable extends TileInventory implements ISidedInventory,
public int ticksRequired = 1;
public BlockPos connectedPos = BlockPos.ORIGIN;
public boolean[] blockedSlots = new boolean[] { false, false, false, false, false, false };
public boolean[] blockedSlots = new boolean[]{false, false, false, false, false, false};
public TileAlchemyTable()
{
public TileAlchemyTable() {
super(9, "alchemyTable");
}
public void setInitialTableParameters(EnumFacing direction, boolean isSlave, BlockPos connectedPos)
{
public void setInitialTableParameters(EnumFacing direction, boolean isSlave, BlockPos connectedPos) {
this.isSlave = isSlave;
this.connectedPos = connectedPos;
if (!isSlave)
{
if (!isSlave) {
this.direction = direction;
}
}
public boolean isInvisible()
{
public boolean isInvisible() {
return isSlave();
}
@ -64,15 +58,13 @@ public class TileAlchemyTable extends TileInventory implements ISidedInventory,
return !(slot < 6 && slot >= 0) || !blockedSlots[slot];
}
public void toggleInputSlotAccessible(int slot)
{
public void toggleInputSlotAccessible(int slot) {
if (slot < 6 && slot >= 0)
blockedSlots[slot] = !blockedSlots[slot];
}
@Override
public void deserialize(NBTTagCompound tag)
{
public void deserialize(NBTTagCompound tag) {
super.deserialize(tag);
isSlave = tag.getBoolean("isSlave");
@ -88,8 +80,7 @@ public class TileAlchemyTable extends TileInventory implements ISidedInventory,
}
@Override
public NBTTagCompound serialize(NBTTagCompound tag)
{
public NBTTagCompound serialize(NBTTagCompound tag) {
super.serialize(tag);
tag.setBoolean("isSlave", isSlave);
@ -111,19 +102,14 @@ public class TileAlchemyTable extends TileInventory implements ISidedInventory,
@SuppressWarnings("unchecked")
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing)
{
if (facing != null && capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
{
if (this.isSlave())
{
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
if (facing != null && capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
if (this.isSlave()) {
TileEntity tile = getWorld().getTileEntity(connectedPos);
if (tile instanceof TileAlchemyTable)
{
if (tile instanceof TileAlchemyTable) {
return (T) new SidedInvWrapper((TileAlchemyTable) tile, facing);
}
} else
{
} else {
return (T) new SidedInvWrapper(this, facing);
}
}
@ -132,73 +118,58 @@ public class TileAlchemyTable extends TileInventory implements ISidedInventory,
}
@Override
public int[] getSlotsForFace(EnumFacing side)
{
switch (side)
{
case DOWN:
return new int[] { outputSlot };
case UP:
return new int[] { orbSlot, toolSlot };
default:
return new int[] { 0, 1, 2, 3, 4, 5 };
public int[] getSlotsForFace(EnumFacing side) {
switch (side) {
case DOWN:
return new int[]{outputSlot};
case UP:
return new int[]{orbSlot, toolSlot};
default:
return new int[]{0, 1, 2, 3, 4, 5};
}
}
@Override
public boolean canInsertItem(int index, ItemStack stack, EnumFacing direction)
{
switch (direction)
{
case DOWN:
return index != outputSlot && index != orbSlot && index != toolSlot;
case UP:
if (index == orbSlot && !stack.isEmpty() && stack.getItem() instanceof IBloodOrb)
{
return true;
} else if (index == toolSlot)
{
return false; //TODO:
} else
{
return true;
}
default:
return getAccessibleInputSlots(direction).contains(index);
public boolean canInsertItem(int index, ItemStack stack, EnumFacing direction) {
switch (direction) {
case DOWN:
return index != outputSlot && index != orbSlot && index != toolSlot;
case UP:
if (index == orbSlot && !stack.isEmpty() && stack.getItem() instanceof IBloodOrb) {
return true;
} else if (index == toolSlot) {
return false; //TODO:
} else {
return true;
}
default:
return getAccessibleInputSlots(direction).contains(index);
}
}
@Override
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction)
{
switch (direction)
{
case DOWN:
return index == outputSlot;
case UP:
if (index == orbSlot && !stack.isEmpty() && stack.getItem() instanceof IBloodOrb)
{
return true;
} else if (index == toolSlot)
{
return true; //TODO:
} else
{
return true;
}
default:
return getAccessibleInputSlots(direction).contains(index);
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction) {
switch (direction) {
case DOWN:
return index == outputSlot;
case UP:
if (index == orbSlot && !stack.isEmpty() && stack.getItem() instanceof IBloodOrb) {
return true;
} else if (index == toolSlot) {
return true; //TODO:
} else {
return true;
}
default:
return getAccessibleInputSlots(direction).contains(index);
}
}
public List<Integer> getAccessibleInputSlots(EnumFacing direction)
{
public List<Integer> getAccessibleInputSlots(EnumFacing direction) {
List<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < 6; i++)
{
if (isInputSlotAccessible(i))
{
for (int i = 0; i < 6; i++) {
if (isInputSlotAccessible(i)) {
list.add(i);
}
}
@ -207,19 +178,15 @@ public class TileAlchemyTable extends TileInventory implements ISidedInventory,
}
@Override
public void update()
{
if (isSlave())
{
public void update() {
if (isSlave()) {
return;
}
List<ItemStack> inputList = new ArrayList<ItemStack>();
for (int i = 0; i < 6; i++)
{
if (!getStackInSlot(i).isEmpty())
{
for (int i = 0; i < 6; i++) {
if (!getStackInSlot(i).isEmpty()) {
inputList.add(getStackInSlot(i));
}
}
@ -227,34 +194,26 @@ public class TileAlchemyTable extends TileInventory implements ISidedInventory,
int tier = getTierOfOrb();
AlchemyTableRecipe recipe = AlchemyTableRecipeRegistry.getMatchingRecipe(inputList, getWorld(), getPos());
if (recipe != null && (burnTime > 0 || (!getWorld().isRemote && tier >= recipe.getTierRequired() && this.getContainedLp() >= recipe.getLpDrained())))
{
if (burnTime == 1)
{
if (recipe != null && (burnTime > 0 || (!getWorld().isRemote && tier >= recipe.getTierRequired() && this.getContainedLp() >= recipe.getLpDrained()))) {
if (burnTime == 1) {
IBlockState state = getWorld().getBlockState(pos);
getWorld().notifyBlockUpdate(getPos(), state, state, 3);
}
if (canCraft(inputList, recipe))
{
if (canCraft(inputList, recipe)) {
ticksRequired = recipe.getTicksRequired();
burnTime++;
if (burnTime == ticksRequired)
{
if (!getWorld().isRemote)
{
if (burnTime == ticksRequired) {
if (!getWorld().isRemote) {
int requiredLp = recipe.getLpDrained();
if (requiredLp > 0)
{
if (!getWorld().isRemote)
{
if (requiredLp > 0) {
if (!getWorld().isRemote) {
consumeLp(requiredLp);
}
}
if (!getWorld().isRemote)
{
if (!getWorld().isRemote) {
craftItem(inputList, recipe);
}
}
@ -263,29 +222,23 @@ public class TileAlchemyTable extends TileInventory implements ISidedInventory,
IBlockState state = getWorld().getBlockState(pos);
getWorld().notifyBlockUpdate(getPos(), state, state, 3);
} else if (burnTime > ticksRequired + 10)
{
} else if (burnTime > ticksRequired + 10) {
burnTime = 0;
}
} else
{
} else {
burnTime = 0;
}
} else
{
} else {
burnTime = 0;
}
}
public double getProgressForGui()
{
public double getProgressForGui() {
return ((double) burnTime) / ticksRequired;
}
private boolean canCraft(List<ItemStack> inputList, AlchemyTableRecipe recipe)
{
if (recipe == null)
{
private boolean canCraft(List<ItemStack> inputList, AlchemyTableRecipe recipe) {
if (recipe == null) {
return false;
}
@ -301,13 +254,10 @@ public class TileAlchemyTable extends TileInventory implements ISidedInventory,
return result <= getInventoryStackLimit() && result <= currentOutputStack.getMaxStackSize();
}
public int getTierOfOrb()
{
public int getTierOfOrb() {
ItemStack orbStack = getStackInSlot(orbSlot);
if (!orbStack.isEmpty())
{
if (orbStack.getItem() instanceof IBloodOrb)
{
if (!orbStack.isEmpty()) {
if (orbStack.getItem() instanceof IBloodOrb) {
BloodOrb orb = ((IBloodOrb) orbStack.getItem()).getOrb(orbStack);
return orb == null ? 0 : orb.getTier();
}
@ -316,24 +266,19 @@ public class TileAlchemyTable extends TileInventory implements ISidedInventory,
return 0;
}
public int getContainedLp()
{
public int getContainedLp() {
ItemStack orbStack = getStackInSlot(orbSlot);
if (!orbStack.isEmpty())
{
if (orbStack.getItem() instanceof IBloodOrb)
{
if (!orbStack.isEmpty()) {
if (orbStack.getItem() instanceof IBloodOrb) {
NBTTagCompound itemTag = orbStack.getTagCompound();
if (itemTag == null)
{
if (itemTag == null) {
return 0;
}
String ownerUUID = itemTag.getString(Constants.NBT.OWNER_UUID);
if (Strings.isNullOrEmpty(ownerUUID))
{
if (Strings.isNullOrEmpty(ownerUUID)) {
return 0;
}
@ -346,18 +291,14 @@ public class TileAlchemyTable extends TileInventory implements ISidedInventory,
return 0;
}
public void craftItem(List<ItemStack> inputList, AlchemyTableRecipe recipe)
{
if (this.canCraft(inputList, recipe))
{
public void craftItem(List<ItemStack> inputList, AlchemyTableRecipe recipe) {
if (this.canCraft(inputList, recipe)) {
ItemStack outputStack = recipe.getRecipeOutput(inputList);
ItemStack currentOutputStack = getStackInSlot(outputSlot);
if (currentOutputStack.isEmpty())
{
if (currentOutputStack.isEmpty()) {
setInventorySlotContents(outputSlot, outputStack);
} else if (ItemHandlerHelper.canItemStacksStack(outputStack, currentOutputStack))
{
} else if (ItemHandlerHelper.canItemStacksStack(outputStack, currentOutputStack)) {
currentOutputStack.grow(outputStack.getCount());
}
@ -365,16 +306,12 @@ public class TileAlchemyTable extends TileInventory implements ISidedInventory,
}
}
public int consumeLp(int requested)
{
public int consumeLp(int requested) {
ItemStack orbStack = getStackInSlot(orbSlot);
if (!orbStack.isEmpty())
{
if (orbStack.getItem() instanceof IBloodOrb)
{
if (NetworkHelper.syphonFromContainer(orbStack, requested))
{
if (!orbStack.isEmpty()) {
if (orbStack.getItem() instanceof IBloodOrb) {
if (NetworkHelper.syphonFromContainer(orbStack, requested)) {
return requested;
}
}
@ -383,34 +320,19 @@ public class TileAlchemyTable extends TileInventory implements ISidedInventory,
return 0;
}
public void consumeInventory(AlchemyTableRecipe recipe)
{
public void consumeInventory(AlchemyTableRecipe recipe) {
ItemStack[] input = new ItemStack[6];
for (int i = 0; i < 6; i++)
{
for (int i = 0; i < 6; i++) {
input[i] = getStackInSlot(i);
}
ItemStack[] result = recipe.getRemainingItems(input);
for (int i = 0; i < 6; i++)
{
for (int i = 0; i < 6; i++) {
setInventorySlotContents(i, result[i]);
}
}
public static int getOrbSlot() {
return orbSlot;
}
public static int getToolSlot() {
return toolSlot;
}
public static int getOutputSlot() {
return outputSlot;
}
public EnumFacing getDirection() {
return direction;
}
@ -434,4 +356,16 @@ public class TileAlchemyTable extends TileInventory implements ISidedInventory,
public boolean[] getBlockedSlots() {
return blockedSlots;
}
public static int getOrbSlot() {
return orbSlot;
}
public static int getToolSlot() {
return toolSlot;
}
public static int getOutputSlot() {
return outputSlot;
}
}

View file

@ -1,31 +1,28 @@
package WayofTime.bloodmagic.tile;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import WayofTime.bloodmagic.altar.BloodAltar;
import WayofTime.bloodmagic.api.altar.EnumAltarTier;
import WayofTime.bloodmagic.api.altar.IBloodAltar;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import WayofTime.bloodmagic.altar.BloodAltar;
import WayofTime.bloodmagic.api.altar.EnumAltarTier;
import WayofTime.bloodmagic.api.altar.IBloodAltar;
public class TileAltar extends TileInventory implements IBloodAltar, ITickable
{
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class TileAltar extends TileInventory implements IBloodAltar, ITickable {
private BloodAltar bloodAltar;
public TileAltar()
{
public TileAltar() {
super(1, "altar");
this.bloodAltar = new BloodAltar(this);
}
@Override
public void deserialize(NBTTagCompound tagCompound)
{
public void deserialize(NBTTagCompound tagCompound) {
super.deserialize(tagCompound);
NBTTagCompound altarTag = tagCompound.getCompoundTag("bloodAltar");
@ -34,8 +31,7 @@ public class TileAltar extends TileInventory implements IBloodAltar, ITickable
}
@Override
public NBTTagCompound serialize(NBTTagCompound tagCompound)
{
public NBTTagCompound serialize(NBTTagCompound tagCompound) {
super.serialize(tagCompound);
NBTTagCompound altarTag = new NBTTagCompound();
@ -46,164 +42,136 @@ public class TileAltar extends TileInventory implements IBloodAltar, ITickable
}
@Override
public void update()
{
public void update() {
bloodAltar.update();
}
@Override
public void sacrificialDaggerCall(int amount, boolean isSacrifice)
{
public void sacrificialDaggerCall(int amount, boolean isSacrifice) {
bloodAltar.sacrificialDaggerCall(amount, isSacrifice);
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack itemstack)
{
public boolean isItemValidForSlot(int slot, ItemStack itemstack) {
return slot == 0;
}
@Override
public int getCapacity()
{
public int getCapacity() {
return bloodAltar.getCapacity();
}
@Override
public int getCurrentBlood()
{
public int getCurrentBlood() {
return bloodAltar.getCurrentBlood();
}
@Override
public EnumAltarTier getTier()
{
public EnumAltarTier getTier() {
return bloodAltar.getTier();
}
@Override
public int getProgress()
{
public int getProgress() {
return bloodAltar.getProgress();
}
@Override
public float getSacrificeMultiplier()
{
public float getSacrificeMultiplier() {
return bloodAltar.getSacrificeMultiplier();
}
@Override
public float getSelfSacrificeMultiplier()
{
public float getSelfSacrificeMultiplier() {
return bloodAltar.getSelfSacrificeMultiplier();
}
@Override
public float getOrbMultiplier()
{
public float getOrbMultiplier() {
return bloodAltar.getOrbMultiplier();
}
@Override
public float getDislocationMultiplier()
{
public float getDislocationMultiplier() {
return bloodAltar.getDislocationMultiplier();
}
@Override
public float getConsumptionMultiplier()
{
public float getConsumptionMultiplier() {
return bloodAltar.getConsumptionMultiplier();
}
@Override
public float getConsumptionRate()
{
public float getConsumptionRate() {
return bloodAltar.getConsumptionRate();
}
@Override
public int getLiquidRequired()
{
public int getLiquidRequired() {
return bloodAltar.getLiquidRequired();
}
@Override
public int getBufferCapacity()
{
public int getBufferCapacity() {
return bloodAltar.getBufferCapacity();
}
@Override
public void startCycle()
{
public void startCycle() {
bloodAltar.startCycle();
}
@Override
public void checkTier()
{
public void checkTier() {
bloodAltar.checkTier();
}
@Override
public void requestPauseAfterCrafting(int cooldown)
{
public void requestPauseAfterCrafting(int cooldown) {
bloodAltar.requestPauseAfterCrafting(cooldown);
}
@Override
public boolean isActive()
{
public boolean isActive() {
return bloodAltar.isActive();
}
@Override
public int fillMainTank(int amount)
{
public int fillMainTank(int amount) {
return bloodAltar.fillMainTank(amount);
}
@Override
public void setActive()
{
public void setActive() {
bloodAltar.setActive();
}
@Override
public int getChargingRate()
{
public int getChargingRate() {
return bloodAltar.getChargingRate();
}
@Override
public int getTotalCharge()
{
public int getTotalCharge() {
return bloodAltar.getTotalCharge();
}
@Override
public int getChargingFrequency()
{
public int getChargingFrequency() {
return bloodAltar.getChargingFrequency();
}
public EnumAltarTier getCurrentTierDisplayed()
{
public EnumAltarTier getCurrentTierDisplayed() {
return bloodAltar.getCurrentTierDisplayed();
}
public boolean setCurrentTierDisplayed(EnumAltarTier altarTier)
{
public boolean setCurrentTierDisplayed(EnumAltarTier altarTier) {
return bloodAltar.setCurrentTierDisplayed(altarTier);
}
@Override
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing)
{
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY)
{
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
return true;
}
@ -212,10 +180,8 @@ public class TileAltar extends TileInventory implements IBloodAltar, ITickable
@SuppressWarnings("unchecked")
@Override
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing)
{
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY)
{
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
return (T) bloodAltar;
}

View file

@ -9,28 +9,23 @@ import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
public class TileBloodTank extends TileBase
{
public class TileBloodTank extends TileBase {
public static final int[] CAPACITIES = {16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65336, 131072, 262144, 524288};
public int capacity;
protected FluidTank tank;
public static final int[] CAPACITIES = { 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65336, 131072, 262144, 524288 };
public TileBloodTank(int meta)
{
public TileBloodTank(int meta) {
capacity = CAPACITIES[meta] * Fluid.BUCKET_VOLUME;
tank = new FluidTank(capacity);
}
public TileBloodTank()
{
public TileBloodTank() {
capacity = CAPACITIES[0] * Fluid.BUCKET_VOLUME;
tank = new FluidTank(capacity);
}
@Override
public void deserialize(NBTTagCompound tagCompound)
{
public void deserialize(NBTTagCompound tagCompound) {
super.deserialize(tagCompound);
tank.readFromNBT(tagCompound.getCompoundTag(Constants.NBT.TANK));
capacity = tagCompound.getInteger(Constants.NBT.ALTAR_CAPACITY);
@ -38,8 +33,7 @@ public class TileBloodTank extends TileBase
}
@Override
public NBTTagCompound serialize(NBTTagCompound tagCompound)
{
public NBTTagCompound serialize(NBTTagCompound tagCompound) {
super.serialize(tagCompound);
if (tank.getFluidAmount() != 0)
tagCompound.setTag(Constants.NBT.TANK, tank.writeToNBT(new NBTTagCompound()));
@ -47,45 +41,38 @@ public class TileBloodTank extends TileBase
return tagCompound;
}
public int getCapacity()
{
public int getCapacity() {
return capacity;
}
public FluidTank getTank()
{
public FluidTank getTank() {
return tank;
}
public Fluid getClientRenderFluid()
{
public Fluid getClientRenderFluid() {
if (tank != null && tank.getFluid() != null)
return tank.getFluid().getFluid();
return null;
}
public float getRenderHeight()
{
public float getRenderHeight() {
if (tank != null && tank.getFluidAmount() > 0)
return (float) tank.getFluidAmount() / (float) getCapacity();
return 0F;
}
public int getComparatorOutput()
{
public int getComparatorOutput() {
return tank.getFluidAmount() > 0 ? (int) (1 + ((double) tank.getFluidAmount() / (double) tank.getCapacity()) * 14) : 0;
}
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing)
{
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
}
@SuppressWarnings("unchecked")
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing)
{
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY)
return (T) tank;
return super.getCapability(capability, facing);

View file

@ -14,72 +14,55 @@ import net.minecraft.util.ITickable;
import java.util.HashMap;
import java.util.Map.Entry;
public class TileDemonCrucible extends TileInventory implements ITickable, IDemonWillConduit, ISidedInventory
{
public HashMap<EnumDemonWillType, Double> willMap = new HashMap<EnumDemonWillType, Double>(); //TODO: Change to DemonWillHolder
public class TileDemonCrucible extends TileInventory implements ITickable, IDemonWillConduit, ISidedInventory {
public final int maxWill = 100;
public final double gemDrainRate = 10;
public HashMap<EnumDemonWillType, Double> willMap = new HashMap<EnumDemonWillType, Double>(); //TODO: Change to DemonWillHolder
public int internalCounter = 0;
public TileDemonCrucible()
{
public TileDemonCrucible() {
super(1, "demonCrucible");
}
@Override
public void update()
{
if (getWorld().isRemote)
{
public void update() {
if (getWorld().isRemote) {
return;
}
internalCounter++;
if (getWorld().isBlockPowered(getPos()))
{
if (getWorld().isBlockPowered(getPos())) {
//TODO: Fill the contained gem if it is there.
ItemStack stack = this.getStackInSlot(0);
if (stack.getItem() instanceof IDemonWillGem)
{
if (stack.getItem() instanceof IDemonWillGem) {
IDemonWillGem gemItem = (IDemonWillGem) stack.getItem();
for (EnumDemonWillType type : EnumDemonWillType.values())
{
if (willMap.containsKey(type))
{
for (EnumDemonWillType type : EnumDemonWillType.values()) {
if (willMap.containsKey(type)) {
double current = willMap.get(type);
double fillAmount = Math.min(gemDrainRate, current);
if (fillAmount > 0)
{
if (fillAmount > 0) {
fillAmount = gemItem.fillWill(type, stack, fillAmount, true);
if (willMap.get(type) - fillAmount <= 0)
{
if (willMap.get(type) - fillAmount <= 0) {
willMap.remove(type);
} else
{
} else {
willMap.put(type, willMap.get(type) - fillAmount);
}
}
}
}
}
} else
{
} else {
ItemStack stack = this.getStackInSlot(0);
if (!stack.isEmpty())
{
if (stack.getItem() instanceof IDemonWillGem)
{
if (!stack.isEmpty()) {
if (stack.getItem() instanceof IDemonWillGem) {
IDemonWillGem gemItem = (IDemonWillGem) stack.getItem();
for (EnumDemonWillType type : EnumDemonWillType.values())
{
for (EnumDemonWillType type : EnumDemonWillType.values()) {
double currentAmount = WorldDemonWillHandler.getCurrentWill(getWorld(), pos, type);
double drainAmount = Math.min(maxWill - currentAmount, gemDrainRate);
double filled = WorldDemonWillHandler.fillWillToMaximum(getWorld(), pos, type, drainAmount, maxWill, false);
filled = gemItem.drainWill(type, stack, filled, false);
if (filled > 0)
{
if (filled > 0) {
filled = gemItem.drainWill(type, stack, filled, true);
WorldDemonWillHandler.fillWillToMaximum(getWorld(), pos, type, filled, maxWill, true);
}
@ -91,14 +74,11 @@ public class TileDemonCrucible extends TileInventory implements ITickable, IDemo
double currentAmount = WorldDemonWillHandler.getCurrentWill(getWorld(), pos, type);
double needed = maxWill - currentAmount;
double discreteAmount = willItem.getDiscretization(stack);
if (needed >= discreteAmount)
{
if (needed >= discreteAmount) {
double filled = willItem.drainWill(stack, discreteAmount);
if (filled > 0)
{
if (filled > 0) {
WorldDemonWillHandler.fillWillToMaximum(getWorld(), pos, type, filled, maxWill, true);
if (stack.getCount() <= 0)
{
if (stack.getCount() <= 0) {
this.setInventorySlotContents(0, ItemStack.EMPTY);
}
}
@ -109,29 +89,24 @@ public class TileDemonCrucible extends TileInventory implements ITickable, IDemo
}
@Override
public void deserialize(NBTTagCompound tag)
{
public void deserialize(NBTTagCompound tag) {
super.deserialize(tag);
willMap.clear();
for (EnumDemonWillType type : EnumDemonWillType.values())
{
for (EnumDemonWillType type : EnumDemonWillType.values()) {
double amount = tag.getDouble("EnumWill" + type.getName());
if (amount > 0)
{
if (amount > 0) {
willMap.put(type, amount);
}
}
}
@Override
public NBTTagCompound serialize(NBTTagCompound tag)
{
public NBTTagCompound serialize(NBTTagCompound tag) {
super.serialize(tag);
for (Entry<EnumDemonWillType, Double> entry : willMap.entrySet())
{
for (Entry<EnumDemonWillType, Double> entry : willMap.entrySet()) {
tag.setDouble("EnumWill" + entry.getKey().getName(), entry.getValue());
}
return tag;
@ -140,36 +115,29 @@ public class TileDemonCrucible extends TileInventory implements ITickable, IDemo
// IDemonWillConduit
@Override
public int getWeight()
{
public int getWeight() {
return 10;
}
@Override
public double fillDemonWill(EnumDemonWillType type, double amount, boolean doFill)
{
if (amount <= 0)
{
public double fillDemonWill(EnumDemonWillType type, double amount, boolean doFill) {
if (amount <= 0) {
return 0;
}
if (!canFill(type))
{
if (!canFill(type)) {
return 0;
}
if (!doFill)
{
if (!willMap.containsKey(type))
{
if (!doFill) {
if (!willMap.containsKey(type)) {
return Math.min(maxWill, amount);
}
return Math.min(maxWill - willMap.get(type), amount);
}
if (!willMap.containsKey(type))
{
if (!willMap.containsKey(type)) {
double max = Math.min(maxWill, amount);
willMap.put(type, max);
@ -180,12 +148,10 @@ public class TileDemonCrucible extends TileInventory implements ITickable, IDemo
double current = willMap.get(type);
double filled = maxWill - current;
if (amount < filled)
{
if (amount < filled) {
willMap.put(type, current + amount);
filled = amount;
} else
{
} else {
willMap.put(type, (double) maxWill);
}
@ -193,28 +159,22 @@ public class TileDemonCrucible extends TileInventory implements ITickable, IDemo
}
@Override
public double drainDemonWill(EnumDemonWillType type, double amount, boolean doDrain)
{
if (!willMap.containsKey(type))
{
public double drainDemonWill(EnumDemonWillType type, double amount, boolean doDrain) {
if (!willMap.containsKey(type)) {
return 0;
}
double drained = amount;
double current = willMap.get(type);
if (current < drained)
{
if (current < drained) {
drained = current;
}
if (doDrain)
{
if (doDrain) {
current -= drained;
if (current <= 0)
{
if (current <= 0) {
willMap.remove(type);
} else
{
} else {
willMap.put(type, current);
}
}
@ -223,38 +183,32 @@ public class TileDemonCrucible extends TileInventory implements ITickable, IDemo
}
@Override
public boolean canFill(EnumDemonWillType type)
{
public boolean canFill(EnumDemonWillType type) {
return true;
}
@Override
public boolean canDrain(EnumDemonWillType type)
{
public boolean canDrain(EnumDemonWillType type) {
return true;
}
@Override
public double getCurrentWill(EnumDemonWillType type)
{
public double getCurrentWill(EnumDemonWillType type) {
return willMap.containsKey(type) ? willMap.get(type) : 0;
}
@Override
public int[] getSlotsForFace(EnumFacing side)
{
return new int[] { 0 };
public int[] getSlotsForFace(EnumFacing side) {
return new int[]{0};
}
@Override
public boolean canInsertItem(int index, ItemStack stack, EnumFacing direction)
{
public boolean canInsertItem(int index, ItemStack stack, EnumFacing direction) {
return !stack.isEmpty() && (stack.getItem() instanceof IDemonWillGem || stack.getItem() instanceof IDiscreteDemonWill);
}
@Override
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction)
{
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction) {
return true;
}
}

View file

@ -1,5 +1,9 @@
package WayofTime.bloodmagic.tile;
import WayofTime.bloodmagic.api.soul.DemonWillHolder;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.block.BlockDemonCrystal;
import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler;
import WayofTime.bloodmagic.tile.base.TileTicking;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem;
@ -7,64 +11,48 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.MathHelper;
import WayofTime.bloodmagic.api.soul.DemonWillHolder;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.block.BlockDemonCrystal;
import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler;
public class TileDemonCrystal extends TileTicking
{
public DemonWillHolder holder = new DemonWillHolder();
public final int maxWill = 100;
public final double drainRate = 1;
public class TileDemonCrystal extends TileTicking {
public static final double sameWillConversionRate = 50;
public static final double defaultWillConversionRate = 100;
public static final double timeDelayForWrongWill = 0.6;
public final int maxWill = 100;
public final double drainRate = 1;
public DemonWillHolder holder = new DemonWillHolder();
public double progressToNextCrystal = 0;
public int internalCounter = 0;
public int crystalCount = 1;
public EnumFacing placement = EnumFacing.UP; //Side that this crystal is placed on.
public TileDemonCrystal()
{
public TileDemonCrystal() {
this.crystalCount = 1;
}
@Override
public void onUpdate()
{
if (getWorld().isRemote)
{
public void onUpdate() {
if (getWorld().isRemote) {
return;
}
internalCounter++;
if (internalCounter % 20 == 0 && crystalCount < 7)
{
if (internalCounter % 20 == 0 && crystalCount < 7) {
EnumDemonWillType type = EnumDemonWillType.values()[this.getBlockMetadata()];
double value = WorldDemonWillHandler.getCurrentWill(getWorld(), pos, type);
if (type != EnumDemonWillType.DEFAULT)
{
if (value >= 100)
{
if (type != EnumDemonWillType.DEFAULT) {
if (value >= 100) {
double nextProgress = getCrystalGrowthPerSecond(value);
progressToNextCrystal += WorldDemonWillHandler.drainWill(getWorld(), getPos(), type, nextProgress * sameWillConversionRate, true) / sameWillConversionRate;
} else
{
} else {
value = WorldDemonWillHandler.getCurrentWill(getWorld(), pos, EnumDemonWillType.DEFAULT);
if (value > 0.5)
{
if (value > 0.5) {
double nextProgress = getCrystalGrowthPerSecond(value) * timeDelayForWrongWill;
progressToNextCrystal += WorldDemonWillHandler.drainWill(getWorld(), getPos(), EnumDemonWillType.DEFAULT, nextProgress * defaultWillConversionRate, true) / defaultWillConversionRate;
}
}
} else
{
if (value > 0.5)
{
} else {
if (value > 0.5) {
double nextProgress = getCrystalGrowthPerSecond(value);
progressToNextCrystal += WorldDemonWillHandler.drainWill(getWorld(), getPos(), type, nextProgress * sameWillConversionRate, true) / sameWillConversionRate;
}
@ -83,18 +71,15 @@ public class TileDemonCrystal extends TileTicking
/**
* Encourages the crystal to grow by a large percentage by telling it to
* drain will from the aura.
*
* @param willDrain
* The amount of drain that is needed for the crystal to grow
* successfully for the desired amount. Can be more than the base
* amount.
*
* @param willDrain The amount of drain that is needed for the crystal to grow
* successfully for the desired amount. Can be more than the base
* amount.
* @param progressPercentage
* @return percentage actually grown.
*/
public double growCrystalWithWillAmount(double willDrain, double progressPercentage)
{
if (crystalCount >= 7)
{
public double growCrystalWithWillAmount(double willDrain, double progressPercentage) {
if (crystalCount >= 7) {
return 0;
}
@ -104,8 +89,7 @@ public class TileDemonCrystal extends TileTicking
double value = WorldDemonWillHandler.getCurrentWill(getWorld(), pos, type);
double percentDrain = willDrain <= 0 ? 1 : Math.min(1, value / willDrain);
if (percentDrain <= 0)
{
if (percentDrain <= 0) {
return 0;
}
@ -118,10 +102,8 @@ public class TileDemonCrystal extends TileTicking
return percentDrain * progressPercentage;
}
public void checkAndGrowCrystal()
{
if (progressToNextCrystal >= 1)
{
public void checkAndGrowCrystal() {
if (progressToNextCrystal >= 1) {
progressToNextCrystal--;
crystalCount++;
IBlockState thisState = getWorld().getBlockState(pos);
@ -130,20 +112,16 @@ public class TileDemonCrystal extends TileTicking
}
}
public double getMaxWillForCrystal()
{
public double getMaxWillForCrystal() {
return 50;
}
public boolean dropSingleCrystal()
{
if (!getWorld().isRemote && crystalCount > 1)
{
public boolean dropSingleCrystal() {
if (!getWorld().isRemote && crystalCount > 1) {
IBlockState state = getWorld().getBlockState(pos);
EnumDemonWillType type = state.getValue(BlockDemonCrystal.TYPE);
ItemStack stack = BlockDemonCrystal.getItemStackDropped(type, 1);
if (stack != null)
{
if (stack != null) {
crystalCount--;
getWorld().spawnEntity(new EntityItem(getWorld(), pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, stack));
return true;
@ -153,19 +131,16 @@ public class TileDemonCrystal extends TileTicking
return false;
}
public double getCrystalGrowthPerSecond(double will)
{
public double getCrystalGrowthPerSecond(double will) {
return 1.0 / 800 * Math.sqrt(will / 200);
}
public int getCrystalCountForRender()
{
public int getCrystalCountForRender() {
return MathHelper.clamp(crystalCount - 1, 0, 6);
}
@Override
public void deserialize(NBTTagCompound tag)
{
public void deserialize(NBTTagCompound tag) {
holder.readFromNBT(tag, "Will");
crystalCount = tag.getInteger("crystalCount");
placement = EnumFacing.getFront(tag.getInteger("placement"));
@ -173,8 +148,7 @@ public class TileDemonCrystal extends TileTicking
}
@Override
public NBTTagCompound serialize(NBTTagCompound tag)
{
public NBTTagCompound serialize(NBTTagCompound tag) {
holder.writeToNBT(tag, "Will");
tag.setInteger("crystalCount", crystalCount);
tag.setInteger("placement", placement.getIndex());

View file

@ -3,35 +3,30 @@ package WayofTime.bloodmagic.tile;
import WayofTime.bloodmagic.api.soul.DemonWillHolder;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.api.soul.IDemonWillConduit;
import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler;
import WayofTime.bloodmagic.core.RegistrarBloodMagicBlocks;
import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler;
import WayofTime.bloodmagic.tile.base.TileTicking;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
public class TileDemonCrystallizer extends TileTicking implements IDemonWillConduit
{
//The whole purpose of this block is to grow a crystal initially. The acceleration and crystal growing is up to the crystal itself afterwards.
public DemonWillHolder holder = new DemonWillHolder();
public class TileDemonCrystallizer extends TileTicking implements IDemonWillConduit {
public static final int maxWill = 100;
public static final double drainRate = 1;
public static final double willToFormCrystal = 99;
public static final double totalFormationTime = 1000;
//The whole purpose of this block is to grow a crystal initially. The acceleration and crystal growing is up to the crystal itself afterwards.
public DemonWillHolder holder = new DemonWillHolder();
public double internalCounter = 0;
public TileDemonCrystallizer()
{
public TileDemonCrystallizer() {
}
@Override
public void onUpdate()
{
if (getWorld().isRemote)
{
public void onUpdate() {
if (getWorld().isRemote) {
return;
}
@ -40,15 +35,11 @@ public class TileDemonCrystallizer extends TileTicking implements IDemonWillCond
{
EnumDemonWillType highestType = WorldDemonWillHandler.getHighestDemonWillType(getWorld(), pos);
double amount = WorldDemonWillHandler.getCurrentWill(getWorld(), pos, highestType);
if (amount >= willToFormCrystal)
{
if (amount >= willToFormCrystal) {
internalCounter += getCrystalFormationRate(amount);
if (internalCounter >= totalFormationTime)
{
if (WorldDemonWillHandler.drainWill(getWorld(), getPos(), highestType, willToFormCrystal, false) >= willToFormCrystal)
{
if (highestType == EnumDemonWillType.DEFAULT && formRandomSpecialCrystal(offsetPos) || formCrystal(highestType, offsetPos))
{
if (internalCounter >= totalFormationTime) {
if (WorldDemonWillHandler.drainWill(getWorld(), getPos(), highestType, willToFormCrystal, false) >= willToFormCrystal) {
if (highestType == EnumDemonWillType.DEFAULT && formRandomSpecialCrystal(offsetPos) || formCrystal(highestType, offsetPos)) {
WorldDemonWillHandler.drainWill(getWorld(), getPos(), highestType, willToFormCrystal, true);
internalCounter = 0;
}
@ -58,12 +49,10 @@ public class TileDemonCrystallizer extends TileTicking implements IDemonWillCond
}
}
public boolean formCrystal(EnumDemonWillType type, BlockPos position)
{
public boolean formCrystal(EnumDemonWillType type, BlockPos position) {
getWorld().setBlockState(position, RegistrarBloodMagicBlocks.DEMON_CRYSTAL.getStateFromMeta(type.ordinal()));
TileEntity tile = getWorld().getTileEntity(position);
if (tile instanceof TileDemonCrystal)
{
if (tile instanceof TileDemonCrystal) {
((TileDemonCrystal) tile).setPlacement(EnumFacing.UP);
return true;
}
@ -71,31 +60,26 @@ public class TileDemonCrystallizer extends TileTicking implements IDemonWillCond
return false;
}
public boolean formRandomSpecialCrystal(BlockPos position)
{
if (getWorld().rand.nextDouble() > 0.1)
{
public boolean formRandomSpecialCrystal(BlockPos position) {
if (getWorld().rand.nextDouble() > 0.1) {
return formCrystal(EnumDemonWillType.DEFAULT, position);
}
EnumDemonWillType crystalType = EnumDemonWillType.values()[getWorld().rand.nextInt(EnumDemonWillType.values().length - 1) + 1];
return formCrystal(crystalType, position);
}
public double getCrystalFormationRate(double currentWill)
{
public double getCrystalFormationRate(double currentWill) {
return 1;
}
@Override
public void deserialize(NBTTagCompound tag)
{
public void deserialize(NBTTagCompound tag) {
holder.readFromNBT(tag, "Will");
internalCounter = tag.getDouble("internalCounter");
}
@Override
public NBTTagCompound serialize(NBTTagCompound tag)
{
public NBTTagCompound serialize(NBTTagCompound tag) {
holder.writeToNBT(tag, "Will");
tag.setDouble("internalCounter", internalCounter);
return tag;
@ -104,26 +88,21 @@ public class TileDemonCrystallizer extends TileTicking implements IDemonWillCond
// IDemonWillConduit
@Override
public int getWeight()
{
public int getWeight() {
return 10;
}
@Override
public double fillDemonWill(EnumDemonWillType type, double amount, boolean doFill)
{
if (amount <= 0)
{
public double fillDemonWill(EnumDemonWillType type, double amount, boolean doFill) {
if (amount <= 0) {
return 0;
}
if (!canFill(type))
{
if (!canFill(type)) {
return 0;
}
if (!doFill)
{
if (!doFill) {
return Math.min(maxWill - holder.getWill(type), amount);
}
@ -131,17 +110,14 @@ public class TileDemonCrystallizer extends TileTicking implements IDemonWillCond
}
@Override
public double drainDemonWill(EnumDemonWillType type, double amount, boolean doDrain)
{
public double drainDemonWill(EnumDemonWillType type, double amount, boolean doDrain) {
double drained = amount;
double current = holder.getWill(type);
if (current < drained)
{
if (current < drained) {
drained = current;
}
if (doDrain)
{
if (doDrain) {
return holder.drainWill(type, amount);
}
@ -149,20 +125,17 @@ public class TileDemonCrystallizer extends TileTicking implements IDemonWillCond
}
@Override
public boolean canFill(EnumDemonWillType type)
{
public boolean canFill(EnumDemonWillType type) {
return true;
}
@Override
public boolean canDrain(EnumDemonWillType type)
{
public boolean canDrain(EnumDemonWillType type) {
return true;
}
@Override
public double getCurrentWill(EnumDemonWillType type)
{
public double getCurrentWill(EnumDemonWillType type) {
return holder.getWill(type);
}
}

View file

@ -9,35 +9,28 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
public class TileDemonPylon extends TileTicking implements IDemonWillConduit
{
public DemonWillHolder holder = new DemonWillHolder();
public class TileDemonPylon extends TileTicking implements IDemonWillConduit {
public final int maxWill = 100;
public final double drainRate = 1;
public DemonWillHolder holder = new DemonWillHolder();
public TileDemonPylon()
{
public TileDemonPylon() {
}
@Override
public void onUpdate()
{
if (getWorld().isRemote)
{
public void onUpdate() {
if (getWorld().isRemote) {
return;
}
for (EnumDemonWillType type : EnumDemonWillType.values())
{
for (EnumDemonWillType type : EnumDemonWillType.values()) {
double currentAmount = WorldDemonWillHandler.getCurrentWill(getWorld(), pos, type);
for (EnumFacing side : EnumFacing.HORIZONTALS)
{
for (EnumFacing side : EnumFacing.HORIZONTALS) {
BlockPos offsetPos = pos.offset(side, 16);
double sideAmount = WorldDemonWillHandler.getCurrentWill(getWorld(), offsetPos, type);
if (sideAmount > currentAmount)
{
if (sideAmount > currentAmount) {
double drainAmount = Math.min((sideAmount - currentAmount) / 2, drainRate);
double drain = WorldDemonWillHandler.drainWill(getWorld(), offsetPos, type, drainAmount, true);
WorldDemonWillHandler.fillWill(getWorld(), pos, type, drain, true);
@ -47,14 +40,12 @@ public class TileDemonPylon extends TileTicking implements IDemonWillConduit
}
@Override
public void deserialize(NBTTagCompound tag)
{
public void deserialize(NBTTagCompound tag) {
holder.readFromNBT(tag, "Will");
}
@Override
public NBTTagCompound serialize(NBTTagCompound tag)
{
public NBTTagCompound serialize(NBTTagCompound tag) {
holder.writeToNBT(tag, "Will");
return tag;
}
@ -62,26 +53,21 @@ public class TileDemonPylon extends TileTicking implements IDemonWillConduit
// IDemonWillConduit
@Override
public int getWeight()
{
public int getWeight() {
return 10;
}
@Override
public double fillDemonWill(EnumDemonWillType type, double amount, boolean doFill)
{
if (amount <= 0)
{
public double fillDemonWill(EnumDemonWillType type, double amount, boolean doFill) {
if (amount <= 0) {
return 0;
}
if (!canFill(type))
{
if (!canFill(type)) {
return 0;
}
if (!doFill)
{
if (!doFill) {
return Math.min(maxWill - holder.getWill(type), amount);
}
@ -89,17 +75,14 @@ public class TileDemonPylon extends TileTicking implements IDemonWillConduit
}
@Override
public double drainDemonWill(EnumDemonWillType type, double amount, boolean doDrain)
{
public double drainDemonWill(EnumDemonWillType type, double amount, boolean doDrain) {
double drained = amount;
double current = holder.getWill(type);
if (current < drained)
{
if (current < drained) {
drained = current;
}
if (doDrain)
{
if (doDrain) {
return holder.drainWill(type, amount);
}
@ -107,20 +90,17 @@ public class TileDemonPylon extends TileTicking implements IDemonWillConduit
}
@Override
public boolean canFill(EnumDemonWillType type)
{
public boolean canFill(EnumDemonWillType type) {
return true;
}
@Override
public boolean canDrain(EnumDemonWillType type)
{
public boolean canDrain(EnumDemonWillType type) {
return true;
}
@Override
public double getCurrentWill(EnumDemonWillType type)
{
public double getCurrentWill(EnumDemonWillType type) {
return holder.getWill(type);
}
}

View file

@ -6,15 +6,13 @@ import com.google.common.base.Strings;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
public class TileDimensionalPortal extends TileBase
{
public class TileDimensionalPortal extends TileBase {
public String portalID = "";
public int masterStoneX;
public int masterStoneY;
public int masterStoneZ;
public void deserialize(NBTTagCompound tagCompound)
{
public void deserialize(NBTTagCompound tagCompound) {
portalID = tagCompound.getString(RitualPortal.PORTAL_ID_TAG);
masterStoneX = tagCompound.getInteger("masterStoneX");
@ -22,8 +20,7 @@ public class TileDimensionalPortal extends TileBase
masterStoneZ = tagCompound.getInteger("masterStoneZ");
}
public NBTTagCompound serialize(NBTTagCompound tagCompound)
{
public NBTTagCompound serialize(NBTTagCompound tagCompound) {
tagCompound.setString(RitualPortal.PORTAL_ID_TAG, Strings.isNullOrEmpty(portalID) ? "" : portalID);
tagCompound.setInteger("masterStoneX", masterStoneX);
@ -32,13 +29,11 @@ public class TileDimensionalPortal extends TileBase
return tagCompound;
}
public BlockPos getMasterStonePos()
{
public BlockPos getMasterStonePos() {
return new BlockPos(masterStoneX, masterStoneY, masterStoneZ);
}
public void setMasterStonePos(BlockPos blockPos)
{
public void setMasterStonePos(BlockPos blockPos) {
this.masterStoneX = blockPos.getX();
this.masterStoneY = blockPos.getY();
this.masterStoneZ = blockPos.getZ();

View file

@ -11,20 +11,15 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class TileImperfectRitualStone extends TileBase implements IImperfectRitualStone
{
public class TileImperfectRitualStone extends TileBase implements IImperfectRitualStone {
// IImperfectRitualStone
@Override
public boolean performRitual(World world, BlockPos pos, ImperfectRitual imperfectRitual, EntityPlayer player)
{
if (imperfectRitual != null && ImperfectRitualRegistry.ritualEnabled(imperfectRitual))
{
if (!PlayerHelper.isFakePlayer(player) && !world.isRemote)
{
public boolean performRitual(World world, BlockPos pos, ImperfectRitual imperfectRitual, EntityPlayer player) {
if (imperfectRitual != null && ImperfectRitualRegistry.ritualEnabled(imperfectRitual)) {
if (!PlayerHelper.isFakePlayer(player) && !world.isRemote) {
NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, imperfectRitual.getActivationCost());
if (imperfectRitual.onActivate(this, player))
{
if (imperfectRitual.onActivate(this, player)) {
if (imperfectRitual.isLightshow())
getWorld().addWeatherEffect(new EntityLightningBolt(getWorld(), getPos().getX(), getPos().getY() + 2, getPos().getZ(), true));
return true;
@ -38,14 +33,12 @@ public class TileImperfectRitualStone extends TileBase implements IImperfectRitu
}
@Override
public World getRitualWorld()
{
public World getRitualWorld() {
return getWorld();
}
@Override
public BlockPos getRitualPos()
{
public BlockPos getRitualPos() {
return getPos();
}
}

View file

@ -23,50 +23,41 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public class TileIncenseAltar extends TileInventory implements ITickable
{
public AreaDescriptor incenseArea = new AreaDescriptor.Rectangle(new BlockPos(-5, -5, -5), 11);
public class TileIncenseAltar extends TileInventory implements ITickable {
public static int maxCheckRange = 5;
public AreaDescriptor incenseArea = new AreaDescriptor.Rectangle(new BlockPos(-5, -5, -5), 11);
public Map<EnumTranquilityType, Double> tranquilityMap = new HashMap<EnumTranquilityType, Double>();
public double incenseAddition = 0; //Self-sacrifice is multiplied by 1 plus this value.
public double tranquility = 0;
public int roadDistance = 0; //Number of road blocks laid down
public TileIncenseAltar()
{
public TileIncenseAltar() {
super(1, "incenseAltar");
}
@Override
public void update()
{
public void update() {
AxisAlignedBB aabb = incenseArea.getAABB(getPos());
List<EntityPlayer> playerList = getWorld().getEntitiesWithinAABB(EntityPlayer.class, aabb);
if (playerList.isEmpty())
{
if (playerList.isEmpty()) {
return;
}
if (getWorld().getTotalWorldTime() % 100 == 0)
{
if (getWorld().getTotalWorldTime() % 100 == 0) {
recheckConstruction();
}
boolean hasPerformed = false;
for (EntityPlayer player : playerList)
{
if (PlayerSacrificeHelper.incrementIncense(player, 0, incenseAddition, incenseAddition / 100))
{
for (EntityPlayer player : playerList) {
if (PlayerSacrificeHelper.incrementIncense(player, 0, incenseAddition, incenseAddition / 100)) {
hasPerformed = true;
}
}
if (hasPerformed)
{
if (getWorld().rand.nextInt(4) == 0 && getWorld() instanceof WorldServer)
{
if (hasPerformed) {
if (getWorld().rand.nextInt(4) == 0 && getWorld() instanceof WorldServer) {
WorldServer server = (WorldServer) getWorld();
server.spawnParticle(EnumParticleTypes.FLAME, pos.getX() + 0.5, pos.getY() + 1.2, pos.getZ() + 0.5, 1, 0.02, 0.03, 0.02, 0, new int[0]);
}
@ -74,94 +65,77 @@ public class TileIncenseAltar extends TileInventory implements ITickable
}
@Override
public void deserialize(NBTTagCompound tag)
{
public void deserialize(NBTTagCompound tag) {
super.deserialize(tag);
tranquility = tag.getDouble("tranquility");
incenseAddition = tag.getDouble("incenseAddition");
}
@Override
public NBTTagCompound serialize(NBTTagCompound tag)
{
public NBTTagCompound serialize(NBTTagCompound tag) {
super.serialize(tag);
tag.setDouble("tranquility", tranquility);
tag.setDouble("incenseAddition", incenseAddition);
return tag;
}
public void recheckConstruction()
{
public void recheckConstruction() {
//TODO: Check the physical construction of the incense altar to determine the maximum length.
int maxLength = 11; //Max length of the path. The path starts two blocks away from the center block.
int yOffset = 0;
Map<EnumTranquilityType, Double> tranquilityMap = new HashMap<EnumTranquilityType, Double>();
for (int currentDistance = 2; currentDistance < currentDistance + maxLength; currentDistance++)
{
for (int currentDistance = 2; currentDistance < currentDistance + maxLength; currentDistance++) {
boolean canFormRoad = false;
for (int i = -maxCheckRange + yOffset; i <= maxCheckRange + yOffset; i++)
{
for (int i = -maxCheckRange + yOffset; i <= maxCheckRange + yOffset; i++) {
BlockPos verticalPos = pos.add(0, i, 0);
canFormRoad = true;
level: for (EnumFacing horizontalFacing : EnumFacing.HORIZONTALS)
{
level:
for (EnumFacing horizontalFacing : EnumFacing.HORIZONTALS) {
BlockPos facingOffsetPos = verticalPos.offset(horizontalFacing, currentDistance);
for (int j = -1; j <= 1; j++)
{
for (int j = -1; j <= 1; j++) {
BlockPos offsetPos = facingOffsetPos.offset(horizontalFacing.rotateY(), j);
IBlockState state = getWorld().getBlockState(offsetPos);
Block block = state.getBlock();
if (!(block instanceof IIncensePath && ((IIncensePath) block).getLevelOfPath(getWorld(), offsetPos, state) >= currentDistance - 2))
{
if (!(block instanceof IIncensePath && ((IIncensePath) block).getLevelOfPath(getWorld(), offsetPos, state) >= currentDistance - 2)) {
canFormRoad = false;
break level;
}
}
}
if (canFormRoad)
{
if (canFormRoad) {
yOffset = i;
break;
}
}
if (canFormRoad)
{
for (int i = -currentDistance; i <= currentDistance; i++)
{
for (int j = -currentDistance; j <= currentDistance; j++)
{
if (Math.abs(i) != currentDistance && Math.abs(j) != currentDistance)
{
if (canFormRoad) {
for (int i = -currentDistance; i <= currentDistance; i++) {
for (int j = -currentDistance; j <= currentDistance; j++) {
if (Math.abs(i) != currentDistance && Math.abs(j) != currentDistance) {
continue; //TODO: Can make this just set j to currentDistance to speed it up.
}
for (int y = 0 + yOffset; y <= 2 + yOffset; y++)
{
for (int y = 0 + yOffset; y <= 2 + yOffset; y++) {
BlockPos offsetPos = pos.add(i, y, j);
IBlockState state = getWorld().getBlockState(offsetPos);
Block block = state.getBlock();
TranquilityStack stack = IncenseTranquilityRegistry.getTranquilityOfBlock(getWorld(), offsetPos, block, state);
if (stack != null)
{
if (!tranquilityMap.containsKey(stack.type))
{
if (stack != null) {
if (!tranquilityMap.containsKey(stack.type)) {
tranquilityMap.put(stack.type, stack.value);
} else
{
} else {
tranquilityMap.put(stack.type, tranquilityMap.get(stack.type) + stack.value);
}
}
}
}
}
} else
{
} else {
roadDistance = currentDistance - 2;
break;
}
@ -170,19 +144,16 @@ public class TileIncenseAltar extends TileInventory implements ITickable
this.tranquilityMap = tranquilityMap;
double totalTranquility = 0;
for (Entry<EnumTranquilityType, Double> entry : tranquilityMap.entrySet())
{
for (Entry<EnumTranquilityType, Double> entry : tranquilityMap.entrySet()) {
totalTranquility += entry.getValue();
}
if (totalTranquility < 0)
{
if (totalTranquility < 0) {
return;
}
double appliedTranquility = 0;
for (Entry<EnumTranquilityType, Double> entry : tranquilityMap.entrySet())
{
for (Entry<EnumTranquilityType, Double> entry : tranquilityMap.entrySet()) {
appliedTranquility += Math.sqrt(entry.getValue());
}

View file

@ -1,6 +1,7 @@
package WayofTime.bloodmagic.tile;
import WayofTime.bloodmagic.tile.base.TileBase;
import WayofTime.bloodmagic.util.helper.TextHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
@ -17,29 +18,31 @@ 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.util.helper.TextHelper;
public class TileInventory extends TileBase implements IInventory
{
public class TileInventory extends TileBase implements IInventory {
protected int[] syncedSlots = new int[0];
protected NonNullList<ItemStack> inventory;
IItemHandler handlerDown;
IItemHandler handlerUp;
IItemHandler handlerNorth;
IItemHandler handlerSouth;
IItemHandler handlerWest;
IItemHandler handlerEast;
private int size;
// IInventory
private String name;
public TileInventory(int size, String name)
{
public TileInventory(int size, String name) {
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)
{
protected boolean isSyncedSlot(int slot) {
for (int s : this.syncedSlots) {
if (s == slot) {
return true;
}
}
@ -47,21 +50,17 @@ public class TileInventory extends TileBase implements IInventory
}
@Override
public void deserialize(NBTTagCompound tagCompound)
{
public void deserialize(NBTTagCompound tagCompound) {
super.deserialize(tagCompound);
NBTTagList tags = tagCompound.getTagList("Items", 10);
inventory = NonNullList.withSize(size, ItemStack.EMPTY);
for (int i = 0; i < tags.tagCount(); i++)
{
if (!isSyncedSlot(i))
{
for (int i = 0; i < tags.tagCount(); i++) {
if (!isSyncedSlot(i)) {
NBTTagCompound data = tags.getCompoundTagAt(i);
byte j = data.getByte("Slot");
if (j >= 0 && j < inventory.size())
{
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
}
}
@ -69,15 +68,12 @@ public class TileInventory extends TileBase implements IInventory
}
@Override
public NBTTagCompound serialize(NBTTagCompound tagCompound)
{
public NBTTagCompound serialize(NBTTagCompound tagCompound) {
super.serialize(tagCompound);
NBTTagList tags = new NBTTagList();
for (int i = 0; i < inventory.size(); i++)
{
if ((!inventory.get(i).isEmpty()) && !isSyncedSlot(i))
{
for (int i = 0; i < inventory.size(); i++) {
if ((!inventory.get(i).isEmpty()) && !isSyncedSlot(i)) {
NBTTagCompound data = new NBTTagCompound();
data.setByte("Slot", (byte) i);
inventory.get(i).writeToNBT(data);
@ -89,35 +85,27 @@ public class TileInventory extends TileBase implements IInventory
return tagCompound;
}
public void dropItems()
{
public void dropItems() {
InventoryHelper.dropInventoryItems(getWorld(), getPos(), this);
}
// IInventory
@Override
public int getSizeInventory()
{
public int getSizeInventory() {
return size;
}
@Override
public ItemStack getStackInSlot(int index)
{
public ItemStack getStackInSlot(int index) {
return inventory.get(index);
}
@Override
public ItemStack decrStackSize(int index, int count)
{
if (!getStackInSlot(index).isEmpty())
{
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)
{
if (getStackInSlot(index).getCount() <= count) {
ItemStack itemStack = inventory.get(index);
inventory.set(index, ItemStack.EMPTY);
markDirty();
@ -133,10 +121,8 @@ public class TileInventory extends TileBase implements IInventory
}
@Override
public ItemStack removeStackFromSlot(int slot)
{
if (!inventory.get(slot).isEmpty())
{
public ItemStack removeStackFromSlot(int slot) {
if (!inventory.get(slot).isEmpty()) {
ItemStack itemStack = inventory.get(slot);
setInventorySlotContents(slot, ItemStack.EMPTY);
return itemStack;
@ -145,8 +131,7 @@ public class TileInventory extends TileBase implements IInventory
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack)
{
public void setInventorySlotContents(int slot, ItemStack stack) {
inventory.set(slot, stack);
if (!stack.isEmpty() && stack.getCount() > getInventoryStackLimit())
stack.setCount(getInventoryStackLimit());
@ -156,50 +141,44 @@ public class TileInventory extends TileBase implements IInventory
}
@Override
public int getInventoryStackLimit()
{
public int getInventoryStackLimit() {
return 64;
}
@Override
public void openInventory(EntityPlayer player)
{
public void openInventory(EntityPlayer player) {
}
@Override
public void closeInventory(EntityPlayer player)
{
public void closeInventory(EntityPlayer player) {
}
@Override
public boolean isItemValidForSlot(int index, ItemStack stack)
{
public boolean isItemValidForSlot(int index, ItemStack stack) {
return true;
}
// IWorldNameable
@Override
public int getField(int id)
{
public int getField(int id) {
return 0;
}
@Override
public void setField(int id, int value)
{
public void setField(int id, int value) {
}
@Override
public int getFieldCount()
{
public int getFieldCount() {
return 0;
}
@Override
public void clear()
{
public void clear() {
this.inventory = NonNullList.withSize(size, ItemStack.EMPTY);
}
@ -217,38 +196,30 @@ public class TileInventory extends TileBase implements IInventory
return true;
}
// IWorldNameable
@Override
public String getName()
{
public String getName() {
return TextHelper.localize("tile.bloodmagic." + name + ".name");
}
@Override
public boolean hasCustomName()
{
public boolean hasCustomName() {
return true;
}
@Override
public ITextComponent getDisplayName()
{
public ITextComponent getDisplayName() {
return new TextComponentString(getName());
}
protected void initializeItemHandlers()
{
if (this instanceof ISidedInventory)
{
protected void initializeItemHandlers() {
if (this instanceof ISidedInventory) {
handlerDown = new SidedInvWrapper((ISidedInventory) this, EnumFacing.DOWN);
handlerUp = new SidedInvWrapper((ISidedInventory) this, EnumFacing.UP);
handlerNorth = new SidedInvWrapper((ISidedInventory) this, EnumFacing.NORTH);
handlerSouth = new SidedInvWrapper((ISidedInventory) this, EnumFacing.SOUTH);
handlerWest = new SidedInvWrapper((ISidedInventory) this, EnumFacing.WEST);
handlerEast = new SidedInvWrapper((ISidedInventory) this, EnumFacing.EAST);
} else
{
} else {
handlerDown = new InvWrapper(this);
handlerUp = handlerDown;
handlerNorth = handlerDown;
@ -258,36 +229,25 @@ public class TileInventory extends TileBase implements IInventory
}
}
IItemHandler handlerDown;
IItemHandler handlerUp;
IItemHandler handlerNorth;
IItemHandler handlerSouth;
IItemHandler handlerWest;
IItemHandler handlerEast;
@SuppressWarnings("unchecked")
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing)
{
if (facing != null && capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
{
switch (facing)
{
case DOWN:
return (T) handlerDown;
case EAST:
return (T) handlerEast;
case NORTH:
return (T) handlerNorth;
case SOUTH:
return (T) handlerSouth;
case UP:
return (T) handlerUp;
case WEST:
return (T) handlerWest;
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
if (facing != null && capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
switch (facing) {
case DOWN:
return (T) handlerDown;
case EAST:
return (T) handlerEast;
case NORTH:
return (T) handlerNorth;
case SOUTH:
return (T) handlerSouth;
case UP:
return (T) handlerUp;
case WEST:
return (T) handlerWest;
}
} else if (facing == null && capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
{
} else if (facing == null && capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
return (T) handlerDown;
}
@ -295,8 +255,7 @@ public class TileInventory extends TileBase implements IInventory
}
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing)
{
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
}
}

View file

@ -1,9 +1,13 @@
package WayofTime.bloodmagic.tile;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.core.RegistrarBloodMagicBlocks;
import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler;
import WayofTime.bloodmagic.inversion.InversionPillarHandler;
import WayofTime.bloodmagic.tile.base.TileTicking;
import com.google.common.collect.ImmutableMap;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
@ -19,18 +23,13 @@ import net.minecraftforge.common.animation.TimeValues.VariableValue;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.model.animation.CapabilityAnimation;
import net.minecraftforge.common.model.animation.IAnimationStateMachine;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler;
import WayofTime.bloodmagic.inversion.InversionPillarHandler;
import WayofTime.bloodmagic.core.RegistrarBloodMagicBlocks;
import WayofTime.bloodmagic.tile.base.TileTicking;
import com.google.common.collect.ImmutableMap;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
public class TileInversionPillar extends TileTicking
{
public class TileInversionPillar extends TileTicking {
public static final double maxWillForChunk = 1000;
public static double willPerOperation = 0.5;
public static double inversionPerOperation = 4;
public static double addedInversionPerFailedCheck = 1;
@ -41,9 +40,7 @@ public class TileInversionPillar extends TileTicking
public static double willPushRate = 1;
public static double inversionCostPerWillSpread = 4;
public static double minimumWillForChunkWhenSpreading = 100;
private final IAnimationStateMachine asm;
private float animationOffsetValue = 0;
private final VariableValue animationOffset = new VariableValue(0);
private final VariableValue cycleLength = new VariableValue(4);
@ -58,45 +55,37 @@ public class TileInversionPillar extends TileTicking
public int counter = 0;
public boolean isRegistered = false;
private float animationOffsetValue = 0;
public static final double maxWillForChunk = 1000;
public TileInversionPillar()
{
public TileInversionPillar() {
this(EnumDemonWillType.DEFAULT);
}
public TileInversionPillar(EnumDemonWillType type)
{
public TileInversionPillar(EnumDemonWillType type) {
this.type = type;
asm = BloodMagic.proxy.load(new ResourceLocation(BloodMagic.MODID.toLowerCase(), "asms/block/inversion_pillar.json"), ImmutableMap.<String, ITimeValue>of("offset", animationOffset, "cycle_length", cycleLength));
animationOffsetValue = -1;
}
@Override
public void onUpdate()
{
if (animationOffsetValue < 0)
{
public void onUpdate() {
if (animationOffsetValue < 0) {
animationOffsetValue = getWorld().getTotalWorldTime() * getWorld().rand.nextFloat();
animationOffset.setValue(animationOffsetValue);
}
if (getWorld().isRemote)
{
if (getWorld().isRemote) {
return;
}
if (!isRegistered)
{
if (!isRegistered) {
isRegistered = InversionPillarHandler.addPillarToMap(getWorld(), getType(), getPos());
}
counter++;
double currentWill = WorldDemonWillHandler.getCurrentWill(getWorld(), pos, type);
if (counter % 1 == 0)
{
if (counter % 1 == 0) {
List<BlockPos> pillarList = getNearbyPillarsExcludingThis();
// if (type == EnumDemonWillType.VENGEFUL)
// {
@ -105,33 +94,27 @@ public class TileInversionPillar extends TileTicking
generateWillForNearbyPillars(currentWill, pillarList);
generateInversionForNearbyPillars(currentWill, pillarList);
int pollute = polluteNearbyBlocks(currentWill);
if (pollute == 1)
{
if (pollute == 1) {
currentInversion += addedInversionPerFailedCheck;
consecutiveFailedChecks++;
} else if (pollute == 3)
{
} else if (pollute == 3) {
currentInversion += addedInversionPerFailedCheck;
consecutiveFailedAirChecks++;
} else if (pollute == 0)
{
} else if (pollute == 0) {
//We successfully found a block to replace!
consecutiveFailedChecks = 0;
consecutiveFailedAirChecks = 0;
}
if (consecutiveFailedAirChecks > 100)
{
if (consecutiveFailedAirChecks > 100) {
createObstructionsInAir();
}
if (currentInversion >= inversionToSpreadWill)
{
if (currentInversion >= inversionToSpreadWill) {
spreadWillToSurroundingChunks();
}
if (consecutiveFailedChecks > 5 * currentInfectionRadius && currentInversion >= inversionToIncreaseRadius)
{
if (consecutiveFailedChecks > 5 * currentInfectionRadius && currentInversion >= inversionToIncreaseRadius) {
currentInfectionRadius++;
consecutiveFailedChecks = 0;
currentInversion -= inversionToIncreaseRadius;
@ -144,13 +127,11 @@ public class TileInversionPillar extends TileTicking
System.out.println("Increasing radius due to being in the air!");
}
if (currentInfectionRadius >= 8 && currentInversion >= inversionToAddPillar)
{
if (currentInfectionRadius >= 8 && currentInversion >= inversionToAddPillar) {
//TODO: Improve algorithm
List<BlockPos> allConnectedPos = InversionPillarHandler.getAllConnectedPillars(getWorld(), type, pos);
BlockPos candidatePos = findCandidatePositionForPillar(getWorld(), type, pos, allConnectedPos, 5, 10);
if (!candidatePos.equals(BlockPos.ORIGIN))
{
if (!candidatePos.equals(BlockPos.ORIGIN)) {
currentInversion = 0;
IBlockState pillarState = RegistrarBloodMagicBlocks.INVERSION_PILLAR.getStateFromMeta(type.ordinal());
IBlockState bottomState = RegistrarBloodMagicBlocks.INVERSION_PILLAR_END.getStateFromMeta(type.ordinal() * 2);
@ -168,10 +149,8 @@ public class TileInversionPillar extends TileTicking
// return 0;
// }
public void createObstructionsInAir()
{
if (currentInversion > 1000)
{
public void createObstructionsInAir() {
if (currentInversion > 1000) {
Vec3d vec = new Vec3d(getWorld().rand.nextDouble() * 2 - 1, getWorld().rand.nextDouble() * 2 - 1, getWorld().rand.nextDouble() * 2 - 1).normalize().scale(2 * currentInfectionRadius);
BlockPos centralPos = pos.add(vec.x, vec.y, vec.z);
@ -181,72 +160,18 @@ public class TileInversionPillar extends TileTicking
}
}
public static BlockPos findCandidatePositionForPillar(World world, EnumDemonWillType type, BlockPos pos, List<BlockPos> posList, double tooCloseDistance, double wantedAverageDistance)
{
int maxIterations = 100;
int heightCheckRange = 3;
for (int i = 0; i < maxIterations; i++)
{
Collections.shuffle(posList);
BlockPos pillarPos = posList.get(0);
Vec3d vec = new Vec3d(world.rand.nextDouble() * 2 - 1, world.rand.nextDouble() * 2 - 1, world.rand.nextDouble() * 2 - 1).normalize().scale(wantedAverageDistance);
BlockPos centralPos = pillarPos.add(vec.x, vec.y, vec.z);
BlockPos testPos = null;
candidateTest: for (int h = 0; h <= heightCheckRange; h++)
{
for (int sig = -1; sig <= 1; sig += (h > 0 ? 2 : 3))
{
BlockPos candidatePos = centralPos.add(0, sig * h, 0);
if (world.isAirBlock(candidatePos) && world.isAirBlock(candidatePos.up()) && world.isAirBlock(candidatePos.down()) && !world.isAirBlock(candidatePos.down(2)))
{
testPos = candidatePos;
break candidateTest;
}
}
}
if (testPos != null)
{
boolean isValid = true;
for (BlockPos pillarTestPos : posList)
{
if (pillarTestPos.distanceSq(testPos) <= tooCloseDistance * tooCloseDistance)
{
isValid = false;
break;
}
}
if (isValid)
{
return testPos;
}
}
}
return BlockPos.ORIGIN;
}
public void spreadWillToSurroundingChunks()
{
public void spreadWillToSurroundingChunks() {
double currentAmount = WorldDemonWillHandler.getCurrentWill(getWorld(), pos, type);
if (currentAmount <= minimumWillForChunkWhenSpreading)
{
if (currentAmount <= minimumWillForChunkWhenSpreading) {
return;
}
for (EnumFacing side : EnumFacing.HORIZONTALS)
{
for (EnumFacing side : EnumFacing.HORIZONTALS) {
BlockPos offsetPos = pos.offset(side, 16);
double sideAmount = WorldDemonWillHandler.getCurrentWill(getWorld(), offsetPos, type);
if (currentAmount > sideAmount)
{
if (currentAmount > sideAmount) {
double drainAmount = Math.min((currentAmount - sideAmount) / 2, willPushRate);
if (drainAmount < willPushRate / 2)
{
if (drainAmount < willPushRate / 2) {
continue;
}
@ -258,26 +183,21 @@ public class TileInversionPillar extends TileTicking
}
}
public void removePillarFromMap()
{
if (!getWorld().isRemote)
{
public void removePillarFromMap() {
if (!getWorld().isRemote) {
InversionPillarHandler.removePillarFromMap(getWorld(), type, pos);
}
}
public List<BlockPos> getNearbyPillarsExcludingThis()
{
public List<BlockPos> getNearbyPillarsExcludingThis() {
return InversionPillarHandler.getNearbyPillars(getWorld(), type, pos);
}
@Override
public void deserialize(NBTTagCompound tag)
{
public void deserialize(NBTTagCompound tag) {
super.deserialize(tag);
if (!tag.hasKey(Constants.NBT.WILL_TYPE))
{
if (!tag.hasKey(Constants.NBT.WILL_TYPE)) {
type = EnumDemonWillType.DEFAULT;
}
@ -291,8 +211,7 @@ public class TileInversionPillar extends TileTicking
}
@Override
public NBTTagCompound serialize(NBTTagCompound tag)
{
public NBTTagCompound serialize(NBTTagCompound tag) {
super.serialize(tag);
tag.setString(Constants.NBT.WILL_TYPE, type.toString());
@ -304,31 +223,26 @@ public class TileInversionPillar extends TileTicking
return tag;
}
public void generateWillForNearbyPillars(double currentWillInChunk, List<BlockPos> offsetPositions)
{
public void generateWillForNearbyPillars(double currentWillInChunk, List<BlockPos> offsetPositions) {
double totalGeneratedWill = 0;
double willFactor = currentWillInChunk / 1000;
for (BlockPos offsetPos : offsetPositions)
{
for (BlockPos offsetPos : offsetPositions) {
double distanceSquared = offsetPos.distanceSq(pos);
totalGeneratedWill += willFactor * 343 / (343 + Math.pow(distanceSquared, 3 / 2));
}
if (totalGeneratedWill > 0)
{
if (totalGeneratedWill > 0) {
WorldDemonWillHandler.fillWillToMaximum(getWorld(), pos, type, totalGeneratedWill, maxWillForChunk, true);
}
}
public void generateInversionForNearbyPillars(double currentWillInChunk, List<BlockPos> offsetPositions)
{
public void generateInversionForNearbyPillars(double currentWillInChunk, List<BlockPos> offsetPositions) {
double willFactor = currentWillInChunk / 400;
double totalGeneratedInversion = willFactor;
for (BlockPos offsetPos : offsetPositions)
{
for (BlockPos offsetPos : offsetPositions) {
double distanceSquared = offsetPos.distanceSq(pos);
totalGeneratedInversion += 3125 / (3125 + Math.pow(distanceSquared, 5 / 2));
@ -338,30 +252,25 @@ public class TileInversionPillar extends TileTicking
}
/**
*
* @param currentWillInChunk
* @return 0 if the block is successfully placed, 1 if the block is not
* placed due to the selected place being invalid, 2 if the block is
* not placed due to there not being enough Will or Inversion, 3 if
* the block is not placed due to the selected block being air.
* placed due to the selected place being invalid, 2 if the block is
* not placed due to there not being enough Will or Inversion, 3 if
* the block is not placed due to the selected block being air.
*/
public int polluteNearbyBlocks(double currentWillInChunk)
{
public int polluteNearbyBlocks(double currentWillInChunk) {
// System.out.println("Hai! :D Current Inversion: " + currentInversion + ", Current Will: " + currentWillInChunk);
if (currentWillInChunk < operationThreshold || currentInversion < inversionPerOperation)
{
if (currentWillInChunk < operationThreshold || currentInversion < inversionPerOperation) {
return 2; //Not enough Will or Inversion available
}
for (int i = 0; i < currentInfectionRadius; i++)
{
for (int i = 0; i < currentInfectionRadius; i++) {
double xOff = (getWorld().rand.nextBoolean() ? 1 : -1) * (getWorld().rand.nextGaussian() + 1) * (currentInfectionRadius);
double yOff = (getWorld().rand.nextBoolean() ? 1 : -1) * (getWorld().rand.nextGaussian() + 1) * (currentInfectionRadius);
double zOff = (getWorld().rand.nextBoolean() ? 1 : -1) * (getWorld().rand.nextGaussian() + 1) * (currentInfectionRadius);
double r2 = xOff * xOff + yOff * yOff + zOff * zOff;
int maxInfectionRadius2 = (9 * currentInfectionRadius * currentInfectionRadius);
if (r2 > maxInfectionRadius2)
{
if (r2 > maxInfectionRadius2) {
double factor = Math.sqrt(maxInfectionRadius2 / r2);
xOff *= factor;
yOff *= factor;
@ -369,20 +278,16 @@ public class TileInversionPillar extends TileTicking
}
BlockPos offsetPos = pos.add(xOff + 0.5, yOff + 0.5, zOff + 0.5);
if (offsetPos.equals(pos))
{
if (offsetPos.equals(pos)) {
return 1; //Invalid block (itself!)
}
IBlockState state = getWorld().getBlockState(offsetPos);
if (!state.getBlock().isAir(state, getWorld(), offsetPos))
{
if (!state.getBlock().isAir(state, getWorld(), offsetPos)) {
//Consume Will and set this block
Block block = state.getBlock();
if (block == Blocks.DIRT || block == Blocks.STONE || block == Blocks.GRASS)
{
if (getWorld().setBlockState(offsetPos, RegistrarBloodMagicBlocks.DEMON_EXTRAS.getStateFromMeta(0)))
{
if (block == Blocks.DIRT || block == Blocks.STONE || block == Blocks.GRASS) {
if (getWorld().setBlockState(offsetPos, RegistrarBloodMagicBlocks.DEMON_EXTRAS.getStateFromMeta(0))) {
WorldDemonWillHandler.drainWill(getWorld(), pos, type, willPerOperation, true);
currentInversion -= inversionPerOperation;
@ -397,40 +302,150 @@ public class TileInversionPillar extends TileTicking
return 3; //The block was air
}
public void handleEvents(float time, Iterable<Event> pastEvents)
{
for (Event event : pastEvents)
{
public void handleEvents(float time, Iterable<Event> pastEvents) {
for (Event event : pastEvents) {
System.out.println("Event: " + event.event() + " " + event.offset() + " " + getPos() + " " + time);
}
}
@Override
public boolean hasFastRenderer()
{
public boolean hasFastRenderer() {
return true;
}
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing side)
{
if (capability == CapabilityAnimation.ANIMATION_CAPABILITY)
{
public boolean hasCapability(Capability<?> capability, EnumFacing side) {
if (capability == CapabilityAnimation.ANIMATION_CAPABILITY) {
return true;
}
return super.hasCapability(capability, side);
}
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing side)
{
if (capability == CapabilityAnimation.ANIMATION_CAPABILITY)
{
public <T> T getCapability(Capability<T> capability, EnumFacing side) {
if (capability == CapabilityAnimation.ANIMATION_CAPABILITY) {
return CapabilityAnimation.ANIMATION_CAPABILITY.cast(asm);
}
return super.getCapability(capability, side);
}
public IAnimationStateMachine getAsm() {
return asm;
}
public float getAnimationOffsetValue() {
return animationOffsetValue;
}
public void setAnimationOffsetValue(float animationOffsetValue) {
this.animationOffsetValue = animationOffsetValue;
}
public VariableValue getAnimationOffset() {
return animationOffset;
}
public VariableValue getCycleLength() {
return cycleLength;
}
public EnumDemonWillType getType() {
return type;
}
public void setType(EnumDemonWillType type) {
this.type = type;
}
public double getCurrentInversion() {
return currentInversion;
}
public void setCurrentInversion(double currentInversion) {
this.currentInversion = currentInversion;
}
public int getConsecutiveFailedChecks() {
return consecutiveFailedChecks;
}
public void setConsecutiveFailedChecks(int consecutiveFailedChecks) {
this.consecutiveFailedChecks = consecutiveFailedChecks;
}
public int getConsecutiveFailedAirChecks() {
return consecutiveFailedAirChecks;
}
public void setConsecutiveFailedAirChecks(int consecutiveFailedAirChecks) {
this.consecutiveFailedAirChecks = consecutiveFailedAirChecks;
}
public int getCurrentInfectionRadius() {
return currentInfectionRadius;
}
public void setCurrentInfectionRadius(int currentInfectionRadius) {
this.currentInfectionRadius = currentInfectionRadius;
}
public int getCounter() {
return counter;
}
public void setCounter(int counter) {
this.counter = counter;
}
public boolean isRegistered() {
return isRegistered;
}
public void setRegistered(boolean registered) {
isRegistered = registered;
}
public static BlockPos findCandidatePositionForPillar(World world, EnumDemonWillType type, BlockPos pos, List<BlockPos> posList, double tooCloseDistance, double wantedAverageDistance) {
int maxIterations = 100;
int heightCheckRange = 3;
for (int i = 0; i < maxIterations; i++) {
Collections.shuffle(posList);
BlockPos pillarPos = posList.get(0);
Vec3d vec = new Vec3d(world.rand.nextDouble() * 2 - 1, world.rand.nextDouble() * 2 - 1, world.rand.nextDouble() * 2 - 1).normalize().scale(wantedAverageDistance);
BlockPos centralPos = pillarPos.add(vec.x, vec.y, vec.z);
BlockPos testPos = null;
candidateTest:
for (int h = 0; h <= heightCheckRange; h++) {
for (int sig = -1; sig <= 1; sig += (h > 0 ? 2 : 3)) {
BlockPos candidatePos = centralPos.add(0, sig * h, 0);
if (world.isAirBlock(candidatePos) && world.isAirBlock(candidatePos.up()) && world.isAirBlock(candidatePos.down()) && !world.isAirBlock(candidatePos.down(2))) {
testPos = candidatePos;
break candidateTest;
}
}
}
if (testPos != null) {
boolean isValid = true;
for (BlockPos pillarTestPos : posList) {
if (pillarTestPos.distanceSq(testPos) <= tooCloseDistance * tooCloseDistance) {
isValid = false;
break;
}
}
if (isValid) {
return testPos;
}
}
}
return BlockPos.ORIGIN;
}
public static double getWillPerOperation() {
return willPerOperation;
}
@ -511,82 +526,6 @@ public class TileInversionPillar extends TileTicking
TileInversionPillar.minimumWillForChunkWhenSpreading = minimumWillForChunkWhenSpreading;
}
public IAnimationStateMachine getAsm() {
return asm;
}
public float getAnimationOffsetValue() {
return animationOffsetValue;
}
public void setAnimationOffsetValue(float animationOffsetValue) {
this.animationOffsetValue = animationOffsetValue;
}
public VariableValue getAnimationOffset() {
return animationOffset;
}
public VariableValue getCycleLength() {
return cycleLength;
}
public EnumDemonWillType getType() {
return type;
}
public void setType(EnumDemonWillType type) {
this.type = type;
}
public double getCurrentInversion() {
return currentInversion;
}
public void setCurrentInversion(double currentInversion) {
this.currentInversion = currentInversion;
}
public int getConsecutiveFailedChecks() {
return consecutiveFailedChecks;
}
public void setConsecutiveFailedChecks(int consecutiveFailedChecks) {
this.consecutiveFailedChecks = consecutiveFailedChecks;
}
public int getConsecutiveFailedAirChecks() {
return consecutiveFailedAirChecks;
}
public void setConsecutiveFailedAirChecks(int consecutiveFailedAirChecks) {
this.consecutiveFailedAirChecks = consecutiveFailedAirChecks;
}
public int getCurrentInfectionRadius() {
return currentInfectionRadius;
}
public void setCurrentInfectionRadius(int currentInfectionRadius) {
this.currentInfectionRadius = currentInfectionRadius;
}
public int getCounter() {
return counter;
}
public void setCounter(int counter) {
this.counter = counter;
}
public boolean isRegistered() {
return isRegistered;
}
public void setRegistered(boolean registered) {
isRegistered = registered;
}
public static double getMaxWillForChunk() {
return maxWillForChunk;
}

View file

@ -1,18 +1,5 @@
package WayofTime.bloodmagic.tile;
import java.util.ArrayList;
import java.util.List;
import WayofTime.bloodmagic.tile.base.TileTicking;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Event;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.event.RitualEvent;
import WayofTime.bloodmagic.api.registry.RitualRegistry;
@ -24,16 +11,26 @@ import WayofTime.bloodmagic.api.util.helper.NBTHelper;
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
import WayofTime.bloodmagic.api.util.helper.PlayerHelper;
import WayofTime.bloodmagic.api.util.helper.RitualHelper;
import WayofTime.bloodmagic.item.ItemActivationCrystal;
import WayofTime.bloodmagic.core.RegistrarBloodMagicItems;
import WayofTime.bloodmagic.item.ItemActivationCrystal;
import WayofTime.bloodmagic.tile.base.TileTicking;
import WayofTime.bloodmagic.util.ChatUtil;
import com.google.common.base.Strings;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Event;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
public class TileMasterRitualStone extends TileTicking implements IMasterRitualStone
{
public class TileMasterRitualStone extends TileTicking implements IMasterRitualStone {
private String owner;
private SoulNetwork cachedNetwork;
private boolean active;
@ -46,21 +43,18 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
private List<EnumDemonWillType> currentActiveWillConfig = new ArrayList<EnumDemonWillType>();
@Override
public void onUpdate()
{
public void onUpdate() {
if (getWorld().isRemote)
return;
if (isPowered() && isActive())
{
if (isPowered() && isActive()) {
active = false;
redstoned = true;
stopRitual(Ritual.BreakType.REDSTONE);
return;
}
if (!isActive() && !isPowered() && isRedstoned() && getCurrentRitual() != null)
{
if (!isActive() && !isPowered() && isRedstoned() && getCurrentRitual() != null) {
active = true;
ItemStack crystalStack = NBTHelper.checkNBT(new ItemStack(RegistrarBloodMagicItems.ACTIVATION_CRYSTAL, 1, getCurrentRitual().getCrystalLevel()));
crystalStack.getTagCompound().setString(Constants.NBT.OWNER_UUID, getOwner());
@ -68,8 +62,7 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
redstoned = false;
}
if (getCurrentRitual() != null && isActive())
{
if (getCurrentRitual() != null && isActive()) {
if (activeTime % getCurrentRitual().getRefreshTime() == 0)
performRitual(getWorld(), getPos());
@ -78,17 +71,14 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
}
@Override
public void deserialize(NBTTagCompound tag)
{
public void deserialize(NBTTagCompound tag) {
owner = tag.getString(Constants.NBT.OWNER_UUID);
if (!Strings.isNullOrEmpty(owner))
cachedNetwork = NetworkHelper.getSoulNetwork(owner);
currentRitual = RitualRegistry.getRitualForId(tag.getString(Constants.NBT.CURRENT_RITUAL));
if (currentRitual != null)
{
if (currentRitual != null) {
NBTTagCompound ritualTag = tag.getCompoundTag(Constants.NBT.CURRENT_RITUAL_TAG);
if (!ritualTag.hasNoTags())
{
if (!ritualTag.hasNoTags()) {
currentRitual.readFromNBT(ritualTag);
}
}
@ -97,23 +87,19 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
direction = EnumFacing.VALUES[tag.getInteger(Constants.NBT.DIRECTION)];
redstoned = tag.getBoolean(Constants.NBT.IS_REDSTONED);
for (EnumDemonWillType type : EnumDemonWillType.values())
{
if (tag.getBoolean("EnumWill" + type))
{
for (EnumDemonWillType type : EnumDemonWillType.values()) {
if (tag.getBoolean("EnumWill" + type)) {
currentActiveWillConfig.add(type);
}
}
}
@Override
public NBTTagCompound serialize(NBTTagCompound tag)
{
public NBTTagCompound serialize(NBTTagCompound tag) {
String ritualId = RitualRegistry.getIdForRitual(getCurrentRitual());
tag.setString(Constants.NBT.OWNER_UUID, Strings.isNullOrEmpty(getOwner()) ? "" : getOwner());
tag.setString(Constants.NBT.CURRENT_RITUAL, Strings.isNullOrEmpty(ritualId) ? "" : ritualId);
if (currentRitual != null)
{
if (currentRitual != null) {
NBTTagCompound ritualTag = new NBTTagCompound();
currentRitual.writeToNBT(ritualTag);
tag.setTag(Constants.NBT.CURRENT_RITUAL_TAG, ritualTag);
@ -123,8 +109,7 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
tag.setInteger(Constants.NBT.DIRECTION, direction.getIndex());
tag.setBoolean(Constants.NBT.IS_REDSTONED, redstoned);
for (EnumDemonWillType type : currentActiveWillConfig)
{
for (EnumDemonWillType type : currentActiveWillConfig) {
tag.setBoolean("EnumWill" + type, true);
}
@ -132,27 +117,21 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
}
@Override
public boolean activateRitual(ItemStack activationCrystal, @Nullable EntityPlayer activator, Ritual ritual)
{
public boolean activateRitual(ItemStack activationCrystal, @Nullable EntityPlayer activator, Ritual ritual) {
if (PlayerHelper.isFakePlayer(activator))
return false;
activationCrystal = NBTHelper.checkNBT(activationCrystal);
String crystalOwner = activationCrystal.getTagCompound().getString(Constants.NBT.OWNER_UUID);
if (!Strings.isNullOrEmpty(crystalOwner) && ritual != null)
{
if (activationCrystal.getItem() instanceof ItemActivationCrystal)
{
if (!Strings.isNullOrEmpty(crystalOwner) && ritual != null) {
if (activationCrystal.getItem() instanceof ItemActivationCrystal) {
int crystalLevel = ((ItemActivationCrystal) activationCrystal.getItem()).getCrystalLevel(activationCrystal);
if (RitualHelper.canCrystalActivate(ritual, crystalLevel))
{
if (!getWorld().isRemote)
{
if (RitualHelper.canCrystalActivate(ritual, crystalLevel)) {
if (!getWorld().isRemote) {
SoulNetwork network = NetworkHelper.getSoulNetwork(crystalOwner);
if (!isRedstoned() && network.getCurrentEssence() < ritual.getActivationCost() && (activator != null && !activator.capabilities.isCreativeMode))
{
if (!isRedstoned() && network.getCurrentEssence() < ritual.getActivationCost() && (activator != null && !activator.capabilities.isCreativeMode)) {
activator.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.ritual.weak"), true);
return false;
}
@ -162,15 +141,13 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
RitualEvent.RitualActivatedEvent event = new RitualEvent.RitualActivatedEvent(this, crystalOwner, ritual, activator, activationCrystal, crystalLevel);
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
{
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY) {
if (activator != null)
activator.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.ritual.prevent"), true);
return false;
}
if (ritual.activateRitual(this, activator, crystalOwner))
{
if (ritual.activateRitual(this, activator, crystalOwner)) {
if (!isRedstoned() && (activator != null && !activator.capabilities.isCreativeMode))
network.syphon(ritual.getActivationCost());
@ -191,8 +168,7 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
return true;
}
}
} else
{
} else {
if (activator != null)
activator.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.ritual.notValid"), true);
}
@ -201,38 +177,31 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
}
@Override
public void performRitual(World world, BlockPos pos)
{
if (!world.isRemote && getCurrentRitual() != null && RitualRegistry.ritualEnabled(getCurrentRitual()))
{
if (RitualHelper.checkValidRitual(getWorld(), getPos(), RitualRegistry.getIdForRitual(currentRitual), getDirection()))
{
public void performRitual(World world, BlockPos pos) {
if (!world.isRemote && getCurrentRitual() != null && RitualRegistry.ritualEnabled(getCurrentRitual())) {
if (RitualHelper.checkValidRitual(getWorld(), getPos(), RitualRegistry.getIdForRitual(currentRitual), getDirection())) {
RitualEvent.RitualRunEvent event = new RitualEvent.RitualRunEvent(this, getOwner(), getCurrentRitual());
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
return;
getCurrentRitual().performRitual(this);
} else
{
} else {
stopRitual(Ritual.BreakType.BREAK_STONE);
}
}
}
@Override
public void stopRitual(Ritual.BreakType breakType)
{
if (!getWorld().isRemote && getCurrentRitual() != null)
{
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) || event.getResult() == Event.Result.DENY)
return;
getCurrentRitual().stopRitual(this, breakType);
if (breakType != Ritual.BreakType.REDSTONE)
{
if (breakType != Ritual.BreakType.REDSTONE) {
this.currentRitual = null;
this.active = false;
this.activeTime = 0;
@ -242,82 +211,71 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
}
@Override
public int getCooldown()
{
public int getCooldown() {
return cooldown;
}
@Override
public void setCooldown(int cooldown)
{
public void setCooldown(int cooldown) {
this.cooldown = cooldown;
}
@Override
public void setActive(boolean active)
{
this.active = active;
}
@Override
public EnumFacing getDirection()
{
public EnumFacing getDirection() {
return direction;
}
public void setDirection(EnumFacing direction) {
this.direction = direction;
}
@Override
public boolean areTanksEmpty()
{
public boolean areTanksEmpty() {
return false;
}
@Override
public int getRunningTime()
{
public int getRunningTime() {
return activeTime;
}
@Override
public String getOwner()
{
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
@Override
public SoulNetwork getOwnerNetwork()
{
public SoulNetwork getOwnerNetwork() {
return cachedNetwork;
}
@Override
public World getWorld()
{
public World getWorld() {
return super.getWorld();
}
@Override
public BlockPos getPos()
{
public BlockPos getPos() {
return super.getPos();
}
@Override
public World getWorldObj()
{
public World getWorldObj() {
return getWorld();
}
@Override
public BlockPos getBlockPos()
{
public BlockPos getBlockPos() {
return getPos();
}
@Override
public String getNextBlockRange(String range)
{
if (this.currentRitual != null)
{
public String getNextBlockRange(String range) {
if (this.currentRitual != null) {
return this.currentRitual.getNextBlockRange(range);
}
@ -325,48 +283,38 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
}
@Override
public void provideInformationOfRitualToPlayer(EntityPlayer player)
{
if (this.currentRitual != null)
{
public void provideInformationOfRitualToPlayer(EntityPlayer player) {
if (this.currentRitual != null) {
ChatUtil.sendNoSpam(player, this.currentRitual.provideInformationOfRitualToPlayer(player));
}
}
@Override
public void provideInformationOfRangeToPlayer(EntityPlayer player, String range)
{
if (this.currentRitual != null && this.currentRitual.getListOfRanges().contains(range))
{
public void provideInformationOfRangeToPlayer(EntityPlayer player, String range) {
if (this.currentRitual != null && this.currentRitual.getListOfRanges().contains(range)) {
ChatUtil.sendNoSpam(player, this.currentRitual.provideInformationOfRangeToPlayer(player, range));
}
}
@Override
public void setActiveWillConfig(EntityPlayer player, List<EnumDemonWillType> typeList)
{
public void setActiveWillConfig(EntityPlayer player, List<EnumDemonWillType> typeList) {
this.currentActiveWillConfig = typeList;
}
@Override
public boolean setBlockRangeByBounds(EntityPlayer player, String range, BlockPos offset1, BlockPos offset2)
{
if (this.currentRitual != null)
{
public boolean setBlockRangeByBounds(EntityPlayer player, String range, BlockPos offset1, BlockPos offset2) {
if (this.currentRitual != null) {
boolean allowed = this.currentRitual.setBlockRangeByBounds(range, this, offset1, offset2);
if (player != null && !allowed)
{
if (player != null && !allowed) {
ChatUtil.sendNoSpam(player, this.currentRitual.getErrorForBlockRangeOnFail(player, range, this, offset1, offset2));
} else
{
} else {
ChatUtil.sendNoSpam(player, new TextComponentTranslation("ritual.bloodmagic.blockRange.success"));
}
return allowed;
}
if (player != null)
{
if (player != null) {
ChatUtil.sendNoSpam(player, new TextComponentTranslation("ritual.bloodmagic.blockRange.inactive"));
}
@ -374,49 +322,38 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
}
@Override
public List<EnumDemonWillType> getActiveWillConfig()
{
public List<EnumDemonWillType> getActiveWillConfig() {
return new ArrayList<EnumDemonWillType>(currentActiveWillConfig);
}
@Override
public void provideInformationOfWillConfigToPlayer(EntityPlayer player, List<EnumDemonWillType> typeList)
{
public void provideInformationOfWillConfigToPlayer(EntityPlayer player, List<EnumDemonWillType> typeList) {
//There is probably an easier way to make expanded chat messages
if (typeList.size() >= 1)
{
if (typeList.size() >= 1) {
Object[] translations = new TextComponentTranslation[typeList.size()];
String constructedString = "%s";
for (int i = 1; i < typeList.size(); i++)
{
for (int i = 1; i < typeList.size(); i++) {
constructedString = constructedString + ", %s";
}
for (int i = 0; i < typeList.size(); i++)
{
for (int i = 0; i < typeList.size(); i++) {
translations[i] = new TextComponentTranslation("tooltip.bloodmagic.currentBaseType." + typeList.get(i).name.toLowerCase());
}
ChatUtil.sendNoSpam(player, new TextComponentTranslation("ritual.bloodmagic.willConfig.set", new TextComponentTranslation(constructedString, translations)));
} else
{
} else {
ChatUtil.sendNoSpam(player, new TextComponentTranslation("ritual.bloodmagic.willConfig.void"));
}
}
public boolean isPowered()
{
public boolean isPowered() {
if (inverted)
return !getWorld().isBlockPowered(getPos());
return getWorld().isBlockPowered(getPos());
}
public void setOwner(String owner) {
this.owner = owner;
}
public SoulNetwork getCachedNetwork() {
return cachedNetwork;
}
@ -429,6 +366,11 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
return active;
}
@Override
public void setActive(boolean active) {
this.active = active;
}
public boolean isRedstoned() {
return redstoned;
}
@ -453,10 +395,6 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
this.currentRitual = currentRitual;
}
public void setDirection(EnumFacing direction) {
this.direction = direction;
}
public boolean isInverted() {
return inverted;
}

View file

@ -1,8 +1,11 @@
package WayofTime.bloodmagic.tile;
import java.lang.reflect.Field;
import java.util.List;
import WayofTime.bloodmagic.block.BlockMimic;
import WayofTime.bloodmagic.core.RegistrarBloodMagicBlocks;
import WayofTime.bloodmagic.core.RegistrarBloodMagicItems;
import WayofTime.bloodmagic.entity.mob.EntityMimic;
import WayofTime.bloodmagic.util.ChatUtil;
import WayofTime.bloodmagic.util.Utils;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
@ -25,17 +28,12 @@ import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.ReflectionHelper;
import WayofTime.bloodmagic.block.BlockMimic;
import WayofTime.bloodmagic.entity.mob.EntityMimic;
import WayofTime.bloodmagic.core.RegistrarBloodMagicBlocks;
import WayofTime.bloodmagic.core.RegistrarBloodMagicItems;
import WayofTime.bloodmagic.util.ChatUtil;
import WayofTime.bloodmagic.util.Utils;
import javax.annotation.Nullable;
import java.lang.reflect.Field;
import java.util.List;
public class TileMimic extends TileInventory implements ITickable
{
public class TileMimic extends TileInventory implements ITickable {
private static Field _blockMetadata = ReflectionHelper.findField(TileEntity.class, "blockMetadata", "field_145847_g");
public boolean dropItemsOnBreak = true;
@ -49,32 +47,25 @@ public class TileMimic extends TileInventory implements ITickable
private int internalCounter = 0;
public TileMimic()
{
public TileMimic() {
super(2, "mimic");
}
@Override
public void update()
{
if (getWorld().isRemote)
{
public void update() {
if (getWorld().isRemote) {
return;
}
internalCounter++;
if (internalCounter % potionSpawnInterval == 0 && this.getBlockMetadata() == BlockMimic.sentientMimicMeta)
{
if (internalCounter % potionSpawnInterval == 0 && this.getBlockMetadata() == BlockMimic.sentientMimicMeta) {
ItemStack potionStack = this.getStackInSlot(1);
if (!potionStack.isEmpty())
{
if (!potionStack.isEmpty()) {
AxisAlignedBB bb = new AxisAlignedBB(this.getPos()).expand(playerCheckRadius, playerCheckRadius, playerCheckRadius);
List<EntityPlayer> playerList = getWorld().getEntitiesWithinAABB(EntityPlayer.class, bb);
for (EntityPlayer player : playerList)
{
if (!player.capabilities.isCreativeMode)
{
for (EntityPlayer player : playerList) {
if (!player.capabilities.isCreativeMode) {
double posX = this.pos.getX() + 0.5 + (2 * getWorld().rand.nextDouble() - 1) * potionSpawnRadius;
double posY = this.pos.getY() + 0.5 + (2 * getWorld().rand.nextDouble() - 1) * potionSpawnRadius;
double posZ = this.pos.getZ() + 0.5 + (2 * getWorld().rand.nextDouble() - 1) * potionSpawnRadius;
@ -91,15 +82,12 @@ public class TileMimic extends TileInventory implements ITickable
}
}
if (this.getBlockMetadata() == BlockMimic.sentientMimicMeta && getWorld().getDifficulty() != EnumDifficulty.PEACEFUL && !(mimicedTile instanceof IInventory))
{
if (this.getBlockMetadata() == BlockMimic.sentientMimicMeta && getWorld().getDifficulty() != EnumDifficulty.PEACEFUL && !(mimicedTile instanceof IInventory)) {
AxisAlignedBB bb = new AxisAlignedBB(this.getPos()).expand(playerCheckRadius, playerCheckRadius, playerCheckRadius);
List<EntityPlayer> playerList = getWorld().getEntitiesWithinAABB(EntityPlayer.class, bb);
for (EntityPlayer player : playerList)
{
if (!player.capabilities.isCreativeMode && Utils.canEntitySeeBlock(getWorld(), player, getPos()))
{
for (EntityPlayer player : playerList) {
if (!player.capabilities.isCreativeMode && Utils.canEntitySeeBlock(getWorld(), player, getPos())) {
spawnMimicEntity(player);
break;
}
@ -108,25 +96,19 @@ public class TileMimic extends TileInventory implements ITickable
}
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side)
{
if (!heldItem.isEmpty() && player.capabilities.isCreativeMode)
{
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side) {
if (!heldItem.isEmpty() && player.capabilities.isCreativeMode) {
List<PotionEffect> list = PotionUtils.getEffectsFromStack(heldItem);
if (!list.isEmpty())
{
if (!world.isRemote)
{
if (!list.isEmpty()) {
if (!world.isRemote) {
setInventorySlotContents(1, heldItem.copy());
world.notifyBlockUpdate(pos, state, state, 3);
ChatUtil.sendNoSpam(player, new TextComponentTranslation("chat.bloodmagic.mimic.potionSet"));
}
return true;
} else if (heldItem.getItem() == RegistrarBloodMagicItems.POTION_FLASK)
{
} else if (heldItem.getItem() == RegistrarBloodMagicItems.POTION_FLASK) {
//The potion flask is empty, therefore we have to reset the stored potion.
if (!world.isRemote)
{
if (!world.isRemote) {
setInventorySlotContents(1, ItemStack.EMPTY);
world.notifyBlockUpdate(pos, state, state, 3);
ChatUtil.sendNoSpam(player, new TextComponentTranslation("chat.bloodmagic.mimic.potionRemove"));
@ -135,8 +117,7 @@ public class TileMimic extends TileInventory implements ITickable
}
}
if (performSpecialAbility(player, side))
{
if (performSpecialAbility(player, side)) {
return true;
}
@ -155,8 +136,7 @@ public class TileMimic extends TileInventory implements ITickable
Utils.insertItemToTile(this, player, 0);
this.refreshTileEntity();
if (player.capabilities.isCreativeMode)
{
if (player.capabilities.isCreativeMode) {
dropItemsOnBreak = getStackInSlot(0).isEmpty();
}
@ -164,93 +144,76 @@ public class TileMimic extends TileInventory implements ITickable
return true;
}
public boolean performSpecialAbility(EntityPlayer player, EnumFacing sideHit)
{
switch (this.getBlockMetadata())
{
case BlockMimic.sentientMimicMeta:
if (player.capabilities.isCreativeMode)
{
if (player.isSneaking())
{
playerCheckRadius = Math.max(playerCheckRadius - 1, 0);
ChatUtil.sendNoSpam(player, new TextComponentTranslation("chat.bloodmagic.mimic.detectRadius.down", playerCheckRadius));
} else
{
playerCheckRadius++;
ChatUtil.sendNoSpam(player, new TextComponentTranslation("chat.bloodmagic.mimic.detectRadius.up", playerCheckRadius));
}
return false;
}
return spawnMimicEntity(player);
default:
if (!player.capabilities.isCreativeMode)
{
return false;
}
if (player.getActiveItemStack().isEmpty() && !getStackInSlot(1).isEmpty())
{
switch (sideHit)
{
case EAST: //When the block is clicked on the EAST or WEST side, potionSpawnRadius is edited.
case WEST:
if (player.isSneaking())
{
potionSpawnRadius = Math.max(potionSpawnRadius - 1, 0);
ChatUtil.sendNoSpam(player, new TextComponentTranslation("chat.bloodmagic.mimic.potionSpawnRadius.down", potionSpawnRadius));
} else
{
potionSpawnRadius++;
ChatUtil.sendNoSpam(player, new TextComponentTranslation("chat.bloodmagic.mimic.potionSpawnRadius.up", potionSpawnRadius));
}
break;
case NORTH: //When the block is clicked on the NORTH or SOUTH side, detectRadius is edited.
case SOUTH:
if (player.isSneaking())
{
public boolean performSpecialAbility(EntityPlayer player, EnumFacing sideHit) {
switch (this.getBlockMetadata()) {
case BlockMimic.sentientMimicMeta:
if (player.capabilities.isCreativeMode) {
if (player.isSneaking()) {
playerCheckRadius = Math.max(playerCheckRadius - 1, 0);
ChatUtil.sendNoSpam(player, new TextComponentTranslation("chat.bloodmagic.mimic.detectRadius.down", playerCheckRadius));
} else
{
} else {
playerCheckRadius++;
ChatUtil.sendNoSpam(player, new TextComponentTranslation("chat.bloodmagic.mimic.detectRadius.up", playerCheckRadius));
}
break;
case UP: //When the block is clicked on the UP or DOWN side, potionSpawnInterval is edited.
case DOWN:
if (player.isSneaking())
{
potionSpawnInterval = Math.max(potionSpawnInterval - 1, 1);
ChatUtil.sendNoSpam(player, new TextComponentTranslation("chat.bloodmagic.mimic.potionInterval.down", potionSpawnInterval));
} else
{
potionSpawnInterval++;
ChatUtil.sendNoSpam(player, new TextComponentTranslation("chat.bloodmagic.mimic.potionInterval.up", potionSpawnInterval));
}
break;
default:
break;
return false;
}
return true;
}
return spawnMimicEntity(player);
default:
if (!player.capabilities.isCreativeMode) {
return false;
}
if (player.getActiveItemStack().isEmpty() && !getStackInSlot(1).isEmpty()) {
switch (sideHit) {
case EAST: //When the block is clicked on the EAST or WEST side, potionSpawnRadius is edited.
case WEST:
if (player.isSneaking()) {
potionSpawnRadius = Math.max(potionSpawnRadius - 1, 0);
ChatUtil.sendNoSpam(player, new TextComponentTranslation("chat.bloodmagic.mimic.potionSpawnRadius.down", potionSpawnRadius));
} else {
potionSpawnRadius++;
ChatUtil.sendNoSpam(player, new TextComponentTranslation("chat.bloodmagic.mimic.potionSpawnRadius.up", potionSpawnRadius));
}
break;
case NORTH: //When the block is clicked on the NORTH or SOUTH side, detectRadius is edited.
case SOUTH:
if (player.isSneaking()) {
playerCheckRadius = Math.max(playerCheckRadius - 1, 0);
ChatUtil.sendNoSpam(player, new TextComponentTranslation("chat.bloodmagic.mimic.detectRadius.down", playerCheckRadius));
} else {
playerCheckRadius++;
ChatUtil.sendNoSpam(player, new TextComponentTranslation("chat.bloodmagic.mimic.detectRadius.up", playerCheckRadius));
}
break;
case UP: //When the block is clicked on the UP or DOWN side, potionSpawnInterval is edited.
case DOWN:
if (player.isSneaking()) {
potionSpawnInterval = Math.max(potionSpawnInterval - 1, 1);
ChatUtil.sendNoSpam(player, new TextComponentTranslation("chat.bloodmagic.mimic.potionInterval.down", potionSpawnInterval));
} else {
potionSpawnInterval++;
ChatUtil.sendNoSpam(player, new TextComponentTranslation("chat.bloodmagic.mimic.potionInterval.up", potionSpawnInterval));
}
break;
default:
break;
}
return true;
}
}
return false;
}
public boolean spawnMimicEntity(EntityPlayer target)
{
if (this.getWorld().getDifficulty() == EnumDifficulty.PEACEFUL)
{
public boolean spawnMimicEntity(EntityPlayer target) {
if (this.getWorld().getDifficulty() == EnumDifficulty.PEACEFUL) {
return false;
}
if (this.getStackInSlot(0).isEmpty() || getWorld().isRemote)
{
if (this.getStackInSlot(0).isEmpty() || getWorld().isRemote) {
return false;
}
@ -263,8 +226,7 @@ public class TileMimic extends TileInventory implements ITickable
this.setInventorySlotContents(0, ItemStack.EMPTY);
getWorld().spawnEntity(mimicEntity);
if (target != null)
{
if (target != null) {
mimicEntity.setAttackTarget(target);
}
@ -273,18 +235,15 @@ public class TileMimic extends TileInventory implements ITickable
return true;
}
public void refreshTileEntity()
{
if (mimicedTile != null)
{
public void refreshTileEntity() {
if (mimicedTile != null) {
dropMimicedTileInventory();
}
mimicedTile = getTileFromStackWithTag(getWorld(), pos, getStackInSlot(0), tileTag, metaOfReplacedBlock);
}
@Override
public void deserialize(NBTTagCompound tag)
{
public void deserialize(NBTTagCompound tag) {
super.deserialize(tag);
dropItemsOnBreak = tag.getBoolean("dropItemsOnBreak");
@ -297,8 +256,7 @@ public class TileMimic extends TileInventory implements ITickable
}
@Override
public NBTTagCompound serialize(NBTTagCompound tag)
{
public NBTTagCompound serialize(NBTTagCompound tag) {
super.serialize(tag);
tag.setBoolean("dropItemsOnBreak", dropItemsOnBreak);
@ -311,25 +269,40 @@ public class TileMimic extends TileInventory implements ITickable
return tag;
}
public static void replaceMimicWithBlockActual(TileMimic mimic)
{
@Override
public void dropItems() {
if (dropItemsOnBreak) {
InventoryHelper.dropInventoryItems(getWorld(), getPos(), this);
}
dropMimicedTileInventory();
}
public void dropMimicedTileInventory() {
if (!getWorld().isRemote && mimicedTile instanceof IInventory) {
InventoryHelper.dropInventoryItems(getWorld(), getPos(), (IInventory) mimicedTile);
}
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack itemstack) {
return slot == 0 && dropItemsOnBreak;
}
public static void replaceMimicWithBlockActual(TileMimic mimic) {
World world = mimic.getWorld();
BlockPos pos = mimic.getPos();
replaceMimicWithBlockActual(world, pos, mimic.getStackInSlot(0), mimic.tileTag, mimic.metaOfReplacedBlock);
}
public static boolean replaceMimicWithBlockActual(World world, BlockPos pos, ItemStack stack, NBTTagCompound tileTag, int replacedMeta)
{
if (!stack.isEmpty() && stack.getItem() instanceof ItemBlock)
{
public static boolean replaceMimicWithBlockActual(World world, BlockPos pos, ItemStack stack, NBTTagCompound tileTag, int replacedMeta) {
if (!stack.isEmpty() && stack.getItem() instanceof ItemBlock) {
Block block = ((ItemBlock) stack.getItem()).getBlock();
IBlockState state = block.getStateFromMeta(replacedMeta);
if (world.setBlockState(pos, state, 3))
{
if (world.setBlockState(pos, state, 3)) {
TileEntity tile = world.getTileEntity(pos);
if (tile != null)
{
if (tile != null) {
tileTag.setInteger("x", pos.getX());
tileTag.setInteger("y", pos.getY());
tileTag.setInteger("z", pos.getZ());
@ -344,21 +317,17 @@ public class TileMimic extends TileInventory implements ITickable
}
@Nullable
public static TileEntity getTileFromStackWithTag(World world, BlockPos pos, ItemStack stack, @Nullable NBTTagCompound tag, int replacementMeta)
{
if (!stack.isEmpty() && stack.getItem() instanceof ItemBlock)
{
public static TileEntity getTileFromStackWithTag(World world, BlockPos pos, ItemStack stack, @Nullable NBTTagCompound tag, int replacementMeta) {
if (!stack.isEmpty() && stack.getItem() instanceof ItemBlock) {
Block block = ((ItemBlock) stack.getItem()).getBlock();
IBlockState state = block.getStateFromMeta(stack.getItemDamage());
if (block.hasTileEntity(state))
{
if (block.hasTileEntity(state)) {
TileEntity tile = block.createTileEntity(world, state);
if (tile == null)
return null;
if (tag != null)
{
if (tag != null) {
NBTTagCompound copyTag = tag.copy();
copyTag.setInteger("x", pos.getX());
copyTag.setInteger("y", pos.getY());
@ -368,14 +337,11 @@ public class TileMimic extends TileInventory implements ITickable
tile.setWorld(world);
try
{
try {
_blockMetadata.setInt(tile, replacementMeta);
} catch (IllegalArgumentException e)
{
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e)
{
} catch (IllegalAccessException e) {
e.printStackTrace();
}
@ -385,29 +351,4 @@ public class TileMimic extends TileInventory implements ITickable
return null;
}
@Override
public void dropItems()
{
if (dropItemsOnBreak)
{
InventoryHelper.dropInventoryItems(getWorld(), getPos(), this);
}
dropMimicedTileInventory();
}
public void dropMimicedTileInventory()
{
if (!getWorld().isRemote && mimicedTile instanceof IInventory)
{
InventoryHelper.dropInventoryItems(getWorld(), getPos(), (IInventory) mimicedTile);
}
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack itemstack)
{
return slot == 0 && dropItemsOnBreak;
}
}

View file

@ -4,38 +4,32 @@ import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.tile.base.TileTicking;
import net.minecraft.nbt.NBTTagCompound;
public class TilePhantomBlock extends TileTicking
{
public class TilePhantomBlock extends TileTicking {
private int ticksRemaining = 10;
public TilePhantomBlock() {
}
public TilePhantomBlock(int ticksRemaining)
{
public TilePhantomBlock(int ticksRemaining) {
this.ticksRemaining = ticksRemaining;
}
@Override
public void deserialize(NBTTagCompound tagCompound)
{
public void deserialize(NBTTagCompound tagCompound) {
this.ticksRemaining = tagCompound.getInteger(Constants.NBT.TICKS_REMAINING);
}
@Override
public NBTTagCompound serialize(NBTTagCompound tagCompound)
{
public NBTTagCompound serialize(NBTTagCompound tagCompound) {
tagCompound.setInteger(Constants.NBT.TICKS_REMAINING, ticksRemaining);
return tagCompound;
}
@Override
public void onUpdate()
{
public void onUpdate() {
ticksRemaining--;
if (ticksRemaining <= 0)
{
if (ticksRemaining <= 0) {
getWorld().setBlockToAir(getPos());
getWorld().removeTileEntity(getPos());
}

View file

@ -1,7 +1,8 @@
package WayofTime.bloodmagic.tile;
import java.util.List;
import WayofTime.bloodmagic.api.iface.IPurificationAsh;
import WayofTime.bloodmagic.api.ritual.AreaDescriptor;
import WayofTime.bloodmagic.api.util.helper.PurificationHelper;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -10,63 +11,51 @@ import net.minecraft.util.ITickable;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldServer;
import WayofTime.bloodmagic.api.iface.IPurificationAsh;
import WayofTime.bloodmagic.api.ritual.AreaDescriptor;
import WayofTime.bloodmagic.api.util.helper.PurificationHelper;
public class TilePurificationAltar extends TileInventory implements ITickable
{
import java.util.List;
public class TilePurificationAltar extends TileInventory implements ITickable {
public AreaDescriptor purityArea = new AreaDescriptor.Rectangle(new BlockPos(-5, -5, -5), 11);
public double totalPurity = 0;
public double maxPurity = 0;
public double purityRate = 0;
public TilePurificationAltar()
{
public TilePurificationAltar() {
super(1, "purificationAltar");
}
@Override
public void update()
{
if (totalPurity <= 0)
{
public void update() {
if (totalPurity <= 0) {
ItemStack stack = this.getStackInSlot(0);
if (!stack.isEmpty() && stack.getItem() instanceof IPurificationAsh)
{
if (!stack.isEmpty() && stack.getItem() instanceof IPurificationAsh) {
totalPurity = ((IPurificationAsh) stack.getItem()).getTotalPurity(stack);
maxPurity = ((IPurificationAsh) stack.getItem()).getMaxPurity(stack);
purityRate = ((IPurificationAsh) stack.getItem()).getPurityRate(stack);
}
} else
{
} else {
return;
}
AxisAlignedBB aabb = purityArea.getAABB(getPos());
List<EntityAnimal> animalList = getWorld().getEntitiesWithinAABB(EntityAnimal.class, aabb);
if (animalList.isEmpty())
{
if (animalList.isEmpty()) {
return;
}
boolean hasPerformed = false;
for (EntityAnimal animal : animalList)
{
for (EntityAnimal animal : animalList) {
double added = PurificationHelper.addPurity(animal, Math.min(purityRate, totalPurity), maxPurity);
if (added > 0)
{
if (added > 0) {
totalPurity -= purityRate;
hasPerformed = true;
}
}
if (hasPerformed)
{
if (getWorld().rand.nextInt(4) == 0 && getWorld() instanceof WorldServer)
{
if (hasPerformed) {
if (getWorld().rand.nextInt(4) == 0 && getWorld() instanceof WorldServer) {
WorldServer server = (WorldServer) getWorld();
server.spawnParticle(EnumParticleTypes.FLAME, pos.getX() + 0.5, pos.getY() + 1.2, pos.getZ() + 0.5, 1, 0.02, 0.03, 0.02, 0, new int[0]);
}
@ -74,8 +63,7 @@ public class TilePurificationAltar extends TileInventory implements ITickable
}
@Override
public void deserialize(NBTTagCompound tag)
{
public void deserialize(NBTTagCompound tag) {
super.deserialize(tag);
totalPurity = tag.getDouble("totalPurity");
maxPurity = tag.getDouble("maxPurity");
@ -83,8 +71,7 @@ public class TilePurificationAltar extends TileInventory implements ITickable
}
@Override
public NBTTagCompound serialize(NBTTagCompound tag)
{
public NBTTagCompound serialize(NBTTagCompound tag) {
super.serialize(tag);
tag.setDouble("totalPurity", totalPurity);

View file

@ -15,8 +15,7 @@ import net.minecraft.util.ITickable;
import java.util.ArrayList;
import java.util.List;
public class TileSoulForge extends TileInventory implements ITickable, IDemonWillConduit
{
public class TileSoulForge extends TileInventory implements ITickable, IDemonWillConduit {
public static final int ticksRequired = 100;
public static final double worldWillTransferRate = 1;
@ -27,22 +26,19 @@ public class TileSoulForge extends TileInventory implements ITickable, IDemonWil
public int burnTime = 0;
public TileSoulForge()
{
public TileSoulForge() {
super(6, "soulForge");
}
@Override
public void deserialize(NBTTagCompound tag)
{
public void deserialize(NBTTagCompound tag) {
super.deserialize(tag);
burnTime = tag.getInteger(Constants.NBT.SOUL_FORGE_BURN);
}
@Override
public NBTTagCompound serialize(NBTTagCompound tag)
{
public NBTTagCompound serialize(NBTTagCompound tag) {
super.serialize(tag);
tag.setInteger(Constants.NBT.SOUL_FORGE_BURN, burnTime);
@ -50,22 +46,17 @@ public class TileSoulForge extends TileInventory implements ITickable, IDemonWil
}
@Override
public void update()
{
if (!getWorld().isRemote)
{
for (EnumDemonWillType type : EnumDemonWillType.values())
{
public void update() {
if (!getWorld().isRemote) {
for (EnumDemonWillType type : EnumDemonWillType.values()) {
double willInWorld = WorldDemonWillHandler.getCurrentWill(getWorld(), pos, type);
double filled = Math.min(willInWorld, worldWillTransferRate);
if (filled > 0)
{
if (filled > 0) {
filled = this.fillDemonWill(type, filled, false);
filled = WorldDemonWillHandler.drainWill(getWorld(), pos, type, filled, false);
if (filled > 0)
{
if (filled > 0) {
this.fillDemonWill(type, filled, true);
WorldDemonWillHandler.drainWill(getWorld(), pos, type, filled, true);
}
@ -73,8 +64,7 @@ public class TileSoulForge extends TileInventory implements ITickable, IDemonWil
}
}
if (!hasSoulGemOrSoul())
{
if (!hasSoulGemOrSoul()) {
burnTime = 0;
return;
}
@ -83,30 +73,22 @@ public class TileSoulForge extends TileInventory implements ITickable, IDemonWil
List<ItemStack> inputList = new ArrayList<ItemStack>();
for (int i = 0; i < 4; i++)
{
if (!getStackInSlot(i).isEmpty())
{
for (int i = 0; i < 4; i++) {
if (!getStackInSlot(i).isEmpty()) {
inputList.add(getStackInSlot(i));
}
}
TartaricForgeRecipe recipe = TartaricForgeRecipeRegistry.getMatchingRecipe(inputList, getWorld(), getPos());
if (recipe != null && (soulsInGem >= recipe.getMinimumSouls() || burnTime > 0))
{
if (canCraft(recipe))
{
if (recipe != null && (soulsInGem >= recipe.getMinimumSouls() || burnTime > 0)) {
if (canCraft(recipe)) {
burnTime++;
if (burnTime == ticksRequired)
{
if (!getWorld().isRemote)
{
if (burnTime == ticksRequired) {
if (!getWorld().isRemote) {
double requiredSouls = recipe.getSoulsDrained();
if (requiredSouls > 0)
{
if (!getWorld().isRemote && soulsInGem >= recipe.getMinimumSouls())
{
if (requiredSouls > 0) {
if (!getWorld().isRemote && soulsInGem >= recipe.getMinimumSouls()) {
consumeSouls(EnumDemonWillType.DEFAULT, requiredSouls);
}
}
@ -116,29 +98,23 @@ public class TileSoulForge extends TileInventory implements ITickable, IDemonWil
}
burnTime = 0;
} else if (burnTime > ticksRequired + 10)
{
} else if (burnTime > ticksRequired + 10) {
burnTime = 0;
}
} else
{
} else {
burnTime = 0;
}
} else
{
} else {
burnTime = 0;
}
}
public double getProgressForGui()
{
public double getProgressForGui() {
return ((double) burnTime) / ticksRequired;
}
private boolean canCraft(TartaricForgeRecipe recipe)
{
if (recipe == null)
{
private boolean canCraft(TartaricForgeRecipe recipe) {
if (recipe == null) {
return false;
}
@ -155,18 +131,14 @@ public class TileSoulForge extends TileInventory implements ITickable, IDemonWil
}
public void craftItem(TartaricForgeRecipe recipe)
{
if (this.canCraft(recipe))
{
public void craftItem(TartaricForgeRecipe recipe) {
if (this.canCraft(recipe)) {
ItemStack outputStack = recipe.getRecipeOutput();
ItemStack currentOutputStack = getStackInSlot(outputSlot);
if (currentOutputStack.isEmpty())
{
if (currentOutputStack.isEmpty()) {
setInventorySlotContents(outputSlot, outputStack);
} else if (currentOutputStack.getItem() == currentOutputStack.getItem())
{
} else if (currentOutputStack.getItem() == currentOutputStack.getItem()) {
currentOutputStack.grow(outputStack.getCount());
}
@ -174,14 +146,11 @@ public class TileSoulForge extends TileInventory implements ITickable, IDemonWil
}
}
public boolean hasSoulGemOrSoul()
{
public boolean hasSoulGemOrSoul() {
ItemStack soulStack = getStackInSlot(soulSlot);
if (!soulStack.isEmpty())
{
if (soulStack.getItem() instanceof IDemonWill || soulStack.getItem() instanceof IDemonWillGem)
{
if (!soulStack.isEmpty()) {
if (soulStack.getItem() instanceof IDemonWill || soulStack.getItem() instanceof IDemonWillGem) {
return true;
}
}
@ -189,20 +158,16 @@ public class TileSoulForge extends TileInventory implements ITickable, IDemonWil
return false;
}
public double getWill(EnumDemonWillType type)
{
public double getWill(EnumDemonWillType type) {
ItemStack soulStack = getStackInSlot(soulSlot);
if (soulStack != null)
{
if (soulStack.getItem() instanceof IDemonWill && ((IDemonWill) soulStack.getItem()).getType(soulStack) == type)
{
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)
{
if (soulStack.getItem() instanceof IDemonWillGem) {
IDemonWillGem soul = (IDemonWillGem) soulStack.getItem();
return soul.getWill(type, soulStack);
}
@ -211,25 +176,20 @@ public class TileSoulForge extends TileInventory implements ITickable, IDemonWil
return 0;
}
public double consumeSouls(EnumDemonWillType type, double requested)
{
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)
{
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)
{
if (soul.getWill(type, soulStack) <= 0) {
setInventorySlotContents(soulSlot, ItemStack.EMPTY);
}
return souls;
}
if (soulStack.getItem() instanceof IDemonWillGem)
{
if (soulStack.getItem() instanceof IDemonWillGem) {
IDemonWillGem soul = (IDemonWillGem) soulStack.getItem();
return soul.drainWill(type, soulStack, requested, true);
}
@ -238,22 +198,17 @@ public class TileSoulForge extends TileInventory implements ITickable, IDemonWil
return 0;
}
public void consumeInventory()
{
for (int i = 0; i < 4; i++)
{
public void consumeInventory() {
for (int i = 0; i < 4; i++) {
ItemStack inputStack = getStackInSlot(i);
if (!inputStack.isEmpty())
{
if (inputStack.getItem().hasContainerItem(inputStack))
{
if (!inputStack.isEmpty()) {
if (inputStack.getItem().hasContainerItem(inputStack)) {
setInventorySlotContents(i, inputStack.getItem().getContainerItem(inputStack));
continue;
}
inputStack.shrink(1);
if (inputStack.isEmpty())
{
if (inputStack.isEmpty()) {
setInventorySlotContents(i, ItemStack.EMPTY);
}
}
@ -261,27 +216,22 @@ public class TileSoulForge extends TileInventory implements ITickable, IDemonWil
}
@Override
public int getWeight()
{
public int getWeight() {
return 50;
}
@Override
public double fillDemonWill(EnumDemonWillType type, double amount, boolean doFill)
{
if (amount <= 0)
{
public double fillDemonWill(EnumDemonWillType type, double amount, boolean doFill) {
if (amount <= 0) {
return 0;
}
if (!canFill(type))
{
if (!canFill(type)) {
return 0;
}
ItemStack stack = this.getStackInSlot(soulSlot);
if (stack.isEmpty() || !(stack.getItem() instanceof IDemonWillGem))
{
if (stack.isEmpty() || !(stack.getItem() instanceof IDemonWillGem)) {
return 0;
}
@ -290,11 +240,9 @@ public class TileSoulForge extends TileInventory implements ITickable, IDemonWil
}
@Override
public double drainDemonWill(EnumDemonWillType type, double amount, boolean doDrain)
{
public double drainDemonWill(EnumDemonWillType type, double amount, boolean doDrain) {
ItemStack stack = this.getStackInSlot(soulSlot);
if (stack.isEmpty() || !(stack.getItem() instanceof IDemonWillGem))
{
if (stack.isEmpty() || !(stack.getItem() instanceof IDemonWillGem)) {
return 0;
}
@ -302,13 +250,11 @@ public class TileSoulForge extends TileInventory implements ITickable, IDemonWil
double drained = amount;
double current = willGem.getWill(type, stack);
if (current < drained)
{
if (current < drained) {
drained = current;
}
if (doDrain)
{
if (doDrain) {
drained = willGem.drainWill(type, stack, drained, true);
}
@ -316,20 +262,17 @@ public class TileSoulForge extends TileInventory implements ITickable, IDemonWil
}
@Override
public boolean canFill(EnumDemonWillType type)
{
public boolean canFill(EnumDemonWillType type) {
return true;
}
@Override
public boolean canDrain(EnumDemonWillType type)
{
public boolean canDrain(EnumDemonWillType type) {
return true;
}
@Override
public double getCurrentWill(EnumDemonWillType type)
{
public double getCurrentWill(EnumDemonWillType type) {
return 0;
}
}

View file

@ -12,27 +12,23 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
public class TileSpectralBlock extends TileTicking
{
public class TileSpectralBlock extends TileTicking {
private int ticksRemaining;
private String containedBlockName;
private int containedBlockMeta;
public TileSpectralBlock()
{
public TileSpectralBlock() {
}
@Override
public void deserialize(NBTTagCompound tagCompound)
{
public void deserialize(NBTTagCompound tagCompound) {
ticksRemaining = tagCompound.getInteger(Constants.NBT.TICKS_REMAINING);
containedBlockName = tagCompound.getString(Constants.NBT.CONTAINED_BLOCK_NAME);
containedBlockMeta = tagCompound.getInteger(Constants.NBT.CONTAINED_BLOCK_META);
}
@Override
public NBTTagCompound serialize(NBTTagCompound tagCompound)
{
public NBTTagCompound serialize(NBTTagCompound tagCompound) {
tagCompound.setInteger(Constants.NBT.TICKS_REMAINING, ticksRemaining);
tagCompound.setString(Constants.NBT.CONTAINED_BLOCK_NAME, Strings.isNullOrEmpty(containedBlockName) ? "" : containedBlockName);
tagCompound.setInteger(Constants.NBT.CONTAINED_BLOCK_META, containedBlockMeta);
@ -40,40 +36,33 @@ public class TileSpectralBlock extends TileTicking
}
@Override
public void onUpdate()
{
if (getWorld().isRemote)
{
public void onUpdate() {
if (getWorld().isRemote) {
return;
}
ticksRemaining--;
if (ticksRemaining <= 0)
{
if (ticksRemaining <= 0) {
returnContainedBlock();
}
}
private void setContainedBlockInfo(IBlockState blockState)
{
private void setContainedBlockInfo(IBlockState blockState) {
containedBlockName = blockState.getBlock().getRegistryName().toString();
containedBlockMeta = blockState.getBlock().getMetaFromState(blockState);
}
private void setDuration(int duration)
{
private void setDuration(int duration) {
ticksRemaining = duration;
}
public void resetDuration(int reset)
{
public void resetDuration(int reset) {
if (ticksRemaining < reset)
ticksRemaining = reset;
}
public void returnContainedBlock()
{
public void returnContainedBlock() {
Block block = null;
if (!Strings.isNullOrEmpty(containedBlockName))
@ -83,8 +72,7 @@ public class TileSpectralBlock extends TileTicking
getWorld().notifyBlockUpdate(getPos(), getWorld().getBlockState(getPos()), getWorld().getBlockState(getPos()), 3);
}
public static void createSpectralBlock(World world, BlockPos blockPos, int duration)
{
public static void createSpectralBlock(World world, BlockPos blockPos, int duration) {
if (world.isAirBlock(blockPos))
return;
IBlockState cachedState = world.getBlockState(blockPos);

View file

@ -22,42 +22,35 @@ import net.minecraftforge.common.MinecraftForge;
import java.util.List;
public class TileTeleposer extends TileInventory implements ITickable
{
public class TileTeleposer extends TileInventory implements ITickable {
//TODO FUTURE: Make AreaDescriptor for Teleposer perhaps?
public static final String TELEPOSER_RANGE = "teleposerRange";
private int previousInput;
public TileTeleposer()
{
public TileTeleposer() {
super(1, "teleposer");
}
@Override
public void deserialize(NBTTagCompound tagCompound)
{
public void deserialize(NBTTagCompound tagCompound) {
super.deserialize(tagCompound);
previousInput = tagCompound.getInteger(Constants.NBT.PREVIOUS_INPUT);
}
@Override
public NBTTagCompound serialize(NBTTagCompound tagCompound)
{
public NBTTagCompound serialize(NBTTagCompound tagCompound) {
super.serialize(tagCompound);
tagCompound.setInteger(Constants.NBT.PREVIOUS_INPUT, previousInput);
return tagCompound;
}
@Override
public void update()
{
if (!getWorld().isRemote)
{
public void update() {
if (!getWorld().isRemote) {
int currentInput = getWorld().getStrongPower(pos);
if (previousInput == 0 && currentInput != 0)
{
if (previousInput == 0 && currentInput != 0) {
initiateTeleport();
}
@ -65,33 +58,25 @@ public class TileTeleposer extends TileInventory implements ITickable
}
}
public void initiateTeleport()
{
if (!getWorld().isRemote && canInitiateTeleport(this) && getBlockType() instanceof BlockTeleposer)
{
public void initiateTeleport() {
if (!getWorld().isRemote && canInitiateTeleport(this) && getBlockType() instanceof BlockTeleposer) {
ItemStack focusStack = NBTHelper.checkNBT(getStackInSlot(0));
ItemTelepositionFocus focus = (ItemTelepositionFocus) focusStack.getItem();
BlockPos focusPos = focus.getBlockPos(getStackInSlot(0));
World focusWorld = focus.getWorld(getStackInSlot(0));
if (focusWorld != null && focusWorld.getTileEntity(focusPos) instanceof TileTeleposer && !focusWorld.getTileEntity(focusPos).equals(this))
{
if (focusWorld != null && focusWorld.getTileEntity(focusPos) instanceof TileTeleposer && !focusWorld.getTileEntity(focusPos).equals(this)) {
final int focusLevel = (getStackInSlot(0).getItemDamage() + 1);
final int lpToBeDrained = (int) (0.5F * Math.sqrt((pos.getX() - focusPos.getX()) * (pos.getX() - focusPos.getX()) + (pos.getY() - focusPos.getY() + 1) * (pos.getY() - focusPos.getY() + 1) + (pos.getZ() - focusPos.getZ()) * (pos.getZ() - focusPos.getZ())));
if (NetworkHelper.getSoulNetwork(focus.getOwnerUUID(focusStack)).syphonAndDamage(PlayerHelper.getPlayerFromUUID(focus.getOwnerUUID(focusStack)), lpToBeDrained * (focusLevel * 2 - 1) * (focusLevel * 2 - 1) * (focusLevel * 2 - 1)))
{
if (NetworkHelper.getSoulNetwork(focus.getOwnerUUID(focusStack)).syphonAndDamage(PlayerHelper.getPlayerFromUUID(focus.getOwnerUUID(focusStack)), lpToBeDrained * (focusLevel * 2 - 1) * (focusLevel * 2 - 1) * (focusLevel * 2 - 1))) {
int blocksTransported = 0;
for (int i = -(focusLevel - 1); i <= (focusLevel - 1); i++)
{
for (int j = 0; j <= (focusLevel * 2 - 2); j++)
{
for (int k = -(focusLevel - 1); k <= (focusLevel - 1); k++)
{
for (int i = -(focusLevel - 1); i <= (focusLevel - 1); i++) {
for (int j = 0; j <= (focusLevel * 2 - 2); j++) {
for (int k = -(focusLevel - 1); k <= (focusLevel - 1); k++) {
TeleposeEvent event = new TeleposeEvent(getWorld(), pos.add(i, 1 + j, k), focusWorld, focusPos.add(i, 1 + j, k));
if (Utils.swapLocations(event.initalWorld, event.initialBlockPos, event.finalWorld, event.finalBlockPos) && !MinecraftForge.EVENT_BUS.post(event))
{
if (Utils.swapLocations(event.initalWorld, event.initialBlockPos, event.finalWorld, event.finalBlockPos) && !MinecraftForge.EVENT_BUS.post(event)) {
blocksTransported++;
}
}
@ -107,37 +92,27 @@ public class TileTeleposer extends TileInventory implements ITickable
AxisAlignedBB focusArea = new AxisAlignedBB(focusPos.getX(), focusPos.getY() + 1, focusPos.getZ(), focusPos.getX() + 1, Math.min(focusWorld.getHeight(), focusPos.getY() + 2 * focusLevel), focusPos.getZ() + 1).expand(focusLevel - 1, 0, focusLevel - 1);
focusWorldEntities = focusWorld.getEntitiesWithinAABB(Entity.class, focusArea);
if (focusWorld.equals(getWorld()))
{
if (!originalWorldEntities.isEmpty())
{
for (Entity entity : originalWorldEntities)
{
if (focusWorld.equals(getWorld())) {
if (!originalWorldEntities.isEmpty()) {
for (Entity entity : originalWorldEntities) {
TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(new BlockPos(entity.posX - pos.getX() + focusPos.getX(), entity.posY - pos.getY() + focusPos.getY(), entity.posZ - pos.getZ() + focusPos.getZ()), entity, focusStack.getTagCompound().getString(Constants.NBT.OWNER_UUID), true));
}
}
if (!focusWorldEntities.isEmpty())
{
for (Entity entity : focusWorldEntities)
{
if (!focusWorldEntities.isEmpty()) {
for (Entity entity : focusWorldEntities) {
TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(new BlockPos(entity.posX - pos.getX() + focusPos.getX(), entity.posY - pos.getY() + focusPos.getY(), entity.posZ - pos.getZ() + focusPos.getZ()), entity, focusStack.getTagCompound().getString(Constants.NBT.OWNER_UUID), true));
}
}
} else
{
if (!originalWorldEntities.isEmpty())
{
for (Entity entity : originalWorldEntities)
{
} else {
if (!originalWorldEntities.isEmpty()) {
for (Entity entity : originalWorldEntities) {
TeleportQueue.getInstance().addITeleport(new Teleports.TeleportToDim(new BlockPos(entity.posX - pos.getX() + focusPos.getX(), entity.posY - pos.getY() + focusPos.getY(), entity.posZ - pos.getZ() + focusPos.getZ()), entity, focusStack.getTagCompound().getString(Constants.NBT.OWNER_UUID), getWorld(), focusWorld.provider.getDimension(), true));
}
}
if (!focusWorldEntities.isEmpty())
{
for (Entity entity : focusWorldEntities)
{
if (!focusWorldEntities.isEmpty()) {
for (Entity entity : focusWorldEntities) {
TeleportQueue.getInstance().addITeleport(new Teleports.TeleportToDim(new BlockPos(entity.posX - pos.getX() + focusPos.getX(), entity.posY - pos.getY() + focusPos.getY(), entity.posZ - pos.getZ() + focusPos.getZ()), entity, focusStack.getTagCompound().getString(Constants.NBT.OWNER_UUID), focusWorld, getWorld().provider.getDimension(), true));
}
}
@ -147,8 +122,7 @@ public class TileTeleposer extends TileInventory implements ITickable
}
}
private boolean canInitiateTeleport(TileTeleposer teleposer)
{
private boolean canInitiateTeleport(TileTeleposer teleposer) {
return !teleposer.getStackInSlot(0).isEmpty() && teleposer.getStackInSlot(0).getItem() instanceof ItemTelepositionFocus && !Strings.isNullOrEmpty(((ItemTelepositionFocus) teleposer.getStackInSlot(0).getItem()).getOwnerName(teleposer.getStackInSlot(0)));
}
}

View file

@ -12,22 +12,19 @@ import net.minecraftforge.fml.relauncher.SideOnly;
/**
* Base tile class.
*
* <p>
* Handles data syncing and core data writing/reading.
*/
public class TileBase extends TileEntity
{
public class TileBase extends TileEntity {
@Override
public final void readFromNBT(NBTTagCompound compound)
{
public final void readFromNBT(NBTTagCompound compound) {
super.readFromNBT(compound);
deserializeBase(compound);
deserialize(compound);
}
@Override
public final NBTTagCompound writeToNBT(NBTTagCompound compound)
{
public final NBTTagCompound writeToNBT(NBTTagCompound compound) {
super.writeToNBT(compound);
serializeBase(compound);
return serialize(compound);
@ -35,38 +32,34 @@ public class TileBase extends TileEntity
/**
* Called by {@link #readFromNBT(NBTTagCompound)}
*
* <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(NBTTagCompound tagCompound)
{
public void deserialize(NBTTagCompound tagCompound) {
}
/**
* Package private method for reading base data from the tag compound.
*
* @see TileTicking
*
* @param tagCompound - The tag compound to read from
* @see TileTicking
*/
void deserializeBase(NBTTagCompound tagCompound)
{
void deserializeBase(NBTTagCompound tagCompound) {
}
/**
* Called by {@link #writeToNBT(NBTTagCompound)}
*
* <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 NBTTagCompound serialize(NBTTagCompound tagCompound)
{
public NBTTagCompound serialize(NBTTagCompound tagCompound) {
return tagCompound;
}
@ -74,13 +67,11 @@ public class TileBase extends TileEntity
/**
* Package private method for writing base data to the tag compound.
*
* @see TileTicking
*
* @param tagCompound - The tag compound to write to.
* @return the modified tag compound
* @see TileTicking
*/
NBTTagCompound serializeBase(NBTTagCompound tagCompound)
{
NBTTagCompound serializeBase(NBTTagCompound tagCompound) {
return tagCompound;
}
@ -91,34 +82,29 @@ public class TileBase extends TileEntity
// Data syncing
@Override
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState)
{
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState) {
return oldState.getBlock() != newState.getBlock();
}
@Override
public final SPacketUpdateTileEntity getUpdatePacket()
{
public final SPacketUpdateTileEntity getUpdatePacket() {
return new SPacketUpdateTileEntity(getPos(), -999, writeToNBT(new NBTTagCompound()));
}
@Override
@SideOnly(Side.CLIENT)
public final void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt)
{
public final void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
super.onDataPacket(net, pkt);
readFromNBT(pkt.getNbtCompound());
}
@Override
public final NBTTagCompound getUpdateTag()
{
public final NBTTagCompound getUpdateTag() {
return writeToNBT(new NBTTagCompound());
}
@Override
public final void handleUpdateTag(NBTTagCompound tag)
{
public final void handleUpdateTag(NBTTagCompound tag) {
readFromNBT(tag);
}
}

View file

@ -7,14 +7,12 @@ import net.minecraft.util.ITickable;
* 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 ITickable
{
public abstract class TileTicking extends TileBase implements ITickable {
private int ticksExisted;
private boolean shouldTick = true;
@Override
public final void update()
{
public final void update() {
if (shouldTick()) {
ticksExisted++;
onUpdate();
@ -22,15 +20,13 @@ public abstract class TileTicking extends TileBase implements ITickable
}
@Override
void deserializeBase(NBTTagCompound tagCompound)
{
void deserializeBase(NBTTagCompound tagCompound) {
this.ticksExisted = tagCompound.getInteger("ticksExisted");
this.shouldTick = tagCompound.getBoolean("shouldTick");
}
@Override
NBTTagCompound serializeBase(NBTTagCompound tagCompound)
{
NBTTagCompound serializeBase(NBTTagCompound tagCompound) {
tagCompound.setInteger("ticksExisted", getTicksExisted());
tagCompound.setBoolean("shouldTick", shouldTick());
return tagCompound;
@ -41,23 +37,19 @@ public abstract class TileTicking extends TileBase implements ITickable
*/
public abstract void onUpdate();
public int getTicksExisted()
{
public int getTicksExisted() {
return ticksExisted;
}
public void resetLifetime()
{
public void resetLifetime() {
ticksExisted = 0;
}
public boolean shouldTick()
{
public boolean shouldTick() {
return shouldTick;
}
public void setShouldTick(boolean shouldTick)
{
public void setShouldTick(boolean shouldTick) {
this.shouldTick = shouldTick;
}
}

View file

@ -1,5 +1,7 @@
package WayofTime.bloodmagic.tile.container;
import WayofTime.bloodmagic.api.orb.IBloodOrb;
import WayofTime.bloodmagic.tile.TileAlchemyTable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ClickType;
@ -7,15 +9,11 @@ import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import WayofTime.bloodmagic.api.orb.IBloodOrb;
import WayofTime.bloodmagic.tile.TileAlchemyTable;
public class ContainerAlchemyTable extends Container
{
public class ContainerAlchemyTable extends Container {
private final IInventory tileTable;
public ContainerAlchemyTable(InventoryPlayer inventoryPlayer, IInventory tileTable)
{
public ContainerAlchemyTable(InventoryPlayer inventoryPlayer, IInventory tileTable) {
this.tileTable = tileTable;
this.addSlotToContainer(new Slot(tileTable, 0, 62, 15));
this.addSlotToContainer(new Slot(tileTable, 1, 80, 51));
@ -27,30 +25,24 @@ public class ContainerAlchemyTable extends Container
this.addSlotToContainer(new SlotOrb(tileTable, TileAlchemyTable.orbSlot, 152, 69));
this.addSlotToContainer(new SlotOutput(tileTable, TileAlchemyTable.outputSlot, 44, 51));
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 9; j++)
{
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 9; j++) {
addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 123 + i * 18));
}
}
for (int i = 0; i < 9; i++)
{
for (int i = 0; i < 9; i++) {
addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 181));
}
}
@Override
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player)
{
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) {
InventoryPlayer inventoryPlayer = player.inventory;
if (slotId < 6 && slotId >= 0)
{
if (slotId < 6 && slotId >= 0) {
Slot slot = this.getSlot(slotId);
if (!slot.getHasStack() && inventoryPlayer.getItemStack().isEmpty())
{
if (!slot.getHasStack() && inventoryPlayer.getItemStack().isEmpty()) {
((TileAlchemyTable) tileTable).toggleInputSlotAccessible(slotId);
}
}
@ -59,51 +51,40 @@ public class ContainerAlchemyTable extends Container
}
@Override
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.inventorySlots.get(index);
if (slot != null && slot.getHasStack())
{
if (slot != null && slot.getHasStack()) {
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (index == 8)
{
if (!this.mergeItemStack(itemstack1, 9, 9 + 36, true))
{
if (index == 8) {
if (!this.mergeItemStack(itemstack1, 9, 9 + 36, true)) {
return ItemStack.EMPTY;
}
slot.onSlotChange(itemstack1, itemstack);
} else if (index > 8)
{
if (itemstack1.getItem() instanceof IBloodOrb)
{
} else if (index > 8) {
if (itemstack1.getItem() instanceof IBloodOrb) {
if (!this.mergeItemStack(itemstack1, 7, 8, false)) //TODO: Add alchemy tools to list
{
return ItemStack.EMPTY;
}
} else if (!this.mergeItemStack(itemstack1, 0, 6, false))
{
} else if (!this.mergeItemStack(itemstack1, 0, 6, false)) {
return ItemStack.EMPTY;
}
} else if (!this.mergeItemStack(itemstack1, 9, 9 + 36, false))
{
} else if (!this.mergeItemStack(itemstack1, 9, 9 + 36, false)) {
return ItemStack.EMPTY;
}
if (itemstack1.getCount() == 0)
{
if (itemstack1.getCount() == 0) {
slot.putStack(ItemStack.EMPTY);
} else
{
} else {
slot.onSlotChanged();
}
if (itemstack1.getCount() == itemstack.getCount())
{
if (itemstack1.getCount() == itemstack.getCount()) {
return ItemStack.EMPTY;
}
@ -114,35 +95,28 @@ public class ContainerAlchemyTable extends Container
}
@Override
public boolean canInteractWith(EntityPlayer playerIn)
{
public boolean canInteractWith(EntityPlayer playerIn) {
return this.tileTable.isUsableByPlayer(playerIn);
}
private class SlotOrb extends Slot
{
public SlotOrb(IInventory inventory, int slotIndex, int x, int y)
{
private class SlotOrb extends Slot {
public SlotOrb(IInventory inventory, int slotIndex, int x, int y) {
super(inventory, slotIndex, x, y);
}
@Override
public boolean isItemValid(ItemStack itemStack)
{
public boolean isItemValid(ItemStack itemStack) {
return itemStack.getItem() instanceof IBloodOrb;
}
}
private class SlotOutput extends Slot
{
public SlotOutput(IInventory inventory, int slotIndex, int x, int y)
{
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)
{
public boolean isItemValid(ItemStack stack) {
return false;
}
}

View file

@ -1,7 +1,8 @@
package WayofTime.bloodmagic.tile.container;
import javax.annotation.Nullable;
import WayofTime.bloodmagic.item.inventory.ItemInventory;
import WayofTime.bloodmagic.item.routing.IRoutingFilterProvider;
import WayofTime.bloodmagic.tile.routing.TileFilteredRoutingNode;
import WayofTime.bloodmagic.util.GhostItemHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
@ -10,54 +11,43 @@ import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import WayofTime.bloodmagic.item.inventory.ItemInventory;
import WayofTime.bloodmagic.item.routing.IRoutingFilterProvider;
import WayofTime.bloodmagic.tile.routing.TileFilteredRoutingNode;
public class ContainerItemRoutingNode extends Container
{
import javax.annotation.Nullable;
public class ContainerItemRoutingNode extends Container {
private final IInventory tileItemRoutingNode;
// private final ItemInventory itemInventory;
private final TileFilteredRoutingNode inventory;
public int lastGhostSlotClicked = -1;
// private final ItemInventory itemInventory;
private int slotsOccupied;
private final TileFilteredRoutingNode inventory;
public int lastGhostSlotClicked = -1;
public ContainerItemRoutingNode(InventoryPlayer inventoryPlayer, IInventory tileItemRoutingNode)
{
public ContainerItemRoutingNode(InventoryPlayer inventoryPlayer, IInventory tileItemRoutingNode) {
this.tileItemRoutingNode = tileItemRoutingNode;
inventory = (TileFilteredRoutingNode) tileItemRoutingNode;
this.addSlotToContainer(new SlotItemFilter(this, tileItemRoutingNode, 0, 8, 33));
ItemInventory itemInventory = inventory.itemInventory;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
addSlotToContainer(new SlotGhostItem(itemInventory, j + i * 3, 26 + j * 18, 15 + i * 18));
}
}
slotsOccupied = 10;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 9; j++)
{
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 9; j++) {
addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 87 + i * 18));
}
}
for (int i = 0; i < 9; i++)
{
for (int i = 0; i < 9; i++) {
addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 145));
}
}
public void resetItemInventory(ItemStack masterStack)
{
public void resetItemInventory(ItemStack masterStack) {
inventory.itemInventory.initializeInventory(masterStack);
}
@ -65,34 +55,28 @@ public class ContainerItemRoutingNode extends Container
* Overridden in order to handle ghost item slots.
*/
@Override
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player)
{
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) {
InventoryPlayer inventoryPlayer = player.inventory;
// if (!player.worldObj.isRemote)
{
if (slotId >= 0)
{
if (slotId >= 0) {
Slot slot = this.inventorySlots.get(slotId);
if (slot instanceof SlotGhostItem) //TODO: make the slot clicking work!
{
lastGhostSlotClicked = slot.getSlotIndex();
if ((dragType == 0 || dragType == 1))
{
if ((dragType == 0 || dragType == 1)) {
ItemStack slotStack = slot.getStack();
ItemStack heldStack = inventoryPlayer.getItemStack();
if (dragType == 0) //Left mouse click-eth
{
{
if (heldStack.isEmpty() && !slotStack.isEmpty())
{
if (heldStack.isEmpty() && !slotStack.isEmpty()) {
//I clicked on the slot with an empty hand. Selecting!
} else if (!heldStack.isEmpty() && slotStack.isEmpty())
{
if (!((SlotGhostItem) slot).canBeAccessed())
{
} else if (!heldStack.isEmpty() && slotStack.isEmpty()) {
if (!((SlotGhostItem) slot).canBeAccessed()) {
return super.slotClick(slotId, dragType, clickTypeIn, player);
}
@ -102,8 +86,7 @@ public class ContainerItemRoutingNode extends Container
slot.putStack(copyStack);
ItemStack filterStack = this.inventorySlots.get(0).getStack();
if (filterStack.getItem() instanceof IRoutingFilterProvider)
{
if (filterStack.getItem() instanceof IRoutingFilterProvider) {
ItemStack filterCopy = ((IRoutingFilterProvider) filterStack.getItem()).getContainedStackForItem(filterStack, heldStack);
slot.putStack(filterCopy);
}
@ -123,55 +106,44 @@ public class ContainerItemRoutingNode extends Container
}
@Override
public void detectAndSendChanges()
{
public void detectAndSendChanges() {
super.detectAndSendChanges();
}
@Override
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.inventorySlots.get(index);
if (slot != null && slot.getHasStack())
{
if (slot != null && slot.getHasStack()) {
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (index == 0)
{
if (!this.mergeItemStack(itemstack1, slotsOccupied, slotsOccupied + 36, true))
{
if (index == 0) {
if (!this.mergeItemStack(itemstack1, slotsOccupied, slotsOccupied + 36, true)) {
return null;
}
slot.onSlotChange(itemstack1, itemstack);
} else if (index > 0)
{
} else if (index > 0) {
// return null;
if (itemstack1.getItem() instanceof IRoutingFilterProvider) // Change to check item is a filter
{
if (!this.mergeItemStack(itemstack1, 0, 1, false))
{
if (!this.mergeItemStack(itemstack1, 0, 1, false)) {
return ItemStack.EMPTY;
}
}
} else if (!this.mergeItemStack(itemstack1, slotsOccupied, 36 + slotsOccupied, false))
{
} else if (!this.mergeItemStack(itemstack1, slotsOccupied, 36 + slotsOccupied, false)) {
return ItemStack.EMPTY;
}
if (itemstack1.isEmpty())
{
if (itemstack1.isEmpty()) {
slot.putStack(ItemStack.EMPTY);
} else
{
} else {
slot.onSlotChanged();
}
if (itemstack1.getCount() == itemstack.getCount())
{
if (itemstack1.getCount() == itemstack.getCount()) {
return ItemStack.EMPTY;
}
@ -182,85 +154,71 @@ public class ContainerItemRoutingNode extends Container
}
@Override
public boolean canInteractWith(EntityPlayer playerIn)
{
public boolean canInteractWith(EntityPlayer playerIn) {
return this.tileItemRoutingNode.isUsableByPlayer(playerIn);
}
private class SlotItemFilter extends Slot
{
private class SlotItemFilter extends Slot {
public ContainerItemRoutingNode container;
public TileFilteredRoutingNode inventory;
public SlotItemFilter(ContainerItemRoutingNode container, IInventory inventory, int slotIndex, int x, int y)
{
public SlotItemFilter(ContainerItemRoutingNode container, IInventory inventory, int slotIndex, int x, int y) {
super(inventory, slotIndex, x, y);
this.container = container;
this.inventory = (TileFilteredRoutingNode) inventory;
}
@Override
public boolean isItemValid(ItemStack itemStack)
{
public boolean isItemValid(ItemStack itemStack) {
return itemStack.getItem() instanceof IRoutingFilterProvider; //TODO: Create a new Item that holds the filter.
}
@Override
public void onSlotChanged()
{
public void onSlotChanged() {
super.onSlotChanged();
container.resetItemInventory(getStack());
for (int i = 1; i <= 9; i++)
{
for (int i = 1; i <= 9; i++) {
Slot slot = container.getSlot(i);
slot.onSlotChanged();
}
}
@Override
public ItemStack getStack()
{
public ItemStack getStack() {
return this.inventory.getStackInSlot(getActiveSlot());
}
@Override
public void putStack(@Nullable ItemStack stack)
{
public void putStack(@Nullable ItemStack stack) {
this.inventory.setInventorySlotContents(getActiveSlot(), stack);
this.onSlotChanged();
}
@Override
public ItemStack decrStackSize(int amount)
{
public ItemStack decrStackSize(int amount) {
return this.inventory.decrStackSize(getActiveSlot(), amount);
}
public int getActiveSlot()
{
public int getActiveSlot() {
return inventory.currentActiveSlot;
}
}
private class SlotGhostItem extends Slot
{
private class SlotGhostItem extends Slot {
private ItemInventory itemInv;
public SlotGhostItem(ItemInventory inventory, int slotIndex, int x, int y)
{
public SlotGhostItem(ItemInventory inventory, int slotIndex, int x, int y) {
super(inventory, slotIndex, x, y);
itemInv = inventory;
}
@Override
public boolean isItemValid(ItemStack stack)
{
public boolean isItemValid(ItemStack stack) {
return false;
}
@Override
public boolean canTakeStack(EntityPlayer playerIn)
{
public boolean canTakeStack(EntityPlayer playerIn) {
return false;
}
@ -270,8 +228,7 @@ public class ContainerItemRoutingNode extends Container
// return itemInv.canInventoryBeManipulated() && super.isHere(inv, slotIn);
// }
public boolean canBeAccessed()
{
public boolean canBeAccessed() {
return itemInv.canInventoryBeManipulated();
}
}

View file

@ -5,19 +5,16 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
public class ContainerMasterRoutingNode extends Container
{
public class ContainerMasterRoutingNode extends Container {
private final IInventory tileMasterRoutingNode;
public ContainerMasterRoutingNode(InventoryPlayer inventoryPlayer, IInventory tileMasterRoutingNode)
{
public ContainerMasterRoutingNode(InventoryPlayer inventoryPlayer, IInventory tileMasterRoutingNode) {
this.tileMasterRoutingNode = tileMasterRoutingNode;
}
@Override
public boolean canInteractWith(EntityPlayer playerIn)
{
public boolean canInteractWith(EntityPlayer playerIn) {
return this.tileMasterRoutingNode.isUsableByPlayer(playerIn);
}
}

View file

@ -10,12 +10,10 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class ContainerSoulForge extends Container
{
public class ContainerSoulForge extends Container {
private final IInventory tileForge;
public ContainerSoulForge(InventoryPlayer inventoryPlayer, IInventory tileForge)
{
public ContainerSoulForge(InventoryPlayer inventoryPlayer, IInventory tileForge) {
this.tileForge = tileForge;
this.addSlotToContainer(new Slot(tileForge, 0, 8, 15));
this.addSlotToContainer(new Slot(tileForge, 1, 80, 15));
@ -24,66 +22,51 @@ public class ContainerSoulForge extends Container
this.addSlotToContainer(new SlotSoul(tileForge, TileSoulForge.soulSlot, 152, 51));
this.addSlotToContainer(new SlotOutput(tileForge, TileSoulForge.outputSlot, 44, 51));
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 9; j++)
{
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 9; j++) {
addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 123 + i * 18));
}
}
for (int i = 0; i < 9; i++)
{
for (int i = 0; i < 9; i++) {
addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 181));
}
}
@Override
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
{
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.inventorySlots.get(index);
if (slot != null && slot.getHasStack())
{
if (slot != null && slot.getHasStack()) {
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (index == 5)
{
if (!this.mergeItemStack(itemstack1, 6, 6 + 36, true))
{
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))
{
} 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))
{
} else if (!this.mergeItemStack(itemstack1, 0, 4, false)) {
return ItemStack.EMPTY;
}
} else if (!this.mergeItemStack(itemstack1, 6, 42, false))
{
} else if (!this.mergeItemStack(itemstack1, 6, 42, false)) {
return ItemStack.EMPTY;
}
if (itemstack1.getCount() == 0)
{
if (itemstack1.getCount() == 0) {
slot.putStack(ItemStack.EMPTY);
} else
{
} else {
slot.onSlotChanged();
}
if (itemstack1.getCount() == itemstack.getCount())
{
if (itemstack1.getCount() == itemstack.getCount()) {
return ItemStack.EMPTY;
}
@ -94,35 +77,28 @@ public class ContainerSoulForge extends Container
}
@Override
public boolean canInteractWith(EntityPlayer playerIn)
{
public boolean canInteractWith(EntityPlayer playerIn) {
return this.tileForge.isUsableByPlayer(playerIn);
}
private class SlotSoul extends Slot
{
public SlotSoul(IInventory inventory, int slotIndex, int x, int y)
{
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)
{
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)
{
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)
{
public boolean isItemValid(ItemStack stack) {
return false;
}
}

View file

@ -8,65 +8,51 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class ContainerTeleposer extends Container
{
public class ContainerTeleposer extends Container {
private final IInventory tileTeleposer;
public ContainerTeleposer(InventoryPlayer inventoryPlayer, IInventory tileTeleposer)
{
public ContainerTeleposer(InventoryPlayer inventoryPlayer, IInventory tileTeleposer) {
this.tileTeleposer = tileTeleposer;
this.addSlotToContainer(new SlotTeleposer(tileTeleposer, 0, 80, 33));
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 9; j++)
{
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 9; j++) {
addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 57 + i * 18));
}
}
for (int i = 0; i < 9; i++)
{
for (int i = 0; i < 9; i++) {
addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 115));
}
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slot)
{
public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
ItemStack stack = ItemStack.EMPTY;
Slot slotObject = inventorySlots.get(slot);
int slots = inventorySlots.size();
if (slotObject != null && slotObject.getHasStack())
{
if (slotObject != null && slotObject.getHasStack()) {
ItemStack stackInSlot = slotObject.getStack();
stack = stackInSlot.copy();
if (stack.getItem() instanceof ItemTelepositionFocus)
{
if (slot <= slots)
{
if (!this.mergeItemStack(stackInSlot, 0, slots, false))
{
if (stack.getItem() instanceof ItemTelepositionFocus) {
if (slot <= slots) {
if (!this.mergeItemStack(stackInSlot, 0, slots, false)) {
return ItemStack.EMPTY;
}
} else if (!this.mergeItemStack(stackInSlot, slots, 36 + slots, false))
{
} else if (!this.mergeItemStack(stackInSlot, slots, 36 + slots, false)) {
return ItemStack.EMPTY;
}
}
if (stackInSlot.getCount() == 0)
{
if (stackInSlot.getCount() == 0) {
slotObject.putStack(ItemStack.EMPTY);
} else
{
} else {
slotObject.onSlotChanged();
}
if (stackInSlot.getCount() == stack.getCount())
{
if (stackInSlot.getCount() == stack.getCount()) {
return ItemStack.EMPTY;
}
@ -77,21 +63,17 @@ public class ContainerTeleposer extends Container
}
@Override
public boolean canInteractWith(EntityPlayer playerIn)
{
public boolean canInteractWith(EntityPlayer playerIn) {
return this.tileTeleposer.isUsableByPlayer(playerIn);
}
private class SlotTeleposer extends Slot
{
public SlotTeleposer(IInventory inventory, int slotIndex, int x, int y)
{
private class SlotTeleposer extends Slot {
public SlotTeleposer(IInventory inventory, int slotIndex, int x, int y) {
super(inventory, slotIndex, x, y);
}
@Override
public boolean isItemValid(ItemStack itemStack)
{
public boolean isItemValid(ItemStack itemStack) {
return itemStack.getItem() instanceof ItemTelepositionFocus;
}
}

View file

@ -1,40 +1,35 @@
package WayofTime.bloodmagic.tile.routing;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.item.inventory.ItemInventory;
import WayofTime.bloodmagic.util.GhostItemHelper;
import net.minecraft.block.state.IBlockState;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.EnumFacing;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.item.inventory.ItemInventory;
import WayofTime.bloodmagic.util.GhostItemHelper;
import net.minecraft.util.NonNullList;
public class TileFilteredRoutingNode extends TileRoutingNode implements ISidedInventory
{
public class TileFilteredRoutingNode extends TileRoutingNode implements ISidedInventory {
public int currentActiveSlot = 0;
public int[] priorities = new int[6];
public ItemInventory itemInventory = new ItemInventory(ItemStack.EMPTY, 9, "");
public TileFilteredRoutingNode(int size, String name)
{
public TileFilteredRoutingNode(int size, String name) {
super(size, name);
}
public ItemStack getFilterStack(EnumFacing side)
{
public ItemStack getFilterStack(EnumFacing side) {
int index = side.getIndex();
return getStackInSlot(index);
}
public void setGhostItemAmount(int ghostItemSlot, int amount)
{
public void setGhostItemAmount(int ghostItemSlot, int amount) {
ItemStack stack = itemInventory.getStackInSlot(ghostItemSlot);
if (!stack.isEmpty())
{
if (!stack.isEmpty()) {
GhostItemHelper.setItemGhostAmount(stack, amount);
}
@ -42,38 +37,30 @@ public class TileFilteredRoutingNode extends TileRoutingNode implements ISidedIn
}
@Override
public boolean isInventoryConnectedToSide(EnumFacing side)
{
public boolean isInventoryConnectedToSide(EnumFacing side) {
return true;
}
@Override
public void deserialize(NBTTagCompound tag)
{
public void deserialize(NBTTagCompound tag) {
super.deserialize(tag);
currentActiveSlot = tag.getInteger("currentSlot");
priorities = tag.getIntArray(Constants.NBT.ROUTING_PRIORITY);
if (priorities.length != 6)
{
if (priorities.length != 6) {
priorities = new int[6];
}
if (!tag.getBoolean("updated"))
{
if (!tag.getBoolean("updated")) {
NBTTagList tags = tag.getTagList("Items", 10);
inventory = NonNullList.withSize(getSizeInventory(), ItemStack.EMPTY);
for (int i = 0; i < tags.tagCount(); i++)
{
if (!isSyncedSlot(i))
{
for (int i = 0; i < tags.tagCount(); i++) {
if (!isSyncedSlot(i)) {
NBTTagCompound data = tags.getCompoundTagAt(i);
byte j = data.getByte("Slot");
if (j == 0)
{
if (j == 0) {
inventory.set(i, new ItemStack(data));
} else if (j >= 1 && j < inventory.size() + 1)
{
} else if (j >= 1 && j < inventory.size() + 1) {
inventory.set(j - 1, new ItemStack(data));
}
}
@ -84,8 +71,7 @@ public class TileFilteredRoutingNode extends TileRoutingNode implements ISidedIn
}
@Override
public NBTTagCompound serialize(NBTTagCompound tag)
{
public NBTTagCompound serialize(NBTTagCompound tag) {
super.serialize(tag);
tag.setInteger("currentSlot", currentActiveSlot);
tag.setIntArray(Constants.NBT.ROUTING_PRIORITY, priorities);
@ -93,46 +79,39 @@ public class TileFilteredRoutingNode extends TileRoutingNode implements ISidedIn
return tag;
}
public void swapFilters(int requestedSlot)
{
public void swapFilters(int requestedSlot) {
currentActiveSlot = requestedSlot;
itemInventory.initializeInventory(getStackInSlot(currentActiveSlot));
this.markDirty();
}
@Override
public int[] getSlotsForFace(EnumFacing side)
{
public int[] getSlotsForFace(EnumFacing side) {
return new int[0];
}
@Override
public boolean canInsertItem(int index, ItemStack itemStackIn, EnumFacing direction)
{
public boolean canInsertItem(int index, ItemStack itemStackIn, EnumFacing direction) {
return false;
}
@Override
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction)
{
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction) {
return false;
}
@Override
public int getPriority(EnumFacing side)
{
public int getPriority(EnumFacing side) {
return priorities[side.getIndex()];
}
public void incrementCurrentPriotiryToMaximum(int max)
{
public void incrementCurrentPriotiryToMaximum(int max) {
priorities[currentActiveSlot] = Math.min(priorities[currentActiveSlot] + 1, max);
IBlockState state = getWorld().getBlockState(pos);
getWorld().notifyBlockUpdate(pos, state, state, 3);
}
public void decrementCurrentPriority()
{
public void decrementCurrentPriority() {
priorities[currentActiveSlot] = Math.max(priorities[currentActiveSlot] - 1, 0);
IBlockState state = getWorld().getBlockState(pos);
getWorld().notifyBlockUpdate(pos, state, state, 3);

View file

@ -1,51 +1,39 @@
package WayofTime.bloodmagic.tile.routing;
import WayofTime.bloodmagic.item.routing.IFluidFilterProvider;
import WayofTime.bloodmagic.item.routing.IItemFilterProvider;
import WayofTime.bloodmagic.routing.*;
import WayofTime.bloodmagic.util.Utils;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.items.IItemHandler;
import WayofTime.bloodmagic.item.routing.IFluidFilterProvider;
import WayofTime.bloodmagic.item.routing.IItemFilterProvider;
import WayofTime.bloodmagic.routing.DefaultItemFilter;
import WayofTime.bloodmagic.routing.IFluidFilter;
import WayofTime.bloodmagic.routing.IInputFluidRoutingNode;
import WayofTime.bloodmagic.routing.IInputItemRoutingNode;
import WayofTime.bloodmagic.routing.IItemFilter;
import WayofTime.bloodmagic.util.Utils;
public class TileInputRoutingNode extends TileFilteredRoutingNode implements IInputItemRoutingNode, IInputFluidRoutingNode
{
public TileInputRoutingNode()
{
public class TileInputRoutingNode extends TileFilteredRoutingNode implements IInputItemRoutingNode, IInputFluidRoutingNode {
public TileInputRoutingNode() {
super(6, "inputNode");
}
@Override
public boolean isInput(EnumFacing side)
{
public boolean isInput(EnumFacing side) {
return true;
}
@Override
public IItemFilter getInputFilterForSide(EnumFacing side)
{
public IItemFilter getInputFilterForSide(EnumFacing side) {
TileEntity tile = getWorld().getTileEntity(pos.offset(side));
if (tile != null)
{
if (tile != null) {
IItemHandler handler = Utils.getInventory(tile, side.getOpposite());
if (handler != null)
{
if (handler != null) {
ItemStack filterStack = this.getFilterStack(side);
if (filterStack.isEmpty())
{
if (filterStack.isEmpty()) {
IItemFilter filter = new DefaultItemFilter();
filter.initializeFilter(null, tile, handler, false);
return filter;
} else if (!(filterStack.getItem() instanceof IItemFilterProvider))
{
} else if (!(filterStack.getItem() instanceof IItemFilterProvider)) {
return null;
}
@ -58,21 +46,17 @@ public class TileInputRoutingNode extends TileFilteredRoutingNode implements IIn
}
@Override
public boolean isFluidInput(EnumFacing side)
{
public boolean isFluidInput(EnumFacing side) {
return true;
}
@Override
public IFluidFilter getInputFluidFilterForSide(EnumFacing side)
{
public IFluidFilter getInputFluidFilterForSide(EnumFacing side) {
TileEntity tile = getWorld().getTileEntity(pos.offset(side));
if (tile != null && tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side))
{
if (tile != null && tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)) {
IFluidHandler handler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
ItemStack filterStack = this.getFilterStack(side);
if (filterStack == null || !(filterStack.getItem() instanceof IFluidFilterProvider))
{
if (filterStack == null || !(filterStack.getItem() instanceof IFluidFilterProvider)) {
return null;
}
@ -83,8 +67,7 @@ public class TileInputRoutingNode extends TileFilteredRoutingNode implements IIn
}
@Override
public boolean isTankConnectedToSide(EnumFacing side)
{
public boolean isTankConnectedToSide(EnumFacing side) {
return true;
}
}

View file

@ -1,9 +1,7 @@
package WayofTime.bloodmagic.tile.routing;
public class TileItemRoutingNode extends TileRoutingNode
{
public TileItemRoutingNode()
{
public class TileItemRoutingNode extends TileRoutingNode {
public TileItemRoutingNode() {
super(0, "itemNode");
}
}

View file

@ -1,12 +1,10 @@
package WayofTime.bloodmagic.tile.routing;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler;
import WayofTime.bloodmagic.routing.*;
import WayofTime.bloodmagic.tile.TileInventory;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
@ -14,42 +12,26 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.soul.EnumDemonWillType;
import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler;
import WayofTime.bloodmagic.routing.IFluidFilter;
import WayofTime.bloodmagic.routing.IInputFluidRoutingNode;
import WayofTime.bloodmagic.routing.IInputItemRoutingNode;
import WayofTime.bloodmagic.routing.IItemFilter;
import WayofTime.bloodmagic.routing.IMasterRoutingNode;
import WayofTime.bloodmagic.routing.IOutputFluidRoutingNode;
import WayofTime.bloodmagic.routing.IOutputItemRoutingNode;
import WayofTime.bloodmagic.routing.IRoutingNode;
import WayofTime.bloodmagic.routing.NodeHelper;
import WayofTime.bloodmagic.tile.TileInventory;
public class TileMasterRoutingNode extends TileInventory implements IMasterRoutingNode, ITickable
{
import java.util.*;
import java.util.Map.Entry;
public class TileMasterRoutingNode extends TileInventory implements IMasterRoutingNode, ITickable {
public static final int tickRate = 20;
private int currentInput;
public TileMasterRoutingNode()
{
super(0, "masterRoutingNode");
}
// A list of connections
private TreeMap<BlockPos, List<BlockPos>> connectionMap = new TreeMap<BlockPos, List<BlockPos>>();
private List<BlockPos> generalNodeList = new LinkedList<BlockPos>();
private List<BlockPos> outputNodeList = new LinkedList<BlockPos>();
private List<BlockPos> inputNodeList = new LinkedList<BlockPos>();
public static final int tickRate = 20;
public TileMasterRoutingNode() {
super(0, "masterRoutingNode");
}
@Override
public void update()
{
if (!getWorld().isRemote)
{
public void update() {
if (!getWorld().isRemote) {
// currentInput = getWorld().isBlockIndirectlyGettingPowered(pos);
currentInput = getWorld().getStrongPower(pos);
@ -64,31 +46,23 @@ public class TileMasterRoutingNode extends TileInventory implements IMasterRouti
Map<Integer, List<IItemFilter>> outputMap = new TreeMap<Integer, List<IItemFilter>>();
Map<Integer, List<IFluidFilter>> outputFluidMap = new TreeMap<Integer, List<IFluidFilter>>();
for (BlockPos outputPos : outputNodeList)
{
for (BlockPos outputPos : outputNodeList) {
TileEntity outputTile = getWorld().getTileEntity(outputPos);
if (this.isConnected(new LinkedList<BlockPos>(), outputPos))
{
if (outputTile instanceof IOutputItemRoutingNode)
{
if (this.isConnected(new LinkedList<BlockPos>(), outputPos)) {
if (outputTile instanceof IOutputItemRoutingNode) {
IOutputItemRoutingNode outputNode = (IOutputItemRoutingNode) outputTile;
for (EnumFacing facing : EnumFacing.VALUES)
{
if (!outputNode.isInventoryConnectedToSide(facing) || !outputNode.isOutput(facing))
{
for (EnumFacing facing : EnumFacing.VALUES) {
if (!outputNode.isInventoryConnectedToSide(facing) || !outputNode.isOutput(facing)) {
continue;
}
IItemFilter filter = outputNode.getOutputFilterForSide(facing);
if (filter != null)
{
if (filter != null) {
int priority = outputNode.getPriority(facing);
if (outputMap.containsKey(priority))
{
if (outputMap.containsKey(priority)) {
outputMap.get(priority).add(filter);
} else
{
} else {
List<IItemFilter> filterList = new LinkedList<IItemFilter>();
filterList.add(filter);
outputMap.put(priority, filterList);
@ -97,26 +71,20 @@ public class TileMasterRoutingNode extends TileInventory implements IMasterRouti
}
}
if (outputTile instanceof IOutputFluidRoutingNode)
{
if (outputTile instanceof IOutputFluidRoutingNode) {
IOutputFluidRoutingNode outputNode = (IOutputFluidRoutingNode) outputTile;
for (EnumFacing facing : EnumFacing.VALUES)
{
if (!outputNode.isTankConnectedToSide(facing) || !outputNode.isFluidOutput(facing))
{
for (EnumFacing facing : EnumFacing.VALUES) {
if (!outputNode.isTankConnectedToSide(facing) || !outputNode.isFluidOutput(facing)) {
continue;
}
IFluidFilter filter = outputNode.getOutputFluidFilterForSide(facing);
if (filter != null)
{
if (filter != null) {
int priority = outputNode.getPriority(facing);
if (outputMap.containsKey(priority))
{
if (outputMap.containsKey(priority)) {
outputFluidMap.get(priority).add(filter);
} else
{
} else {
List<IFluidFilter> filterList = new LinkedList<IFluidFilter>();
filterList.add(filter);
outputFluidMap.put(priority, filterList);
@ -130,31 +98,23 @@ public class TileMasterRoutingNode extends TileInventory implements IMasterRouti
Map<Integer, List<IItemFilter>> inputMap = new TreeMap<Integer, List<IItemFilter>>();
Map<Integer, List<IFluidFilter>> inputFluidMap = new TreeMap<Integer, List<IFluidFilter>>();
for (BlockPos inputPos : inputNodeList)
{
for (BlockPos inputPos : inputNodeList) {
TileEntity inputTile = getWorld().getTileEntity(inputPos);
if (this.isConnected(new LinkedList<BlockPos>(), inputPos))
{
if (inputTile instanceof IInputItemRoutingNode)
{
if (this.isConnected(new LinkedList<BlockPos>(), inputPos)) {
if (inputTile instanceof IInputItemRoutingNode) {
IInputItemRoutingNode inputNode = (IInputItemRoutingNode) inputTile;
for (EnumFacing facing : EnumFacing.VALUES)
{
if (!inputNode.isInventoryConnectedToSide(facing) || !inputNode.isInput(facing))
{
for (EnumFacing facing : EnumFacing.VALUES) {
if (!inputNode.isInventoryConnectedToSide(facing) || !inputNode.isInput(facing)) {
continue;
}
IItemFilter filter = inputNode.getInputFilterForSide(facing);
if (filter != null)
{
if (filter != null) {
int priority = inputNode.getPriority(facing);
if (inputMap.containsKey(priority))
{
if (inputMap.containsKey(priority)) {
inputMap.get(priority).add(filter);
} else
{
} else {
List<IItemFilter> filterList = new LinkedList<IItemFilter>();
filterList.add(filter);
inputMap.put(priority, filterList);
@ -163,26 +123,20 @@ public class TileMasterRoutingNode extends TileInventory implements IMasterRouti
}
}
if (inputTile instanceof IInputFluidRoutingNode)
{
if (inputTile instanceof IInputFluidRoutingNode) {
IInputFluidRoutingNode inputNode = (IInputFluidRoutingNode) inputTile;
for (EnumFacing facing : EnumFacing.VALUES)
{
if (!inputNode.isTankConnectedToSide(facing) || !inputNode.isFluidInput(facing))
{
for (EnumFacing facing : EnumFacing.VALUES) {
if (!inputNode.isTankConnectedToSide(facing) || !inputNode.isFluidInput(facing)) {
continue;
}
IFluidFilter filter = inputNode.getInputFluidFilterForSide(facing);
if (filter != null)
{
if (filter != null) {
int priority = inputNode.getPriority(facing);
if (inputMap.containsKey(priority))
{
if (inputMap.containsKey(priority)) {
inputFluidMap.get(priority).add(filter);
} else
{
} else {
List<IFluidFilter> filterList = new LinkedList<IFluidFilter>();
filterList.add(filter);
inputFluidMap.put(priority, filterList);
@ -196,19 +150,14 @@ public class TileMasterRoutingNode extends TileInventory implements IMasterRouti
int maxTransfer = this.getMaxTransferForDemonWill(WorldDemonWillHandler.getCurrentWill(getWorld(), pos, EnumDemonWillType.DEFAULT));
int maxFluidTransfer = 1000;
for (Entry<Integer, List<IItemFilter>> outputEntry : outputMap.entrySet())
{
for (Entry<Integer, List<IItemFilter>> outputEntry : outputMap.entrySet()) {
List<IItemFilter> outputList = outputEntry.getValue();
for (IItemFilter outputFilter : outputList)
{
for (Entry<Integer, List<IItemFilter>> inputEntry : inputMap.entrySet())
{
for (IItemFilter outputFilter : outputList) {
for (Entry<Integer, List<IItemFilter>> inputEntry : inputMap.entrySet()) {
List<IItemFilter> inputList = inputEntry.getValue();
for (IItemFilter inputFilter : inputList)
{
for (IItemFilter inputFilter : inputList) {
maxTransfer -= inputFilter.transferThroughInputFilter(outputFilter, maxTransfer);
if (maxTransfer <= 0)
{
if (maxTransfer <= 0) {
return;
}
}
@ -216,19 +165,14 @@ public class TileMasterRoutingNode extends TileInventory implements IMasterRouti
}
}
for (Entry<Integer, List<IFluidFilter>> outputEntry : outputFluidMap.entrySet())
{
for (Entry<Integer, List<IFluidFilter>> outputEntry : outputFluidMap.entrySet()) {
List<IFluidFilter> outputList = outputEntry.getValue();
for (IFluidFilter outputFilter : outputList)
{
for (Entry<Integer, List<IFluidFilter>> inputEntry : inputFluidMap.entrySet())
{
for (IFluidFilter outputFilter : outputList) {
for (Entry<Integer, List<IFluidFilter>> inputEntry : inputFluidMap.entrySet()) {
List<IFluidFilter> inputList = inputEntry.getValue();
for (IFluidFilter inputFilter : inputList)
{
for (IFluidFilter inputFilter : inputList) {
maxFluidTransfer -= inputFilter.transferThroughInputFilter(outputFilter, maxFluidTransfer);
if (maxFluidTransfer <= 0)
{
if (maxFluidTransfer <= 0) {
return;
}
}
@ -237,18 +181,15 @@ public class TileMasterRoutingNode extends TileInventory implements IMasterRouti
}
}
public int getMaxTransferForDemonWill(double will)
{
public int getMaxTransferForDemonWill(double will) {
return 8;
}
@Override
public NBTTagCompound serialize(NBTTagCompound tag)
{
public NBTTagCompound serialize(NBTTagCompound tag) {
super.serialize(tag);
NBTTagList tags = new NBTTagList();
for (BlockPos pos : generalNodeList)
{
for (BlockPos pos : generalNodeList) {
NBTTagCompound posTag = new NBTTagCompound();
posTag.setInteger(Constants.NBT.X_COORD, pos.getX());
posTag.setInteger(Constants.NBT.Y_COORD, pos.getY());
@ -258,8 +199,7 @@ public class TileMasterRoutingNode extends TileInventory implements IMasterRouti
tag.setTag(Constants.NBT.ROUTING_MASTER_GENERAL, tags);
tags = new NBTTagList();
for (BlockPos pos : inputNodeList)
{
for (BlockPos pos : inputNodeList) {
NBTTagCompound posTag = new NBTTagCompound();
posTag.setInteger(Constants.NBT.X_COORD, pos.getX());
posTag.setInteger(Constants.NBT.Y_COORD, pos.getY());
@ -269,8 +209,7 @@ public class TileMasterRoutingNode extends TileInventory implements IMasterRouti
tag.setTag(Constants.NBT.ROUTING_MASTER_INPUT, tags);
tags = new NBTTagList();
for (BlockPos pos : outputNodeList)
{
for (BlockPos pos : outputNodeList) {
NBTTagCompound posTag = new NBTTagCompound();
posTag.setInteger(Constants.NBT.X_COORD, pos.getX());
posTag.setInteger(Constants.NBT.Y_COORD, pos.getY());
@ -282,29 +221,25 @@ public class TileMasterRoutingNode extends TileInventory implements IMasterRouti
}
@Override
public void deserialize(NBTTagCompound tag)
{
public void deserialize(NBTTagCompound tag) {
super.deserialize(tag);
NBTTagList tags = tag.getTagList(Constants.NBT.ROUTING_MASTER_GENERAL, 10);
for (int i = 0; i < tags.tagCount(); i++)
{
for (int i = 0; i < tags.tagCount(); i++) {
NBTTagCompound blockTag = tags.getCompoundTagAt(i);
BlockPos newPos = new BlockPos(blockTag.getInteger(Constants.NBT.X_COORD), blockTag.getInteger(Constants.NBT.Y_COORD), blockTag.getInteger(Constants.NBT.Z_COORD));
generalNodeList.add(newPos);
}
tags = tag.getTagList(Constants.NBT.ROUTING_MASTER_INPUT, 10);
for (int i = 0; i < tags.tagCount(); i++)
{
for (int i = 0; i < tags.tagCount(); i++) {
NBTTagCompound blockTag = tags.getCompoundTagAt(i);
BlockPos newPos = new BlockPos(blockTag.getInteger(Constants.NBT.X_COORD), blockTag.getInteger(Constants.NBT.Y_COORD), blockTag.getInteger(Constants.NBT.Z_COORD));
inputNodeList.add(newPos);
}
tags = tag.getTagList(Constants.NBT.ROUTING_MASTER_OUTPUT, 10);
for (int i = 0; i < tags.tagCount(); i++)
{
for (int i = 0; i < tags.tagCount(); i++) {
NBTTagCompound blockTag = tags.getCompoundTagAt(i);
BlockPos newPos = new BlockPos(blockTag.getInteger(Constants.NBT.X_COORD), blockTag.getInteger(Constants.NBT.Y_COORD), blockTag.getInteger(Constants.NBT.Z_COORD));
outputNodeList.add(newPos);
@ -312,16 +247,14 @@ public class TileMasterRoutingNode extends TileInventory implements IMasterRouti
}
@Override
public boolean isConnected(List<BlockPos> path, BlockPos nodePos)
{
public boolean isConnected(List<BlockPos> path, BlockPos nodePos) {
//TODO: Figure out how to make it so the path is obtained
// if (!connectionMap.containsKey(nodePos))
// {
// return false;
// }
TileEntity tile = getWorld().getTileEntity(nodePos);
if (!(tile instanceof IRoutingNode))
{
if (!(tile instanceof IRoutingNode)) {
// connectionMap.remove(nodePos);
return false;
}
@ -330,22 +263,17 @@ public class TileMasterRoutingNode extends TileInventory implements IMasterRouti
List<BlockPos> connectionList = node.getConnected();
// List<BlockPos> testPath = path.subList(0, path.size());
path.add(nodePos);
for (BlockPos testPos : connectionList)
{
if (path.contains(testPos))
{
for (BlockPos testPos : connectionList) {
if (path.contains(testPos)) {
continue;
}
if (testPos.equals(this.getPos()) && node.isConnectionEnabled(testPos))
{
if (testPos.equals(this.getPos()) && node.isConnectionEnabled(testPos)) {
// path.clear();
// path.addAll(testPath);
return true;
} else if (NodeHelper.isNodeConnectionEnabled(getWorld(), node, testPos))
{
if (isConnected(path, testPos))
{
} else if (NodeHelper.isNodeConnectionEnabled(getWorld(), node, testPos)) {
if (isConnected(path, testPos)) {
// path.clear();
// path.addAll(testPath);
return true;
@ -357,56 +285,44 @@ public class TileMasterRoutingNode extends TileInventory implements IMasterRouti
}
@Override
public boolean isConnectionEnabled(BlockPos testPos)
{
public boolean isConnectionEnabled(BlockPos testPos) {
return currentInput <= 0;
}
@Override
public void addNodeToList(IRoutingNode node)
{
public void addNodeToList(IRoutingNode node) {
BlockPos newPos = node.getBlockPos();
if (!generalNodeList.contains(newPos))
{
if (!generalNodeList.contains(newPos)) {
generalNodeList.add(newPos);
}
if (node instanceof IInputItemRoutingNode && !inputNodeList.contains(newPos))
{
if (node instanceof IInputItemRoutingNode && !inputNodeList.contains(newPos)) {
inputNodeList.add(newPos);
}
if (node instanceof IOutputItemRoutingNode && !outputNodeList.contains(newPos))
{
if (node instanceof IOutputItemRoutingNode && !outputNodeList.contains(newPos)) {
outputNodeList.add(newPos);
}
}
@Override
public void addConnections(BlockPos pos, List<BlockPos> connectionList)
{
for (BlockPos testPos : connectionList)
{
public void addConnections(BlockPos pos, List<BlockPos> connectionList) {
for (BlockPos testPos : connectionList) {
addConnection(pos, testPos);
}
}
@Override
public void addConnection(BlockPos pos1, BlockPos pos2)
{
if (connectionMap.containsKey(pos1) && !connectionMap.get(pos1).contains(pos2))
{
public void addConnection(BlockPos pos1, BlockPos pos2) {
if (connectionMap.containsKey(pos1) && !connectionMap.get(pos1).contains(pos2)) {
connectionMap.get(pos1).add(pos2);
} else
{
} else {
List<BlockPos> list = new LinkedList<BlockPos>();
list.add(pos2);
connectionMap.put(pos1, list);
}
if (connectionMap.containsKey(pos2) && !connectionMap.get(pos2).contains(pos1))
{
if (connectionMap.containsKey(pos2) && !connectionMap.get(pos2).contains(pos1)) {
connectionMap.get(pos2).add(pos1);
} else
{
} else {
List<BlockPos> list = new LinkedList<BlockPos>();
list.add(pos1);
connectionMap.put(pos2, list);
@ -414,84 +330,69 @@ public class TileMasterRoutingNode extends TileInventory implements IMasterRouti
}
@Override
public void removeConnection(BlockPos pos1, BlockPos pos2)
{
if (connectionMap.containsKey(pos1))
{
public void removeConnection(BlockPos pos1, BlockPos pos2) {
if (connectionMap.containsKey(pos1)) {
List<BlockPos> posList = connectionMap.get(pos1);
posList.remove(pos2);
if (posList.isEmpty())
{
if (posList.isEmpty()) {
connectionMap.remove(pos1);
}
}
if (connectionMap.containsKey(pos2))
{
if (connectionMap.containsKey(pos2)) {
List<BlockPos> posList = connectionMap.get(pos2);
posList.remove(pos1);
if (posList.isEmpty())
{
if (posList.isEmpty()) {
connectionMap.remove(pos2);
}
}
}
@Override
public void connectMasterToRemainingNode(World world, List<BlockPos> alreadyChecked, IMasterRoutingNode master)
{
public void connectMasterToRemainingNode(World world, List<BlockPos> alreadyChecked, IMasterRoutingNode master) {
return;
}
@Override
public BlockPos getBlockPos()
{
public BlockPos getBlockPos() {
return this.getPos();
}
@Override
public List<BlockPos> getConnected()
{
public List<BlockPos> getConnected() {
return new LinkedList<BlockPos>();
}
@Override
public BlockPos getMasterPos()
{
public BlockPos getMasterPos() {
return this.getPos();
}
@Override
public boolean isMaster(IMasterRoutingNode master)
{
public boolean isMaster(IMasterRoutingNode master) {
return false;
}
@Override
public void addConnection(BlockPos pos1)
{
public void addConnection(BlockPos pos1) {
// Empty
}
@Override
public void removeConnection(BlockPos pos1)
{
public void removeConnection(BlockPos pos1) {
generalNodeList.remove(pos1);
inputNodeList.remove(pos1);
outputNodeList.remove(pos1);
}
@Override
public void removeAllConnections()
{
public void removeAllConnections() {
List<BlockPos> list = generalNodeList.subList(0, generalNodeList.size());
Iterator<BlockPos> itr = list.iterator();
while (itr.hasNext())
{
while (itr.hasNext()) {
BlockPos testPos = itr.next();
TileEntity tile = getWorld().getTileEntity(testPos);
if (tile instanceof IRoutingNode)
{
if (tile instanceof IRoutingNode) {
((IRoutingNode) tile).removeConnection(pos);
getWorld().notifyBlockUpdate(getPos(), getWorld().getBlockState(testPos), getWorld().getBlockState(testPos), 3);
}

View file

@ -1,51 +1,39 @@
package WayofTime.bloodmagic.tile.routing;
import WayofTime.bloodmagic.item.routing.IFluidFilterProvider;
import WayofTime.bloodmagic.item.routing.IItemFilterProvider;
import WayofTime.bloodmagic.routing.*;
import WayofTime.bloodmagic.util.Utils;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.items.IItemHandler;
import WayofTime.bloodmagic.item.routing.IFluidFilterProvider;
import WayofTime.bloodmagic.item.routing.IItemFilterProvider;
import WayofTime.bloodmagic.routing.DefaultItemFilter;
import WayofTime.bloodmagic.routing.IFluidFilter;
import WayofTime.bloodmagic.routing.IItemFilter;
import WayofTime.bloodmagic.routing.IOutputFluidRoutingNode;
import WayofTime.bloodmagic.routing.IOutputItemRoutingNode;
import WayofTime.bloodmagic.util.Utils;
public class TileOutputRoutingNode extends TileFilteredRoutingNode implements IOutputItemRoutingNode, IOutputFluidRoutingNode
{
public TileOutputRoutingNode()
{
public class TileOutputRoutingNode extends TileFilteredRoutingNode implements IOutputItemRoutingNode, IOutputFluidRoutingNode {
public TileOutputRoutingNode() {
super(6, "outputNode");
}
@Override
public boolean isOutput(EnumFacing side)
{
public boolean isOutput(EnumFacing side) {
return true;
}
@Override
public IItemFilter getOutputFilterForSide(EnumFacing side)
{
public IItemFilter getOutputFilterForSide(EnumFacing side) {
TileEntity tile = getWorld().getTileEntity(pos.offset(side));
if (tile != null)
{
if (tile != null) {
IItemHandler handler = Utils.getInventory(tile, side.getOpposite());
if (handler != null)
{
if (handler != null) {
ItemStack filterStack = this.getFilterStack(side);
if (filterStack.isEmpty())
{
if (filterStack.isEmpty()) {
IItemFilter filter = new DefaultItemFilter();
filter.initializeFilter(null, tile, handler, true);
return filter;
} else if (!(filterStack.getItem() instanceof IItemFilterProvider))
{
} else if (!(filterStack.getItem() instanceof IItemFilterProvider)) {
return null;
}
@ -58,21 +46,17 @@ public class TileOutputRoutingNode extends TileFilteredRoutingNode implements IO
}
@Override
public boolean isFluidOutput(EnumFacing side)
{
public boolean isFluidOutput(EnumFacing side) {
return true;
}
@Override
public IFluidFilter getOutputFluidFilterForSide(EnumFacing side)
{
public IFluidFilter getOutputFluidFilterForSide(EnumFacing side) {
TileEntity tile = getWorld().getTileEntity(pos.offset(side));
if (tile != null && tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side))
{
if (tile != null && tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)) {
IFluidHandler handler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
ItemStack filterStack = this.getFilterStack(side);
if (filterStack == null || !(filterStack.getItem() instanceof IFluidFilterProvider))
{
if (filterStack == null || !(filterStack.getItem() instanceof IFluidFilterProvider)) {
return null;
}
@ -83,8 +67,7 @@ public class TileOutputRoutingNode extends TileFilteredRoutingNode implements IO
}
@Override
public boolean isTankConnectedToSide(EnumFacing side)
{
public boolean isTankConnectedToSide(EnumFacing side) {
return true;
}
}

View file

@ -1,8 +1,10 @@
package WayofTime.bloodmagic.tile.routing;
import java.util.LinkedList;
import java.util.List;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.routing.IItemRoutingNode;
import WayofTime.bloodmagic.routing.IMasterRoutingNode;
import WayofTime.bloodmagic.routing.IRoutingNode;
import WayofTime.bloodmagic.tile.TileInventory;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
@ -12,37 +14,29 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.routing.IItemRoutingNode;
import WayofTime.bloodmagic.routing.IMasterRoutingNode;
import WayofTime.bloodmagic.routing.IRoutingNode;
import WayofTime.bloodmagic.tile.TileInventory;
public class TileRoutingNode extends TileInventory implements IRoutingNode, IItemRoutingNode, ITickable
{
import java.util.LinkedList;
import java.util.List;
public class TileRoutingNode extends TileInventory implements IRoutingNode, IItemRoutingNode, ITickable {
private int currentInput;
private BlockPos masterPos = BlockPos.ORIGIN;
private List<BlockPos> connectionList = new LinkedList<BlockPos>();
public TileRoutingNode(int size, String name)
{
public TileRoutingNode(int size, String name) {
super(size, name);
}
@Override
public void update()
{
if (!getWorld().isRemote)
{
public void update() {
if (!getWorld().isRemote) {
currentInput = getWorld().isBlockIndirectlyGettingPowered(pos);
// currentInput = getWorld().getStrongPower(pos);
}
}
private BlockPos masterPos = BlockPos.ORIGIN;
private List<BlockPos> connectionList = new LinkedList<BlockPos>();
@Override
public NBTTagCompound serialize(NBTTagCompound tag)
{
public NBTTagCompound serialize(NBTTagCompound tag) {
super.serialize(tag);
NBTTagCompound masterTag = new NBTTagCompound();
masterTag.setInteger(Constants.NBT.X_COORD, masterPos.getX());
@ -51,8 +45,7 @@ public class TileRoutingNode extends TileInventory implements IRoutingNode, IIte
tag.setTag(Constants.NBT.ROUTING_MASTER, masterTag);
NBTTagList tags = new NBTTagList();
for (BlockPos pos : connectionList)
{
for (BlockPos pos : connectionList) {
NBTTagCompound posTag = new NBTTagCompound();
posTag.setInteger(Constants.NBT.X_COORD, pos.getX());
posTag.setInteger(Constants.NBT.Y_COORD, pos.getY());
@ -64,16 +57,14 @@ public class TileRoutingNode extends TileInventory implements IRoutingNode, IIte
}
@Override
public void deserialize(NBTTagCompound tag)
{
public void deserialize(NBTTagCompound tag) {
super.deserialize(tag);
connectionList.clear();
NBTTagCompound masterTag = tag.getCompoundTag(Constants.NBT.ROUTING_MASTER);
masterPos = new BlockPos(masterTag.getInteger(Constants.NBT.X_COORD), masterTag.getInteger(Constants.NBT.Y_COORD), masterTag.getInteger(Constants.NBT.Z_COORD));
NBTTagList tags = tag.getTagList(Constants.NBT.ROUTING_CONNECTION, 10);
for (int i = 0; i < tags.tagCount(); i++)
{
for (int i = 0; i < tags.tagCount(); i++) {
NBTTagCompound blockTag = tags.getCompoundTagAt(i);
BlockPos newPos = new BlockPos(blockTag.getInteger(Constants.NBT.X_COORD), blockTag.getInteger(Constants.NBT.Y_COORD), blockTag.getInteger(Constants.NBT.Z_COORD));
connectionList.add(newPos);
@ -81,18 +72,14 @@ public class TileRoutingNode extends TileInventory implements IRoutingNode, IIte
}
@Override
public void removeAllConnections()
{
public void removeAllConnections() {
TileEntity testTile = getWorld().getTileEntity(getMasterPos());
if (testTile instanceof IMasterRoutingNode)
{
if (testTile instanceof IMasterRoutingNode) {
((IMasterRoutingNode) testTile).removeConnection(pos); // Remove this node from the master
}
for (BlockPos testPos : connectionList)
{
for (BlockPos testPos : connectionList) {
TileEntity tile = getWorld().getTileEntity(testPos);
if (tile instanceof IRoutingNode)
{
if (tile instanceof IRoutingNode) {
((IRoutingNode) tile).removeConnection(pos);
getWorld().notifyBlockUpdate(getPos(), getWorld().getBlockState(testPos), getWorld().getBlockState(testPos), 3);
}
@ -102,20 +89,16 @@ public class TileRoutingNode extends TileInventory implements IRoutingNode, IIte
}
@Override
public void connectMasterToRemainingNode(World world, List<BlockPos> alreadyChecked, IMasterRoutingNode master)
{
public void connectMasterToRemainingNode(World world, List<BlockPos> alreadyChecked, IMasterRoutingNode master) {
this.masterPos = master.getBlockPos();
List<BlockPos> connectedList = this.getConnected();
for (BlockPos testPos : connectedList)
{
if (alreadyChecked.contains(testPos))
{
for (BlockPos testPos : connectedList) {
if (alreadyChecked.contains(testPos)) {
continue;
}
alreadyChecked.add(testPos);
TileEntity tile = world.getTileEntity(testPos);
if (!(tile instanceof IRoutingNode))
{
if (!(tile instanceof IRoutingNode)) {
continue;
}
IRoutingNode node = (IRoutingNode) tile;
@ -130,77 +113,64 @@ public class TileRoutingNode extends TileInventory implements IRoutingNode, IIte
}
@Override
public BlockPos getBlockPos()
{
public BlockPos getBlockPos() {
return this.getPos();
}
@Override
public List<BlockPos> getConnected()
{
public List<BlockPos> getConnected() {
return connectionList;
}
@Override
public BlockPos getMasterPos()
{
public BlockPos getMasterPos() {
return masterPos;
}
@Override
public boolean isMaster(IMasterRoutingNode master)
{
public boolean isMaster(IMasterRoutingNode master) {
BlockPos checkPos = master.getBlockPos();
return checkPos.equals(getMasterPos());
}
@Override
public boolean isConnectionEnabled(BlockPos testPos)
{
public boolean isConnectionEnabled(BlockPos testPos) {
return currentInput <= 0;
}
@Override
public void addConnection(BlockPos pos1)
{
if (!connectionList.contains(pos1))
{
public void addConnection(BlockPos pos1) {
if (!connectionList.contains(pos1)) {
getWorld().notifyBlockUpdate(getPos(), getWorld().getBlockState(getPos()), getWorld().getBlockState(getPos()), 3);
connectionList.add(pos1);
}
}
@Override
public void removeConnection(BlockPos pos1)
{
if (connectionList.contains(pos1))
{
public void removeConnection(BlockPos pos1) {
if (connectionList.contains(pos1)) {
connectionList.remove(pos1);
getWorld().notifyBlockUpdate(getPos(), getWorld().getBlockState(getPos()), getWorld().getBlockState(getPos()), 3);
}
if (pos1.equals(masterPos))
{
if (pos1.equals(masterPos)) {
this.masterPos = BlockPos.ORIGIN;
}
}
@Override
public boolean isInventoryConnectedToSide(EnumFacing side)
{
public boolean isInventoryConnectedToSide(EnumFacing side) {
return false;
}
@Override
public int getPriority(EnumFacing side)
{
public int getPriority(EnumFacing side) {
return 0;
}
@Override
@SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared()
{
public double getMaxRenderDistanceSquared() {
return 10000;
}
}