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
This commit is contained in:
PepperCode1 2023-02-03 00:32:13 -08:00
parent af57857367
commit 6c7bcb2d64
6 changed files with 101 additions and 34 deletions

View File

@ -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<?>, 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<Item, ItemStack> stackFunc = makeStackFunc();
Function<Item, TabVisibility> visibilityFunc = makeVisibilityFunc();
if (addItems) {
outputAll(output, collectItems(itemRenderer, true, exclusionPredicate, orderings), stackFunc, visibilityFunc);
}
outputAll(output, collectBlocks(exclusionPredicate, orderings), stackFunc, visibilityFunc);
List<Item> 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<Item> collectBlocks(Predicate<Item> exclusionPredicate, List<ItemOrdering> orderings) {
private List<Item> collectBlocks(Predicate<Item> exclusionPredicate) {
List<Item> items = new ReferenceArrayList<>();
for (AllSections section : sections) {
for (RegistryEntry<Block> 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<Item> collectItems(ItemRenderer itemRenderer, boolean special, Predicate<Item> exclusionPredicate, List<ItemOrdering> orderings) {
List<Item> items = new LinkedList<>();
private List<Item> collectItems(ItemRenderer itemRenderer, boolean special, Predicate<Item> exclusionPredicate) {
List<Item> items = new ReferenceArrayList<>();
for (AllSections section : sections) {
for (RegistryEntry<Item> 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);
}
}
}
}

View File

@ -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<BakedMod
this.partials.put(name, null);
}
public void loadPartials(ModelEvent.BakingCompleted event) {
ModelManager modelManager = event.getModelManager();
public void loadPartials(ModelEvent.ModifyBakingResult event) {
Map<ResourceLocation, BakedModel> 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<ResourceLocation, BakedModel> models, String name) {
return models.get(getPartialModelLocation(name));
}
protected ResourceLocation getPartialModelLocation(String name) {

View File

@ -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();
}

View File

@ -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;

View File

@ -43,7 +43,7 @@ public class ModelSwapper {
.forEach(event::register));
}
public void onModelBake(ModelEvent.BakingCompleted event) {
public void onModelBake(ModelEvent.ModifyBakingResult event) {
Map<ResourceLocation, BakedModel> modelRegistry = event.getModels();
customBlockModels.forEach((block, modelFunc) -> swapModels(modelRegistry, getAllBlockStateModelLocations(block), modelFunc));

View File

@ -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"
}
]
}