mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 19:15:32 +00:00
Forge 1.19.4
Properly move `ServerStatusPing` to codec Reimplement custom display contexts Co-authored-by: Matyrobbrt <[email protected]> Co-authored-by: coehlrich <[email protected]> Signed-off-by: SizableShrimp <[email protected]>
This commit is contained in:
1 parent
1f44339d6e
commit
44c689f171
347 files changed
+2545
-2436
No files matched your search
@@ -94,6 +94,7 @@ import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.flag.FeatureFlagSet;
|
||||
import net.minecraft.world.inventory.tooltip.TooltipComponent;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.ItemStackLinkedSet;
|
||||
import net.minecraft.world.item.crafting.RecipeManager;
|
||||
@@ -154,6 +155,7 @@ import net.minecraftforge.fml.VersionChecker;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.network.NetworkConstants;
|
||||
import net.minecraftforge.network.NetworkRegistry;
|
||||
import net.minecraftforge.network.ServerStatusPing;
|
||||
import net.minecraftforge.registries.GameData;
|
||||
import net.minecraftforge.versions.forge.ForgeVersion;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
@@ -484,7 +486,7 @@ public class ForgeHooksClient
|
||||
ModLoader.get().postEvent(new ModelEvent.BakingCompleted(modelManager, Collections.unmodifiableMap(models), modelBakery));
|
||||
}
|
||||
|
||||
public static BakedModel handleCameraTransforms(PoseStack poseStack, BakedModel model, ItemTransforms.TransformType cameraTransformType, boolean applyLeftHandTransform)
|
||||
public static BakedModel handleCameraTransforms(PoseStack poseStack, BakedModel model, ItemDisplayContext cameraTransformType, boolean applyLeftHandTransform)
|
||||
{
|
||||
model = model.applyTransform(cameraTransformType, poseStack, applyLeftHandTransform);
|
||||
return model;
|
||||
@@ -818,10 +820,11 @@ public class ForgeHooksClient
|
||||
|
||||
public static void processForgeListPingData(ServerStatus packet, ServerData target)
|
||||
{
|
||||
if (packet.getForgeData() != null) {
|
||||
final Map<String, String> mods = packet.getForgeData().getRemoteModData();
|
||||
final Map<ResourceLocation, Pair<String, Boolean>> remoteChannels = packet.getForgeData().getRemoteChannels();
|
||||
final int fmlver = packet.getForgeData().getFMLNetworkVersion();
|
||||
packet.forgeData().ifPresentOrElse(forgeData ->
|
||||
{
|
||||
final Map<String, String> mods = forgeData.getRemoteModData();
|
||||
final Map<ResourceLocation, ServerStatusPing.ChannelData> remoteChannels = forgeData.getRemoteChannels();
|
||||
final int fmlver = forgeData.getFMLNetworkVersion();
|
||||
|
||||
boolean fmlNetMatches = fmlver == NetworkConstants.FMLNETVERSION;
|
||||
boolean channelsMatch = NetworkRegistry.checkListPingCompatibilityForClient(remoteChannels);
|
||||
@@ -867,11 +870,8 @@ public class ForgeHooksClient
|
||||
if (fmlver > NetworkConstants.FMLNETVERSION) {
|
||||
extraReason = "fml.menu.multiplayer.clientoutdated";
|
||||
}
|
||||
target.forgeData = new ExtendedServerListData("FML", extraServerMods.isEmpty() && fmlNetMatches && channelsMatch && modsMatch, mods.size(), extraReason, packet.getForgeData().isTruncated());
|
||||
} else {
|
||||
target.forgeData = new ExtendedServerListData("VANILLA", NetworkRegistry.canConnectToVanillaServer(),0, null);
|
||||
}
|
||||
|
||||
target.forgeData = new ExtendedServerListData("FML", extraServerMods.isEmpty() && fmlNetMatches && channelsMatch && modsMatch, mods.size(), extraReason, forgeData.isTruncated());
|
||||
}, () -> target.forgeData = new ExtendedServerListData("VANILLA", NetworkRegistry.canConnectToVanillaServer(),0, null));
|
||||
}
|
||||
|
||||
private static final ResourceLocation ICON_SHEET = new ResourceLocation(ForgeVersion.MOD_ID, "textures/gui/icons.png");
|
||||
@@ -1202,7 +1202,7 @@ public class ForgeHooksClient
|
||||
return new ResourceLocation(loc.getNamespace(), normalised);
|
||||
}
|
||||
|
||||
public static void onCreativeModeTabBuildContents(CreativeModeTab tab, CreativeModeTab.DisplayItemsGenerator originalGenerator, FeatureFlagSet flags, CreativeModeTab.Output output, boolean hasPermisions)
|
||||
public static void onCreativeModeTabBuildContents(CreativeModeTab tab, CreativeModeTab.DisplayItemsGenerator originalGenerator, CreativeModeTab.ItemDisplayParameters params, CreativeModeTab.Output output)
|
||||
{
|
||||
final var entries = new MutableHashedLinkedMap<ItemStack, CreativeModeTab.TabVisibility>(ItemStackLinkedSet.TYPE_AND_TAG,
|
||||
(key, left, right) -> {
|
||||
@@ -1213,13 +1213,13 @@ public class ForgeHooksClient
|
||||
}
|
||||
);
|
||||
|
||||
originalGenerator.accept(flags, (stack, vis) -> {
|
||||
originalGenerator.accept(params, (stack, vis) -> {
|
||||
if (stack.getCount() != 1)
|
||||
throw new IllegalArgumentException("The stack count must be 1");
|
||||
entries.put(stack, vis);
|
||||
}, hasPermisions);
|
||||
});
|
||||
|
||||
ModLoader.get().postEvent(new CreativeModeTabEvent.BuildContents(tab, flags, hasPermisions, entries));
|
||||
ModLoader.get().postEvent(new CreativeModeTabEvent.BuildContents(tab, params, entries));
|
||||
|
||||
for (var entry : entries)
|
||||
output.accept(entry.getKey(), entry.getValue());
|
||||
|
||||
@@ -371,7 +371,6 @@ public enum ForgeRenderTypes
|
||||
this.setupState = () -> {
|
||||
this.blur = blur.get();
|
||||
this.mipmap = mipmap.get();
|
||||
RenderSystem.enableTexture();
|
||||
TextureManager texturemanager = Minecraft.getInstance().getTextureManager();
|
||||
texturemanager.getTexture(resLoc).setFilter(this.blur, this.mipmap);
|
||||
RenderSystem.setShaderTexture(0, resLoc);
|
||||
|
||||
@@ -65,7 +65,6 @@ public final class ItemDecoratorHandler
|
||||
|
||||
private void resetRenderState()
|
||||
{
|
||||
RenderSystem.enableTexture();
|
||||
RenderSystem.enableDepthTest();
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
|
||||
@@ -47,11 +47,18 @@ public class RegisterParticleProvidersEvent extends Event implements IModBusEven
|
||||
* or a redundant texture list error will occur when particle jsons load.
|
||||
* @param provider ParticleProvider responsible for providing that ParticleType's particles.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public <T extends ParticleOptions> void register(ParticleType<T> type, ParticleProvider<T> provider)
|
||||
{
|
||||
particleEngine.register(type, provider);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public <T extends ParticleOptions> void register(ParticleType<T> type, ParticleProvider.Sprite<T> sprite)
|
||||
{
|
||||
particleEngine.register(type, sprite);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a ParticleProvider for a json-based ParticleType.
|
||||
* Particle jsons define a list of texture sprites which the particle can use to render itself.
|
||||
@@ -61,6 +68,7 @@ public class RegisterParticleProvidersEvent extends Event implements IModBusEven
|
||||
* or a missing texture list error will occur when particle jsons load.
|
||||
* @param registration SpriteParticleRegistration responsible for providing that ParticleType's particles.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public <T extends ParticleOptions> void register(ParticleType<T> type, ParticleEngine.SpriteParticleRegistration<T> registration)
|
||||
{
|
||||
particleEngine.register(type, registration);
|
||||
|
||||
@@ -15,6 +15,7 @@ import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.BlockAndTintGetter;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
@@ -59,7 +60,7 @@ public interface IForgeBakedModel
|
||||
* Applies a transform for the given {@link ItemTransforms.TransformType} and {@code applyLeftHandTransform}, and
|
||||
* returns the model to be rendered.
|
||||
*/
|
||||
default BakedModel applyTransform(ItemTransforms.TransformType transformType, PoseStack poseStack, boolean applyLeftHandTransform)
|
||||
default BakedModel applyTransform(ItemDisplayContext transformType, PoseStack poseStack, boolean applyLeftHandTransform)
|
||||
{
|
||||
self().getTransforms().getTransform(transformType).apply(applyLeftHandTransform, poseStack);
|
||||
return self();
|
||||
|
||||
@@ -45,6 +45,6 @@ public interface IForgeMinecraft
|
||||
*/
|
||||
default Locale getLocale()
|
||||
{
|
||||
return self().getLanguageManager().getSelected().getJavaLocale();
|
||||
return self().getLanguageManager().getJavaLocale();
|
||||
}
|
||||
}
|
||||
@@ -283,7 +283,7 @@ public class ModListScreen extends Screen
|
||||
this.addRenderableWidget(configButton);
|
||||
this.addRenderableWidget(openModsFolderButton);
|
||||
|
||||
search.setFocus(false);
|
||||
search.setFocused(false);
|
||||
search.setCanLoseFocus(true);
|
||||
configButton.active = false;
|
||||
|
||||
|
||||
@@ -212,7 +212,6 @@ public class ScreenUtils
|
||||
float endBlue = (float)(endColor & 255) / 255.0F;
|
||||
|
||||
RenderSystem.enableDepthTest();
|
||||
RenderSystem.disableTexture();
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.setShader(GameRenderer::getPositionColorShader);
|
||||
@@ -227,7 +226,6 @@ public class ScreenUtils
|
||||
tessellator.end();
|
||||
|
||||
RenderSystem.disableBlend();
|
||||
RenderSystem.enableTexture();
|
||||
}
|
||||
|
||||
public static void blitInscribed(PoseStack poseStack, int x, int y, int boundsWidth, int boundsHeight, int rectWidth, int rectHeight)
|
||||
|
||||
@@ -105,13 +105,8 @@ public class ForgeGui extends Gui
|
||||
|
||||
if (texture != null)
|
||||
{
|
||||
RenderSystem.enableTexture();
|
||||
bind(texture);
|
||||
}
|
||||
else
|
||||
{
|
||||
RenderSystem.disableTexture();
|
||||
}
|
||||
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
@@ -172,7 +167,7 @@ public class ForgeGui extends Gui
|
||||
minecraft.getProfiler().pop();
|
||||
}
|
||||
|
||||
void renderSpyglassOverlay()
|
||||
void renderSpyglassOverlay(PoseStack stack)
|
||||
{
|
||||
float deltaFrame = this.minecraft.getDeltaFrameTime();
|
||||
this.scopeScale = Mth.lerp(0.5F * deltaFrame, this.scopeScale, 1.125F);
|
||||
@@ -180,7 +175,7 @@ public class ForgeGui extends Gui
|
||||
{
|
||||
if (this.minecraft.player.isScoping())
|
||||
{
|
||||
this.renderSpyglassOverlay(this.scopeScale);
|
||||
this.renderSpyglassOverlay(stack, this.scopeScale);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -198,7 +193,7 @@ public class ForgeGui extends Gui
|
||||
Item item = itemstack.getItem();
|
||||
if (item == Blocks.CARVED_PUMPKIN.asItem())
|
||||
{
|
||||
renderTextureOverlay(PUMPKIN_BLUR_LOCATION, 1.0F);
|
||||
renderTextureOverlay(poseStack, PUMPKIN_BLUR_LOCATION, 1.0F);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -211,7 +206,7 @@ public class ForgeGui extends Gui
|
||||
{
|
||||
if (this.minecraft.player.getTicksFrozen() > 0)
|
||||
{
|
||||
this.renderTextureOverlay(POWDER_SNOW_OUTLINE_LOCATION, this.minecraft.player.getPercentFrozen());
|
||||
this.renderTextureOverlay(pStack, POWDER_SNOW_OUTLINE_LOCATION, this.minecraft.player.getPercentFrozen());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,13 +242,13 @@ public class ForgeGui extends Gui
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderPortalOverlay(float partialTick)
|
||||
protected void renderPortalOverlay(PoseStack stack, float partialTick)
|
||||
{
|
||||
float f1 = Mth.lerp(partialTick, this.minecraft.player.oPortalTime, this.minecraft.player.portalTime);
|
||||
|
||||
if (f1 > 0.0F)
|
||||
{
|
||||
super.renderPortalOverlay(f1);
|
||||
super.renderPortalOverlay(stack, f1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,12 +27,12 @@ public enum VanillaGuiOverlay
|
||||
if (Minecraft.useFancyGraphics())
|
||||
{
|
||||
gui.setupOverlayRenderState(true, false);
|
||||
gui.renderVignette(gui.getMinecraft().getCameraEntity());
|
||||
gui.renderVignette(poseStack, gui.getMinecraft().getCameraEntity());
|
||||
}
|
||||
}),
|
||||
SPYGLASS("spyglass", (gui, poseStack, partialTick, screenWidth, screenHeight) -> {
|
||||
gui.setupOverlayRenderState(true, false);
|
||||
gui.renderSpyglassOverlay();
|
||||
gui.renderSpyglassOverlay(poseStack);
|
||||
}),
|
||||
HELMET("helmet", (gui, poseStack, partialTick, screenWidth, screenHeight) -> {
|
||||
gui.setupOverlayRenderState(true, false);
|
||||
@@ -47,7 +47,7 @@ public enum VanillaGuiOverlay
|
||||
if (!gui.getMinecraft().player.hasEffect(MobEffects.CONFUSION))
|
||||
{
|
||||
gui.setupOverlayRenderState(true, false);
|
||||
gui.renderPortalOverlay(partialTick);
|
||||
gui.renderPortalOverlay(poseStack, partialTick);
|
||||
}
|
||||
|
||||
}),
|
||||
@@ -69,18 +69,22 @@ public enum VanillaGuiOverlay
|
||||
if (!gui.getMinecraft().options.hideGui)
|
||||
{
|
||||
gui.setupOverlayRenderState(true, false);
|
||||
gui.setBlitOffset(-90);
|
||||
|
||||
poseStack.pushPose();
|
||||
poseStack.translate(0, 0, -90);
|
||||
gui.renderCrosshair(poseStack);
|
||||
poseStack.popPose();
|
||||
}
|
||||
}),
|
||||
BOSS_EVENT_PROGRESS("boss_event_progress", (gui, poseStack, partialTick, screenWidth, screenHeight) -> {
|
||||
if (!gui.getMinecraft().options.hideGui)
|
||||
{
|
||||
gui.setupOverlayRenderState(true, false);
|
||||
gui.setBlitOffset(-90);
|
||||
|
||||
poseStack.pushPose();
|
||||
poseStack.translate(0, 0, -90);
|
||||
gui.renderBossHealth(poseStack);
|
||||
poseStack.popPose();
|
||||
}
|
||||
}),
|
||||
PLAYER_HEALTH("player_health", (gui, poseStack, partialTick, screenWidth, screenHeight) -> {
|
||||
@@ -138,7 +142,7 @@ public enum VanillaGuiOverlay
|
||||
if (!gui.getMinecraft().options.hideGui)
|
||||
{
|
||||
gui.setupOverlayRenderState(true, false);
|
||||
if (gui.getMinecraft().options.heldItemTooltips && gui.getMinecraft().gameMode.getPlayerMode() != GameType.SPECTATOR)
|
||||
if (gui.getMinecraft().gameMode.getPlayerMode() != GameType.SPECTATOR)
|
||||
{
|
||||
gui.renderSelectedItemName(poseStack);
|
||||
}
|
||||
|
||||
@@ -44,12 +44,11 @@ public class ExtendedButton extends Button
|
||||
* Draws this button to the screen.
|
||||
*/
|
||||
@Override
|
||||
public void renderButton(PoseStack poseStack, int mouseX, int mouseY, float partialTick)
|
||||
public void renderWidget(PoseStack poseStack, int mouseX, int mouseY, float partialTick)
|
||||
{
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
int k = this.getYImage(this.isHoveredOrFocused());
|
||||
ScreenUtils.blitWithBorder(poseStack, WIDGETS_LOCATION, this.getX(), this.getY(), 0, 46 + k * 20, this.width, this.height, 200, 20, 2, 3, 2, 2, this.getBlitOffset());
|
||||
this.renderBg(poseStack, mc, mouseX, mouseY);
|
||||
int k = !this.active ? 0 : (this.isHoveredOrFocused() ? 2 : 1);
|
||||
ScreenUtils.blitWithBorder(poseStack, WIDGETS_LOCATION, this.getX(), this.getY(), 0, 46 + k * 20, this.width, this.height, 200, 20, 2, 3, 2, 2, 0);
|
||||
|
||||
final FormattedText buttonText = mc.font.ellipsize(this.getMessage(), this.width - 6); // Remove 6 pixels so that the text is always contained within the button's borders
|
||||
drawCenteredString(poseStack, mc.font, Language.getInstance().getVisualOrder(buttonText), this.getX() + this.width / 2, this.getY() + (this.height - 8) / 2, getFGColor());
|
||||
|
||||
@@ -226,17 +226,17 @@ public class ForgeSlider extends AbstractSliderButton
|
||||
protected void applyValue() {}
|
||||
|
||||
@Override
|
||||
public void renderButton(@NotNull PoseStack poseStack, int mouseX, int mouseY, float partialTick)
|
||||
public void renderWidget(@NotNull PoseStack poseStack, int mouseX, int mouseY, float partialTick)
|
||||
{
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.setShaderTexture(0, WIDGETS_LOCATION);
|
||||
|
||||
final Minecraft mc = Minecraft.getInstance();
|
||||
final int bgYImage = this.getYImage(this.isHoveredOrFocused());
|
||||
ScreenUtils.blitWithBorder(poseStack, this.getX(), this.getY(), 0, 46 + bgYImage * 20, this.width, this.height, 200, 20, 2, 3, 2, 2, this.getBlitOffset());
|
||||
final int bgYImage = !this.active ? 0 : (this.isHoveredOrFocused() ? 2 : 1);
|
||||
ScreenUtils.blitWithBorder(poseStack, this.getX(), this.getY(), 0, 46 + bgYImage * 20, this.width, this.height, 200, 20, 2, 3, 2, 2, 0);
|
||||
|
||||
final int sliderYImage = (this.isHoveredOrFocused() ? 2 : 1) * 20;
|
||||
ScreenUtils.blitWithBorder(poseStack, this.getX() + (int)(this.value * (double)(this.width - 8)), this.getY(), 0, 46 + sliderYImage, 8, this.height, 200, 20 , 2, 3, 2, 2, this.getBlitOffset());
|
||||
ScreenUtils.blitWithBorder(poseStack, this.getX() + (int)(this.value * (double)(this.width - 8)), this.getY(), 0, 46 + sliderYImage, 8, this.height, 200, 20 , 2, 3, 2, 2, 0);
|
||||
|
||||
final FormattedText message = mc.font.ellipsize(getMessage(), this.width - 6);
|
||||
drawCenteredString(poseStack, mc.font, Language.getInstance().getVisualOrder(message), this.getX() + this.width / 2, this.getY() + (this.height - 8) / 2, getFGColor());
|
||||
|
||||
@@ -328,7 +328,6 @@ public abstract class ScrollPanel extends AbstractContainerEventHandler implemen
|
||||
int barBgBlue = this.barBgColor & 0xff;
|
||||
|
||||
RenderSystem.setShader(GameRenderer::getPositionColorShader);
|
||||
RenderSystem.disableTexture();
|
||||
worldr.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR);
|
||||
worldr.vertex(barLeft, this.bottom, 0.0D).color(barBgRed, barBgGreen, barBgBlue, barBgAlpha).endVertex();
|
||||
worldr.vertex(barLeft + barWidth, this.bottom, 0.0D).color(barBgRed, barBgGreen, barBgBlue, barBgAlpha).endVertex();
|
||||
@@ -361,7 +360,6 @@ public abstract class ScrollPanel extends AbstractContainerEventHandler implemen
|
||||
tess.end();
|
||||
}
|
||||
|
||||
RenderSystem.enableTexture();
|
||||
RenderSystem.disableBlend();
|
||||
RenderSystem.disableScissor();
|
||||
}
|
||||
|
||||
@@ -35,9 +35,8 @@ public class UnicodeGlyphButton extends ExtendedButton
|
||||
{
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
this.isHovered = mouseX >= this.getX() && mouseY >= this.getY() && mouseX < this.getX() + this.width && mouseY < this.getY() + this.height;
|
||||
int k = this.getYImage(this.isHoveredOrFocused());
|
||||
ScreenUtils.blitWithBorder(poseStack, WIDGETS_LOCATION, this.getX(), this.getY(), 0, 46 + k * 20, this.width, this.height, 200, 20, 2, 3, 2, 2, this.getBlitOffset());
|
||||
this.renderBg(poseStack, mc, mouseX, mouseY);
|
||||
int k = !this.active ? 0 : (this.isHoveredOrFocused() ? 2 : 1);
|
||||
ScreenUtils.blitWithBorder(poseStack, WIDGETS_LOCATION, this.getX(), this.getY(), 0, 46 + k * 20, this.width, this.height, 200, 20, 2, 3, 2, 2, 0);
|
||||
|
||||
Component buttonText = this.createNarrationMessage();
|
||||
int glyphWidth = (int) (mc.font.width(glyph) * glyphScale);
|
||||
|
||||
@@ -140,8 +140,6 @@ public class ClientModLoader
|
||||
|
||||
public static boolean completeModLoading()
|
||||
{
|
||||
RenderSystem.disableTexture();
|
||||
RenderSystem.enableTexture();
|
||||
List<ModLoadingWarning> warnings = ModLoader.get().getWarnings();
|
||||
boolean showWarnings = true;
|
||||
try {
|
||||
@@ -209,7 +207,7 @@ public class ClientModLoader
|
||||
// Create a resource pack merging all mod resources that should be hidden
|
||||
final Pack modResourcesPack = Pack.readMetaAndCreate("mod_resources", Component.literal("Mod Resources"), true,
|
||||
id -> new DelegatingPackResources(id, false, new PackMetadataSection(Component.translatable("fml.resources.modresources", hiddenPacks.size()),
|
||||
PackType.CLIENT_RESOURCES.getVersion(SharedConstants.getCurrentVersion())), hiddenPacks),
|
||||
SharedConstants.getCurrentVersion().getPackVersion(PackType.CLIENT_RESOURCES)), hiddenPacks),
|
||||
PackType.CLIENT_RESOURCES, Pack.Position.BOTTOM, PackSource.DEFAULT);
|
||||
packAcceptor.accept(modResourcesPack);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.BlockAndTintGetter;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
@@ -100,7 +101,7 @@ public abstract class BakedModelWrapper<T extends BakedModel> implements BakedMo
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel applyTransform(ItemTransforms.TransformType cameraTransformType, PoseStack poseStack, boolean applyLeftHandTransform)
|
||||
public BakedModel applyTransform(ItemDisplayContext cameraTransformType, PoseStack poseStack, boolean applyLeftHandTransform)
|
||||
{
|
||||
return originalModel.applyTransform(cameraTransformType, poseStack, applyLeftHandTransform);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import net.minecraft.core.Direction;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.client.ChunkRenderTypeSet;
|
||||
import net.minecraftforge.client.model.data.ModelData;
|
||||
@@ -41,22 +42,22 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* A model composed of multiple sub-models which are picked based on the {@link ItemTransforms.TransformType} being used.
|
||||
* A model composed of multiple sub-models which are picked based on the {@link ItemDisplayContext} being used.
|
||||
*/
|
||||
public class SeparateTransformsModel implements IUnbakedGeometry<SeparateTransformsModel>
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
private final BlockModel baseModel;
|
||||
private final ImmutableMap<ItemTransforms.TransformType, BlockModel> perspectives;
|
||||
private final ImmutableMap<ItemDisplayContext, BlockModel> perspectives;
|
||||
private final boolean deprecatedLoader;
|
||||
|
||||
public SeparateTransformsModel(BlockModel baseModel, ImmutableMap<ItemTransforms.TransformType, BlockModel> perspectives)
|
||||
public SeparateTransformsModel(BlockModel baseModel, ImmutableMap<ItemDisplayContext, BlockModel> perspectives)
|
||||
{
|
||||
this(baseModel, perspectives, false);
|
||||
}
|
||||
|
||||
private SeparateTransformsModel(BlockModel baseModel, ImmutableMap<ItemTransforms.TransformType, BlockModel> perspectives, boolean deprecatedLoader)
|
||||
private SeparateTransformsModel(BlockModel baseModel, ImmutableMap<ItemDisplayContext, BlockModel> perspectives, boolean deprecatedLoader)
|
||||
{
|
||||
this.baseModel = baseModel;
|
||||
this.perspectives = perspectives;
|
||||
@@ -94,9 +95,9 @@ public class SeparateTransformsModel implements IUnbakedGeometry<SeparateTransfo
|
||||
private final TextureAtlasSprite particle;
|
||||
private final ItemOverrides overrides;
|
||||
private final BakedModel baseModel;
|
||||
private final ImmutableMap<ItemTransforms.TransformType, BakedModel> perspectives;
|
||||
private final ImmutableMap<ItemDisplayContext, BakedModel> perspectives;
|
||||
|
||||
public Baked(boolean isAmbientOcclusion, boolean isGui3d, boolean isSideLit, TextureAtlasSprite particle, ItemOverrides overrides, BakedModel baseModel, ImmutableMap<ItemTransforms.TransformType, BakedModel> perspectives)
|
||||
public Baked(boolean isAmbientOcclusion, boolean isGui3d, boolean isSideLit, TextureAtlasSprite particle, ItemOverrides overrides, BakedModel baseModel, ImmutableMap<ItemDisplayContext, BakedModel> perspectives)
|
||||
{
|
||||
this.isAmbientOcclusion = isAmbientOcclusion;
|
||||
this.isGui3d = isGui3d;
|
||||
@@ -157,7 +158,7 @@ public class SeparateTransformsModel implements IUnbakedGeometry<SeparateTransfo
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel applyTransform(ItemTransforms.TransformType cameraTransformType, PoseStack poseStack, boolean applyLeftHandTransform)
|
||||
public BakedModel applyTransform(ItemDisplayContext cameraTransformType, PoseStack poseStack, boolean applyLeftHandTransform)
|
||||
{
|
||||
if (perspectives.containsKey(cameraTransformType))
|
||||
{
|
||||
@@ -194,12 +195,12 @@ public class SeparateTransformsModel implements IUnbakedGeometry<SeparateTransfo
|
||||
|
||||
JsonObject perspectiveData = GsonHelper.getAsJsonObject(jsonObject, "perspectives");
|
||||
|
||||
Map<ItemTransforms.TransformType, BlockModel> perspectives = new HashMap<>();
|
||||
for (ItemTransforms.TransformType transform : ItemTransforms.TransformType.values())
|
||||
Map<ItemDisplayContext, BlockModel> perspectives = new HashMap<>();
|
||||
for (ItemDisplayContext transform : ItemDisplayContext.values())
|
||||
{
|
||||
if (perspectiveData.has(transform.getSerializeName()))
|
||||
if (perspectiveData.has(transform.getSerializedName()))
|
||||
{
|
||||
BlockModel perspectiveModel = deserializationContext.deserialize(GsonHelper.getAsJsonObject(perspectiveData, transform.getSerializeName()), BlockModel.class);
|
||||
BlockModel perspectiveModel = deserializationContext.deserialize(GsonHelper.getAsJsonObject(perspectiveData, transform.getSerializedName()), BlockModel.class);
|
||||
perspectives.put(transform, perspectiveModel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,12 +27,12 @@ import net.minecraft.client.renderer.block.model.BlockModel.GuiLight;
|
||||
import net.minecraft.client.renderer.block.model.BlockElement;
|
||||
import net.minecraft.client.renderer.block.model.BlockElementFace;
|
||||
import net.minecraft.client.renderer.block.model.BlockElementRotation;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms.TransformType;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransform;
|
||||
import net.minecraft.client.renderer.texture.MissingTextureAtlasSprite;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraftforge.client.model.ForgeFaceData;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -245,10 +245,10 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
root.addProperty("render_type", this.renderType);
|
||||
}
|
||||
|
||||
Map<TransformType, ItemTransform> transforms = this.transforms.build();
|
||||
Map<ItemDisplayContext, ItemTransform> transforms = this.transforms.build();
|
||||
if (!transforms.isEmpty()) {
|
||||
JsonObject display = new JsonObject();
|
||||
for (Entry<TransformType, ItemTransform> e : transforms.entrySet()) {
|
||||
for (Entry<ItemDisplayContext, ItemTransform> e : transforms.entrySet()) {
|
||||
JsonObject transform = new JsonObject();
|
||||
ItemTransform vec = e.getValue();
|
||||
if (vec.equals(ItemTransform.NO_TRANSFORM)) continue;
|
||||
@@ -265,7 +265,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
if (hasRightRotation) {
|
||||
transform.add("right_rotation", serializeVector3f(vec.rightRotation));
|
||||
}
|
||||
display.add(e.getKey().getSerializeName(), transform);
|
||||
display.add(e.getKey().getSerializedName(), transform);
|
||||
}
|
||||
root.add("display", display);
|
||||
}
|
||||
@@ -716,7 +716,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
|
||||
public class TransformsBuilder {
|
||||
|
||||
private final Map<TransformType, TransformVecBuilder> transforms = new LinkedHashMap<>();
|
||||
private final Map<ItemDisplayContext, TransformVecBuilder> transforms = new LinkedHashMap<>();
|
||||
|
||||
/**
|
||||
* Begin building a new transform for the given perspective.
|
||||
@@ -725,12 +725,12 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
* @return the builder for the given perspective
|
||||
* @throws NullPointerException if {@code type} is {@code null}
|
||||
*/
|
||||
public TransformVecBuilder transform(TransformType type) {
|
||||
public TransformVecBuilder transform(ItemDisplayContext type) {
|
||||
Preconditions.checkNotNull(type, "Perspective cannot be null");
|
||||
return transforms.computeIfAbsent(type, TransformVecBuilder::new);
|
||||
}
|
||||
|
||||
Map<TransformType, ItemTransform> build() {
|
||||
Map<ItemDisplayContext, ItemTransform> build() {
|
||||
return this.transforms.entrySet().stream()
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().build(), (k1, k2) -> { throw new IllegalArgumentException(); }, LinkedHashMap::new));
|
||||
}
|
||||
@@ -744,7 +744,7 @@ public class ModelBuilder<T extends ModelBuilder<T>> extends ModelFile {
|
||||
private Vector3f scale = new Vector3f(ItemTransform.Deserializer.DEFAULT_SCALE);
|
||||
private Vector3f rightRotation = new Vector3f(ItemTransform.Deserializer.DEFAULT_ROTATION);
|
||||
|
||||
TransformVecBuilder(TransformType type) {
|
||||
TransformVecBuilder(ItemDisplayContext type) {
|
||||
// param unused for functional match
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -9,6 +9,7 @@ import com.google.common.base.Preconditions;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraftforge.client.model.generators.CustomLoaderBuilder;
|
||||
import net.minecraftforge.client.model.generators.ModelBuilder;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
@@ -38,11 +39,11 @@ public class SeparateTransformsModelBuilder<T extends ModelBuilder<T>> extends C
|
||||
return this;
|
||||
}
|
||||
|
||||
public SeparateTransformsModelBuilder<T> perspective(ItemTransforms.TransformType perspective, T modelBuilder)
|
||||
public SeparateTransformsModelBuilder<T> perspective(ItemDisplayContext perspective, T modelBuilder)
|
||||
{
|
||||
Preconditions.checkNotNull(perspective, "layer must not be null");
|
||||
Preconditions.checkNotNull(modelBuilder, "modelBuilder must not be null");
|
||||
childModels.put(perspective.getSerializeName(), modelBuilder);
|
||||
childModels.put(perspective.getSerializedName(), modelBuilder);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -1549,7 +1549,7 @@ public class ForgeHooks
|
||||
|
||||
private static String makePackFormatKey(PackType packType)
|
||||
{
|
||||
return "forge:" + packType.bridgeType.name().toLowerCase(Locale.ROOT) + "_pack_format";
|
||||
return "forge:" + packType.name().toLowerCase(Locale.ROOT) + "_pack_format";
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -483,7 +483,7 @@ public class ForgeMod
|
||||
ExistingFileHelper existingFileHelper = event.getExistingFileHelper();
|
||||
ForgeBlockTagsProvider blockTags = new ForgeBlockTagsProvider(packOutput, lookupProvider, existingFileHelper);
|
||||
gen.addProvider(event.includeServer(), blockTags);
|
||||
gen.addProvider(event.includeServer(), new ForgeItemTagsProvider(packOutput, lookupProvider, blockTags, existingFileHelper));
|
||||
gen.addProvider(event.includeServer(), new ForgeItemTagsProvider(packOutput, lookupProvider, blockTags.contentsGetter(), existingFileHelper));
|
||||
gen.addProvider(event.includeServer(), new ForgeEntityTypeTagsProvider(packOutput, lookupProvider, existingFileHelper));
|
||||
gen.addProvider(event.includeServer(), new ForgeFluidTagsProvider(packOutput, lookupProvider, existingFileHelper));
|
||||
gen.addProvider(event.includeServer(), new ForgeRecipeProvider(packOutput));
|
||||
|
||||
@@ -51,11 +51,11 @@ public interface IExtensibleEnum
|
||||
either -> either.map(
|
||||
str -> {
|
||||
var val = enumValueFromNameFunction.apply(str);
|
||||
return val != null ? DataResult.success(val) : DataResult.error("Unknown enum value name: " + str);
|
||||
return val != null ? DataResult.success(val) : DataResult.error(() -> "Unknown enum value name: " + str);
|
||||
},
|
||||
num -> {
|
||||
var values = valuesSupplier.get();
|
||||
return num >= 0 && num < values.length ? DataResult.success(values[num]) : DataResult.error("Unknown enum id: " + num);
|
||||
return num >= 0 && num < values.length ? DataResult.success(values[num]) : DataResult.error(() -> "Unknown enum id: " + num);
|
||||
}
|
||||
),
|
||||
value -> Either.left(value.getSerializedName())
|
||||
|
||||
@@ -351,7 +351,7 @@ public class TierSortingRegistry
|
||||
|
||||
private static void syncToPlayer(ServerPlayer serverPlayer)
|
||||
{
|
||||
if (SYNC_CHANNEL.isRemotePresent(serverPlayer.connection.getConnection()) && !serverPlayer.connection.getConnection().isMemoryConnection())
|
||||
if (SYNC_CHANNEL.isRemotePresent(serverPlayer.connection.connection) && !serverPlayer.connection.connection.isMemoryConnection())
|
||||
{
|
||||
SYNC_CHANNEL.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new SyncPacket(sortedTiers.stream().map(TierSortingRegistry::getName).toList()));
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.function.Consumer;
|
||||
|
||||
public final class ForgeItemTagsProvider extends ItemTagsProvider
|
||||
{
|
||||
public ForgeItemTagsProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> lookupProvider, TagsProvider<Block> blockTagProvider, ExistingFileHelper existingFileHelper)
|
||||
public ForgeItemTagsProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> lookupProvider, CompletableFuture<TagLookup<Block>> blockTagProvider, ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
super(output, lookupProvider, blockTagProvider, "forge", existingFileHelper);
|
||||
}
|
||||
|
||||
@@ -543,8 +543,7 @@ public interface IForgeBlock
|
||||
@Nullable
|
||||
default BlockPathTypes getAdjacentBlockPathType(BlockState state, BlockGetter level, BlockPos pos, @Nullable Mob mob, BlockPathTypes originalType)
|
||||
{
|
||||
if (state.is(Blocks.CACTUS)) return BlockPathTypes.DANGER_CACTUS;
|
||||
else if (state.is(Blocks.SWEET_BERRY_BUSH)) return BlockPathTypes.DANGER_OTHER;
|
||||
if (state.is(Blocks.SWEET_BERRY_BUSH)) return BlockPathTypes.DANGER_OTHER;
|
||||
else if (WalkNodeEvaluator.isBurningBlock(state)) return BlockPathTypes.DANGER_FIRE;
|
||||
else return null;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.flag.FeatureFlags;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
@@ -15,7 +16,7 @@ public interface IForgeMenuType<T>
|
||||
{
|
||||
static <T extends AbstractContainerMenu> MenuType<T> create(IContainerFactory<T> factory)
|
||||
{
|
||||
return new MenuType<>(factory);
|
||||
return new MenuType<>(factory, FeatureFlags.DEFAULT_FLAGS);
|
||||
}
|
||||
|
||||
T create(int windowId, Inventory playerInv, FriendlyByteBuf extraData);
|
||||
|
||||
@@ -42,7 +42,7 @@ public interface IGlobalLootModifier {
|
||||
catch (JsonSyntaxException e)
|
||||
{
|
||||
LootModifierManager.LOGGER.warn("Unable to decode loot conditions", e);
|
||||
return DataResult.error(e.getMessage());
|
||||
return DataResult.error(e::getMessage);
|
||||
}
|
||||
},
|
||||
conditions ->
|
||||
@@ -55,7 +55,7 @@ public interface IGlobalLootModifier {
|
||||
catch (JsonSyntaxException e)
|
||||
{
|
||||
LootModifierManager.LOGGER.warn("Unable to encode loot conditions", e);
|
||||
return DataResult.error(e.getMessage());
|
||||
return DataResult.error(e::getMessage);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@@ -69,6 +69,7 @@ import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.stats.Stat;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.RelativeMovement;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -125,7 +126,6 @@ public class FakePlayer extends ServerPlayer
|
||||
@Override public void handleBlockEntityTagQuery(ServerboundBlockEntityTagQuery packet) { }
|
||||
@Override public void handleMovePlayer(ServerboundMovePlayerPacket packet) { }
|
||||
@Override public void teleport(double x, double y, double z, float yaw, float pitch) { }
|
||||
@Override public void teleport(double x, double y, double z, float yaw, float pitch, Set<ClientboundPlayerPositionPacket.RelativeArgument> flags) { }
|
||||
@Override public void handlePlayerAction(ServerboundPlayerActionPacket packet) { }
|
||||
@Override public void handleUseItemOn(ServerboundUseItemOnPacket packet) { }
|
||||
@Override public void handleUseItem(ServerboundUseItemPacket packet) { }
|
||||
@@ -153,8 +153,7 @@ public class FakePlayer extends ServerPlayer
|
||||
@Override public void handleCustomPayload(ServerboundCustomPayloadPacket packet) { }
|
||||
@Override public void handleChangeDifficulty(ServerboundChangeDifficultyPacket packet) { }
|
||||
@Override public void handleLockDifficulty(ServerboundLockDifficultyPacket packet) { }
|
||||
@Override public void dismount(double x, double y, double z, float yaw, float pitch) { }
|
||||
@Override public void teleport(double x, double y, double z, float yaw, float pitch, Set<ClientboundPlayerPositionPacket.RelativeArgument> relativeSet, boolean dismountVehicle) { }
|
||||
@Override public void teleport(double x, double y, double z, float yaw, float pitch, Set<RelativeMovement> relativeSet) { }
|
||||
@Override public void ackBlockChangesUpTo(int sequence) { }
|
||||
@Override public void handleChatCommand(ServerboundChatCommandPacket packet) { }
|
||||
@Override public void handleChatAck(ServerboundChatAckPacket packet) { }
|
||||
|
||||
@@ -14,7 +14,7 @@ import net.minecraft.world.level.biome.Biome.TemperatureModifier;
|
||||
*/
|
||||
public class ClimateSettingsBuilder
|
||||
{
|
||||
private Precipitation precipitation;
|
||||
private boolean hasPrecipitation;
|
||||
private float temperature;
|
||||
private TemperatureModifier temperatureModifier;
|
||||
private float downfall;
|
||||
@@ -25,11 +25,11 @@ public class ClimateSettingsBuilder
|
||||
*/
|
||||
public static ClimateSettingsBuilder copyOf(ClimateSettings settings)
|
||||
{
|
||||
return create(settings.precipitation(), settings.temperature(), settings.temperatureModifier(), settings.downfall());
|
||||
return create(settings.hasPrecipitation(), settings.temperature(), settings.temperatureModifier(), settings.downfall());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param precipitation Synced to clients, determines weather effects
|
||||
* @param hasPrecipitation Synced to clients, determines weather effects
|
||||
* @param temperature Synced to clients, affects foliage color, freezing, and weather effects.
|
||||
* Vanilla values are in the range [-0.5, 2.0]
|
||||
* @param temperatureModifier Synced to clients, applies a positional modifier to temperature.
|
||||
@@ -38,14 +38,14 @@ public class ClimateSettingsBuilder
|
||||
* Biomes with downfall > 0.85 count as humid, inhibiting fire spread.
|
||||
* @return a new builder with the given values
|
||||
*/
|
||||
public static ClimateSettingsBuilder create(Precipitation precipitation, float temperature, TemperatureModifier temperatureModifier, float downfall)
|
||||
public static ClimateSettingsBuilder create(boolean hasPrecipitation, float temperature, TemperatureModifier temperatureModifier, float downfall)
|
||||
{
|
||||
return new ClimateSettingsBuilder(precipitation, temperature, temperatureModifier, downfall);
|
||||
return new ClimateSettingsBuilder(hasPrecipitation, temperature, temperatureModifier, downfall);
|
||||
}
|
||||
|
||||
private ClimateSettingsBuilder(Precipitation precipitation, float temperature, TemperatureModifier temperatureModifier, float downfall)
|
||||
private ClimateSettingsBuilder(boolean hasPrecipitation, float temperature, TemperatureModifier temperatureModifier, float downfall)
|
||||
{
|
||||
this.precipitation = precipitation;
|
||||
this.hasPrecipitation = hasPrecipitation;
|
||||
this.temperature = temperature;
|
||||
this.temperatureModifier = temperatureModifier;
|
||||
this.downfall = downfall;
|
||||
@@ -56,23 +56,23 @@ public class ClimateSettingsBuilder
|
||||
*/
|
||||
public ClimateSettings build()
|
||||
{
|
||||
return new ClimateSettings(this.precipitation, this.temperature, this.temperatureModifier, this.downfall);
|
||||
return new ClimateSettings(true, this.temperature, this.temperatureModifier, this.downfall);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Synced to clients, determines weather effects.
|
||||
*/
|
||||
public Precipitation getPrecipitation()
|
||||
public boolean hasPrecipitation()
|
||||
{
|
||||
return precipitation;
|
||||
return hasPrecipitation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param precipitation Synced to clients, determines weather effects.
|
||||
* @param hasPrecipitation Synced to clients, determines weather effects.
|
||||
*/
|
||||
public void setPrecipitation(Precipitation precipitation)
|
||||
public void setHasPrecipitation(boolean hasPrecipitation)
|
||||
{
|
||||
this.precipitation = precipitation;
|
||||
this.hasPrecipitation = hasPrecipitation;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -112,16 +112,14 @@ public class CreativeModeTabEvent extends Event implements IModBusEvent
|
||||
public static final class BuildContents extends CreativeModeTabEvent implements Output
|
||||
{
|
||||
private final CreativeModeTab tab;
|
||||
private final FeatureFlagSet flags;
|
||||
private final boolean hasPermissions;
|
||||
private final CreativeModeTab.ItemDisplayParameters parameters;
|
||||
private final MutableHashedLinkedMap<ItemStack, TabVisibility> entries;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public BuildContents(CreativeModeTab tab, FeatureFlagSet flags, boolean hasPermissions, MutableHashedLinkedMap<ItemStack, TabVisibility> entries)
|
||||
public BuildContents(CreativeModeTab tab, CreativeModeTab.ItemDisplayParameters parameters, MutableHashedLinkedMap<ItemStack, TabVisibility> entries)
|
||||
{
|
||||
this.tab = tab;
|
||||
this.flags = flags;
|
||||
this.hasPermissions = hasPermissions;
|
||||
this.parameters = parameters;
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
@@ -135,12 +133,17 @@ public class CreativeModeTabEvent extends Event implements IModBusEvent
|
||||
|
||||
public FeatureFlagSet getFlags()
|
||||
{
|
||||
return this.flags;
|
||||
return this.parameters.enabledFeatures();
|
||||
}
|
||||
|
||||
public CreativeModeTab.ItemDisplayParameters getParameters()
|
||||
{
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public boolean hasPermissions()
|
||||
{
|
||||
return this.hasPermissions;
|
||||
return this.parameters.hasPermissions();
|
||||
}
|
||||
|
||||
public MutableHashedLinkedMap<ItemStack, TabVisibility> getEntries()
|
||||
|
||||
@@ -365,7 +365,7 @@ public class FluidType
|
||||
*/
|
||||
public boolean canRideVehicleUnder(Entity vehicle, Entity rider)
|
||||
{
|
||||
if (this == ForgeMod.WATER_TYPE.get()) return vehicle.rideableUnderWater();
|
||||
if (this == ForgeMod.WATER_TYPE.get()) return !vehicle.dismountsUnderwater();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ public class BlockPosValueConverter implements ValueConverter<BlockPos>
|
||||
public BlockPos convert(String value)
|
||||
{
|
||||
String[] split = value.split(",");
|
||||
return new BlockPos(Double.parseDouble(split[0]), Double.parseDouble(split[1]), Double.parseDouble(split[2]));
|
||||
return BlockPos.containing(Double.parseDouble(split[0]), Double.parseDouble(split[1]), Double.parseDouble(split[2]));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -49,7 +49,7 @@ public class SlotItemHandler extends Slot
|
||||
}
|
||||
|
||||
// Override if your IItemHandler does not implement IItemHandlerModifiable
|
||||
@Override
|
||||
// @Override
|
||||
public void initialize(ItemStack stack)
|
||||
{
|
||||
((IItemHandlerModifiable) this.getItemHandler()).setStackInSlot(index, stack);
|
||||
|
||||
@@ -107,7 +107,7 @@ public class ConnectionData
|
||||
public static ModMismatchData registry(Multimap<ResourceLocation, ResourceLocation> mismatchedRegistryData, ConnectionData connectionData)
|
||||
{
|
||||
List<ResourceLocation> mismatchedRegistryMods = mismatchedRegistryData.values().stream().map(ResourceLocation::getNamespace).distinct().map(id -> new ResourceLocation(id, "")).toList();
|
||||
Map<ResourceLocation, String> mismatchedRegistryModData = mismatchedRegistryMods.stream().map(id -> ModList.get().getModContainerById(id.getNamespace()).map(modContainer -> Pair.of(id, modContainer.getModInfo().getVersion().toString())).orElse(Pair.of(id, NetworkRegistry.ABSENT))).collect(Collectors.toMap(Pair::getLeft, Pair::getRight));
|
||||
Map<ResourceLocation, String> mismatchedRegistryModData = mismatchedRegistryMods.stream().map(id -> ModList.get().getModContainerById(id.getNamespace()).map(modContainer -> Pair.of(id, modContainer.getModInfo().getVersion().toString())).orElse(Pair.of(id, NetworkRegistry.ABSENT.version()))).collect(Collectors.toMap(Pair::getLeft, Pair::getRight));
|
||||
Map<ResourceLocation, Pair<String, String>> presentModData = getServerSidePresentModData(mismatchedRegistryModData.keySet(), connectionData);
|
||||
|
||||
return new ModMismatchData(mismatchedRegistryModData, presentModData, false);
|
||||
@@ -140,7 +140,7 @@ public class ConnectionData
|
||||
{
|
||||
mismatchedModVersions = ModList.get().getMods().stream().map(info -> Pair.of(info.getModId(), info.getVersion().toString())).collect(Collectors.toMap(Pair::getLeft, Pair::getRight));
|
||||
}
|
||||
return mismatchedChannels.keySet().stream().map(channel -> Pair.of(channel, mismatchedChannels.get(channel).equals(NetworkRegistry.ABSENT) ? NetworkRegistry.ABSENT : mismatchedModVersions.getOrDefault(channel.getNamespace(), NetworkRegistry.ABSENT))).collect(Collectors.toMap(Pair::getLeft, Pair::getRight));
|
||||
return mismatchedChannels.keySet().stream().map(channel -> Pair.of(channel, mismatchedChannels.get(channel).equals(NetworkRegistry.ABSENT.version()) ? NetworkRegistry.ABSENT.version() : mismatchedModVersions.getOrDefault(channel.getNamespace(), NetworkRegistry.ABSENT.version()))).collect(Collectors.toMap(Pair::getLeft, Pair::getRight));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -204,7 +204,7 @@ public class NetworkHooks
|
||||
AbstractContainerMenu c = containerSupplier.createMenu(openContainerId, player.getInventory(), player);
|
||||
MenuType<?> type = c.getType();
|
||||
PlayMessages.OpenContainer msg = new PlayMessages.OpenContainer(type, openContainerId, containerSupplier.getDisplayName(), output);
|
||||
NetworkConstants.playChannel.sendTo(msg, player.connection.getConnection(), NetworkDirection.PLAY_TO_CLIENT);
|
||||
NetworkConstants.playChannel.sendTo(msg, player.connection.connection, NetworkDirection.PLAY_TO_CLIENT);
|
||||
|
||||
player.containerMenu = c;
|
||||
player.initMenu(player.containerMenu);
|
||||
|
||||
@@ -45,10 +45,8 @@ public class NetworkRegistry
|
||||
* Special value for clientAcceptedVersions and serverAcceptedVersions predicates indicating the other side lacks
|
||||
* this channel.
|
||||
*/
|
||||
@SuppressWarnings("RedundantStringConstructorCall")
|
||||
public static String ABSENT = new String("ABSENT \uD83E\uDD14");
|
||||
public static ServerStatusPing.ChannelData ABSENT = new ServerStatusPing.ChannelData(new ResourceLocation("absent"), "ABSENT \uD83E\uDD14", false);
|
||||
|
||||
@SuppressWarnings("RedundantStringConstructorCall")
|
||||
public static String ACCEPTVANILLA = new String("ALLOWVANILLA \uD83D\uDC93\uD83D\uDC93\uD83D\uDC93");
|
||||
|
||||
/**
|
||||
@@ -68,7 +66,7 @@ public class NetworkRegistry
|
||||
*/
|
||||
public static Predicate<String> acceptMissingOr(Predicate<String> versionCheck)
|
||||
{
|
||||
return versionCheck.or(ABSENT::equals).or(ACCEPTVANILLA::equals);
|
||||
return versionCheck.or(ABSENT.version()::equals).or(ACCEPTVANILLA::equals);
|
||||
}
|
||||
|
||||
public static List<String> getServerNonVanillaNetworkMods()
|
||||
@@ -172,11 +170,10 @@ public class NetworkRegistry
|
||||
* @see HandshakeMessages.S2CModList
|
||||
* @see HandshakeMessages.C2SModListReply
|
||||
*/
|
||||
static Map<ResourceLocation, Pair<String, Boolean>> buildChannelVersionsForListPing() {
|
||||
static Map<ResourceLocation, ServerStatusPing.ChannelData> buildChannelVersionsForListPing() {
|
||||
return instances.entrySet().stream().
|
||||
map( p -> Pair.of(p.getKey(), Pair.of(p.getValue().getNetworkProtocolVersion(), p.getValue().tryClientVersionOnServer(ABSENT)))).
|
||||
filter(p -> !p.getLeft().getNamespace().equals("fml")).
|
||||
collect(Collectors.toMap(Pair::getLeft, Pair::getRight));
|
||||
filter(p -> !p.getKey().getNamespace().equals("fml")).
|
||||
collect(Collectors.toMap(Map.Entry::getKey, val -> new ServerStatusPing.ChannelData(val.getKey(), val.getValue().getNetworkProtocolVersion(), val.getValue().tryClientVersionOnServer(ABSENT.version()))));
|
||||
}
|
||||
|
||||
static List<String> listRejectedVanillaMods(BiFunction<NetworkInstance, String, Boolean> testFunction) {
|
||||
@@ -186,7 +183,7 @@ public class NetworkRegistry
|
||||
final boolean test = testFunction.apply(ni, incomingVersion);
|
||||
LOGGER.debug(NETREGISTRY, "Channel '{}' : Vanilla acceptance test: {}", ni.getChannelName(), test ? "ACCEPTED" : "REJECTED");
|
||||
return Pair.of(ni.getChannelName(), test);
|
||||
}).filter(p->!p.getRight()).collect(Collectors.toList());
|
||||
}).filter(p->!p.getRight()).toList();
|
||||
|
||||
if (!results.isEmpty()) {
|
||||
LOGGER.error(NETREGISTRY, "Channels [{}] rejected vanilla connections",
|
||||
@@ -228,7 +225,7 @@ public class NetworkRegistry
|
||||
private static Map<ResourceLocation, String> validateChannels(final Map<ResourceLocation, String> incoming, final String originName, BiFunction<NetworkInstance, String, Boolean> testFunction) {
|
||||
final Map<ResourceLocation, String> results = instances.values().stream().
|
||||
map(ni -> {
|
||||
final String incomingVersion = incoming.getOrDefault(ni.getChannelName(), ABSENT);
|
||||
final String incomingVersion = incoming.getOrDefault(ni.getChannelName(), ABSENT.version());
|
||||
final boolean test = testFunction.apply(ni, incomingVersion);
|
||||
LOGGER.debug(NETREGISTRY, "Channel '{}' : Version test of '{}' from {} : {}", ni.getChannelName(), incomingVersion, originName, test ? "ACCEPTED" : "REJECTED");
|
||||
return Pair.of(Pair.of(ni.getChannelName(), incomingVersion), test);
|
||||
@@ -258,20 +255,20 @@ public class NetworkRegistry
|
||||
return gatheredPayloads;
|
||||
}
|
||||
|
||||
public static boolean checkListPingCompatibilityForClient(Map<ResourceLocation, Pair<String, Boolean>> incoming) {
|
||||
public static boolean checkListPingCompatibilityForClient(Map<ResourceLocation, ServerStatusPing.ChannelData> incoming) {
|
||||
Set<ResourceLocation> handled = new HashSet<>();
|
||||
final List<Pair<ResourceLocation, Boolean>> results = instances.values().stream().
|
||||
filter(p -> !p.getChannelName().getNamespace().equals("fml")).
|
||||
map(ni -> {
|
||||
final Pair<String, Boolean> incomingVersion = incoming.getOrDefault(ni.getChannelName(), Pair.of(ABSENT, true));
|
||||
final boolean test = ni.tryServerVersionOnClient(incomingVersion.getLeft());
|
||||
final ServerStatusPing.ChannelData incomingVersion = incoming.getOrDefault(ni.getChannelName(), ABSENT);
|
||||
final boolean test = ni.tryServerVersionOnClient(incomingVersion.version());
|
||||
handled.add(ni.getChannelName());
|
||||
LOGGER.debug(NETREGISTRY, "Channel '{}' : Version test of '{}' during listping : {}", ni.getChannelName(), incomingVersion, test ? "ACCEPTED" : "REJECTED");
|
||||
return Pair.of(ni.getChannelName(), test);
|
||||
}).filter(p->!p.getRight()).collect(Collectors.toList());
|
||||
final List<ResourceLocation> missingButRequired = incoming.entrySet().stream().
|
||||
filter(p -> !p.getKey().getNamespace().equals("fml")).
|
||||
filter(p -> !p.getValue().getRight()).
|
||||
filter(p -> !p.getValue().required()).
|
||||
filter(p -> !handled.contains(p.getKey())).
|
||||
map(Map.Entry::getKey).
|
||||
collect(Collectors.toList());
|
||||
|
||||
@@ -5,31 +5,24 @@
|
||||
|
||||
package net.minecraftforge.network;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.ResourceLocationException;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.fml.IExtensionPoint;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
/**
|
||||
* Represents additional data sent by FML when a server is pinged.
|
||||
@@ -59,14 +52,11 @@ import java.util.stream.StreamSupport;
|
||||
*
|
||||
* <p>
|
||||
* Modern versions will send binary data, which is encoded in a custom format optimized for UTF-16 code point count.
|
||||
* See {@link Serializer#encodeOptimized(ByteBuf)} and {@link Serializer#decodeOptimized(String)}.
|
||||
* See {@link #encodeOptimized(ByteBuf)} and {@link #decodeOptimized(String)}.
|
||||
* Essentially 15 bits of binary data are encoded into every UTF-16 code point. The resulting string is then stored in
|
||||
* the "d" property of the resulting JSON.
|
||||
*
|
||||
* <p>
|
||||
* For the format of the binary data see {@link Serializer#serialize(ServerStatusPing)}.
|
||||
*
|
||||
* <p>
|
||||
* The "channels" and "mods" properties are retained for backwards compatibility,
|
||||
* but left empty. A client that cannot read the old format would not be able to connect anyways, but the properties
|
||||
* must exist to not cause exceptions.
|
||||
@@ -81,48 +71,49 @@ import java.util.stream.StreamSupport;
|
||||
* }</pre>
|
||||
*
|
||||
*/
|
||||
public class ServerStatusPing
|
||||
public record ServerStatusPing(
|
||||
Map<ResourceLocation, ChannelData> channels,
|
||||
Map<String, String> mods,
|
||||
int fmlNetworkVer,
|
||||
boolean truncated
|
||||
)
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final Codec<ByteBuf> BYTE_BUF_CODEC = Codec.STRING
|
||||
.xmap(ServerStatusPing::decodeOptimized, ServerStatusPing::encodeOptimized);
|
||||
|
||||
public static final Codec<ServerStatusPing> CODEC = RecordCodecBuilder.create(in -> in.group(
|
||||
Codec.INT.fieldOf("fmlNetworkVersion").forGetter(ServerStatusPing::getFMLNetworkVersion),
|
||||
|
||||
ServerStatusPing.BYTE_BUF_CODEC.optionalFieldOf("d").forGetter(ping -> Optional.of(ping.toBuf())),
|
||||
|
||||
ChannelData.CODEC.listOf().optionalFieldOf("channels").forGetter(ping -> Optional.of(List.of())),
|
||||
ModInfo.CODEC.listOf().optionalFieldOf("mods").forGetter(ping -> Optional.of(List.of())),
|
||||
|
||||
// legacy versions see truncated lists, modern versions ignore this truncated flag (binary data has its own)
|
||||
Codec.BOOL.optionalFieldOf("truncated").forGetter(ping -> Optional.of(ping.isTruncated()))
|
||||
).apply(in, (fmlVer, buf, channels, mods, truncated) -> buf.map(byteBuf -> deserializeOptimized(fmlVer, byteBuf))
|
||||
.orElseGet(() -> new ServerStatusPing(
|
||||
channels.orElseGet(List::of).stream().collect(Collectors.toMap(ChannelData::res, Function.identity())),
|
||||
mods.orElseGet(List::of).stream().collect(Collectors.toMap(ModInfo::modId, ModInfo::modmarker)),
|
||||
fmlVer, truncated.orElse(false)
|
||||
))));
|
||||
|
||||
private final transient Map<ResourceLocation, Pair<String, Boolean>> channels;
|
||||
private final transient Map<String, String> mods;
|
||||
private final transient int fmlNetworkVer;
|
||||
private final transient boolean truncated;
|
||||
|
||||
public ServerStatusPing()
|
||||
{
|
||||
this.channels = NetworkRegistry.buildChannelVersionsForListPing();
|
||||
this.mods = new HashMap<>();
|
||||
ModList.get().forEachModContainer((modid, mc) ->
|
||||
mods.put(modid, mc.getCustomExtension(IExtensionPoint.DisplayTest.class)
|
||||
.map(IExtensionPoint.DisplayTest::suppliedVersion)
|
||||
.map(Supplier::get)
|
||||
.orElse(NetworkConstants.IGNORESERVERONLY)));
|
||||
this.fmlNetworkVer = NetworkConstants.FMLNETVERSION;
|
||||
this.truncated = false;
|
||||
this(
|
||||
NetworkRegistry.buildChannelVersionsForListPing(),
|
||||
Util.make(new HashMap<>(), map -> ModList.get().forEachModContainer((modid, mc) ->
|
||||
map.put(modid, mc.getCustomExtension(IExtensionPoint.DisplayTest.class)
|
||||
.map(IExtensionPoint.DisplayTest::suppliedVersion)
|
||||
.map(Supplier::get)
|
||||
.orElse(NetworkConstants.IGNORESERVERONLY)))),
|
||||
NetworkConstants.FMLNETVERSION,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
private ServerStatusPing(Map<ResourceLocation, Pair<String, Boolean>> deserialized, Map<String,String> modMarkers, int fmlNetVer, boolean truncated) {
|
||||
this.channels = ImmutableMap.copyOf(deserialized);
|
||||
this.mods = modMarkers;
|
||||
this.fmlNetworkVer = fmlNetVer;
|
||||
this.truncated = truncated;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "FMLStatusPing{" +
|
||||
"channels=" + channels +
|
||||
", mods=" + mods +
|
||||
", fmlNetworkVer="
|
||||
+ fmlNetworkVer +
|
||||
", truncated=" + truncated +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override // Don't compare the truncated flag as it is irrelevant
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o) return true;
|
||||
@@ -136,266 +127,220 @@ public class ServerStatusPing
|
||||
return Objects.hash(channels, mods, fmlNetworkVer);
|
||||
}
|
||||
|
||||
private List<Map.Entry<ResourceLocation, Pair<String, Boolean>>> getChannelsForMod(String modId)
|
||||
private List<Map.Entry<ResourceLocation, ChannelData>> getChannelsForMod(String modId)
|
||||
{
|
||||
return channels.entrySet().stream()
|
||||
.filter(c -> c.getKey().getNamespace().equals(modId))
|
||||
.toList();
|
||||
}
|
||||
|
||||
private List<Map.Entry<ResourceLocation, Pair<String, Boolean>>> getNonModChannels()
|
||||
private List<Map.Entry<ResourceLocation, ChannelData>> getNonModChannels()
|
||||
{
|
||||
return channels.entrySet().stream()
|
||||
.filter(c -> !mods.containsKey(c.getKey().getNamespace()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
public static class Serializer
|
||||
{
|
||||
public static ServerStatusPing deserialize(JsonObject forgeData)
|
||||
public ByteBuf toBuf() {
|
||||
// The following techniques are used to keep the size down:
|
||||
// 1. Try and group channels by ModID, this relies on the assumption that a mod "examplemod" uses a channel
|
||||
// like "examplemod:network". In that case only the "path" of the ResourceLocation is written
|
||||
// 2. Avoid sending IGNORESERVERONLY in plain text, instead use a flag (if set, no version string is sent)
|
||||
//
|
||||
// The size can be estimated as follows (assuming there are no non-mod network channels)
|
||||
// bytes = 2
|
||||
// + mod_count * (avg_mod_id_length + avg_mod_version_length + 1)
|
||||
// + (mod_count * avg_channel_count_per_mod) * (avg_mod_channel_length + avg_mod_channel_version_length + 1)
|
||||
// + 1
|
||||
// for 600 mods with an average ModID and channel length of 20, an average channel of 1 per mod and an
|
||||
// average version length of 5 this turns out to be 31203 bytes, which easily fits into the upper limit of
|
||||
// roughly 60000 bytes. As such it is estimated that the upper limit will never be reached.
|
||||
// we still check though and potentially truncate the list
|
||||
var reachedSizeLimit = false;
|
||||
var buf = new FriendlyByteBuf(Unpooled.buffer());
|
||||
buf.writeBoolean(false); // placeholder for whether we are truncating
|
||||
buf.writeShort(mods.size()); // short so that we can replace it later in case of truncation
|
||||
int writtenCount = 0;
|
||||
for (var modEntry : mods.entrySet())
|
||||
{
|
||||
try
|
||||
var isIgnoreServerOnly = modEntry.getValue().equals(NetworkConstants.IGNORESERVERONLY);
|
||||
|
||||
var channelsForMod = getChannelsForMod(modEntry.getKey());
|
||||
var channelSizeAndVersionFlag = channelsForMod.size() << 1;
|
||||
if (isIgnoreServerOnly)
|
||||
{
|
||||
if (forgeData.has("d"))
|
||||
{
|
||||
return deserializeOptimized(forgeData);
|
||||
}
|
||||
final Map<ResourceLocation, Pair<String, Boolean>> channels = StreamSupport.stream(GsonHelper.getAsJsonArray(forgeData, "channels").spliterator(), false).
|
||||
map(JsonElement::getAsJsonObject).
|
||||
collect(Collectors.toMap(jo -> new ResourceLocation(GsonHelper.getAsString(jo, "res")),
|
||||
jo -> Pair.of(GsonHelper.getAsString(jo, "version"), GsonHelper.getAsBoolean(jo, "required")))
|
||||
);
|
||||
|
||||
final Map<String, String> mods = StreamSupport.stream(GsonHelper.getAsJsonArray(forgeData, "mods").spliterator(), false).
|
||||
map(JsonElement::getAsJsonObject).
|
||||
collect(Collectors.toMap(jo -> GsonHelper.getAsString(jo, "modId"), jo->GsonHelper.getAsString(jo, "modmarker")));
|
||||
|
||||
final int remoteFMLVersion = GsonHelper.getAsInt(forgeData, "fmlNetworkVersion");
|
||||
final boolean truncated = GsonHelper.getAsBoolean(forgeData, "truncated", false);
|
||||
return new ServerStatusPing(channels, mods, remoteFMLVersion, truncated);
|
||||
channelSizeAndVersionFlag |= VERSION_FLAG_IGNORESERVERONLY;
|
||||
}
|
||||
catch (JsonSyntaxException | IndexOutOfBoundsException | ResourceLocationException e)
|
||||
buf.writeVarInt(channelSizeAndVersionFlag);
|
||||
|
||||
buf.writeUtf(modEntry.getKey());
|
||||
if (!isIgnoreServerOnly)
|
||||
{
|
||||
LOGGER.debug(NetworkConstants.NETWORK, "Encountered an error parsing status ping data", e);
|
||||
return null;
|
||||
buf.writeUtf(modEntry.getValue());
|
||||
}
|
||||
|
||||
// write the channels for this mod, if any
|
||||
for (var entry : channelsForMod)
|
||||
{
|
||||
buf.writeUtf(entry.getKey().getPath());
|
||||
buf.writeUtf(entry.getValue().version());
|
||||
buf.writeBoolean(entry.getValue().required());
|
||||
}
|
||||
|
||||
writtenCount++;
|
||||
|
||||
if (buf.readableBytes() >= 60000)
|
||||
{
|
||||
reachedSizeLimit = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static JsonObject serialize(ServerStatusPing forgeData)
|
||||
if (!reachedSizeLimit)
|
||||
{
|
||||
// The following techniques are used to keep the size down:
|
||||
// 1. Try and group channels by ModID, this relies on the assumption that a mod "examplemod" uses a channel
|
||||
// like "examplemod:network". In that case only the "path" of the ResourceLocation is written
|
||||
// 2. Avoid sending IGNORESERVERONLY in plain text, instead use a flag (if set, no version string is sent)
|
||||
//
|
||||
// The size can be estimated as follows (assuming there are no non-mod network channels)
|
||||
// bytes = 2
|
||||
// + mod_count * (avg_mod_id_length + avg_mod_version_length + 1)
|
||||
// + (mod_count * avg_channel_count_per_mod) * (avg_mod_channel_length + avg_mod_channel_version_length + 1)
|
||||
// + 1
|
||||
// for 600 mods with an average ModID and channel length of 20, an average channel of 1 per mod and an
|
||||
// average version length of 5 this turns out to be 31203 bytes, which easily fits into the upper limit of
|
||||
// roughly 60000 bytes. As such it is estimated that the upper limit will never be reached.
|
||||
// we still check though and potentially truncate the list
|
||||
|
||||
var reachedSizeLimit = false;
|
||||
var buf = new FriendlyByteBuf(Unpooled.buffer());
|
||||
buf.writeBoolean(false); // placeholder for whether we are truncating
|
||||
buf.writeShort(forgeData.mods.size()); // short so that we can replace it later in case of truncation
|
||||
int writtenCount = 0;
|
||||
for (var modEntry : forgeData.mods.entrySet())
|
||||
// write any channels that don't match up with a ModID.
|
||||
var nonModChannels = getNonModChannels();
|
||||
buf.writeVarInt(nonModChannels.size());
|
||||
for (var entry : nonModChannels)
|
||||
{
|
||||
var isIgnoreServerOnly = modEntry.getValue().equals(NetworkConstants.IGNORESERVERONLY);
|
||||
|
||||
var channelsForMod = forgeData.getChannelsForMod(modEntry.getKey());
|
||||
var channelSizeAndVersionFlag = channelsForMod.size() << 1;
|
||||
if (isIgnoreServerOnly)
|
||||
{
|
||||
channelSizeAndVersionFlag |= VERSION_FLAG_IGNORESERVERONLY;
|
||||
}
|
||||
buf.writeVarInt(channelSizeAndVersionFlag);
|
||||
|
||||
buf.writeUtf(modEntry.getKey());
|
||||
if (!isIgnoreServerOnly)
|
||||
{
|
||||
buf.writeUtf(modEntry.getValue());
|
||||
}
|
||||
|
||||
// write the channels for this mod, if any
|
||||
for (var entry : channelsForMod)
|
||||
{
|
||||
buf.writeUtf(entry.getKey().getPath());
|
||||
buf.writeUtf(entry.getValue().getLeft());
|
||||
buf.writeBoolean(entry.getValue().getRight());
|
||||
}
|
||||
|
||||
writtenCount++;
|
||||
|
||||
if (buf.readableBytes() >= 60000)
|
||||
{
|
||||
reachedSizeLimit = true;
|
||||
break;
|
||||
}
|
||||
buf.writeResourceLocation(entry.getKey());
|
||||
buf.writeUtf(entry.getValue().version());
|
||||
buf.writeBoolean(entry.getValue().required());
|
||||
}
|
||||
|
||||
if (!reachedSizeLimit)
|
||||
{
|
||||
// write any channels that don't match up with a ModID.
|
||||
var nonModChannels = forgeData.getNonModChannels();
|
||||
buf.writeVarInt(nonModChannels.size());
|
||||
for (var entry : nonModChannels)
|
||||
{
|
||||
buf.writeResourceLocation(entry.getKey());
|
||||
buf.writeUtf(entry.getValue().getLeft());
|
||||
buf.writeBoolean(entry.getValue().getRight());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
buf.setShort(1, writtenCount);
|
||||
buf.writeVarInt(0);
|
||||
}
|
||||
|
||||
buf.setBoolean(0, reachedSizeLimit);
|
||||
|
||||
var obj = new JsonObject();
|
||||
obj.addProperty("fmlNetworkVersion", forgeData.fmlNetworkVer);
|
||||
obj.addProperty("d", encodeOptimized(buf));
|
||||
|
||||
// add dummy properties, so old versions do not crash when deserializing
|
||||
obj.add("channels", new JsonArray());
|
||||
obj.add("mods", new JsonArray());
|
||||
// legacy versions see truncated lists, modern versions ignore this truncated flag (binary data has its own)
|
||||
obj.addProperty("truncated", true);
|
||||
return obj;
|
||||
}
|
||||
else
|
||||
{
|
||||
buf.setShort(1, writtenCount);
|
||||
buf.writeVarInt(0);
|
||||
}
|
||||
|
||||
private static final int VERSION_FLAG_IGNORESERVERONLY = 0b1;
|
||||
buf.setBoolean(0, reachedSizeLimit);
|
||||
return buf;
|
||||
}
|
||||
|
||||
private static ServerStatusPing deserializeOptimized(JsonObject forgeData)
|
||||
private static final int VERSION_FLAG_IGNORESERVERONLY = 0b1;
|
||||
|
||||
private static ServerStatusPing deserializeOptimized(int fmlNetworkVersion, ByteBuf bbuf) {
|
||||
var buf = new FriendlyByteBuf(bbuf);
|
||||
boolean truncated;
|
||||
Map<ResourceLocation, ChannelData> channels;
|
||||
Map<String, String> mods;
|
||||
|
||||
try
|
||||
{
|
||||
int remoteFMLVersion = GsonHelper.getAsInt(forgeData, "fmlNetworkVersion");
|
||||
var buf = new FriendlyByteBuf(decodeOptimized(GsonHelper.getAsString(forgeData, "d")));
|
||||
|
||||
boolean truncated;
|
||||
Map<ResourceLocation, Pair<String, Boolean>> channels;
|
||||
Map<String, String> mods;
|
||||
|
||||
try
|
||||
{
|
||||
truncated = buf.readBoolean();
|
||||
var modsSize = buf.readUnsignedShort();
|
||||
mods = new HashMap<>();
|
||||
channels = new HashMap<>();
|
||||
for (var i = 0; i < modsSize; i++) {
|
||||
var channelSizeAndVersionFlag = buf.readVarInt();
|
||||
var channelSize = channelSizeAndVersionFlag >>> 1;
|
||||
var isIgnoreServerOnly = (channelSizeAndVersionFlag & VERSION_FLAG_IGNORESERVERONLY) != 0;
|
||||
var modId = buf.readUtf();
|
||||
var modVersion = isIgnoreServerOnly ? NetworkConstants.IGNORESERVERONLY : buf.readUtf();
|
||||
for (var i1 = 0; i1 < channelSize; i1++) {
|
||||
var channelName = buf.readUtf();
|
||||
var channelVersion = buf.readUtf();
|
||||
var requiredOnClient = buf.readBoolean();
|
||||
channels.put(new ResourceLocation(modId, channelName), Pair.of(channelVersion, requiredOnClient));
|
||||
}
|
||||
|
||||
mods.put(modId, modVersion);
|
||||
}
|
||||
|
||||
var nonModChannelCount = buf.readVarInt();
|
||||
for (var i = 0; i < nonModChannelCount; i++) {
|
||||
var channelName = buf.readResourceLocation();
|
||||
truncated = buf.readBoolean();
|
||||
var modsSize = buf.readUnsignedShort();
|
||||
mods = new HashMap<>();
|
||||
channels = new HashMap<>();
|
||||
for (var i = 0; i < modsSize; i++) {
|
||||
var channelSizeAndVersionFlag = buf.readVarInt();
|
||||
var channelSize = channelSizeAndVersionFlag >>> 1;
|
||||
var isIgnoreServerOnly = (channelSizeAndVersionFlag & VERSION_FLAG_IGNORESERVERONLY) != 0;
|
||||
var modId = buf.readUtf();
|
||||
var modVersion = isIgnoreServerOnly ? NetworkConstants.IGNORESERVERONLY : buf.readUtf();
|
||||
for (var i1 = 0; i1 < channelSize; i1++) {
|
||||
var channelName = buf.readUtf();
|
||||
var channelVersion = buf.readUtf();
|
||||
var requiredOnClient = buf.readBoolean();
|
||||
channels.put(channelName, Pair.of(channelVersion, requiredOnClient));
|
||||
final ResourceLocation id = new ResourceLocation(modId, channelName);
|
||||
channels.put(id, new ChannelData(id, channelVersion, requiredOnClient));
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
buf.release();
|
||||
|
||||
mods.put(modId, modVersion);
|
||||
}
|
||||
|
||||
return new ServerStatusPing(channels, mods, remoteFMLVersion, truncated);
|
||||
var nonModChannelCount = buf.readVarInt();
|
||||
for (var i = 0; i < nonModChannelCount; i++) {
|
||||
var channelName = buf.readResourceLocation();
|
||||
var channelVersion = buf.readUtf();
|
||||
var requiredOnClient = buf.readBoolean();
|
||||
channels.put(channelName, new ChannelData(channelName, channelVersion, requiredOnClient));
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
buf.release();
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode given ByteBuf to a String. This is optimized for UTF-16 Code-Point count.
|
||||
* Supports at most 2^30 bytes in length
|
||||
*/
|
||||
private static String encodeOptimized(ByteBuf buf)
|
||||
return new ServerStatusPing(channels, mods, fmlNetworkVersion, truncated);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode given ByteBuf to a String. This is optimized for UTF-16 Code-Point count.
|
||||
* Supports at most 2^30 bytes in length
|
||||
*/
|
||||
private static String encodeOptimized(ByteBuf buf)
|
||||
{
|
||||
var byteLength = buf.readableBytes();
|
||||
var sb = new StringBuilder();
|
||||
sb.append((char) (byteLength & 0x7FFF));
|
||||
sb.append((char) ((byteLength >>> 15) & 0x7FFF));
|
||||
|
||||
int buffer = 0; // we will need at most 8 + 14 = 22 bits of buffer, so an int is enough
|
||||
int bitsInBuf = 0;
|
||||
while (buf.isReadable())
|
||||
{
|
||||
var byteLength = buf.readableBytes();
|
||||
var sb = new StringBuilder();
|
||||
sb.append((char) (byteLength & 0x7FFF));
|
||||
sb.append((char) ((byteLength >>> 15) & 0x7FFF));
|
||||
|
||||
int buffer = 0; // we will need at most 8 + 14 = 22 bits of buffer, so an int is enough
|
||||
int bitsInBuf = 0;
|
||||
while (buf.isReadable())
|
||||
{
|
||||
if (bitsInBuf >= 15)
|
||||
{
|
||||
char c = (char) (buffer & 0x7FFF);
|
||||
sb.append(c);
|
||||
buffer >>>= 15;
|
||||
bitsInBuf -= 15;
|
||||
}
|
||||
var b = buf.readUnsignedByte();
|
||||
buffer |= (int) b << bitsInBuf;
|
||||
bitsInBuf += 8;
|
||||
}
|
||||
|
||||
if (bitsInBuf > 0)
|
||||
if (bitsInBuf >= 15)
|
||||
{
|
||||
char c = (char) (buffer & 0x7FFF);
|
||||
sb.append(c);
|
||||
buffer >>>= 15;
|
||||
bitsInBuf -= 15;
|
||||
}
|
||||
return sb.toString();
|
||||
var b = buf.readUnsignedByte();
|
||||
buffer |= (int) b << bitsInBuf;
|
||||
bitsInBuf += 8;
|
||||
}
|
||||
buf.release();
|
||||
|
||||
/**
|
||||
* Decode binary data encoded by {@link #encodeOptimized}
|
||||
*/
|
||||
private static ByteBuf decodeOptimized(String s)
|
||||
if (bitsInBuf > 0)
|
||||
{
|
||||
var size0 = ((int) s.charAt(0));
|
||||
var size1 = ((int) s.charAt(1));
|
||||
var size = size0 | (size1 << 15);
|
||||
char c = (char) (buffer & 0x7FFF);
|
||||
sb.append(c);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
var buf = Unpooled.buffer(size);
|
||||
/**
|
||||
* Decode binary data encoded by {@link #encodeOptimized}
|
||||
*/
|
||||
private static ByteBuf decodeOptimized(String s)
|
||||
{
|
||||
var size0 = ((int) s.charAt(0));
|
||||
var size1 = ((int) s.charAt(1));
|
||||
var size = size0 | (size1 << 15);
|
||||
|
||||
int stringIndex = 2;
|
||||
int buffer = 0; // we will need at most 8 + 14 = 22 bits of buffer, so an int is enough
|
||||
int bitsInBuf = 0;
|
||||
while (stringIndex < s.length())
|
||||
{
|
||||
while (bitsInBuf >= 8)
|
||||
{
|
||||
buf.writeByte(buffer);
|
||||
buffer >>>= 8;
|
||||
bitsInBuf -= 8;
|
||||
}
|
||||
var buf = Unpooled.buffer(size);
|
||||
|
||||
var c = s.charAt(stringIndex);
|
||||
buffer |= (((int) c) & 0x7FFF) << bitsInBuf;
|
||||
bitsInBuf += 15;
|
||||
stringIndex++;
|
||||
}
|
||||
|
||||
// write any leftovers
|
||||
while (buf.readableBytes() < size)
|
||||
int stringIndex = 2;
|
||||
int buffer = 0; // we will need at most 8 + 14 = 22 bits of buffer, so an int is enough
|
||||
int bitsInBuf = 0;
|
||||
while (stringIndex < s.length())
|
||||
{
|
||||
while (bitsInBuf >= 8)
|
||||
{
|
||||
buf.writeByte(buffer);
|
||||
buffer >>>= 8;
|
||||
bitsInBuf -= 8;
|
||||
}
|
||||
return buf;
|
||||
|
||||
var c = s.charAt(stringIndex);
|
||||
buffer |= (((int) c) & 0x7FFF) << bitsInBuf;
|
||||
bitsInBuf += 15;
|
||||
stringIndex++;
|
||||
}
|
||||
|
||||
// write any leftovers
|
||||
while (buf.readableBytes() < size)
|
||||
{
|
||||
buf.writeByte(buffer);
|
||||
buffer >>>= 8;
|
||||
bitsInBuf -= 8;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
public Map<ResourceLocation, Pair<String, Boolean>> getRemoteChannels()
|
||||
public Map<ResourceLocation, ChannelData> getRemoteChannels()
|
||||
{
|
||||
return this.channels;
|
||||
}
|
||||
@@ -414,4 +359,19 @@ public class ServerStatusPing
|
||||
{
|
||||
return truncated;
|
||||
}
|
||||
|
||||
public record ModInfo(String modId, String modmarker) {
|
||||
public static final Codec<ModInfo> CODEC = RecordCodecBuilder.create(in -> in.group(
|
||||
Codec.STRING.fieldOf("modId").forGetter(ModInfo::modId),
|
||||
Codec.STRING.fieldOf("modmarker").forGetter(ModInfo::modmarker)
|
||||
).apply(in, ModInfo::new));
|
||||
}
|
||||
|
||||
public record ChannelData(ResourceLocation res, String version, boolean required) {
|
||||
public static final Codec<ChannelData> CODEC = RecordCodecBuilder.create(in -> in.group(
|
||||
ResourceLocation.CODEC.fieldOf("res").forGetter(ChannelData::res),
|
||||
Codec.STRING.fieldOf("version").forGetter(ChannelData::version),
|
||||
Codec.BOOL.fieldOf("required").forGetter(ChannelData::required)
|
||||
).apply(in, ChannelData::new));
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ public class ForgeDeferredRegistriesSetup
|
||||
ForgeRegistries.DEFERRED_FLUID_TYPES.register(modEventBus);
|
||||
ForgeRegistries.DEFERRED_STRUCTURE_MODIFIER_SERIALIZERS.register(modEventBus);
|
||||
ForgeRegistries.DEFERRED_HOLDER_SET_TYPES.register(modEventBus);
|
||||
ForgeRegistries.DEFERRED_DISPLAY_CONTEXTS.register(modEventBus);
|
||||
|
||||
setup = true;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.mojang.serialization.Codec;
|
||||
import net.minecraft.commands.synchronization.ArgumentTypeInfo;
|
||||
import net.minecraft.network.syncher.EntityDataSerializer;
|
||||
import net.minecraft.world.entity.decoration.PaintingVariant;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
@@ -48,7 +49,9 @@ import net.minecraftforge.fluids.FluidType;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.holdersets.HolderSetType;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
import net.minecraftforge.common.world.StructureModifier;
|
||||
|
||||
@@ -137,6 +140,13 @@ public class ForgeRegistries
|
||||
*/
|
||||
public static final Supplier<IForgeRegistry<HolderSetType>> HOLDER_SET_TYPES = DEFERRED_HOLDER_SET_TYPES.makeRegistry(GameData::getHolderSetTypeRegistryBuilder);
|
||||
|
||||
static final DeferredRegister<ItemDisplayContext> DEFERRED_DISPLAY_CONTEXTS = DeferredRegister.create(Keys.DISPLAY_CONTEXTS, "forge");
|
||||
/**
|
||||
* Calling {@link Supplier#get()} before {@link NewRegistryEvent} is fired will result in a null registry returned.
|
||||
* Use {@link Keys#DISPLAY_CONTEXTS} to create a {@link DeferredRegister}.
|
||||
*/
|
||||
public static final Supplier<IForgeRegistry<ItemDisplayContext>> DISPLAY_CONTEXTS = DEFERRED_DISPLAY_CONTEXTS.makeRegistry(GameData::getItemDisplayContextRegistryBuilder);
|
||||
|
||||
public static final class Keys {
|
||||
//Vanilla
|
||||
public static final ResourceKey<Registry<Block>> BLOCKS = key("block");
|
||||
@@ -179,6 +189,7 @@ public class ForgeRegistries
|
||||
public static final ResourceKey<Registry<Codec<? extends StructureModifier>>> STRUCTURE_MODIFIER_SERIALIZERS = key("forge:structure_modifier_serializers");
|
||||
public static final ResourceKey<Registry<FluidType>> FLUID_TYPES = key("forge:fluid_type");
|
||||
public static final ResourceKey<Registry<HolderSetType>> HOLDER_SET_TYPES = key("forge:holder_set_type");
|
||||
public static final ResourceKey<Registry<ItemDisplayContext>> DISPLAY_CONTEXTS = key("forge:display_contexts");
|
||||
|
||||
// Forge Dynamic
|
||||
public static final ResourceKey<Registry<BiomeModifier>> BIOME_MODIFIERS = key("forge:biome_modifier");
|
||||
|
||||
@@ -7,6 +7,7 @@ package net.minecraftforge.registries;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.function.IntFunction;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.Codec;
|
||||
@@ -351,6 +352,7 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
|
||||
return getIDRaw(this.names.get(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public V getValue(int id)
|
||||
{
|
||||
V ret = this.ids.get(id);
|
||||
@@ -381,6 +383,11 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
|
||||
return new ForgeRegistry<>(stage, name, builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(int id, ResourceLocation key, V value) {
|
||||
add(id, key, value, key.getNamespace());
|
||||
}
|
||||
|
||||
int add(int id, ResourceLocation key, V value)
|
||||
{
|
||||
final String owner = ModLoadingContext.get().getActiveNamespace();
|
||||
@@ -995,7 +1002,7 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
|
||||
int id = n.intValue();
|
||||
if (ids.get(id) == null)
|
||||
{
|
||||
return DataResult.error("Unknown registry id in " + ForgeRegistry.this.key + ": " + n);
|
||||
return DataResult.error(() -> "Unknown registry id in " + ForgeRegistry.this.key + ": " + n);
|
||||
}
|
||||
V val = ForgeRegistry.this.getValue(id);
|
||||
return DataResult.success(val);
|
||||
@@ -1004,7 +1011,7 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
|
||||
else
|
||||
{
|
||||
return ResourceLocation.CODEC.decode(ops, input).flatMap(keyValuePair -> !ForgeRegistry.this.containsKey(keyValuePair.getFirst())
|
||||
? DataResult.error("Unknown registry key in " + ForgeRegistry.this.key + ": " + keyValuePair.getFirst())
|
||||
? DataResult.error(() -> "Unknown registry key in " + ForgeRegistry.this.key + ": " + keyValuePair.getFirst())
|
||||
: DataResult.success(keyValuePair.mapFirst(ForgeRegistry.this::getValue)));
|
||||
}
|
||||
}
|
||||
@@ -1015,7 +1022,7 @@ public class ForgeRegistry<V> implements IForgeRegistryInternal<V>, IForgeRegist
|
||||
ResourceLocation key = getKey(input);
|
||||
if (key == null)
|
||||
{
|
||||
return DataResult.error("Unknown registry element in " + ForgeRegistry.this.key + ": " + input);
|
||||
return DataResult.error(() -> "Unknown registry element in " + ForgeRegistry.this.key + ": " + input);
|
||||
}
|
||||
T toMerge = ops.compressMaps() ? ops.createInt(getID(input)) : ops.createString(key.toString());
|
||||
return ops.mergeToPrimitive(prefix, toMerge);
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
@@ -22,6 +23,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import net.minecraft.core.IdMapper;
|
||||
import net.minecraft.core.MappedRegistry;
|
||||
@@ -37,6 +39,7 @@ import net.minecraft.world.entity.ai.attributes.DefaultAttributes;
|
||||
import net.minecraft.world.entity.ai.village.poi.PoiType;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraft.world.level.block.AirBlock;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
@@ -201,6 +204,17 @@ public class GameData
|
||||
return new RegistryBuilder<HolderSetType>().disableSaving().disableSync();
|
||||
}
|
||||
|
||||
static RegistryBuilder<ItemDisplayContext> getItemDisplayContextRegistryBuilder()
|
||||
{
|
||||
return new RegistryBuilder<ItemDisplayContext>()
|
||||
.setMaxID(128 * 2) /* 0 -> 127 gets positive ID, 128 -> 256 gets negative ID */.disableOverrides().disableSaving()
|
||||
.setDefaultKey(new ResourceLocation("minecraft:none"))
|
||||
.onCreate((owner, stage) -> Arrays.stream(ItemDisplayContext.values())
|
||||
.filter(Predicate.not(ItemDisplayContext::isModded))
|
||||
.forEach(ctx -> owner.register(ctx.getId(), new ResourceLocation("minecraft", ctx.getSerializedName()), ctx)))
|
||||
.onAdd(ItemDisplayContext.ADD_CALLBACK);
|
||||
}
|
||||
|
||||
private static <T> RegistryBuilder<T> makeRegistry(ResourceKey<? extends Registry<T>> key)
|
||||
{
|
||||
return new RegistryBuilder<T>().setName(key.location()).setMaxID(MAX_VARINT).hasWrapper();
|
||||
|
||||
@@ -10,4 +10,7 @@ import net.minecraft.resources.ResourceLocation;
|
||||
public interface IForgeRegistryInternal<V> extends IForgeRegistry<V>
|
||||
{
|
||||
void setSlaveMap(ResourceLocation name, Object obj);
|
||||
|
||||
void register(int id, ResourceLocation key, V value);
|
||||
V getValue(int id);
|
||||
}
|
||||
@@ -86,7 +86,6 @@ public class ServerLifecycleHooks
|
||||
public static boolean handleServerAboutToStart(final MinecraftServer server)
|
||||
{
|
||||
currentServer = server;
|
||||
currentServer.getStatus().setForgeData(new ServerStatusPing()); //gathers NetworkRegistry data
|
||||
// on the dedi server we need to force the stuff to setup properly
|
||||
LogicalSidedProvider.setServer(()->server);
|
||||
ConfigTracker.INSTANCE.loadConfigs(ModConfig.Type.SERVER, getServerConfigPath(server));
|
||||
|
||||
@@ -198,7 +198,7 @@ class TagsCommand
|
||||
{
|
||||
final String allElementNames = names.get().sorted().collect(Collectors.joining("\n"));
|
||||
final long totalPages = (count - 1) / PAGE_SIZE + 1;
|
||||
final long actualPage = Mth.clamp(currentPage, 1, totalPages);
|
||||
final long actualPage = (long) Mth.clamp(currentPage, 1, totalPages);
|
||||
|
||||
MutableComponent containsComponent = Component.translatable(containsText, count);
|
||||
if (count > 0) // Highlight the count text, make it clickable, and append page counters
|
||||
|
||||
Reference in new issue
Block a user