Skip to content

Commit

Permalink
DEV-7!
Browse files Browse the repository at this point in the history
  • Loading branch information
strubium committed Jul 11, 2024
1 parent 7c7400b commit 8f07db3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 31 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ org.gradle.caching = true
org.gradle.daemon = true

modname=TheOneSmeagle
version=1.12-Dev-6
version=1.12-Dev-7
curse_type=release
projectId=245211
github_project=strubium/TheOneSmeagle
Expand Down
1 change: 1 addition & 0 deletions src/main/java/mcjty/theoneprobe/api/TextStyleClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public String getReadableName() {
/**
* Returns a string representation of the enum constant,
* formatted as "{=code=}".
*
* @return String representation of the enum constant.
*/
@Override
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/mcjty/theoneprobe/network/NetworkTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.math.BlockPos;

import javax.annotation.Nullable;
import java.io.IOException;
import java.util.Collection;
import java.util.Objects;
Expand Down Expand Up @@ -126,14 +127,14 @@ public static void writeString(ByteBuf dataOut, String str) {
* @return The String read from the buffer, or null if the length was -1, or an empty string if the length was 0.
*/
public static String readStringUTF8(ByteBuf dataIn) {
int s = dataIn.readInt();
if (s == -1) {
int length = dataIn.readInt();
if (length == -1) {
return null;
}
if (s == 0) {
if (length == 0) {
return "";
}
byte[] dst = new byte[s];
byte[] dst = new byte[length];
dataIn.readBytes(dst);
return new String(dst, java.nio.charset.StandardCharsets.UTF_8);
}
Expand Down Expand Up @@ -210,7 +211,7 @@ public static <T extends Enum<T>> T readEnum(ByteBuf buf, T[] values) {
* Writes a collection of enum values to the given ByteBuf.
*
* @param buf The ByteBuf to write to.
* @param collection The collection of enum values to write.
* @param collection A {@link Collection} of enum values to write.
* @param <T> The enum type.
*/
public static <T extends Enum<T>> void writeEnumCollection(ByteBuf buf, Collection<T> collection) {
Expand All @@ -224,7 +225,7 @@ public static <T extends Enum<T>> void writeEnumCollection(ByteBuf buf, Collecti
* Reads a collection of enum values from the given ByteBuf.
*
* @param buf The ByteBuf to read from.
* @param collection The collection to populate with the enum values.
* @param collection A {@link Collection} to populate with the enum values.
* @param values The array of possible enum values.
* @param <T> The enum type.
*/
Expand All @@ -240,12 +241,12 @@ public static <T extends Enum<T>> void readEnumCollection(ByteBuf buf, Collectio
* Writes a Float value to the given ByteBuf.
*
* @param buf The ByteBuf to write to.
* @param f The Float value to write, or null to indicate no value.
* @param value The Float value to write, or null to indicate no value.
*/
public static void writeFloat(ByteBuf buf, Float f) {
if (f != null) {
public static void writeFloat(ByteBuf buf, @Nullable Float value) {
if (value != null) {
buf.writeBoolean(true);
buf.writeFloat(f);
buf.writeFloat(value);
} else {
buf.writeBoolean(false);
}
Expand Down
28 changes: 8 additions & 20 deletions src/main/java/mcjty/theoneprobe/network/PacketGetEntityInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

import java.util.List;
import java.util.UUID;

import static mcjty.theoneprobe.api.TextStyleClass.ERROR;
Expand Down Expand Up @@ -50,18 +49,15 @@ public void toBytes(ByteBuf buf) {
buf.writeLong(uuid.getMostSignificantBits());
buf.writeLong(uuid.getLeastSignificantBits());
buf.writeByte(mode.ordinal());
if (hitVec == null) {
buf.writeBoolean(false);
} else {
buf.writeBoolean(true);
buf.writeBoolean(hitVec != null);
if (hitVec != null) {
buf.writeDouble(hitVec.x);
buf.writeDouble(hitVec.y);
buf.writeDouble(hitVec.z);
}
}

public PacketGetEntityInfo() {
}
public PacketGetEntityInfo() {}

public PacketGetEntityInfo(int dim, ProbeMode mode, RayTraceResult mouseOver, Entity entity) {
this.dim = dim;
Expand Down Expand Up @@ -91,30 +87,23 @@ private void handle(PacketGetEntityInfo message, MessageContext ctx) {

private static ProbeInfo getProbeInfo(EntityPlayer player, ProbeMode mode, World world, Entity entity, Vec3d hitVec) {
if (ConfigSetup.needsProbe == PROBE_NEEDEDFOREXTENDED) {
// We need a probe only for extended information
if (!ModItems.hasAProbeSomewhere(player)) {
// No probe anywhere, switch EXTENDED to NORMAL
if (mode == ProbeMode.EXTENDED) {
mode = ProbeMode.NORMAL;
}
if (!ModItems.hasAProbeSomewhere(player) && mode == ProbeMode.EXTENDED) {
mode = ProbeMode.NORMAL;
}
} else if (ConfigSetup.needsProbe == PROBE_NEEDEDHARD && !ModItems.hasAProbeSomewhere(player)) {
// The server says we need a probe, but we don't have one in our hands or on our head
return null;
}

ProbeInfo probeInfo = TheOneProbe.theOneProbeImp.create();
IProbeHitEntityData data = new ProbeHitEntityData(hitVec);

IProbeConfig probeConfig = TheOneProbe.theOneProbeImp.createProbeConfig();
List<IProbeConfigProvider> configProviders = TheOneProbe.theOneProbeImp.getConfigProviders();
for (IProbeConfigProvider configProvider : configProviders) {

for (IProbeConfigProvider configProvider : TheOneProbe.theOneProbeImp.getConfigProviders()) {
configProvider.getProbeConfig(probeConfig, player, world, entity, data);
}
ConfigSetup.setRealConfig(probeConfig);

List<IProbeInfoEntityProvider> entityProviders = TheOneProbe.theOneProbeImp.getEntityProviders();
for (IProbeInfoEntityProvider provider : entityProviders) {
for (IProbeInfoEntityProvider provider : TheOneProbe.theOneProbeImp.getEntityProviders()) {
try {
provider.addProbeEntityInfo(mode, probeInfo, player, world, entity, data);
} catch (Throwable e) {
Expand All @@ -124,5 +113,4 @@ private static ProbeInfo getProbeInfo(EntityPlayer player, ProbeMode mode, World
}
return probeInfo;
}

}

0 comments on commit 8f07db3

Please sign in to comment.