Skip to content

Commit f754b66

Browse files
committed
Get rid of magic numbers in previous commit
1 parent f29dea5 commit f754b66

10 files changed

+108
-106
lines changed

src/main/java/corundum/rubinated_nether/client/RubinatedNetherClient.java

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
@OnlyIn(Dist.CLIENT)
1919
public class RubinatedNetherClient {
20+
public static final int WHITE = 0xFFFFFFFF;
21+
2022
public static void client(IEventBus bussin) {
2123
bussin.addListener(RubinatedNetherClient::registerParticleProviders);
2224
bussin.addListener(RubinatedNetherClient::registerEntityLayers);

src/main/java/corundum/rubinated_nether/client/render/ShaderHelper.java

+37-39
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,40 @@
1010

1111
@OnlyIn(Dist.CLIENT)
1212
public class ShaderHelper {
13-
14-
private static final BooleanSupplier shaderPackInUse;
15-
16-
static {
17-
if (ModList.get().isLoaded("iris") || ModList.get().isLoaded("oculus")) {
18-
shaderPackInUse = () -> IrisApi.getInstance().isShaderPackInUse();
19-
} else if (ClassLoader.getPlatformClassLoader().getDefinedPackage("net.optifine") != null) {
20-
shaderPackInUse = optifineShadersInUse();
21-
} else {
22-
shaderPackInUse = () -> false;
23-
}
24-
}
25-
26-
public static boolean isShaderPackInUse() {
27-
return shaderPackInUse.getAsBoolean();
28-
}
29-
30-
/**
31-
* Code taken from Flywheel by Jozufozu, licensed under MIT.
32-
* Thank you for your scary reflection magic.
33-
*/
34-
private static BooleanSupplier optifineShadersInUse() {
35-
try {
36-
Class<?> ofShaders = Class.forName("net.optifine.shaders.Shaders");
37-
Field field = ofShaders.getDeclaredField("shaderPackLoaded");
38-
field.setAccessible(true);
39-
return () -> {
40-
try {
41-
return field.getBoolean(null);
42-
} catch (IllegalAccessException ignored) {
43-
return false;
44-
}
45-
};
46-
} catch (Exception ignored) {
47-
return () -> false;
48-
}
49-
}
50-
51-
}
13+
private static final BooleanSupplier shaderPackInUse;
14+
15+
static {
16+
if (ModList.get().isLoaded("iris") || ModList.get().isLoaded("oculus")) {
17+
shaderPackInUse = () -> IrisApi.getInstance().isShaderPackInUse();
18+
} else if (ClassLoader.getPlatformClassLoader().getDefinedPackage("net.optifine") != null) {
19+
shaderPackInUse = optifineShadersInUse();
20+
} else {
21+
shaderPackInUse = () -> false;
22+
}
23+
}
24+
25+
public static boolean isShaderPackInUse() {
26+
return shaderPackInUse.getAsBoolean();
27+
}
28+
29+
/**
30+
* Code taken from Flywheel by Jozufozu, licensed under MIT.
31+
* Thank you for your scary reflection magic.
32+
*/
33+
private static BooleanSupplier optifineShadersInUse() {
34+
try {
35+
Class<?> ofShaders = Class.forName("net.optifine.shaders.Shaders");
36+
Field field = ofShaders.getDeclaredField("shaderPackLoaded");
37+
field.setAccessible(true);
38+
return () -> {
39+
try {
40+
return field.getBoolean(null);
41+
} catch (IllegalAccessException ignored) {
42+
return false;
43+
}
44+
};
45+
} catch (Exception ignored) {
46+
return () -> false;
47+
}
48+
}
49+
}

src/main/java/corundum/rubinated_nether/client/render/entity/RubyLensRenderLayer.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.mojang.blaze3d.vertex.PoseStack;
44

55
import corundum.rubinated_nether.RubinatedNether;
6+
import corundum.rubinated_nether.client.RubinatedNetherClient;
67
import corundum.rubinated_nether.content.RNItems;
78
import net.minecraft.client.model.EntityModel;
89
import net.minecraft.client.model.HeadedModel;
@@ -37,7 +38,7 @@ public void render(PoseStack poseStack, MultiBufferSource buffer, int packedLigh
3738
buffer.getBuffer(lensModel.renderType(RUBY_LENS_TEXTURE)),
3839
packedLight,
3940
OverlayTexture.NO_OVERLAY,
40-
0xFFFFFFFF
41+
RubinatedNetherClient.WHITE
4142
);
4243
}
4344
}

src/main/java/corundum/rubinated_nether/client/render/entity/RubyLensRenderer.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package corundum.rubinated_nether.client.render.entity;
22

