-
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.
Merge branch '1.20.1' into gp/QuarkTechMultitool
- Loading branch information
Showing
11 changed files
with
277 additions
and
23 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
71 changes: 71 additions & 0 deletions
71
src/main/java/com/gregtechceu/gtceu/common/network/packets/SPacketSyncBedrockOreVeins.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,71 @@ | ||
package com.gregtechceu.gtceu.common.network.packets; | ||
|
||
import com.gregtechceu.gtceu.GTCEu; | ||
import com.gregtechceu.gtceu.api.data.worldgen.bedrockore.BedrockOreDefinition; | ||
import com.gregtechceu.gtceu.api.registry.GTRegistries; | ||
|
||
import com.lowdragmc.lowdraglib.Platform; | ||
import com.lowdragmc.lowdraglib.networking.IHandlerContext; | ||
import com.lowdragmc.lowdraglib.networking.IPacket; | ||
|
||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.nbt.NbtOps; | ||
import net.minecraft.nbt.Tag; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.resources.RegistryOps; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.stream.Stream; | ||
|
||
@RequiredArgsConstructor | ||
public class SPacketSyncBedrockOreVeins implements IPacket { | ||
|
||
private final Map<ResourceLocation, BedrockOreDefinition> veins; | ||
|
||
public SPacketSyncBedrockOreVeins() { | ||
this.veins = new HashMap<>(); | ||
} | ||
|
||
@Override | ||
public void encode(FriendlyByteBuf buf) { | ||
RegistryOps<Tag> ops = RegistryOps.create(NbtOps.INSTANCE, Platform.getFrozenRegistry()); | ||
int size = veins.size(); | ||
buf.writeVarInt(size); | ||
for (var entry : veins.entrySet()) { | ||
buf.writeResourceLocation(entry.getKey()); | ||
CompoundTag tag = (CompoundTag) BedrockOreDefinition.FULL_CODEC.encodeStart(ops, entry.getValue()) | ||
.getOrThrow(false, GTCEu.LOGGER::error); | ||
buf.writeNbt(tag); | ||
} | ||
} | ||
|
||
@Override | ||
public void decode(FriendlyByteBuf buf) { | ||
RegistryOps<Tag> ops = RegistryOps.create(NbtOps.INSTANCE, Platform.getFrozenRegistry()); | ||
Stream.generate(() -> { | ||
ResourceLocation id = buf.readResourceLocation(); | ||
CompoundTag tag = buf.readAnySizeNbt(); | ||
BedrockOreDefinition def = BedrockOreDefinition.FULL_CODEC.parse(ops, tag).getOrThrow(false, | ||
GTCEu.LOGGER::error); | ||
return Map.entry(id, def); | ||
}).limit(buf.readVarInt()).forEach(entry -> veins.put(entry.getKey(), entry.getValue())); | ||
} | ||
|
||
@Override | ||
public void execute(IHandlerContext handler) { | ||
if (GTRegistries.BEDROCK_ORE_DEFINITIONS.isFrozen()) { | ||
GTRegistries.BEDROCK_ORE_DEFINITIONS.unfreeze(); | ||
} | ||
GTRegistries.BEDROCK_ORE_DEFINITIONS.registry().clear(); | ||
for (var entry : veins.entrySet()) { | ||
GTRegistries.BEDROCK_ORE_DEFINITIONS.registerOrOverride(entry.getKey(), entry.getValue()); | ||
} | ||
if (!GTRegistries.BEDROCK_ORE_DEFINITIONS.isFrozen()) { | ||
GTRegistries.BEDROCK_ORE_DEFINITIONS.freeze(); | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/com/gregtechceu/gtceu/common/network/packets/SPacketSyncFluidVeins.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,71 @@ | ||
package com.gregtechceu.gtceu.common.network.packets; | ||
|
||
import com.gregtechceu.gtceu.GTCEu; | ||
import com.gregtechceu.gtceu.api.data.worldgen.bedrockfluid.BedrockFluidDefinition; | ||
import com.gregtechceu.gtceu.api.registry.GTRegistries; | ||
|
||
import com.lowdragmc.lowdraglib.Platform; | ||
import com.lowdragmc.lowdraglib.networking.IHandlerContext; | ||
import com.lowdragmc.lowdraglib.networking.IPacket; | ||
|
||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.nbt.NbtOps; | ||
import net.minecraft.nbt.Tag; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.resources.RegistryOps; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.stream.Stream; | ||
|
||
@RequiredArgsConstructor | ||
public class SPacketSyncFluidVeins implements IPacket { | ||
|
||
private final Map<ResourceLocation, BedrockFluidDefinition> veins; | ||
|
||
public SPacketSyncFluidVeins() { | ||
this.veins = new HashMap<>(); | ||
} | ||
|
||
@Override | ||
public void encode(FriendlyByteBuf buf) { | ||
RegistryOps<Tag> ops = RegistryOps.create(NbtOps.INSTANCE, Platform.getFrozenRegistry()); | ||
int size = veins.size(); | ||
buf.writeVarInt(size); | ||
for (var entry : veins.entrySet()) { | ||
buf.writeResourceLocation(entry.getKey()); | ||
CompoundTag tag = (CompoundTag) BedrockFluidDefinition.FULL_CODEC.encodeStart(ops, entry.getValue()) | ||
.getOrThrow(false, GTCEu.LOGGER::error); | ||
buf.writeNbt(tag); | ||
} | ||
} | ||
|
||
@Override | ||
public void decode(FriendlyByteBuf buf) { | ||
RegistryOps<Tag> ops = RegistryOps.create(NbtOps.INSTANCE, Platform.getFrozenRegistry()); | ||
Stream.generate(() -> { | ||
ResourceLocation id = buf.readResourceLocation(); | ||
CompoundTag tag = buf.readAnySizeNbt(); | ||
BedrockFluidDefinition def = BedrockFluidDefinition.FULL_CODEC.parse(ops, tag).getOrThrow(false, | ||
GTCEu.LOGGER::error); | ||
return Map.entry(id, def); | ||
}).limit(buf.readVarInt()).forEach(entry -> veins.put(entry.getKey(), entry.getValue())); | ||
} | ||
|
||
@Override | ||
public void execute(IHandlerContext handler) { | ||
if (GTRegistries.BEDROCK_FLUID_DEFINITIONS.isFrozen()) { | ||
GTRegistries.BEDROCK_FLUID_DEFINITIONS.unfreeze(); | ||
} | ||
GTRegistries.BEDROCK_FLUID_DEFINITIONS.registry().clear(); | ||
for (var entry : veins.entrySet()) { | ||
GTRegistries.BEDROCK_FLUID_DEFINITIONS.registerOrOverride(entry.getKey(), entry.getValue()); | ||
} | ||
if (!GTRegistries.BEDROCK_FLUID_DEFINITIONS.isFrozen()) { | ||
GTRegistries.BEDROCK_FLUID_DEFINITIONS.freeze(); | ||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/com/gregtechceu/gtceu/common/network/packets/SPacketSyncOreVeins.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,70 @@ | ||
package com.gregtechceu.gtceu.common.network.packets; | ||
|
||
import com.gregtechceu.gtceu.GTCEu; | ||
import com.gregtechceu.gtceu.api.data.worldgen.GTOreDefinition; | ||
import com.gregtechceu.gtceu.api.registry.GTRegistries; | ||
|
||
import com.lowdragmc.lowdraglib.Platform; | ||
import com.lowdragmc.lowdraglib.networking.IHandlerContext; | ||
import com.lowdragmc.lowdraglib.networking.IPacket; | ||
|
||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.nbt.NbtOps; | ||
import net.minecraft.nbt.Tag; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.resources.RegistryOps; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.stream.Stream; | ||
|
||
@RequiredArgsConstructor | ||
public class SPacketSyncOreVeins implements IPacket { | ||
|
||
private final Map<ResourceLocation, GTOreDefinition> veins; | ||
|
||
public SPacketSyncOreVeins() { | ||
this.veins = new HashMap<>(); | ||
} | ||
|
||
@Override | ||
public void encode(FriendlyByteBuf buf) { | ||
RegistryOps<Tag> ops = RegistryOps.create(NbtOps.INSTANCE, Platform.getFrozenRegistry()); | ||
int size = veins.size(); | ||
buf.writeVarInt(size); | ||
for (var entry : veins.entrySet()) { | ||
buf.writeResourceLocation(entry.getKey()); | ||
CompoundTag tag = (CompoundTag) GTOreDefinition.FULL_CODEC.encodeStart(ops, entry.getValue()) | ||
.getOrThrow(false, GTCEu.LOGGER::error); | ||
buf.writeNbt(tag); | ||
} | ||
} | ||
|
||
@Override | ||
public void decode(FriendlyByteBuf buf) { | ||
RegistryOps<Tag> ops = RegistryOps.create(NbtOps.INSTANCE, Platform.getFrozenRegistry()); | ||
Stream.generate(() -> { | ||
ResourceLocation id = buf.readResourceLocation(); | ||
CompoundTag tag = buf.readAnySizeNbt(); | ||
GTOreDefinition def = GTOreDefinition.FULL_CODEC.parse(ops, tag).getOrThrow(false, GTCEu.LOGGER::error); | ||
return Map.entry(id, def); | ||
}).limit(buf.readVarInt()).forEach(entry -> veins.put(entry.getKey(), entry.getValue())); | ||
} | ||
|
||
@Override | ||
public void execute(IHandlerContext handler) { | ||
if (GTRegistries.ORE_VEINS.isFrozen()) { | ||
GTRegistries.ORE_VEINS.unfreeze(); | ||
} | ||
GTRegistries.ORE_VEINS.registry().clear(); | ||
for (var entry : veins.entrySet()) { | ||
GTRegistries.ORE_VEINS.registerOrOverride(entry.getKey(), entry.getValue()); | ||
} | ||
if (!GTRegistries.ORE_VEINS.isFrozen()) { | ||
GTRegistries.ORE_VEINS.freeze(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.