Attempt to fix 1.16.3 branch's issues on the repository
Added the original 'wayoftime' folder back, so see if that fixed the multiple folder issue.
This commit is contained in:
parent
6b4145a67c
commit
9fa68e86ae
224 changed files with 24047 additions and 0 deletions
|
@ -0,0 +1,151 @@
|
|||
package wayoftime.bloodmagic.network;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.RegistryKey;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraftforge.fml.network.NetworkDirection;
|
||||
import net.minecraftforge.fml.network.NetworkEvent.Context;
|
||||
import net.minecraftforge.fml.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.network.PacketDistributor;
|
||||
import net.minecraftforge.fml.network.simple.SimpleChannel;
|
||||
|
||||
/**
|
||||
* Copied liberally from Mekanism. Many thanks to pupnewfster!
|
||||
*
|
||||
*/
|
||||
public abstract class BasePacketHandler
|
||||
{
|
||||
|
||||
protected static SimpleChannel createChannel(ResourceLocation name)
|
||||
{
|
||||
return NetworkRegistry.ChannelBuilder.named(name).clientAcceptedVersions(getProtocolVersion()::equals).serverAcceptedVersions(getProtocolVersion()::equals).networkProtocolVersion(BasePacketHandler::getProtocolVersion).simpleChannel();
|
||||
}
|
||||
|
||||
private static String getProtocolVersion()
|
||||
{
|
||||
return "1";
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for reading strings to make sure we don't accidentally call
|
||||
* PacketBuffer#readString on the server
|
||||
*/
|
||||
public static String readString(PacketBuffer buffer)
|
||||
{
|
||||
return buffer.readString(Short.MAX_VALUE);
|
||||
}
|
||||
|
||||
// public static void log(String log)
|
||||
// {
|
||||
// // TODO: Add more logging for packets using this
|
||||
// if (MekanismConfig.general.logPackets.get())
|
||||
// {
|
||||
// Mekanism.logger.info(log);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
public static PlayerEntity getPlayer(Supplier<Context> context)
|
||||
{
|
||||
return context.get().getSender();
|
||||
}
|
||||
|
||||
private int index = 0;
|
||||
|
||||
protected abstract SimpleChannel getChannel();
|
||||
|
||||
public abstract void initialize();
|
||||
|
||||
protected <MSG> void registerClientToServer(Class<MSG> type, BiConsumer<MSG, PacketBuffer> encoder,
|
||||
Function<PacketBuffer, MSG> decoder, BiConsumer<MSG, Supplier<Context>> consumer)
|
||||
{
|
||||
getChannel().registerMessage(index++, type, encoder, decoder, consumer, Optional.of(NetworkDirection.PLAY_TO_SERVER));
|
||||
}
|
||||
|
||||
protected <MSG> void registerServerToClient(Class<MSG> type, BiConsumer<MSG, PacketBuffer> encoder,
|
||||
Function<PacketBuffer, MSG> decoder, BiConsumer<MSG, Supplier<Context>> consumer)
|
||||
{
|
||||
getChannel().registerMessage(index++, type, encoder, decoder, consumer, Optional.of(NetworkDirection.PLAY_TO_CLIENT));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send this message to the specified player.
|
||||
*
|
||||
* @param message - the message to send
|
||||
* @param player - the player to send it to
|
||||
*/
|
||||
public <MSG> void sendTo(MSG message, ServerPlayerEntity player)
|
||||
{
|
||||
getChannel().sendTo(message, player.connection.getNetworkManager(), NetworkDirection.PLAY_TO_CLIENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send this message to everyone connected to the server.
|
||||
*
|
||||
* @param message - message to send
|
||||
*/
|
||||
public <MSG> void sendToAll(MSG message)
|
||||
{
|
||||
getChannel().send(PacketDistributor.ALL.noArg(), message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send this message to everyone within the supplied dimension.
|
||||
*
|
||||
* @param message - the message to send
|
||||
* @param dimension - the dimension to target
|
||||
*/
|
||||
public <MSG> void sendToDimension(MSG message, RegistryKey<World> dimension)
|
||||
{
|
||||
getChannel().send(PacketDistributor.DIMENSION.with(() -> dimension), message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send this message to the server.
|
||||
*
|
||||
* @param message - the message to send
|
||||
*/
|
||||
public <MSG> void sendToServer(MSG message)
|
||||
{
|
||||
getChannel().sendToServer(message);
|
||||
}
|
||||
|
||||
public <MSG> void sendToAllTracking(MSG message, Entity entity)
|
||||
{
|
||||
getChannel().send(PacketDistributor.TRACKING_ENTITY.with(() -> entity), message);
|
||||
}
|
||||
|
||||
public <MSG> void sendToAllTracking(MSG message, TileEntity tile)
|
||||
{
|
||||
sendToAllTracking(message, tile.getWorld(), tile.getPos());
|
||||
}
|
||||
|
||||
public <MSG> void sendToAllTracking(MSG message, World world, BlockPos pos)
|
||||
{
|
||||
if (world instanceof ServerWorld)
|
||||
{
|
||||
// If we have a ServerWorld just directly figure out the ChunkPos so as to not
|
||||
// require looking up the chunk
|
||||
// This provides a decent performance boost over using the packet distributor
|
||||
((ServerWorld) world).getChunkProvider().chunkManager.getTrackingPlayers(new ChunkPos(pos), false).forEach(p -> sendTo(message, p));
|
||||
} else
|
||||
{
|
||||
// Otherwise fallback to entities tracking the chunk if some mod did something
|
||||
// odd and our world is not a ServerWorld
|
||||
getChannel().send(PacketDistributor.TRACKING_CHUNK.with(() -> world.getChunk(pos.getX() >> 4, pos.getZ() >> 4)), message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package wayoftime.bloodmagic.network;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.network.simple.SimpleChannel;
|
||||
import wayoftime.bloodmagic.BloodMagic;
|
||||
import wayoftime.bloodmagic.util.ChatUtil;
|
||||
|
||||
public class BloodMagicPacketHandler extends BasePacketHandler
|
||||
{
|
||||
// public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(new ResourceLocation(BloodMagic.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals);
|
||||
public static final SimpleChannel INSTANCE = createChannel(new ResourceLocation(BloodMagic.MODID, "main"));
|
||||
|
||||
@Override
|
||||
public void initialize()
|
||||
{
|
||||
registerServerToClient(ChatUtil.PacketNoSpamChat.class, ChatUtil.PacketNoSpamChat::encode, ChatUtil.PacketNoSpamChat::decode, ChatUtil.PacketNoSpamChat::handle);
|
||||
// INSTANCE.registerMessage(id, messageType, encoder, decoder, messageConsumer);
|
||||
// INSTANCE.registerMessage(ChatUtil.PacketNoSpamChat.Handler.class, ChatUtil.PacketNoSpamChat.class, 0, Side.CLIENT);
|
||||
// INSTANCE.registerMessage(ItemRouterButtonPacketProcessor.class, ItemRouterButtonPacketProcessor.class, 1, Side.SERVER);
|
||||
// INSTANCE.registerMessage(PlayerVelocityPacketProcessor.class, PlayerVelocityPacketProcessor.class, 2, Side.CLIENT);
|
||||
// INSTANCE.registerMessage(PlayerFallDistancePacketProcessor.class, PlayerFallDistancePacketProcessor.class, 3, Side.SERVER);
|
||||
// INSTANCE.registerMessage(SigilHoldingPacketProcessor.class, SigilHoldingPacketProcessor.class, 4, Side.SERVER);
|
||||
// INSTANCE.registerMessage(KeyProcessor.class, KeyProcessor.class, 5, Side.SERVER);
|
||||
// INSTANCE.registerMessage(DemonAuraPacketProcessor.class, DemonAuraPacketProcessor.class, 6, Side.CLIENT);
|
||||
// INSTANCE.registerMessage(ItemRouterAmountPacketProcessor.class, ItemRouterAmountPacketProcessor.class, 7, Side.SERVER);
|
||||
}
|
||||
|
||||
protected SimpleChannel getChannel()
|
||||
{
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
// public static void sendToAllAround(IMessage message, TileEntity te, int range)
|
||||
// {
|
||||
// INSTANCE.sendToAllAround(message, new NetworkRegistry.TargetPoint(te.getWorld().provider.getDimension(), te.getPos().getX(), te.getPos().getY(), te.getPos().getZ(), range));
|
||||
// }
|
||||
//
|
||||
// public static void sendToAllAround(IMessage message, TileEntity te)
|
||||
// {
|
||||
// sendToAllAround(message, te, 64);
|
||||
// }
|
||||
//
|
||||
// public static void sendTo(IMessage message, EntityPlayerMP player)
|
||||
// {
|
||||
// INSTANCE.sendTo(message, player);
|
||||
// }
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue