Browse Source

Improve UI; Seems to not save correctly?

master
Martmists 2 years ago
parent
commit
3b4f0bb94e
  1. 38
      src/main/java/com/martmists/ynet/YNetMod.java
  2. 16
      src/main/java/com/martmists/ynet/YNetModClient.java
  3. 13
      src/main/java/com/martmists/ynet/api/FluidProvider.java
  4. 12
      src/main/java/com/martmists/ynet/blockentities/ControllerBlockEntity.java
  5. 9
      src/main/java/com/martmists/ynet/blocks/ControllerBlock.java
  6. 21
      src/main/java/com/martmists/ynet/containers/ControllerContainer.java
  7. 68
      src/main/java/com/martmists/ynet/event/impl/EnergyTickCallback.java
  8. 113
      src/main/java/com/martmists/ynet/event/impl/FluidTickCallback.java
  9. 68
      src/main/java/com/martmists/ynet/event/impl/ItemTickCallback.java
  10. 37
      src/main/java/com/martmists/ynet/mixin/providers/fluid/BlockMachineBaseMixin.java
  11. 6
      src/main/java/com/martmists/ynet/network/Channel.java
  12. 14
      src/main/java/com/martmists/ynet/network/ConnectorConfiguration.java
  13. 251
      src/main/java/com/martmists/ynet/screens/ControllerScreen.java
  14. 17
      src/main/java/spinnery/widget/WItem.java
  15. 4
      src/main/resources/assets/ynet/models/block/cable.json
  16. 1
      src/main/resources/assets/ynet/models/block/connector.json
  17. 21
      src/main/resources/assets/ynet/models/item/cable.json
  18. 33
      src/main/resources/assets/ynet/models/item/connector.json
  19. 3
      src/main/resources/fabric.mod.json
  20. 3
      versions/1.15.2/gradle.properties
  21. 1
      versions/1.16/gradle.properties
  22. 7
      versions/common.gradle

38
src/main/java/com/martmists/ynet/YNetMod.java

