Skip to content

Commit c423641

Browse files
committed
Add box bounding and set inversion to render regions
This can make for some interesting behaviour. Also fixes bad default data bugs.
1 parent a108e55 commit c423641

6 files changed

Lines changed: 351 additions & 63 deletions

File tree

src/main/java/net/modfest/fireblanket/command/RegionCommand.java

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package net.modfest.fireblanket.command;
22

33
import com.google.common.collect.Iterables;
4+
import com.mojang.brigadier.Command;
5+
import com.mojang.brigadier.arguments.BoolArgumentType;
46
import com.mojang.brigadier.arguments.StringArgumentType;
57
import com.mojang.brigadier.builder.ArgumentBuilder;
68
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
@@ -41,6 +43,7 @@
4143
import java.util.Locale;
4244
import java.util.UUID;
4345
import java.util.concurrent.CompletableFuture;
46+
import java.util.function.BiPredicate;
4447
import java.util.function.Predicate;
4548

4649
import static net.minecraft.server.command.CommandManager.argument;
@@ -98,6 +101,39 @@ public static void init(LiteralArgumentBuilder<ServerCommandSource> base, Comman
98101
)
99102
)
100103
)
104+
.then(literal("meta")
105+
.then(argument("name", StringArgumentType.word())
106+
.suggests(RegionCommand::suggestRegionNames)
107+
.then(literal("entityType")
108+
.then(literal("bounded")
109+
.then(argument("value", BoolArgumentType.bool())
110+
.executes(passThroughBoolean(RenderRegions::setEntityTypeBoxBounded))
111+
)
112+
.executes(printBoolean("EntityBounded", RenderRegions::getEntityTypeBoxBounded))
113+
)
114+
.then(literal("inverted")
115+
.then(argument("value", BoolArgumentType.bool())
116+
.executes(passThroughBoolean(RenderRegions::setEntityTypeAttachmentsInverted))
117+
)
118+
.executes(printBoolean("EntityInverted", RenderRegions::getEntityTypeAttachmentsInverted))
119+
)
120+
)
121+
.then(literal("beType")
122+
.then(literal("bounded")
123+
.then(argument("value", BoolArgumentType.bool())
124+
.executes(passThroughBoolean(RenderRegions::setBeTypeBoxBounded))
125+
)
126+
.executes(printBoolean("BeBounded", RenderRegions::getBeTypeBoxBounded))
127+
)
128+
.then(literal("inverted")
129+
.then(argument("value", BoolArgumentType.bool())
130+
.executes(passThroughBoolean(RenderRegions::setBeTypeAttachmentsInverted))
131+
)
132+
.executes(printBoolean("BeInverted", RenderRegions::getBeTypeAttachmentsInverted))
133+
)
134+
)
135+
)
136+
)
101137
.then(applyBranch(access, true))
102138
.then(applyBranch(access, false))
103139
.then(literal("select")
@@ -588,4 +624,37 @@ public static int addRegion(CommandContext<ServerCommandSource> ctx, RenderRegio
588624
return 1;
589625
}
590626

627+
// Why duplicate code?
628+
private static Command<ServerCommandSource> passThroughBoolean(
629+
ObjObjBoolTriConsumer<RenderRegions, RenderRegion> triConsumer
630+
) {
631+
return ctx -> {
632+
RenderRegion r = getRegion(ctx);
633+
RenderRegions regions = getRegions(ctx);
634+
boolean value = BoolArgumentType.getBool(ctx, "value");
635+
636+
triConsumer.consume(regions, r, value);
637+
return 1;
638+
};
639+
}
640+
641+
private static Command<ServerCommandSource> printBoolean(
642+
String name,
643+
BiPredicate<RenderRegions, RenderRegion> toValue
644+
) {
645+
return ctx -> {
646+
RenderRegion r = getRegion(ctx);
647+
RenderRegions regions = getRegions(ctx);
648+
boolean value = toValue.test(regions, r);
649+
650+
ctx.getSource().sendFeedback(() -> Text.of(name + ": " + value), false);
651+
652+
return 1;
653+
};
654+
}
655+
656+
@FunctionalInterface
657+
private interface ObjObjBoolTriConsumer<I1, I2> {
658+
void consume(I1 i1, I2 i2, boolean i3);
659+
}
591660
}
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
package net.modfest.fireblanket.mixin.client.render_regions;
22

3+
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
34
import net.minecraft.client.render.Frustum;
45
import net.minecraft.client.render.entity.EntityRenderDispatcher;
56
import net.minecraft.entity.Entity;
67
import net.modfest.fireblanket.FireblanketClient;
78
import net.modfest.fireblanket.client.render.RenderRegionRenderer;
89
import org.spongepowered.asm.mixin.Mixin;
910
import org.spongepowered.asm.mixin.injection.At;
10-
import org.spongepowered.asm.mixin.injection.Inject;
11-
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1211

