mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-01-13 15:56:07 +01:00
Improve StitchedSprite functionality
- Make StitchedSprite work like PartialModel - Allow StitchedSprite instances to be created directly - Allow StitchSprites to be created for any atlas - Use texture stitch post event instead of lazy computation for filling StitchedSprites - Remove legacy method from AngleHelper - Change artifact name from flywheel to flywheel-forge - Organize imports
This commit is contained in:
parent
b762b1a7d3
commit
b1f34389b7
9 changed files with 55 additions and 78 deletions
|
@ -29,7 +29,7 @@ project.buildnumber = System.getenv('BUILD_NUMBER') != null ? System.getenv('BUI
|
|||
|
||||
version = "${mc_update_version}-${mod_version}" + (dev ? ".${buildnumber}" : '')
|
||||
group = 'com.jozufozu.flywheel'
|
||||
archivesBaseName = 'flywheel'
|
||||
archivesBaseName = 'flywheel-forge'
|
||||
|
||||
java.toolchain.languageVersion = JavaLanguageVersion.of(16)
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ org.gradle.daemon = false
|
|||
mod_version = 0.3.0
|
||||
mc_update_version = 1.17
|
||||
minecraft_version = 1.17.1
|
||||
forge_version = 37.0.108
|
||||
forge_version = 37.0.117
|
||||
|
||||
# build dependency versions
|
||||
forgegradle_version = 5.1.+
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package com.jozufozu.flywheel;
|
||||
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
import com.jozufozu.flywheel.core.AtlasStitcher;
|
||||
import com.jozufozu.flywheel.core.Contexts;
|
||||
import com.jozufozu.flywheel.core.Materials;
|
||||
import com.jozufozu.flywheel.core.PartialModel;
|
||||
import com.jozufozu.flywheel.core.StitchedSprite;
|
||||
import com.jozufozu.flywheel.vanilla.VanillaInstances;
|
||||
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
|
@ -18,12 +18,12 @@ public class FlywheelClient {
|
|||
IEventBus modEventBus = FMLJavaModLoadingContext.get()
|
||||
.getModEventBus();
|
||||
|
||||
modEventBus.addListener(AtlasStitcher.getInstance()::onTextureStitch);
|
||||
|
||||
modEventBus.addListener(Contexts::flwInit);
|
||||
modEventBus.addListener(Materials::flwInit);
|
||||
modEventBus.addListener(PartialModel::onModelRegistry);
|
||||
modEventBus.addListener(PartialModel::onModelBake);
|
||||
modEventBus.addListener(StitchedSprite::onTextureStitchPre);
|
||||
modEventBus.addListener(StitchedSprite::onTextureStitchPost);
|
||||
|
||||
VanillaInstances.init();
|
||||
}
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
package com.jozufozu.flywheel.core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.inventory.InventoryMenu;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
|
||||
/**
|
||||
* This is primarily for hacking entity textures into the block atlas.
|
||||
*/
|
||||
public class AtlasStitcher {
|
||||
protected static final AtlasStitcher INSTANCE = new AtlasStitcher();
|
||||
|
||||
public static AtlasStitcher getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private final List<StitchedSprite> sprites = new ArrayList<>();
|
||||
|
||||
public StitchedSprite get(ResourceLocation loc) {
|
||||
StitchedSprite sprite = new StitchedSprite(loc);
|
||||
|
||||
sprites.add(sprite);
|
||||
|
||||
return sprite;
|
||||
}
|
||||
|
||||
public void onTextureStitch(TextureStitchEvent.Pre event) {
|
||||
if (!event.getMap()
|
||||
.location()
|
||||
.equals(InventoryMenu.BLOCK_ATLAS)) return;
|
||||
|
||||
sprites.forEach(StitchedSprite::reset);
|
||||
sprites.stream()
|
||||
.map(StitchedSprite::getLoc)
|
||||
.forEach(event::addSprite);
|
||||
}
|
||||
}
|
|
@ -1,35 +1,67 @@
|
|||
package com.jozufozu.flywheel.core;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.inventory.InventoryMenu;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
|
||||
public class StitchedSprite {
|
||||
private static final Map<ResourceLocation, List<StitchedSprite>> ALL = new HashMap<>();
|
||||
|
||||
private final ResourceLocation loc;
|
||||
protected final ResourceLocation atlasLocation;
|
||||
protected final ResourceLocation location;
|
||||
protected TextureAtlasSprite sprite;
|
||||
|
||||
TextureAtlasSprite sprite;
|
||||
|
||||
StitchedSprite(ResourceLocation loc) {
|
||||
this.loc = loc;
|
||||
public StitchedSprite(ResourceLocation atlas, ResourceLocation location) {
|
||||
atlasLocation = atlas;
|
||||
this.location = location;
|
||||
ALL.computeIfAbsent(atlasLocation, $ -> new ArrayList<>()).add(this);
|
||||
}
|
||||
|
||||
public ResourceLocation getLoc() {
|
||||
return loc;
|
||||
public StitchedSprite(ResourceLocation location) {
|
||||
this(InventoryMenu.BLOCK_ATLAS, location);
|
||||
}
|
||||
|
||||
public TextureAtlasSprite getSprite() {
|
||||
if (sprite == null) {
|
||||
sprite = Minecraft.getInstance()
|
||||
.getTextureAtlas(InventoryMenu.BLOCK_ATLAS)
|
||||
.apply(loc);
|
||||
public static void onTextureStitchPre(TextureStitchEvent.Pre event) {
|
||||
ResourceLocation atlasLocation = event.getMap().location();
|
||||
List<StitchedSprite> sprites = ALL.get(atlasLocation);
|
||||
if (sprites != null) {
|
||||
for (StitchedSprite sprite : sprites) {
|
||||
event.addSprite(sprite.getLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void onTextureStitchPost(TextureStitchEvent.Post event) {
|
||||
TextureAtlas atlas = event.getMap();
|
||||
ResourceLocation atlasLocation = atlas.location();
|
||||
List<StitchedSprite> sprites = ALL.get(atlasLocation);
|
||||
if (sprites != null) {
|
||||
for (StitchedSprite sprite : sprites) {
|
||||
sprite.loadSprite(atlas);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void loadSprite(TextureAtlas atlas) {
|
||||
sprite = atlas.getSprite(location);
|
||||
}
|
||||
|
||||
public ResourceLocation getAtlasLocation() {
|
||||
return atlasLocation;
|
||||
}
|
||||
|
||||
public ResourceLocation getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public TextureAtlasSprite get() {
|
||||
return sprite;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
sprite = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@ package com.jozufozu.flywheel.core.materials.oriented;
|
|||
|
||||
import com.jozufozu.flywheel.backend.gl.buffer.VecBuffer;
|
||||
import com.jozufozu.flywheel.core.materials.BasicData;
|
||||
import com.jozufozu.flywheel.util.transform.Rotate;
|
||||
import com.jozufozu.flywheel.util.transform.Translate;
|
||||
import com.jozufozu.flywheel.util.vec.Vec3;
|
||||
import com.mojang.math.Quaternion;
|
||||
import com.mojang.math.Vector3f;
|
||||
|
|
|
@ -4,9 +4,9 @@ import java.util.ArrayList;
|
|||
|
||||
import com.jozufozu.flywheel.backend.Backend;
|
||||
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
|
||||
import com.jozufozu.flywheel.util.WorldAttached;
|
||||
import com.jozufozu.flywheel.light.LightUpdater;
|
||||
import com.jozufozu.flywheel.util.ChunkIter;
|
||||
import com.jozufozu.flywheel.util.WorldAttached;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
|
|
|
@ -5,19 +5,7 @@ import net.minecraft.core.Direction.Axis;
|
|||
|
||||
public class AngleHelper {
|
||||
|
||||
/**
|
||||
* Legacy method. See {@link #horizontalAngleNew(Direction)} for new method.
|
||||
*/
|
||||
public static float horizontalAngle(Direction facing) {
|
||||
float angle = facing.toYRot();
|
||||
if (facing.getAxis() == Axis.X) angle = -angle;
|
||||
return angle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as {@link #horizontalAngle(Direction)}, but returns 0 instead of -90 for vertical directions.
|
||||
*/
|
||||
public static float horizontalAngleNew(Direction facing) {
|
||||
if (facing.getAxis()
|
||||
.isVertical()) {
|
||||
return 0;
|
||||
|
|
|
@ -13,7 +13,6 @@ import com.jozufozu.flywheel.core.materials.model.ModelData;
|
|||
import com.jozufozu.flywheel.core.materials.oriented.OrientedData;
|
||||
import com.jozufozu.flywheel.core.model.ModelPart;
|
||||
import com.jozufozu.flywheel.util.AnimationTickHolder;
|
||||
import com.jozufozu.flywheel.util.transform.MatrixTransformStack;
|
||||
import com.mojang.math.Quaternion;
|
||||
import com.mojang.math.Vector3f;
|
||||
|
||||
|
|
Loading…
Reference in a new issue