From 2a0757e867fb12fb993e8fff0b84409dc258542a Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Mon, 12 Jul 2021 14:52:54 -0700 Subject: [PATCH] Atlases, bells, breaking - Bell instance - Fix some inconsistencies with PartBuilder - Store information on texture atlasses - Crumbling overlay fixes --- .../backend/instancing/InstanceManager.java | 1 + .../instancing/InstancedRenderDispatcher.java | 6 +- .../instancing/InstancedRenderRegistry.java | 31 ++------ .../backend/instancing/MaterialManager.java | 2 +- .../com/jozufozu/flywheel/core/Contexts.java | 1 + .../flywheel/core/CrumblingProgram.java | 31 -------- .../flywheel/core/atlas/AtlasInfo.java | 43 ++++++++++ .../flywheel/core/atlas/SheetData.java | 17 ++++ .../CrumblingInstanceManager.java | 6 +- .../crumbling/CrumblingMaterialManager.java | 68 ++++++++++++++++ .../core/crumbling/CrumblingProgram.java | 63 +++++++++++++++ .../flywheel/core/model/PartBuilder.java | 23 +++--- .../flywheel/mixin/atlas/AtlasDataMixin.java | 33 ++++++++ .../mixin/atlas/SheetDataAccessor.java | 17 ++++ .../flywheel/vanilla/BellInstance.java | 78 +++++++++++++++++++ .../flywheel/vanilla/VanillaInstances.java | 34 ++++++-- src/main/resources/flywheel.mixins.json | 2 + 17 files changed, 376 insertions(+), 80 deletions(-) delete mode 100644 src/main/java/com/jozufozu/flywheel/core/CrumblingProgram.java create mode 100644 src/main/java/com/jozufozu/flywheel/core/atlas/AtlasInfo.java create mode 100644 src/main/java/com/jozufozu/flywheel/core/atlas/SheetData.java rename src/main/java/com/jozufozu/flywheel/core/{ => crumbling}/CrumblingInstanceManager.java (77%) create mode 100644 src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingMaterialManager.java create mode 100644 src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingProgram.java create mode 100644 src/main/java/com/jozufozu/flywheel/mixin/atlas/AtlasDataMixin.java create mode 100644 src/main/java/com/jozufozu/flywheel/mixin/atlas/SheetDataAccessor.java create mode 100644 src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java index 984bfaf37..41159f061 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstanceManager.java @@ -167,6 +167,7 @@ public abstract class InstanceManager implements MaterialManager.OriginShiftL } public void invalidate() { + instances.values().forEach(IInstance::remove); instances.clear(); dynamicInstances.clear(); tickableInstances.clear(); diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java index 883fbd228..6df479ddc 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java @@ -16,7 +16,8 @@ import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.instancing.entity.EntityInstanceManager; import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceManager; import com.jozufozu.flywheel.core.Contexts; -import com.jozufozu.flywheel.core.CrumblingInstanceManager; +import com.jozufozu.flywheel.core.crumbling.CrumblingInstanceManager; +import com.jozufozu.flywheel.core.crumbling.CrumblingProgram; import com.jozufozu.flywheel.event.BeginFrameEvent; import com.jozufozu.flywheel.event.ReloadRenderersEvent; import com.jozufozu.flywheel.event.RenderLayerEvent; @@ -163,8 +164,6 @@ public class InstancedRenderDispatcher { glBindTexture(GL_TEXTURE_2D, textureManager.getTexture(PlayerContainer.BLOCK_ATLAS_TEXTURE) .getGlTextureId()); - glActiveTexture(GL_TEXTURE4); - crumblingLayer.startDrawing(); bitSet.stream() .forEach(i -> { @@ -173,6 +172,7 @@ public class InstancedRenderDispatcher { renderer.beginFrame(info); if (breaking != null) { + glActiveTexture(GL_TEXTURE4); glBindTexture(GL_TEXTURE_2D, breaking.getGlTextureId()); renderer.materialManager.render(RenderType.getCutoutMipped(), viewProjection, cameraX, cameraY, cameraZ); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderRegistry.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderRegistry.java index 78f8f2c4b..ee0c37e07 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderRegistry.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderRegistry.java @@ -62,8 +62,7 @@ public class InstancedRenderRegistry { @Deprecated public void register(TileEntityType type, ITileInstanceFactory rendererFactory) { this.tile(type) - .factory(rendererFactory) - .register(); + .factory(rendererFactory); } /** @@ -72,8 +71,7 @@ public class InstancedRenderRegistry { @Deprecated public void register(EntityType type, IEntityInstanceFactory rendererFactory) { this.entity(type) - .factory(rendererFactory) - .register(); + .factory(rendererFactory); } @SuppressWarnings("unchecked") @@ -104,56 +102,39 @@ public class InstancedRenderRegistry { public class TileConfig { private final TileEntityType type; - private ITileInstanceFactory factory; - private boolean skipRender = false; public TileConfig(TileEntityType type) { this.type = type; } public TileConfig factory(ITileInstanceFactory rendererFactory) { - factory = rendererFactory; + tiles.put(type, rendererFactory); return this; } public TileConfig setSkipRender(boolean skipRender) { - this.skipRender = skipRender; - return this; - } - - public InstancedRenderRegistry register() { - tiles.put(type, factory); InstancedRenderRegistry.this.skipRender.put(type, skipRender); - - return InstancedRenderRegistry.this; + return this; } } public class EntityConfig { private final EntityType type; - private IEntityInstanceFactory factory; - private boolean skipRender = false; public EntityConfig(EntityType type) { this.type = type; } public EntityConfig factory(IEntityInstanceFactory rendererFactory) { - factory = rendererFactory; + entities.put(type, rendererFactory); return this; } public EntityConfig setSkipRender(boolean skipRender) { - this.skipRender = skipRender; - return this; - } - - public InstancedRenderRegistry register() { - entities.put(type, factory); InstancedRenderRegistry.this.skipRender.put(type, skipRender); - return InstancedRenderRegistry.this; + return this; } } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialManager.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialManager.java index dc912edc7..af338c604 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialManager.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/MaterialManager.java @@ -34,7 +34,7 @@ public class MaterialManager

{ protected final Map>> renderers; protected final Map, InstanceMaterial>> materials; - private BlockPos originCoordinate = BlockPos.ZERO; + protected BlockPos originCoordinate = BlockPos.ZERO; private final WeakHashSet listeners; diff --git a/src/main/java/com/jozufozu/flywheel/core/Contexts.java b/src/main/java/com/jozufozu/flywheel/core/Contexts.java index f4d0a3c40..1752bba54 100644 --- a/src/main/java/com/jozufozu/flywheel/core/Contexts.java +++ b/src/main/java/com/jozufozu/flywheel/core/Contexts.java @@ -4,6 +4,7 @@ import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.SpecMetaRegistry; import com.jozufozu.flywheel.backend.gl.shader.ShaderType; +import com.jozufozu.flywheel.core.crumbling.CrumblingProgram; import com.jozufozu.flywheel.core.shader.WorldFog; import com.jozufozu.flywheel.core.shader.WorldProgram; import com.jozufozu.flywheel.core.shader.gamestate.FogStateProvider; diff --git a/src/main/java/com/jozufozu/flywheel/core/CrumblingProgram.java b/src/main/java/com/jozufozu/flywheel/core/CrumblingProgram.java deleted file mode 100644 index dff507f42..000000000 --- a/src/main/java/com/jozufozu/flywheel/core/CrumblingProgram.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.jozufozu.flywheel.core; - -import static org.lwjgl.opengl.GL20.glUniform2f; - -import java.util.List; - -import com.jozufozu.flywheel.backend.loading.Program; -import com.jozufozu.flywheel.core.shader.WorldProgram; -import com.jozufozu.flywheel.core.shader.extension.IProgramExtension; - -public class CrumblingProgram extends WorldProgram { - protected final int uTextureScale; - protected int uCrumbling; - - public CrumblingProgram(Program program, List extensions) { - super(program, extensions); - - uTextureScale = getUniformLocation("uTextureScale"); - } - - @Override - protected void registerSamplers() { - super.registerSamplers(); - uCrumbling = setSamplerBinding("uCrumbling", 4); - } - - public void setTextureScale(float x, float y) { - glUniform2f(uTextureScale, x, y); - } - -} diff --git a/src/main/java/com/jozufozu/flywheel/core/atlas/AtlasInfo.java b/src/main/java/com/jozufozu/flywheel/core/atlas/AtlasInfo.java new file mode 100644 index 000000000..91333f875 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/core/atlas/AtlasInfo.java @@ -0,0 +1,43 @@ +package com.jozufozu.flywheel.core.atlas; + +import com.jozufozu.flywheel.mixin.atlas.SheetDataAccessor; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.texture.AtlasTexture; +import net.minecraft.client.renderer.texture.Texture; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.util.ResourceLocation; + +import java.util.HashMap; +import java.util.Map; + +public class AtlasInfo { + + private static final Map sheetData = new HashMap<>(); + + public static AtlasTexture getAtlas(ResourceLocation name) { + Texture texture = Minecraft.getInstance().textureManager.getTexture(name); + + if (texture instanceof AtlasTexture) + return (AtlasTexture) texture; + else + return null; + } + + public static SheetData getAtlasData(TextureAtlasSprite texture) { + return getAtlasData(texture.getAtlas()); + } + + public static SheetData getAtlasData(AtlasTexture atlas) { + return getAtlasData(atlas.getId()); + } + + public static SheetData getAtlasData(ResourceLocation loc) { + return sheetData.get(loc); + } + + public static void setAtlasData(ResourceLocation atlas, SheetDataAccessor accessor) { + sheetData.put(atlas, new SheetData(accessor.getWidth(), accessor.getHeight())); + } + +} diff --git a/src/main/java/com/jozufozu/flywheel/core/atlas/SheetData.java b/src/main/java/com/jozufozu/flywheel/core/atlas/SheetData.java new file mode 100644 index 000000000..9841e6899 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/core/atlas/SheetData.java @@ -0,0 +1,17 @@ +package com.jozufozu.flywheel.core.atlas; + +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.util.ResourceLocation; + +import java.util.List; +import java.util.Set; + +public class SheetData { + public final int width; + public final int height; + + public SheetData(int width, int height) { + this.width = width; + this.height = height; + } +} diff --git a/src/main/java/com/jozufozu/flywheel/core/CrumblingInstanceManager.java b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingInstanceManager.java similarity index 77% rename from src/main/java/com/jozufozu/flywheel/core/CrumblingInstanceManager.java rename to src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingInstanceManager.java index bbea00ada..8d2cbc8eb 100644 --- a/src/main/java/com/jozufozu/flywheel/core/CrumblingInstanceManager.java +++ b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingInstanceManager.java @@ -1,13 +1,15 @@ -package com.jozufozu.flywheel.core; +package com.jozufozu.flywheel.core.crumbling; import com.jozufozu.flywheel.backend.instancing.MaterialManager; import com.jozufozu.flywheel.backend.instancing.tile.TileInstanceManager; +import com.jozufozu.flywheel.core.Contexts; + import net.minecraft.util.math.BlockPos; public class CrumblingInstanceManager extends TileInstanceManager { public CrumblingInstanceManager() { - super(new MaterialManager<>(Contexts.CRUMBLING)); + super(new CrumblingMaterialManager()); } @Override diff --git a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingMaterialManager.java b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingMaterialManager.java new file mode 100644 index 000000000..2d8a6a8cb --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingMaterialManager.java @@ -0,0 +1,68 @@ +package com.jozufozu.flywheel.core.crumbling; + +import com.jozufozu.flywheel.backend.instancing.MaterialManager; +import com.jozufozu.flywheel.backend.instancing.MaterialRenderer; +import com.jozufozu.flywheel.core.Contexts; +import com.jozufozu.flywheel.core.WorldContext; +import com.jozufozu.flywheel.core.atlas.AtlasInfo; +import com.jozufozu.flywheel.core.atlas.SheetData; +import com.jozufozu.flywheel.core.shader.IProgramCallback; +import com.jozufozu.flywheel.core.shader.WorldProgram; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.inventory.container.PlayerContainer; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.vector.Matrix4f; + +import java.util.ArrayList; +import java.util.Map; + +import static org.lwjgl.opengl.GL11.GL_TEXTURE_2D; +import static org.lwjgl.opengl.GL11.glBindTexture; +import static org.lwjgl.opengl.GL13.GL_TEXTURE0; +import static org.lwjgl.opengl.GL13.glActiveTexture; + +public class CrumblingMaterialManager extends MaterialManager { + + public CrumblingMaterialManager() { + super(Contexts.CRUMBLING); + } + + /** + * Render every model for every material. + * + * @param layer Which vanilla {@link RenderType} is being drawn? + * @param viewProjection How do we get from camera space to clip space? + * @param callback Provide additional uniforms or state here. + */ + public void render(RenderType layer, Matrix4f viewProjection, double camX, double camY, double camZ, IProgramCallback callback) { + camX -= originCoordinate.getX(); + camY -= originCoordinate.getY(); + camZ -= originCoordinate.getZ(); + + Matrix4f translate = Matrix4f.translate((float) -camX, (float) -camY, (float) -camZ); + + translate.multiplyBackward(viewProjection); + + TextureManager textureManager = Minecraft.getInstance().textureManager; + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, textureManager.getTexture(PlayerContainer.BLOCK_ATLAS_TEXTURE) + .getGlTextureId()); + + for (MaterialRenderer material : atlasRenderers) { + material.render(layer, translate, camX, camY, camZ, CrumblingProgram::setDefaultAtlasSize); + } + + for (Map.Entry>> entry : renderers.entrySet()) { + glBindTexture(GL_TEXTURE_2D, textureManager.getTexture(entry.getKey()) + .getGlTextureId()); + SheetData atlasData = AtlasInfo.getAtlasData(entry.getKey()); + for (MaterialRenderer materialRenderer : entry.getValue()) { + materialRenderer.render(layer, translate, camX, camY, camZ, p -> p.setAtlasSize(atlasData.width, atlasData.height)); + } + } + } +} diff --git a/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingProgram.java b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingProgram.java new file mode 100644 index 000000000..cafe62259 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/core/crumbling/CrumblingProgram.java @@ -0,0 +1,63 @@ +package com.jozufozu.flywheel.core.crumbling; + +import static org.lwjgl.opengl.GL20.glUniform2f; + +import java.util.List; + +import com.jozufozu.flywheel.backend.loading.Program; +import com.jozufozu.flywheel.core.atlas.AtlasInfo; +import com.jozufozu.flywheel.core.atlas.SheetData; +import com.jozufozu.flywheel.core.shader.WorldProgram; +import com.jozufozu.flywheel.core.shader.extension.IProgramExtension; + +import net.minecraft.client.renderer.model.ModelBakery; +import net.minecraft.client.renderer.texture.AtlasTexture; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.inventory.container.PlayerContainer; + +public class CrumblingProgram extends WorldProgram { + protected final int uTextureScale; + protected int uCrumbling; + + public CrumblingProgram(Program program, List extensions) { + super(program, extensions); + + uTextureScale = getUniformLocation("uTextureScale"); + } + + @Override + public void bind() { + super.bind(); + setDefaultAtlasSize(); + } + + @Override + protected void registerSamplers() { + super.registerSamplers(); + uCrumbling = setSamplerBinding("uCrumbling", 4); + } + + public void setTextureScale(float x, float y) { + glUniform2f(uTextureScale, x, y); + } + + public void setDefaultAtlasSize() { + SheetData atlasData = AtlasInfo.getAtlasData(PlayerContainer.BLOCK_ATLAS_TEXTURE); + if (atlasData == null) return; + + int width = atlasData.width; + int height = atlasData.height; + + setAtlasSize(width, height); + } + + public void setAtlasSize(int width, int height) { + AtlasTexture blockAtlas = AtlasInfo.getAtlas(PlayerContainer.BLOCK_ATLAS_TEXTURE); + if (blockAtlas == null) return; + + TextureAtlasSprite sprite = blockAtlas.getSprite(ModelBakery.BLOCK_DESTRUCTION_STAGE_TEXTURES.get(0)); + + setTextureScale(width / (float) sprite.getWidth(), height / (float) sprite.getHeight()); + } + +} diff --git a/src/main/java/com/jozufozu/flywheel/core/model/PartBuilder.java b/src/main/java/com/jozufozu/flywheel/core/model/PartBuilder.java index 178b34f5f..721355dc2 100644 --- a/src/main/java/com/jozufozu/flywheel/core/model/PartBuilder.java +++ b/src/main/java/com/jozufozu/flywheel/core/model/PartBuilder.java @@ -9,6 +9,8 @@ import com.jozufozu.flywheel.backend.model.IndexedModel; import com.jozufozu.flywheel.core.Formats; +import com.jozufozu.flywheel.core.atlas.AtlasInfo; + import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.util.Direction; import net.minecraft.util.math.vector.Vector3f; @@ -157,19 +159,16 @@ public class PartBuilder { float f11 = getV((float)textureOffsetV + sizeZ); float f12 = getV((float)textureOffsetV + sizeZ + sizeY); - - float textureWidth = partBuilder.sizeU; - float textureHeight = partBuilder.sizeV; - quad(buffer, new Vector3f[]{hlh, llh, lll, hll}, f5, f10, f6, f11, textureWidth, textureHeight, Direction.DOWN); - quad(buffer, new Vector3f[]{hhl, lhl, lhh, hhh}, f6, f11, f7, f10, textureWidth, textureHeight, Direction.UP); - quad(buffer, new Vector3f[]{lll, llh, lhh, lhl}, f4, f11, f5, f12, textureWidth, textureHeight, Direction.WEST); - quad(buffer, new Vector3f[]{hll, lll, lhl, hhl}, f5, f11, f6, f12, textureWidth, textureHeight, Direction.NORTH); - quad(buffer, new Vector3f[]{hlh, hll, hhl, hhh}, f6, f11, f8, f12, textureWidth, textureHeight, Direction.EAST); - quad(buffer, new Vector3f[]{llh, hlh, hhh, lhh}, f8, f11, f9, f12, textureWidth, textureHeight, Direction.SOUTH); + quad(buffer, new Vector3f[]{hlh, llh, lll, hll}, f5, f10, f6, f11, Direction.DOWN); + quad(buffer, new Vector3f[]{hhl, lhl, lhh, hhh}, f6, f11, f7, f10, Direction.UP); + quad(buffer, new Vector3f[]{lll, llh, lhh, lhl}, f4, f11, f5, f12, Direction.WEST); + quad(buffer, new Vector3f[]{hll, lll, lhl, hhl}, f5, f11, f6, f12, Direction.NORTH); + quad(buffer, new Vector3f[]{hlh, hll, hhl, hhh}, f6, f11, f8, f12, Direction.EAST); + quad(buffer, new Vector3f[]{llh, hlh, hhh, lhh}, f8, f11, f9, f12, Direction.SOUTH); } - public void quad(VecBuffer buffer, Vector3f[] vertices, float minU, float minV, float maxU, float maxV, float texWidth, float texHeight, Direction dir) { + public void quad(VecBuffer buffer, Vector3f[] vertices, float minU, float minV, float maxU, float maxV, Direction dir) { Vector3f normal = dir.getUnitVector(); @@ -182,14 +181,14 @@ public class PartBuilder { public float getU(float u) { if (sprite != null) - return sprite.getInterpolatedU(u / 4.); + return sprite.getInterpolatedU(u * 16 / partBuilder.sizeU); else return u; } public float getV(float v) { if (sprite != null) - return sprite.getInterpolatedV(v / 4.); + return sprite.getInterpolatedV(v * 16 / partBuilder.sizeV); else return v; } diff --git a/src/main/java/com/jozufozu/flywheel/mixin/atlas/AtlasDataMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/atlas/AtlasDataMixin.java new file mode 100644 index 000000000..27c5eb5c8 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/mixin/atlas/AtlasDataMixin.java @@ -0,0 +1,33 @@ +package com.jozufozu.flywheel.mixin.atlas; + +import com.jozufozu.flywheel.core.atlas.AtlasInfo; + +import net.minecraft.client.renderer.texture.AtlasTexture; + +import net.minecraft.profiler.IProfiler; +import net.minecraft.resources.IResourceManager; +import net.minecraft.util.ResourceLocation; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.stream.Stream; + +@Mixin(AtlasTexture.class) +public abstract class AtlasDataMixin { + + @Shadow + public abstract ResourceLocation getId(); + + @Inject(method = "stitch", at = @At("RETURN")) + public void stealAtlasData(IResourceManager resourceManager, Stream locationStream, IProfiler profiler, int mipMapLevels, CallbackInfoReturnable cir) { + AtlasTexture.SheetData value = cir.getReturnValue(); + + SheetDataAccessor dataAccessor = (SheetDataAccessor) value; + + AtlasInfo.setAtlasData(getId(), dataAccessor); + } +} diff --git a/src/main/java/com/jozufozu/flywheel/mixin/atlas/SheetDataAccessor.java b/src/main/java/com/jozufozu/flywheel/mixin/atlas/SheetDataAccessor.java new file mode 100644 index 000000000..daa4fdd8e --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/mixin/atlas/SheetDataAccessor.java @@ -0,0 +1,17 @@ +package com.jozufozu.flywheel.mixin.atlas; + +import net.minecraft.client.renderer.texture.AtlasTexture; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(AtlasTexture.SheetData.class) +public interface SheetDataAccessor { + + @Accessor("width") + int getWidth(); + + @Accessor("height") + int getHeight(); + +} diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java b/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java new file mode 100644 index 000000000..6380e49e2 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/vanilla/BellInstance.java @@ -0,0 +1,78 @@ +package com.jozufozu.flywheel.vanilla; + +import com.jozufozu.flywheel.backend.instancing.IDynamicInstance; +import com.jozufozu.flywheel.backend.instancing.MaterialManager; +import com.jozufozu.flywheel.backend.instancing.MaterialSpec; +import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance; + +import com.jozufozu.flywheel.backend.model.BufferedModel; +import com.jozufozu.flywheel.core.Materials; +import com.jozufozu.flywheel.core.materials.OrientedData; + +import com.jozufozu.flywheel.core.model.ModelPart; +import com.jozufozu.flywheel.core.model.PartBuilder; + +import com.jozufozu.flywheel.util.AnimationTickHolder; + +import net.minecraft.client.renderer.tileentity.BellTileEntityRenderer; +import net.minecraft.tileentity.BellTileEntity; +import net.minecraft.util.Direction; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.vector.Quaternion; +import net.minecraft.util.math.vector.Vector3f; + +public class BellInstance extends TileEntityInstance implements IDynamicInstance { + + private final OrientedData bell; + + public BellInstance(MaterialManager materialManager, BellTileEntity tile) { + super(materialManager, tile); + + bell = createBellInstance() + .setPivot(0.5f, 0.75f, 0.5f) + .setPosition(getInstancePosition()); + } + + @Override + public void beginFrame() { + if (tile.isRinging) { + float ringness = (float)tile.ringingTicks + AnimationTickHolder.getPartialTicks(); + float angle = MathHelper.sin(ringness / (float)Math.PI) / (4.0F + ringness / 3.0F); + + Vector3f ringAxis = tile.ringDirection.rotateYCCW().getUnitVector(); + + bell.setRotation(ringAxis.getRadialQuaternion(angle)); + } + } + + @Override + public void updateLight() { + relight(getWorldPosition(), bell); + } + + @Override + public void remove() { + bell.delete(); + } + + private OrientedData createBellInstance() { + return materialManager.getMaterial(Materials.ORIENTED) + .get(tile.getType(), BellInstance::createBellModel) + .createInstance(); + } + + private static BufferedModel createBellModel() { + return ModelPart.builder(32, 32) + .sprite(BellTileEntityRenderer.field_217653_c.getSprite()) + .cuboid() + .start(5.0F, 6.0F, 5.0F) + .size(6.0F, 7.0F, 6.0F) + .endCuboid() + .cuboid() + .textureOffset(0, 13) + .start(4.0F, 4.0F, 4.0F) + .size(8.0F, 2.0F, 8.0F) + .endCuboid() + .build(); + } +} diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/VanillaInstances.java b/src/main/java/com/jozufozu/flywheel/vanilla/VanillaInstances.java index 7b7628b2d..36f6567ee 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/VanillaInstances.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/VanillaInstances.java @@ -4,6 +4,27 @@ import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry; import net.minecraft.tileentity.TileEntityType; +/** + * TODO: + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
{@link TileEntityType#SIGN} {@link net.minecraft.client.renderer.tileentity.SignTileEntityRenderer SignTileEntityRenderer}
{@link TileEntityType#MOB_SPAWNER} {@link net.minecraft.client.renderer.tileentity.MobSpawnerTileEntityRenderer MobSpawnerTileEntityRenderer}
{@link TileEntityType#PISTON} {@link net.minecraft.client.renderer.tileentity.PistonTileEntityRenderer PistonTileEntityRenderer}
{@link TileEntityType#ENCHANTING_TABLE} {@link net.minecraft.client.renderer.tileentity.EnchantmentTableTileEntityRenderer EnchantmentTableTileEntityRenderer}
{@link TileEntityType#LECTERN} {@link net.minecraft.client.renderer.tileentity.LecternTileEntityRenderer LecternTileEntityRenderer}
{@link TileEntityType#END_PORTAL} {@link net.minecraft.client.renderer.tileentity.EndPortalTileEntityRenderer EndPortalTileEntityRenderer}
{@link TileEntityType#END_GATEWAY} {@link net.minecraft.client.renderer.tileentity.EndGatewayTileEntityRenderer EndGatewayTileEntityRenderer}
{@link TileEntityType#BEACON} {@link net.minecraft.client.renderer.tileentity.BeaconTileEntityRenderer BeaconTileEntityRenderer}
{@link TileEntityType#SKULL} {@link net.minecraft.client.renderer.tileentity.SkullTileEntityRenderer SkullTileEntityRenderer}
{@link TileEntityType#BANNER} {@link net.minecraft.client.renderer.tileentity.BannerTileEntityRenderer BannerTileEntityRenderer}
{@link TileEntityType#STRUCTURE_BLOCK} {@link net.minecraft.client.renderer.tileentity.StructureTileEntityRenderer StructureTileEntityRenderer}
{@link TileEntityType#SHULKER_BOX} {@link net.minecraft.client.renderer.tileentity.ShulkerBoxTileEntityRenderer ShulkerBoxTileEntityRenderer}
{@link TileEntityType#BED} {@link net.minecraft.client.renderer.tileentity.BedTileEntityRenderer BedTileEntityRenderer}
{@link TileEntityType#CONDUIT} {@link net.minecraft.client.renderer.tileentity.ConduitTileEntityRenderer ConduitTileEntityRenderer}
{@link TileEntityType#BELL} {@link net.minecraft.client.renderer.tileentity.BellTileEntityRenderer BellTileEntityRenderer}
{@link TileEntityType#CAMPFIRE} {@link net.minecraft.client.renderer.tileentity.CampfireTileEntityRenderer CampfireTileEntityRenderer}
+ */ public class VanillaInstances { public static void init() { @@ -11,15 +32,16 @@ public class VanillaInstances { r.tile(TileEntityType.CHEST) .setSkipRender(true) - .factory(ChestInstance::new) - .register(); + .factory(ChestInstance::new); r.tile(TileEntityType.ENDER_CHEST) .setSkipRender(true) - .factory(ChestInstance::new) - .register(); + .factory(ChestInstance::new); r.tile(TileEntityType.TRAPPED_CHEST) .setSkipRender(true) - .factory(ChestInstance::new) - .register(); + .factory(ChestInstance::new); + + r.tile(TileEntityType.BELL) + .setSkipRender(true) + .factory(BellInstance::new); } } diff --git a/src/main/resources/flywheel.mixins.json b/src/main/resources/flywheel.mixins.json index 42f08b576..b930f4173 100644 --- a/src/main/resources/flywheel.mixins.json +++ b/src/main/resources/flywheel.mixins.json @@ -15,6 +15,8 @@ "StoreProjectionMatrixMixin", "TileRemoveMixin", "TileWorldHookMixin", + "atlas.AtlasDataMixin", + "atlas.SheetDataAccessor", "light.LightUpdateMixin", "light.NetworkLightUpdateMixin" ],