Search in sources :

Example 1 with MapItem

use of net.minecraft.world.item.MapItem in project SpongeCommon by SpongePowered.

the class MapInfoItemStackData method register.

// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
    registrator.asMutable(ItemStack.class).create(Keys.MAP_INFO).supports(item -> item.getItem() instanceof MapItem).get(itemStack -> {
        if (itemStack.getTag() == null) {
            return null;
        }
        return (MapInfo) ((Level) Sponge.server().worldManager().defaultWorld()).getMapData(Constants.Map.MAP_PREFIX + itemStack.getTag().getInt(Constants.Map.MAP_ID));
    }).set((itemStack, mapInfo) -> {
        @Nullable CompoundTag nbt = itemStack.getTag();
        if (nbt == null) {
            nbt = new CompoundTag();
        }
        nbt.putInt(Constants.Map.MAP_ID, ((MapItemSavedDataBridge) mapInfo).bridge$getMapId());
        itemStack.setTag(nbt);
    });
}
Also used : Keys(org.spongepowered.api.data.Keys) CompoundTag(net.minecraft.nbt.CompoundTag) MapInfo(org.spongepowered.api.map.MapInfo) Constants(org.spongepowered.common.util.Constants) DataProviderRegistrator(org.spongepowered.common.data.provider.DataProviderRegistrator) MapItem(net.minecraft.world.item.MapItem) Sponge(org.spongepowered.api.Sponge) ItemStack(net.minecraft.world.item.ItemStack) MapItemSavedDataBridge(org.spongepowered.common.bridge.world.storage.MapItemSavedDataBridge) Level(net.minecraft.world.level.Level) Nullable(org.checkerframework.checker.nullness.qual.Nullable) Level(net.minecraft.world.level.Level) MapItem(net.minecraft.world.item.MapItem) Nullable(org.checkerframework.checker.nullness.qual.Nullable) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 2 with MapItem

use of net.minecraft.world.item.MapItem in project Tropicraft by Tropicraft.

the class BambooItemFrameRenderer method render.

@Override
public void render(BambooItemFrame entityIn, float entityYaw, float partialTicks, PoseStack matrixStackIn, MultiBufferSource bufferIn, int packedLightIn) {
    super.render(entityIn, entityYaw, partialTicks, matrixStackIn, bufferIn, packedLightIn);
    matrixStackIn.pushPose();
    Direction direction = entityIn.getDirection();
    Vec3 Vector3d = this.getRenderOffset(entityIn, partialTicks);
    matrixStackIn.translate(-Vector3d.x, -Vector3d.y, -Vector3d.z);
    double d0 = 0.46875D;
    matrixStackIn.translate((double) direction.getStepX() * 0.46875D, (double) direction.getStepY() * 0.46875D, (double) direction.getStepZ() * 0.46875D);
    matrixStackIn.mulPose(Vector3f.XP.rotationDegrees(entityIn.getXRot()));
    matrixStackIn.mulPose(Vector3f.YP.rotationDegrees(180.0F - entityIn.getYRot()));
    BlockRenderDispatcher blockrendererdispatcher = this.mc.getBlockRenderer();
    ModelManager modelmanager = blockrendererdispatcher.getBlockModelShaper().getModelManager();
    ModelResourceLocation modelresourcelocation = entityIn.getItem().getItem() instanceof MapItem ? LOCATION_MODEL_MAP : LOCATION_MODEL;
    matrixStackIn.pushPose();
    matrixStackIn.translate(-0.5D, -0.5D, -0.5D);
    blockrendererdispatcher.getModelRenderer().renderModel(matrixStackIn.last(), bufferIn.getBuffer(Sheets.solidBlockSheet()), null, modelmanager.getModel(modelresourcelocation), 1.0F, 1.0F, 1.0F, packedLightIn, OverlayTexture.NO_OVERLAY);
    matrixStackIn.popPose();
    ItemStack itemstack = entityIn.getItem();
    if (!itemstack.isEmpty()) {
        MapItemSavedData mapdata = MapItem.getSavedData(itemstack, entityIn.level);
        matrixStackIn.translate(0.0D, 0.0D, 0.4375D);
        int i = mapdata != null ? entityIn.getRotation() % 4 * 2 : entityIn.getRotation();
        matrixStackIn.mulPose(Vector3f.ZP.rotationDegrees((float) i * 360.0F / 8.0F));
        if (mapdata != null) {
            matrixStackIn.mulPose(Vector3f.ZP.rotationDegrees(180.0F));
            float f = 0.0078125F;
            matrixStackIn.scale(0.0078125F, 0.0078125F, 0.0078125F);
            matrixStackIn.translate(-64.0D, -64.0D, 0.0D);
            matrixStackIn.translate(0.0D, 0.0D, -1.0D);
            Integer id = MapItem.getMapId(itemstack);
            if (mapdata != null && id != null) {
                this.mc.gameRenderer.getMapRenderer().render(matrixStackIn, bufferIn, id, mapdata, true, packedLightIn);
            }
        } else {
            matrixStackIn.scale(0.5F, 0.5F, 0.5F);
            this.itemRenderer.renderStatic(itemstack, ItemTransforms.TransformType.FIXED, packedLightIn, OverlayTexture.NO_OVERLAY, matrixStackIn, bufferIn, entityIn.getId());
        }
    }
    matrixStackIn.popPose();
}
Also used : MapItemSavedData(net.minecraft.world.level.saveddata.maps.MapItemSavedData) BlockRenderDispatcher(net.minecraft.client.renderer.block.BlockRenderDispatcher) Vec3(net.minecraft.world.phys.Vec3) ModelResourceLocation(net.minecraft.client.resources.model.ModelResourceLocation) ModelManager(net.minecraft.client.resources.model.ModelManager) MapItem(net.minecraft.world.item.MapItem) ItemStack(net.minecraft.world.item.ItemStack) Direction(net.minecraft.core.Direction)

Aggregations

ItemStack (net.minecraft.world.item.ItemStack)2 MapItem (net.minecraft.world.item.MapItem)2 BlockRenderDispatcher (net.minecraft.client.renderer.block.BlockRenderDispatcher)1 ModelManager (net.minecraft.client.resources.model.ModelManager)1 ModelResourceLocation (net.minecraft.client.resources.model.ModelResourceLocation)1 Direction (net.minecraft.core.Direction)1 CompoundTag (net.minecraft.nbt.CompoundTag)1 Level (net.minecraft.world.level.Level)1 MapItemSavedData (net.minecraft.world.level.saveddata.maps.MapItemSavedData)1 Vec3 (net.minecraft.world.phys.Vec3)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1 Sponge (org.spongepowered.api.Sponge)1 Keys (org.spongepowered.api.data.Keys)1 MapInfo (org.spongepowered.api.map.MapInfo)1 MapItemSavedDataBridge (org.spongepowered.common.bridge.world.storage.MapItemSavedDataBridge)1 DataProviderRegistrator (org.spongepowered.common.data.provider.DataProviderRegistrator)1 Constants (org.spongepowered.common.util.Constants)1