Skip to content

Commit

Permalink
fix: issue with wrong things showed in SignalController
Browse files Browse the repository at this point in the history
  • Loading branch information
Uhutown committed Oct 9, 2024
1 parent a7f647f commit 107f42f
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import java.util.Objects;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Quaternion;
import com.troblecodings.core.VectorWrapper;
import com.troblecodings.signals.core.RenderAnimationInfo;

public class ModelTranslation {

Expand All @@ -24,18 +24,17 @@ public ModelTranslation(final VectorWrapper translation) {
this.translation = translation;
}

public void translate(final RenderAnimationInfo info) {
info.stack.translate(modelTranslation.getX() - 0.5f, modelTranslation.getY() - 0.5f,
public void translate(final PoseStack stack) {
stack.translate(modelTranslation.getX() - 0.5f, modelTranslation.getY() - 0.5f,
modelTranslation.getZ() - 0.5f);

if (!quaternion.equals(Quaternion.ONE)) {
info.stack.mulPose(quaternion);
stack.mulPose(quaternion);
}
if (!translation.equals(VectorWrapper.ZERO)) {
info.stack.translate(translation.getX(), translation.getY(), translation.getZ());
stack.translate(translation.getX(), translation.getY(), translation.getZ());
}
info.stack.translate(pivotTranslation.getX(), pivotTranslation.getY(),
pivotTranslation.getZ());
stack.translate(pivotTranslation.getX(), pivotTranslation.getY(), pivotTranslation.getZ());
}

public Quaternion getQuaternion() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ public interface SignalAnimation extends Predicate<ModelInfoWrapper> {

public SignalAnimation copy();

public Predicate<ModelInfoWrapper> getPredicate();

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void render(final RenderAnimationInfo info) {
info.stack.pushPose();
info.stack.translate(0.5f, 0.5f, 0.5f);
info.stack.mulPose(angle.getQuaternion());
translation.translate(info);
translation.translate(info.stack);
renderer.renderModel(info.stack.last(), vertex, state, model, 0, 0, 0, info.lightColor,
info.overlayTexture, data);
info.stack.popPose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public SignalAnimation copy() {
return new SignalAnimationRotation(predicate, animationSpeed, axis, rotation, pivot);
}

@Override
public Predicate<ModelInfoWrapper> getPredicate() {
return predicate;
}

@Override
public int hashCode() {
return Objects.hash(animationSpeed, axis, pivot, calc, rotation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public SignalAnimation copy() {
return new SignalAnimationTranslation(predicate, animationSpeed, dest);
}

@Override
public Predicate<ModelInfoWrapper> getPredicate() {
return predicate;
}

@Override
public int hashCode() {
return Objects.hash(animationSpeed, dest, model);
Expand Down
56 changes: 53 additions & 3 deletions src/main/java/com/troblecodings/signals/guis/PreviewSideBar.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,45 @@
package com.troblecodings.signals.guis;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.Predicate;

import com.mojang.math.Quaternion;
import com.troblecodings.core.VectorWrapper;
import com.troblecodings.guilib.ecs.entitys.UIBlockRender;
import com.troblecodings.guilib.ecs.entitys.UIBlockRenderInfo;
import com.troblecodings.guilib.ecs.entitys.UIEntity;
import com.troblecodings.guilib.ecs.entitys.UIMultiBlockRender;
import com.troblecodings.guilib.ecs.entitys.input.UIDrag;
import com.troblecodings.guilib.ecs.entitys.render.UIColor;
import com.troblecodings.guilib.ecs.entitys.render.UIScissor;
import com.troblecodings.signals.OpenSignalsMain;
import com.troblecodings.signals.SEProperty;
import com.troblecodings.signals.animation.ModelTranslation;
import com.troblecodings.signals.animation.SignalAnimation;
import com.troblecodings.signals.blocks.Signal;
import com.troblecodings.signals.contentpacks.SignalAnimationConfigParser;
import com.troblecodings.signals.enums.ChangeableStage;
import com.troblecodings.signals.models.ModelInfoWrapper;
import com.troblecodings.signals.models.SignalCustomModel;

import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.resources.ResourceLocation;

public class PreviewSideBar {
public static final float MODIFIER = 0.1f;

private final UIBlockRender blockRender;
private UIBlockRender blockRender;
private final Map<SEProperty, String> properties = new HashMap<>();
private final UIEntity blockRenderEntity = new UIEntity();
private final float height;
private final List<UIBlockRenderInfo> animationInfos = new ArrayList<>();

public PreviewSideBar(final float height) {
this.height = height;
blockRender = new UIBlockRender(20, height);
blockRenderEntity.setInheritHeight(true);
blockRenderEntity.setWidth(60);
Expand Down Expand Up @@ -69,8 +86,41 @@ public void clear() {
properties.clear();
}

private void buildRenderListForAnimations(final Signal signal, final ModelInfoWrapper wrapper) {
animationInfos.clear();
final Map<Entry<String, VectorWrapper>, List<SignalAnimation>> //
map = SignalAnimationConfigParser.ALL_ANIMATIONS.get(signal);
map.forEach((entry, list) -> {
for (final SignalAnimation animation : list) {
final Predicate<ModelInfoWrapper> predicate = animation.getPredicate();
final ModelTranslation modelTranslation = animation.getFinalModelTranslation();
modelTranslation.setModelTranslation(entry.getValue().copy());

final BakedModel model = SignalCustomModel.getModelFromLocation(
new ResourceLocation(OpenSignalsMain.MODID, entry.getKey()));

final UIBlockRenderInfo info = new UIBlockRenderInfo(model,
signal.defaultBlockState(), wrapper, new VectorWrapper(0.5f, 0.5f, 0.5f));
info.predicate = p -> predicate.test(wrapper);
info.consumer = d -> {
modelTranslation.translate(d.stack);
};
animationInfos.add(info);
}
});
}

public void update(final Signal signal) {
blockRender.setBlockState(new UIBlockRenderInfo(signal.defaultBlockState(),
new ModelInfoWrapper(properties)));
final ModelInfoWrapper wrapper = new ModelInfoWrapper(properties);
blockRenderEntity.remove(blockRender);
if (signal.hasAnimation()) {
buildRenderListForAnimations(signal, wrapper);
blockRender = new UIMultiBlockRender(20, height);
animationInfos.forEach(blockRender::setBlockState);
} else {
blockRender = new UIBlockRender(20, height);
}
blockRender.setBlockState(new UIBlockRenderInfo(signal.defaultBlockState(), wrapper));
blockRenderEntity.add(blockRender);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,10 @@ public void onResourceManagerReload(final ResourceManager manager) {
final Map<Entry<String, VectorWrapper>, List<SignalAnimation>> animations = //
SignalAnimationConfigParser.ALL_ANIMATIONS.get(signaltype);
if (animations != null) {
animations.keySet().forEach(
entry -> accumulator.add(new SignalModelLoaderInfo(entry.getKey(),
predicate -> false, 0, 0, 0, new HashMap<>()).setOnAnimation()));
animations.keySet()
.forEach(entry -> accumulator.add(
new SignalModelLoaderInfo(entry.getKey(), predicate -> false, 0,
0, 0, new HashMap<>()).setOnAnimation()));
}
registeredModels.put(lowercaseName, accumulator);
}
Expand Down

0 comments on commit 107f42f

Please sign in to comment.