New API method to allow to connect graphically other tiles to cables (#650)
* Added to the API the a method to connect graphically tile entities to cables * Changed a Set of Class to Predicate<TileEntity> and moved it to the API class * Unneeded imports. Sorry. * Moved the addition of the connectable condition of INetworkMaster and INetworkNode to ProxyCommon class
This commit is contained in:
@@ -12,9 +12,12 @@ import com.raoulvdberge.refinedstorage.api.util.IComparer;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IFluidStackList;
|
||||
import com.raoulvdberge.refinedstorage.api.util.IItemStackList;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* Represents a Refined Storage API implementation.
|
||||
@@ -89,4 +92,9 @@ public interface IRSAPI {
|
||||
* @return a hashcode for the given stack
|
||||
*/
|
||||
int getFluidStackHashCode(FluidStack stack);
|
||||
|
||||
/**
|
||||
* @return a set with the predicates to check if a block is connectable
|
||||
*/
|
||||
Set<Predicate<TileEntity>> getConnectableConditions();
|
||||
}
|
||||
|
@@ -24,12 +24,15 @@ import com.raoulvdberge.refinedstorage.apiimpl.util.Comparer;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.util.FluidStackList;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.util.ItemStackList;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.common.discovery.ASMDataTable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class API implements IRSAPI {
|
||||
private static final IRSAPI INSTANCE = new API();
|
||||
@@ -40,6 +43,7 @@ public class API implements IRSAPI {
|
||||
private ICraftingMonitorElementRegistry craftingMonitorElementRegistry = new CraftingMonitorElementRegistry();
|
||||
private ICraftingPreviewElementRegistry craftingPreviewElementRegistry = new CraftingPreviewElementRegistry();
|
||||
private IReaderWriterHandlerRegistry readerWriterHandlerRegistry = new ReaderWriterHandlerRegistry();
|
||||
private Set<Predicate<TileEntity>> connectableConditions = new HashSet<>();
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@@ -111,6 +115,11 @@ public class API implements IRSAPI {
|
||||
return stack.getFluid().hashCode() * (stack.tag != null ? stack.tag.hashCode() : 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Predicate<TileEntity>> getConnectableConditions() {
|
||||
return connectableConditions;
|
||||
}
|
||||
|
||||
public static IRSAPI instance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@ package com.raoulvdberge.refinedstorage.block;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetworkMaster;
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.tile.TileBase;
|
||||
import com.raoulvdberge.refinedstorage.tile.TileCable;
|
||||
import com.raoulvdberge.refinedstorage.tile.TileMultipartNode;
|
||||
@@ -30,9 +30,7 @@ import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public class BlockCable extends BlockCoverable {
|
||||
protected static final PropertyDirection DIRECTION = PropertyDirection.create("direction");
|
||||
@@ -151,7 +149,8 @@ public class BlockCable extends BlockCoverable {
|
||||
private boolean hasConnectionWith(IBlockAccess world, BlockPos pos, EnumFacing direction) {
|
||||
TileEntity facing = world.getTileEntity(pos.offset(direction));
|
||||
|
||||
if (facing instanceof INetworkMaster || facing instanceof INetworkNode) {
|
||||
boolean isConnectable = API.instance().getConnectableConditions().stream().anyMatch(p -> p.test(facing));
|
||||
if (isConnectable) {
|
||||
// Do not render a cable extension where our cable "head" is (e.g. importer, exporter, external storage heads).
|
||||
if (getPlacementType() != null && ((TileMultipartNode) world.getTileEntity(pos)).getFacingTile() == facing) {
|
||||
return false;
|
||||
|
@@ -4,6 +4,8 @@ import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.RSBlocks;
|
||||
import com.raoulvdberge.refinedstorage.RSItems;
|
||||
import com.raoulvdberge.refinedstorage.RSUtils;
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetworkMaster;
|
||||
import com.raoulvdberge.refinedstorage.api.network.INetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.*;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementFluidStack;
|
||||
@@ -84,6 +86,8 @@ public class ProxyCommon {
|
||||
API.instance().getReaderWriterHandlerRegistry().add(ReaderWriterHandlerRedstone.ID, tag -> new ReaderWriterHandlerRedstone());
|
||||
API.instance().getReaderWriterHandlerRegistry().add(ReaderWriterHandlerForgeEnergy.ID, ReaderWriterHandlerForgeEnergy::new);
|
||||
|
||||
API.instance().getConnectableConditions().add(tile -> tile instanceof INetworkMaster || tile instanceof INetworkNode);
|
||||
|
||||
if (IntegrationTesla.isLoaded()) {
|
||||
API.instance().getReaderWriterHandlerRegistry().add(ReaderWriterHandlerTesla.ID, ReaderWriterHandlerTesla::new);
|
||||
}
|
||||
|
Reference in New Issue
Block a user