@ -2,18 +2,21 @@ package com.martmists.ynet; @@ -2,18 +2,21 @@ package com.martmists.ynet;
import com.martmists.ynet.api.BaseProvider;
import com.martmists.ynet.api.EnergyProvider;
import com.martmists.ynet.api.FluidProvider;
import com.martmists.ynet.api.ItemProvider;
import com.martmists.ynet.blockentities.ConnectorBlockEntity;
import com.martmists.ynet.blockentities.ControllerBlockEntity;
import com.martmists.ynet.blocks.CableBlock;
import com.martmists.ynet.blocks.ConnectorBlock;
import com.martmists.ynet.blocks.ControllerBlock;
import com.martmists.ynet.event.DefaultListeners;
import com.martmists.ynet.containers.ControllerContainer;
import com.martmists.ynet.event.impl.EnergyTickCallback;
import com.martmists.ynet.event.impl.FluidTickCallback;
import com.martmists.ynet.event.impl.ItemTickCallback;
import com.martmists.ynet.event.ProviderTickCallback;
import com.martmists.ynet.network.ConnectorConfiguration;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.fabric.api.container.ContainerProviderRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.Material;
import net.minecraft.block.entity.BlockEntityType;
@ -21,18 +24,11 @@ import net.minecraft.item.BlockItem; @@ -21,18 +24,11 @@ import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.SimpleRegistry;
import net.minecraft.world.World;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
public class YNetMod implements ModInitializer {
public static ItemGroup YNET_GROUP = FabricItemGroupBuilder.build(
@ -62,19 +58,20 @@ public class YNetMod implements ModInitializer { @@ -62,19 +58,20 @@ public class YNetMod implements ModInitializer {
// Internal use
public static Map<Class<? extends BaseProvider>, ProviderTickCallback<? extends BaseProvider>> PROVIDERS = new HashMap<>();
public static Map<Class<? extends BaseProvider>, String> PROVIDER_NAMES = new HashMap<>();
public static Map<Class<? extends BaseProvider>, Integer> COLOR_MAP = new HashMap<>();
@Override
public void onInitialize() {
System.out.println("YNet loading up!");
register("ynet:item", ItemProvider.class, DefaultListeners::handleItemChannel);
if (FabricLoader.getInstance().isModLoaded("techreborn")){
// Enable energy
register("ynet:energy", EnergyProvider.class, DefaultListeners::handleEnergyChannel);
}
register("ynet:item", 0xff489030, ItemProvider.class, new ItemTickCallback());
register("ynet:fluid", 0xff0077be, FluidProvider.class, new FluidTickCallback());
register("ynet:energy", 0xfffffe00, EnergyProvider.class, new EnergyTickCallback());
// TODO:
// - Add support for configuring redstone signals on connectors
// - Add support for configuring redstone signals on connectorss
ContainerProviderRegistry.INSTANCE.registerFactory(new Identifier("ynet:controller"), (syncId, id, player, buf) -> {
return new ControllerContainer(syncId, player.inventory, buf);
});
}
static <T extends Block> T register(String name, T block) {
@ -91,9 +88,10 @@ public class YNetMod implements ModInitializer { @@ -91,9 +88,10 @@ public class YNetMod implements ModInitializer {
return Registry.register(Registry.ITEM, new Identifier("ynet", name), item);
}
static <T extends BaseProvider> ProviderTickCallback<T> register(String name, Class<T> clazz, ProviderTickCallback<T> callback) {
PROVIDER_NAMES.put(clazz, name);
static <T extends BaseProvider> ProviderTickCallback<T> register(String name, int color, Class<T> clazz, ProviderTickCallback<T> callback) {
PROVIDER_NAMES.put(clazz, name.replace(":", "."));
PROVIDERS.put(clazz, callback);
COLOR_MAP.put(clazz, color);
return callback;
}
}

16
src/main/java/com/martmists/ynet/YNetModClient.java

@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
package com.martmists.ynet;
import com.martmists.ynet.screens.ControllerScreen;
import com.martmists.ynet.containers.ControllerContainer;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.screen.ScreenProviderRegistry;
import net.minecraft.util.Identifier;
public class YNetModClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
ScreenProviderRegistry.INSTANCE.registerFactory(new Identifier("ynet:controller"), (c) -> {
return new ControllerScreen((ControllerContainer) c);
});
}
}

13
src/main/java/com/martmists/ynet/api/FluidProvider.java

@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
package com.martmists.ynet.api;
import net.minecraft.fluid.Fluid;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
public interface FluidProvider extends BaseProvider {
int getFluidOutputCount(BlockView world, BlockPos pos);
Fluid getFluidOutput(BlockView world, BlockPos pos);
int getFluidInputCount(BlockView world, BlockPos pos, Fluid fluid);
void outputFluid(BlockView world, BlockPos pos, Fluid fluid, int amount);
void inputFluid(BlockView world, BlockPos pos, Fluid fluid, int amount);
}

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

@ -2,20 +2,14 @@ package com.martmists.ynet.blockentities; @@ -2,20 +2,14 @@ package com.martmists.ynet.blockentities;
import com.martmists.ynet.YNetMod;
import com.martmists.ynet.api.BaseProvider;
import com.martmists.ynet.blocks.CableBlock;
import com.martmists.ynet.blocks.ConnectorBlock;
import com.martmists.ynet.event.ProviderTickCallback;
import com.martmists.ynet.network.Channel;
import com.martmists.ynet.network.Network;
import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.Tickable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import java.lang.reflect.Array;
import java.util.*;
import java.util.stream.Collectors;
public class ControllerBlockEntity extends BlockEntity implements Tickable {
public Network network;
@ -49,10 +43,10 @@ public class ControllerBlockEntity extends BlockEntity implements Tickable { @@ -49,10 +43,10 @@ public class ControllerBlockEntity extends BlockEntity implements Tickable {
network.setController(pos);
updateNetwork();
}
Set<BlockPos> blocks = network.getProviders(world);
for (Channel ch : channels) {
if (ch != null) {
YNetMod.PROVIDERS.get(ch.providerType).interact(ch.connectorSettings, this);
if (ch != null && ch.providerType != null) {
ProviderTickCallback<?> callback = YNetMod.PROVIDERS.get(ch.providerType);
callback.interact(ch.connectorSettings, this);
}
}
}

9
src/main/java/com/martmists/ynet/blocks/ControllerBlock.java

@ -1,7 +1,9 @@ @@ -1,7 +1,9 @@
package com.martmists.ynet.blocks;
import com.martmists.ynet.YNetModClient;
import com.martmists.ynet.api.BaseProvider;
import com.martmists.ynet.blockentities.ControllerBlockEntity;
import net.fabricmc.fabric.api.container.ContainerProviderRegistry;
import net.minecraft.block.BlockState;
import net.minecraft.block.BlockWithEntity;
import net.minecraft.block.entity.BlockEntity;
@ -10,6 +12,7 @@ import net.minecraft.entity.player.PlayerEntity; @@ -10,6 +12,7 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
@ -41,6 +44,12 @@ public class ControllerBlock extends BlockWithEntity { @@ -41,6 +44,12 @@ public class ControllerBlock extends BlockWithEntity {
System.out.println("End of list");
}
if (!world.isClient) {
ContainerProviderRegistry.INSTANCE.openContainer(new Identifier("ynet:controller"), player, (buffer) -> {
buffer.writeBlockPos(pos);
});
}
return ActionResult.SUCCESS;
}
}

21
src/main/java/com/martmists/ynet/containers/ControllerContainer.java

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
package com.martmists.ynet.containers;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.PacketByteBuf;
import spinnery.common.BaseContainer;
import spinnery.widget.WInterface;
import spinnery.widget.WSlot;
public class ControllerContainer extends BaseContainer {
public PlayerInventory playerInv;
public PacketByteBuf packet;
public ControllerContainer(int synchronizationID, PlayerInventory linkedPlayerInventory, PacketByteBuf packet) {
super(synchronizationID, linkedPlayerInventory);
playerInv = linkedPlayerInventory;
this.packet = packet;
WInterface mainInterface = getInterface();
WSlot.addHeadlessPlayerInventory(mainInterface);
}
}

68
src/main/java/com/martmists/ynet/event/impl/EnergyTickCallback.java

@ -0,0 +1,68 @@ @@ -0,0 +1,68 @@
package com.martmists.ynet.event.impl;
import com.martmists.ynet.api.EnergyProvider;
import com.martmists.ynet.blockentities.ControllerBlockEntity;
import com.martmists.ynet.event.ProviderTickCallback;
import com.martmists.ynet.network.ConnectorConfiguration;
import net.minecraft.world.World;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class EnergyTickCallback implements ProviderTickCallback<EnergyProvider> {
@Override
public void interact(Set<ConnectorConfiguration> listeners, ControllerBlockEntity be) {
World world = be.getWorld();
List<ConnectorConfiguration> takeEnergy = listeners.stream()
.filter(config -> config.state == ConnectorConfiguration.State.INPUT)
.sorted((a, b) -> a.priority >= b.priority ? 0 : 1)
.collect(Collectors.toList());
List<ConnectorConfiguration> giveEnergy = listeners.stream()
.filter(config -> config.state == ConnectorConfiguration.State.OUTPUT)
.sorted((a, b) -> a.priority >= b.priority ? 0 : 1)
.collect(Collectors.toList());
double lastStored = 0.0;
double lastTaken = 0.0;
while (!takeEnergy.isEmpty() && !giveEnergy.isEmpty()) {
ConnectorConfiguration receiverConfig = takeEnergy.get(0);
ConnectorConfiguration providerConfig = giveEnergy.get(0);
EnergyProvider receiver = (EnergyProvider) world.getBlockState(receiverConfig.providerPos).getBlock();
EnergyProvider provider = (EnergyProvider) world.getBlockState(providerConfig.providerPos).getBlock();
if (lastStored >= receiver.getEnergyInputLimit(world, receiverConfig.providerPos)) {
lastStored = 0.0;
try {
receiverConfig = takeEnergy.get(1);
} catch (IndexOutOfBoundsException exc) {
break;
}
receiver = (EnergyProvider) world.getBlockState(receiverConfig.providerPos);
takeEnergy.remove(0);
}
if (lastTaken >= provider.getEnergyOutputLimit(world, providerConfig.providerPos)) {
lastTaken = 0.0;
try {
providerConfig = giveEnergy.get(1);
} catch (IndexOutOfBoundsException exc) {
break;
}
provider = (EnergyProvider) world.getBlockState(providerConfig.providerPos);
giveEnergy.remove(0);
}
double toTransfer = Math.min(
receiver.getEnergyInputLimit(world, receiverConfig.providerPos),
provider.getEnergyOutputLimit(world, providerConfig.providerPos));
provider.outputEnergy(world, providerConfig.providerPos, toTransfer);
receiver.inputEnergy(world, receiverConfig.providerPos, toTransfer);
lastStored += toTransfer;
lastTaken += toTransfer;
}
}
}

113
src/main/java/com/martmists/ynet/event/impl/FluidTickCallback.java

@ -0,0 +1,113 @@ @@ -0,0 +1,113 @@
package com.martmists.ynet.event.impl;
import com.martmists.ynet.api.FluidProvider;
import com.martmists.ynet.api.ItemProvider;
import com.martmists.ynet.blockentities.ControllerBlockEntity;
import com.martmists.ynet.event.ProviderTickCallback;
import com.martmists.ynet.network.ConnectorConfiguration;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import java.util.*;
import java.util.stream.Collectors;
public class FluidTickCallback implements ProviderTickCallback<FluidProvider> {
@Override
public void interact(Set<ConnectorConfiguration> listeners, ControllerBlockEntity be) {
// Simple tuple class
class Entry {
private final BlockPos pos;
private final FluidProvider provider;
private final Fluid fluid;
private int amount;
Entry(BlockPos pos, FluidProvider provider, Fluid fluid, int amount) {
this.pos = pos;
this.provider = provider;
this.fluid = fluid;
this.amount = amount;
}
}
World world = be.getWorld();
List<ConnectorConfiguration> takeItems = listeners.stream()
.filter(config -> config.state == ConnectorConfiguration.State.INPUT)
.sorted((a, b) -> a.priority >= b.priority ? 0 : 1)
.collect(Collectors.toList());
List<Entry> entries = new ArrayList<>();
listeners.stream()
.filter(config -> config.state == ConnectorConfiguration.State.OUTPUT)
.sorted((a, b) -> a.priority >= b.priority ? 0 : 1)
.forEach(config -> {
FluidProvider p = (FluidProvider) world.getBlockState(config.providerPos).getBlock();
Fluid f = p.getFluidOutput(world, config.providerPos);
if (f != Fluids.EMPTY) {
entries.add(new Entry(config.providerPos, p, f, p.getFluidOutputCount(world, config.providerPos)));
}
});
if (entries.isEmpty()) {
return;
}
Entry e = entries.get(0);
Map<FluidProvider, Integer> fluidsStored = new HashMap<>();
Map<FluidProvider, Integer> fluidsRemoved = new HashMap<>();
while (!entries.isEmpty()) {
if (e.amount <= 0){
try {
e = entries.get(1);
} catch (IndexOutOfBoundsException exc) {
break;
}
entries.remove(0);
}
fluidsRemoved.putIfAbsent(e.provider, 0);
if (fluidsRemoved.get(e.provider) >= 1000) {
e.amount = 0;
continue;
}
boolean found = false;
for (ConnectorConfiguration receiverConfig : takeItems){
FluidProvider receiver = (FluidProvider) world.getBlockState(receiverConfig.providerPos).getBlock();
fluidsStored.putIfAbsent(receiver, 0);
int count = Math.min(
receiver.getFluidInputCount(world, receiverConfig.providerPos, e.fluid),
Math.min(
1000 - fluidsStored.get(receiver),
1000 - fluidsRemoved.get(e.provider)));
if (receiverConfig.filter != null) {
Entry fe = e;
if (Arrays.stream(receiverConfig.filter).noneMatch((obj) -> obj == fe.fluid)){
continue;
}
}
if (count > 0){
fluidsStored.put(receiver, fluidsStored.get(receiver) + count);
fluidsRemoved.put(e.provider, fluidsRemoved.get(e.provider) + count);
int finalCount = e.amount - count;
e.amount = count;
e.provider.outputFluid(world, e.pos, e.fluid, e.amount);
receiver.inputFluid(world, e.pos, e.fluid, e.amount);
e.amount = finalCount;
found = true;
}
}
if (!found) {
// Remove next
e.amount = 0;
}
}
}
}

68
src/main/java/com/martmists/ynet/event/DefaultListeners.java → src/main/java/com/martmists/ynet/event/impl/ItemTickCallback.java

@ -1,8 +1,9 @@ @@ -1,8 +1,9 @@
package com.martmists.ynet.event;
package com.martmists.ynet.event.impl;
import com.martmists.ynet.api.EnergyProvider;
import com.martmists.ynet.api.ItemProvider;
import com.martmists.ynet.blockentities.ControllerBlockEntity;
import com.martmists.ynet.event.ProviderTickCallback;
import com.martmists.ynet.network.ConnectorConfiguration;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
@ -11,62 +12,9 @@ import net.minecraft.world.World; @@ -11,62 +12,9 @@ import net.minecraft.world.World;
import java.util.*;
import java.util.stream.Collectors;
public class DefaultListeners {
public static void handleEnergyChannel(Set<ConnectorConfiguration> listeners, ControllerBlockEntity be) {
World world = be.getWorld();
List<ConnectorConfiguration> takeEnergy = listeners.stream()
.filter(config -> config.state == ConnectorConfiguration.State.INPUT)
.sorted((a, b) -> a.priority >= b.priority ? 0 : 1)
.collect(Collectors.toList());
List<ConnectorConfiguration> giveEnergy = listeners.stream()
.filter(config -> config.state == ConnectorConfiguration.State.OUTPUT)
.sorted((a, b) -> a.priority >= b.priority ? 0 : 1)
.collect(Collectors.toList());
double lastStored = 0.0;
double lastTaken = 0.0;
while (!takeEnergy.isEmpty() && !giveEnergy.isEmpty()) {
ConnectorConfiguration receiverConfig = takeEnergy.get(0);
ConnectorConfiguration providerConfig = giveEnergy.get(0);
EnergyProvider receiver = (EnergyProvider) world.getBlockState(receiverConfig.providerPos);
EnergyProvider provider = (EnergyProvider) world.getBlockState(providerConfig.providerPos);
if (lastStored >= receiver.getEnergyInputLimit(world, receiverConfig.providerPos)) {
lastStored = 0.0;
try {
receiverConfig = takeEnergy.get(1);
} catch (IndexOutOfBoundsException exc) {
break;
}
receiver = (EnergyProvider) world.getBlockState(receiverConfig.providerPos);
takeEnergy.remove(0);
}
if (lastTaken >= provider.getEnergyOutputLimit(world, providerConfig.providerPos)) {
lastTaken = 0.0;
try {
providerConfig = giveEnergy.get(1);
} catch (IndexOutOfBoundsException exc) {
break;
}
provider = (EnergyProvider) world.getBlockState(providerConfig.providerPos);
giveEnergy.remove(0);
}
double toTransfer = Math.min(
receiver.getEnergyInputLimit(world, receiverConfig.providerPos),
provider.getEnergyOutputLimit(world, providerConfig.providerPos));
provider.outputEnergy(world, providerConfig.providerPos, toTransfer);
receiver.inputEnergy(world, receiverConfig.providerPos, toTransfer);
lastStored += toTransfer;
lastTaken += toTransfer;
}
}
public static void handleItemChannel(Set<ConnectorConfiguration> listeners, ControllerBlockEntity be) {
public class ItemTickCallback implements ProviderTickCallback<ItemProvider> {
@Override
public void interact(Set<ConnectorConfiguration> listeners, ControllerBlockEntity be) {
// Simple tuple class
class Entry {
private final BlockPos pos;
@ -90,7 +38,7 @@ public class DefaultListeners { @@ -90,7 +38,7 @@ public class DefaultListeners {
.filter(config -> config.state == ConnectorConfiguration.State.OUTPUT)
.sorted((a, b) -> a.priority >= b.priority ? 0 : 1)
.forEach(config -> {
ItemProvider p = (ItemProvider) world.getBlockState(config.providerPos);
ItemProvider p = (ItemProvider) world.getBlockState(config.providerPos).getBlock();
for (ItemStack s : p.getItemOutputStacks(world, config.providerPos)){
entries.add(new Entry(config.providerPos, p, s));
}
@ -124,7 +72,7 @@ public class DefaultListeners { @@ -124,7 +72,7 @@ public class DefaultListeners {
boolean found = false;
for (ConnectorConfiguration receiverConfig : takeItems){
ItemProvider receiver = (ItemProvider) world.getBlockState(receiverConfig.providerPos);
ItemProvider receiver = (ItemProvider) world.getBlockState(receiverConfig.providerPos).getBlock();
itemsStored.putIfAbsent(receiver, 0);
int count = Math.min(
receiver.getItemInputCount(world, receiverConfig.providerPos, e.items),
@ -134,7 +82,7 @@ public class DefaultListeners { @@ -134,7 +82,7 @@ public class DefaultListeners {
if (receiverConfig.filter != null) {
Entry fe = e;
if (Arrays.stream(receiverConfig.filter).noneMatch((item) -> item == fe.items.getItem())){
if (Arrays.stream(receiverConfig.filter).noneMatch((obj) -> obj == fe.items.getItem())){
continue;
}
}

37
src/main/java/com/martmists/ynet/mixin/providers/fluid/BlockMachineBaseMixin.java

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
package com.martmists.ynet.mixin.providers.fluid;
import com.martmists.ynet.api.FluidProvider;
import net.minecraft.fluid.Fluid;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import org.spongepowered.asm.mixin.Mixin;
import reborncore.common.blocks.BlockMachineBase;
@Mixin(BlockMachineBase.class)
public class BlockMachineBaseMixin implements FluidProvider {
@Override
public int getFluidOutputCount(BlockView world, BlockPos pos) {
return 0;
}
@Override
public Fluid getFluidOutput(BlockView world, BlockPos pos) {
return null;
}
@Override
public int getFluidInputCount(BlockView world, BlockPos pos, Fluid fluid) {
return 0;
}
@Override
public void outputFluid(BlockView world, BlockPos pos, Fluid fluid, int amount) {
}
@Override
public void inputFluid(BlockView world, BlockPos pos, Fluid fluid, int amount) {
}
}

6
src/main/java/com/martmists/ynet/network/Channel.java

@ -2,9 +2,15 @@ package com.martmists.ynet.network; @@ -2,9 +2,15 @@ package com.martmists.ynet.network;
import com.martmists.ynet.api.BaseProvider;
import java.util.HashSet;
import java.util.Set;
public class Channel {
public Class<? extends BaseProvider> providerType;
public Set<ConnectorConfiguration> connectorSettings;
public Channel() {
providerType = BaseProvider.class;
connectorSettings = new HashSet<>();
}
}

14
src/main/java/com/martmists/ynet/network/ConnectorConfiguration.java

@ -1,17 +1,21 @@ @@ -1,17 +1,21 @@
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 ConnectorConfiguration() {
state = State.DISABLED;
priority = 0;
}
public State state;
public BlockPos providerPos;
public int priority;
// For items
public Item[] filter;
// For items/fluids/etc
public Object[] filter;
public static enum State {
public enum State {
DISABLED,
INPUT,
OUTPUT

251
src/main/java/com/martmists/ynet/screens/ControllerScreen.java

@ -0,0 +1,251 @@ @@ -0,0 +1,251 @@
package com.martmists.ynet.screens;
import com.martmists.ynet.YNetMod;
import com.martmists.ynet.api.BaseProvider;
import com.martmists.ynet.blockentities.ControllerBlockEntity;
import com.martmists.ynet.containers.ControllerContainer;
import com.martmists.ynet.network.Channel;
import com.martmists.ynet.network.ConnectorConfiguration;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.text.LiteralText;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.math.BlockPos;
import spinnery.client.BaseRenderer;
import spinnery.common.BaseContainerScreen;
import spinnery.widget.*;
import spinnery.widget.api.Position;
import spinnery.widget.api.Size;
import spinnery.widget.api.WVerticalScrollable;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class ControllerScreen extends BaseContainerScreen<ControllerContainer> {
private final ControllerBlockEntity sourceBlockEntity;
private int channelNum;
private Channel currentChannel;
private ConnectorConfiguration currentConfig;
private WButton[] channelButtons = new WButton[9];
private WButton configButtonClicked;
private static List<Class<? extends BaseProvider>> TYPE_LOOP = new ArrayList<>(YNetMod.PROVIDER_NAMES.keySet());
static {
TYPE_LOOP.add(null);
}
public ControllerScreen(ControllerContainer linkedContainer) {
super(new LiteralText(""), linkedContainer, linkedContainer.getPlayerInventory().player);
PlayerEntity player = linkedContainer.getPlayerInventory().player;
this.sourceBlockEntity = (ControllerBlockEntity) player.world.getBlockEntity(linkedContainer.packet.readBlockPos());
assert sourceBlockEntity != null;
WInterface mainInterface = getInterface();
WPanel mainPanel = mainInterface.createChild(
WPanel.class,
Position.of(0, 0, 0),
Size.of(320, 155)
);
mainPanel.center();
WPanel channelSettingsPanel = mainPanel.createChild(
WPanel.class,
Position.of(mainPanel, 169, 5, 100),
Size.of(145, 73)
);
channelNum = 0;
currentChannel = sourceBlockEntity.channels[0];
channelSettingsPanel.setLabel("Channel 1");
channelSettingsPanel.createChild(
WStaticText.class,
Position.of(channelSettingsPanel, 4, 22),
Size.of(2, 20)
).setText("Mode:");
WButton channelTypeButton = channelSettingsPanel.createChild(
WButton.class,
Position.of(channelSettingsPanel, 40, 20),
Size.of(100, 14)
);
channelTypeButton.setLabel("Disabled");
channelTypeButton.setOnMouseClicked((WButton w, int mouseX, int mouseY, int mouseButton) -> {
if (channelSettingsPanel.getZ() != 100){
return;
}
int currentIndex = TYPE_LOOP.indexOf((currentChannel != null) ? currentChannel.providerType : null);
Class<? extends BaseProvider> nextType;
try {
nextType = TYPE_LOOP.get(currentIndex + ((mouseButton == 0) ? 1 : -1));
} catch (IndexOutOfBoundsException e) {
nextType = TYPE_LOOP.get((mouseButton == 0) ? 0 : TYPE_LOOP.size()-1);
}
if (TYPE_LOOP.get(currentIndex) == null) {
currentChannel = new Channel();
}
currentChannel.providerType = nextType;
sourceBlockEntity.channels[channelNum] = currentChannel;
if (nextType == null) {
currentChannel = null;
channelButtons[channelNum].overrideStyle("background.on", 0xff8b8b8b);
channelButtons[channelNum].overrideStyle("background.off", 0xff8b8b8b);
} else {
channelButtons[channelNum].overrideStyle("background.on", YNetMod.COLOR_MAP.get(nextType));
channelButtons[channelNum].overrideStyle("background.off", YNetMod.COLOR_MAP.get(nextType));
}
channelTypeButton.setLabel(YNetMod.PROVIDER_NAMES.getOrDefault(nextType, "Disabled"));
});
WPanel connectorSettingsPanel = mainPanel.createChild(
WPanel.class,
Position.of(mainPanel, 169, 5, 0),
Size.of(145, 73)
);
connectorSettingsPanel.setLabel("Connector settings");
connectorSettingsPanel.createChild(
WStaticText.class,
Position.of(connectorSettingsPanel, 4, 22),
Size.of(2, 20)
).setText("Mode:");
WButton stateButton = connectorSettingsPanel.createChild(
WButton.class,
Position.of(connectorSettingsPanel, 40, 20),
Size.of(100, 14)
);
stateButton.setOnMouseClicked((WButton w, int mouseX, int mouseY, int mouseButton) -> {
if (connectorSettingsPanel.getZ() != 100){
return;
}
ConnectorConfiguration.State nextState;
switch (currentConfig.state) {
case DISABLED:
nextState = ConnectorConfiguration.State.INPUT;
break;
case INPUT:
nextState = ConnectorConfiguration.State.OUTPUT;
break;
case OUTPUT:
nextState = ConnectorConfiguration.State.DISABLED;
break;
default:
throw new IllegalStateException("Unexpected value: " + currentConfig.state);
}
currentConfig.state = nextState;
stateButton.setLabel(nextState.name());
if (currentConfig.state != ConnectorConfiguration.State.DISABLED) {
configButtonClicked.setLabel((currentConfig.state == ConnectorConfiguration.State.INPUT) ? "I" : "O");
int inputColor = 0xff0077be;
int outputColor = 0xffffcc99;
configButtonClicked.overrideStyle("background.on", (currentConfig.state == ConnectorConfiguration.State.INPUT) ? inputColor : outputColor);
configButtonClicked.overrideStyle("background.off", (currentConfig.state == ConnectorConfiguration.State.INPUT) ? inputColor : outputColor);
} else {
configButtonClicked.overrideStyle("background.on", 0xff8b8b8b);
configButtonClicked.overrideStyle("background.off", 0xff8b8b8b);
}
});
for (int i = 0; i < 9; i++){
int f = i;
WButton button = mainPanel.createChild(
WButton.class,
Position.of(mainPanel, 25 + 14*i, 5),
Size.of(12, 14)
);
channelButtons[f] = button;
button.setLabel(Integer.toString(i+1));
button.setOnMouseClicked((WButton widget, int mouseX, int mouseY, int mouseButton) -> {
currentChannel = sourceBlockEntity.channels[f];
connectorSettingsPanel.setZ(0);
channelSettingsPanel.setZ(100);
channelNum = f;
channelSettingsPanel.setLabel("Channel " + (f + 1));
if (currentChannel != null) {
channelTypeButton.setLabel(new TranslatableText(YNetMod.PROVIDER_NAMES.get(currentChannel.providerType)));
}
});
if (sourceBlockEntity.channels[i] != null) {
button.overrideStyle("background.on", YNetMod.COLOR_MAP.get(sourceBlockEntity.channels[i].providerType));
button.overrideStyle("background.off", YNetMod.COLOR_MAP.get(sourceBlockEntity.channels[i].providerType));
}
}
WVerticalScrollableContainer blockList = mainPanel.createChild(
WVerticalScrollableContainer.class,
Position.of(mainPanel, 4, 20),
Size.of(163, 130)
);
Set<BlockPos> blocksToShow = sourceBlockEntity.network.getProviders(player.world);
int i = 0;
for (BlockPos p : blocksToShow) {
WPanel row = blockList.createChild(
WPanel.class,
Position.of(blockList, 0, 26*i),
Size.of(154, 25)
);
i++;
WItem item = row.createChild(
WItem.class,
Position.of(row, 4, 4),
Size.of(16, 16)
);
item.setItemStack(new ItemStack(player.world.getBlockState(p).getBlock().asItem()));
for (int j = 0; j < 9; j++){
int k = j;
WButton button = row.createChild(
WButton.class,
Position.of(row, 21 + 14*j, 5),
Size.of(12, 14)
);
// Get configuration for block in channel
Channel channel = sourceBlockEntity.channels[j];
if (channel != null) {
ConnectorConfiguration config = channel.connectorSettings.stream().filter((s) -> s.providerPos == p).findFirst().orElse(null);
if (config == null) {
config = new ConnectorConfiguration();
config.providerPos = p;
channel.connectorSettings.add(config);
}
if (config.state != ConnectorConfiguration.State.DISABLED) {
button.setLabel((config.state == ConnectorConfiguration.State.INPUT) ? "I" : "O");
int inputColor = 0xff0077be;
int outputColor = 0xffffcc99;
button.overrideStyle("background.on", (config.state == ConnectorConfiguration.State.INPUT) ? inputColor : outputColor);
button.overrideStyle("background.off", (config.state == ConnectorConfiguration.State.INPUT) ? inputColor : outputColor);
} else {
button.overrideStyle("background.on", 0xff8b8b8b);
button.overrideStyle("background.off", 0xff8b8b8b);
}
}
button.setOnMouseClicked((WButton widget, int mouseX, int mouseY, int mouseButton) -> {
if (sourceBlockEntity.channels[k] != null) {
currentConfig = sourceBlockEntity.channels[k].connectorSettings.stream().filter((s) -> s.providerPos == p).findFirst().orElse(null);
if (currentConfig == null) {
currentConfig = new ConnectorConfiguration();
currentConfig.providerPos = p;
sourceBlockEntity.channels[k].connectorSettings.add(currentConfig);
}
stateButton.setLabel(currentConfig.state.name());
connectorSettingsPanel.setZ(100);
channelSettingsPanel.setZ(0);
configButtonClicked = button;
}
});
}
}
WSlot.addPlayerInventory(Position.of(mainPanel, 170, 83, 1), Size.of(16, 16), mainInterface);
}
}

17
src/main/java/spinnery/widget/WItem.java

@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
package spinnery.widget;
import net.minecraft.item.ItemStack;
import spinnery.client.BaseRenderer;
public class WItem extends WAbstractWidget {
private ItemStack itemStack;
@Override
public void draw() {
BaseRenderer.getItemRenderer().renderGuiItem(itemStack, getX(), getY());
}
public void setItemStack(ItemStack itemStack) {
this.itemStack = itemStack;
}
}

4
src/main/resources/assets/ynet/models/block/cable.json

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
{
"parent": "block/block",
"credit": "Made with Blockbench",
"ambientocclusion": false,
"textures": {
@ -19,6 +20,5 @@ @@ -19,6 +20,5 @@
"down": {"uv": [0, 0, 6, 6], "texture": "#0"}
}
}
],
"display": {}
]
}

1
src/main/resources/assets/ynet/models/block/connector.json

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
{
"parent": "block/block",
"credit": "Made with Blockbench",
"ambientocclusion": false,
"textures": {

21
src/main/resources/assets/ynet/models/item/cable.json

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
{
"parent": "ynet:block/cable",
"display": {
"thirdperson_righthand": {
"scale": [0.5, 0.5, 0.5]
},
"thirdperson_lefthand": {
"scale": [0.5, 0.5, 0.5]
},
"firstperson_righthand": {
"scale": [0.5, 0.5, 0.5]
},
"firstperson_lefthand": {
"scale": [0.5, 0.5, 0.5]
},
"gui": {
"rotation": [30, -135, 0],
"scale": [1.5, 1.5, 1.5]
}
}
}

33
src/main/resources/assets/ynet/models/item/connector.json

@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
{
"parent": "ynet:block/connector",
"display": {
"thirdperson_righthand": {
"rotation": [-180, 0, 0],
"translation": [0, -2.5, 0],
"scale": [0.5, 0.5, 0.5]
},
"thirdperson_lefthand": {
"rotation": [-180, 0, 0],
"translation": [0, -2.5, 0],
"scale": [0.5, 0.5, 0.5]
},
"firstperson_righthand": {
"rotation": [-180, 0, 0],
"translation": [0, -2.5, 0],
"scale": [0.5, 0.5, 0.5]
},
"firstperson_lefthand": {
"rotation": [-180, 0, 0],
"translation": [0, -2.5, 0],
"scale": [0.5, 0.5, 0.5]
},
"ground": {
"rotation": [90, 0, 0],
"translation": [0, 0, 5]
},
"gui": {
"rotation": [30, -135, 90],
"translation": [4, 2, 0]
}
}
}

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

@ -12,6 +12,9 @@ @@ -12,6 +12,9 @@
"entrypoints": {
"main": [
"com.martmists.ynet.YNetMod"
],
"client": [
"com.martmists.ynet.YNetModClient"
]
},
"mixins": [

3
versions/1.15.2/gradle.properties

@ -2,4 +2,5 @@ minecraft_version=1.15.2 @@ -2,4 +2,5 @@ minecraft_version=1.15.2
yarn_mappings=1.15.2+build.14
loader_version=0.7.8+build.184
fabric_version=0.4.32+build.292-1.15
tr_slug=TechReborn-1.15:3.3.4+build.193
tr_slug=TechReborn-1.15:3.3.4+build.193
spinnery_version=2.0.18+fabric-1.15

1
versions/1.16/gradle.properties

@ -3,3 +3,4 @@ yarn_mappings=20w10a+build.2 @@ -3,3 +3,4 @@ yarn_mappings=20w10a+build.2
loader_version=0.7.8+build.186
fabric_version=0.4.34+build.303-1.16
tr_slug=TechReborn-1.16:3.3.3+build.3
spinnery_version=2.0.18+fabric-20w06a

7
versions/common.gradle

@ -11,7 +11,8 @@ dependencies { @@ -11,7 +11,8 @@ dependencies {
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modCompile "TechReborn:${project.tr_slug}"
modCompileOnly "TechReborn:${project.tr_slug}"
modImplementation "com.github.vini2003:spinnery:${project.spinnery_version}"
}
repositories {
@ -19,6 +20,10 @@ repositories { @@ -19,6 +20,10 @@ repositories {
name = "TechReborn"
url = "https://maven.fabricmc.net/"
}
maven {
name = "Spinnery"
url "https://dl.bintray.com/spinnery/Spinnery"
}
}
processResources {

Loading…
Cancel
Save