Skip to content

Commit

Permalink
improv: 1.20.1 fabric port finishes (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphaMode authored Oct 23, 2023
1 parent 030748a commit 469ac8c
Show file tree
Hide file tree
Showing 15 changed files with 872 additions and 903 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ parchment_mappings=2023.08.20
fabric_api_version=0.89.3+1.20.1
components_version=5.1.0
porting_lib_version=2.1.1087+1.20
porting_lib_modules=accessors,base,data,networking,utility
porting_lib_modules=accessors,base,data,networking,utility,model_generators
jei_version=15.2.0.27

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
package com.aetherteam.nitrogen.capability;

//import com.aetherteam.nitrogen.network.packet.SyncLevelPacket;
//import net.minecraft.client.Minecraft;
//import net.minecraft.world.entity.player.Player;
//import net.minecraft.world.level.Level;
//
//public class CapabilityUtil {
// /**
// * Used to sync data for level capabilities. This is in its own class to avoid classloading {@link Minecraft} from {@link SyncLevelPacket} on servers.
// * @param syncLevelPacket The {@link SyncLevelPacket}.
// * @param playerEntity The {@link Player} that the level belongs to.
// * @param key The {@link String} key for the field to sync.
// * @param value The {@link Object} value to sync to the field.
// * @param isClientSide Whether the level is clientside, as a {@link Boolean}.
// * @see SyncLevelPacket
// */
// public static void syncLevelCapability(SyncLevelPacket<?> syncLevelPacket, Player playerEntity, String key, Object value, boolean isClientSide) {
// Level level = isClientSide ? Minecraft.getInstance().level : playerEntity.level();
// syncLevelPacket.getCapability(level).ifPresent((synchable) -> synchable.getSynchableFunctions().get(key).getMiddle().accept(value));
// }
//}
// todo CARDINAL COMPONENTS
import com.aetherteam.nitrogen.network.packet.SyncLevelPacket;
import net.minecraft.client.Minecraft;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;

public class CapabilityUtil {
/**
* Used to sync data for level capabilities. This is in its own class to avoid classloading {@link Minecraft} from {@link SyncLevelPacket} on servers.
* @param syncLevelPacket The {@link SyncLevelPacket}.
* @param playerEntity The {@link Player} that the level belongs to.
* @param key The {@link String} key for the field to sync.
* @param value The {@link Object} value to sync to the field.
* @param isClientSide Whether the level is clientside, as a {@link Boolean}.
* @see SyncLevelPacket
*/
public static void syncLevelCapability(SyncLevelPacket<?> syncLevelPacket, Player playerEntity, String key, Object value, boolean isClientSide) {
Level level = isClientSide ? Minecraft.getInstance().level : playerEntity.level();
syncLevelPacket.getCapability(level).ifPresent((synchable) -> synchable.getSynchableFunctions().get(key).getMiddle().accept(value));
}
}
258 changes: 129 additions & 129 deletions src/main/java/com/aetherteam/nitrogen/capability/INBTSynchable.java
Original file line number Diff line number Diff line change
@@ -1,131 +1,131 @@
package com.aetherteam.nitrogen.capability;

//import com.aetherteam.nitrogen.network.BasePacket;
//import com.aetherteam.nitrogen.network.PacketRelay;
//import net.minecraft.nbt.Tag;
//import net.minecraft.resources.ResourceKey;
//import net.minecraft.server.level.ServerPlayer;
//import net.minecraft.world.level.Level;
//import net.minecraftforge.common.util.INBTSerializable;
//import net.minecraftforge.network.simple.SimpleChannel;
//import org.apache.commons.lang3.tuple.Triple;
//import oshi.util.tuples.Quintet;
//
//import org.jetbrains.annotations.Nullable;
//import java.util.Map;
//import java.util.function.Consumer;
//import java.util.function.Supplier;
//
//public interface INBTSynchable<T extends Tag> extends INBTSerializable<T> {
// /**
// * Sets a value to be synced to the given direction.
// * @param direction The network {@link Direction} to send the packet.
// * @param key The {@link String} key for the field to sync.
// * @param value The {@link Object} value to sync to the field.
// */
// default void setSynched(Direction direction, String key, Object value) {
// this.setSynched(direction, key, value, null);
// }
//
// /**
// * Sets a value to be synced to the given direction.<br><br>
// * Warning for "unchecked" is suppressed because casting from wildcards to classes inside type bounds is fine.
// * @param direction The network {@link Direction} to send the packet.
// * @param key The {@link String} key for the field to sync.
// * @param value The {@link Object} value to sync to the field.
// * @param extra An extra value if necessary. The type of class that needs to be given depends on the direction.<br><br>
// * {@link Direction#SERVER} - None.<br><br>
// * {@link Direction#CLIENT} - None.<br><br>
// * {@link Direction#NEAR} - {@link Quintet}<{@link Double}, {@link Double}, {@link Double}, {@link Double}, {@link ResourceKey}<{@link Level}>>. This represents the 5 values needed for {@link PacketRelay#sendToNear(SimpleChannel, Object, double, double, double, double, ResourceKey)}.<br><br>
// * {@link Direction#PLAYER} - {@link ServerPlayer}.<br><br>
// * {@link Direction#DIMENSION} - {@link ResourceKey}<{@link Level}>>. This represents the dimension to send the packet to.
// */
// @SuppressWarnings("unchecked")
// default void setSynched(Direction direction, String key, Object value, @Nullable Object extra) {
// switch(direction) {
// case SERVER -> PacketRelay.sendToServer(this.getPacketChannel(), this.getSyncPacket(key, this.getSynchableFunctions().get(key).getLeft(), value));
// case CLIENT -> PacketRelay.sendToAll(this.getPacketChannel(), this.getSyncPacket(key, this.getSynchableFunctions().get(key).getLeft(), value));
// case NEAR -> {
// if (extra instanceof Quintet<?,?,?,?,?> quintet) {
// Quintet<Double, Double, Double, Double, ResourceKey<Level>> nearValues = (Quintet<Double, Double, Double, Double, ResourceKey<Level>>) quintet;
// PacketRelay.sendToNear(this.getPacketChannel(), this.getSyncPacket(key, this.getSynchableFunctions().get(key).getLeft(), value), nearValues.getA(), nearValues.getB(), nearValues.getC(), nearValues.getD(), nearValues.getE());
// }
// }
// case PLAYER -> {
// if (extra instanceof ServerPlayer serverPlayer) {
// PacketRelay.sendToPlayer(this.getPacketChannel(), this.getSyncPacket(key, this.getSynchableFunctions().get(key).getLeft(), value), serverPlayer);
// }
// }
// case DIMENSION -> {
// if (extra instanceof ResourceKey<?> resourceKey) {
// ResourceKey<Level> dimensionValue = (ResourceKey<Level>) resourceKey;
// PacketRelay.sendToDimension(this.getPacketChannel(), this.getSyncPacket(key, this.getSynchableFunctions().get(key).getLeft(), value), dimensionValue);
// }
// }
// }
// this.getSynchableFunctions().get(key).getMiddle().accept(value);
// }
//
// /**
// * Forces all synchable capability values to sync to the given direction.
// * @param direction The network {@link Direction} to send the packet.
// */
// default void forceSync(Direction direction) {
// this.forceSync(direction, null);
// }
//
// /**
// * Forces all synchable capability values to sync to the given direction.
// * @param direction The network {@link Direction} to send the packet.
// * @param extra An extra value if necessary. The type of class that needs to be given depends on the direction.<br><br>
// * {@link Direction#SERVER} - None.<br><br>
// * {@link Direction#CLIENT} - None.<br><br>
// * {@link Direction#NEAR} - {@link Quintet}<{@link Double}, {@link Double}, {@link Double}, {@link Double}, {@link ResourceKey}<{@link Level}>>. This represents the 5 values needed for {@link PacketRelay#sendToNear(SimpleChannel, Object, double, double, double, double, ResourceKey)}.<br><br>
// * {@link Direction#PLAYER} - {@link ServerPlayer}.<br><br>
// * {@link Direction#DIMENSION} - {@link ResourceKey}<{@link Level}>>. This represents the dimension to send the packet to.
// */
// default void forceSync(Direction direction, @Nullable Object extra) {
// for (Map.Entry<String, Triple<Type, Consumer<Object>, Supplier<Object>>> entry : this.getSynchableFunctions().entrySet()) {
// this.setSynched(direction, entry.getKey(), entry.getValue().getRight().get(), extra);
// }
// }
//
// /**
// * @return A {@link Map} of {@link String}s (representing the name of a field), and {@link Triple}s, containing
// * {@link Type}s (representing the data type),
// * {@link Consumer}<{@link Object}>s (representing setter methods), and
// * {@link Supplier}<{@link Object}>s (representing getter methods).
// */
// Map<String, Triple<Type, Consumer<Object>, Supplier<Object>>> getSynchableFunctions();
//
// /**
// * Creates the packet used for syncing.
// * @param key The {@link String} key for the field to sync.
// * @param type The {@link Type} for the field's data type.
// * @param value The {@link Object} value to sync to the field.
// * @return The {@link BasePacket} for syncing.
// */
// BasePacket getSyncPacket(String key, INBTSynchable.Type type, Object value);
//
// /**
// * @return The {@link SimpleChannel} to send the packet through.
// */
// SimpleChannel getPacketChannel();
//
// enum Direction {
// SERVER,
// CLIENT,
// NEAR,
// PLAYER,
// DIMENSION
// }
//
// enum Type {
// INT,
// FLOAT,
// DOUBLE,
// BOOLEAN,
// UUID
// }
//}
// todo CARDINAL COMPONENTS
import com.aetherteam.nitrogen.network.BasePacket;
import com.aetherteam.nitrogen.network.PacketRelay;
import io.github.fabricators_of_create.porting_lib.core.util.INBTSerializable;
import io.github.fabricators_of_create.porting_lib.util.ServerLifecycleHooks;
import me.pepperbell.simplenetworking.SimpleChannel;
import net.minecraft.nbt.Tag;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.Level;
import org.apache.commons.lang3.tuple.Triple;
import oshi.util.tuples.Quintet;

import org.jetbrains.annotations.Nullable;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Supplier;

public interface INBTSynchable<T extends Tag> extends INBTSerializable<T> {
/**
* Sets a value to be synced to the given direction.
* @param direction The network {@link Direction} to send the packet.
* @param key The {@link String} key for the field to sync.
* @param value The {@link Object} value to sync to the field.
*/
default void setSynched(Direction direction, String key, Object value) {
this.setSynched(direction, key, value, null);
}

/**
* Sets a value to be synced to the given direction.<br><br>
* Warning for "unchecked" is suppressed because casting from wildcards to classes inside type bounds is fine.
* @param direction The network {@link Direction} to send the packet.
* @param key The {@link String} key for the field to sync.
* @param value The {@link Object} value to sync to the field.
* @param extra An extra value if necessary. The type of class that needs to be given depends on the direction.<br><br>
* {@link Direction#SERVER} - None.<br><br>
* {@link Direction#CLIENT} - None.<br><br>
* {@link Direction#NEAR} - {@link Quintet}<{@link Double}, {@link Double}, {@link Double}, {@link Double}, {@link ResourceKey}<{@link Level}>>. This represents the 5 values needed for {@link PacketRelay#sendToNear(SimpleChannel, BasePacket, double, double, double, double, ResourceKey)}.<br><br>
* {@link Direction#PLAYER} - {@link ServerPlayer}.<br><br>
* {@link Direction#DIMENSION} - {@link ResourceKey}<{@link Level}>>. This represents the dimension to send the packet to.
*/
@SuppressWarnings("unchecked")
default void setSynched(Direction direction, String key, Object value, @Nullable Object extra) {
switch(direction) {
case SERVER -> PacketRelay.sendToServer(this.getPacketChannel(), this.getSyncPacket(key, this.getSynchableFunctions().get(key).getLeft(), value));
case CLIENT -> PacketRelay.sendToAll(this.getPacketChannel(), this.getSyncPacket(key, this.getSynchableFunctions().get(key).getLeft(), value));
case NEAR -> {
if (extra instanceof Quintet<?,?,?,?,?> quintet) {
Quintet<Double, Double, Double, Double, ResourceKey<Level>> nearValues = (Quintet<Double, Double, Double, Double, ResourceKey<Level>>) quintet;
PacketRelay.sendToNear(this.getPacketChannel(), this.getSyncPacket(key, this.getSynchableFunctions().get(key).getLeft(), value), nearValues.getA(), nearValues.getB(), nearValues.getC(), nearValues.getD(), nearValues.getE());
}
}
case PLAYER -> {
if (extra instanceof ServerPlayer serverPlayer) {
PacketRelay.sendToPlayer(this.getPacketChannel(), this.getSyncPacket(key, this.getSynchableFunctions().get(key).getLeft(), value), serverPlayer);
}
}
case DIMENSION -> {
if (extra instanceof ResourceKey<?> resourceKey) {
ResourceKey<Level> dimensionValue = (ResourceKey<Level>) resourceKey;
PacketRelay.sendToDimension(this.getPacketChannel(), this.getSyncPacket(key, this.getSynchableFunctions().get(key).getLeft(), value), dimensionValue);
}
}
}
this.getSynchableFunctions().get(key).getMiddle().accept(value);
}

/**
* Forces all synchable capability values to sync to the given direction.
* @param direction The network {@link Direction} to send the packet.
*/
default void forceSync(Direction direction) {
this.forceSync(direction, null);
}

/**
* Forces all synchable capability values to sync to the given direction.
* @param direction The network {@link Direction} to send the packet.
* @param extra An extra value if necessary. The type of class that needs to be given depends on the direction.<br><br>
* {@link Direction#SERVER} - None.<br><br>
* {@link Direction#CLIENT} - None.<br><br>
* {@link Direction#NEAR} - {@link Quintet}<{@link Double}, {@link Double}, {@link Double}, {@link Double}, {@link ResourceKey}<{@link Level}>>. This represents the 5 values needed for {@link PacketRelay#sendToNear(SimpleChannel, Object, double, double, double, double, ResourceKey)}.<br><br>
* {@link Direction#PLAYER} - {@link ServerPlayer}.<br><br>
* {@link Direction#DIMENSION} - {@link ResourceKey}<{@link Level}>>. This represents the dimension to send the packet to.
*/
default void forceSync(Direction direction, @Nullable Object extra) {
for (Map.Entry<String, Triple<Type, Consumer<Object>, Supplier<Object>>> entry : this.getSynchableFunctions().entrySet()) {
this.setSynched(direction, entry.getKey(), entry.getValue().getRight().get(), extra);
}
}

/**
* @return A {@link Map} of {@link String}s (representing the name of a field), and {@link Triple}s, containing
* {@link Type}s (representing the data type),
* {@link Consumer}<{@link Object}>s (representing setter methods), and
* {@link Supplier}<{@link Object}>s (representing getter methods).
*/
Map<String, Triple<Type, Consumer<Object>, Supplier<Object>>> getSynchableFunctions();

/**
* Creates the packet used for syncing.
* @param key The {@link String} key for the field to sync.
* @param type The {@link Type} for the field's data type.
* @param value The {@link Object} value to sync to the field.
* @return The {@link BasePacket} for syncing.
*/
BasePacket getSyncPacket(String key, INBTSynchable.Type type, Object value);

/**
* @return The {@link SimpleChannel} to send the packet through.
*/
SimpleChannel getPacketChannel();

enum Direction {
SERVER,
CLIENT,
NEAR,
PLAYER,
DIMENSION
}

enum Type {
INT,
FLOAT,
DOUBLE,
BOOLEAN,
UUID
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.aetherteam.nitrogen.data.providers;

import io.github.fabricators_of_create.porting_lib.data.ModdedBlockLootSubProvider;
import io.github.fabricators_of_create.porting_lib.tags.Tags;
import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.data.loot.BlockLootSubProvider;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
Expand All @@ -16,7 +16,7 @@

import java.util.Set;

public abstract class NitrogenBlockLootSubProvider extends BlockLootSubProvider {
public abstract class NitrogenBlockLootSubProvider extends ModdedBlockLootSubProvider {
public NitrogenBlockLootSubProvider(Set<Item> items, FeatureFlagSet flags) {
super(items, flags);
}
Expand Down
Loading

0 comments on commit 469ac8c

Please sign in to comment.