33
import com.mojang.blaze3d.vertex.PoseStack;
4+
5+
import corundum.rubinated_nether.client.RubinatedNetherClient;
46
import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap;
57
import net.minecraft.client.model.EntityModel;
68
import net.minecraft.client.model.HeadedModel;
@@ -26,7 +28,7 @@ protected void renderInternal(EntityModel<? extends LivingEntity> entityModel, P
2628
multiBufferSource.getBuffer(model.renderType(RubyLensRenderLayer.RUBY_LENS_TEXTURE)),
2729
light,
2830
OverlayTexture.NO_OVERLAY,
29-
0xFFFFFFFF
31+
RubinatedNetherClient.WHITE
3032
);
3133
}
3234
}

src/main/java/corundum/rubinated_nether/mixin/LevelMixin.java

+27-28
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,34 @@
1717

1818
@Mixin(Level.class)
1919
public abstract class LevelMixin implements UpdateListenerHolder {
20+
@Shadow
21+
public abstract BlockState getBlockState(BlockPos pos);
2022

21-
@Shadow
22-
public abstract BlockState getBlockState(BlockPos pos);
23+
@Unique
24+
private final Long2ReferenceMap<Set<BlockUpdateListener>> rubinatedNether$updateListeners = new Long2ReferenceOpenHashMap<>();
2325

24-
@Unique
25-
private final Long2ReferenceMap<Set<BlockUpdateListener>> rubinatedNether$updateListeners = new Long2ReferenceOpenHashMap<>();
26+
@Override
27+
public void rubinatedNether$addUpdateListener(BlockUpdateListener listener) {
28+
listener.getListenedPositions()
29+
.mapToLong(BlockPos::asLong)
30+
.forEach(l -> rubinatedNether$updateListeners.computeIfAbsent(l, $ -> new ObjectArraySet<>()).add(listener));
31+
}
2632

27-
@Override
28-
public void rubinatedNether$addUpdateListener(BlockUpdateListener listener) {
29-
listener.getListenedPositions()
30-
.mapToLong(BlockPos::asLong)
31-
.forEach(l -> rubinatedNether$updateListeners.computeIfAbsent(l, $ -> new ObjectArraySet<>()).add(listener));
32-
}
33-
34-
@Override
35-
public void rubinatedNether$handleBlockUpdate(BlockPos pos) {
36-
long longPos = pos.asLong();
37-
Set<BlockUpdateListener> listeners = rubinatedNether$updateListeners.get(longPos);
38-
if(listeners != null) {
39-
Iterator<BlockUpdateListener> iterator = listeners.iterator();
40-
while (iterator.hasNext()) {
41-
BlockUpdateListener listener = iterator.next();
42-
if(listener.shouldRemove()) {
43-
iterator.remove();
44-
} else {
45-
listener.handleBlockUpdate((Level) (Object) this, pos, getBlockState(pos));
46-
}
47-
}
48-
if(listeners.isEmpty()) rubinatedNether$updateListeners.remove(longPos);
49-
}
50-
}
33+
@Override
34+
public void rubinatedNether$handleBlockUpdate(BlockPos pos) {
35+
long longPos = pos.asLong();
36+
Set<BlockUpdateListener> listeners = rubinatedNether$updateListeners.get(longPos);
37+
if(listeners != null) {
38+
Iterator<BlockUpdateListener> iterator = listeners.iterator();
39+
while (iterator.hasNext()) {
40+
BlockUpdateListener listener = iterator.next();
41+
if(listener.shouldRemove()) {
42+
iterator.remove();
43+
} else {
44+
listener.handleBlockUpdate((Level) (Object) this, pos, getBlockState(pos));
45+
}
46+
}
47+
if(listeners.isEmpty()) rubinatedNether$updateListeners.remove(longPos);
48+
}
49+
}
5150
}

src/main/java/corundum/rubinated_nether/mixin/accessors/AbstractFurnaceBlockEntityAccessor.java

+28-28
Original file line numberDiff line numberDiff line change
@@ -13,44 +13,44 @@
1313

