From 6c7bcb2d6429c53cf27c7f60c4053b03e132646d Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Fri, 3 Feb 2023 00:32:13 -0800 Subject: [PATCH] 1.19.3 Port Part IV - Fix FixNormalScalingMixin and MapItemSavedDataMixin - Fix ModelSwapper using BakingCompleted instead of ModifyBakingResult - Add necessary extra sprites to block atlas - Fix creative tab order and item sorting --- .../simibubi/create/AllCreativeModeTabs.java | 52 ++++++++++------- .../item/render/CustomRenderedItemModel.java | 11 ++-- .../mixin/FixNormalScalingMixin.java | 2 +- .../mixin/MapItemSavedDataMixin.java | 12 ++-- .../foundation/utility/ModelSwapper.java | 2 +- .../assets/minecraft/atlases/blocks.json | 56 +++++++++++++++++++ 6 files changed, 101 insertions(+), 34 deletions(-) create mode 100644 src/main/resources/assets/minecraft/atlases/blocks.json diff --git a/src/main/java/com/simibubi/create/AllCreativeModeTabs.java b/src/main/java/com/simibubi/create/AllCreativeModeTabs.java index dfaa6fd51..f5cd01592 100644 --- a/src/main/java/com/simibubi/create/AllCreativeModeTabs.java +++ b/src/main/java/com/simibubi/create/AllCreativeModeTabs.java @@ -30,9 +30,11 @@ import net.minecraft.client.renderer.entity.ItemRenderer; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.flag.FeatureFlagSet; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.CreativeModeTabs; import net.minecraft.world.item.CreativeModeTab.DisplayItemsGenerator; import net.minecraft.world.item.CreativeModeTab.Output; import net.minecraft.world.item.CreativeModeTab.TabVisibility; @@ -48,18 +50,21 @@ import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; @EventBusSubscriber(bus = Bus.MOD) public class AllCreativeModeTabs { + public static final ResourceLocation BASE_TAB_ID = Create.asResource("base"); + public static final ResourceLocation PALETTES_TAB_ID = Create.asResource("palettes"); + private static CreativeModeTab baseTab; private static CreativeModeTab palettesTab; @SubscribeEvent public static void onCreativeModeTabRegister(CreativeModeTabEvent.Register event) { - baseTab = event.registerCreativeModeTab(Create.asResource("base"), builder -> { + baseTab = event.registerCreativeModeTab(BASE_TAB_ID, List.of(PALETTES_TAB_ID), List.of(CreativeModeTabs.SPAWN_EGGS), builder -> { builder.title(Component.translatable("itemGroup.create.base")) .icon(() -> AllBlocks.COGWHEEL.asStack()) .displayItems(new RegistrateDisplayItemsGenerator(EnumSet.complementOf(EnumSet.of(AllSections.PALETTES)), true)); }); - palettesTab = event.registerCreativeModeTab(Create.asResource("palettes"), builder -> { + palettesTab = event.registerCreativeModeTab(PALETTES_TAB_ID, List.of(), List.of(CreativeModeTabs.SPAWN_EGGS, BASE_TAB_ID), builder -> { builder.title(Component.translatable("itemGroup.create.palettes")) .icon(() -> AllPaletteBlocks.ORNATE_IRON_WINDOW.asStack()) .displayItems(new RegistrateDisplayItemsGenerator(EnumSet.of(AllSections.PALETTES), false)); @@ -139,7 +144,6 @@ public class AllCreativeModeTabs { Map, ItemProviderEntry> simpleBeforeOrderings = Map.of( AllItems.EMPTY_BLAZE_BURNER, AllBlocks.BLAZE_BURNER, - AllItems.BELT_CONNECTOR, AllBlocks.CREATIVE_MOTOR, AllItems.SCHEDULE, AllBlocks.TRACK_STATION ); @@ -228,18 +232,23 @@ public class AllCreativeModeTabs { Function stackFunc = makeStackFunc(); Function visibilityFunc = makeVisibilityFunc(); - if (addItems) { - outputAll(output, collectItems(itemRenderer, true, exclusionPredicate, orderings), stackFunc, visibilityFunc); - } - - outputAll(output, collectBlocks(exclusionPredicate, orderings), stackFunc, visibilityFunc); + List items = new LinkedList<>(); if (addItems) { - outputAll(output, collectItems(itemRenderer, false, exclusionPredicate, orderings), stackFunc, visibilityFunc); + items.addAll(collectItems(itemRenderer, true, exclusionPredicate)); } + + items.addAll(collectBlocks(exclusionPredicate)); + + if (addItems) { + items.addAll(collectItems(itemRenderer, false, exclusionPredicate)); + } + + applyOrderings(items, orderings); + outputAll(output, items, stackFunc, visibilityFunc); } - private List collectBlocks(Predicate exclusionPredicate, List orderings) { + private List collectBlocks(Predicate exclusionPredicate) { List items = new ReferenceArrayList<>(); for (AllSections section : sections) { for (RegistryEntry entry : Create.REGISTRATE.getAll(section, Registries.BLOCK)) { @@ -251,13 +260,12 @@ public class AllCreativeModeTabs { } } } - items = new LinkedList<>(new ReferenceLinkedOpenHashSet<>(items)); - applyOrderings(items, orderings); + items = new ReferenceArrayList<>(new ReferenceLinkedOpenHashSet<>(items)); return items; } - private List collectItems(ItemRenderer itemRenderer, boolean special, Predicate exclusionPredicate, List orderings) { - List items = new LinkedList<>(); + private List collectItems(ItemRenderer itemRenderer, boolean special, Predicate exclusionPredicate) { + List items = new ReferenceArrayList<>(); for (AllSections section : sections) { for (RegistryEntry entry : Create.REGISTRATE.getAll(section, Registries.ITEM)) { Item item = entry.get(); @@ -271,7 +279,6 @@ public class AllCreativeModeTabs { } } } - applyOrderings(items, orderings); return items; } @@ -280,13 +287,18 @@ public class AllCreativeModeTabs { int anchorIndex = items.indexOf(ordering.anchor()); if (anchorIndex != -1) { Item item = ordering.item(); - if (items.remove(item)) { - if (ordering.type() == ItemOrdering.Type.AFTER) { - items.add(anchorIndex + 1, item); - } else { - items.add(anchorIndex, item); + int itemIndex = items.indexOf(item); + if (itemIndex != -1) { + items.remove(itemIndex); + if (itemIndex < anchorIndex) { + anchorIndex--; } } + if (ordering.type() == ItemOrdering.Type.AFTER) { + items.add(anchorIndex + 1, item); + } else { + items.add(anchorIndex, item); + } } } } diff --git a/src/main/java/com/simibubi/create/foundation/item/render/CustomRenderedItemModel.java b/src/main/java/com/simibubi/create/foundation/item/render/CustomRenderedItemModel.java index 5eb15d700..c5f2c43d3 100644 --- a/src/main/java/com/simibubi/create/foundation/item/render/CustomRenderedItemModel.java +++ b/src/main/java/com/simibubi/create/foundation/item/render/CustomRenderedItemModel.java @@ -9,7 +9,6 @@ import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.renderer.block.model.ItemTransforms; import net.minecraft.client.resources.model.BakedModel; -import net.minecraft.client.resources.model.ModelManager; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.client.event.ModelEvent; import net.minecraftforge.client.model.BakedModelWrapper; @@ -56,14 +55,14 @@ public abstract class CustomRenderedItemModel extends BakedModelWrapper models = event.getModels(); for (String name : partials.keySet()) - partials.put(name, loadPartial(modelManager, name)); + partials.put(name, loadPartial(models, name)); } - protected BakedModel loadPartial(ModelManager modelManager, String name) { - return modelManager.getModel(getPartialModelLocation(name)); + protected BakedModel loadPartial(Map models, String name) { + return models.get(getPartialModelLocation(name)); } protected ResourceLocation getPartialModelLocation(String name) { diff --git a/src/main/java/com/simibubi/create/foundation/mixin/FixNormalScalingMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/FixNormalScalingMixin.java index c50a52115..d1daf3293 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/FixNormalScalingMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/FixNormalScalingMixin.java @@ -17,7 +17,7 @@ public class FixNormalScalingMixin { * applied, which negates the matrix again, resulting in the matrix being the * same as in the beginning. */ - @Inject(at = @At(value = "INVOKE", target = "Lcom/mojang/math/Matrix3f;mul(F)V", shift = Shift.AFTER), method = "scale(FFF)V", cancellable = true) + @Inject(at = @At(value = "INVOKE", target = "Lorg/joml/Matrix3f;scale(F)Lorg/joml/Matrix3f;", shift = Shift.AFTER, remap = false), method = "scale(FFF)V", cancellable = true) private void returnAfterNegate(float x, float y, float z, CallbackInfo ci) { ci.cancel(); } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/MapItemSavedDataMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/MapItemSavedDataMixin.java index 203401f6c..fe433ad35 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/MapItemSavedDataMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/MapItemSavedDataMixin.java @@ -35,11 +35,11 @@ public class MapItemSavedDataMixin implements StationMapData { @Shadow @Final - public int x; + public int centerX; @Shadow @Final - public int z; + public int centerZ; @Shadow @Final @@ -87,8 +87,8 @@ public class MapItemSavedDataMixin implements StationMapData { stationMarkers.put(marker.getId(), marker); int scaleMultiplier = 1 << scale; - float localX = (marker.getTarget().getX() - x) / (float) scaleMultiplier; - float localZ = (marker.getTarget().getZ() - z) / (float) scaleMultiplier; + float localX = (marker.getTarget().getX() - centerX) / (float) scaleMultiplier; + float localZ = (marker.getTarget().getZ() - centerZ) / (float) scaleMultiplier; if (localX < -63.0F || localX > 63.0F || localZ < -63.0F || localZ > 63.0F) { removeDecoration(marker.getId()); @@ -134,8 +134,8 @@ public class MapItemSavedDataMixin implements StationMapData { double zCenter = pos.getZ() + 0.5D; int scaleMultiplier = 1 << scale; - double localX = (xCenter - (double) x) / (double) scaleMultiplier; - double localZ = (zCenter - (double) z) / (double) scaleMultiplier; + double localX = (xCenter - (double) centerX) / (double) scaleMultiplier; + double localZ = (zCenter - (double) centerZ) / (double) scaleMultiplier; if (localX < -63.0D || localX > 63.0D || localZ < -63.0D || localZ > 63.0D) return false; diff --git a/src/main/java/com/simibubi/create/foundation/utility/ModelSwapper.java b/src/main/java/com/simibubi/create/foundation/utility/ModelSwapper.java index cf2663713..ddeb1b55e 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/ModelSwapper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/ModelSwapper.java @@ -43,7 +43,7 @@ public class ModelSwapper { .forEach(event::register)); } - public void onModelBake(ModelEvent.BakingCompleted event) { + public void onModelBake(ModelEvent.ModifyBakingResult event) { Map modelRegistry = event.getModels(); customBlockModels.forEach((block, modelFunc) -> swapModels(modelRegistry, getAllBlockStateModelLocations(block), modelFunc)); diff --git a/src/main/resources/assets/minecraft/atlases/blocks.json b/src/main/resources/assets/minecraft/atlases/blocks.json new file mode 100644 index 000000000..62070df2a --- /dev/null +++ b/src/main/resources/assets/minecraft/atlases/blocks.json @@ -0,0 +1,56 @@ +{ + "sources": [ + { + "type": "single", + "resource": "create:entity/blueprint_large" + }, + { + "type": "single", + "resource": "create:entity/blueprint_medium" + }, + { + "type": "single", + "resource": "create:entity/blueprint_small" + }, + { + "type": "single", + "resource": "create:entity/coupling" + }, + { + "type": "single", + "resource": "create:entity/train_hat" + }, + { + "type": "single", + "resource": "create:fluid/chocolate_flow" + }, + { + "type": "single", + "resource": "create:fluid/chocolate_still" + }, + { + "type": "single", + "resource": "create:fluid/honey_flow" + }, + { + "type": "single", + "resource": "create:fluid/honey_still" + }, + { + "type": "single", + "resource": "create:fluid/potion_flow" + }, + { + "type": "single", + "resource": "create:fluid/potion_still" + }, + { + "type": "single", + "resource": "create:fluid/tea_flow" + }, + { + "type": "single", + "resource": "create:fluid/tea_still" + } + ] +}