use of net.minecraft.util.Direction in project BluePower by Qmunity.
the class TileBlulectricAlloyFurnace method tick.
/**
* Function gets called every tick. Do not forget to call the super method!
*/
@Override
public void tick() {
super.tick();
if (level != null && !level.isClientSide) {
storage.resetCurrent();
// Balance power of attached blulectric blocks.
for (Direction facing : Direction.values()) {
TileEntity tile = level.getBlockEntity(worldPosition.relative(facing));
if (tile != null)
tile.getCapability(CapabilityBlutricity.BLUTRICITY_CAPABILITY, facing.getOpposite()).ifPresent(exStorage -> EnergyHelper.balancePower(exStorage, storage));
}
if (updatingRecipe) {
if (this.level.getRecipeManager().getRecipeFor(AlloyFurnaceRegistry.ALLOYFURNACE_RECIPE, this, this.level).isPresent()) {
currentRecipe = (IAlloyFurnaceRecipe) this.level.getRecipeManager().getRecipeFor(AlloyFurnaceRegistry.ALLOYFURNACE_RECIPE, this, this.level).get();
} else {
currentRecipe = null;
}
updatingRecipe = false;
}
if (currentRecipe != null) {
if ((storage.getEnergy() / storage.getMaxEnergy()) > 0.5) {
storage.addEnergy(-1, false);
this.setIsActive(true);
// Check if progress completed, and output slot is empty and less then a stack of the same item.
if (++currentProcessTime >= (100 / (storage.getEnergy() / storage.getMaxEnergy())) && ((outputInventory.getItem() == currentRecipe.getResultItem().getItem() && (outputInventory.getCount() + currentRecipe.assemble(inventory, this.level.getRecipeManager()).getCount()) <= 64) || outputInventory.isEmpty())) {
currentProcessTime = 0;
if (!outputInventory.isEmpty()) {
outputInventory.setCount(outputInventory.getCount() + currentRecipe.assemble(inventory, this.level.getRecipeManager()).getCount());
} else {
outputInventory = currentRecipe.assemble(inventory, this.level.getRecipeManager()).copy();
}
currentRecipe.useItems(inventory, this.level.getRecipeManager());
updatingRecipe = true;
}
} else {
this.setIsActive(false);
}
} else {
currentProcessTime = 0;
this.setIsActive(false);
}
}
}
use of net.minecraft.util.Direction in project BluePower by Qmunity.
the class TileBlulectricFurnace method tick.
@Override
public void tick() {
if (level != null && !level.isClientSide) {
storage.resetCurrent();
// Balance power of attached blulectric blocks.
for (Direction facing : Direction.values()) {
TileEntity tile = level.getBlockEntity(worldPosition.relative(facing));
if (tile != null)
tile.getCapability(CapabilityBlutricity.BLUTRICITY_CAPABILITY, facing.getOpposite()).ifPresent(exStorage -> EnergyHelper.balancePower(exStorage, storage));
}
if (updatingRecipe) {
if (this.level.getRecipeManager().getRecipeFor(IRecipeType.SMELTING, this, this.level).isPresent()) {
currentRecipe = this.level.getRecipeManager().getRecipeFor(IRecipeType.SMELTING, this, this.level).get();
} else {
currentRecipe = null;
}
updatingRecipe = false;
}
if (currentRecipe != null) {
if ((storage.getEnergy() / storage.getMaxEnergy()) > 0.5) {
storage.addEnergy(-1, false);
this.setIsActive(true);
// Check if progress completed, and output slot is empty and less then a stack of the same item.
if (++currentProcessTime >= (100 / (storage.getEnergy() / storage.getMaxEnergy())) && ((outputInventory.getItem() == currentRecipe.getResultItem().getItem() && (outputInventory.getCount() + currentRecipe.assemble(this).getCount()) <= 64) || outputInventory.isEmpty())) {
currentProcessTime = 0;
if (!outputInventory.isEmpty()) {
outputInventory.setCount(outputInventory.getCount() + currentRecipe.assemble(this).getCount());
} else {
outputInventory = currentRecipe.assemble(this).copy();
}
this.removeItem(0, 1);
updatingRecipe = true;
}
} else {
this.setIsActive(false);
}
} else {
currentProcessTime = 0;
this.setIsActive(false);
}
}
}
use of net.minecraft.util.Direction in project BluePower by Qmunity.
the class TileWire method getCapability.
@Nonnull
@Override
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
List<Direction> directions = new ArrayList<>(BlockBPCableBase.FACING.getPossibleValues());
if (level != null) {
BlockState state = getBlockState();
if (state.getBlock() instanceof BlockAlloyWire) {
// Remove upward connections
directions.remove(state.getValue(BlockAlloyWire.FACING));
// Make sure the cable is on the same side of the block
directions.removeIf(d -> level.getBlockState(worldPosition.relative(d)).getBlock() instanceof BlockAlloyWire && level.getBlockState(worldPosition.relative(d)).getValue(BlockAlloyWire.FACING) != state.getValue(BlockAlloyWire.FACING));
// Make sure the cable is the same color or none
// if(device.getInsulationColor(null) != MinecraftColor.NONE)
// directions.removeIf(d -> {
// TileEntity tile = world.getBlockEntity(worldPosition.relative(d));
// return tile instanceof TileWire
// && !(((TileWire) tile).device.getInsulationColor(d) == device.getInsulationColor(d.getOpposite())
// || ((TileWire) tile).device.getInsulationColor(d) == MinecraftColor.NONE);
// });
}
}
if (cap == CapabilityRedstoneDevice.UNINSULATED_CAPABILITY && (side == null || directions.contains(side))) {
if (redstoneCap == null)
redstoneCap = LazyOptional.of(() -> device);
return redstoneCap.cast();
}
return LazyOptional.empty();
}
use of net.minecraft.util.Direction in project BluePower by Qmunity.
the class TileTransposer method pullItem.
protected void pullItem() {
Direction dir = getOutputDirection().getOpposite();
TileEntity inputTE = getTileCache(dir);
ItemStack extractedStack = IOHelper.extractOneItem(inputTE, dir.getOpposite());
if (!extractedStack.isEmpty())
addItemToOutputBuffer(extractedStack);
}
use of net.minecraft.util.Direction in project BluePower by Qmunity.
the class TileTransposer method redstoneChanged.
@Override
protected void redstoneChanged(boolean newValue) {
super.redstoneChanged(newValue);
Direction direction = getFacingDirection();
if (!level.isClientSide && newValue) {
if (level.isEmptyBlock(worldPosition.relative(direction))) {
suckItems();
} else {
pullItem();
}
}
}
Aggregations