Move getting a network node/network from a tile to util class + move setOwner/getOwner to API
This commit is contained in:
@@ -51,10 +51,5 @@ public final class RS {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onServerStarting(FMLServerStartingEvent e) {
|
public void onServerStarting(FMLServerStartingEvent e) {
|
||||||
e.registerServerCommand(new CommandCreateDisk());
|
e.registerServerCommand(new CommandCreateDisk());
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onFingerprintViolation(FMLFingerprintViolationEvent e) {
|
|
||||||
FMLLog.bigWarning("Invalid fingerprint detected for the Refined Storage jar file! The file " + e.getSource().getName() + " may have been tampered with. This version will NOT be supported!");
|
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import net.minecraft.world.World;
|
|||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a node in the network.
|
* Represents a node in the network.
|
||||||
@@ -87,4 +88,15 @@ public interface INetworkNode {
|
|||||||
* @return the id of this node as specified in {@link INetworkNodeRegistry}
|
* @return the id of this node as specified in {@link INetworkNodeRegistry}
|
||||||
*/
|
*/
|
||||||
ResourceLocation getId();
|
ResourceLocation getId();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param owner the owner
|
||||||
|
*/
|
||||||
|
void setOwner(@Nullable UUID owner);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the owner
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
UUID getOwner();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import com.raoulvdberge.refinedstorage.api.network.INetworkNodeGraphListener;
|
|||||||
import com.raoulvdberge.refinedstorage.api.network.INetworkNodeVisitor;
|
import com.raoulvdberge.refinedstorage.api.network.INetworkNodeVisitor;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
|
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.Action;
|
import com.raoulvdberge.refinedstorage.api.util.Action;
|
||||||
import com.raoulvdberge.refinedstorage.capability.NetworkNodeProxyCapability;
|
import com.raoulvdberge.refinedstorage.util.NetworkUtils;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.Direction;
|
||||||
@@ -18,8 +18,6 @@ import javax.annotation.Nullable;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import static com.raoulvdberge.refinedstorage.capability.NetworkNodeProxyCapability.NETWORK_NODE_PROXY_CAPABILITY;
|
|
||||||
|
|
||||||
public class NetworkNodeGraph implements INetworkNodeGraph {
|
public class NetworkNodeGraph implements INetworkNodeGraph {
|
||||||
private INetwork network;
|
private INetwork network;
|
||||||
private Set<INetworkNode> nodes = Sets.newConcurrentHashSet();
|
private Set<INetworkNode> nodes = Sets.newConcurrentHashSet();
|
||||||
@@ -39,15 +37,9 @@ public class NetworkNodeGraph implements INetworkNodeGraph {
|
|||||||
|
|
||||||
Operator operator = new Operator(action);
|
Operator operator = new Operator(action);
|
||||||
|
|
||||||
TileEntity tile = world.getTileEntity(origin);
|
INetworkNode originNode = NetworkUtils.getNodeFromTile(world.getTileEntity(origin));
|
||||||
if (tile != null) {
|
if (originNode instanceof INetworkNodeVisitor) {
|
||||||
tile.getCapability(NetworkNodeProxyCapability.NETWORK_NODE_PROXY_CAPABILITY, null).ifPresent(proxy -> {
|
((INetworkNodeVisitor) originNode).visit(operator);
|
||||||
INetworkNode node = proxy.getNode();
|
|
||||||
|
|
||||||
if (node instanceof INetworkNodeVisitor) {
|
|
||||||
((INetworkNodeVisitor) node).visit(operator);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Visitor currentVisitor;
|
Visitor currentVisitor;
|
||||||
@@ -134,13 +126,12 @@ public class NetworkNodeGraph implements INetworkNodeGraph {
|
|||||||
public void apply(World world, BlockPos pos, @Nullable Direction side) {
|
public void apply(World world, BlockPos pos, @Nullable Direction side) {
|
||||||
TileEntity tile = world.getTileEntity(pos);
|
TileEntity tile = world.getTileEntity(pos);
|
||||||
|
|
||||||
if (tile != null) {
|
INetworkNode otherNode = NetworkUtils.getNodeFromTile(tile);
|
||||||
tile.getCapability(NETWORK_NODE_PROXY_CAPABILITY, side).ifPresent(otherNodeProxy -> {
|
|
||||||
INetworkNode otherNode = otherNodeProxy.getNode();
|
|
||||||
|
|
||||||
|
if (otherNode != null) {
|
||||||
if (otherNode.getNetwork() != null && !otherNode.getNetwork().equals(network)) {
|
if (otherNode.getNetwork() != null && !otherNode.getNetwork().equals(network)) {
|
||||||
if (action == Action.PERFORM) {
|
if (action == Action.PERFORM) {
|
||||||
dropConflictingBlock(world, tile.getPos());
|
dropConflictingBlock(world, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -158,7 +149,6 @@ public class NetworkNodeGraph implements INetworkNodeGraph {
|
|||||||
|
|
||||||
toCheck.add(new Visitor(otherNode, world, pos, side, tile));
|
toCheck.add(new Visitor(otherNode, world, pos, side, tile));
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,13 +180,11 @@ public class NetworkNodeGraph implements INetworkNodeGraph {
|
|||||||
} else {
|
} else {
|
||||||
for (Direction checkSide : Direction.values()) {
|
for (Direction checkSide : Direction.values()) {
|
||||||
if (checkSide != side) { // Avoid going backward
|
if (checkSide != side) { // Avoid going backward
|
||||||
tile.getCapability(NETWORK_NODE_PROXY_CAPABILITY, checkSide).ifPresent(nodeOnSideProxy -> {
|
INetworkNode nodeOnSide = NetworkUtils.getNodeFromTile(tile);
|
||||||
INetworkNode nodeOnSide = nodeOnSideProxy.getNode();
|
|
||||||
|
|
||||||
if (nodeOnSide == node) {
|
if (nodeOnSide == node) {
|
||||||
operator.apply(world, pos.offset(checkSide), checkSide.getOpposite());
|
operator.apply(world, pos.offset(checkSide), checkSide.getOpposite());
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,12 @@
|
|||||||
package com.raoulvdberge.refinedstorage.apiimpl.network;
|
package com.raoulvdberge.refinedstorage.apiimpl.network;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
|
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeProxy;
|
|
||||||
import com.raoulvdberge.refinedstorage.api.network.security.Permission;
|
import com.raoulvdberge.refinedstorage.api.network.security.Permission;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.Action;
|
import com.raoulvdberge.refinedstorage.api.util.Action;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNode;
|
import com.raoulvdberge.refinedstorage.util.NetworkUtils;
|
||||||
import com.raoulvdberge.refinedstorage.capability.NetworkNodeProxyCapability;
|
|
||||||
import com.raoulvdberge.refinedstorage.util.WorldUtils;
|
import com.raoulvdberge.refinedstorage.util.WorldUtils;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.Direction;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.IWorld;
|
import net.minecraft.world.IWorld;
|
||||||
@@ -39,26 +36,17 @@ public class NetworkNodeListener {
|
|||||||
if (!e.getWorld().isRemote() && e.getEntity() instanceof PlayerEntity) {
|
if (!e.getWorld().isRemote() && e.getEntity() instanceof PlayerEntity) {
|
||||||
PlayerEntity player = (PlayerEntity) e.getEntity();
|
PlayerEntity player = (PlayerEntity) e.getEntity();
|
||||||
|
|
||||||
TileEntity placed = e.getWorld().getTileEntity(e.getPos());
|
INetworkNode placed = NetworkUtils.getNodeFromTile(e.getWorld().getTileEntity(e.getPos()));
|
||||||
|
|
||||||
if (placed != null) {
|
if (placed != null) {
|
||||||
placed.getCapability(NetworkNodeProxyCapability.NETWORK_NODE_PROXY_CAPABILITY).ifPresent(proxy -> {
|
|
||||||
discoverNode(e.getWorld(), e.getPos());
|
discoverNode(e.getWorld(), e.getPos());
|
||||||
|
|
||||||
if (proxy.getNode() instanceof NetworkNode) {
|
placed.setOwner(player.getGameProfile().getId());
|
||||||
((NetworkNode) proxy.getNode()).setOwner(player.getGameProfile().getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Direction facing : Direction.values()) {
|
for (Direction facing : Direction.values()) {
|
||||||
TileEntity side = e.getWorld().getTileEntity(e.getBlockSnapshot().getPos().offset(facing));
|
INetworkNode node = NetworkUtils.getNodeFromTile(e.getWorld().getTileEntity(e.getBlockSnapshot().getPos().offset(facing)));
|
||||||
|
|
||||||
if (side != null) {
|
if (node != null && node.getNetwork() != null && !node.getNetwork().getSecurityManager().hasPermission(Permission.BUILD, player)) {
|
||||||
INetworkNodeProxy neighborProxy = side.getCapability(NetworkNodeProxyCapability.NETWORK_NODE_PROXY_CAPABILITY, facing.getOpposite()).orElse(null);
|
|
||||||
|
|
||||||
if (neighborProxy != null) {
|
|
||||||
INetworkNode node = neighborProxy.getNode();
|
|
||||||
|
|
||||||
if (node.getNetwork() != null && !node.getNetwork().getSecurityManager().hasPermission(Permission.BUILD, player)) {
|
|
||||||
WorldUtils.sendNoPermissionMessage(player);
|
WorldUtils.sendNoPermissionMessage(player);
|
||||||
|
|
||||||
e.setCanceled(true);
|
e.setCanceled(true);
|
||||||
@@ -68,46 +56,30 @@ public class NetworkNodeListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void discoverNode(IWorld world, BlockPos pos) {
|
private void discoverNode(IWorld world, BlockPos pos) {
|
||||||
for (Direction facing : Direction.values()) {
|
for (Direction facing : Direction.values()) {
|
||||||
TileEntity tile = world.getTileEntity(pos.offset(facing));
|
INetworkNode node = NetworkUtils.getNodeFromTile(world.getTileEntity(pos.offset(facing)));
|
||||||
|
|
||||||
if (tile != null) {
|
if (node != null && node.getNetwork() != null) {
|
||||||
INetworkNodeProxy proxy = tile.getCapability(NetworkNodeProxyCapability.NETWORK_NODE_PROXY_CAPABILITY, facing.getOpposite()).orElse(null);
|
|
||||||
if (proxy != null) {
|
|
||||||
INetworkNode node = proxy.getNode();
|
|
||||||
|
|
||||||
if (node.getNetwork() != null) {
|
|
||||||
node.getNetwork().getNodeGraph().invalidate(Action.PERFORM, node.getNetwork().getWorld(), node.getNetwork().getPosition());
|
node.getNetwork().getNodeGraph().invalidate(Action.PERFORM, node.getNetwork().getWorld(), node.getNetwork().getPosition());
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onBlockBreak(BlockEvent.BreakEvent e) {
|
public void onBlockBreak(BlockEvent.BreakEvent e) {
|
||||||
if (!e.getWorld().isRemote()) {
|
if (!e.getWorld().isRemote()) {
|
||||||
TileEntity tile = e.getWorld().getTileEntity(e.getPos());
|
INetworkNode node = NetworkUtils.getNodeFromTile(e.getWorld().getTileEntity(e.getPos()));
|
||||||
|
|
||||||
if (tile != null) {
|
if (node != null && node.getNetwork() != null && !node.getNetwork().getSecurityManager().hasPermission(Permission.BUILD, e.getPlayer())) {
|
||||||
tile.getCapability(NetworkNodeProxyCapability.NETWORK_NODE_PROXY_CAPABILITY).ifPresent(nodeProxy -> {
|
|
||||||
INetworkNode node = nodeProxy.getNode();
|
|
||||||
|
|
||||||
if (node.getNetwork() != null && !node.getNetwork().getSecurityManager().hasPermission(Permission.BUILD, e.getPlayer())) {
|
|
||||||
WorldUtils.sendNoPermissionMessage(e.getPlayer());
|
WorldUtils.sendNoPermissionMessage(e.getPlayer());
|
||||||
|
|
||||||
e.setCanceled(true);
|
e.setCanceled(true);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -251,12 +251,14 @@ public abstract class NetworkNode implements INetworkNode, INetworkNodeVisitor {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setOwner(@Nullable UUID owner) {
|
public void setOwner(@Nullable UUID owner) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
|
|
||||||
markDirty();
|
markDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public UUID getOwner() {
|
public UUID getOwner() {
|
||||||
return owner;
|
return owner;
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class RootNetworkNode implements INetworkNode, INetworkNodeVisitor {
|
public class RootNetworkNode implements INetworkNode, INetworkNodeVisitor {
|
||||||
private final INetwork network;
|
private final INetwork network;
|
||||||
@@ -31,6 +33,17 @@ public class RootNetworkNode implements INetworkNode, INetworkNodeVisitor {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOwner(@Nullable UUID owner) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public UUID getOwner() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getEnergyUsage() {
|
public int getEnergyUsage() {
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package com.raoulvdberge.refinedstorage.apiimpl.storage.externalstorage;
|
package com.raoulvdberge.refinedstorage.apiimpl.storage.externalstorage;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeProxy;
|
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.IStorageProvider;
|
import com.raoulvdberge.refinedstorage.api.storage.IStorageProvider;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.externalstorage.IExternalStorage;
|
import com.raoulvdberge.refinedstorage.api.storage.externalstorage.IExternalStorage;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.externalstorage.IExternalStorageContext;
|
import com.raoulvdberge.refinedstorage.api.storage.externalstorage.IExternalStorageContext;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.externalstorage.IExternalStorageProvider;
|
import com.raoulvdberge.refinedstorage.api.storage.externalstorage.IExternalStorageProvider;
|
||||||
import com.raoulvdberge.refinedstorage.capability.NetworkNodeProxyCapability;
|
|
||||||
import com.raoulvdberge.refinedstorage.tile.InterfaceTile;
|
import com.raoulvdberge.refinedstorage.tile.InterfaceTile;
|
||||||
|
import com.raoulvdberge.refinedstorage.util.NetworkUtils;
|
||||||
import com.raoulvdberge.refinedstorage.util.WorldUtils;
|
import com.raoulvdberge.refinedstorage.util.WorldUtils;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
@@ -18,9 +18,9 @@ import java.util.function.Supplier;
|
|||||||
public class ItemExternalStorageProvider implements IExternalStorageProvider<ItemStack> {
|
public class ItemExternalStorageProvider implements IExternalStorageProvider<ItemStack> {
|
||||||
@Override
|
@Override
|
||||||
public boolean canProvide(TileEntity tile, Direction direction) {
|
public boolean canProvide(TileEntity tile, Direction direction) {
|
||||||
INetworkNodeProxy nodeProxy = tile.getCapability(NetworkNodeProxyCapability.NETWORK_NODE_PROXY_CAPABILITY, direction.getOpposite()).orElse(null);
|
INetworkNode node = NetworkUtils.getNodeFromTile(tile);
|
||||||
|
|
||||||
if (nodeProxy != null && nodeProxy.getNode() instanceof IStorageProvider) {
|
if (node instanceof IStorageProvider) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,8 @@ package com.raoulvdberge.refinedstorage.item;
|
|||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.item.INetworkItemProvider;
|
import com.raoulvdberge.refinedstorage.api.network.item.INetworkItemProvider;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeProxy;
|
|
||||||
import com.raoulvdberge.refinedstorage.capability.NetworkNodeProxyCapability;
|
|
||||||
import com.raoulvdberge.refinedstorage.render.Styles;
|
import com.raoulvdberge.refinedstorage.render.Styles;
|
||||||
|
import com.raoulvdberge.refinedstorage.util.NetworkUtils;
|
||||||
import net.minecraft.client.util.ITooltipFlag;
|
import net.minecraft.client.util.ITooltipFlag;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
@@ -12,7 +11,6 @@ import net.minecraft.item.ItemStack;
|
|||||||
import net.minecraft.item.ItemUseContext;
|
import net.minecraft.item.ItemUseContext;
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.util.ActionResult;
|
||||||
import net.minecraft.util.ActionResultType;
|
import net.minecraft.util.ActionResultType;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
@@ -72,19 +70,7 @@ public abstract class NetworkItem extends EnergyItem implements INetworkItemProv
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TileEntity node = nodeWorld.getTileEntity(new BlockPos(getX(stack), getY(stack), getZ(stack)));
|
INetwork network = NetworkUtils.getNetworkFromNode(NetworkUtils.getNodeFromTile(nodeWorld.getTileEntity(new BlockPos(getX(stack), getY(stack), getZ(stack)))));
|
||||||
if (node == null) {
|
|
||||||
onError.accept(notFound);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
INetworkNodeProxy proxy = node.getCapability(NetworkNodeProxyCapability.NETWORK_NODE_PROXY_CAPABILITY).orElse(null);
|
|
||||||
if (proxy == null) {
|
|
||||||
onError.accept(notFound);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
INetwork network = proxy.getNode().getNetwork();
|
|
||||||
if (network == null) {
|
if (network == null) {
|
||||||
onError.accept(notFound);
|
onError.accept(notFound);
|
||||||
return;
|
return;
|
||||||
@@ -106,13 +92,7 @@ public abstract class NetworkItem extends EnergyItem implements INetworkItemProv
|
|||||||
public ActionResultType onItemUse(ItemUseContext ctx) {
|
public ActionResultType onItemUse(ItemUseContext ctx) {
|
||||||
ItemStack stack = ctx.getPlayer().getHeldItem(ctx.getHand());
|
ItemStack stack = ctx.getPlayer().getHeldItem(ctx.getHand());
|
||||||
|
|
||||||
TileEntity tile = ctx.getWorld().getTileEntity(ctx.getPos());
|
INetwork network = NetworkUtils.getNetworkFromNode(NetworkUtils.getNodeFromTile(ctx.getWorld().getTileEntity(ctx.getPos())));
|
||||||
if (tile != null) {
|
|
||||||
INetworkNodeProxy proxy = tile.getCapability(NetworkNodeProxyCapability.NETWORK_NODE_PROXY_CAPABILITY).orElse(null);
|
|
||||||
|
|
||||||
if (proxy != null) {
|
|
||||||
INetwork network = proxy.getNode().getNetwork();
|
|
||||||
|
|
||||||
if (network != null) {
|
if (network != null) {
|
||||||
CompoundNBT tag = stack.getTag();
|
CompoundNBT tag = stack.getTag();
|
||||||
|
|
||||||
@@ -129,8 +109,6 @@ public abstract class NetworkItem extends EnergyItem implements INetworkItemProv
|
|||||||
|
|
||||||
return ActionResultType.SUCCESS;
|
return ActionResultType.SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ActionResultType.PASS;
|
return ActionResultType.PASS;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
package com.raoulvdberge.refinedstorage.item;
|
package com.raoulvdberge.refinedstorage.item;
|
||||||
|
|
||||||
import com.raoulvdberge.refinedstorage.RS;
|
import com.raoulvdberge.refinedstorage.RS;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeProxy;
|
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.security.Permission;
|
import com.raoulvdberge.refinedstorage.api.network.security.Permission;
|
||||||
import com.raoulvdberge.refinedstorage.capability.NetworkNodeProxyCapability;
|
import com.raoulvdberge.refinedstorage.util.NetworkUtils;
|
||||||
import com.raoulvdberge.refinedstorage.util.WorldUtils;
|
import com.raoulvdberge.refinedstorage.util.WorldUtils;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemUseContext;
|
import net.minecraft.item.ItemUseContext;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.ActionResultType;
|
import net.minecraft.util.ActionResultType;
|
||||||
import net.minecraft.util.Rotation;
|
import net.minecraft.util.Rotation;
|
||||||
|
|
||||||
@@ -29,19 +28,12 @@ public class WrenchItem extends Item {
|
|||||||
return ActionResultType.SUCCESS;
|
return ActionResultType.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
TileEntity tile = ctx.getWorld().getTileEntity(ctx.getPos());
|
INetwork network = NetworkUtils.getNetworkFromNode(NetworkUtils.getNodeFromTile(ctx.getWorld().getTileEntity(ctx.getPos())));
|
||||||
|
if (network != null && !network.getSecurityManager().hasPermission(Permission.BUILD, ctx.getPlayer())) {
|
||||||
if (tile != null) {
|
|
||||||
INetworkNodeProxy proxy = tile.getCapability(NetworkNodeProxyCapability.NETWORK_NODE_PROXY_CAPABILITY, ctx.getFace().getOpposite()).orElse(null);
|
|
||||||
|
|
||||||
if (proxy != null &&
|
|
||||||
proxy.getNode().getNetwork() != null &&
|
|
||||||
!proxy.getNode().getNetwork().getSecurityManager().hasPermission(Permission.BUILD, ctx.getPlayer())) {
|
|
||||||
WorldUtils.sendNoPermissionMessage(ctx.getPlayer());
|
WorldUtils.sendNoPermissionMessage(ctx.getPlayer());
|
||||||
|
|
||||||
return ActionResultType.FAIL;
|
return ActionResultType.FAIL;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
BlockState state = ctx.getWorld().getBlockState(ctx.getPos());
|
BlockState state = ctx.getWorld().getBlockState(ctx.getPos());
|
||||||
|
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public class InputConfigurationScreen extends BaseScreen {
|
|||||||
ItemListLine line = new ItemListLine();
|
ItemListLine line = new ItemListLine();
|
||||||
|
|
||||||
for (Item item : ItemTags.getCollection().get(owningTag).getAllElements()) {
|
for (Item item : ItemTags.getCollection().get(owningTag).getAllElements()) {
|
||||||
if (itemCount > 0 && itemCount % 7 == 0) {
|
if (itemCount > 0 && itemCount % 8 == 0) {
|
||||||
lines.add(line);
|
lines.add(line);
|
||||||
line = new ItemListLine();
|
line = new ItemListLine();
|
||||||
}
|
}
|
||||||
@@ -108,7 +108,7 @@ public class InputConfigurationScreen extends BaseScreen {
|
|||||||
FluidListLine line = new FluidListLine();
|
FluidListLine line = new FluidListLine();
|
||||||
|
|
||||||
for (Fluid fluid : FluidTags.getCollection().get(owningTag).getAllElements()) {
|
for (Fluid fluid : FluidTags.getCollection().get(owningTag).getAllElements()) {
|
||||||
if (fluidCount > 0 && fluidCount % 7 == 0) {
|
if (fluidCount > 0 && fluidCount % 8 == 0) {
|
||||||
lines.add(line);
|
lines.add(line);
|
||||||
line = new FluidListLine();
|
line = new FluidListLine();
|
||||||
}
|
}
|
||||||
@@ -337,7 +337,7 @@ public class InputConfigurationScreen extends BaseScreen {
|
|||||||
for (ItemStack item : items) {
|
for (ItemStack item : items) {
|
||||||
renderItem(x + 3, y, item);
|
renderItem(x + 3, y, item);
|
||||||
|
|
||||||
x += 18;
|
x += 17;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -348,7 +348,7 @@ public class InputConfigurationScreen extends BaseScreen {
|
|||||||
InputConfigurationScreen.this.renderTooltip(item, mx, my, RenderUtils.getTooltipFromItem(item));
|
InputConfigurationScreen.this.renderTooltip(item, mx, my, RenderUtils.getTooltipFromItem(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
x += 18;
|
x += 17;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -367,7 +367,7 @@ public class InputConfigurationScreen extends BaseScreen {
|
|||||||
for (FluidStack fluid : fluids) {
|
for (FluidStack fluid : fluids) {
|
||||||
FluidRenderer.INSTANCE.render(x + 3, y, fluid);
|
FluidRenderer.INSTANCE.render(x + 3, y, fluid);
|
||||||
|
|
||||||
x += 18;
|
x += 17;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -378,7 +378,7 @@ public class InputConfigurationScreen extends BaseScreen {
|
|||||||
InputConfigurationScreen.this.renderTooltip(mx, my, fluid.getDisplayName().getFormattedText());
|
InputConfigurationScreen.this.renderTooltip(mx, my, fluid.getDisplayName().getFormattedText());
|
||||||
}
|
}
|
||||||
|
|
||||||
x += 18;
|
x += 17;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import com.raoulvdberge.refinedstorage.apiimpl.API;
|
|||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.Network;
|
import com.raoulvdberge.refinedstorage.apiimpl.network.Network;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.RootNetworkNode;
|
import com.raoulvdberge.refinedstorage.apiimpl.network.node.RootNetworkNode;
|
||||||
import com.raoulvdberge.refinedstorage.block.ControllerBlock;
|
import com.raoulvdberge.refinedstorage.block.ControllerBlock;
|
||||||
|
import com.raoulvdberge.refinedstorage.capability.NetworkNodeProxyCapability;
|
||||||
import com.raoulvdberge.refinedstorage.tile.config.IRedstoneConfigurable;
|
import com.raoulvdberge.refinedstorage.tile.config.IRedstoneConfigurable;
|
||||||
import com.raoulvdberge.refinedstorage.tile.config.RedstoneMode;
|
import com.raoulvdberge.refinedstorage.tile.config.RedstoneMode;
|
||||||
import com.raoulvdberge.refinedstorage.tile.data.RSSerializers;
|
import com.raoulvdberge.refinedstorage.tile.data.RSSerializers;
|
||||||
@@ -29,8 +30,6 @@ import javax.annotation.Nullable;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.raoulvdberge.refinedstorage.capability.NetworkNodeProxyCapability.NETWORK_NODE_PROXY_CAPABILITY;
|
|
||||||
|
|
||||||
public class ControllerTile extends BaseTile implements INetworkNodeProxy<RootNetworkNode>, IRedstoneConfigurable {
|
public class ControllerTile extends BaseTile implements INetworkNodeProxy<RootNetworkNode>, IRedstoneConfigurable {
|
||||||
public static final TileDataParameter<Integer, ControllerTile> REDSTONE_MODE = RedstoneMode.createParameter();
|
public static final TileDataParameter<Integer, ControllerTile> REDSTONE_MODE = RedstoneMode.createParameter();
|
||||||
public static final TileDataParameter<Integer, ControllerTile> ENERGY_USAGE = new TileDataParameter<>(DataSerializers.VARINT, 0, t -> t.getNetwork().getEnergyUsage());
|
public static final TileDataParameter<Integer, ControllerTile> ENERGY_USAGE = new TileDataParameter<>(DataSerializers.VARINT, 0, t -> t.getNetwork().getEnergyUsage());
|
||||||
@@ -156,7 +155,7 @@ public class ControllerTile extends BaseTile implements INetworkNodeProxy<RootNe
|
|||||||
return energyProxyCap.cast();
|
return energyProxyCap.cast();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cap == NETWORK_NODE_PROXY_CAPABILITY) {
|
if (cap == NetworkNodeProxyCapability.NETWORK_NODE_PROXY_CAPABILITY) {
|
||||||
return networkNodeProxyCap.cast();
|
return networkNodeProxyCap.cast();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,16 +4,14 @@ import com.raoulvdberge.refinedstorage.RS;
|
|||||||
import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingManager;
|
import com.raoulvdberge.refinedstorage.api.autocrafting.ICraftingManager;
|
||||||
import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingTask;
|
import com.raoulvdberge.refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeProxy;
|
|
||||||
import com.raoulvdberge.refinedstorage.capability.NetworkNodeProxyCapability;
|
|
||||||
import com.raoulvdberge.refinedstorage.item.WirelessCraftingMonitorItem;
|
import com.raoulvdberge.refinedstorage.item.WirelessCraftingMonitorItem;
|
||||||
import com.raoulvdberge.refinedstorage.network.craftingmonitor.WirelessCraftingMonitorSettingsUpdateMessage;
|
import com.raoulvdberge.refinedstorage.network.craftingmonitor.WirelessCraftingMonitorSettingsUpdateMessage;
|
||||||
import com.raoulvdberge.refinedstorage.tile.data.TileDataParameter;
|
import com.raoulvdberge.refinedstorage.tile.data.TileDataParameter;
|
||||||
|
import com.raoulvdberge.refinedstorage.util.NetworkUtils;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
import net.minecraft.util.text.ITextComponent;
|
||||||
import net.minecraft.util.text.TranslationTextComponent;
|
import net.minecraft.util.text.TranslationTextComponent;
|
||||||
@@ -100,15 +98,7 @@ public class WirelessCraftingMonitor implements ICraftingMonitor {
|
|||||||
World world = DimensionManager.getWorld(server, nodeDimension, true, true);
|
World world = DimensionManager.getWorld(server, nodeDimension, true, true);
|
||||||
|
|
||||||
if (world != null) {
|
if (world != null) {
|
||||||
TileEntity tile = world.getTileEntity(nodePos);
|
return NetworkUtils.getNetworkFromNode(NetworkUtils.getNodeFromTile(world.getTileEntity(nodePos)));
|
||||||
|
|
||||||
if (tile != null) {
|
|
||||||
INetworkNodeProxy proxy = tile.getCapability(NetworkNodeProxyCapability.NETWORK_NODE_PROXY_CAPABILITY).orElse(null);
|
|
||||||
|
|
||||||
if (proxy != null) {
|
|
||||||
return proxy.getNode().getNetwork();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -5,17 +5,16 @@ import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
|||||||
import com.raoulvdberge.refinedstorage.api.network.grid.*;
|
import com.raoulvdberge.refinedstorage.api.network.grid.*;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IFluidGridHandler;
|
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IFluidGridHandler;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IItemGridHandler;
|
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IItemGridHandler;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeProxy;
|
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.cache.IStorageCache;
|
import com.raoulvdberge.refinedstorage.api.storage.cache.IStorageCache;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.cache.IStorageCacheListener;
|
import com.raoulvdberge.refinedstorage.api.storage.cache.IStorageCacheListener;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IFilter;
|
import com.raoulvdberge.refinedstorage.api.util.IFilter;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.cache.listener.FluidGridStorageCacheListener;
|
import com.raoulvdberge.refinedstorage.apiimpl.storage.cache.listener.FluidGridStorageCacheListener;
|
||||||
import com.raoulvdberge.refinedstorage.capability.NetworkNodeProxyCapability;
|
|
||||||
import com.raoulvdberge.refinedstorage.inventory.item.FilterItemHandler;
|
import com.raoulvdberge.refinedstorage.inventory.item.FilterItemHandler;
|
||||||
import com.raoulvdberge.refinedstorage.item.WirelessFluidGridItem;
|
import com.raoulvdberge.refinedstorage.item.WirelessFluidGridItem;
|
||||||
import com.raoulvdberge.refinedstorage.network.grid.WirelessFluidGridSettingsUpdateMessage;
|
import com.raoulvdberge.refinedstorage.network.grid.WirelessFluidGridSettingsUpdateMessage;
|
||||||
import com.raoulvdberge.refinedstorage.screen.BaseScreen;
|
import com.raoulvdberge.refinedstorage.screen.BaseScreen;
|
||||||
import com.raoulvdberge.refinedstorage.screen.grid.GridScreen;
|
import com.raoulvdberge.refinedstorage.screen.grid.GridScreen;
|
||||||
|
import com.raoulvdberge.refinedstorage.util.NetworkUtils;
|
||||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
@@ -24,7 +23,6 @@ import net.minecraft.inventory.CraftingInventory;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
import net.minecraft.util.text.ITextComponent;
|
||||||
import net.minecraft.util.text.TranslationTextComponent;
|
import net.minecraft.util.text.TranslationTextComponent;
|
||||||
@@ -95,15 +93,7 @@ public class WirelessFluidGrid implements INetworkAwareGrid {
|
|||||||
World world = DimensionManager.getWorld(server, nodeDimension, true, true);
|
World world = DimensionManager.getWorld(server, nodeDimension, true, true);
|
||||||
|
|
||||||
if (world != null) {
|
if (world != null) {
|
||||||
TileEntity tile = world.getTileEntity(nodePos);
|
return NetworkUtils.getNetworkFromNode(NetworkUtils.getNodeFromTile(world.getTileEntity(nodePos)));
|
||||||
|
|
||||||
if (tile != null) {
|
|
||||||
INetworkNodeProxy proxy = tile.getCapability(NetworkNodeProxyCapability.NETWORK_NODE_PROXY_CAPABILITY).orElse(null);
|
|
||||||
|
|
||||||
if (proxy != null) {
|
|
||||||
return proxy.getNode().getNetwork();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -5,17 +5,16 @@ import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
|||||||
import com.raoulvdberge.refinedstorage.api.network.grid.*;
|
import com.raoulvdberge.refinedstorage.api.network.grid.*;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IFluidGridHandler;
|
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IFluidGridHandler;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IItemGridHandler;
|
import com.raoulvdberge.refinedstorage.api.network.grid.handler.IItemGridHandler;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeProxy;
|
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.cache.IStorageCache;
|
import com.raoulvdberge.refinedstorage.api.storage.cache.IStorageCache;
|
||||||
import com.raoulvdberge.refinedstorage.api.storage.cache.IStorageCacheListener;
|
import com.raoulvdberge.refinedstorage.api.storage.cache.IStorageCacheListener;
|
||||||
import com.raoulvdberge.refinedstorage.api.util.IFilter;
|
import com.raoulvdberge.refinedstorage.api.util.IFilter;
|
||||||
import com.raoulvdberge.refinedstorage.apiimpl.storage.cache.listener.ItemGridStorageCacheListener;
|
import com.raoulvdberge.refinedstorage.apiimpl.storage.cache.listener.ItemGridStorageCacheListener;
|
||||||
import com.raoulvdberge.refinedstorage.capability.NetworkNodeProxyCapability;
|
|
||||||
import com.raoulvdberge.refinedstorage.inventory.item.FilterItemHandler;
|
import com.raoulvdberge.refinedstorage.inventory.item.FilterItemHandler;
|
||||||
import com.raoulvdberge.refinedstorage.item.WirelessGridItem;
|
import com.raoulvdberge.refinedstorage.item.WirelessGridItem;
|
||||||
import com.raoulvdberge.refinedstorage.network.grid.WirelessGridSettingsUpdateMessage;
|
import com.raoulvdberge.refinedstorage.network.grid.WirelessGridSettingsUpdateMessage;
|
||||||
import com.raoulvdberge.refinedstorage.screen.BaseScreen;
|
import com.raoulvdberge.refinedstorage.screen.BaseScreen;
|
||||||
import com.raoulvdberge.refinedstorage.screen.grid.GridScreen;
|
import com.raoulvdberge.refinedstorage.screen.grid.GridScreen;
|
||||||
|
import com.raoulvdberge.refinedstorage.util.NetworkUtils;
|
||||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
@@ -24,7 +23,6 @@ import net.minecraft.inventory.CraftingInventory;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
import net.minecraft.util.text.ITextComponent;
|
||||||
import net.minecraft.util.text.TranslationTextComponent;
|
import net.minecraft.util.text.TranslationTextComponent;
|
||||||
@@ -97,16 +95,7 @@ public class WirelessGrid implements INetworkAwareGrid {
|
|||||||
World world = DimensionManager.getWorld(server, nodeDimension, true, true);
|
World world = DimensionManager.getWorld(server, nodeDimension, true, true);
|
||||||
|
|
||||||
if (world != null) {
|
if (world != null) {
|
||||||
TileEntity tile = world.getTileEntity(nodePos);
|
return NetworkUtils.getNetworkFromNode(NetworkUtils.getNodeFromTile(world.getTileEntity(nodePos)));
|
||||||
|
|
||||||
// TODO Create helper to get INetworkNodeProxy of tile
|
|
||||||
if (tile != null) {
|
|
||||||
INetworkNodeProxy proxy = tile.getCapability(NetworkNodeProxyCapability.NETWORK_NODE_PROXY_CAPABILITY).orElse(null);
|
|
||||||
|
|
||||||
if (proxy != null) {
|
|
||||||
return proxy.getNode().getNetwork();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.raoulvdberge.refinedstorage.util;
|
package com.raoulvdberge.refinedstorage.util;
|
||||||
|
|
||||||
|
import com.raoulvdberge.refinedstorage.api.network.INetwork;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
|
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeProxy;
|
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeProxy;
|
||||||
import com.raoulvdberge.refinedstorage.api.network.security.Permission;
|
import com.raoulvdberge.refinedstorage.api.network.security.Permission;
|
||||||
@@ -10,7 +11,31 @@ import net.minecraft.util.Direction;
|
|||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class NetworkUtils {
|
public class NetworkUtils {
|
||||||
|
@Nullable
|
||||||
|
public static INetworkNode getNodeFromTile(@Nullable TileEntity tile) {
|
||||||
|
if (tile != null) {
|
||||||
|
INetworkNodeProxy proxy = tile.getCapability(NetworkNodeProxyCapability.NETWORK_NODE_PROXY_CAPABILITY).orElse(null);
|
||||||
|
|
||||||
|
if (proxy != null) {
|
||||||
|
return proxy.getNode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static INetwork getNetworkFromNode(@Nullable INetworkNode node) {
|
||||||
|
if (node != null) {
|
||||||
|
return node.getNetwork();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean attemptModify(World world, BlockPos pos, Direction facing, PlayerEntity player, Runnable action) {
|
public static boolean attemptModify(World world, BlockPos pos, Direction facing, PlayerEntity player, Runnable action) {
|
||||||
return attempt(world, pos, facing, player, action, Permission.MODIFY);
|
return attempt(world, pos, facing, player, action, Permission.MODIFY);
|
||||||
}
|
}
|
||||||
@@ -20,22 +45,14 @@ public class NetworkUtils {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TileEntity tile = world.getTileEntity(pos);
|
INetwork network = getNetworkFromNode(getNodeFromTile(world.getTileEntity(pos)));
|
||||||
|
|
||||||
if (tile != null) {
|
if (network != null) {
|
||||||
INetworkNodeProxy proxy = tile.getCapability(NetworkNodeProxyCapability.NETWORK_NODE_PROXY_CAPABILITY, facing).orElse(null);
|
|
||||||
|
|
||||||
if (proxy != null) {
|
|
||||||
INetworkNode node = proxy.getNode();
|
|
||||||
|
|
||||||
if (node.getNetwork() != null) {
|
|
||||||
for (Permission permission : permissionsRequired) {
|
for (Permission permission : permissionsRequired) {
|
||||||
if (!node.getNetwork().getSecurityManager().hasPermission(permission, player)) {
|
if (!network.getSecurityManager().hasPermission(permission, player)) {
|
||||||
WorldUtils.sendNoPermissionMessage(player);
|
WorldUtils.sendNoPermissionMessage(player);
|
||||||
|
|
||||||
return true; // Avoid placing blocks
|
return true;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user