1312
@Mixin(EntityRenderDispatcher.class)
1413
public class MixinEntityRenderDispatcher {
1514

16-
@Inject(at = @At("RETURN"), method = "shouldRender", cancellable = true)
17-
public void shouldRender(Entity entity, Frustum frustum, double x, double y, double z, CallbackInfoReturnable<Boolean> ci) {
18-
if (ci.getReturnValueZ() && RenderRegionRenderer.useRegionRenderer && !FireblanketClient.shouldRender(entity)) {
19-
ci.setReturnValue(false);
20-
}
15+
@ModifyReturnValue(at = @At("RETURN"), method = "shouldRender")
16+
private static boolean shouldRender(boolean original, Entity entity, Frustum frustum, double x, double y, double z) {
17+
return original && (!RenderRegionRenderer.useRegionRenderer || FireblanketClient.shouldRender(entity));
2118
}
22-
2319
}

src/main/java/net/modfest/fireblanket/world/render_regions/ExplainedRenderRegion.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
44
import it.unimi.dsi.fastutil.longs.LongSet;
55
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
6+
import net.minecraft.block.entity.BlockEntity;
7+
import net.minecraft.block.entity.BlockEntityType;
8+
import net.minecraft.entity.Entity;
9+
import net.minecraft.entity.EntityType;
610
import net.minecraft.util.Identifier;
711

12+
import java.util.BitSet;
813
import java.util.Set;
914
import java.util.UUID;
1015

@@ -15,6 +20,11 @@ public class ExplainedRenderRegion {
1520

1621
public boolean blanketDeny;
1722

23+
public boolean entityTypeAttachmentsInverted;
24+
public boolean entityTypeBoxBounded;
25+
public boolean beTypeAttachmentsInverted;
26+
public boolean beTypeBoxBounded;
27+
1828
public final Set<UUID> entityAttachments = new ObjectOpenHashSet<>();
1929
public final LongSet blockAttachments = new LongOpenHashSet();
2030
public final Set<Identifier> entityTypeAttachments = new ObjectOpenHashSet<>();
@@ -28,11 +38,57 @@ public ExplainedRenderRegion(String name, RenderRegion reg) {
2838
public ExplainedRenderRegion copy() {
2939
ExplainedRenderRegion nw = new ExplainedRenderRegion(name, reg);
3040
nw.blanketDeny = blanketDeny;
41+
nw.entityTypeAttachmentsInverted = entityTypeAttachmentsInverted;
42+
nw.entityTypeBoxBounded = entityTypeBoxBounded;
43+
nw.beTypeAttachmentsInverted = beTypeAttachmentsInverted;
44+
nw.beTypeBoxBounded = beTypeBoxBounded;
3145
nw.entityAttachments.addAll(entityAttachments);
3246
nw.blockAttachments.addAll(blockAttachments);
3347
nw.entityTypeAttachments.addAll(entityTypeAttachments);
3448
nw.beTypeAttachments.addAll(beTypeAttachments);
3549
return nw;
3650
}
3751

52+
public boolean isEntityTypeTargeted(Identifier id) {
53+
return entityTypeAttachmentsInverted ^ entityTypeAttachments.contains(id);
54+
}
55+
56+
public boolean isEntityTypeTargeted(Entity entity) {
57+
return isEntityTypeTargeted(EntityType.getId(entity.getType()))
58+
&& (!entityTypeBoxBounded || reg.contains(entity.getPos()));
59+
}
60+
61+
public boolean isBlockEntityTypeTargeted(Identifier id) {
62+
return beTypeAttachmentsInverted ^ beTypeAttachments.contains(id);
63+
}
64+
65+
public boolean isBlockEntityTypeTargeted(BlockEntity blockEntity) {
66+
return isBlockEntityTypeTargeted(BlockEntityType.getId(blockEntity.getType()))
67+
&& (!beTypeBoxBounded || reg.contains(blockEntity.getPos()));
68+
}
69+
70+
public BitSet getMeta() {
71+
final BitSet set = new BitSet();
72+
73+
set.set(0, this.entityTypeAttachmentsInverted);
74+
set.set(1, this.entityTypeBoxBounded);
75+
set.set(2, this.beTypeAttachmentsInverted);
76+
set.set(3, this.beTypeBoxBounded);
77+
78+
return set;
79+
}
80+
81+
public void applyMeta(BitSet set) {
82+
this.entityTypeAttachmentsInverted = set.get(0);
83+
this.entityTypeBoxBounded = set.get(1);
84+
this.beTypeAttachmentsInverted = set.get(2);
85+
this.beTypeBoxBounded = set.get(3);
86+
}
87+
88+
void copyMeta(ExplainedRenderRegion other) {
89+
this.entityTypeAttachmentsInverted = other.entityTypeAttachmentsInverted;
90+
this.entityTypeBoxBounded = other.entityTypeBoxBounded;
91+
this.beTypeAttachmentsInverted = other.beTypeAttachmentsInverted;
92+
this.beTypeBoxBounded = other.beTypeBoxBounded;
93+
}
3894
}

0 commit comments

Comments
 (0)