aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Hilyard <anthony.hilyard@gmail.com>2023-04-20 14:06:02 -0700
committerAnthony Hilyard <anthony.hilyard@gmail.com>2023-04-20 14:06:02 -0700
commitb35061a82bed88966b6efdab39fc3c5b11cb0267 (patch)
treea5e9d6cd5e86a69aa1a03c58897909dda862176c
parentde97dac7b449909e46db843aa4e65ccdcc9eb9ff (diff)
downloadIceberg-b35061a82bed88966b6efdab39fc3c5b11cb0267.tar.gz
Iceberg-b35061a82bed88966b6efdab39fc3c5b11cb0267.tar.bz2
Iceberg-b35061a82bed88966b6efdab39fc3c5b11cb0267.zip
Ported changes through 1.1.8.
Fixed crash when previewing fishing rods.
-rw-r--r--.vs/Iceberg-Fabric-1.18/v17/.suobin14336 -> 0 bytes
-rw-r--r--.vs/VSWorkspaceState.json6
-rw-r--r--.vs/slnx.sqlitebin90112 -> 0 bytes
-rw-r--r--CHANGELOG.md11
-rw-r--r--build.gradle2
-rw-r--r--gradle.properties8
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java12
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/renderer/CheckedBufferSource.java4
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/renderer/CustomItemRenderer.java128
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/renderer/VertexCollector.java2
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/util/EntityCollector.java94
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/util/GuiHelper.java4
-rw-r--r--src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java14
-rw-r--r--src/main/resources/fabric.mod.json6
-rw-r--r--src/main/resources/iceberg.accesswidener2
15 files changed, 189 insertions, 104 deletions
diff --git a/.vs/Iceberg-Fabric-1.18/v17/.suo b/.vs/Iceberg-Fabric-1.18/v17/.suo
deleted file mode 100644
index 8effe01..0000000
--- a/.vs/Iceberg-Fabric-1.18/v17/.suo
+++ /dev/null
Binary files differ
diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json
deleted file mode 100644
index 6b61141..0000000
--- a/.vs/VSWorkspaceState.json
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "ExpandedNodes": [
- ""
- ],
- "PreviewInSolutionExplorer": false
-} \ No newline at end of file
diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite
deleted file mode 100644
index 87a95ba..0000000
--- a/.vs/slnx.sqlite
+++ /dev/null
Binary files differ
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fb0fc10..2a22e84 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,16 @@
# Changelog
+### 1.1.9
+- Fixed a bug that could cause crashes when trying to preview fishing rods.
+
+### 1.1.8
+- Fixed a bug that prevented item models from being rendered into custom GUIs with alpha applied.
+
+### 1.1.7
+- Fixed a crash when previewing some modded 3D entity models.
+- Added painting support for 3D item previews.
+- Added support for Rubidium 0.6.4 / Sodium 0.4.10.
+
### 1.1.6
- Fixed crash with some mods when rendering custom 3D models.
- Added support to 3D item previews for most items that spawn entities (boats, minecarts, spawn eggs, etc).
diff --git a/build.gradle b/build.gradle
index e371cb7..0f2a442 100644
--- a/build.gradle
+++ b/build.gradle
@@ -23,7 +23,7 @@ dependencies {
mappings loom.officialMojangMappings()
modImplementation "net.fabricmc:fabric-loader:${project.loaderVersion}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabricVersion}"
- modImplementation "curse.maven:sodium-394468:4381988"
+ modImplementation "curse.maven:sodium-394468:4437119"
}
loom {
diff --git a/gradle.properties b/gradle.properties
index a741dfc..febfb40 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -6,8 +6,8 @@ org.gradle.daemon=false
name=${rootProject.name}
group=com.anthonyhilyard.${name.toLowerCase()}
author=anthonyhilyard
-version=1.1.6
+version=1.1.9
-mcVersion=1.19.3
-fabricVersion=0.72.0+1.19.3
-loaderVersion=0.14.12
+mcVersion=1.19.4
+fabricVersion=0.78.0+1.19.4
+loaderVersion=0.14.19
diff --git a/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java b/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java
index bc3674f..1b1d67d 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/mixin/ScreenMixin.java
@@ -11,6 +11,7 @@ import com.anthonyhilyard.iceberg.util.Tooltips;
import com.google.common.collect.Lists;
import com.mojang.blaze3d.vertex.PoseStack;
+import org.joml.Vector2ic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@@ -165,8 +166,8 @@ public class ScreenMixin extends AbstractContainerEventHandler
}
@SuppressWarnings("deprecation")
- @Inject(method = "renderTooltipInternal", at = @At(value = "TAIL"), locals = LocalCapture.CAPTURE_FAILEXCEPTION)
- private void renderTooltipInternal(PoseStack poseStack, List<ClientTooltipComponent> components, int x, int y, ClientTooltipPositioner positioner, CallbackInfo info, int tooltipWidth, int tooltipHeight, int postX, int postY)
+ @Inject(method = "renderTooltipInternal", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;popPose()V", shift = Shift.BEFORE), locals = LocalCapture.CAPTURE_FAILEXCEPTION, cancellable = true)
+ private void renderTooltipInternal(PoseStack poseStack, List<ClientTooltipComponent> components, int x, int y, ClientTooltipPositioner positioner, CallbackInfo info, int tooltipWidth, int tooltipHeight, int tooltipWidth2, int tooltipHeight2, Vector2ic postPos)
{
Screen self = (Screen)(Object)this;
ItemStack containerStack = ItemStack.EMPTY;
@@ -184,13 +185,16 @@ public class ScreenMixin extends AbstractContainerEventHandler
containerStack = tooltipStack;
}
+ poseStack.popPose();
+
if (!containerStack.isEmpty() && !components.isEmpty())
{
- RenderTooltipEvents.POSTEXT.invoker().onPost(containerStack, components, poseStack, postX, postY, font, tooltipWidth, tooltipHeight, false, 0);
- RenderTooltipEvents.POST.invoker().onPost(containerStack, components, poseStack, postX, postY, font, tooltipWidth, tooltipHeight, false);
+ RenderTooltipEvents.POSTEXT.invoker().onPost(containerStack, components, poseStack, postPos.x(), postPos.y(), font, tooltipWidth, tooltipHeight, false, 0);
+ RenderTooltipEvents.POST.invoker().onPost(containerStack, components, poseStack, postPos.x(), postPos.y(), font, tooltipWidth, tooltipHeight, false);
}
tooltipStack = ItemStack.EMPTY;
+ info.cancel();
}
@Override
diff --git a/src/main/java/com/anthonyhilyard/iceberg/renderer/CheckedBufferSource.java b/src/main/java/com/anthonyhilyard/iceberg/renderer/CheckedBufferSource.java
index e0ae33a..706fd9c 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/renderer/CheckedBufferSource.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/renderer/CheckedBufferSource.java
@@ -28,8 +28,8 @@ public class CheckedBufferSource implements MultiBufferSource
{
try
{
- // If Sodium 0.4.9 is installed, use the Sodium implementation.
- useSodiumVersion = FabricLoader.getInstance().isModLoaded("sodium") && VersionPredicateParser.parse("0.4.9").test(FabricLoader.getInstance().getModContainer("sodium").get().getMetadata().getVersion());
+ // If Sodium 0.4.10 is installed, use the Sodium implementation.
+ useSodiumVersion = FabricLoader.getInstance().isModLoaded("sodium") && VersionPredicateParser.parse("0.4.10").test(FabricLoader.getInstance().getModContainer("sodium").get().getMetadata().getVersion());
}
catch (Exception e)
{
diff --git a/src/main/java/com/anthonyhilyard/iceberg/renderer/CustomItemRenderer.java b/src/main/java/com/anthonyhilyard/iceberg/renderer/CustomItemRenderer.java
index 70a3481..88b3b6d 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/renderer/CustomItemRenderer.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/renderer/CustomItemRenderer.java
@@ -19,6 +19,7 @@ import org.lwjgl.opengl.GL11;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.datafixers.util.Pair;
+import com.mojang.math.Axis;
import com.mojang.math.MatrixUtil;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.pipeline.MainTarget;
@@ -44,8 +45,6 @@ import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.MultiBufferSource.BufferSource;
import net.minecraft.client.renderer.block.BlockModelShaper;
-import net.minecraft.client.renderer.block.model.ItemTransforms;
-import net.minecraft.client.renderer.block.model.ItemTransforms.TransformType;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.ModelManager;
@@ -66,6 +65,7 @@ import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.HorseArmorItem;
import net.minecraft.world.item.Item;
+import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Block;
@@ -93,8 +93,8 @@ public class CustomItemRenderer extends ItemRenderer
private static Entity entity = null;
private static Pair<Item, CompoundTag> cachedArmorStandItem = null;
private static Pair<Item, CompoundTag> cachedHorseArmorItem = null;
- private static Item cachedEntityItem = null;
- private static Map<Item, ModelBounds> modelBoundsCache = Maps.newHashMap();
+ private static Pair<Item, CompoundTag> cachedEntityItem = null;
+ private static Map<Pair<Item, CompoundTag>, ModelBounds> modelBoundsCache = Maps.newHashMap();
private static final List<Direction> quadDirections;
static
@@ -103,17 +103,18 @@ public class CustomItemRenderer extends ItemRenderer
quadDirections.add(null);
}
- private Minecraft mc;
+ private Minecraft minecraft;
private final ModelManager modelManager;
private final BlockEntityWithoutLevelRenderer blockEntityRenderer;
+ private float blitOffset = 100.0f;
public CustomItemRenderer(TextureManager textureManagerIn, ModelManager modelManagerIn, ItemColors itemColorsIn, BlockEntityWithoutLevelRenderer blockEntityRendererIn, Minecraft mcIn)
{
- super(textureManagerIn, modelManagerIn, itemColorsIn, blockEntityRendererIn);
- mc = mcIn;
+ super(mcIn, textureManagerIn, modelManagerIn, itemColorsIn, blockEntityRendererIn);
+ minecraft = mcIn;
modelManager = modelManagerIn;
blockEntityRenderer = blockEntityRendererIn;
- if (mc.getResourceManager() instanceof ReloadableResourceManager resourceManager)
+ if (minecraft.getResourceManager() instanceof ReloadableResourceManager resourceManager)
{
resourceManager.registerReloadListener(this);
}
@@ -130,7 +131,7 @@ public class CustomItemRenderer extends ItemRenderer
private void renderGuiModel(ItemStack itemStack, int x, int y, Quaternionf rotation, BakedModel bakedModel)
{
- mc.getTextureManager().getTexture(InventoryMenu.BLOCK_ATLAS).setFilter(false, false);
+ minecraft.getTextureManager().getTexture(InventoryMenu.BLOCK_ATLAS).setFilter(false, false);
RenderSystem.setShaderTexture(0, InventoryMenu.BLOCK_ATLAS);
RenderSystem.enableBlend();
RenderSystem.blendFunc(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA);
@@ -150,7 +151,7 @@ public class CustomItemRenderer extends ItemRenderer
if (flatLighting) { Lighting.setupForFlatItems(); }
PoseStack poseStack = new PoseStack();
- renderModel(itemStack, ItemTransforms.TransformType.GUI, false, poseStack, rotation, bufferSource, LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY, bakedModel);
+ renderModel(itemStack, ItemDisplayContext.GUI, false, poseStack, rotation, bufferSource, LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY, bakedModel);
poseStack.popPose();
bufferSource.endBatch();
@@ -171,7 +172,16 @@ public class CustomItemRenderer extends ItemRenderer
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
entityRenderDispatcher.setRenderShadow(false);
- RenderSystem.runAsFancy(() -> entityRenderDispatcher.render(entity, 0.0, 0.0, 0.0, 0.0f, 1.0f, poseStack, bufferSource, packedLight));
+ poseStack.pushPose();
+ poseStack.mulPose(Axis.YP.rotationDegrees(90.0f));
+
+ try
+ {
+ RenderSystem.runAsFancy(() -> entityRenderDispatcher.render(entity, 0.0, 0.0, 0.0, 0.0f, 1.0f, poseStack, bufferSource, packedLight));
+ }
+ catch (Exception e) {}
+
+ poseStack.popPose();
if (bufferSource instanceof BufferSource source)
{
@@ -184,7 +194,7 @@ public class CustomItemRenderer extends ItemRenderer
Lighting.setupFor3DItems();
}
- private <T extends MultiBufferSource> void renderModelInternal(ItemStack itemStack, ItemTransforms.TransformType transformType, boolean leftHanded, PoseStack poseStack,
+ private <T extends MultiBufferSource> void renderModelInternal(ItemStack itemStack, ItemDisplayContext displayContext, boolean leftHanded, PoseStack poseStack,
Quaternionf rotation, T bufferSource, int packedLight, int packedOverlay, BakedModel bakedModel,
Predicate<T> bufferSourceReady)
{
@@ -194,14 +204,17 @@ public class CustomItemRenderer extends ItemRenderer
{
if (updateArmorStand(itemStack))
{
+ poseStack.pushPose();
+ poseStack.mulPose(Axis.YP.rotationDegrees(-90.0f));
renderEntityModel(armorStand, poseStack, bufferSource, packedLight);
+ poseStack.popPose();
}
}
if (!bakedModel.isCustomRenderer() && !itemStack.is(Items.TRIDENT))
{
boolean fabulous;
- if (transformType != ItemTransforms.TransformType.GUI && !transformType.firstPerson() && itemStack.getItem() instanceof BlockItem blockItem)
+ if (displayContext != ItemDisplayContext.GUI && !displayContext.firstPerson() && itemStack.getItem() instanceof BlockItem blockItem)
{
Block block = blockItem.getBlock();
fabulous = !(block instanceof HalfTransparentBlock) && !(block instanceof StainedGlassPaneBlock);
@@ -224,7 +237,7 @@ public class CustomItemRenderer extends ItemRenderer
// First try rendering via the BlockEntityWithoutLevelRenderer.
try
{
- blockEntityRenderer.renderByItem(itemStack, transformType, poseStack, bufferSource, packedLight, packedOverlay);
+ blockEntityRenderer.renderByItem(itemStack, displayContext, poseStack, bufferSource, packedLight, packedOverlay);
}
catch (Exception e)
{
@@ -242,14 +255,14 @@ public class CustomItemRenderer extends ItemRenderer
// First render the bottom half.
BlockState bottomState = block.defaultBlockState().setValue(BlockStateProperties.DOUBLE_BLOCK_HALF, DoubleBlockHalf.LOWER);
BakedModel bottomModel = blockModelShaper.getBlockModel(bottomState);
- renderBakedModel(itemStack, transformType, poseStack, bufferSource, packedLight, packedOverlay, bottomModel, fabulous);
+ renderBakedModel(itemStack, displayContext, poseStack, bufferSource, packedLight, packedOverlay, bottomModel, fabulous);
// Then render the top half.
poseStack.pushPose();
poseStack.translate(0.0f, 1.0f, 0.0f);
BlockState topState = block.defaultBlockState().setValue(BlockStateProperties.DOUBLE_BLOCK_HALF, DoubleBlockHalf.UPPER);
BakedModel topModel = blockModelShaper.getBlockModel(topState);
- renderBakedModel(itemStack, transformType, poseStack, bufferSource, packedLight, packedOverlay, topModel, fabulous);
+ renderBakedModel(itemStack, displayContext, poseStack, bufferSource, packedLight, packedOverlay, topModel, fabulous);
poseStack.popPose();
}
@@ -269,14 +282,14 @@ public class CustomItemRenderer extends ItemRenderer
// If we still haven't rendered anything or this is a block entity, try rendering the block model.
if (blockModel != null && (bufferSourceReady.test(bufferSource) || isBlockEntity))
{
- renderBakedModel(itemStack, transformType, poseStack, bufferSource, packedLight, packedOverlay, blockModel, fabulous);
+ renderBakedModel(itemStack, displayContext, poseStack, bufferSource, packedLight, packedOverlay, blockModel, fabulous);
}
}
// Now try rendering entity models for items that spawn entities.
- if (bufferSourceReady.test(bufferSource) && EntityCollector.itemCreatesEntity(itemStack.getItem(), Entity.class))
+ if (bufferSourceReady.test(bufferSource) && EntityCollector.itemCreatesEntity(itemStack, Entity.class))
{
- if (updateEntity(itemStack.getItem()))
+ if (updateEntity(itemStack))
{
renderEntityModel(entity, poseStack, bufferSource, packedLight);
}
@@ -294,24 +307,24 @@ public class CustomItemRenderer extends ItemRenderer
// Finally, fall back to just rendering the item model.
if (bufferSourceReady.test(bufferSource))
{
- renderBakedModel(itemStack, transformType, poseStack, bufferSource, packedLight, packedOverlay, bakedModel, fabulous);
+ renderBakedModel(itemStack, displayContext, poseStack, bufferSource, packedLight, packedOverlay, bakedModel, fabulous);
}
}
else if (bufferSourceReady.test(bufferSource))
{
- blockEntityRenderer.renderByItem(itemStack, transformType, poseStack, bufferSource, packedLight, packedOverlay);
+ blockEntityRenderer.renderByItem(itemStack, displayContext, poseStack, bufferSource, packedLight, packedOverlay);
}
}
- private void renderModel(ItemStack itemStack, TransformType transformType, boolean leftHanded, PoseStack poseStack, Quaternionf rotation, MultiBufferSource bufferSource, int packedLight, int packedOverlay, BakedModel bakedModel)
+ private void renderModel(ItemStack itemStack, ItemDisplayContext displayContext, boolean leftHanded, PoseStack poseStack, Quaternionf rotation, MultiBufferSource bufferSource, int packedLight, int packedOverlay, BakedModel bakedModel)
{
if (!itemStack.isEmpty())
{
- // If this model doesn't have a special transform for the given transform type (most likely GUI), default to first-person right handed instead.
- TransformType previewTransform = transformType;
- if (!bakedModel.getTransforms().hasTransform(transformType))
+ // If this model doesn't have a special transform for the given context type (most likely GUI), default to ground instead.
+ ItemDisplayContext previewContext = displayContext;
+ if (!bakedModel.getTransforms().hasTransform(displayContext))
{
- previewTransform = TransformType.GROUND;
+ previewContext = ItemDisplayContext.GROUND;
}
boolean isBlockItem = false, spawnsEntity = false, isArmor = false;
@@ -319,7 +332,7 @@ public class CustomItemRenderer extends ItemRenderer
{
isBlockItem = true;
}
- else if (EntityCollector.itemCreatesEntity(itemStack.getItem(), Entity.class))
+ else if (EntityCollector.itemCreatesEntity(itemStack, Entity.class))
{
spawnsEntity = true;
}
@@ -340,12 +353,12 @@ public class CustomItemRenderer extends ItemRenderer
}
else
{
- bakedModel.getTransforms().getTransform(previewTransform).apply(leftHanded, poseStack);
+ bakedModel.getTransforms().getTransform(previewContext).apply(leftHanded, poseStack);
}
poseStack.translate(-0.5f, -0.5f, -0.5f);
// Get the model bounds.
- ModelBounds modelBounds = getModelBounds(itemStack, previewTransform, leftHanded, poseStack, rotation, bufferSource, packedLight, packedOverlay, bakedModel);
+ ModelBounds modelBounds = getModelBounds(itemStack, previewContext, leftHanded, poseStack, rotation, bufferSource, packedLight, packedOverlay, bakedModel);
// Undo the camera transforms now that we have the model bounds.
poseStack.popPose();
@@ -390,13 +403,13 @@ public class CustomItemRenderer extends ItemRenderer
}
else
{
- bakedModel.getTransforms().getTransform(previewTransform).apply(leftHanded, poseStack);
+ bakedModel.getTransforms().getTransform(previewContext).apply(leftHanded, poseStack);
}
poseStack.translate(-0.5f, -0.5f, -0.5f);
CheckedBufferSource checkedBufferSource = CheckedBufferSource.create(bufferSource);
- renderModelInternal(itemStack, previewTransform, leftHanded, poseStack, rotation, checkedBufferSource, packedLight, packedOverlay, bakedModel, b -> !b.hasRendered());
+ renderModelInternal(itemStack, previewContext, leftHanded, poseStack, rotation, checkedBufferSource, packedLight, packedOverlay, bakedModel, b -> !b.hasRendered());
poseStack.popPose();
}
@@ -422,7 +435,7 @@ public class CustomItemRenderer extends ItemRenderer
}
}
- private void renderBakedModel(ItemStack itemStack, ItemTransforms.TransformType transformType, PoseStack poseStack,
+ private void renderBakedModel(ItemStack itemStack, ItemDisplayContext displayContext, PoseStack poseStack,
MultiBufferSource bufferSource, int packedLight, int packedOverlay, BakedModel bakedModel, boolean fabulous)
{
RenderType renderType = ItemBlockRenderTypes.getRenderType(itemStack, fabulous);
@@ -431,11 +444,11 @@ public class CustomItemRenderer extends ItemRenderer
{
poseStack.pushPose();
PoseStack.Pose posestack$pose = poseStack.last();
- if (transformType == ItemTransforms.TransformType.GUI)
+ if (displayContext == ItemDisplayContext.GUI)
{
MatrixUtil.mulComponentWise(posestack$pose.pose(), 0.5F);
}
- else if (transformType.firstPerson())
+ else if (displayContext.firstPerson())
{
MatrixUtil.mulComponentWise(posestack$pose.pose(), 0.75F);
}
@@ -502,10 +515,10 @@ public class CustomItemRenderer extends ItemRenderer
return true;
}
- private Entity getEntityFromItem(Item item)
+ private Entity getEntityFromItem(ItemStack itemStack)
{
Entity collectedEntity = null;
- List<Entity> collectedEntities = EntityCollector.collectEntitiesFromItem(item);
+ List<Entity> collectedEntities = EntityCollector.collectEntitiesFromItem(itemStack);
if (!collectedEntities.isEmpty())
{
// Just return the first entity collected.
@@ -516,12 +529,13 @@ public class CustomItemRenderer extends ItemRenderer
return collectedEntity;
}
- private boolean updateEntity(Item item)
+ private boolean updateEntity(ItemStack itemStack)
{
- if (entity == null || cachedEntityItem != item)
+ Pair<Item, CompoundTag> entityItem = Pair.of(itemStack.getItem(), itemStack.getTag());
+ if (entity == null || cachedEntityItem != entityItem)
{
- entity = getEntityFromItem(item);
- cachedEntityItem = item;
+ entity = getEntityFromItem(itemStack);
+ cachedEntityItem = entityItem;
}
// If somehow the entity is still null, then we can't render anything.
@@ -594,19 +608,20 @@ public class CustomItemRenderer extends ItemRenderer
return new ModelBounds(center, height, radius);
}
- private ModelBounds getModelBounds(ItemStack itemStack, ItemTransforms.TransformType transformType, boolean leftHanded, PoseStack poseStack,
+ private ModelBounds getModelBounds(ItemStack itemStack, ItemDisplayContext displayContext, boolean leftHanded, PoseStack poseStack,
Quaternionf rotation, MultiBufferSource bufferSource, int packedLight, int packedOverlay, BakedModel bakedModel)
{
- if (!modelBoundsCache.containsKey(itemStack.getItem()))
+ Pair<Item, CompoundTag> key = Pair.of(itemStack.getItem(), itemStack.getTag());
+ if (!modelBoundsCache.containsKey(key))
{
VertexCollector vertexCollector = VertexCollector.create();
- renderModelInternal(itemStack, transformType, leftHanded, poseStack, rotation, vertexCollector, packedLight, packedOverlay, bakedModel, b -> b.getVertices().isEmpty());
+ renderModelInternal(itemStack, displayContext, leftHanded, poseStack, rotation, vertexCollector, packedLight, packedOverlay, bakedModel, b -> b.getVertices().isEmpty());
// Now store the bounds in the cache.
- modelBoundsCache.put(itemStack.getItem(), boundsFromVertices(vertexCollector.getVertices()));
+ modelBoundsCache.put(key, boundsFromVertices(vertexCollector.getVertices()));
}
- return modelBoundsCache.get(itemStack.getItem());
+ return modelBoundsCache.get(key);
}
public void renderDetailModelIntoGUI(ItemStack stack, int x, int y, Quaternionf rotation)
@@ -643,10 +658,10 @@ public class CustomItemRenderer extends ItemRenderer
blitOffset -= 50.0f;
}
- public void renderItemModelIntoGUIWithAlpha(ItemStack stack, int x, int y, float alpha)
+ public void renderItemModelIntoGUIWithAlpha(PoseStack poseStack, ItemStack stack, int x, int y, float alpha)
{
- BakedModel bakedModel = mc.getItemRenderer().getModel(stack, null, null, 0);
- RenderTarget lastFrameBuffer = mc.getMainRenderTarget();
+ BakedModel bakedModel = minecraft.getItemRenderer().getModel(stack, null, null, 0);
+ RenderTarget lastFrameBuffer = minecraft.getMainRenderTarget();
// Bind the icon framebuffer so we can render to texture.
iconFrameBuffer.clear(Minecraft.ON_OSX);
@@ -659,7 +674,7 @@ public class CustomItemRenderer extends ItemRenderer
RenderSystem.backupProjectionMatrix();
RenderSystem.setProjectionMatrix(matrix);
- mc.getTextureManager().getTexture(InventoryMenu.BLOCK_ATLAS).setFilter(false, false);
+ minecraft.getTextureManager().getTexture(InventoryMenu.BLOCK_ATLAS).setFilter(false, false);
RenderSystem.setShaderTexture(0, InventoryMenu.BLOCK_ATLAS);
RenderSystem.disableCull();
RenderSystem.enableBlend();
@@ -672,8 +687,8 @@ public class CustomItemRenderer extends ItemRenderer
modelViewStack.translate(48.0f, 48.0f, -2000.0f);
modelViewStack.scale(96.0f, 96.0f, 96.0f);
RenderSystem.applyModelViewMatrix();
- PoseStack poseStack = new PoseStack();
- BufferSource bufferSource = mc.renderBuffers().bufferSource();
+
+ BufferSource bufferSource = minecraft.renderBuffers().bufferSource();
boolean flatLighting = !bakedModel.usesBlockLight();
if (flatLighting)
@@ -681,7 +696,7 @@ public class CustomItemRenderer extends ItemRenderer
Lighting.setupForFlatItems();
}
- render(stack, ItemTransforms.TransformType.GUI, false, poseStack, bufferSource, LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY, bakedModel);
+ render(stack, ItemDisplayContext.GUI, false, new PoseStack(), bufferSource, LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY, bakedModel);
bufferSource.endBatch();
RenderSystem.enableDepthTest();
if (flatLighting)
@@ -703,15 +718,12 @@ public class CustomItemRenderer extends ItemRenderer
RenderSystem.defaultBlendFunc();
RenderSystem.disableCull();
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, alpha);
- modelViewStack.pushPose();
- modelViewStack.translate(0.0f, 0.0f, 50.0f + this.blitOffset);
- RenderSystem.applyModelViewMatrix();
RenderSystem.setShaderTexture(0, iconFrameBuffer.getColorTextureId());
+ GuiComponent.blit(poseStack, x, y, 16, 16, 0, 0, iconFrameBuffer.width, iconFrameBuffer.height, iconFrameBuffer.width, iconFrameBuffer.height);
+
+ RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
- GuiComponent.blit(new PoseStack(), x, y, 16, 16, 0, 0, iconFrameBuffer.width, iconFrameBuffer.height, iconFrameBuffer.width, iconFrameBuffer.height);
- modelViewStack.popPose();
- RenderSystem.applyModelViewMatrix();
iconFrameBuffer.unbindRead();
}
else
diff --git a/src/main/java/com/anthonyhilyard/iceberg/renderer/VertexCollector.java b/src/main/java/com/anthonyhilyard/iceberg/renderer/VertexCollector.java
index ba9d799..22b98e1 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/renderer/VertexCollector.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/renderer/VertexCollector.java
@@ -35,7 +35,7 @@ public class VertexCollector implements MultiBufferSource
try
{
// If Sodium 0.4.9+ is installed, use the Sodium implementation.
- useSodiumVersion = FabricLoader.getInstance().isModLoaded("sodium") && VersionPredicateParser.parse(">=0.4.9").test(FabricLoader.getInstance().getModContainer("sodium").get().getMetadata().getVersion());
+ useSodiumVersion = FabricLoader.getInstance().isModLoaded("sodium") && VersionPredicateParser.parse("0.4.10").test(FabricLoader.getInstance().getModContainer("sodium").get().getMetadata().getVersion());
}
catch (Exception e)
{
diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/EntityCollector.java b/src/main/java/com/anthonyhilyard/iceberg/util/EntityCollector.java
index 1524a88..6e3b079 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/util/EntityCollector.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/util/EntityCollector.java
@@ -2,6 +2,7 @@ package com.anthonyhilyard.iceberg.util;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.UUID;
import java.util.function.Consumer;
@@ -18,16 +19,22 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.AbortableIterationConsumer;
+import net.minecraft.world.Difficulty;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity;
+import net.minecraft.world.entity.decoration.Painting;
+import net.minecraft.world.entity.decoration.PaintingVariant;
import net.minecraft.world.entity.player.Player;
+import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SpawnEggItem;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.item.crafting.RecipeManager;
+import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.Level;
+import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
@@ -39,6 +46,7 @@ import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.level.gameevent.GameEvent.Context;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
+import net.minecraft.world.level.storage.WritableLevelData;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
@@ -54,11 +62,29 @@ public class EntityCollector extends Level
private static final Map<Level, EntityCollector> wrappedLevelsMap = Maps.newHashMap();
private static final Map<ItemClassPair, Boolean> itemCreatesEntityResultCache = Maps.newHashMap();
- private record ItemClassPair(Item item, Class<?> targetClass) {}
+ private record ItemClassPair(Item item, CompoundTag tag, Class<?> targetClass) {}
protected EntityCollector(Level wrapped)
{
- super(null, null, wrapped.dimensionTypeRegistration(), wrapped.getProfilerSupplier(), false, wrapped.isDebug(), 0, 0);
+ super(new WritableLevelData() {
+ @Override public int getXSpawn() { return 0; }
+ @Override public int getYSpawn() { return 0; }
+ @Override public int getZSpawn() { return 0; }
+ @Override public float getSpawnAngle() { return 0.0f; }
+ @Override public long getGameTime() { return 0; }
+ @Override public long getDayTime() { return 0; }
+ @Override public boolean isThundering() { return false; }
+ @Override public boolean isRaining() { return false; }
+ @Override public void setRaining(boolean isRaining) {}
+ @Override public boolean isHardcore() { return false; }
+ @Override public GameRules getGameRules() { return new GameRules(); }
+ @Override public Difficulty getDifficulty() { return Difficulty.EASY; }
+ @Override public boolean isDifficultyLocked() { return false; }
+ @Override public void setXSpawn(int x) {}
+ @Override public void setYSpawn(int p_78652_) {}
+ @Override public void setZSpawn(int p_78653_) {}
+ @Override public void setSpawnAngle(float p_78648_) {}
+ }, null, wrapped.registryAccess(), wrapped.dimensionTypeRegistration(), wrapped.getProfilerSupplier(), false, wrapped.isDebug(), 0, 0);
wrappedLevel = wrapped;
}
@@ -72,10 +98,13 @@ public class EntityCollector extends Level
return wrappedLevelsMap.get(wrappedLevel);
}
- public static List<Entity> collectEntitiesFromItem(Item item)
+ public static List<Entity> collectEntitiesFromItem(ItemStack itemStack)
{
Minecraft minecraft = Minecraft.getInstance();
List<Entity> entities = Lists.newArrayList();
+ Item item = itemStack.getItem();
+ ItemStack dummyStack = new ItemStack(item, itemStack.getCount());
+ dummyStack.setTag(itemStack.getTag());
try
{
@@ -84,7 +113,7 @@ public class EntityCollector extends Level
@Override public boolean isCreative() { return false; }
};
- dummyPlayer.setItemInHand(InteractionHand.MAIN_HAND, new ItemStack(item));
+ dummyPlayer.setItemInHand(InteractionHand.MAIN_HAND, dummyStack);
EntityCollector levelWrapper = EntityCollector.of(dummyPlayer.level);
@@ -94,7 +123,7 @@ public class EntityCollector extends Level
}
else
{
- item.use(levelWrapper, dummyPlayer, InteractionHand.MAIN_HAND);
+ dummyStack.use(levelWrapper, dummyPlayer, InteractionHand.MAIN_HAND);
}
entities.addAll(levelWrapper.getCollectedEntities());
@@ -103,11 +132,51 @@ public class EntityCollector extends Level
if (entities.isEmpty())
{
levelWrapper.setBlockState(Blocks.RAIL.defaultBlockState());
- item.useOn(new UseOnContext(levelWrapper, dummyPlayer, InteractionHand.MAIN_HAND, dummyPlayer.getItemInHand(InteractionHand.MAIN_HAND), new BlockHitResult(Vec3.ZERO, Direction.DOWN, BlockPos.ZERO, false)));
+ dummyStack.useOn(new UseOnContext(levelWrapper, dummyPlayer, InteractionHand.MAIN_HAND, dummyPlayer.getItemInHand(InteractionHand.MAIN_HAND), new BlockHitResult(Vec3.ZERO, Direction.DOWN, BlockPos.ZERO, false)));
levelWrapper.setBlockState(Blocks.AIR.defaultBlockState());
entities.addAll(levelWrapper.getCollectedEntities());
}
+
+ // If we still didn't spawn any entities, try again but this time simulate placing on a solid wall for painting-like items.
+ if (entities.isEmpty())
+ {
+ levelWrapper.setBlockState(Blocks.STONE.defaultBlockState());
+ dummyStack.useOn(new UseOnContext(levelWrapper, dummyPlayer, InteractionHand.MAIN_HAND, dummyPlayer.getItemInHand(InteractionHand.MAIN_HAND), new BlockHitResult(Vec3.ZERO, Direction.NORTH, BlockPos.ZERO, false)));
+ levelWrapper.setBlockState(Blocks.AIR.defaultBlockState());
+
+ entities.addAll(levelWrapper.getCollectedEntities());
+
+ CompoundTag itemTag = dummyStack.getTag();
+ if (itemTag != null && itemTag.contains("EntityTag", 10))
+ {
+ CompoundTag entityTag = itemTag.getCompound("EntityTag");
+
+ Optional<Holder<PaintingVariant>> loadedVariant = Painting.loadVariant(entityTag);
+ if (loadedVariant.isPresent())
+ {
+ // Entities collected here should be updated in case the item used a specific variant.
+ for (Entity entity : entities)
+ {
+ if (entity instanceof Painting paintingEntity)
+ {
+ paintingEntity.setVariant(loadedVariant.get());
+ }
+ }
+ }
+ else
+ {
+ entities.clear();
+ }
+ }
+ else
+ {
+ entities.clear();
+ }
+ }
+
+ // Now iterate through all the collected entities and remove any projectiles to prevent some crashes with modded bobbers, etc.
+ entities.removeIf(entity -> entity instanceof Projectile);
}
catch (Exception e)
{
@@ -117,14 +186,14 @@ public class EntityCollector extends Level
return entities;
}
- public static <T extends Entity> boolean itemCreatesEntity(Item item, Class<T> targetClass)
+ public static <T extends Entity> boolean itemCreatesEntity(ItemStack itemStack, Class<T> targetClass)
{
- ItemClassPair key = new ItemClassPair(item, targetClass);
+ ItemClassPair key = new ItemClassPair(itemStack.getItem(), itemStack.getTag(), targetClass);
boolean result = false;
if (!itemCreatesEntityResultCache.containsKey(key))
{
// Return true if any collected entities from this item are a subclass of the given type.
- for (Entity entity : collectEntitiesFromItem(item))
+ for (Entity entity : collectEntitiesFromItem(itemStack))
{
if (targetClass.isInstance(entity))
{
@@ -160,6 +229,12 @@ public class EntityCollector extends Level
}
@Override
+ public int getBrightness(LightLayer lightLayer, BlockPos blockPos)
+ {
+ return 15;
+ }
+
+ @Override
public boolean noCollision(Entity entity, AABB boundingBox)
{
return true;
@@ -168,6 +243,7 @@ public class EntityCollector extends Level
@Override
public boolean addFreshEntity(Entity entity)
{
+ entity.setYRot(180.0f);
collectedEntities.add(entity);
return false;
}
diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/GuiHelper.java b/src/main/java/com/anthonyhilyard/iceberg/util/GuiHelper.java
index 54cf422..eb91073 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/util/GuiHelper.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/util/GuiHelper.java
@@ -17,7 +17,6 @@ public class GuiHelper
public static void drawGradientRect(Matrix4f mat, int zLevel, int left, int top, int right, int bottom, int startColor, int endColor)
{
RenderSystem.enableDepthTest();
- RenderSystem.disableTexture();
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.setShader(GameRenderer::getPositionColorShader);
@@ -29,7 +28,6 @@ public class GuiHelper
BufferUploader.drawWithShader(bufferBuilder.end());
RenderSystem.disableBlend();
- RenderSystem.enableTexture();
}
public static void drawGradientRect(Matrix4f mat, BufferBuilder bufferBuilder, int left, int top, int right, int bottom, int zLevel, int startColor, int endColor)
@@ -61,7 +59,6 @@ public class GuiHelper
float endBlue = (float)(endColor & 255) / 255.0F;
RenderSystem.enableDepthTest();
- RenderSystem.disableTexture();
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.setShader(GameRenderer::getPositionColorShader);
@@ -76,6 +73,5 @@ public class GuiHelper
tessellator.end();
RenderSystem.disableBlend();
- RenderSystem.enableTexture();
}
}
diff --git a/src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java b/src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java
index 48184b9..29cc39b 100644
--- a/src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java
+++ b/src/main/java/com/anthonyhilyard/iceberg/util/Tooltips.java
@@ -222,8 +222,6 @@ public class Tooltips
poseStack.pushPose();
final int zLevel = 400;
- float f = itemRenderer.blitOffset;
- itemRenderer.blitOffset = zLevel;
Tesselator tesselator = Tesselator.getInstance();
BufferBuilder bufferbuilder = tesselator.getBuilder();
@@ -245,12 +243,9 @@ public class Tooltips
}, matrix4f, bufferbuilder, rectX, rectY, rect.getWidth(), rect.getHeight(), zLevel);
RenderSystem.enableDepthTest();
- RenderSystem.disableTexture();
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
BufferUploader.drawWithShader(bufferbuilder.end());
- RenderSystem.disableBlend();
- RenderSystem.enableTexture();
BufferSource bufferSource = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());
poseStack.translate(0.0f, 0.0f, zLevel);
@@ -273,17 +268,16 @@ public class Tooltips
}
bufferSource.endBatch();
- poseStack.popPose();
tooltipTop = rectY;
for (int componentNumber = 0; componentNumber < info.getComponents().size(); ++componentNumber)
{
ClientTooltipComponent imageComponent = (ClientTooltipComponent)info.getComponents().get(componentNumber);
- imageComponent.renderImage(info.getFont(), rectX, tooltipTop, poseStack, itemRenderer, zLevel);
+ imageComponent.renderImage(info.getFont(), rectX, tooltipTop, poseStack, itemRenderer);
tooltipTop += imageComponent.getHeight() + (componentNumber == 0 ? 2 : 0);
}
- itemRenderer.blitOffset = f;
+ poseStack.popPose();
RenderTooltipEvents.POSTEXT.invoker().onPost(stack, info.getComponents(), poseStack, rectX, rectY, info.getFont(), rect.getWidth(), rect.getHeight(), comparison, index);
}
@@ -489,9 +483,9 @@ public class Tooltips
// Find the title component, which is the first text component.
int titleIndex = 0;
- for (ClientTooltipComponent clienttooltipcomponent : components)
+ for (ClientTooltipComponent clientTooltipComponent : components)
{
- if (clienttooltipcomponent instanceof ClientTextTooltip)
+ if (clientTooltipComponent instanceof ClientTextTooltip)
{
break;
}
diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json
index f88b402..8f4e5a0 100644
--- a/src/main/resources/fabric.mod.json
+++ b/src/main/resources/fabric.mod.json
@@ -28,13 +28,13 @@
],
"depends": {
- "fabricloader": ">=0.12.8",
+ "fabricloader": ">=0.14.14",
"fabric": "*",
- "minecraft": "1.19.3",
+ "minecraft": "1.19.4",
"java": ">=17"
},
"suggests": {
- "sodium": "<=0.4.9"
+ "sodium": "0.4.10"
},
"custom": {
"modupdater": {
diff --git a/src/main/resources/iceberg.accesswidener b/src/main/resources/iceberg.accesswidener
index 2c544b7..3413404 100644
--- a/src/main/resources/iceberg.accesswidener
+++ b/src/main/resources/iceberg.accesswidener
@@ -5,6 +5,4 @@ accessible field net/minecraft/client/gui/screens/inventory/tooltip/Toolti
accessible field net/minecraft/client/gui/screens/inventory/tooltip/TooltipRenderUtil BORDER_COLOR_TOP I
accessible field net/minecraft/client/gui/screens/inventory/tooltip/TooltipRenderUtil BORDER_COLOR_BOTTOM I
accessible field net/minecraft/world/item/MinecartItem type Lnet/minecraft/world/entity/vehicle/AbstractMinecart$Type;
-accessible field net/minecraft/world/item/BoatItem type Lnet/minecraft/world/entity/vehicle/Boat$Type;
-accessible field net/minecraft/world/item/BoatItem hasChest Z
accessible method net/minecraft/client/renderer/entity/ItemRenderer renderModelLists (Lnet/minecraft/client/resources/model/BakedModel;Lnet/minecraft/world/item/ItemStack;IILcom/mojang/blaze3d/vertex/PoseStack;Lcom/mojang/blaze3d/vertex/VertexConsumer;)V \ No newline at end of file