Skip to content

Commit

Permalink
A lot of fixes (AAAAAAAAAA), add metadata system to polymer networkin…
Browse files Browse the repository at this point in the history
…g, add method for checking if client is bedrock (wraps floodgate)
  • Loading branch information
Patbox committed Jun 15, 2023
1 parent d5a6594 commit 1689879
Show file tree
Hide file tree
Showing 52 changed files with 614 additions and 94 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ allprojects {
maven { url "https://maven.terraformersmc.com/releases" }
maven { url "https://maven.theepicblock.nl" }
maven { url "https://lazurite.dev/maven/releases" }
maven { url "https://repo.opencollab.dev/maven-snapshots/" }
maven {
name = 'Ladysnake Mods'
url = 'https://ladysnake.jfrog.io/artifactory/mods'
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.20
yarn_mappings=1.20+build.1
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.1
loader_version=0.14.21

#Fabric api
fabric_version=0.82.1+1.20
fabric_version=0.83.0+1.20.1

maven_group = eu.pb4

mod_version = 0.5.0
mod_version = 0.5.1

minecraft_version_supported = ">=1.20-"

Expand Down
1 change: 1 addition & 0 deletions polymer-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies {
transitive(false)
}
modCompileOnly "xyz.nucleoid:disguiselib-fabric:1.2.2"
modCompileOnly "org.geysermc.floodgate:api:2.2.0-SNAPSHOT"
}

afterEvaluate {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package eu.pb4.polymer.common.api;

import eu.pb4.polymer.common.api.events.SimpleEvent;
import eu.pb4.polymer.common.impl.CommonImpl;
import eu.pb4.polymer.common.impl.CommonImplUtils;
import eu.pb4.polymer.common.impl.CommonResourcePackInfoHolder;
import eu.pb4.polymer.common.impl.FakeWorld;
import eu.pb4.polymer.common.impl.*;
import eu.pb4.polymer.common.impl.client.ClientUtils;
import eu.pb4.polymer.common.impl.compat.FloodGateUtils;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
Expand Down Expand Up @@ -99,6 +97,13 @@ public static ServerPlayerEntity getPlayerContext() {
return player;
}

public static boolean isBedrockPlayer(ServerPlayerEntity player) {
if (CompatStatus.FLOODGATE) {
return FloodGateUtils.isPlayerBroken(player);
}
return false;
}

public static boolean hasResourcePack(@Nullable ServerPlayerEntity player) {
return CommonImpl.FORCE_RESOURCEPACK_ENABLED_STATE || (player != null && ((CommonResourcePackInfoHolder) player).polymerCommon$hasResourcePack())
|| (player != null && ((CommonResourcePackInfoHolder) player).polymerCommon$hasResourcePack())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import eu.pb4.polymer.common.api.PolymerCommonUtils;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
Expand Down Expand Up @@ -137,6 +138,11 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher, C
consumer.accept(dev, access);
}

dev.then(literal("is_bedrock").executes((ctx) -> {
ctx.getSource().sendFeedback(() -> Text.literal("Bedrock: " + PolymerCommonUtils.isBedrockPlayer(ctx.getSource().getPlayer())), false);
return 0;
}));

command.then(dev);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public final class CompatStatus {
public static final boolean POLYMER_BLOCKS = LOADER.isModLoaded("polymer-blocks");
public static final boolean POLYMER_CORE = LOADER.isModLoaded("polymer-core");
public static final boolean POLYMER_AUTOHOST = LOADER.isModLoaded("polymer-autohost");
public static final boolean POLYMER_VIRTUAL_ENTITY = LOADER.isModLoaded("polymer-virtual-entity");


public static final boolean POLYMER_RESOURCE_PACK = LOADER.isModLoaded("polymer-resource-pack");
Expand All @@ -18,7 +19,9 @@ public final class CompatStatus {

public static final boolean FABRIC_SYNC = LOADER.isModLoaded("fabric-registry-sync-v0");
public static final boolean FABRIC_NETWORKING = LOADER.isModLoaded("fabric-networking-api-v1");
public static final boolean FABRIC_FLUID_RENDERERING = LOADER.isModLoaded("fabric-rendering-fluids-v1");
public static final boolean FABRIC_FLUID_RENDERING = LOADER.isModLoaded("fabric-rendering-fluids-v1");
@Deprecated
public static final boolean FABRIC_FLUID_RENDERERING = FABRIC_FLUID_RENDERING;
public static final boolean FABRIC_ITEM_GROUP = LOADER.isModLoaded("fabric-item-group-api-v1");
public static final boolean FABRIC_SCREEN_HANDLER = LOADER.isModLoaded("fabric-screen-handler-api-v1");
public static final boolean FABRIC_PERMISSION_API_V0 = LOADER.isModLoaded("fabric-permissions-api-v0");
Expand All @@ -39,8 +42,11 @@ public final class CompatStatus {
public static final boolean FABRIC_PROXY_LITE = LOADER.isModLoaded("fabricproxy-lite");
public static final boolean FABRIC_PROXY = LOADER.isModLoaded("fabricproxy");
public static final boolean QFORWARD = LOADER.isModLoaded("qforward");
public static final boolean FAPROXY = LOADER.isModLoaded("fabroxy");

public static final boolean PROXY_MODS = FABRIC_PROXY || FABRIC_PROXY_LITE || QFORWARD || FAPROXY;

public static final boolean PROXY_MODS = FABRIC_PROXY || FABRIC_PROXY_LITE || QFORWARD;
public static final boolean FLOODGATE = LOADER.isModLoaded("floodgate");

public static final boolean IRIS = LOADER.isModLoaded("iris");
public static final boolean CANVAS = LOADER.isModLoaded("canvas");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package eu.pb4.polymer.common.impl.compat;

import net.minecraft.server.network.ServerPlayerEntity;
import org.geysermc.floodgate.api.FloodgateApi;

public class FloodGateUtils {
public static boolean isPlayerBroken(ServerPlayerEntity player) {
return FloodgateApi.getInstance().isFloodgatePlayer(player.getUuid());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import eu.pb4.polymer.common.api.events.BooleanEvent;
import eu.pb4.polymer.common.api.events.SimpleEvent;
import eu.pb4.polymer.core.api.utils.PolymerUtils;
import eu.pb4.polymer.core.impl.interfaces.BlockStateExtra;
import eu.pb4.polymer.core.mixin.block.BlockEntityUpdateS2CPacketAccessor;
import eu.pb4.polymer.rsm.api.RegistrySyncUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import eu.pb4.polymer.core.impl.PolymerImpl;
import eu.pb4.polymer.core.impl.PolymerImplUtils;
import eu.pb4.polymer.core.impl.interfaces.PolymerNetworkHandlerExtension;
import eu.pb4.polymer.core.impl.networking.ServerPackets;
import eu.pb4.polymer.core.mixin.block.packet.ThreadedAnvilChunkStorageAccessor;
import eu.pb4.polymer.core.mixin.entity.ServerWorldAccessor;
import eu.pb4.polymer.networking.api.PolymerServerNetworking;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.EntityType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import eu.pb4.polymer.core.impl.ui.CreativeTabListUi;
import eu.pb4.polymer.core.impl.ui.CreativeTabUi;
import eu.pb4.polymer.core.impl.ui.PotionUi;
import eu.pb4.polymer.core.mixin.block.PalettedContainerAccessor;
import eu.pb4.polymer.networking.impl.NetworkHandlerExtension;
import net.minecraft.block.Block;
import net.minecraft.command.CommandRegistryAccess;
Expand Down Expand Up @@ -156,7 +157,18 @@ public static void registerDev(LiteralArgumentBuilder<ServerCommandSource> dev)
ctx.getSource().sendFeedback(() -> Text.literal("Resource pack status: " + status), false);
return 0;
})
);
)
.then(literal("chunk_section_info")
.executes((ctx) -> {
var chunk = ctx.getSource().getWorld().getChunk(ctx.getSource().getPlayer().getBlockPos());
var s = chunk.getSection(ctx.getSource().getWorld().getSectionIndex(ctx.getSource().getPlayer().getBlockY()));

var a = ((PalettedContainerAccessor) s.getBlockStateContainer()).getData();

ctx.getSource().sendFeedback(() -> Text.literal("Chunk: " + chunk.getPos() + " Palette: " + a.palette() + " | " + " Storage: " + a.storage() + " | Bits: " + a.storage().getElementBits()), false);
return 0;
})
);
}

private static int targetBlock(CommandContext<ServerCommandSource> context) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package eu.pb4.polymer.core.impl;

import it.unimi.dsi.fastutil.objects.Object2ObjectOpenCustomHashMap;
import net.minecraft.registry.Registry;
import net.minecraft.util.Util;
import org.jetbrains.annotations.ApiStatus;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

@ApiStatus.Internal
public class ImplPolymerRegistryEvent {
private static final Map<Registry<?>, List<Consumer<?>>> EVENTS = new Object2ObjectOpenCustomHashMap<>(Util.identityHashStrategy());
public static void invokeRegistered(Registry<?> ts, Object entry) {
//noinspection unchecked
var x = (List<Consumer<Object>>) (Object) EVENTS.get(ts);

if (x != null) {
for (var a : x) {
a.accept(entry);
}
}
}

public static <T> void register(Registry<T> registry, Consumer<T> tConsumer) {
EVENTS.computeIfAbsent(registry, (a) -> new ArrayList<>()).add(tConsumer);
}

public static <T> void iterateAndRegister(Registry<T> registry, Consumer<T> tConsumer) {
for (var x : registry) {
tConsumer.accept(x);
}
register(registry, tConsumer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import java.util.stream.Stream;

public class PolymerImplUtils {
public static final SimpleEvent<BiConsumer<Registry<Object>, Object>> ON_REGISTERED = new SimpleEvent<>();
public static final Collection<BlockState> POLYMER_STATES = ((PolymerIdList<BlockState>) Block.STATE_IDS).polymer$getPolymerEntries();

public static Identifier id(String path) {
Expand Down Expand Up @@ -238,10 +237,6 @@ public static boolean getStateIdsLock(boolean value) {
return ((PolymerIdList) Block.STATE_IDS).polymer$getReorderLock();
}

public static void invokeRegistered(Registry<Object> ts, Object entry) {
ON_REGISTERED.invoke((a) -> a.accept(ts, entry));
}

public static boolean shouldSkipStateInitialization(Stream<StackWalker.StackFrame> s) {
if (CompatStatus.QUILT_REGISTRY) {
var x = s.skip(3).findFirst();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package eu.pb4.polymer.core.impl;

import net.minecraft.util.Identifier;
import org.jetbrains.annotations.ApiStatus;

import static eu.pb4.polymer.core.impl.PolymerImplUtils.id;

@ApiStatus.Internal
public class PolymerMetadataKeys {
public static final Identifier BLOCKSTATE_BITS = id("core/blockstate_bits");
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void onInitializeClient() {
ReiCompatibility.registerEvents();
}

if (CompatStatus.FABRIC_FLUID_RENDERERING) {
if (CompatStatus.FABRIC_FLUID_RENDERING) {
FabricFluids.register();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import eu.pb4.polymer.core.impl.other.EventRunners;
import eu.pb4.polymer.core.impl.other.ImplPolymerRegistry;
import eu.pb4.polymer.core.mixin.client.CreativeInventoryScreenAccessor;
import eu.pb4.polymer.core.mixin.other.IdListAccessor;
import eu.pb4.polymer.core.mixin.other.ItemGroupsAccessor;
import eu.pb4.polymer.networking.api.client.PolymerClientNetworking;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
Expand Down Expand Up @@ -67,7 +68,12 @@ public class InternalClientRegistry {
public static final Int2ObjectMap<Identifier> ARMOR_TEXTURES_1 = new Int2ObjectOpenHashMap<>();
public static final Int2ObjectMap<Identifier> ARMOR_TEXTURES_2 = new Int2ObjectOpenHashMap<>();
public static final ImplPolymerRegistry<ClientPolymerBlock> BLOCKS = new ImplPolymerRegistry<>("block", "B", ClientPolymerBlock.NONE.identifier(), ClientPolymerBlock.NONE);
public static final IdList<ClientPolymerBlock.State> BLOCK_STATES = new IdList<>();
public static final IdList<ClientPolymerBlock.State> BLOCK_STATES = new IdList<>() {
@Override
public int size() {
return ((IdListAccessor) (Object) this).getList().size();
}
};
public static final ImplPolymerRegistry<ClientPolymerItem> ITEMS = new ImplPolymerRegistry<>("item", "I");
public static final ImplPolymerRegistry<ClientPolymerEntityType> ENTITY_TYPES = new ImplPolymerRegistry<>("entity_type", "E");
public static final ImplPolymerRegistry<ClientPolymerEntry<VillagerProfession>> VILLAGER_PROFESSIONS = new ImplPolymerRegistry<>("villager_profession", "VP");
Expand Down Expand Up @@ -109,15 +115,18 @@ private static Map<Identifier, ImplPolymerRegistry<ClientPolymerEntry<?>>> creat
}

public static ClientPolymerBlock.State getBlockAt(BlockPos pos) {
if (MinecraftClient.getInstance().world != null) {
var chunk = MinecraftClient.getInstance().world.getChunkManager().getChunk(
ChunkSectionPos.getSectionCoord(pos.getX()), ChunkSectionPos.getSectionCoord(pos.getZ()),
ChunkStatus.FULL,
true
);
try {
if (MinecraftClient.getInstance().world != null) {
var chunk = MinecraftClient.getInstance().world.getChunkManager().getChunk(
ChunkSectionPos.getSectionCoord(pos.getX()), ChunkSectionPos.getSectionCoord(pos.getZ()),
ChunkStatus.FULL,
true
);

return ((ClientBlockStorageInterface) chunk).polymer$getClientBlock(pos.getX(), pos.getY(), pos.getZ());
}
} catch (Throwable e) {}

return ((ClientBlockStorageInterface) chunk).polymer$getClientBlock(pos.getX(), pos.getY(), pos.getZ());
}

return ClientPolymerBlock.NONE_STATE;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package eu.pb4.polymer.core.impl.client.compat;

import eu.pb4.polymer.core.api.utils.PolymerObject;
import eu.pb4.polymer.core.impl.PolymerImplUtils;
import eu.pb4.polymer.core.impl.ImplPolymerRegistryEvent;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler;
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.texture.Sprite;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.FluidState;
import net.minecraft.registry.Registries;
import net.minecraft.util.math.BlockPos;
Expand All @@ -28,16 +27,10 @@ public Sprite[] getFluidSprites(@Nullable BlockRenderView view, @Nullable BlockP
}
};

for (var fluid : Registries.FLUID) {
ImplPolymerRegistryEvent.iterateAndRegister(Registries.FLUID, (fluid) -> {
if (fluid instanceof PolymerObject && FluidRenderHandlerRegistry.INSTANCE.get(fluid) == null) {
FluidRenderHandlerRegistry.INSTANCE.register(fluid, renderer);
}
}

PolymerImplUtils.ON_REGISTERED.register((reg, obj) -> {
if (obj instanceof Fluid fluid && fluid instanceof PolymerObject && FluidRenderHandlerRegistry.INSTANCE.get(fluid) == null) {
FluidRenderHandlerRegistry.INSTANCE.register(fluid, renderer);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import eu.pb4.polymer.core.api.client.*;
import eu.pb4.polymer.core.api.utils.PolymerClientDecoded;
import eu.pb4.polymer.core.impl.PolymerImplUtils;
import eu.pb4.polymer.core.impl.PolymerMetadataKeys;
import eu.pb4.polymer.core.impl.client.InternalClientRegistry;
import eu.pb4.polymer.core.impl.client.interfaces.ClientBlockStorageInterface;
import eu.pb4.polymer.core.impl.client.interfaces.ClientEntityExtension;
Expand All @@ -24,6 +25,7 @@
import net.minecraft.command.argument.BlockArgumentParser;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtInt;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
Expand All @@ -33,6 +35,7 @@
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkSectionPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.chunk.ChunkStatus;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -100,8 +103,10 @@ public static void register() {
InternalClientRegistry.setVersion(PolymerClientNetworking.getServerVersion());
});

PolymerClientNetworking.AFTER_DISABLE.register(() -> {
InternalClientRegistry.disable();
PolymerClientNetworking.AFTER_DISABLE.register(InternalClientRegistry::disable);

PolymerClientNetworking.BEFORE_METADATA_SYNC.register(() -> {
PolymerClientNetworking.setClientMetadata(PolymerMetadataKeys.BLOCKSTATE_BITS, NbtInt.of(MathHelper.ceilLog2(Block.STATE_IDS.size())));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public interface PolymerIdList<T> {
int polymer$getOffset();
void polymer$clear();

int polymer$getVanillaBitCount();

void polymer$setReorderLock(boolean value);
boolean polymer$getReorderLock();
}
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ private static <T> void sendSync(ServerPlayNetworkHandler handler, Identifier pa
}

public static void sendDebugValidateStatesPackets(ServerPlayNetworkHandler handler) {
var polymerHandler = PolymerNetworkHandlerExtension.of(handler);
var version = PolymerServerNetworking.getSupportedVersion(handler, ServerPackets.DEBUG_VALIDATE_STATES);

if (version != -1) {
Expand Down
Loading

0 comments on commit 1689879

Please sign in to comment.