Skip to content

Commit

Permalink
Fix villager professions on singleplayer, fix polymer packets decodin…
Browse files Browse the repository at this point in the history
…g to null blocks update fabric.mod.json
  • Loading branch information
Patbox committed Jul 26, 2023
1 parent 76247cf commit 8ebbcdb
Show file tree
Hide file tree
Showing 21 changed files with 105 additions and 78 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fabric_version=0.83.0+1.20.1

maven_group = eu.pb4

mod_version = 0.5.6-dev
mod_version = 0.5.6

minecraft_version_supported = ">=1.20-"

Expand Down
8 changes: 7 additions & 1 deletion polymer-autohost/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,11 @@
},
"mixins": [
"polymer-autohost.mixins.json"
]
],
"custom": {
"modmenu": {
"parent": "polymer-bundled",
"update_checker": false
}
}
}
4 changes: 3 additions & 1 deletion polymer-blocks/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
"modmenu": {
"badges": [
"library"
]
],
"parent": "polymer-bundled",
"update-checker": false
}
}
}
Binary file modified polymer-common/src/main/resources/assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added polymer-common/src/main/resources/assets/iconm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 10 additions & 2 deletions polymer-common/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"polymer-common.mixins.json"
],
"license": "LGPLv3",
"icon": "assets/icon.png",
"icon": "assets/iconm.png",
"environment": "*",
"depends": {
"minecraft": ">=1.20",
Expand All @@ -28,7 +28,15 @@
"custom": {
"modmenu": {
"badges": [ "library" ],
"discord": "https://pb4.eu/discord"
"discord": "https://pb4.eu/discord",
"parent": {
"id": "polymer-bundled",
"name": "Polymer",
"description": "Set of libraries for creation of better server driven content!",
"icon": "assets/icon.png",
"badges": [ "library" ]
},
"update_checker": false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public static BlockState getBlockStateSafely(PolymerBlock block, BlockState bloc
public static Block getBlockSafely(PolymerBlock block, BlockState state, int maxDistance, @Nullable ServerPlayerEntity player) {
int req = 0;
Block out = player != null
? block.getPolymerBlock(state)
? block.getPolymerBlock(state, player)
: block.getPolymerBlock(state);

while (out instanceof PolymerBlock newBlock && newBlock != block && req < maxDistance) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package eu.pb4.polymer.core.impl;

import eu.pb4.polymer.common.api.events.SimpleEvent;
import eu.pb4.polymer.common.impl.CompatStatus;
import eu.pb4.polymer.core.api.block.PolymerBlock;
import eu.pb4.polymer.core.api.item.PolymerItemUtils;
Expand Down Expand Up @@ -28,16 +27,13 @@
import net.minecraft.registry.Registry;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.state.property.Property;
import net.minecraft.text.TranslatableTextContent;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Collection;
import java.util.Locale;
import java.util.Objects;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.stream.Stream;

Expand Down Expand Up @@ -249,6 +245,12 @@ public static boolean shouldLogStateRebuild(StackTraceElement[] trace) {
return trace.length <= 4 || !trace[4].getClassName().startsWith("org.quiltmc.qsl.registry.impl.sync");
}

public static boolean removeFromItemGroup(ItemStack stack) {
if (stack == null) {
return true;
}
return isPolymerControlled(stack);
}
public static boolean isPolymerControlled(ItemStack stack) {
return PolymerItemUtils.isPolymerServerItem(stack) || PolymerItemUtils.getServerIdentifier(stack) != null || PolymerUtils.isServerOnly(stack);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import dev.emi.emi.api.stack.EmiStack;
import eu.pb4.polymer.core.impl.PolymerImpl;
import eu.pb4.polymer.core.impl.PolymerImplUtils;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.Version;
import org.jetbrains.annotations.ApiStatus;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import eu.pb4.polymer.common.impl.CommonImpl;
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.ClientMetadataKeys;
import eu.pb4.polymer.core.impl.PolymerImplUtils;
import eu.pb4.polymer.core.impl.ServerMetadataKeys;
import eu.pb4.polymer.core.impl.client.InternalClientRegistry;
import eu.pb4.polymer.core.impl.client.interfaces.ClientBlockStorageInterface;
Expand Down Expand Up @@ -99,9 +99,7 @@ public static void register() {
registerPacketHandler(ServerPackets.SYNC_ITEM_GROUP_REMOVE, (handler, version, buf) -> handleItemGroupRemove(handler, version, buf));
registerPacketHandler(ServerPackets.SYNC_ITEM_GROUP_APPLY_UPDATE, (handler, version, buf) -> handleItemGroupApplyUpdates(handler, version, buf));
registerPacketHandler(ServerPackets.SYNC_CLEAR, (handler, version, buf) -> {
MinecraftClient.getInstance().execute(() -> {
InternalClientRegistry.clear();
});
MinecraftClient.getInstance().execute(InternalClientRegistry::clear);
});
registerPacketHandler(ServerPackets.DEBUG_VALIDATE_STATES, (handler, version, buf) -> handleGenericSync(handler, version, buf, DebugBlockStateEntry::read, PolymerClientProtocolHandler::handleDebugValidateStates));

Expand Down Expand Up @@ -157,8 +155,7 @@ private static void handleDebugValidateStates(DebugBlockStateEntry entry) {
}
}

private static boolean handleSyncInfo(ClientPlayNetworkHandler handler, int version, PacketByteBuf buf) {
return true;
private static void handleSyncInfo(ClientPlayNetworkHandler handler, int version, PacketByteBuf buf) {
}

@Nullable
Expand Down Expand Up @@ -192,20 +189,18 @@ private static BlockState blockStateOrNull(Map<String, String> states, ClientPol
return null;
}

private static boolean handleItemGroupApplyUpdates(ClientPlayNetworkHandler handler, int version, PacketByteBuf buf) {
private static void handleItemGroupApplyUpdates(ClientPlayNetworkHandler handler, int version, PacketByteBuf buf) {
if (version > -1 && InternalClientRegistry.enabled) {
MinecraftClient.getInstance().execute(() -> {
if (ItemGroupsAccessor.getDisplayContext() != null) {
ItemGroupsAccessor.callUpdateEntries(ItemGroupsAccessor.getDisplayContext());
}
PolymerClientUtils.ON_SEARCH_REBUILD.invoke(EventRunners.RUN);
});
return true;
}
return false;
}

private static boolean handleItemGroupDefine(ClientPlayNetworkHandler handler, int version, PacketByteBuf buf) {
private static void handleItemGroupDefine(ClientPlayNetworkHandler handler, int version, PacketByteBuf buf) {
if (version > -1 && InternalClientRegistry.enabled) {
var id = buf.readIdentifier();
var name = buf.readText();
Expand All @@ -216,24 +211,20 @@ private static boolean handleItemGroupDefine(ClientPlayNetworkHandler handler, i
InternalClientRegistry.createItemGroup(id, name, icon);
});

return true;
}
return false;
}

private static boolean handleItemGroupRemove(ClientPlayNetworkHandler handler, int version, PacketByteBuf buf) {
private static void handleItemGroupRemove(ClientPlayNetworkHandler handler, int version, PacketByteBuf buf) {
if (version > -1 && InternalClientRegistry.enabled) {
var id = buf.readIdentifier();
MinecraftClient.getInstance().execute(() -> {
InternalClientRegistry.clearTabs((x) -> x.getIdentifier().equals(id));
});
return true;
}

return false;
}

private static boolean handleItemGroupContentsAdd(ClientPlayNetworkHandler handler, int version, PacketByteBuf buf) {
private static void handleItemGroupContentsAdd(ClientPlayNetworkHandler handler, int version, PacketByteBuf buf) {
if (version > -1 && InternalClientRegistry.enabled) {
var id = buf.readIdentifier();

Expand Down Expand Up @@ -277,12 +268,10 @@ private static boolean handleItemGroupContentsAdd(ClientPlayNetworkHandler handl
}
}
});
return true;
}
return false;
}

private static boolean handleItemGroupContentsClear(ClientPlayNetworkHandler handler, int version, PacketByteBuf buf) {
private static void handleItemGroupContentsClear(ClientPlayNetworkHandler handler, int version, PacketByteBuf buf) {
if (version > -1 && InternalClientRegistry.enabled) {
var id = buf.readIdentifier();
MinecraftClient.getInstance().execute(() -> {
Expand All @@ -294,12 +283,10 @@ private static boolean handleItemGroupContentsClear(ClientPlayNetworkHandler han
}

});
return true;
}
return false;
}

private static boolean handleEntity(ClientPlayNetworkHandler handler, int version, PacketByteBuf buf) {
private static void handleEntity(ClientPlayNetworkHandler handler, int version, PacketByteBuf buf) {
if (version > -1 && InternalClientRegistry.enabled) {
var id = buf.readVarInt();
var polymerId = buf.readIdentifier();
Expand All @@ -309,18 +296,16 @@ private static boolean handleEntity(ClientPlayNetworkHandler handler, int versio
((ClientEntityExtension) entity).polymer$setId(polymerId);
}
});
return true;
}
return false;
}

private static boolean handleSetBlock(ClientPlayNetworkHandler handler, int version, PacketByteBuf buf) {
private static void handleSetBlock(ClientPlayNetworkHandler handler, int version, PacketByteBuf buf) {
if (version == 2 && InternalClientRegistry.enabled) {
var pos = buf.readBlockPos();
var id = buf.readVarInt();
var block = InternalClientRegistry.BLOCK_STATES.get(id);
if (block != null) {
MinecraftClient.getInstance().execute(() -> {
MinecraftClient.getInstance().execute(() -> {
var block = InternalClientRegistry.BLOCK_STATES.get(id);
if (block != null) {
var chunk = MinecraftClient.getInstance().world.getChunkManager().getChunk(
ChunkSectionPos.getSectionCoord(pos.getX()), ChunkSectionPos.getSectionCoord(pos.getZ()),
ChunkStatus.FULL,
Expand All @@ -335,25 +320,24 @@ private static boolean handleSetBlock(ClientPlayNetworkHandler handler, int vers
chunk.setBlockState(pos, block.blockState(), false);
}
}
});
}
return true;
}
});

}
return false;
}

private static boolean handleWorldSectionUpdate(ClientPlayNetworkHandler handler, int version, PacketByteBuf buf) {
private static void handleWorldSectionUpdate(ClientPlayNetworkHandler handler, int version, PacketByteBuf buf) {
if (version == 2 && InternalClientRegistry.enabled) {
var sectionPos = buf.readChunkSectionPos();
var size = buf.readVarInt();

var blockPos = new short[size];
var states = new ClientPolymerBlock.State[size];
var states = new int[size];

for (int i = 0; i < size; i++) {
var value = buf.readVarLong();
blockPos[i] = (short) ((int) (value & 4095L));
states[i] = InternalClientRegistry.BLOCK_STATES.get((int) (value >>> 12));
states[i] = (int) (value >>> 12);
}

MinecraftClient.getInstance().execute(() -> {
Expand All @@ -369,7 +353,7 @@ private static boolean handleWorldSectionUpdate(ClientPlayNetworkHandler handler
var mutableBlockPos = new BlockPos.Mutable(0, 0, 0);
for (int i = 0; i < size; i++) {
var pos = blockPos[i];
var block = states[i];
var block = InternalClientRegistry.BLOCK_STATES.get(states[i]);
if (block != null) {
var x = ChunkSectionPos.unpackLocalX(pos);
var y = ChunkSectionPos.unpackLocalY(pos);
Expand All @@ -386,16 +370,14 @@ private static boolean handleWorldSectionUpdate(ClientPlayNetworkHandler handler
}
}
});
return true;

}
return false;
}


private static <T> boolean handleGenericSync(ClientPlayNetworkHandler handler, int version, PacketByteBuf buf, EntryReader<T> reader, Consumer<T> entryConsumer) {
private static <T> void handleGenericSync(ClientPlayNetworkHandler handler, int version, PacketByteBuf buf, EntryReader<T> reader, Consumer<T> entryConsumer) {
if (!InternalClientRegistry.enabled) {
return false;
return;
}
var size = buf.readVarInt();

Expand All @@ -412,7 +394,6 @@ private static <T> boolean handleGenericSync(ClientPlayNetworkHandler handler, i
entryConsumer.accept(entry);
}
});
return true;
}

interface EntryReader<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public abstract class ItemGroupMixin implements ClientItemGroupExtension {
@Inject(method = "updateEntries", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemGroup;reloadSearchProvider()V"))
private void polymer$injectEntriesVanilla(ItemGroup.DisplayContext arg, CallbackInfo ci) {
if (this.type == ItemGroup.Type.CATEGORY && ClientUtils.isClientThread()) {
this.displayStacks.removeIf(PolymerImplUtils::isPolymerControlled);
this.searchTabStacks.removeIf(PolymerImplUtils::isPolymerControlled);
this.displayStacks.removeIf(PolymerImplUtils::removeFromItemGroup);
this.searchTabStacks.removeIf(PolymerImplUtils::removeFromItemGroup);

this.displayStacks.addAll(this.polymer$itemsGroup);
this.searchTabStacks.addAll(this.polymer$itemsSearch);
Expand Down
Loading

0 comments on commit 8ebbcdb

Please sign in to comment.