Skip to content

Commit

Permalink
Backport
Browse files Browse the repository at this point in the history
  • Loading branch information
1foxy2 committed Dec 14, 2024
1 parent b99668b commit 5b551b6
Show file tree
Hide file tree
Showing 15 changed files with 187 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
// see https://fabricmc.net/develop/ for new versions
id 'fabric-loom' version '1.7-SNAPSHOT' apply false
id 'fabric-loom' version '1.8-SNAPSHOT' apply false
// see https://projects.neoforged.net/neoforged/moddevgradle for new versions
id 'net.neoforged.moddev' version '1.0.19' apply false
}
1 change: 0 additions & 1 deletion common/src/main/java/ca/fxco/moreculling/MoreCulling.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public class MoreCulling {
public static BlockRenderDispatcher blockRenderManager = null;

public static final String MOD_ID = "moreculling";
//TODO: make so it would work on the servers too
public static final TagKey<Block> DONT_CULL = TagKey.create(BuiltInRegistries.BLOCK.key(), ResourceLocation.fromNamespaceAndPath(MOD_ID, "dont_cull"));

public static Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
Expand Down
41 changes: 41 additions & 0 deletions common/src/main/java/ca/fxco/moreculling/config/ModMenuConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@
import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.clothconfig2.api.ConfigBuilder;
import me.shedaniel.clothconfig2.api.ConfigCategory;
import me.shedaniel.clothconfig2.impl.builders.StringListBuilder;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;

public class ModMenuConfig {

Expand Down Expand Up @@ -164,6 +169,42 @@ public static Screen createConfigScreen(Screen parent) {
})
.build();

//dont cull list
generalCategory.addEntry(new StringListBuilder(
Component.translatable("text.cloth-config.reset_value"),
Component.translatable("moreculling.config.option.dontCull"), MoreCulling.CONFIG.dontCull)
.setDefaultValue(new ArrayList<>())
.setTooltip(Component.translatable("moreculling.config.option.dontCull.tooltip"))
.setSaveConsumer(
value -> {
MoreCulling.CONFIG.dontCull.forEach(prevBlockId -> {
Optional<Block> optionalBlock =
BuiltInRegistries.BLOCK.getOptional(ResourceLocation.parse(prevBlockId));

if (optionalBlock.isEmpty())
return;

((MoreBlockCulling) optionalBlock.get()).moreculling$setCanCull(true);
}
);

value.forEach(blockId -> {
Optional<Block> optionalBlock = BuiltInRegistries.BLOCK.getOptional(ResourceLocation.parse(blockId));

if (optionalBlock.isEmpty()) {
MoreCulling.LOGGER.warn("Block with id {} doesn't exist", blockId);
return;
}

MoreBlockCulling block = (MoreBlockCulling) optionalBlock.get();
if (block.moreculling$canCull())
block.moreculling$setCanCull(false);
});

MoreCulling.CONFIG.dontCull = value;
}
).build());

// BlockStates
generalCategory.addEntry(new DynamicBooleanBuilder("moreculling.config.option.blockStateCulling")
.setValue(MoreCulling.CONFIG.useBlockStateCulling)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import me.shedaniel.autoconfig.annotation.Config;
import me.shedaniel.autoconfig.annotation.ConfigEntry;

import java.util.ArrayList;
import java.util.List;

@Config(name = "moreculling")
public class MoreCullingConfig implements ConfigData {

Expand All @@ -21,6 +24,8 @@ public class MoreCullingConfig implements ConfigData {

public boolean rainCulling = true;

public List<String> dontCull = new ArrayList<>();

public boolean useBlockStateCulling = true;

public boolean useCustomItemFrameRenderer = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public abstract class BrewingStandBlock_voxelMixin extends BaseEntityBlock imple
private static final VoxelShape moreculling$occlusionShape = Shapes.or(
Block.box(1, 0, 1, 7, 2, 7),
Block.box(1, 0, 9, 7, 2, 15),
Block.box(9, 0, 5, 15, 2, 11)
Block.box(9, 0, 5, 15, 2, 11),
Block.box(7.0, 0.0, 7.0, 9.0, 14.0, 9.0)
) ;

protected BrewingStandBlock_voxelMixin(Properties settings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.main.GameConfig;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Optional;

@Mixin(Minecraft.class)
public class Minecraft_loadBlocksMixin {

Expand All @@ -24,6 +28,19 @@ public class Minecraft_loadBlocksMixin {
MoreCulling.CONFIG.useOnModdedBlocksByDefault
));
});
MoreCulling.CONFIG.dontCull.forEach(blockId -> {
Optional<Block> optionalBlock =
BuiltInRegistries.BLOCK.getOptional(ResourceLocation.parse(blockId));

if (optionalBlock.isEmpty()) {
MoreCulling.LOGGER.warn("Block with id {} doesn't exist", blockId);
return;
}

MoreBlockCulling block = (MoreBlockCulling) optionalBlock.get();
if (block.moreculling$canCull())
block.moreculling$setCanCull(false);
});
MoreCulling.LOGGER.info("Cached all modded block culling states");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public abstract class SimpleBakedModel_cacheMixin implements BakedOpacity {
if (!layeredQuads.isEmpty()) {
BakedQuad initialQuad = layeredQuads.removeFirst();
SpriteOpacity opacity = ((SpriteOpacity) initialQuad.getSprite());
QuadBounds bounds = VertexUtils.getQuadBounds(initialQuad, direction.getAxis());
NativeImage image = opacity.moreculling$getUnmipmappedImage();
QuadBounds bounds = VertexUtils.getQuadBounds(initialQuad, direction.getAxis(),
image.getWidth(), image.getHeight());
if (!opacity.moreculling$hasTranslucency(bounds)) {
if (!layeredQuads.isEmpty()) {
List<NativeImage> overlappingImages = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ public static boolean shouldDrawSideCulling(BlockState thisState,
return shouldDrawFace.get();
}
}
if (sideState.canOcclude() || (!sideState.getRenderShape().equals(RenderShape.INVISIBLE) &&
if (((MoreStateCulling) sideState).moreculling$canCull() &&
(sideState.canOcclude() || (!sideState.getRenderShape().equals(RenderShape.INVISIBLE) &&
((MoreStateCulling) sideState).moreculling$canCull() &&
((MoreStateCulling) thisState).moreculling$shouldAttemptToCull(side) &&
((MoreStateCulling) sideState).moreculling$shouldAttemptToCull(side.getOpposite()))) {
((MoreStateCulling) sideState).moreculling$shouldAttemptToCull(side.getOpposite())))) {
return shouldDrawFace(world, thisState, sideState, thisPos, sidePos, side);
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,19 @@ private static Vector2f getPos(int[] data, int vertexIndex, Direction.Axis axis)
}
}

public static QuadBounds getQuadBounds(BakedQuad quad, Direction.Axis axis) {
public static QuadBounds getQuadBounds(BakedQuad quad, Direction.Axis axis,
int resolutionScaleX, int resolutionScaleY) {
Vector2i minPos = new Vector2i(Integer.MAX_VALUE);
Vector2i maxPos = new Vector2i(-Integer.MAX_VALUE);
int[] vertexData = quad.getVertices();
for (int i = 0; i < 4; i++) {
Vector2f tmpPos = getPos(vertexData, i, axis).mul(16);
Vector2f tmpPos = getPos(vertexData, i, axis);
Vector2i pos = new Vector2i(Math.round(tmpPos.x), Math.round(tmpPos.y));
minPos.min(pos);
maxPos.max(pos);
}
return new QuadBounds(minPos.x, minPos.y, maxPos.x, maxPos.y);
return new QuadBounds(minPos.x * resolutionScaleX, minPos.y * resolutionScaleY,
maxPos.x * resolutionScaleX, maxPos.y * resolutionScaleY);
}

public static boolean isAxisAligned(BakedQuad quad) {
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/moreculling/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"moreculling.config.option.beaconBeamCulling.tooltip": "Does frustum culling on beacon beams",
"moreculling.config.option.entityModelCulling": "Entity Model Culling",
"moreculling.config.option.entityModelCulling.tooltip": "This only helps if your gpu is the bottleneck and your cpu has some performance to spare!",
"moreculling.config.option.dontCull": "Dont Cull",
"moreculling.config.option.dontCull.tooltip": "Add block id here to prevent it from culling. for example minecraft:bamboo",
"moreculling.config.option.blockStateCulling": "BlockState Culling",
"moreculling.config.option.blockStateCulling.tooltip": "Enables aggressive blockstate culling",
"moreculling.config.option.customItemFrameRenderer": "Custom Item Frame Renderer",
Expand Down
53 changes: 53 additions & 0 deletions common/src/main/resources/assets/moreculling/lang/ja_jp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"modmenu.descriptionTranslation.moreculling": "様々なカリングの処理方法を変更して、パフォーマンスを向上させるMod",
"moreculling.title": "MoreCulling",
"moreculling.config.category.general": "カリングの一般設定",
"moreculling.config.category.compat": "Modの互換性",
"moreculling.config.option.dontCull": "カリングしないブロック",
"moreculling.config.option.dontCull.tooltip": "ここにブロックIDを追加すると、そのブロックがカリングされなくなります(例:minecraft:bamboo)",
"moreculling.config.option.cloudCulling": "雲のカリング",
"moreculling.config.option.cloudCulling.tooltip": "OpenGLの頂点の並び順(winding order)を変更して、面カリングを適用します",
"moreculling.config.option.signTextCulling": "看板の文字のカリング",
"moreculling.config.option.signTextCulling.tooltip": "看板の文字が見えない場合に、描画されないようにします",
"moreculling.config.option.rainCulling": "雨/雪のカリング",
"moreculling.config.option.rainCulling.tooltip": "雨/雪のフラスタムカリングを行います",
"moreculling.config.option.beaconBeamCulling": "ビーコンビームのカリング",
"moreculling.config.option.beaconBeamCulling.tooltip": "ビーコンのビームのフラスタムカリングを行います",
"moreculling.config.option.entityModelCulling": "エンティティモデルのカリング",
"moreculling.config.option.entityModelCulling.tooltip": "これはGPUがボトルネックになっていて、CPU性能に余裕がある場合にのみ役立ちます!",
"moreculling.config.option.blockStateCulling": "ブロック状態カリング",
"moreculling.config.option.blockStateCulling.tooltip": "積極的なブロック状態によるカリングを有効にします",
"moreculling.config.option.customItemFrameRenderer": "カスタム額縁描画",
"moreculling.config.option.customItemFrameRenderer.tooltip": "額縁のカスタム描画を有効にします",
"moreculling.config.option.itemFrameMapCulling": "額縁内のマップのカリング",
"moreculling.config.option.itemFrameMapCulling.tooltip": "額縁に入れられたマップのカリングを有効にします",
"moreculling.config.option.itemFrameLOD": "額縁のLOD",
"moreculling.config.option.itemFrameLOD.tooltip": "額縁のLevel of Detail(LOD)を有効にします",
"moreculling.config.option.itemFrameLODRange": "額縁のLODの距離",
"moreculling.config.option.itemFrameLODRange.tooltip": "額縁のLODが機能し始める距離を変更します",
"moreculling.config.option.itemFrame3FaceCulling": "額縁の3面カリング",
"moreculling.config.option.itemFrame3FaceCulling.tooltip": "3面カリング技術を有効にします",
"moreculling.config.option.itemFrame3FaceCullingRange": "額縁の3面カリングの距離",
"moreculling.config.option.itemFrame3FaceCullingRange.tooltip": "3面カリングが機能し始める距離を変更します。より短い距離では見える可能性があります。",
"moreculling.config.option.leavesCulling": "葉のカリング",
"moreculling.config.option.leavesCulling.tooltip": "葉ブロックのカリング方法を変更します",
"moreculling.config.option.leavesCullingAmount": "葉のカリングの量",
"moreculling.config.option.leavesCullingAmount.tooltip": "「深度」ベースのカリングで葉をチェックする量を変更します。低いほど速いです!",
"moreculling.config.option.mangroveOnly": "%s を使用中のため、マングローブの根のみをカリングします",
"moreculling.config.option.includeMangroveRoots": "マングローブの根を含める",
"moreculling.config.option.includeMangroveRoots.tooltip": "マングローブの根も同じ方法でカリングします。「ブロック状態」モードは機能しません!",
"moreculling.config.option.powderSnowCulling": "粉雪のカリング",
"moreculling.config.option.powderSnowCulling.tooltip": "粉雪が固体ブロックの面に対してカリングされない問題を修正します",
"moreculling.config.option.endGatewayCulling": "エンドゲートウェイのカリング",
"moreculling.config.option.endGatewayCulling.tooltip": "他のブロックがエンドゲートウェイに対してカリングされるようにします",
"moreculling.config.option.useOnModdedBlocks": "Modのブロック状態カリング",
"moreculling.config.option.useOnModdedBlocks.tooltip": "ブロック状態カリングを、デフォルトでModのブロックに対しても機能するようにします",
"moreculling.config.options.blockstate": "ブロック状態",
"moreculling.config.options.check": "周囲をチェック",
"moreculling.config.options.gap": "隙間",
"moreculling.config.options.depth": "深度",
"moreculling.config.options.random": "ランダム",
"moreculling.config.options.vertical": "垂直",
"moreculling.config.resetCache": "キャッシュをリセット",
"moreculling.config.optionDisabled": "%s を使用中のため、このオプションは無効になっています"
}
Loading

0 comments on commit 5b551b6

Please sign in to comment.