Skip to content

Commit

Permalink
ref: first try of AS
Browse files Browse the repository at this point in the history
  • Loading branch information
Uhutown committed Nov 5, 2024
1 parent fba9650 commit 9e5f681
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 294 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public ModelTranslation(final VectorWrapper translation) {
}

public void translate() {
GlStateManager.translate(modelTranslation.getX() - 0.5f, modelTranslation.getY() - 0.5f,
modelTranslation.getZ() - 0.5f);

// GlStateManager.translate(modelTranslation.getX() - 0.5f,
// modelTranslation.getY() - 0.5f,
// modelTranslation.getZ() - 0.5f);
if (quaternion != null) {
GlStateManager.rotate(quaternion);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import net.minecraft.client.renderer.vertex.VertexFormatElement;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.client.model.pipeline.LightUtil;

public class SignalAnimationHandler {
Expand All @@ -44,23 +46,25 @@ public SignalAnimationHandler(final SignalTileEntity tile) {
this.tile = tile;
}

private final Map<BufferBuilder, Entry<ModelTranslation, List<SignalAnimation>>>//
private final Map<Entry<IBakedModel, BufferBuilder>, Entry<ModelTranslation, List<SignalAnimation>>>//
animationPerModel = new HashMap<>();

public void render() {
final IBlockState state = tile.getWorld().getBlockState(tile.getPos());
public void render(final VectorWrapper vector) {
final World world = tile.getWorld();
final BlockPos pos = tile.getPos();
final IBlockState state = world.getBlockState(pos);
final SignalAngel angle = state.getValue(Signal.ANGEL);

animationPerModel.forEach((buffer, entry) -> {
animationPerModel.forEach((first, entry) -> {
final ModelTranslation translation = entry.getKey();
if (!translation.shouldRenderModel())
return;

GlStateManager.enableAlpha();
GlStateManager.pushMatrix();
GlStateManager.translate(0.5f, 0.5f, 0.5f);
GlStateManager.rotate(angle.getDregree(), 0, 1, 0);
GlStateManager.translate(vector.getX(), vector.getY(), vector.getZ());
translation.translate();
drawBuffer(buffer);
GlStateManager.rotate(angle.getDregree(), 0, 1, 0);
drawBuffer(first.getValue());
GlStateManager.popMatrix();

if (translation.isAnimationAssigned()) {
Expand Down Expand Up @@ -154,17 +158,19 @@ public void updateAnimationListFromBlock() {
final ModelTranslation translation = new ModelTranslation(VectorWrapper.ZERO,
new Quaternion(0, 0, 0, 0));
translation.setModelTranslation(entry.getValue().copy());
final BufferBuilder buffer = getBufferFromModel(model);
animationPerModel.put(buffer, Maps.immutableEntry(translation, animations.stream()
.map(animation -> animation.copy()).collect(Collectors.toList())));
final BufferBuilder buffer = getBufferFromModel(model, entry.getValue().copy());
animationPerModel.put(Maps.immutableEntry(model, buffer),
Maps.immutableEntry(translation, animations.stream()
.map(animation -> animation.copy()).collect(Collectors.toList())));
});
}

private BufferBuilder getBufferFromModel(final IBakedModel model) {
private BufferBuilder getBufferFromModel(final IBakedModel model, final VectorWrapper vec) {
final BufferBuilder buffer = new BufferBuilder(500);
final IBlockState ebs = tile.getWorld().getBlockState(tile.getPos());
assert ebs != null;
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
buffer.setTranslation(vec.getX(), vec.getY(), vec.getZ());
final List<BakedQuad> lst = new ArrayList<>();
lst.addAll(model.getQuads(ebs, null, 0));
for (final EnumFacing face : EnumFacing.VALUES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void deserializeClient(final ReadBuffer buffer) {
mc.addScheduledTask(() -> {
final TileEntity tile = level.getTileEntity(signalPos);
if (tile != null && tile instanceof SignalTileEntity) {
((SignalTileEntity) tile).updateAnimationStates(properties, contains);
((SignalTileEntity) tile).updateAnimationStates(properties, !contains);
}
final Chunk chunk = level.getChunkFromBlockCoords(signalPos);
if (chunk == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.troblecodings.signals.tileentitys;

import com.troblecodings.core.VectorWrapper;
import com.troblecodings.signals.core.RenderOverlayInfo;

import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
Expand All @@ -13,12 +14,12 @@ public void render(final SignalTileEntity tile, final double x, final double y,
tile.renderOverlay(new RenderOverlayInfo(x, y, z, getFontRenderer()));
}
if (tile.getSignal().hasAnimation()) {
tile.getAnimationHandler().render();
tile.getAnimationHandler().render(new VectorWrapper((float) x, (float) y, (float) z));
}
}

@Override
public boolean isGlobalRenderer(final SignalTileEntity te) {
return te.hasCustomName();
return te.hasCustomName() || te.hasAnimation();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ public Signal getSignal() {
return block instanceof Signal ? (Signal) block : null;
}

public boolean hasAnimation() {
final Signal signal = getSignal();
if (signal == null)
return false;
return signal.hasAnimation();
}

public Map<SEProperty, String> getProperties() {
return ImmutableMap.copyOf(properties);
}
Expand Down

This file was deleted.

251 changes: 0 additions & 251 deletions src/main/resources/assets/opensignals/textures/blocks/sh/sh_light.json

This file was deleted.

Loading

0 comments on commit 9e5f681

Please sign in to comment.