mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-11-10 20:45:59 +01:00
Atlases, bells, breaking
- Bell instance - Fix some inconsistencies with PartBuilder - Store information on texture atlasses - Crumbling overlay fixes
This commit is contained in:
parent
1cfffa4448
commit
37a72842cf
@ -167,6 +167,7 @@ public abstract class InstanceManager<T> implements MaterialManager.OriginShiftL
|
||||
}
|
||||
|
||||
public void invalidate() {
|
||||
instances.values().forEach(IInstance::remove);
|
||||
instances.clear();
|
||||
dynamicInstances.clear();
|
||||
tickableInstances.clear();
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -62,8 +62,7 @@ public class InstancedRenderRegistry {
|
||||
@Deprecated
|
||||
public <T extends TileEntity> void register(TileEntityType<? extends T> type, ITileInstanceFactory<? super T> rendererFactory) {
|
||||
this.tile(type)
|
||||
.factory(rendererFactory)
|
||||
.register();
|
||||
.factory(rendererFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,8 +71,7 @@ public class InstancedRenderRegistry {
|
||||
@Deprecated
|
||||
public <T extends Entity> void register(EntityType<? extends T> type, IEntityInstanceFactory<? super T> rendererFactory) {
|
||||
this.entity(type)
|
||||
.factory(rendererFactory)
|
||||
.register();
|
||||
.factory(rendererFactory);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -104,56 +102,39 @@ public class InstancedRenderRegistry {
|
||||
public class TileConfig<T extends TileEntity> {
|
||||
|
||||
private final TileEntityType<T> type;
|
||||
private ITileInstanceFactory<? super T> factory;
|
||||
private boolean skipRender = false;
|
||||
|
||||
public TileConfig(TileEntityType<T> type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public TileConfig<T> factory(ITileInstanceFactory<? super T> rendererFactory) {
|
||||
factory = rendererFactory;
|
||||
tiles.put(type, rendererFactory);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TileConfig<T> 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<T extends Entity> {
|
||||
|
||||
private final EntityType<T> type;
|
||||
private IEntityInstanceFactory<? super T> factory;
|
||||
private boolean skipRender = false;
|
||||
|
||||
public EntityConfig(EntityType<T> type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public EntityConfig<T> factory(IEntityInstanceFactory<? super T> rendererFactory) {
|
||||
factory = rendererFactory;
|
||||
entities.put(type, rendererFactory);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityConfig<T> 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ public class MaterialManager<P extends WorldProgram> {
|
||||
protected final Map<ResourceLocation, ArrayList<MaterialRenderer<P>>> renderers;
|
||||
protected final Map<ResourceLocation, Map<MaterialSpec<?>, InstanceMaterial<?>>> materials;
|
||||
|
||||
private BlockPos originCoordinate = BlockPos.ZERO;
|
||||
protected BlockPos originCoordinate = BlockPos.ZERO;
|
||||
|
||||
private final WeakHashSet<OriginShiftListener> listeners;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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<IProgramExtension> 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);
|
||||
}
|
||||
|
||||
}
|
@ -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<ResourceLocation, SheetData> 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()));
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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
|
@ -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<CrumblingProgram> {
|
||||
|
||||
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<CrumblingProgram> 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<CrumblingProgram> material : atlasRenderers) {
|
||||
material.render(layer, translate, camX, camY, camZ, CrumblingProgram::setDefaultAtlasSize);
|
||||
}
|
||||
|
||||
for (Map.Entry<ResourceLocation, ArrayList<MaterialRenderer<CrumblingProgram>>> entry : renderers.entrySet()) {
|
||||
glBindTexture(GL_TEXTURE_2D, textureManager.getTexture(entry.getKey())
|
||||
.getGlTextureId());
|
||||
SheetData atlasData = AtlasInfo.getAtlasData(entry.getKey());
|
||||
for (MaterialRenderer<CrumblingProgram> materialRenderer : entry.getValue()) {
|
||||
materialRenderer.render(layer, translate, camX, camY, camZ, p -> p.setAtlasSize(atlasData.width, atlasData.height));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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<IProgramExtension> 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());
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -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<ResourceLocation> locationStream, IProfiler profiler, int mipMapLevels, CallbackInfoReturnable<AtlasTexture.SheetData> cir) {
|
||||
AtlasTexture.SheetData value = cir.getReturnValue();
|
||||
|
||||
SheetDataAccessor dataAccessor = (SheetDataAccessor) value;
|
||||
|
||||
AtlasInfo.setAtlasData(getId(), dataAccessor);
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
||||
}
|
@ -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<BellTileEntity> 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();
|
||||
}
|
||||
}
|
@ -4,6 +4,27 @@ import com.jozufozu.flywheel.backend.instancing.InstancedRenderRegistry;
|
||||
|
||||
import net.minecraft.tileentity.TileEntityType;
|
||||
|
||||
/**
|
||||
* TODO:
|
||||
* <table>
|
||||
* <tr><td>{@link TileEntityType#SIGN}</td><td> {@link net.minecraft.client.renderer.tileentity.SignTileEntityRenderer SignTileEntityRenderer}</td></tr>
|
||||
* <tr><td>{@link TileEntityType#MOB_SPAWNER}</td><td> {@link net.minecraft.client.renderer.tileentity.MobSpawnerTileEntityRenderer MobSpawnerTileEntityRenderer}</td></tr>
|
||||
* <tr><td>{@link TileEntityType#PISTON}</td><td> {@link net.minecraft.client.renderer.tileentity.PistonTileEntityRenderer PistonTileEntityRenderer}</td></tr>
|
||||
* <tr><td>{@link TileEntityType#ENCHANTING_TABLE}</td><td> {@link net.minecraft.client.renderer.tileentity.EnchantmentTableTileEntityRenderer EnchantmentTableTileEntityRenderer}</td></tr>
|
||||
* <tr><td>{@link TileEntityType#LECTERN}</td><td> {@link net.minecraft.client.renderer.tileentity.LecternTileEntityRenderer LecternTileEntityRenderer}</td></tr>
|
||||
* <tr><td>{@link TileEntityType#END_PORTAL}</td><td> {@link net.minecraft.client.renderer.tileentity.EndPortalTileEntityRenderer EndPortalTileEntityRenderer}</td></tr>
|
||||
* <tr><td>{@link TileEntityType#END_GATEWAY}</td><td> {@link net.minecraft.client.renderer.tileentity.EndGatewayTileEntityRenderer EndGatewayTileEntityRenderer}</td></tr>
|
||||
* <tr><td>{@link TileEntityType#BEACON}</td><td> {@link net.minecraft.client.renderer.tileentity.BeaconTileEntityRenderer BeaconTileEntityRenderer}</td></tr>
|
||||
* <tr><td>{@link TileEntityType#SKULL}</td><td> {@link net.minecraft.client.renderer.tileentity.SkullTileEntityRenderer SkullTileEntityRenderer}</td></tr>
|
||||
* <tr><td>{@link TileEntityType#BANNER}</td><td> {@link net.minecraft.client.renderer.tileentity.BannerTileEntityRenderer BannerTileEntityRenderer}</td></tr>
|
||||
* <tr><td>{@link TileEntityType#STRUCTURE_BLOCK}</td><td> {@link net.minecraft.client.renderer.tileentity.StructureTileEntityRenderer StructureTileEntityRenderer}</td></tr>
|
||||
* <tr><td>{@link TileEntityType#SHULKER_BOX}</td><td> {@link net.minecraft.client.renderer.tileentity.ShulkerBoxTileEntityRenderer ShulkerBoxTileEntityRenderer}</td></tr>
|
||||
* <tr><td>{@link TileEntityType#BED}</td><td> {@link net.minecraft.client.renderer.tileentity.BedTileEntityRenderer BedTileEntityRenderer}</td></tr>
|
||||
* <tr><td>{@link TileEntityType#CONDUIT}</td><td> {@link net.minecraft.client.renderer.tileentity.ConduitTileEntityRenderer ConduitTileEntityRenderer}</td></tr>
|
||||
* <tr><td>{@link TileEntityType#BELL}</td><td> {@link net.minecraft.client.renderer.tileentity.BellTileEntityRenderer BellTileEntityRenderer}</td></tr>
|
||||
* <tr><td>{@link TileEntityType#CAMPFIRE}</td><td> {@link net.minecraft.client.renderer.tileentity.CampfireTileEntityRenderer CampfireTileEntityRenderer}</td></tr>
|
||||
* </table>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,8 @@
|
||||
"StoreProjectionMatrixMixin",
|
||||
"TileRemoveMixin",
|
||||
"TileWorldHookMixin",
|
||||
"atlas.AtlasDataMixin",
|
||||
"atlas.SheetDataAccessor",
|
||||
"light.LightUpdateMixin",
|
||||
"light.NetworkLightUpdateMixin"
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user