Skip to content

Commit

Permalink
0.2.0-beta.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Nov 23, 2021
1 parent 4ce613b commit 68834b9
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 55 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ loader_version=0.12.5
fabric_version=0.42.6+1.18

# Mod Properties
mod_version = 0.2.0-alpha.5
mod_version = 0.2.0-beta.1
maven_group = eu.pb4
archives_base_name = polymer

Expand Down
6 changes: 2 additions & 4 deletions legacy/src/main/java/eu/pb4/polymer/PolymerMod.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package eu.pb4.polymer;

import eu.pb4.polymer.block.BlockHelper;
import eu.pb4.polymer.impl.PolymerImpl;
import eu.pb4.polymer.impl.compat.CompatStatus;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;


import net.minecraft.util.Identifier;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.ApiStatus;

Expand All @@ -17,7 +15,7 @@
public class PolymerMod implements ModInitializer {
public static final boolean POLYMC_COMPAT = CompatStatus.POLYMC;

public static final Logger LOGGER = LogManager.getLogger("Polymer (Legacy)");
public static final Logger LOGGER = PolymerImpl.LOGGER;

@Override
public void onInitialize() {
Expand Down
2 changes: 0 additions & 2 deletions legacy/src/main/java/eu/pb4/polymer/PolymerUtils.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package eu.pb4.polymer;

import eu.pb4.polymer.api.block.PolymerBlockUtils;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.network.Packet;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/eu/pb4/polymer/api/block/PolymerBlockUtils.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package eu.pb4.polymer.api.block;

import eu.pb4.polymer.api.utils.events.BooleanEvent;
import eu.pb4.polymer.impl.interfaces.PolymerBlockPosStorage;
import it.unimi.dsi.fastutil.objects.Object2BooleanMap;
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
import net.minecraft.block.Block;
Expand All @@ -11,15 +10,16 @@
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkSectionPos;
import net.minecraft.world.chunk.WorldChunk;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.function.BiPredicate;
import java.util.function.Predicate;

public final class PolymerBlockUtils {
private PolymerBlockUtils() {
}

public static final int NESTED_DEFAULT_DISTANCE = 32;
public static final int BLOCK_STATE_OFFSET = Integer.MAX_VALUE / 64;

Expand Down
14 changes: 2 additions & 12 deletions src/main/java/eu/pb4/polymer/api/block/PolymerHeadBlock.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package eu.pb4.polymer.api.block;

import eu.pb4.polymer.api.utils.PolymerUtils;
import eu.pb4.polymer.mixin.block.BlockEntityUpdateS2CPacketAccessor;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
Expand Down Expand Up @@ -32,18 +33,7 @@ default Block getPolymerBlock() {
* @return NbtCompound representing client-side
*/
default NbtCompound getPolymerHeadSkullOwner(BlockState state) {
NbtCompound skullOwner = new NbtCompound();
NbtCompound properties = new NbtCompound();
NbtCompound data = new NbtCompound();
NbtList textures = new NbtList();
textures.add(data);

data.putString("Value", ((PolymerHeadBlock) state.getBlock()).getPolymerSkinValue(state));
properties.put("textures", textures);
skullOwner.put("Properties", properties);
skullOwner.putIntArray("Id", new int[] { 0, 0, 0, 0 });

return skullOwner;
return PolymerUtils.createSkullOwner(((PolymerHeadBlock) state.getBlock()).getPolymerSkinValue(state));
}

/**
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/eu/pb4/polymer/api/client/PolymerClientUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,26 @@

import eu.pb4.polymer.api.client.registry.ClientPolymerBlock;
import eu.pb4.polymer.api.client.registry.ClientPolymerEntityType;
import eu.pb4.polymer.api.client.registry.ClientPolymerItem;
import eu.pb4.polymer.api.utils.events.BooleanEvent;
import eu.pb4.polymer.api.utils.events.SimpleEvent;
import eu.pb4.polymer.impl.client.InternalClientRegistry;
import eu.pb4.polymer.impl.client.interfaces.ClientEntityExtension;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
* General utilities while dealing with client side integrations
*/
public final class PolymerClientUtils {
private PolymerClientUtils() {
}

public static final SimpleEvent<Runnable> ON_HANDSHAKE = new SimpleEvent<>();
public static final SimpleEvent<Runnable> ON_CLEAR = new SimpleEvent<>();
public static final SimpleEvent<Runnable> ON_SYNC_STARTED = new SimpleEvent<>();
public static final SimpleEvent<Runnable> ON_SYNC_FINISHED = new SimpleEvent<>();
public static final SimpleEvent<Runnable> ON_SEARCH_REBUILD = new SimpleEvent<>();

@Nullable
public static ClientPolymerBlock.State getPolymerStateAt(BlockPos pos) {
return InternalClientRegistry.getBlockAt(pos);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package eu.pb4.polymer.api.entity;

import eu.pb4.polymer.impl.other.InternalEntityHelpers;
import eu.pb4.polymer.mixin.entity.EntityAccessor;
import eu.pb4.polymer.mixin.entity.PlayerSpawnS2CPacketAccessor;
import eu.pb4.polymer.impl.other.InternalEntityHelpers;
import io.netty.util.internal.shaded.org.jctools.util.UnsafeAccess;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
Expand All @@ -15,7 +15,10 @@
import java.util.List;
import java.util.UUID;

public class PolymerEntityUtils {
public final class PolymerEntityUtils {
private PolymerEntityUtils() {
}

private static final HashSet<EntityType<?>> ENTITY_IDENTIFIERS = new HashSet<>();

/**
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/eu/pb4/polymer/api/item/PolymerItemGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public final class PolymerItemGroup extends ItemGroup implements PolymerObject {
/**
* Even called on synchronization of PolymerItemGroups
*/
public static final SimpleEvent<ItemGroupListEventListener> LIST_EVENT = new SimpleEvent<>();
public static final SimpleEvent<ItemGroupEventListener> LIST_EVENT = new SimpleEvent<>();
public static List<ItemStack> items = new ArrayList<>();
private final Text name;
private final Identifier identifier;
Expand Down Expand Up @@ -94,12 +94,12 @@ public boolean shouldSyncWithPolymerClient(ServerPlayerEntity player) {
}

@FunctionalInterface
public interface ItemGroupListEventListener {
void onItemGroupSync(ServerPlayerEntity player, ItemGroupSyncer helper);
public interface ItemGroupEventListener {
void onItemGroupSync(ServerPlayerEntity player, ItemGroupListBuilder builder);
}

public interface ItemGroupSyncer {
void send(PolymerItemGroup group);
public interface ItemGroupListBuilder {
void add(PolymerItemGroup group);

void remove(PolymerItemGroup group);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
import eu.pb4.polymer.api.item.PolymerItemGroup;
import eu.pb4.polymer.impl.interfaces.PolymerNetworkHandlerExtension;
import eu.pb4.polymer.impl.networking.PacketUtils;
import eu.pb4.polymer.impl.networking.PolymerServerProtocolHandler;
import eu.pb4.polymer.impl.networking.ServerPackets;
import eu.pb4.polymer.impl.networking.PolymerServerProtocol;
import net.minecraft.network.PacketByteBuf;
import eu.pb4.polymer.impl.networking.ServerPackets;
import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.ApiStatus;

public final class PolymerSyncUtils {
private PolymerSyncUtils(){};
private PolymerSyncUtils() {
}

/**
* Resends synchronization packets to player if their client supports that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@

import net.minecraft.util.Identifier;

/**
* Represents information about armor texture
*/
public record PolymerArmorModel(int value, Identifier modelPath) {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
import net.minecraft.item.Item;
import net.minecraft.util.Identifier;

/**
* Represents information about CustomModelData of item
*/
public record PolymerModelData(Item item, int value, Identifier modelPath) {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import eu.pb4.polymer.api.utils.events.SimpleEvent;
import eu.pb4.polymer.impl.PolymerImpl;
import eu.pb4.polymer.impl.PolymerMod;
import eu.pb4.polymer.impl.client.ClientUtils;
import eu.pb4.polymer.impl.compat.CompatStatus;
import eu.pb4.polymer.impl.interfaces.PolymerNetworkHandlerExtension;
Expand All @@ -24,7 +23,10 @@
/**
* Utilities allowing creation of single, polymer mod compatible resource pack
*/
public class PolymerRPUtils {
public final class PolymerRPUtils {
private PolymerRPUtils() {
}

public static final SimpleEvent<Consumer<PolymerRPBuilder>> RESOURCE_PACK_CREATION_EVENT = new SimpleEvent<>();
private static final Object2ObjectMap<Item, List<PolymerModelData>> ITEMS = new Object2ObjectArrayMap<>();
private static final Set<String> MOD_IDS = new HashSet<>();
Expand Down Expand Up @@ -53,10 +55,11 @@ public static PolymerModelData requestModel(Item vanillaItem, Identifier modelPa
cmdInfoList.add(cmdInfo);
return cmdInfo;
}

/**
* This method can be used to register custom model data for items
*
* @param modelPath Path to model in resource pack
* @param modelPath Path to model in resource pack
* @return PolymerArmorModel with data about this model
*/
public static PolymerArmorModel requestArmor(Identifier modelPath) {
Expand Down
50 changes: 43 additions & 7 deletions src/main/java/eu/pb4/polymer/api/utils/PolymerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import eu.pb4.polymer.api.item.PolymerItemGroup;
import eu.pb4.polymer.api.networking.PolymerSyncUtils;
import eu.pb4.polymer.impl.InternalServerRegistry;
import eu.pb4.polymer.impl.interfaces.PolymerNetworkHandlerExtension;
import eu.pb4.polymer.impl.client.ClientUtils;
import eu.pb4.polymer.impl.interfaces.PolymerNetworkHandlerExtension;
import eu.pb4.polymer.mixin.block.packet.ThreadedAnvilChunkStorageAccessor;
import eu.pb4.polymer.mixin.entity.ServerWorldAccessor;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
import net.minecraft.network.Packet;
import net.minecraft.network.packet.s2c.play.InventoryS2CPacket;
import net.minecraft.server.network.ServerPlayNetworkHandler;
Expand All @@ -23,7 +25,10 @@
/**
* General use case utils that can be useful in multiple situations
*/
public class PolymerUtils {
public final class PolymerUtils {
private PolymerUtils() {
}

public static final String ID = "polymer";

/**
Expand Down Expand Up @@ -72,8 +77,9 @@ public static boolean isOnPlayerNetworking() {

/**
* Schedules a packet sending
* @param handler used for packet sending
* @param packet sent packet
*
* @param handler used for packet sending
* @param packet sent packet
* @param duration time (in ticks) waited before packet is send
*/
public static void schedulePacket(ServerPlayNetworkHandler handler, Packet<?> packet, int duration) {
Expand All @@ -92,16 +98,25 @@ public static void reloadWorld(ServerPlayerEntity player) {
tracker.stopTracking(player);
tracker.updateTrackedStatus(player);
}
};
}

/**
* Resends inventory to player
*/
public static void reloadInventory(ServerPlayerEntity player) {
player.networkHandler.sendPacket(new InventoryS2CPacket(0, 0, player.playerScreenHandler.getStacks(), player.playerScreenHandler.getCursorStack()));
}

/**
* Returns current TooltipContext of player,
*/
public static TooltipContext getTooltipContext(@Nullable ServerPlayerEntity player) {
return player != null && player.networkHandler instanceof PolymerNetworkHandlerExtension h && h.polymer_advancedTooltip() ? TooltipContext.Default.ADVANCED : TooltipContext.Default.NORMAL;
}

/**
* Returns list of ItemGroups accessible by player
*/
public static List<PolymerItemGroup> getItemGroups(ServerPlayerEntity player) {
var list = new ArrayList<PolymerItemGroup>();

Expand All @@ -111,9 +126,9 @@ public static List<PolymerItemGroup> getItemGroups(ServerPlayerEntity player) {
}
}

var sync = new PolymerItemGroup.ItemGroupSyncer() {
var sync = new PolymerItemGroup.ItemGroupListBuilder() {
@Override
public void send(PolymerItemGroup group) {
public void add(PolymerItemGroup group) {
list.add(group);
}

Expand All @@ -127,4 +142,25 @@ public void remove(PolymerItemGroup group) {

return list;
}

/**
* Creates SkullOwner NbtCompound from provided skin value
*
* @param value Skin value
* @return NbtCompound representing SkullOwner
*/
public static NbtCompound createSkullOwner(String value) {
NbtCompound skullOwner = new NbtCompound();
NbtCompound properties = new NbtCompound();
NbtCompound data = new NbtCompound();
NbtList textures = new NbtList();
textures.add(data);

data.putString("Value", value);
properties.put("textures", textures);
skullOwner.put("Properties", properties);
skullOwner.putIntArray("Id", new int[]{0, 0, 0, 0});

return skullOwner;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ public static void sendCreativeSyncPackets(ServerPlayNetworkHandler handler) {
}
}

var sync = new PolymerItemGroup.ItemGroupSyncer() {
var sync = new PolymerItemGroup.ItemGroupListBuilder() {
@Override
public void send(PolymerItemGroup group) {
public void add(PolymerItemGroup group) {
list.add(group);
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/eu/pb4/polymer/impl/package-info.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/**
* Internal use only!
*
* If you call anything in this package, it might break in any patch and minor release
*/
@ApiStatus.Internal
package eu.pb4.polymer.impl;
Expand Down
2 changes: 1 addition & 1 deletion src/testmod/java/eu/pb4/polymertest/TestMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public void onInitialize() {

PolymerItemGroup.LIST_EVENT.register((p, s) -> {
if (atomicBoolean.get()) {
s.send(ITEM_GROUP_2);
s.add(ITEM_GROUP_2);
}
});

Expand Down

0 comments on commit 68834b9

Please sign in to comment.