Skip to content

Commit

Permalink
Fixed recipe conditions and network packets handling
Browse files Browse the repository at this point in the history
  • Loading branch information
JackyyTV committed Oct 9, 2023
1 parent 217c9ea commit b1cdbe7
Show file tree
Hide file tree
Showing 145 changed files with 2,287 additions and 1,497 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'eclipse'
id 'idea'
id 'net.minecraftforge.gradle' version '[6.0,6.2)'
id 'net.minecraftforge.gradle' version '[6.0.14,6.2)'
}

import net.minecraftforge.gradle.common.tasks.SignJar
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ mod_name=Exchangers
mc_version=1.20.2
mc_version_range=[1.20.2,1.21)

forge_version=48.0.13
forge_version_range=[48,)
forge_version=48.0.20
forge_version_range=[48.0.17,)
loader_version_range=[48,)

mappings_channel=official
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/jackyy/exchangers/Exchangers.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jackyy.exchangers.handler.ClientEventsHandler;
import jackyy.exchangers.handler.CommonEventsHandler;
import jackyy.exchangers.handler.network.NetworkHandler;
import jackyy.exchangers.registry.ModConfigs;
import jackyy.exchangers.registry.ModItems;
import jackyy.exchangers.registry.crafting.ModCrafting;
Expand All @@ -27,6 +28,7 @@ public Exchangers() {

private void commonSetup(final FMLCommonSetupEvent event) {
MinecraftForge.EVENT_BUS.register(new CommonEventsHandler());
NetworkHandler.registerMessages();
}

private void clientSetup(final FMLClientSetupEvent event) {
Expand Down
110 changes: 58 additions & 52 deletions src/main/java/jackyy/exchangers/handler/network/NetworkHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,76 +5,82 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.network.ChannelBuilder;
import net.minecraftforge.network.NetworkDirection;
import net.minecraftforge.network.PacketDistributor;
import net.minecraftforge.network.SimpleChannel;

public class NetworkHandler {
public static SimpleChannel CHANNEL = ChannelBuilder
.named(new ResourceLocation(Reference.MODID, "main_channel"))
.networkProtocolVersion(1)
.simpleChannel()
public static SimpleChannel channel;

.messageBuilder(PacketSwitchRange.class)
.encoder(PacketSwitchRange::encode)
.decoder(PacketSwitchRange::decode)
.consumerNetworkThread(PacketSwitchRange::handle)
.add()
public static void registerMessages() {
channel = ChannelBuilder
.named(new ResourceLocation(Reference.MODID, "main_channel"))
.networkProtocolVersion(1)
.acceptedVersions((s, v) -> v == 1)
.simpleChannel();

.messageBuilder(PacketIncreaseRange.class)
.encoder(PacketIncreaseRange::encode)
.decoder(PacketIncreaseRange::decode)
.consumerNetworkThread(PacketIncreaseRange::handle)
.add()
channel.messageBuilder(PacketSwitchRange.class, NetworkDirection.PLAY_TO_SERVER)
.encoder(PacketSwitchRange::encode)
.decoder(PacketSwitchRange::decode)
.consumerNetworkThread(PacketSwitchRange::handle)
.add();

.messageBuilder(PacketDecreaseRange.class)
.encoder(PacketDecreaseRange::encode)
.decoder(PacketDecreaseRange::decode)
.consumerNetworkThread(PacketDecreaseRange::handle)
.add()
channel.messageBuilder(PacketIncreaseRange.class, NetworkDirection.PLAY_TO_SERVER)
.encoder(PacketIncreaseRange::encode)
.decoder(PacketIncreaseRange::decode)
.consumerNetworkThread(PacketIncreaseRange::handle)
.add();

.messageBuilder(PacketSwitchMode.class)
.encoder(PacketSwitchMode::encode)
.decoder(PacketSwitchMode::decode)
.consumerNetworkThread(PacketSwitchMode::handle)
.add()
channel.messageBuilder(PacketDecreaseRange.class, NetworkDirection.PLAY_TO_SERVER)
.encoder(PacketDecreaseRange::encode)
.decoder(PacketDecreaseRange::decode)
.consumerNetworkThread(PacketDecreaseRange::handle)
.add();

.messageBuilder(PacketToggleForceDropItems.class)
.encoder(PacketToggleForceDropItems::encode)
.decoder(PacketToggleForceDropItems::decode)
.consumerNetworkThread(PacketToggleForceDropItems::handle)
.add()
channel.messageBuilder(PacketSwitchMode.class, NetworkDirection.PLAY_TO_SERVER)
.encoder(PacketSwitchMode::encode)
.decoder(PacketSwitchMode::decode)
.consumerNetworkThread(PacketSwitchMode::handle)
.add();

.messageBuilder(PacketToggleDirectionalPlacement.class)
.encoder(PacketToggleDirectionalPlacement::encode)
.decoder(PacketToggleDirectionalPlacement::decode)
.consumerNetworkThread(PacketToggleDirectionalPlacement::handle)
.add()
channel.messageBuilder(PacketToggleForceDropItems.class, NetworkDirection.PLAY_TO_SERVER)
.encoder(PacketToggleForceDropItems::encode)
.decoder(PacketToggleForceDropItems::decode)
.consumerNetworkThread(PacketToggleForceDropItems::handle)
.add();

.messageBuilder(PacketToggleFuzzyPlacement.class)
.encoder(PacketToggleFuzzyPlacement::encode)
.decoder(PacketToggleFuzzyPlacement::decode)
.consumerNetworkThread(PacketToggleFuzzyPlacement::handle)
.add()
channel.messageBuilder(PacketToggleDirectionalPlacement.class, NetworkDirection.PLAY_TO_SERVER)
.encoder(PacketToggleDirectionalPlacement::encode)
.decoder(PacketToggleDirectionalPlacement::decode)
.consumerNetworkThread(PacketToggleDirectionalPlacement::handle)
.add();

.messageBuilder(PacketSetFuzzyPlacementChance.class)
.encoder(PacketSetFuzzyPlacementChance::encode)
.decoder(PacketSetFuzzyPlacementChance::decode)
.consumerNetworkThread(PacketSetFuzzyPlacementChance::handle)
.add()
channel.messageBuilder(PacketToggleFuzzyPlacement.class, NetworkDirection.PLAY_TO_SERVER)
.encoder(PacketToggleFuzzyPlacement::encode)
.decoder(PacketToggleFuzzyPlacement::decode)
.consumerNetworkThread(PacketToggleFuzzyPlacement::handle)
.add();

.messageBuilder(PacketToggleVoidItems.class)
.encoder(PacketToggleVoidItems::encode)
.decoder(PacketToggleVoidItems::decode)
.consumerNetworkThread(PacketToggleVoidItems::handle)
.add();
channel.messageBuilder(PacketSetFuzzyPlacementChance.class, NetworkDirection.PLAY_TO_SERVER)
.encoder(PacketSetFuzzyPlacementChance::encode)
.decoder(PacketSetFuzzyPlacementChance::decode)
.consumerNetworkThread(PacketSetFuzzyPlacementChance::handle)
.add();

channel.messageBuilder(PacketToggleVoidItems.class, NetworkDirection.PLAY_TO_SERVER)
.encoder(PacketToggleVoidItems::encode)
.decoder(PacketToggleVoidItems::decode)
.consumerNetworkThread(PacketToggleVoidItems::handle)
.add();
}

public static void sendToClient(Object packet, ServerPlayer player) {
if (CHANNEL.isRemotePresent(player.connection.getConnection()) && !player.connection.getConnection().isMemoryConnection())
CHANNEL.send(packet, PacketDistributor.PLAYER.with(player));
if (channel.isRemotePresent(player.connection.getConnection()) && !player.connection.getConnection().isMemoryConnection())
channel.send(packet, PacketDistributor.PLAYER.with(player));
}

public static void sendToServer(Object packet) {
CHANNEL.send(packet, PacketDistributor.SERVER.noArg());
channel.send(packet, PacketDistributor.SERVER.noArg());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@

public record PacketSetFuzzyPlacementChance(int chance) {

public PacketSetFuzzyPlacementChance(int chance) {
this.chance = chance;
}

public void encode(FriendlyByteBuf buffer) {
buffer.writeInt(chance);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
{
"type": "crafting_shaped",
"conditions": [
{
"type": "exchangers:ender_io_module", "enabled": true
},
{
"type": "forge:mod_loaded", "modid": "enderio"
}
],
"forge:condition": {
"type": "forge:and",
"values": [
{
"type": "exchangers:ender_io_module",
"enabled": true
},
{
"type": "forge:mod_loaded",
"modid": "enderio"
}
]
},
"pattern": [
"IBI",
"ICI",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
{
"type": "crafting_shaped",
"conditions": [
{
"type": "exchangers:ender_io_module", "enabled": true
},
{
"type": "forge:mod_loaded", "modid": "enderio"
},
{
"type": "exchangers:ender_io_recipes_type", "value": "easy"
}
],
"forge:condition": {
"type": "forge:and",
"values": [
{
"type": "exchangers:ender_io_module",
"enabled": true
},
{
"type": "forge:mod_loaded",
"modid": "enderio"
},
{
"type": "exchangers:ender_io_recipes_type",
"value": "easy"
}
]
},
"pattern": [
"IGI",
"ICI",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
{
"type": "crafting_shaped",
"conditions": [
{
"type": "exchangers:ender_io_module", "enabled": true
},
{
"type": "forge:mod_loaded", "modid": "enderio"
},
{
"type": "exchangers:ender_io_recipes_type", "value": "easy"
}
],
"forge:condition": {
"type": "forge:and",
"values": [
{
"type": "exchangers:ender_io_module",
"enabled": true
},
{
"type": "forge:mod_loaded",
"modid": "enderio"
},
{
"type": "exchangers:ender_io_recipes_type",
"value": "easy"
}
]
},
"pattern": [
"DVD",
"DCD",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
{
"type": "crafting_shaped",
"conditions": [
{
"type": "exchangers:ender_io_module", "enabled": true
},
{
"type": "forge:mod_loaded", "modid": "enderio"
},
{
"type": "exchangers:ender_io_recipes_type", "value": "easy"
}
],
"forge:condition": {
"type": "forge:and",
"values": [
{
"type": "exchangers:ender_io_module",
"enabled": true
},
{
"type": "forge:mod_loaded",
"modid": "enderio"
},
{
"type": "exchangers:ender_io_recipes_type",
"value": "easy"
}
]
},
"pattern": [
"PEP",
"EDE",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
{
"type": "crafting_shaped",
"conditions": [
{
"type": "exchangers:ender_io_module", "enabled": true
},
{
"type": "forge:mod_loaded", "modid": "enderio"
},
{
"type": "exchangers:ender_io_recipes_type", "value": "easy"
}
],
"forge:condition": {
"type": "forge:and",
"values": [
{
"type": "exchangers:ender_io_module",
"enabled": true
},
{
"type": "forge:mod_loaded",
"modid": "enderio"
},
{
"type": "exchangers:ender_io_recipes_type",
"value": "easy"
}
]
},
"pattern": [
"PSP",
"SVS",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
{
"type": "crafting_shaped",
"conditions": [
{
"type": "exchangers:ender_io_module", "enabled": true
},
{
"type": "forge:mod_loaded", "modid": "enderio"
},
{
"type": "exchangers:ender_io_recipes_type", "value": "easy"
}
],
"forge:condition": {
"type": "forge:and",
"values": [
{
"type": "exchangers:ender_io_module",
"enabled": true
},
{
"type": "forge:mod_loaded",
"modid": "enderio"
},
{
"type": "exchangers:ender_io_recipes_type",
"value": "easy"
}
]
},
"pattern": [
"EPE",
"ECE",
Expand Down
Loading

0 comments on commit b1cdbe7

Please sign in to comment.