Martmists 2 years ago
parent
commit
8baeea29cf
  1. 32
      src/main/java/com/martmists/ynet/blockentities/ControllerBlockEntity.java
  2. 14
      src/main/java/com/martmists/ynet/blocks/ConnectorBlock.java
  3. 46
      src/main/java/com/martmists/ynet/plugin/TRPlugin.java
  4. 6
      src/main/resources/fabric.mod.json
  5. 4
      src/main/resources/mod.mixins.json
  6. 13
      src/main/resources/tr.mod.mixins.json

32
src/main/java/com/martmists/ynet/blockentities/ControllerBlockEntity.java

@ -25,25 +25,25 @@ public class ControllerBlockEntity extends BlockEntity implements Tickable { @@ -25,25 +25,25 @@ public class ControllerBlockEntity extends BlockEntity implements Tickable {
// - Add a way to get input/output blocks from said channel
private Block[] getConnectedBlocks() {
List<BlockPos> searched = new ArrayList<>();
ArrayDeque<BlockPos> toSearch = new ArrayDeque<>(pos);
List<BlockPos> searched = new ArrayList<>(pos);
List<BlockPos> providers = new ArrayList<>();
searched.add(pos);
findNeighbors(world, pos, searched, providers);
return (Block[]) providers.stream().map(p -> world.getBlockState(p).getBlock()).toArray();
}
private static void findNeighbors(BlockView world, BlockPos p, List<BlockPos> searched, List<BlockPos> providers) {
List<BlockPos> toSearch = Arrays.asList(p.up(), p.down(), p.north(), p.south(), p.east(), p.west());
for (BlockPos bp : toSearch) {
searched.add(bp);
Block block = world.getBlockState(bp).getBlock();
if (block instanceof BaseProvider){
providers.add(bp);
}
if (block instanceof CableBlock || block instanceof ConnectorBlock){
findNeighbors(world, bp, searched, providers);
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 instanceof BaseProvider) {
providers.add(p2);
}
}
}
return (Block[]) providers.stream().map(p -> world.getBlockState(p).getBlock()).toArray();
}
@Override

14
src/main/java/com/martmists/ynet/blocks/ConnectorBlock.java

@ -65,7 +65,7 @@ public class ConnectorBlock extends ConnectingBlock { @@ -65,7 +65,7 @@ public class ConnectorBlock extends ConnectingBlock {
return super.getStateForNeighborUpdate(state, facing, neighborState, world, pos, neighborPos);
} else {
Block block = neighborState.getBlock();
return state.with(FACING_PROPERTIES.get(facing), block == this || block == YNetMod.CABLE || block instanceof BaseProvider);
return state.with(FACING_PROPERTIES.get(facing), block == this || block == YNetMod.CABLE || block == YNetMod.CONTROLLER || block instanceof BaseProvider);
}
}
@ -88,12 +88,12 @@ public class ConnectorBlock extends ConnectingBlock { @@ -88,12 +88,12 @@ public class ConnectorBlock extends ConnectingBlock {
Block block5 = world.getBlockState(pos.south()).getBlock();
Block block6 = world.getBlockState(pos.west()).getBlock();
return this.getDefaultState()
.with(DOWN, block == this || block == YNetMod.CABLE || block instanceof BaseProvider)
.with(UP, block2 == this || block2 == YNetMod.CABLE || block2 instanceof BaseProvider)
.with(NORTH, block3 == this || block3 == YNetMod.CABLE || block3 instanceof BaseProvider)
.with(EAST, block4 == this || block4 == YNetMod.CABLE || block4 instanceof BaseProvider)
.with(SOUTH, block5 == this || block5 == YNetMod.CABLE || block5 instanceof BaseProvider)
.with(WEST, block6 == this || block6 == YNetMod.CABLE || block6 instanceof BaseProvider);
.with(DOWN, block == this || block == YNetMod.CABLE || block == YNetMod.CONTROLLER || block instanceof BaseProvider)
.with(UP, block2 == this || block2 == YNetMod.CABLE || block2 == YNetMod.CONTROLLER || block2 instanceof BaseProvider)
.with(NORTH, block3 == this || block3 == YNetMod.CABLE || block3 == YNetMod.CONTROLLER || block3 instanceof BaseProvider)
.with(EAST, block4 == this || block4 == YNetMod.CABLE || block4 == YNetMod.CONTROLLER || block4 instanceof BaseProvider)
.with(SOUTH, block5 == this || block5 == YNetMod.CABLE || block5 == YNetMod.CONTROLLER || block5 instanceof BaseProvider)
.with(WEST, block6 == this || block6 == YNetMod.CABLE || block6 == YNetMod.CONTROLLER || block6 instanceof BaseProvider);
}
@Override

46
src/main/java/com/martmists/ynet/plugin/TRPlugin.java

@ -0,0 +1,46 @@ @@ -0,0 +1,46 @@
package com.martmists.ynet.plugin;
import net.fabricmc.loader.api.FabricLoader;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
import java.util.List;
import java.util.Set;
public class TRPlugin implements IMixinConfigPlugin {
@Override
public void onLoad(String mixinPackage) {
}
@Override
public String getRefMapperConfig() {
return null;
}
@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
return FabricLoader.getInstance().isModLoaded("techreborn");
}
@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
}
@Override
public List<String> getMixins() {
return null;
}
@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}
@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}
}

6
src/main/resources/fabric.mod.json

@ -15,9 +15,13 @@ @@ -15,9 +15,13 @@
]
},
"mixins": [
"mod.mixins.json"
"mod.mixins.json",
"tr.mod.mixins.json"
],
"depends": {
"fabricloader": ">=0.4.0"
},
"suggests": {
"techreborn": "*"
}
}

4
src/main/resources/mod.mixins.json

@ -3,7 +3,9 @@ @@ -3,7 +3,9 @@
"package": "com.martmists.ynet.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
"ChestBlockEntityMixin"
"accessors.InventoryStacksAccessor",
"providers.item.AbstractFurnaceBlockMixin",
"providers.item.LootableContainerBlockMixin"
],
"injectors": {
"defaultRequire": 1

13
src/main/resources/tr.mod.mixins.json

@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
{
"required": false,
"package": "com.martmists.ynet.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
"providers.energy.PowerAcceptorMixin",
"providers.item.GenericMachineBlockMixin"
],
"plugin": "com.martmists.ynet.plugin.TRPlugin",
"injectors": {
"defaultRequire": 1
}
}
Loading…
Cancel
Save