Skip to content

Commit b8a4e13

Browse files
committed
Merge remote-tracking branch 'origin/1.18' into 1.19.2
2 parents 26bbe78 + d52e646 commit b8a4e13

File tree

16 files changed

+472
-3
lines changed

16 files changed

+472
-3
lines changed

common/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dependencies {
1111
// Do NOT use other classes from fabric loader
1212
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
1313

14-
modApi("dev.latvian.mods:kubejs:${kubejs_version}") {
14+
modCompileOnly("dev.latvian.mods:kubejs:${kubejs_version}") {
1515
transitive = false
1616
}
1717
modApi("dev.latvian.mods:rhino:${rhino_version}") {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.embeddedt.modernfix.fabric.mixin.perf.faster_command_suggestions;
2+
3+
import com.mojang.brigadier.suggestion.Suggestion;
4+
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
5+
import org.spongepowered.asm.mixin.*;
6+
import org.spongepowered.asm.mixin.injection.At;
7+
import org.spongepowered.asm.mixin.injection.Redirect;
8+
9+
import java.util.List;
10+
11+
/**
12+
* Simple hack-fix to limit the number of suggestions being processed. Not a perfect fix but mitigates lag decently
13+
* on an i3-4150.
14+
*/
15+
@Mixin(SuggestionsBuilder.class)
16+
public class SuggestionsBuilderMixin {
17+
@Unique
18+
private static final int MAX_SUGGESTIONS = 10000;
19+
20+
@Shadow @Final @Mutable
21+
private List<Suggestion> result;
22+
23+
@Redirect(method = "*", at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z"), require = 0)
24+
private <T> boolean addIfFits(List<T> list, T entry) {
25+
if(list != result || list.size() < MAX_SUGGESTIONS) {
26+
return list.add(entry);
27+
}
28+
return false;
29+
}
30+
}

fabric/testmod/build.gradle

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
apply plugin: "dev.architectury.loom"
2+
3+
loom {
4+
accessWidenerPath = project(":common").loom.accessWidenerPath
5+
}
6+
7+
dependencies {
8+
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
9+
mappings loom.layered() {
10+
officialMojangMappings()
11+
if(rootProject.hasProperty("parchment_version")) {
12+
parchment("org.parchmentmc.data:parchment-${minecraft_version}:${parchment_version}@zip")
13+
}
14+
}
15+
16+
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
17+
modImplementation(fabricApi.module("fabric-resource-loader-v0", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' }
18+
modImplementation(fabricApi.module("fabric-models-v0", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' }
19+
modImplementation(fabricApi.module("fabric-registry-sync-v0", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' }
20+
modImplementation(fabricApi.module("fabric-renderer-api-v1", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' }
21+
modRuntimeOnly(fabricApi.module("fabric-renderer-indigo", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' }
22+
23+
implementation project(path: ":common", configuration: "namedElements")
24+
implementation project(path: ":fabric", configuration: "namedElements")
25+
}
26+
27+
processResources {
28+
inputs.property "version", project.version
29+
30+
filesMatching("fabric.mod.json") {
31+
expand "version": project.version
32+
}
33+
}
34+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.embeddedt.modernfix.testmod;
2+
3+
import net.minecraft.world.level.block.Block;
4+
import net.minecraft.world.level.block.Blocks;
5+
import net.minecraft.world.level.block.state.BlockBehaviour;
6+
7+
public class TestBlock extends Block {
8+
private static final BlockBehaviour.Properties PROPERTIES = BlockBehaviour.Properties.copy(Blocks.STONE);
9+
10+
public TestBlock() {
11+
super(PROPERTIES);
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.embeddedt.modernfix.testmod;
2+
3+
import net.minecraft.world.item.BlockItem;
4+
import net.minecraft.world.item.CreativeModeTab;
5+
import net.minecraft.world.item.Item;
6+
7+
public class TestBlockItem extends BlockItem {
8+
private static final Item.Properties PROPERTIES = new Item.Properties().tab(CreativeModeTab.TAB_BUILDING_BLOCKS);
9+
10+
public TestBlockItem(TestBlock block) {
11+
super(block, PROPERTIES);
12+
}
13+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package org.embeddedt.modernfix.testmod;
2+
3+
import com.google.common.base.Stopwatch;
4+
import net.fabricmc.api.ModInitializer;
5+
import net.minecraft.core.Registry;
6+
import net.minecraft.resources.ResourceLocation;
7+
import net.minecraft.world.level.block.Blocks;
8+
import net.minecraft.world.level.block.state.BlockState;
9+
import org.apache.logging.log4j.LogManager;
10+
import org.apache.logging.log4j.Logger;
11+
12+
import java.util.ArrayList;
13+
import java.util.List;
14+
15+
public class TestMod implements ModInitializer {
16+
public static final String ID = "mfix_testmod";
17+
public static final Logger LOGGER = LogManager.getLogger("ModernFix TestMod");
18+
19+
public static final int NUM_COLORS = 100;
20+
public static final int MAX_COLOR = NUM_COLORS - 1;
21+
22+
public static final List<BlockState> WOOL_STATES = new ArrayList<>();
23+
24+
@Override
25+
public void onInitialize() {
26+
// Register 1 million blocks & items
27+
Stopwatch watch = Stopwatch.createStarted();
28+
int totalToRegister = NUM_COLORS * NUM_COLORS * NUM_COLORS;
29+
int progressReport = totalToRegister / 20;
30+
int numRegistered = 0;
31+
for(int r = 0; r < NUM_COLORS; r++) {
32+
for(int g = 0; g < NUM_COLORS; g++) {
33+
for(int b = 0; b < NUM_COLORS; b++) {
34+
ResourceLocation name = new ResourceLocation(ID, "wool_" + r + "_" + g + "_" + b);
35+
TestBlock block = Registry.register(Registry.BLOCK, name, new TestBlock());
36+
WOOL_STATES.add(block.defaultBlockState());
37+
Registry.register(Registry.ITEM, name, new TestBlockItem(block));
38+
numRegistered++;
39+
if((numRegistered % progressReport) == 0) {
40+
LOGGER.info(String.format("Registering... %.02f%%", ((float)numRegistered)/totalToRegister * 100));
41+
}
42+
}
43+
}
44+
}
45+
watch.stop();
46+
LOGGER.info("Registered {} registry entries in {}", totalToRegister, watch);
47+
}
48+
49+
private static final BlockState AIR = Blocks.AIR.defaultBlockState();
50+
51+
public static BlockState getColorCubeStateFor(int chunkX, int chunkY, int chunkZ) {
52+
BlockState blockState = AIR;
53+
if (chunkX >= 0 && chunkY >= 0 && chunkZ >= 0 && chunkX % 2 == 0 && chunkY % 2 == 0 && chunkZ % 2 == 0) {
54+
chunkX /= 2;
55+
chunkY /= 2;
56+
chunkZ /= 2;
57+
if(chunkX <= TestMod.MAX_COLOR && chunkY <= TestMod.MAX_COLOR && chunkZ <= TestMod.MAX_COLOR) {
58+
blockState = TestMod.WOOL_STATES.get((chunkX * TestMod.NUM_COLORS * TestMod.NUM_COLORS) + (chunkY * TestMod.NUM_COLORS) + chunkZ);
59+
}
60+
}
61+
62+
return blockState;
63+
}
64+
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
package org.embeddedt.modernfix.testmod.client;
2+
3+
import com.google.common.collect.ImmutableList;
4+
import com.mojang.datafixers.util.Pair;
5+
import net.fabricmc.fabric.api.renderer.v1.Renderer;
6+
import net.fabricmc.fabric.api.renderer.v1.RendererAccess;
7+
import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh;
8+
import net.fabricmc.fabric.api.renderer.v1.mesh.MeshBuilder;
9+
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
10+
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter;
11+
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
12+
import net.fabricmc.fabric.api.renderer.v1.model.ModelHelper;
13+
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
14+
import net.minecraft.client.renderer.block.model.BakedQuad;
15+
import net.minecraft.client.renderer.block.model.ItemOverrides;
16+
import net.minecraft.client.renderer.block.model.ItemTransforms;
17+
import net.minecraft.client.renderer.texture.TextureAtlas;
18+
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
19+
import net.minecraft.client.resources.model.*;
20+
import net.minecraft.core.BlockPos;
21+
import net.minecraft.core.Direction;
22+
import net.minecraft.resources.ResourceLocation;
23+
import net.minecraft.world.item.ItemStack;
24+
import net.minecraft.world.level.BlockAndTintGetter;
25+
import net.minecraft.world.level.block.state.BlockState;
26+
import org.embeddedt.modernfix.testmod.TestMod;
27+
import org.jetbrains.annotations.Nullable;
28+
29+
import java.util.*;
30+
import java.util.function.Function;
31+
import java.util.function.Supplier;
32+
33+
public class TestModBlockModel implements UnbakedModel, BakedModel, FabricBakedModel {
34+
private static final Material BASE_WOOL = new Material(TextureAtlas.LOCATION_BLOCKS, new ResourceLocation(TestMod.ID, "block/base_wool"));
35+
36+
private Mesh mesh;
37+
private TextureAtlasSprite texture;
38+
39+
private final int r, g, b;
40+
41+
public TestModBlockModel(int r, int g, int b) {
42+
this.r = r;
43+
this.g = g;
44+
this.b = b;
45+
}
46+
47+
@Override
48+
public boolean isVanillaAdapter() {
49+
return false;
50+
}
51+
52+
@Override
53+
public void emitBlockQuads(BlockAndTintGetter blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, RenderContext context) {
54+
context.meshConsumer().accept(mesh);
55+
}
56+
57+
@Override
58+
public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context) {
59+
context.meshConsumer().accept(mesh);
60+
}
61+
62+
@Override
63+
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) {
64+
return Collections.emptyList();
65+
}
66+
67+
@Override
68+
public boolean useAmbientOcclusion() {
69+
return true;
70+
}
71+
72+
@Override
73+
public boolean isGui3d() {
74+
return true;
75+
}
76+
77+
@Override
78+
public boolean usesBlockLight() {
79+
return true;
80+
}
81+
82+
@Override
83+
public boolean isCustomRenderer() {
84+
return false;
85+
}
86+
87+
@Override
88+
public TextureAtlasSprite getParticleIcon() {
89+
return texture;
90+
}
91+
92+
@Override
93+
public ItemTransforms getTransforms() {
94+
return ModelHelper.MODEL_TRANSFORM_BLOCK;
95+
}
96+
97+
@Override
98+
public ItemOverrides getOverrides() {
99+
return ItemOverrides.EMPTY;
100+
}
101+
102+
@Override
103+
public Collection<ResourceLocation> getDependencies() {
104+
return Collections.emptyList();
105+
}
106+
107+
@Override
108+
public Collection<Material> getMaterials(Function<ResourceLocation, UnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
109+
return ImmutableList.of(BASE_WOOL);
110+
}
111+
112+
private static int scaleColor(int c) {
113+
return c * 255 / TestMod.MAX_COLOR;
114+
}
115+
116+
@Nullable
117+
@Override
118+
public BakedModel bake(ModelBakery modelBakery, Function<Material, TextureAtlasSprite> spriteGetter, ModelState transform, ResourceLocation location) {
119+
// Build the mesh using the Renderer API
120+
Renderer renderer = RendererAccess.INSTANCE.getRenderer();
121+
MeshBuilder builder = renderer.meshBuilder();
122+
QuadEmitter emitter = builder.getEmitter();
123+
124+
texture = spriteGetter.apply(BASE_WOOL);
125+
126+
for(Direction direction : Direction.values()) {
127+
// Add a new face to the mesh
128+
emitter.square(direction, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f);
129+
// Set the sprite of the face, must be called after .square()
130+
// We haven't specified any UV coordinates, so we want to use the whole texture. BAKE_LOCK_UV does exactly that.
131+
emitter.spriteBake(0, texture, MutableQuadView.BAKE_LOCK_UV);
132+
int color = (255 << 24) | (scaleColor(r) << 16) | (scaleColor(g) << 8) | scaleColor(b);
133+
// Enable texture usage
134+
emitter.spriteColor(0, color, color, color, color);
135+
// Add the quad to the mesh
136+
emitter.emit();
137+
}
138+
mesh = builder.build();
139+
140+
return this;
141+
}
142+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.embeddedt.modernfix.testmod.client;
2+
3+
import net.fabricmc.api.ClientModInitializer;
4+
import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry;
5+
import net.minecraft.client.Minecraft;
6+
import org.embeddedt.modernfix.testmod.TestMod;
7+
8+
import java.util.regex.Matcher;
9+
import java.util.regex.Pattern;
10+
11+
public class TestModClient implements ClientModInitializer {
12+
private static final Pattern RGB_PATTERN = Pattern.compile("^wool_([0-9]+)_([0-9]+)_([0-9]+)$");
13+
@Override
14+
public void onInitializeClient() {
15+
ModelLoadingRegistry.INSTANCE.registerVariantProvider(resourceManager -> (modelId, context) -> {
16+
if(modelId.getNamespace().equals(TestMod.ID)) {
17+
Matcher matcher = RGB_PATTERN.matcher(modelId.getPath());
18+
if(matcher.matches()) {
19+
int r = Integer.parseInt(matcher.group(1));
20+
int g = Integer.parseInt(matcher.group(2));
21+
int b = Integer.parseInt(matcher.group(3));
22+
return new TestModBlockModel(r, g, b);
23+
}
24+
}
25+
return null;
26+
});
27+
// needed to make debug level rendering work correctly
28+
Minecraft.getInstance().smartCull = false;
29+
}
30+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.embeddedt.modernfix.testmod.mixin;
2+
3+
import net.minecraft.core.BlockPos;
4+
import net.minecraft.world.level.Level;
5+
import net.minecraft.world.level.block.state.BlockState;
6+
import net.minecraft.world.level.chunk.LevelChunk;
7+
import org.embeddedt.modernfix.testmod.TestMod;
8+
import org.spongepowered.asm.mixin.Final;
9+
import org.spongepowered.asm.mixin.Mixin;
10+
import org.spongepowered.asm.mixin.Shadow;
11+
import org.spongepowered.asm.mixin.injection.At;
12+
import org.spongepowered.asm.mixin.injection.Inject;
13+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
14+
15+
@Mixin(LevelChunk.class)
16+
public class ChunkMixin {
17+
@Shadow @Final private Level level;
18+
19+
@Inject(method = "getBlockState", at = @At("HEAD"), cancellable = true)
20+
private void redirectDebugWorld(BlockPos pos, CallbackInfoReturnable<BlockState> cir) {
21+
if(this.level.isDebug()) {
22+
cir.setReturnValue(TestMod.getColorCubeStateFor(pos.getX(), pos.getY(), pos.getZ()));
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)