-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/1.16' into 1.18
- Loading branch information
Showing
15 changed files
with
438 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...ddedt/modernfix/fabric/mixin/perf/faster_command_suggestions/SuggestionsBuilderMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.embeddedt.modernfix.fabric.mixin.perf.faster_command_suggestions; | ||
|
||
import com.mojang.brigadier.suggestion.Suggestion; | ||
import com.mojang.brigadier.suggestion.SuggestionsBuilder; | ||
import org.spongepowered.asm.mixin.*; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Simple hack-fix to limit the number of suggestions being processed. Not a perfect fix but mitigates lag decently | ||
* on an i3-4150. | ||
*/ | ||
@Mixin(SuggestionsBuilder.class) | ||
public class SuggestionsBuilderMixin { | ||
@Unique | ||
private static final int MAX_SUGGESTIONS = 10000; | ||
|
||
@Shadow @Final @Mutable | ||
private List<Suggestion> result; | ||
|
||
@Redirect(method = "*", at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z"), require = 0) | ||
private <T> boolean addIfFits(List<T> list, T entry) { | ||
if(list != result || list.size() < MAX_SUGGESTIONS) { | ||
return list.add(entry); | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
apply plugin: "dev.architectury.loom" | ||
|
||
loom { | ||
accessWidenerPath = project(":common").loom.accessWidenerPath | ||
} | ||
|
||
dependencies { | ||
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}" | ||
mappings loom.layered() { | ||
officialMojangMappings() | ||
if(rootProject.hasProperty("parchment_version")) { | ||
parchment("org.parchmentmc.data:parchment-${minecraft_version}:${parchment_version}@zip") | ||
} | ||
} | ||
|
||
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" | ||
modImplementation(fabricApi.module("fabric-resource-loader-v0", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' } | ||
modImplementation(fabricApi.module("fabric-models-v0", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' } | ||
modImplementation(fabricApi.module("fabric-renderer-api-v1", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' } | ||
modRuntimeOnly(fabricApi.module("fabric-renderer-indigo", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' } | ||
|
||
implementation project(path: ":common", configuration: "namedElements") | ||
implementation project(path: ":fabric", configuration: "namedElements") | ||
} | ||
|
||
processResources { | ||
inputs.property "version", project.version | ||
|
||
filesMatching("fabric.mod.json") { | ||
expand "version": project.version | ||
} | ||
} | ||
|
13 changes: 13 additions & 0 deletions
13
fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/TestBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.embeddedt.modernfix.testmod; | ||
|
||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.Blocks; | ||
import net.minecraft.world.level.block.state.BlockBehaviour; | ||
|
||
public class TestBlock extends Block { | ||
private static final BlockBehaviour.Properties PROPERTIES = BlockBehaviour.Properties.copy(Blocks.STONE); | ||
|
||
public TestBlock() { | ||
super(PROPERTIES); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/TestBlockItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.embeddedt.modernfix.testmod; | ||
|
||
import net.minecraft.world.item.BlockItem; | ||
import net.minecraft.world.item.CreativeModeTab; | ||
import net.minecraft.world.item.Item; | ||
|
||
public class TestBlockItem extends BlockItem { | ||
private static final Item.Properties PROPERTIES = new Item.Properties().tab(CreativeModeTab.TAB_BUILDING_BLOCKS); | ||
|
||
public TestBlockItem(TestBlock block) { | ||
super(block, PROPERTIES); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/TestMod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.embeddedt.modernfix.testmod; | ||
|
||
import com.google.common.base.Stopwatch; | ||
import net.fabricmc.api.ModInitializer; | ||
import net.minecraft.core.Registry; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.level.block.Blocks; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class TestMod implements ModInitializer { | ||
public static final String ID = "mfix_testmod"; | ||
public static final Logger LOGGER = LogManager.getLogger("ModernFix TestMod"); | ||
|
||
public static final int NUM_COLORS = 100; | ||
public static final int MAX_COLOR = NUM_COLORS - 1; | ||
|
||
public static final List<BlockState> WOOL_STATES = new ArrayList<>(); | ||
|
||
@Override | ||
public void onInitialize() { | ||
// Register 1 million blocks & items | ||
Stopwatch watch = Stopwatch.createStarted(); | ||
int totalToRegister = NUM_COLORS * NUM_COLORS * NUM_COLORS; | ||
int progressReport = totalToRegister / 20; | ||
int numRegistered = 0; | ||
for(int r = 0; r < NUM_COLORS; r++) { | ||
for(int g = 0; g < NUM_COLORS; g++) { | ||
for(int b = 0; b < NUM_COLORS; b++) { | ||
ResourceLocation name = new ResourceLocation(ID, "wool_" + r + "_" + g + "_" + b); | ||
TestBlock block = Registry.register(Registry.BLOCK, name, new TestBlock()); | ||
WOOL_STATES.add(block.defaultBlockState()); | ||
Registry.register(Registry.ITEM, name, new TestBlockItem(block)); | ||
numRegistered++; | ||
if((numRegistered % progressReport) == 0) { | ||
LOGGER.info(String.format("Registering... %.02f%%", ((float)numRegistered)/totalToRegister * 100)); | ||
} | ||
} | ||
} | ||
} | ||
watch.stop(); | ||
LOGGER.info("Registered {} registry entries in {}", totalToRegister, watch); | ||
} | ||
|
||
private static final BlockState AIR = Blocks.AIR.defaultBlockState(); | ||
|
||
public static BlockState getColorCubeStateFor(int chunkX, int chunkY, int chunkZ) { | ||
BlockState blockState = AIR; | ||
if (chunkX >= 0 && chunkY >= 0 && chunkZ >= 0 && chunkX % 2 == 0 && chunkY % 2 == 0 && chunkZ % 2 == 0) { | ||
chunkX /= 2; | ||
chunkY /= 2; | ||
chunkZ /= 2; | ||
if(chunkX <= TestMod.MAX_COLOR && chunkY <= TestMod.MAX_COLOR && chunkZ <= TestMod.MAX_COLOR) { | ||
blockState = TestMod.WOOL_STATES.get((chunkX * TestMod.NUM_COLORS * TestMod.NUM_COLORS) + (chunkY * TestMod.NUM_COLORS) + chunkZ); | ||
} | ||
} | ||
|
||
return blockState; | ||
} | ||
} |
142 changes: 142 additions & 0 deletions
142
fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/client/TestModBlockModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package org.embeddedt.modernfix.testmod.client; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.mojang.datafixers.util.Pair; | ||
import net.fabricmc.fabric.api.renderer.v1.Renderer; | ||
import net.fabricmc.fabric.api.renderer.v1.RendererAccess; | ||
import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh; | ||
import net.fabricmc.fabric.api.renderer.v1.mesh.MeshBuilder; | ||
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView; | ||
import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter; | ||
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel; | ||
import net.fabricmc.fabric.api.renderer.v1.model.ModelHelper; | ||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; | ||
import net.minecraft.client.renderer.block.model.BakedQuad; | ||
import net.minecraft.client.renderer.block.model.ItemOverrides; | ||
import net.minecraft.client.renderer.block.model.ItemTransforms; | ||
import net.minecraft.client.renderer.texture.TextureAtlas; | ||
import net.minecraft.client.renderer.texture.TextureAtlasSprite; | ||
import net.minecraft.client.resources.model.*; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.BlockAndTintGetter; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import org.embeddedt.modernfix.testmod.TestMod; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.*; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
public class TestModBlockModel implements UnbakedModel, BakedModel, FabricBakedModel { | ||
private static final Material BASE_WOOL = new Material(TextureAtlas.LOCATION_BLOCKS, new ResourceLocation(TestMod.ID, "block/base_wool")); | ||
|
||
private Mesh mesh; | ||
private TextureAtlasSprite texture; | ||
|
||
private final int r, g, b; | ||
|
||
public TestModBlockModel(int r, int g, int b) { | ||
this.r = r; | ||
this.g = g; | ||
this.b = b; | ||
} | ||
|
||
@Override | ||
public boolean isVanillaAdapter() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void emitBlockQuads(BlockAndTintGetter blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, RenderContext context) { | ||
context.meshConsumer().accept(mesh); | ||
} | ||
|
||
@Override | ||
public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context) { | ||
context.meshConsumer().accept(mesh); | ||
} | ||
|
||
@Override | ||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public boolean useAmbientOcclusion() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isGui3d() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean usesBlockLight() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isCustomRenderer() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public TextureAtlasSprite getParticleIcon() { | ||
return texture; | ||
} | ||
|
||
@Override | ||
public ItemTransforms getTransforms() { | ||
return ModelHelper.MODEL_TRANSFORM_BLOCK; | ||
} | ||
|
||
@Override | ||
public ItemOverrides getOverrides() { | ||
return ItemOverrides.EMPTY; | ||
} | ||
|
||
@Override | ||
public Collection<ResourceLocation> getDependencies() { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public Collection<Material> getMaterials(Function<ResourceLocation, UnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) { | ||
return ImmutableList.of(BASE_WOOL); | ||
} | ||
|
||
private static int scaleColor(int c) { | ||
return c * 255 / TestMod.MAX_COLOR; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BakedModel bake(ModelBakery modelBakery, Function<Material, TextureAtlasSprite> spriteGetter, ModelState transform, ResourceLocation location) { | ||
// Build the mesh using the Renderer API | ||
Renderer renderer = RendererAccess.INSTANCE.getRenderer(); | ||
MeshBuilder builder = renderer.meshBuilder(); | ||
QuadEmitter emitter = builder.getEmitter(); | ||
|
||
texture = spriteGetter.apply(BASE_WOOL); | ||
|
||
for(Direction direction : Direction.values()) { | ||
// Add a new face to the mesh | ||
emitter.square(direction, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f); | ||
// Set the sprite of the face, must be called after .square() | ||
// We haven't specified any UV coordinates, so we want to use the whole texture. BAKE_LOCK_UV does exactly that. | ||
emitter.spriteBake(0, texture, MutableQuadView.BAKE_LOCK_UV); | ||
int color = (255 << 24) | (scaleColor(r) << 16) | (scaleColor(g) << 8) | scaleColor(b); | ||
// Enable texture usage | ||
emitter.spriteColor(0, color, color, color, color); | ||
// Add the quad to the mesh | ||
emitter.emit(); | ||
} | ||
mesh = builder.build(); | ||
|
||
return this; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/client/TestModClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.embeddedt.modernfix.testmod.client; | ||
|
||
import net.fabricmc.api.ClientModInitializer; | ||
import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry; | ||
import org.embeddedt.modernfix.testmod.TestMod; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class TestModClient implements ClientModInitializer { | ||
private static final Pattern RGB_PATTERN = Pattern.compile("^wool_([0-9]+)_([0-9]+)_([0-9]+)$"); | ||
@Override | ||
public void onInitializeClient() { | ||
ModelLoadingRegistry.INSTANCE.registerVariantProvider(resourceManager -> (modelId, context) -> { | ||
if(modelId.getNamespace().equals(TestMod.ID)) { | ||
Matcher matcher = RGB_PATTERN.matcher(modelId.getPath()); | ||
if(matcher.matches()) { | ||
int r = Integer.parseInt(matcher.group(1)); | ||
int g = Integer.parseInt(matcher.group(2)); | ||
int b = Integer.parseInt(matcher.group(3)); | ||
return new TestModBlockModel(r, g, b); | ||
} | ||
} | ||
return null; | ||
}); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
fabric/testmod/src/main/java/org/embeddedt/modernfix/testmod/mixin/ChunkMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.embeddedt.modernfix.testmod.mixin; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.chunk.LevelChunk; | ||
import org.embeddedt.modernfix.testmod.TestMod; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(LevelChunk.class) | ||
public class ChunkMixin { | ||
@Shadow @Final private Level level; | ||
|
||
@Inject(method = "getBlockState", at = @At("HEAD"), cancellable = true) | ||
private void redirectDebugWorld(BlockPos pos, CallbackInfoReturnable<BlockState> cir) { | ||
if(this.level.isDebug()) { | ||
cir.setReturnValue(TestMod.getColorCubeStateFor(pos.getX(), pos.getY(), pos.getZ())); | ||
} | ||
} | ||
} |
Oops, something went wrong.