forked from Martmists/YNet
17 changed files with 536 additions and 139 deletions
@ -0,0 +1,24 @@
@@ -0,0 +1,24 @@
|
||||
package com.martmists.ynet.blockentities; |
||||
|
||||
import com.martmists.ynet.YNetMod; |
||||
import net.minecraft.block.entity.BlockEntity; |
||||
import net.minecraft.util.math.Direction; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
public class ConnectorBlockEntity extends BlockEntity { |
||||
private Map<Direction, Integer> redstoneState = new HashMap<>(); |
||||
|
||||
public ConnectorBlockEntity() { |
||||
super(YNetMod.CONNECTOR_BE); |
||||
} |
||||
|
||||
public void setRedstonePower(Direction d, int p) { |
||||
redstoneState.put(d, p); |
||||
} |
||||
|
||||
public int getRedstonePower(Direction d) { |
||||
return redstoneState.getOrDefault(d, 0); |
||||
} |
||||
} |
@ -0,0 +1,10 @@
@@ -0,0 +1,10 @@
|
||||
package com.martmists.ynet.network; |
||||
|
||||
import com.martmists.ynet.api.BaseProvider; |
||||
|
||||
import java.util.Set; |
||||
|
||||
public class Channel { |
||||
public Class<? extends BaseProvider> providerType; |
||||
public Set<ConnectorConfiguration> connectorSettings; |
||||
} |
@ -0,0 +1,17 @@
@@ -0,0 +1,17 @@
|
||||
package com.martmists.ynet.network; |
||||
|
||||
import net.minecraft.item.Item; |
||||
import net.minecraft.util.math.BlockPos; |
||||
|
||||
public class ConnectorConfiguration { |
||||
public State state = State.DISABLED; |
||||
public BlockPos providerPos; |
||||
public int priority; |
||||
public Item[] filter; |
||||
|
||||
public static enum State { |
||||
DISABLED, |
||||
INPUT, |
||||
OUTPUT |
||||
} |
||||
} |
@ -0,0 +1,119 @@
@@ -0,0 +1,119 @@
|
||||
package com.martmists.ynet.network; |
||||
|
||||
import com.martmists.ynet.YNetMod; |
||||
import com.martmists.ynet.api.BaseProvider; |
||||
import com.martmists.ynet.blockentities.ControllerBlockEntity; |
||||
import net.minecraft.block.Block; |
||||
import net.minecraft.util.math.BlockPos; |
||||
import net.minecraft.world.BlockView; |
||||
|
||||
import java.util.*; |
||||
|
||||
public class Network { |
||||
private BlockPos controller; |
||||
public Set<BlockPos> cables; |
||||
public Set<BlockPos> connectors; |
||||
|
||||
public void reloadAllNodes(BlockView world) { |
||||
cables = new HashSet<>(); |
||||
connectors = new HashSet<>(); |
||||
ControllerBlockEntity be = ((ControllerBlockEntity)world.getBlockEntity(controller)); |
||||
getConnectedBlocks(be.getWorld(), controller, cables, connectors); |
||||
} |
||||
|
||||
public static void getConnectedBlocks(BlockView world, BlockPos origin, Set<BlockPos> cables, Set<BlockPos> connectors) { |
||||
getConnectedBlocks(world, origin, new HashSet<>(), cables, connectors); |
||||
} |
||||
|
||||
public static void getConnectedBlocks(BlockView world, BlockPos origin, Set<BlockPos> exclude, Set<BlockPos> cables, Set<BlockPos> connectors) { |
||||
ArrayDeque<BlockPos> toSearch = new ArrayDeque<>(); |
||||
toSearch.push(origin); |
||||
exclude.add(origin); |
||||
// Search origin first
|
||||
Block bo = world.getBlockState(origin).getBlock(); |
||||
if (bo == YNetMod.CABLE) { |
||||
cables.add(origin); |
||||
} else if (bo == YNetMod.CONNECTOR) { |
||||
connectors.add(origin); |
||||
} |
||||
|
||||
// Search connected
|
||||
while (!toSearch.isEmpty()){ |
||||
BlockPos p = toSearch.removeFirst(); |
||||
for (BlockPos p2 : Arrays.asList(p.up(), p.down(), p.north(), p.south(), p.east(), p.west())) { |
||||
if (exclude.contains(p2)) { |
||||
continue; |
||||
} |
||||
exclude.add(p2); |
||||
Block b = world.getBlockState(p2).getBlock(); |
||||
if (b == YNetMod.CABLE) { |
||||
toSearch.add(p2); |
||||
cables.add(p2); |
||||
} else if (b == YNetMod.CONNECTOR) { |
||||
toSearch.add(p2); |
||||
connectors.add(p2); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
public static void getConnectedControllers(BlockView world, BlockPos origin, Set<BlockPos> controllers) { |
||||
ArrayDeque<BlockPos> toSearch = new ArrayDeque<>(); |
||||
toSearch.push(origin); |
||||
List<BlockPos> searched = new ArrayList<>(); |
||||
while (!toSearch.isEmpty()){ |
||||
BlockPos p = toSearch.removeFirst(); |
||||
for (BlockPos p2 : Arrays.asList(p.up(), p.down(), p.north(), p.south(), p.east(), p.west())) { |
||||
if (searched.contains(p2)) { |
||||
continue; |
||||
} |
||||
searched.add(p2); |
||||
Block b = world.getBlockState(p2).getBlock(); |
||||
if (b == YNetMod.CABLE || b == YNetMod.CONNECTOR) { |
||||
toSearch.add(p2); |
||||
} else if (b == YNetMod.CONTROLLER) { |
||||
controllers.add(p2); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
public void setController(BlockPos pos) { |
||||
controller = pos; |
||||
} |
||||
|
||||
public Set<BlockPos> getProviders(BlockView world) { |
||||
return getProviders(world, BaseProvider.class); |
||||
} |
||||
|
||||
public Set<BlockPos> getProviders(BlockView world, Class<BaseProvider> type) { |
||||
Set<BlockPos> providers = new HashSet<>(); |
||||
connectors.forEach((c) -> { |
||||
for (BlockPos p : Arrays.asList(c.up(), c.down(), c.north(), c.south(), c.east(), c.west())) { |
||||
Block b = world.getBlockState(p).getBlock(); |
||||
Set<Class<? extends BaseProvider>> providerTypes = new HashSet<>(); |
||||
findProviderTypes(b.getClass(), providerTypes); |
||||
if (providerTypes.contains(type) || (type == BaseProvider.class && b instanceof BaseProvider)) { |
||||
providers.add(p); |
||||
} |
||||
} |
||||
}); |
||||
return providers; |
||||
} |
||||
|
||||
|
||||
// Ugly hack by Pyrofab
|
||||
private static Map<Class<?>, Set<Class<? extends BaseProvider>>> tMap = new HashMap<>(); |
||||
private static void findProviderTypes(Class<?> cls, Set<Class<? extends BaseProvider>> ret) { |
||||
tMap.putIfAbsent(cls, ret); |
||||
if (cls != Object.class && cls != null) { |
||||
if (BaseProvider.class.isAssignableFrom(cls)) { |
||||
ret.add((Class<? extends BaseProvider>) cls); |
||||
} |
||||
findProviderTypes(cls.getSuperclass(), ret); |
||||
for (Class<?> itf : cls.getInterfaces()) { |
||||
findProviderTypes(itf, ret); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,119 @@
@@ -0,0 +1,119 @@
|
||||
{ |
||||
"multipart": [ |
||||
{ |
||||
"apply": { |
||||
"model": "ynet:block/cable" |
||||
} |
||||
}, |
||||
{ |
||||
"when": { |
||||
"north": true |
||||
}, |
||||
"apply": { |
||||
"model": "ynet:block/connector", |
||||
"x": 270 |
||||
} |
||||
}, |
||||
{ |
||||
"when": { |
||||
"east": true |
||||
}, |
||||
"apply": { |
||||
"model": "ynet:block/connector", |
||||
"x": 90, |
||||
"y": 270 |
||||
} |
||||
}, |
||||
{ |
||||
"when": { |
||||
"south": true |
||||
}, |
||||
"apply": { |
||||
"model": "ynet:block/connector", |
||||
"x": 90 |
||||
} |
||||
}, |
||||
{ |
||||
"when": { |
||||
"west": true |
||||
}, |
||||
"apply": { |
||||
"model": "ynet:block/connector", |
||||
"x": 90, |
||||
"y": 90 |
||||
} |
||||
}, |
||||
{ |
||||
"when": { |
||||
"up": true |
||||
}, |
||||
"apply": { |
||||
"model": "ynet:block/connector", |
||||
"x": 180 |
||||
} |
||||
}, |
||||
{ |
||||
"when": { |
||||
"down": true |
||||
}, |
||||
"apply": { |
||||
"model": "ynet:block/connector" |
||||
} |
||||
}, |
||||
{ |
||||
"when": { |
||||
"north_cable": true |
||||
}, |
||||
"apply": { |
||||
"model": "ynet:block/cable_side", |
||||
"x": 270 |
||||
} |
||||
}, |
||||
{ |
||||
"when": { |
||||
"east_cable": true |
||||
}, |
||||
"apply": { |
||||
"model": "ynet:block/cable_side", |
||||
"x": 90, |
||||
"y": 270 |
||||
} |
||||
}, |
||||
{ |
||||
"when": { |
||||
"south_cable": true |
||||
}, |
||||
"apply": { |
||||
"model": "ynet:block/cable_side", |
||||
"x": 90 |
||||
} |
||||
}, |
||||
{ |
||||
"when": { |
||||
"west_cable": true |
||||
}, |
||||
"apply": { |
||||
"model": "ynet:block/cable_side", |
||||
"x": 90, |
||||
"y": 90 |
||||
} |
||||
}, |
||||
{ |
||||
"when": { |
||||
"up_cable": true |
||||
}, |
||||
"apply": { |
||||
"model": "ynet:block/cable_side", |
||||
"x": 180 |
||||
} |
||||
}, |
||||
{ |
||||
"when": { |
||||
"down_cable": true |
||||
}, |
||||
"apply": { |
||||
"model": "ynet:block/cable_side" |
||||
} |
||||
} |
||||
] |
||||
} |
@ -0,0 +1,37 @@
@@ -0,0 +1,37 @@
|
||||
{ |
||||
"credit": "Made with Blockbench", |
||||
"ambientocclusion": false, |
||||
"textures": { |
||||
"0": "ynet:block/pipe", |
||||
"1": "ynet:block/connector", |
||||
"particle": "ynet:block/pipe" |
||||
}, |
||||
"elements": [ |
||||
{ |
||||
"name": "pipe_side", |
||||
"from": [5, 1, 5], |
||||
"to": [11, 5, 11], |
||||
"faces": { |
||||
"north": {"uv": [0, 0, 6, 4], "texture": "#0"}, |
||||
"east": {"uv": [0, 0, 6, 4], "texture": "#0"}, |
||||
"south": {"uv": [0, 0, 6, 4], "texture": "#0"}, |
||||
"west": {"uv": [0, 0, 6, 4], "texture": "#0"}, |
||||
"up": {"uv": [0, 0, 6, 6], "texture": "#0"}, |
||||
"down": {"uv": [0, 0, 6, 6], "texture": "#0"} |
||||
} |
||||
}, |
||||
{ |
||||
"name": "connector", |
||||
"from": [3, 0, 3], |
||||
"to": [13, 1, 13], |
||||
"faces": { |
||||
"north": {"uv": [0, 0, 10, 1], "texture": "#1"}, |
||||
"east": {"uv": [0, 0, 10, 1], "texture": "#1"}, |
||||
"south": {"uv": [0, 0, 10, 1], "texture": "#1"}, |
||||
"west": {"uv": [0, 0, 10, 1], "texture": "#1"}, |
||||
"up": {"uv": [0, 0, 10, 10], "texture": "#1"}, |
||||
"down": {"uv": [0, 0, 10, 10], "texture": "#1"} |
||||
} |
||||
} |
||||
] |
||||
} |
After Width: | Height: | Size: 128 B |
Before Width: | Height: | Size: 105 B After Width: | Height: | Size: 99 B |
Loading…
Reference in new issue