Skip to content

Commit

Permalink
Migrate lang files
Browse files Browse the repository at this point in the history
  • Loading branch information
ramidzkh committed Aug 13, 2023
1 parent 9e57cf2 commit 85e243b
Show file tree
Hide file tree
Showing 28 changed files with 13,323 additions and 18,072 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* A global loot modifier used by forestry to inject the additional chest loot to the vanilla loot tables.
*/
public class ConditionLootModifier extends LootModifier {
public static final Serializer SERIALIZER = new Serializer();
public static final GlobalLootModifierSerializer<ConditionLootModifier> SERIALIZER = new Serializer();

private final ResourceLocation tableLocation;
private final String[] extensions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package forestry.core.network;

import java.io.IOException;

import net.minecraft.server.level.ServerPlayer;

public interface IForestryPacketHandlerServer extends IForestryPacketHandler {
void onPacketData(PacketBufferForestry data, ServerPlayer player) throws IOException;
void onPacketData(PacketBufferForestry data, ServerPlayer player);
}
70 changes: 4 additions & 66 deletions src/main/java/forestry/core/network/PacketHandlerServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
******************************************************************************/
package forestry.core.network;

import java.io.IOException;

import org.apache.commons.lang3.tuple.Pair;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -27,37 +25,13 @@

import forestry.core.config.Constants;

//import net.minecraft.util.IThreadListener;
//import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
//import net.minecraftforge.fml.common.network.FMLEventChannel;
//import net.minecraftforge.fml.common.network.FMLNetworkEvent.ClientCustomPacketEvent;
//import net.minecraftforge.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent;
//import net.minecraftforge.fml.common.network.NetworkRegistry;
//import net.minecraftforge.fml.common.network.internal.FMLProxyPacket;

public class PacketHandlerServer {

private static final Logger LOGGER = LogManager.getLogger();

public static final ResourceLocation CHANNEL_ID = new ResourceLocation(Constants.MOD_ID, "channel");
public static final String VERSION = "1.0.0";

// public static final String channelId = "FOR"; //TODO - change to 1 or similar...
// public static final EventNetworkChannel channel = NetworkRegistry.ChannelBuilder
// .named(new ResourceLocation(Constants.MOD_ID, "channel"))
// .clientAcceptedVersions(s -> s.equals("1"))
// .serverAcceptedVersions(s -> s.equals("1"))
// .networkProtocolVersion(() -> "1")
// .eventNetworkChannel();
// static {
// channel.addListener();
// }

public PacketHandlerServer() {
// channel = NetworkRegistry.INSTANCE.newEventDrivenChannel(channelId);
// channel.register(this);
}

public void onPacket(NetworkEvent.ClientCustomPayloadEvent event) {
PacketBufferForestry data = new PacketBufferForestry(event.getPayload());
NetworkEvent.Context ctx = event.getSource().get();
Expand All @@ -68,15 +42,10 @@ public void onPacket(NetworkEvent.ClientCustomPayloadEvent event) {
return;
}

try {
byte packetIdOrdinal = data.readByte();
PacketIdServer packetId = PacketIdServer.VALUES[packetIdOrdinal];
IForestryPacketHandlerServer packetHandler = packetId.getPacketHandler();
packetHandler.onPacketData(data, player);
} catch (IOException e) { //TODO - is this actually thrown?
LOGGER.error("exception handling packet", e);
return;
}
byte packetIdOrdinal = data.readByte();
PacketIdServer packetId = PacketIdServer.VALUES[packetIdOrdinal];
IForestryPacketHandlerServer packetHandler = packetId.getPacketHandler();
packetHandler.onPacketData(data, player);
event.getSource().get().setPacketHandled(true);
}

Expand All @@ -85,35 +54,4 @@ public static void sendPacket(IForestryPacketClient packet, ServerPlayer player)
ICustomPacket<Packet<?>> payload = NetworkDirection.PLAY_TO_CLIENT.buildPacket(packetData, PacketHandlerServer.CHANNEL_ID);
player.connection.send(payload.getThis());
}

// @OnlyIn(Dist.CLIENT)
// private static void checkThreadAndEnqueue(final IForestryPacketHandlerClient packet, final PacketBufferForestry data, IThreadListener threadListener) {
// if (!threadListener.isCallingFromMinecraftThread()) {
// data.retain();
// threadListener.addScheduledTask(() -> {
// try {
// PlayerEntity player = Minecraft.getInstance().player;
// Preconditions.checkNotNull(player, "Tried to send data to client before the player exists.");
// packet.onPacketData(data, player);
// data.release();
// } catch (IOException e) {
// Log.error("Network Error", e);
// }
// });
// }
// }
//
// private static void checkThreadAndEnqueue(final IForestryPacketHandlerServer packet, final PacketBufferForestry data, final ServerPlayerEntity player, IThreadListener threadListener) {
// if (!threadListener.isCallingFromMinecraftThread()) {
// data.retain();
// threadListener.addScheduledTask(() -> {
// try {
// packet.onPacketData(data, player);
// data.release();
// } catch (IOException e) {
// Log.error("Network Error", e);
// }
// });
// }
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
******************************************************************************/
package forestry.factory.network.packets;

import java.io.IOException;

import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BlockEntity;
Expand Down Expand Up @@ -51,7 +49,7 @@ public PacketIdServer getPacketId() {

public static class Handler implements IForestryPacketHandlerServer {
@Override
public void onPacketData(PacketBufferForestry data, ServerPlayer player) throws IOException {
public void onPacketData(PacketBufferForestry data, ServerPlayer player) {
BlockPos pos = data.readBlockPos();
NonNullList<ItemStack> craftingInventory = data.readItemStacks();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
******************************************************************************/
package forestry.worktable.network.packets;

import java.io.IOException;

import net.minecraft.server.level.ServerPlayer;
import net.minecraft.core.BlockPos;

Expand Down Expand Up @@ -52,7 +50,7 @@ protected void writeData(PacketBufferForestry data) {
public static class Handler implements IForestryPacketHandlerServer {

@Override
public void onPacketData(PacketBufferForestry data, ServerPlayer player) throws IOException {
public void onPacketData(PacketBufferForestry data, ServerPlayer player) {
BlockPos pos = data.readBlockPos();
MemorizedRecipe recipe = new MemorizedRecipe(data);

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/forestry/worktable/recipes/MemorizedRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public final class MemorizedRecipe implements INbtWritable, INbtReadable, IStrea
private long lastUsed;
private boolean locked;

public MemorizedRecipe(PacketBufferForestry data) throws IOException {
public MemorizedRecipe(PacketBufferForestry data) {
readData(data);
}

Expand Down Expand Up @@ -224,7 +224,7 @@ public void writeData(PacketBufferForestry data) {
}

@Override
public void readData(PacketBufferForestry data) throws IOException {
public void readData(PacketBufferForestry data) {
data.readInventory(craftMatrix);
locked = data.readBoolean();
selectedRecipe = data.readVarInt();
Expand Down
28 changes: 28 additions & 0 deletions src/main/resources/assets/forestry/lang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,31 @@ Files must be encoded in UTF-8. Anything else will not work. Pull requests, subm
Put the files into your .minecraft directory into a subfolder "assets/" that mirrors that of the Forestry jar. Any correctly named localization file should take precedence over the defaults in the jar.

Alternatively you can also add your localization files to the Forestry .jar directly.

### Notes

Script used to translate .lang files to .json files (except en_us)

```awk
BEGIN {
FS="="
print "{"
}
# enable to persist comments
# /^#/ {
# sub(/^# /, "")
# gsub(/"/, "\\\"", $0)
# print " \"_comment\": \"" $0 "\","
# next
# }
NF==2 {
gsub(/"/, "\\\"", $2)
print " \"" $1 "\": \"" $2 "\","
}
END {
print "}"
}
```
Loading

0 comments on commit 85e243b

Please sign in to comment.