Skip to content

Commit

Permalink
Add widget NOINTERACT / NOTOUCH
Browse files Browse the repository at this point in the history
  • Loading branch information
cam72cam committed Dec 8, 2023
1 parent 8dd18ab commit 7f87493
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
import cam72cam.mod.net.PacketDirection;
import cam72cam.mod.serialization.TagField;
import cam72cam.mod.world.World;
import org.apache.commons.lang3.tuple.Pair;

import java.util.Comparator;
import java.util.Objects;
import java.util.UUID;

public class ClientPartDragging {
Expand Down Expand Up @@ -183,6 +180,9 @@ private void tick() {

double padding = 0.05 * stock.gauge.scale();
for (Interactable<?> interactable : stock.getDefinition().getModel().getInteractable()) {
if (interactable.disabled()) {
continue;
}
IBoundingBox bb = interactable.getBoundingBox(stock).grow(new Vec3d(padding, padding, padding));
for (double i = 0.125; i < 3; i += 0.05 * stock.gauge.scale()) {
Vec3d cast = start.add(look.scale(i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class Control<T extends EntityMoveableRollingStock> extends Interactable<
private final Vec3d center;
protected final ModelState state;
private final String modelId;
private final boolean noInteract;
private Vec3d rotationPoint = null;
private float rotationDegrees = 0;
private final Map<Axis, Float> rotations = new HashMap<>();
Expand Down Expand Up @@ -73,6 +74,10 @@ public Control(ModelComponent part, ModelState state, double internal_model_scal
this.global = part.modelIDs.stream().anyMatch(g -> g.contains("_GLOBAL_") || g.startsWith("GLOBAL_") || g.endsWith("_GLOBAL"));
this.invert = part.modelIDs.stream().anyMatch(g -> g.contains("_INVERT_") || g.startsWith("INVERT_") || g.endsWith("_INVERT"));
this.hide = part.modelIDs.stream().anyMatch(g -> g.contains("_HIDE_") || g.startsWith("HIDE_") || g.endsWith("_HIDE"));
this.noInteract = part.modelIDs.stream().anyMatch(g ->
g.contains("_NOINTERACT_") || g.startsWith("NOINTERACT_") || g.endsWith("_NOINTERACT") ||
g.contains("_NOTOUCH_") || g.startsWith("NOTOUCH_") || g.endsWith("_NOTOUCH")
);
this.offset = part.modelIDs.stream().map(group -> {
Matcher matcher = Pattern.compile("_OFFSET_([^_]+)").matcher(group);
return matcher.find() ? Float.parseFloat(matcher.group(1)) : null;
Expand Down Expand Up @@ -198,6 +203,11 @@ public Control(ModelComponent part, ModelState state, double internal_model_scal
this.modelId = part.modelIDs.stream().findFirst().get();
}

@Override
public boolean disabled() {
return noInteract;
}

private static String formatLabel(ModelComponentType label) {
return WordUtils.capitalizeFully(label.name().replace("_X", "").replaceAll("_CONTROL", "").replaceAll("_", " ").toLowerCase(Locale.ROOT));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import cam72cam.mod.entity.boundingbox.IBoundingBox;
import cam72cam.mod.math.Vec3d;

// TODO rename to Widget?
public class Interactable<T extends EntityMoveableRollingStock> {
public final ModelComponent part;
public long lookedAt;
Expand All @@ -18,6 +19,10 @@ public Vec3d center(EntityRollingStock stock) {
return stock.getModelMatrix().apply(part.center);
}

public boolean disabled() {
return false;
}

public IBoundingBox getBoundingBox(EntityRollingStock stock) {
return IBoundingBox.from(
stock.getModelMatrix().apply(part.min),
Expand Down

0 comments on commit 7f87493

Please sign in to comment.