Skip to content

Commit

Permalink
Update to 1.19.3 (Polymer Port)
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Dec 17, 2022
1 parent b532bb2 commit 10373bf
Show file tree
Hide file tree
Showing 19 changed files with 49 additions and 34 deletions.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@ dependencies {
modImplementation include("dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${project.cca_version}")

modImplementation include("eu.pb4:sgui:${project.sgui_version}")
modImplementation include("eu.pb4:polymer:${project.polymer_version}")
modImplementation include("eu.pb4:polymer-resource-pack:${project.polymer_version}")
modImplementation include("eu.pb4:player-data-api:${project.pda_version}")
modImplementation include("fr.catcore:server-translations-api:${project.translation_version}")


modLocalRuntime "eu.pb4:polymer-autohost:${project.polymer_version}"
modCompileOnly "eu.pb4:polymer-core:${project.polymer_version}"
modLocalRuntime "eu.pb4:polymer-core:${project.polymer_version}"

// Dev Runtime
testmodImplementation sourceSets.main.output
//modLocalRuntime "com.terraformersmc:modmenu:${project.mod_menu_version}"
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ port_version=1
polymer_version=0.3.1+1.19.3
sgui_version=1.2.0+1.19.3
translation_version=1.4.19+1.19.3
pda_version=0.2.3+1.19.3
pda_version=0.2.2+1.19.3
4 changes: 1 addition & 3 deletions src/main/java/dev/emi/trinkets/api/Trinket.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import net.minecraft.sound.SoundEvents;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.registry.Registry;

public interface Trinket {

Expand Down Expand Up @@ -133,7 +131,7 @@ default Multimap<EntityAttribute, EntityAttributeModifier> getModifiers(ItemStac
* @param entity The entity that is breaking the stack
*/
default void onBreak(ItemStack stack, SlotReference slot, LivingEntity entity) {
((LivingEntityAccessor) entity).invokePlayEquipmentBreakEffects(stack);

}

default TrinketEnums.DropRule getDropRule(ItemStack stack, SlotReference slot, LivingEntity entity) {
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/dev/emi/trinkets/api/TrinketsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@
import net.minecraft.network.PacketByteBuf;
import net.minecraft.particle.ItemStackParticleEffect;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.registry.Registries;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.TagKey;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundEvents;
import net.minecraft.tag.TagKey;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.registry.Registry;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -88,7 +87,7 @@ public static void onTrinketBroken(ItemStack stack, SlotReference ref, LivingEnt
world.spawnParticles(new ItemStackParticleEffect(ParticleTypes.ITEM, stack), vec3d2.x, vec3d2.y, vec3d2.z, 0, vec3d.x, vec3d.y + 0.05D, vec3d.z, 1);
}
if (!entity.isSilent()) {
world.playSoundFromEntity(null, entity, SoundEvents.ENTITY_ITEM_BREAK, entity.getSoundCategory(), 0.8F, 0.8F + world.random.nextFloat() * 0.4F, world.random.nextInt());
world.playSoundFromEntity(null, entity, Registries.SOUND_EVENT.getEntry(SoundEvents.ENTITY_ITEM_BREAK), entity.getSoundCategory(), 0.8F, 0.8F + world.random.nextFloat() * 0.4F, world.random.nextInt());
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/dev/emi/trinkets/data/SlotLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@
import dev.emi.trinkets.api.TrinketEnums.DropRule;
import dev.emi.trinkets.data.SlotLoader.GroupData;
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
import net.minecraft.command.CommandRegistryWrapper;
import net.minecraft.command.argument.ItemStringReader;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.registry.Registries;
import net.minecraft.resource.Resource;
import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.SinglePreparationResourceReloader;
import net.minecraft.util.Identifier;
import net.minecraft.util.JsonHelper;
import net.minecraft.util.profiler.Profiler;
import net.minecraft.util.registry.Registry;

public class SlotLoader extends SinglePreparationResourceReloader<Map<String, GroupData>> implements IdentifiableResourceReloadListener {

Expand Down Expand Up @@ -166,7 +165,7 @@ SlotType create(String group, String name) {
ItemStack iconItem;

try {
var decode = ItemStringReader.item(CommandRegistryWrapper.of(Registry.ITEM), new StringReader(this.iconItem));
var decode = ItemStringReader.item(Registries.ITEM.getReadOnlyWrapper(), new StringReader(this.iconItem));
var stack = new ItemStack(decode.item().value());

stack.setNbt(decode.nbt());
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/dev/emi/trinkets/poly/Elements.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package dev.emi.trinkets.poly;

import dev.emi.trinkets.TrinketsMain;
import eu.pb4.polymer.api.resourcepack.PolymerModelData;
import eu.pb4.polymer.resourcepack.api.PolymerModelData;
import eu.pb4.sgui.api.elements.GuiElementBuilder;
import net.minecraft.item.Items;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

public class Elements {
public static final GuiElementBuilder FILLER = new GuiElementBuilder(Items.WHITE_STAINED_GLASS_PANE).setName(Text.empty())
.setCustomModelData(GuiModels.getOrCreate(new Identifier(TrinketsMain.MOD_ID, "gui/filler"), Items.WHITE_STAINED_GLASS_PANE).value());
.setCustomModelData(GuiModels.getOrCreate(new Identifier(TrinketsMain.MOD_ID, "gui/polybuttons/filler"), Items.WHITE_STAINED_GLASS_PANE).value());
public static final GuiElementBuilder FILLER_NAVBAR = new GuiElementBuilder(Items.BLACK_STAINED_GLASS_PANE).setName(Text.empty());


public static final PolymerModelData PREVIOUS = GuiModels.getOrCreate(new Identifier(TrinketsMain.MOD_ID, "gui/previous"), Items.GREEN_STAINED_GLASS_PANE);
public static final PolymerModelData NEXT = GuiModels.getOrCreate(new Identifier(TrinketsMain.MOD_ID, "gui/next"), Items.GREEN_STAINED_GLASS_PANE);
public static final PolymerModelData SUBPAGE = GuiModels.getOrCreate(new Identifier(TrinketsMain.MOD_ID, "gui/subpage"), Items.LIGHT_BLUE_STAINED_GLASS_PANE);
public static final PolymerModelData PREVIOUS = GuiModels.getOrCreate(new Identifier(TrinketsMain.MOD_ID, "gui/polybuttons/previous"), Items.GREEN_STAINED_GLASS_PANE);
public static final PolymerModelData NEXT = GuiModels.getOrCreate(new Identifier(TrinketsMain.MOD_ID, "gui/polybuttons/next"), Items.GREEN_STAINED_GLASS_PANE);
public static final PolymerModelData SUBPAGE = GuiModels.getOrCreate(new Identifier(TrinketsMain.MOD_ID, "gui/polybuttons/subpage"), Items.LIGHT_BLUE_STAINED_GLASS_PANE);

}
18 changes: 9 additions & 9 deletions src/main/java/dev/emi/trinkets/poly/GuiModels.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package dev.emi.trinkets.poly;

import dev.emi.trinkets.TrinketsMain;
import eu.pb4.polymer.api.resourcepack.PolymerModelData;
import eu.pb4.polymer.api.resourcepack.PolymerRPBuilder;
import eu.pb4.polymer.api.resourcepack.PolymerRPUtils;
import eu.pb4.polymer.resourcepack.api.PolymerModelData;
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
import eu.pb4.polymer.resourcepack.api.ResourcePackBuilder;
import net.minecraft.item.Item;
import net.minecraft.util.Identifier;

Expand All @@ -21,16 +21,16 @@ public class GuiModels {
public static PolymerModelData getOrCreate(Identifier icon, Item item) {
if (init) {
init = false;
PolymerRPUtils.addAssetSource(TrinketsMain.MOD_ID);
PolymerResourcePackUtils.addModAssets(TrinketsMain.MOD_ID);

PolymerRPUtils.RESOURCE_PACK_CREATION_EVENT.register(GuiModels::createFiles);
PolymerResourcePackUtils.RESOURCE_PACK_CREATION_EVENT.register(GuiModels::createFiles);
}

MODELS.add(icon);
return MODEL_MAP.computeIfAbsent(item, i -> new HashMap<>()).computeIfAbsent(icon, i -> PolymerRPUtils.requestModel(item, icon));
return MODEL_MAP.computeIfAbsent(item, i -> new HashMap<>()).computeIfAbsent(icon, i -> PolymerResourcePackUtils.requestModel(item, icon));
}

private static void createFiles(PolymerRPBuilder polymerRPBuilder) {
private static void createFiles(ResourcePackBuilder polymerRPBuilder) {
for (var id : MODELS) {
var json = """
{
Expand All @@ -49,7 +49,7 @@ private static void createFiles(PolymerRPBuilder polymerRPBuilder) {
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "trinkets:gui/filler"
"layer0": "trinkets:gui/polybuttons/filler"
},
"display": {
"gui": {
Expand All @@ -60,7 +60,7 @@ private static void createFiles(PolymerRPBuilder polymerRPBuilder) {
}
}
""";
polymerRPBuilder.addData("assets/trinkets/models/gui/filler.json", json.getBytes(StandardCharsets.UTF_8));
polymerRPBuilder.addData("assets/trinkets/models/gui/polybuttons/filler.json", json.getBytes(StandardCharsets.UTF_8));
}
}
}
12 changes: 6 additions & 6 deletions src/main/java/dev/emi/trinkets/poly/TrinketsFlatUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import dev.emi.trinkets.api.TrinketComponent;
import dev.emi.trinkets.api.TrinketInventory;
import dev.emi.trinkets.api.TrinketsApi;
import eu.pb4.polymer.api.resourcepack.PolymerRPUtils;
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
import eu.pb4.sgui.api.elements.GuiElementBuilder;
import eu.pb4.sgui.api.gui.SimpleGui;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -58,7 +58,7 @@ public TrinketsFlatUI(ServerPlayerEntity player, boolean compact) {
.flatMap((x) -> x.values().stream().sorted(Comparator.comparingInt(a -> a.getSlotType().getOrder())))
.collect(Collectors.toList());

this.setTitle(PolymerRPUtils.hasPack(player)
this.setTitle(PolymerResourcePackUtils.hasPack(player)
? Text.empty().append(Text.literal(compact ? "-1." : "-0.")
.setStyle(Style.EMPTY.withColor(Formatting.WHITE).withFont(new Identifier(TrinketsMain.MOD_ID, "gui"))))
.append(Text.translatable("trinkets.name"))
Expand All @@ -77,7 +77,7 @@ public static int open(ServerPlayerEntity player) {
}

public void drawLines() {
if (this.compact && !PolymerRPUtils.hasPack(this.player)) {
if (this.compact && !PolymerResourcePackUtils.hasPack(this.player)) {
for (int x = 0; x < 5; x++) {
this.setSlot(9 * x + 4, Elements.FILLER);
}
Expand Down Expand Up @@ -130,7 +130,7 @@ private void drawLine(int index, TrinketInventory trinketInventory, int subPage)
this.setSlot(base + slot++, Elements.FILLER);
}

boolean hasPack = PolymerRPUtils.hasPack(player);
boolean hasPack = PolymerResourcePackUtils.hasPack(player);

if (trinketInventory.size() <= invSize) {
for (int i = 0; i < invSize; i++) {
Expand Down Expand Up @@ -189,7 +189,7 @@ private void drawLine(int index, TrinketInventory trinketInventory, int subPage)
}

private void drawNavbar() {
boolean addNavbarFiller = !PolymerRPUtils.hasPack(this.player);
boolean addNavbarFiller = !PolymerResourcePackUtils.hasPack(this.player);

if (this.inventories.size() > this.displayPerPage) {

Expand Down Expand Up @@ -249,6 +249,6 @@ private void drawNavbar() {


public static final void playClickSound(ServerPlayerEntity player) {
player.playSound(SoundEvents.UI_BUTTON_CLICK, SoundCategory.MASTER, 0.7f, 1);
player.playSound(SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.MASTER, 0.7f, 1);
}
}
14 changes: 14 additions & 0 deletions src/main/resources/assets/minecraft/atlases/blocks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"sources": [
{
"type": "directory",
"source": "gui/slots",
"prefix": "gui/slots/"
},
{
"type": "directory",
"source": "gui/polybuttons",
"prefix": "gui/polybuttons/"
}
]
}
4 changes: 2 additions & 2 deletions src/main/resources/assets/trinkets/font/gui.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
{
"type": "bitmap",
"file": "trinkets:gui/flat_gui.png",
"file": "trinkets:font_gui/flat_gui.png",
"ascent": 13,
"height": 256,
"chars": [
Expand All @@ -18,7 +18,7 @@
},
{
"type": "bitmap",
"file": "trinkets:gui/flat_gui_compact.png",
"file": "trinkets:font_gui/flat_gui_compact.png",
"ascent": 13,
"height": 256,
"chars": [
Expand Down
Binary file not shown.
3 changes: 2 additions & 1 deletion src/testmod/java/dev/emi/trinkets/TestTrinket.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import dev.emi.trinkets.api.SlotAttributes;
import dev.emi.trinkets.api.SlotReference;
import dev.emi.trinkets.api.TrinketItem;
import eu.pb4.polymer.api.item.PolymerItem;
import eu.pb4.polymer.core.api.item.PolymerItem;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.client.render.entity.model.BipedEntityModel;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.attribute.EntityAttribute;
Expand Down

0 comments on commit 10373bf

Please sign in to comment.