Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fake level for JEI #10304

Open
wants to merge 6 commits into
base: version/main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ mappingsVersion=1.20.1

dataGeneratorsVersion=1.19.3-0.1.54-ALPHA
blockUI_version=1.20.1-1.0.139-BETA
structurize_version=1.20.1-1.0.740-BETA
structurize_version=1.20.1-1.0.759-snapshot
domumOrnamentumVersion=1.20.1-1.0.184-BETA
multiPistonVersion=1.20-1.2.30-ALPHA

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.minecolonies.core.compatibility.jei;

import com.ldtteam.structurize.client.fakelevel.SingleBlockFakeLevel;
import net.minecraft.client.Minecraft;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why onlyin? dont think we should use that in 1.21

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paranoia, mostly. Since it's using client-only classes it must not be loaded in the server jar. Though that should be the case even without this, it seems safer to make it explicit.

public class JeiFakeLevel extends SingleBlockFakeLevel
{
public JeiFakeLevel()
{
super(null);
prepare(Blocks.AIR.defaultBlockState(), null, null);
}

@Override
public Level realLevel()
{
return Minecraft.getInstance().level;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
*/
public abstract class JobBasedRecipeCategory<T> implements IRecipeCategory<T>
{
protected static final JeiFakeLevel FAKE_LEVEL = new JeiFakeLevel();
protected static final ResourceLocation TEXTURE = new ResourceLocation(Constants.MOD_ID, "textures/gui/jei_recipe.png");
@NotNull protected final IJob<?> job;
@NotNull private final RecipeType<T> type;
Expand Down Expand Up @@ -300,7 +301,7 @@ public InfoBlock(final String text, final String tip, final Rect2i bounds)
@NotNull
private static EntityCitizen createCitizenWithJob(@NotNull final IJob<?> job)
{
final EntityCitizen citizen = new EntityCitizen(ModEntities.CITIZEN, Minecraft.getInstance().level);
final EntityCitizen citizen = new EntityCitizen(ModEntities.CITIZEN, FAKE_LEVEL);
citizen.setFemale(citizen.getRandom().nextBoolean());
citizen.setTextureId(citizen.getRandom().nextInt(255));
citizen.getEntityData().set(EntityCitizen.DATA_TEXTURE_SUFFIX, CitizenData.SUFFIXES.get(citizen.getRandom().nextInt(CitizenData.SUFFIXES.size())));
Expand Down