-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix prospecting inconsistencies (#2688)
Co-authored-by: screret <68943070+screret@users.noreply.github.com>
- Loading branch information
1 parent
d1196ba
commit 6eece36
Showing
10 changed files
with
241 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 0 additions & 93 deletions
93
src/main/java/com/gregtechceu/gtceu/common/network/packets/SPacketOreProspect.java
This file was deleted.
Oops, something went wrong.
87 changes: 87 additions & 0 deletions
87
src/main/java/com/gregtechceu/gtceu/common/network/packets/prospecting/SPacketProspect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.gregtechceu.gtceu.common.network.packets.prospecting; | ||
|
||
import com.lowdragmc.lowdraglib.networking.IHandlerContext; | ||
import com.lowdragmc.lowdraglib.networking.IPacket; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.world.level.Level; | ||
|
||
import com.google.common.collect.HashBasedTable; | ||
import com.google.common.collect.Table; | ||
|
||
import java.util.Collection; | ||
|
||
public abstract class SPacketProspect<T> implements IPacket { | ||
|
||
protected final Table<ResourceKey<Level>, BlockPos, T> data; | ||
|
||
protected SPacketProspect() { | ||
data = HashBasedTable.create(); | ||
} | ||
|
||
protected SPacketProspect(Table<ResourceKey<Level>, BlockPos, T> data) { | ||
this.data = data; | ||
} | ||
|
||
protected SPacketProspect(Collection<ResourceKey<Level>> keys, Collection<BlockPos> positions, | ||
Collection<T> prospected) { | ||
this(); | ||
var keyIterator = keys.iterator(); | ||
var posIterator = positions.iterator(); | ||
var prospectedIterator = prospected.iterator(); | ||
while (keyIterator.hasNext()) { | ||
data.put(keyIterator.next(), posIterator.next(), prospectedIterator.next()); | ||
} | ||
} | ||
|
||
protected SPacketProspect(ResourceKey<Level> key, Collection<BlockPos> positions, Collection<T> prospected) { | ||
data = HashBasedTable.create(1, prospected.size()); | ||
var posIterator = positions.iterator(); | ||
var prospectedIterator = prospected.iterator(); | ||
while (posIterator.hasNext()) { | ||
data.put(key, posIterator.next(), prospectedIterator.next()); | ||
} | ||
} | ||
|
||
protected SPacketProspect(ResourceKey<Level> key, BlockPos position, T prospected) { | ||
data = HashBasedTable.create(1, 1); | ||
data.put(key, position, prospected); | ||
} | ||
|
||
public abstract void encodeData(FriendlyByteBuf buf, T data); | ||
|
||
public abstract T decodeData(FriendlyByteBuf buf); | ||
|
||
@Override | ||
public void encode(FriendlyByteBuf buf) { | ||
buf.writeInt(data.rowKeySet().size()); | ||
data.rowMap().forEach((key, entry) -> { | ||
buf.writeResourceKey(key); | ||
buf.writeInt(entry.size()); | ||
entry.forEach(((blockPos, t) -> { | ||
buf.writeBlockPos(blockPos); | ||
encodeData(buf, t); | ||
})); | ||
}); | ||
} | ||
|
||
@Override | ||
public void decode(FriendlyByteBuf buf) { | ||
var rowCount = buf.readInt(); | ||
for (int i = 0; i < rowCount; i++) { | ||
var rowKey = buf.readResourceKey(Registries.DIMENSION); | ||
var entryCount = buf.readInt(); | ||
for (int j = 0; j < entryCount; j++) { | ||
var blockPos = buf.readBlockPos(); | ||
var t = decodeData(buf); | ||
data.put(rowKey, blockPos, t); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public abstract void execute(IHandlerContext handler); | ||
} |
46 changes: 46 additions & 0 deletions
46
...com/gregtechceu/gtceu/common/network/packets/prospecting/SPacketProspectBedrockFluid.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.gregtechceu.gtceu.common.network.packets.prospecting; | ||
|
||
import com.gregtechceu.gtceu.api.gui.misc.ProspectorMode; | ||
import com.gregtechceu.gtceu.integration.map.cache.client.GTClientCache; | ||
|
||
import com.lowdragmc.lowdraglib.networking.IHandlerContext; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.world.level.Level; | ||
|
||
import java.util.Collection; | ||
|
||
public class SPacketProspectBedrockFluid extends SPacketProspect<ProspectorMode.FluidInfo> { | ||
|
||
public SPacketProspectBedrockFluid() { | ||
super(); | ||
} | ||
|
||
public SPacketProspectBedrockFluid(ResourceKey<Level> key, Collection<BlockPos> positions, | ||
Collection<ProspectorMode.FluidInfo> prospected) { | ||
super(key, positions, prospected); | ||
} | ||
|
||
public SPacketProspectBedrockFluid(ResourceKey<Level> key, BlockPos pos, ProspectorMode.FluidInfo vein) { | ||
super(key, pos, vein); | ||
} | ||
|
||
@Override | ||
public void encodeData(FriendlyByteBuf buf, ProspectorMode.FluidInfo data) { | ||
ProspectorMode.FLUID.serialize(data, buf); | ||
} | ||
|
||
@Override | ||
public ProspectorMode.FluidInfo decodeData(FriendlyByteBuf buf) { | ||
return ProspectorMode.FLUID.deserialize(buf); | ||
} | ||
|
||
@Override | ||
public void execute(IHandlerContext handler) { | ||
data.rowMap().forEach((level, fluids) -> fluids | ||
.forEach((blockPos, fluid) -> GTClientCache.instance.addFluid(level, | ||
blockPos.getX() >> 4, blockPos.getZ() >> 4, fluid))); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...a/com/gregtechceu/gtceu/common/network/packets/prospecting/SPacketProspectBedrockOre.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.gregtechceu.gtceu.common.network.packets.prospecting; | ||
|
||
import com.gregtechceu.gtceu.api.gui.misc.ProspectorMode; | ||
|
||
import com.lowdragmc.lowdraglib.networking.IHandlerContext; | ||
|
||
import net.minecraft.network.FriendlyByteBuf; | ||
|
||
public class SPacketProspectBedrockOre extends SPacketProspect<ProspectorMode.OreInfo> { | ||
|
||
public SPacketProspectBedrockOre() { | ||
super(); | ||
} | ||
|
||
@Override | ||
public void encodeData(FriendlyByteBuf buf, ProspectorMode.OreInfo data) { | ||
ProspectorMode.BEDROCK_ORE.serialize(data, buf); | ||
} | ||
|
||
@Override | ||
public ProspectorMode.OreInfo decodeData(FriendlyByteBuf buf) { | ||
return ProspectorMode.BEDROCK_ORE.deserialize(buf); | ||
} | ||
|
||
@Override | ||
public void execute(IHandlerContext handler) { | ||
// todo: add cache for bedrock ore veins | ||
} | ||
} |
Oops, something went wrong.