Skip to content

Commit

Permalink
Initial update to snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed May 25, 2024
1 parent f1a3ab4 commit 1788861
Show file tree
Hide file tree
Showing 61 changed files with 267 additions and 471 deletions.
8 changes: 4 additions & 4 deletions docs/polymer-resource-pack/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ resource pack is build.
Example use:

```
PolymerModelData modelData = PolymerResourcePackUtils.requestModel(Items.IRON_SWORD, new Identifier("mymod", "item/silver_sword"));
PolymerModelData modelData = PolymerResourcePackUtils.requestModel(Items.IRON_SWORD, Identifier.of("mymod", "item/silver_sword"));
```

### Requesting armor textures
Expand All @@ -43,7 +43,7 @@ To apply it to your armor, you need to set your client side item to leather armo
Then you need to override `PolymerItem.getPolymerArmorColor()` method and return used color.

```
PolymerArmorModel armorModel = PolymerResourcePackUtils.requestArmor(new Identifier("mymod", "silver"));
PolymerArmorModel armorModel = PolymerResourcePackUtils.requestArmor(Identifier.of("mymod", "silver"));
```

## Checking players
Expand All @@ -56,9 +56,9 @@ Example use:
Identifier font;
if (PolymerResourcePackUtils.hasPack(player)) {
font = new Identifier("mymod", "myfont");
font = Identifier.of("mymod", "myfont");
} else {
font = new Identifier("minecraft", "default");
font = Identifier.of("minecraft", "default");
}
```

Expand Down
15 changes: 8 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ org.gradle.jvmargs=-Xmx4G

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

#Fabric api
fabric_version=0.97.6+1.20.6
minecraft_version=24w21b
yarn_mappings=24w21b+build.5
loader_version=0.15.11

# Fabric API
fabric_version=0.99.1+1.21

maven_group = eu.pb4

mod_version = 0.8.1
mod_version = 0.9.0-alpha

minecraft_version_supported = ">=1.20.5-"

packet_tweaker_version = 0.5.3+1.20.6

is_stable = true
is_stable = false
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ public static Path getPath(String path) {

@Override
public void onInitialize() {
ResourcePackDataProvider.register(new Identifier("polymer", "automatic"), NettyProvider::new);
ResourcePackDataProvider.register(new Identifier("polymer", "auto"), NettyProvider::new);
ResourcePackDataProvider.register(new Identifier("polymer", "netty"), NettyProvider::new);
ResourcePackDataProvider.register(new Identifier("polymer", "same_port"), NettyProvider::new);
ResourcePackDataProvider.register(new Identifier("polymer", "http_server"), StandaloneWebServerProvider::new);
ResourcePackDataProvider.register(new Identifier("polymer", "standalone"), StandaloneWebServerProvider::new);
ResourcePackDataProvider.register(new Identifier("polymer", "empty"), EmptyProvider::new);
ResourcePackDataProvider.register(Identifier.of("polymer", "automatic"), NettyProvider::new);
ResourcePackDataProvider.register(Identifier.of("polymer", "auto"), NettyProvider::new);
ResourcePackDataProvider.register(Identifier.of("polymer", "netty"), NettyProvider::new);
ResourcePackDataProvider.register(Identifier.of("polymer", "same_port"), NettyProvider::new);
ResourcePackDataProvider.register(Identifier.of("polymer", "http_server"), StandaloneWebServerProvider::new);
ResourcePackDataProvider.register(Identifier.of("polymer", "standalone"), StandaloneWebServerProvider::new);
ResourcePackDataProvider.register(Identifier.of("polymer", "empty"), EmptyProvider::new);

CommonImplUtils.registerDevCommands((c) -> {
c.then(literal("reload_resourcepack").executes(context -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public class DefaultModelData {
generateDefault(BlockModelType.CACTUS_BLOCK, Blocks.CACTUS);

{
var farmland = new PolymerBlockModel[]{PolymerBlockModel.of(new Identifier("minecraft:block/farmland"))};
var farmland = new PolymerBlockModel[]{PolymerBlockModel.of(Identifier.of("minecraft:block/farmland"))};
MODELS.put(Blocks.FARMLAND.getDefaultState().with(FarmlandBlock.MOISTURE, 1), farmland);
MODELS.put(Blocks.FARMLAND.getDefaultState().with(FarmlandBlock.MOISTURE, 7), new PolymerBlockModel[]{PolymerBlockModel.of(new Identifier("minecraft:block/farmland_moist"))});
MODELS.put(Blocks.FARMLAND.getDefaultState().with(FarmlandBlock.MOISTURE, 7), new PolymerBlockModel[]{PolymerBlockModel.of(Identifier.of("minecraft:block/farmland_moist"))});


var list = new ArrayList<BlockState>();
Expand All @@ -51,7 +51,7 @@ public class DefaultModelData {

for (var block : new Block[]{Blocks.TWISTING_VINES, Blocks.WEEPING_VINES}) {
var id = Registries.BLOCK.getId(block);
var model = new PolymerBlockModel[]{PolymerBlockModel.of(new Identifier(id.getNamespace() + ":block/" + id.getPath()))};
var model = new PolymerBlockModel[]{PolymerBlockModel.of(Identifier.of(id.getNamespace() + ":block/" + id.getPath()))};
for (var state : block.getStateManager().getStates()) {
MODELS.put(state, model);
}
Expand All @@ -62,8 +62,8 @@ public class DefaultModelData {

{
var id = Registries.BLOCK.getId(Blocks.CAVE_VINES);
var model = new PolymerBlockModel[]{PolymerBlockModel.of(new Identifier(id.getNamespace() + ":block/" + id.getPath()))};
var model2 = new PolymerBlockModel[]{PolymerBlockModel.of(new Identifier(id.getNamespace() + ":block/" + id.getPath() + "_lit"))};
var model = new PolymerBlockModel[]{PolymerBlockModel.of(Identifier.of(id.getNamespace() + ":block/" + id.getPath()))};
var model2 = new PolymerBlockModel[]{PolymerBlockModel.of(Identifier.of(id.getNamespace() + ":block/" + id.getPath() + "_lit"))};
for (var state : Blocks.CAVE_VINES.getStateManager().getStates()) {
var berries = state.get(CaveVines.BERRIES);
MODELS.put(state, berries ? model2 : model);
Expand All @@ -84,7 +84,7 @@ public class DefaultModelData {

{
var id = Registries.BLOCK.getId(Blocks.SUGAR_CANE);
var model = new PolymerBlockModel[]{PolymerBlockModel.of(new Identifier(id.getNamespace() + ":block/" + id.getPath()))};
var model = new PolymerBlockModel[]{PolymerBlockModel.of(Identifier.of(id.getNamespace() + ":block/" + id.getPath()))};
for (var state : Blocks.SUGAR_CANE.getStateManager().getStates()) {
MODELS.put(state, model);
}
Expand All @@ -102,7 +102,7 @@ public class DefaultModelData {
for (var block : new Block[]{Blocks.OAK_SAPLING, Blocks.BIRCH_SAPLING, Blocks.SPRUCE_SAPLING, Blocks.JUNGLE_SAPLING, Blocks.ACACIA_SAPLING, Blocks.DARK_OAK_SAPLING}) {
var id = Registries.BLOCK.getId(block);

var model = new PolymerBlockModel[]{PolymerBlockModel.of(new Identifier(id.getNamespace() + ":block/" + id.getPath()))};
var model = new PolymerBlockModel[]{PolymerBlockModel.of(Identifier.of(id.getNamespace() + ":block/" + id.getPath()))};
for (var state : block.getStateManager().getStates()) {
MODELS.put(state, model);
}
Expand All @@ -124,7 +124,7 @@ private static void generateDefault(BlockModelType type, Predicate<BlockState> s

for (var block : blocks) {
var id = Registries.BLOCK.getId(block);
var model = new PolymerBlockModel[]{PolymerBlockModel.of(new Identifier(id.getNamespace() + ":block/" + id.getPath()))};
var model = new PolymerBlockModel[]{PolymerBlockModel.of(Identifier.of(id.getNamespace() + ":block/" + id.getPath()))};
for (var state : block.getStateManager().getStates()) {
MODELS.put(state, model);
if (shouldInclude.test(state)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public TestBlock(Settings settings, BlockModelType type, String modelId) {

this.polymerBlockState = PolymerBlockResourceUtils.requestBlock(
type,
PolymerBlockModel.of(new Identifier("blocktest", modelId)));
PolymerBlockModel.of(Identifier.of("blocktest", modelId)));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import net.minecraft.util.Identifier;

public class TestInitializer implements ModInitializer {
//public static final PolymerItemGroupUtils ITEM_GROUP = PolymerItemGroupUtils.create(new Identifier("test/textured_blocks"), Text.literal("Textured blocks"), () -> new ItemStack(Items.BAMBOO));
//public static final PolymerItemGroupUtils ITEM_GROUP = PolymerItemGroupUtils.create(Identifier.of("test/textured_blocks"), Text.literal("Textured blocks"), () -> new ItemStack(Items.BAMBOO));

@Override
public void onInitialize() {
Expand All @@ -27,7 +27,7 @@ public void onInitialize() {
}

public static void register(BlockModelType type, String modelId) {
var id = new Identifier("blocktest", modelId);
var id = Identifier.of("blocktest", modelId);
var block = Registry.register(Registries.BLOCK, id,
new TestBlock(FabricBlockSettings.copy(Blocks.DIAMOND_BLOCK), type, modelId));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class TestItem extends BlockItem implements PolymerItem {

public TestItem(Settings settings, Block block, String modelId) {
super(block, settings);
this.polymerModel = PolymerResourcePackUtils.requestModel(Items.BARRIER, new Identifier("blocktest", modelId));
this.polymerModel = PolymerResourcePackUtils.requestModel(Items.BARRIER, Identifier.of("blocktest", modelId));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static String shortId(Identifier key) {
}

public static Identifier id(String s) {
return new Identifier("polymer", s);
return Identifier.of("polymer", s);
}

public static boolean isMainPlayer(ServerPlayerEntity player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public Lifecycle getLifecycle() {
return Lifecycle.experimental();
}

@Override
public Optional<RegistryEntry.Reference<T>> getDefaultEntry() {
return Optional.empty();
}

@Override
public Set<Identifier> getIds() {
return Set.of(defaultId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ public final class FakeWorld extends World implements LightSourceView {
static final Scoreboard SCOREBOARD = new Scoreboard();

static final DynamicRegistryManager FALLBACK_REGISTRY_MANAGER = new DynamicRegistryManager.Immutable() {
private final FakeRegistry<DamageType> damageTypes = new FakeRegistry<>(RegistryKeys.DAMAGE_TYPE, new Identifier("polymer","fake_damage"),
private final FakeRegistry<DamageType> damageTypes = new FakeRegistry<>(RegistryKeys.DAMAGE_TYPE, Identifier.of("polymer","fake_damage"),
new DamageType("", DamageScaling.NEVER, 0));
private final FakeRegistry<BannerPattern> bannerPatterns = new FakeRegistry<>(RegistryKeys.BANNER_PATTERN,
new Identifier("polymer","fake_pattern"),
new BannerPattern(new Identifier("polymer","fake_pattern"), ""));
Identifier.of("polymer","fake_pattern"),
new BannerPattern(Identifier.of("polymer","fake_pattern"), ""));
@Override
public Optional<Registry> getOptional(RegistryKey key) {
var x = Registries.REGISTRIES.get(key);
Expand Down Expand Up @@ -213,7 +213,7 @@ public int getTickCount() {
World worldUnsafe, worldDefault;

var dimType = RegistryEntry.Reference.intrusive(new RegistryEntryOwner<>() {}, new DimensionType(OptionalLong.empty(), true, false, false, true, 1.0D, true, false, -64, 384, 384, BlockTags.INFINIBURN_OVERWORLD, DimensionTypes.OVERWORLD_ID, 0.0F, new DimensionType.MonsterSettings(false, true, UniformIntProvider.create(0, 7), 0)));
((ReferenceAccessor) dimType).callSetRegistryKey(RegistryKey.of(RegistryKeys.DIMENSION_TYPE, new Identifier("overworld")));
((ReferenceAccessor) dimType).callSetRegistryKey(RegistryKey.of(RegistryKeys.DIMENSION_TYPE, Identifier.of("overworld")));
try {
worldUnsafe = (FakeWorld) UnsafeAccess.UNSAFE.allocateInstance(FakeWorld.class);
var accessor = (WorldAccessor) worldUnsafe;
Expand All @@ -222,7 +222,7 @@ public int getTickCount() {
accessor.polymer$setDebugWorld(true);
accessor.polymer$setProfiler(() -> new ProfilerSystem(() -> 0l, () -> 0, false));
accessor.polymer$setProperties(new FakeWorldProperties());
accessor.polymer$setRegistryKey(RegistryKey.of(RegistryKeys.WORLD, new Identifier("polymer","fake_world")));
accessor.polymer$setRegistryKey(RegistryKey.of(RegistryKeys.WORLD, Identifier.of("polymer","fake_world")));
//accessor.polymer$setDimensionKey(DimensionTypes.OVERWORLD);
accessor.polymer$setDimensionEntry(dimType);
accessor.polymer$setThread(Thread.currentThread());
Expand All @@ -244,7 +244,7 @@ public int getTickCount() {
try {
worldDefault = new FakeWorld(
new FakeWorldProperties(),
RegistryKey.of(RegistryKeys.WORLD, new Identifier("polymer", "fake_world")),
RegistryKey.of(RegistryKeys.WORLD, Identifier.of("polymer", "fake_world")),
dimType,
() -> new ProfilerSystem(() -> 0l, () -> 0, false),
false,
Expand Down Expand Up @@ -322,7 +322,7 @@ public void putMapState(MapIdComponent id, MapState state) {
}

@Override
public MapIdComponent getNextMapId() {
public MapIdComponent increaseAndGetMapId() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import eu.pb4.polymer.rsm.api.RegistrySyncUtils;
import it.unimi.dsi.fastutil.objects.ObjectOpenCustomHashSet;
import net.minecraft.client.item.TooltipType;
import net.minecraft.component.DataComponentType;
import net.minecraft.component.ComponentType;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.*;
import net.minecraft.item.BlockPredicatesChecker;
Expand Down Expand Up @@ -81,7 +81,7 @@ public final class PolymerItemUtils {
* You can also return new ItemStack, however please keep previous nbt so other modifications aren't removed if not needed!
*/
public static final FunctionEvent<ItemModificationEventHandler, ItemStack> ITEM_MODIFICATION_EVENT = new FunctionEvent<>();
private static final DataComponentType<?>[] COMPONENTS_TO_COPY = {DataComponentTypes.CAN_BREAK, DataComponentTypes.CAN_PLACE_ON,
private static final ComponentType<?>[] COMPONENTS_TO_COPY = {DataComponentTypes.CAN_BREAK, DataComponentTypes.CAN_PLACE_ON,
DataComponentTypes.BLOCK_ENTITY_DATA, DataComponentTypes.TRIM,
DataComponentTypes.TOOL,
DataComponentTypes.MAX_STACK_SIZE,
Expand Down Expand Up @@ -116,7 +116,7 @@ public final class PolymerItemUtils {
HideableTooltip.of(DataComponentTypes.CAN_BREAK, BlockPredicatesChecker::withShowInTooltip),
HideableTooltip.of(DataComponentTypes.CAN_PLACE_ON, BlockPredicatesChecker::withShowInTooltip)
);
private static final Set<DataComponentType<?>> UNSYNCED_COMPONENTS = new ObjectOpenCustomHashSet<>(CommonImplUtils.IDENTITY_HASH);
private static final Set<ComponentType<?>> UNSYNCED_COMPONENTS = new ObjectOpenCustomHashSet<>(CommonImplUtils.IDENTITY_HASH);

private PolymerItemUtils() {
}
Expand Down Expand Up @@ -359,7 +359,7 @@ public static ItemStack createMinimalItemStack(ItemStack itemStack, RegistryWrap
));
});
} catch (Throwable e) {
out.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT.with(POLYMER_STACK_ID_CODEC, Registries.ITEM.getId(itemStack.getItem())).getOrThrow());
out.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT.with(RegistryOps.of(NbtOps.INSTANCE, lookup), POLYMER_STACK_ID_CODEC, Registries.ITEM.getId(itemStack.getItem())).getOrThrow());
}

if (cmd != -1) {
Expand Down Expand Up @@ -429,10 +429,10 @@ public static ItemStack createItemStack(ItemStack itemStack, TooltipType tooltip

if (x instanceof TransformingDataComponent t) {
//noinspection unchecked,rawtypes
out.set((DataComponentType) key, t.polymer$getTransformed(player));
out.set((ComponentType) key, t.polymer$getTransformed(player));
} else {
//noinspection unchecked,rawtypes
out.set((DataComponentType) key, (Object) itemStack.get(key));
out.set((ComponentType) key, (Object) itemStack.get(key));
}
}
try {
Expand All @@ -442,13 +442,13 @@ public static ItemStack createItemStack(ItemStack itemStack, TooltipType tooltip
.encodeStart(RegistryOps.of(NbtOps.INSTANCE, lookup), itemStack).getOrThrow()
);
if (storeCount) {
out.set(DataComponentTypes.CUSTOM_DATA, comp.with(POLYMER_STACK_HAS_COUNT_CODEC, true).getOrThrow());
out.set(DataComponentTypes.CUSTOM_DATA, comp.with(RegistryOps.of(NbtOps.INSTANCE, lookup), POLYMER_STACK_HAS_COUNT_CODEC, true).getOrThrow());
} else {
out.set(DataComponentTypes.CUSTOM_DATA, comp);
}
});
} catch (Throwable e) {
out.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT.with(POLYMER_STACK_ID_CODEC, Registries.ITEM.getId(itemStack.getItem())).getOrThrow());
out.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT.with(RegistryOps.of(NbtOps.INSTANCE, lookup), POLYMER_STACK_ID_CODEC, Registries.ITEM.getId(itemStack.getItem())).getOrThrow());
}


Expand Down Expand Up @@ -544,14 +544,14 @@ public static ItemWithMetadata getItemSafely(PolymerItem item, ItemStack stack,
return getItemSafely(item, stack, player, PolymerBlockUtils.NESTED_DEFAULT_DISTANCE);
}

public static void markAsPolymer(DataComponentType<?>... types) {
public static void markAsPolymer(ComponentType<?>... types) {
for (var x : types) {
UNSYNCED_COMPONENTS.add(x);
RegistrySyncUtils.setServerEntry(Registries.DATA_COMPONENT_TYPE, x);
}
}

public static boolean isPolymerComponent(DataComponentType<?> type) {
public static boolean isPolymerComponent(ComponentType<?> type) {
return UNSYNCED_COMPONENTS.add(type);
}

Expand All @@ -571,17 +571,17 @@ public interface ItemModificationEventHandler {
public record ItemWithMetadata(Item item, int customModelData, int color) {
}

private record HideableTooltip<T>(DataComponentType<T> type, Predicate<T> shouldSet, TooltipSetter<T> setter) {
private record HideableTooltip<T>(ComponentType<T> type, Predicate<T> shouldSet, TooltipSetter<T> setter) {

public static <T> HideableTooltip<T> of(DataComponentType<T> type, TooltipSetter<T> setter) {
public static <T> HideableTooltip<T> of(ComponentType<T> type, TooltipSetter<T> setter) {
return new HideableTooltip<>(type, x -> true, setter);
}

public static <T> HideableTooltip<T> of(DataComponentType<T> type, Predicate<T> shouldSet, TooltipSetter<T> setter) {
public static <T> HideableTooltip<T> of(ComponentType<T> type, Predicate<T> shouldSet, TooltipSetter<T> setter) {
return new HideableTooltip<>(type, shouldSet, setter);
}

public static <T> HideableTooltip<T> ofNeg(DataComponentType<T> type, Predicate<T> shouldntSet, TooltipSetter<T> setter) {
public static <T> HideableTooltip<T> ofNeg(ComponentType<T> type, Predicate<T> shouldntSet, TooltipSetter<T> setter) {
return new HideableTooltip<>(type, shouldntSet.negate(), setter);
}

Expand Down
Loading

0 comments on commit 1788861

Please sign in to comment.