Skip to content

Commit

Permalink
-Added support for The One Probe and HWYLA.
Browse files Browse the repository at this point in the history
-Fixed sync bug with tiny transmitters and receivers where a channel change would not sync to client if change did not result in an output change.
  • Loading branch information
dannydjdk committed Sep 27, 2021
1 parent 4d0ac5d commit f1dc269
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 5 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ dependencies {

implementation fg.deobf("curse.maven:theoneprobe-245211:${theOneProbeFileID}")
implementation fg.deobf("curse.maven:jei-238222:${jeiFileID}")
implementation fg.deobf('curse.maven:jade-324717:3447700')

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dannyandson.rangedwirelessredstone;

import com.dannyandson.rangedwirelessredstone.compat.CompatHandler;
import com.dannyandson.rangedwirelessredstone.setup.ClientSetup;
import com.dannyandson.rangedwirelessredstone.setup.Registration;
import com.dannyandson.rangedwirelessredstone.setup.ModSetup;
Expand Down Expand Up @@ -40,6 +41,8 @@ public RangedWirelessRedstone() {

// Register ourselves for server and other game events we are interested in
MinecraftForge.EVENT_BUS.register(this);

CompatHandler.register();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import com.dannyandson.rangedwirelessredstone.gui.ChannelSelectGUI;
import com.dannyandson.rangedwirelessredstone.logic.IWirelessComponent;
import com.dannyandson.rangedwirelessredstone.network.ModNetworkHandler;
import com.dannyandson.tinyredstone.api.IOverlayBlockInfo;
import com.dannyandson.tinyredstone.api.IPanelCell;
import com.dannyandson.tinyredstone.api.IPanelCellInfoProvider;
import com.dannyandson.tinyredstone.blocks.*;
import com.dannyandson.tinyredstone.network.PanelCellSync;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.player.Player;
Expand Down Expand Up @@ -52,9 +54,7 @@ public PanelCellVoxelShape getShape() {

@Override
public void addInfo(IOverlayBlockInfo overlayBlockInfo, PanelTile panelTile, PosInPanelCell posInPanelCell) {
overlayBlockInfo.addText("Signal", this.signal + "");
overlayBlockInfo.addText("Channel", this.channel + "");
//overlayBlockInfo.setPowerOutput(0);
}

@Override
Expand All @@ -75,6 +75,8 @@ public int getChannel() {
@Override
public void setChannel(int channel) {
this.channel = channel;
if (panelCellPos!=null && !panelCellPos.getPanelTile().getLevel().isClientSide)
ModNetworkHandler.sendToClient(new PanelCellSync(panelCellPos.getPanelTile().getBlockPos(), panelCellPos.getIndex(), writeNBT()), panelCellPos.getPanelTile());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import com.dannyandson.rangedwirelessredstone.RenderHelper;
import com.dannyandson.rangedwirelessredstone.logic.ChannelData;
import com.dannyandson.tinyredstone.blocks.PanelCellNeighbor;
import com.dannyandson.tinyredstone.blocks.PanelCellPos;
import com.dannyandson.tinyredstone.blocks.Side;
import com.dannyandson.tinyredstone.api.IOverlayBlockInfo;
import com.dannyandson.tinyredstone.blocks.*;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Vector3f;
Expand Down Expand Up @@ -131,4 +130,11 @@ public void onRemove(PanelCellPos cellPos) {
if (cellPos.getPanelTile().getLevel() instanceof ServerLevel serverLevel)
ChannelData.getChannelData(serverLevel).removeTransmitter(cellPos.getPanelTile().getBlockPos(), cellPos.getIndex());
}

@Override
public void addInfo(IOverlayBlockInfo overlayBlockInfo, PanelTile panelTile, PosInPanelCell posInPanelCell) {
overlayBlockInfo.addText("Signal", this.getSignal() + "");
super.addInfo(overlayBlockInfo, panelTile, posInPanelCell);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.dannyandson.rangedwirelessredstone.compat;

import com.dannyandson.rangedwirelessredstone.compat.theoneprobe.InfoProvider;
import net.minecraftforge.fml.InterModComms;
import net.minecraftforge.fml.ModList;

public class CompatHandler {
public static void register() {
if(ModList.get().isLoaded("theoneprobe")) {
InterModComms.sendTo("theoneprobe", "getTheOneProbe", InfoProvider::new);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.dannyandson.rangedwirelessredstone.compat.hwyla;

import com.dannyandson.rangedwirelessredstone.RangedWirelessRedstone;
import com.dannyandson.rangedwirelessredstone.blocks.AbstractWirelessEntity;
import com.dannyandson.rangedwirelessredstone.blocks.ReceiverBlock;
import com.dannyandson.rangedwirelessredstone.blocks.TransmitterBlock;
import mcp.mobius.waila.api.*;
import mcp.mobius.waila.api.config.IPluginConfig;
import mcp.mobius.waila.api.ui.IElement;
import mcp.mobius.waila.api.ui.IElementHelper;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.entity.BlockEntity;

import java.util.ArrayList;
import java.util.List;

@WailaPlugin(RangedWirelessRedstone.MODID)
public class InfoProvider implements IWailaPlugin, IComponentProvider {
static final ResourceLocation RENDER_STRING = new ResourceLocation("string");
static final ResourceLocation RENDER_ITEM_INLINE = new ResourceLocation("item_inline");
static final ResourceLocation RENDER_INFO_STRING = new ResourceLocation("info_string");

@Override
public void register(IRegistrar registrar) {
registrar.registerComponentProvider(this, TooltipPosition.BODY, ReceiverBlock.class);
registrar.registerComponentProvider(this, TooltipPosition.BODY, TransmitterBlock.class);
}

@Override
public void appendTooltip(ITooltip tooltip, BlockAccessor accessor, IPluginConfig config) {
if(accessor.getBlock() != null) {
BlockPos pos = accessor.getPosition();
BlockEntity tileEntity = accessor.getLevel().getBlockEntity(pos);

if (tileEntity instanceof AbstractWirelessEntity wirelessEntity) {
IElementHelper helper = tooltip.getElementHelper();

List<IElement> elements = new ArrayList<>();
elements.add(helper.text(Component.nullToEmpty("Channel:")).tag(RENDER_STRING));
elements.add(helper.text(Component.nullToEmpty(" " + wirelessEntity.getChannel())).tag(RENDER_INFO_STRING));
elements.add(helper.text(Component.nullToEmpty(" Signal:")).tag(RENDER_STRING));
elements.add(helper.text(Component.nullToEmpty(" " + wirelessEntity.getSignal())).tag(RENDER_INFO_STRING));
tooltip.add(elements);

}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.dannyandson.rangedwirelessredstone.compat.theoneprobe;

import com.dannyandson.rangedwirelessredstone.RangedWirelessRedstone;
import com.dannyandson.rangedwirelessredstone.blocks.AbstractWirelessEntity;
import com.dannyandson.rangedwirelessredstone.blocks.TransmitterBlockEntity;
import mcjty.theoneprobe.api.*;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;

import java.util.function.Function;

public class InfoProvider implements IBlockDisplayOverride, Function<ITheOneProbe, Void>, IProbeInfoProvider {

@Override
public ResourceLocation getID() {
return new ResourceLocation(RangedWirelessRedstone.MODID , "wireless_block");
}

@Override
public Void apply(ITheOneProbe theOneProbe) {
theOneProbe.registerBlockDisplayOverride(this);
theOneProbe.registerProvider(this);
return null;
}

@Override
public void addProbeInfo(ProbeMode probeMode, IProbeInfo probeInfo, Player playerEntity, Level world, BlockState blockState, IProbeHitData probeHitData) {
BlockPos pos = probeHitData.getPos();
BlockEntity tileEntity = world.getBlockEntity(pos);

if (tileEntity instanceof AbstractWirelessEntity wirelessEntity) {
probeInfo.horizontal()
.text(CompoundText.createLabelInfo("Channel: ", wirelessEntity.getChannel()));
if (tileEntity instanceof TransmitterBlockEntity)
probeInfo.horizontal()
.text(CompoundText.createLabelInfo("Signal: ", wirelessEntity.getSignal()));
}
}

@Override
public boolean overrideStandardInfo(ProbeMode probeMode, IProbeInfo iProbeInfo, Player playerEntity, Level world, BlockState blockState, IProbeHitData iProbeHitData) {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.dannyandson.rangedwirelessredstone.network;

import com.dannyandson.rangedwirelessredstone.RangedWirelessRedstone;
import com.dannyandson.tinyredstone.blocks.PanelTile;
import com.dannyandson.tinyredstone.network.PanelCellSync;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.fmllegacy.network.NetworkDirection;
import net.minecraftforge.fmllegacy.network.NetworkRegistry;
import net.minecraftforge.fmllegacy.network.simple.SimpleChannel;
Expand Down Expand Up @@ -40,6 +44,12 @@ public static void registerMessages() {
.decoder(NetworkViewerTrigger::new)
.consumer(NetworkViewerTrigger::handle)
.add();

INSTANCE.messageBuilder(PanelCellSync.class,nextID())
.encoder(PanelCellSync::toBytes)
.decoder(PanelCellSync::new)
.consumer(PanelCellSync::handle)
.add();
}

public static void sendToServer(Object packet) {
Expand All @@ -48,4 +58,13 @@ public static void sendToServer(Object packet) {
public static void sendToClient(Object packet, ServerPlayer player) {
INSTANCE.sendTo(packet, player.connection.connection, NetworkDirection.PLAY_TO_CLIENT);
}

public static void sendToClient(Object packet, PanelTile panelTile) {
BlockPos pos = panelTile.getBlockPos();
for (Player player : panelTile.getLevel().players()) {
if (player instanceof ServerPlayer && player.distanceToSqr(pos.getX(),pos.getY(),pos.getZ()) < 64d) {
INSTANCE.sendTo(packet, ((ServerPlayer) player).connection.connection, NetworkDirection.PLAY_TO_CLIENT);
}
}
}
}

0 comments on commit f1dc269

Please sign in to comment.