1414
@Mixin(AbstractFurnaceBlockEntity.class)
1515
public interface AbstractFurnaceBlockEntityAccessor {
16-
@Accessor("quickCheck")
17-
RecipeManager.CachedCheck<SingleRecipeInput, ? extends AbstractCookingRecipe> rubinatedNether$getQuickCheck();
16+
@Accessor("quickCheck")
17+
RecipeManager.CachedCheck<SingleRecipeInput, ? extends AbstractCookingRecipe> rubinatedNether$getQuickCheck();
1818

19-
@Invoker
20-
boolean callCanBurn(RegistryAccess registryAccess, @Nullable RecipeHolder<?> recipe, NonNullList<ItemStack> stacks, int stackSize, AbstractFurnaceBlockEntity furnaceBlockEntity);
19+
@Invoker
20+
boolean callCanBurn(RegistryAccess registryAccess, @Nullable RecipeHolder<?> recipe, NonNullList<ItemStack> stacks, int stackSize, AbstractFurnaceBlockEntity furnaceBlockEntity);
2121

22-
@Accessor("litTime")
23-
int rubinatedNether$getLitTime();
22+
@Accessor("litTime")
23+
int rubinatedNether$getLitTime();
2424

25-
@Accessor("litTime")
26-
void rubinatedNether$setLitTime(int litTime);
25+
@Accessor("litTime")
26+
void rubinatedNether$setLitTime(int litTime);
2727

28-
@Accessor("litDuration")
29-
void rubinatedNether$setLitDuration(int litDuration);
28+
@Accessor("litDuration")
29+
void rubinatedNether$setLitDuration(int litDuration);
3030

31-
@Accessor("cookingProgress")
32-
int rubinatedNether$getCookingProgress();
31+
@Accessor("cookingProgress")
32+
int rubinatedNether$getCookingProgress();
3333

34-
@Accessor("cookingProgress")
35-
void rubinatedNether$setCookingProgress(int cookingProgress);
34+
@Accessor("cookingProgress")
35+
void rubinatedNether$setCookingProgress(int cookingProgress);
3636

37-
@Accessor("cookingTotalTime")
38-
int rubinatedNether$getCookingTotalTime();
37+
@Accessor("cookingTotalTime")
38+
int rubinatedNether$getCookingTotalTime();
3939

40-
@Accessor("cookingTotalTime")
41-
void rubinatedNether$setCookingTotalTime(int cookingTotalTime);
40+
@Accessor("cookingTotalTime")
41+
void rubinatedNether$setCookingTotalTime(int cookingTotalTime);
4242

43-
@Invoker
44-
boolean callIsLit();
43+
@Invoker
44+
boolean callIsLit();
4545

46-
@Invoker
47-
static int callGetTotalCookTime(Level level, AbstractFurnaceBlockEntity blockEntity) {
48-
throw new AssertionError();
49-
}
46+
@Invoker
47+
static int callGetTotalCookTime(Level level, AbstractFurnaceBlockEntity blockEntity) {
48+
throw new AssertionError();
49+
}
5050

51-
@Accessor("items")
52-
NonNullList<ItemStack> rubinatedNether$getItems();
51+
@Accessor("items")
52+
NonNullList<ItemStack> rubinatedNether$getItems();
5353

54-
@Invoker
55-
int callGetBurnDuration(ItemStack pFuel);
54+
@Invoker
55+
int callGetBurnDuration(ItemStack pFuel);
5656
}

src/main/java/corundum/rubinated_nether/mixin/accessors/DoublePlantBlockAccessor.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
@Mixin(DoublePlantBlock.class)
1212
public interface DoublePlantBlockAccessor {
13-
@Invoker
14-
static void invokePreventDropFromBottomPart(Level level, BlockPos pos, BlockState state, Player player) {
15-
throw new AssertionError();
16-
}
13+
@Invoker
14+
static void invokePreventDropFromBottomPart(Level level, BlockPos pos, BlockState state, Player player) {
15+
throw new AssertionError();
16+
}
1717
}

src/main/java/corundum/rubinated_nether/mixin/accessors/EntityRenderDispatcherAccessor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ public interface EntityRenderDispatcherAccessor {
1616

1717
@Accessor("renderers")
1818
public void setRenderers(Map<EntityType<?>, EntityRenderer<?>> renderers);
19-
}
19+
}

src/main/java/corundum/rubinated_nether/mixin/accessors/GuiAccessor.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88

99
@Mixin(Gui.class)
1010
public interface GuiAccessor {
11-
@Invoker("renderTextureOverlay")
12-
void invokeRenderTextureOverlay(GuiGraphics guiGraphics, ResourceLocation shaderLocation, float alpha);
11+
@Invoker("renderTextureOverlay")
12+
void invokeRenderTextureOverlay(GuiGraphics guiGraphics, ResourceLocation shaderLocation, float alpha);
1313
}

src/main/java/corundum/rubinated_nether/mixin/accessors/LevelAccessor.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88

99
@Mixin(Level.class)
1010
public interface LevelAccessor {
11-
@Invoker("getEntities")
12-
LevelEntityGetter<Entity> invokeGetEntities();
11+
@Invoker("getEntities")
12+
LevelEntityGetter<Entity> invokeGetEntities();
1313
}

0 commit comments

Comments
 (0)