Skip to content

Commit

Permalink
🚧 Update to Blockbench 4.12.0
Browse files Browse the repository at this point in the history
- Removed internal transparent texture.
- Replaced all references to `Group.selected` with `Group.first_selected`.
  • Loading branch information
SnaveSutit committed Jan 10, 2025
1 parent 4482a54 commit 26a5af7
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 143 deletions.
1 change: 0 additions & 1 deletion src/blockbenchTypeMods.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ declare global {
isDataPackPath: typeof isDataPackPath
blueprintSettingErrors: typeof blueprintSettingErrors
openUnexpectedErrorDialog: typeof openUnexpectedErrorDialog
TRANSPARENT_TEXTURE: Texture
BLUEPRINT_FORMAT: typeof BLUEPRINT_FORMAT
BLUEPRINT_CODEC: typeof BLUEPRINT_CODEC
TextDisplay: typeof TextDisplay
Expand Down
7 changes: 2 additions & 5 deletions src/blueprintFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { injectSvelteCompomponent } from './util/injectSvelteComponent'
import { toSafeFuntionName } from './util/minecraftUtil'
import { addProjectToRecentProjects } from './util/misc'
import { Valuable } from './util/stores'
import { TRANSPARENT_TEXTURE, TRANSPARENT_TEXTURE_MATERIAL, Variant } from './variants'
import { Variant } from './variants'
import FormatPageSvelte from './components/formatPage.svelte'
import { translate } from './util/translation'
import { process } from './systems/modelDataFixerUpper'
Expand Down Expand Up @@ -577,9 +577,6 @@ export const BLUEPRINT_FORMAT = new Blockbench.ModelFormat({
events.UNLOAD.subscribe(() => clearInterval(updateBoundingBoxIntervalId), true)
events.UNINSTALL.subscribe(() => clearInterval(updateBoundingBoxIntervalId), true)

thisProject.materials[TRANSPARENT_TEXTURE.uuid] = TRANSPARENT_TEXTURE_MATERIAL
TRANSPARENT_TEXTURE.updateMaterial()

Project.loadingPromises ??= []
Project.loadingPromises.push(
new Promise<void>(resolve => {
Expand Down Expand Up @@ -669,7 +666,7 @@ export function saveBlueprint() {
export function updateRotationLock() {
if (!isCurrentFormat()) return
BLUEPRINT_FORMAT.rotation_limit = !(
!!Group.selected ||
!!Group.first_selected ||
!!AnimatedJava.API.TextDisplay.selected.length ||
!!AnimatedJava.API.VanillaItemDisplay.selected.length ||
!!AnimatedJava.API.VanillaBlockDisplay.selected.length ||
Expand Down
4 changes: 2 additions & 2 deletions src/components/variantConfigDialog.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts" context="module">
import { type Valuable } from '../util/stores'
import { translate } from '../util/translation'
import { TRANSPARENT_TEXTURE, TextureMap, Variant } from '../variants'
import { TextureMap, Variant } from '../variants'
import Checkbox from './dialogItems/checkbox.svelte'
import LineInput from './dialogItems/lineInput.svelte'
import MissingTexture from '../assets/missing_texture.png'
Expand All @@ -19,7 +19,7 @@
export let generateNameFromDisplayName: Valuable<boolean>
export let excludedNodes: Valuable<Array<CollectionItem>>
const availableTextures = [...Texture.all, TRANSPARENT_TEXTURE]
const availableTextures = [...Texture.all]
const primaryTextures = [...Texture.all]
const secondaryTextures = availableTextures
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import './systems/minecraft/blockstateManager'
import './systems/minecraft/assetManager'
import './systems/minecraft/fontManager'
// Misc imports
import { TRANSPARENT_TEXTURE, Variant } from './variants'
import { Variant } from './variants'
import './systems/minecraft/registryManager'
import { MINECRAFT_REGISTRY } from './systems/minecraft/registryManager'
import resourcepackCompiler from './systems/resourcepackCompiler'
Expand Down Expand Up @@ -58,7 +58,6 @@ globalThis.AnimatedJava = {
isDataPackPath,
blueprintSettingErrors,
openUnexpectedErrorDialog,
TRANSPARENT_TEXTURE,
BLUEPRINT_FORMAT,
BLUEPRINT_CODEC,
TextDisplay,
Expand Down
3 changes: 2 additions & 1 deletion src/interface/boneConfigDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export const BONE_CONFIG_ACTION = createAction(`${PACKAGE.name}:bone_config`, {
name: translate('action.open_bone_config.name'),
condition: () => Format === BLUEPRINT_FORMAT,
click: () => {
openBoneConfigDialog(Group.selected)
if (!Group.first_selected) return
openBoneConfigDialog(Group.first_selected)
},
})
6 changes: 3 additions & 3 deletions src/outliner/textDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ export class TextDisplay extends ResizableOutlinerElement {
}

select() {
if (Group.selected) {
Group.selected.unselect()
if (Group.first_selected) {
Group.first_selected.unselect()
}

if (!Pressing.ctrl && !Pressing.shift) {
Expand Down Expand Up @@ -551,7 +551,7 @@ export const CREATE_ACTION = createAction(`${PACKAGE.name}:create_text_display`,
}

selected.forEachReverse(el => el.unselect())
Group.selected && Group.selected.unselect()
Group.first_selected && Group.first_selected.unselect()
textDisplay.select()

Undo.finishEdit('Create Text Display', {
Expand Down
6 changes: 3 additions & 3 deletions src/outliner/vanillaBlockDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ export class VanillaBlockDisplay extends ResizableOutlinerElement {
}

select() {
if (Group.selected) {
Group.selected.unselect()
if (Group.first_selected) {
Group.first_selected.unselect()
}
if (!Pressing.ctrl && !Pressing.shift) {
if (Cube.selected.length) {
Expand Down Expand Up @@ -428,7 +428,7 @@ export const CREATE_ACTION = createAction(`${PACKAGE.name}:create_vanilla_block_
}

selected.forEachReverse(el => el.unselect())
Group.selected && Group.selected.unselect()
Group.first_selected && Group.first_selected.unselect()
vanillaBlockDisplay.select()

Undo.finishEdit('Create Vanilla Block Display', {
Expand Down
6 changes: 3 additions & 3 deletions src/outliner/vanillaItemDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ export class VanillaItemDisplay extends ResizableOutlinerElement {
}

select() {
if (Group.selected) {
Group.selected.unselect()
if (Group.first_selected) {
Group.first_selected.unselect()
}
if (!Pressing.ctrl && !Pressing.shift) {
if (Cube.selected.length) {
Expand Down Expand Up @@ -428,7 +428,7 @@ export const CREATE_ACTION = createAction(`${PACKAGE.name}:create_vanilla_item_d
}

selected.forEachReverse(el => el.unselect())
Group.selected && Group.selected.unselect()
Group.first_selected && Group.first_selected.unselect()
vanillaItemDisplay.select()

Undo.finishEdit('Create Vanilla Item Display', {
Expand Down
11 changes: 0 additions & 11 deletions src/systems/resourcepackCompiler/1.21.1.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { MAX_PROGRESS, PROGRESS, PROGRESS_DESCRIPTION } from '../../interface/exportProgressDialog'
import { isResourcePackPath, toSafeFuntionName } from '../../util/minecraftUtil'
import { TRANSPARENT_TEXTURE } from '../../variants'
import { IntentionalExportError } from '../exporter'
import { ITextureAtlas } from '../minecraft/textureAtlas'
import { IRenderedNodes, IRenderedRig } from '../rigRenderer'
Expand Down Expand Up @@ -268,16 +267,6 @@ export default async function compileResourcePack(options: {
}
exportedFiles.set(blockAtlasFile, autoStringify(blockAtlas))

// Transparent texture
const transparentTexturePath = PathModule.join(
resourcePackFolder,
'assets/animated_java/textures/blueprint/transparent.png'
)
exportedFiles.set(
transparentTexturePath,
nativeImage.createFromDataURL(TRANSPARENT_TEXTURE.source).toPNG()
)

// Variant Models
for (const variant of Object.values(rig.variants)) {
for (const [boneUuid, variantModel] of Object.entries(variant.models)) {
Expand Down
11 changes: 0 additions & 11 deletions src/systems/resourcepackCompiler/1.21.2.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { MAX_PROGRESS, PROGRESS, PROGRESS_DESCRIPTION } from '../../interface/exportProgressDialog'
import { isResourcePackPath, toSafeFuntionName } from '../../util/minecraftUtil'
import { TRANSPARENT_TEXTURE } from '../../variants'
import { IntentionalExportError } from '../exporter'
import { type ITextureAtlas } from '../minecraft/textureAtlas'
import { IRenderedNodes, IRenderedRig } from '../rigRenderer'
Expand Down Expand Up @@ -131,16 +130,6 @@ export default async function compileResourcePack(options: {
)
}

// Transparent texture
const transparentTexturePath = PathModule.join(
resourcePackFolder,
'assets/animated_java/textures/blueprint/transparent.png'
)
exportedFiles.set(
transparentTexturePath,
nativeImage.createFromDataURL(TRANSPARENT_TEXTURE.source).toPNG()
)

// Variant Models
for (const variant of Object.values(rig.variants)) {
for (const [boneUuid, variantModel] of Object.entries(variant.models)) {
Expand Down
12 changes: 1 addition & 11 deletions src/systems/resourcepackCompiler/1.21.4.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MAX_PROGRESS, PROGRESS, PROGRESS_DESCRIPTION } from '../../interface/exportProgressDialog'
import { isResourcePackPath, toSafeFuntionName } from '../../util/minecraftUtil'
import { TRANSPARENT_TEXTURE, Variant } from '../../variants'
import { Variant } from '../../variants'
import { IntentionalExportError } from '../exporter'
import { IItemDefinition } from '../minecraft/itemDefinitions'
import { type ITextureAtlas } from '../minecraft/textureAtlas'
Expand Down Expand Up @@ -119,16 +119,6 @@ export default async function compileResourcePack(options: {
)
}

// Transparent texture
const transparentTexturePath = PathModule.join(
resourcePackFolder,
'assets/animated_java/textures/blueprint/transparent.png'
)
exportedFiles.set(
transparentTexturePath,
nativeImage.createFromDataURL(TRANSPARENT_TEXTURE.source).toPNG()
)

// Item Model Definitions
const defaultVariant = Variant.getDefault()

Expand Down
24 changes: 7 additions & 17 deletions src/systems/rigRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
parseResourcePackPath,
toSafeFuntionName,
} from '../util/minecraftUtil'
import { TRANSPARENT_TEXTURE, TRANSPARENT_TEXTURE_RESOURCE_LOCATION, Variant } from '../variants'
import { Variant } from '../variants'
import {
correctSceneAngle,
getFrame,
Expand Down Expand Up @@ -240,8 +240,7 @@ function renderCube(cube: Cube, rig: IRenderedRig, model: IRenderedModel) {

element.faces = {}
for (const [face, data] of Object.entries(cube.faces)) {
if (!data) continue
if (!data.texture || data.getTexture()?.uuid === TRANSPARENT_TEXTURE.uuid) continue
if (!data?.texture) continue
const renderedFace = {} as IRenderedFace
if (data.enabled) {
renderedFace.uv = data.uv
Expand Down Expand Up @@ -570,20 +569,11 @@ function renderVariantModels(variant: Variant, rig: IRenderedRig) {
for (const [fromUUID, toUUID] of variant.textureMap.map.entries()) {
const fromTexture = Texture.all.find(t => t.uuid === fromUUID)
if (!fromTexture) throw new Error(`From texture not found: ${fromUUID}`)
if (toUUID === TRANSPARENT_TEXTURE.uuid) {
textures[fromTexture.id] = TRANSPARENT_TEXTURE_RESOURCE_LOCATION
rig.textures[TRANSPARENT_TEXTURE.id] = TRANSPARENT_TEXTURE
unreplacedTextures.delete(fromTexture.id)
} else {
const toTexture = Texture.all.find(t => t.uuid === toUUID)
if (!toTexture) throw new Error(`To texture not found: ${toUUID}`)
textures[fromTexture.id] = getTextureResourceLocation(
toTexture,
rig
).resourceLocation
rig.textures[toTexture.id] = toTexture
isOnlyTransparent = false
}
const toTexture = Texture.all.find(t => t.uuid === toUUID)
if (!toTexture) throw new Error(`To texture not found: ${toUUID}`)
textures[fromTexture.id] = getTextureResourceLocation(toTexture, rig).resourceLocation
rig.textures[toTexture.id] = toTexture
isOnlyTransparent = false
}

// Don't export models without any texture changes
Expand Down
18 changes: 0 additions & 18 deletions src/variants.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
import { IBlueprintVariantJSON } from './blueprintFormat'
import { PACKAGE } from './constants'
import { events } from './util/events'
import TransparentTexture from './assets/transparent.png'
import { toSafeFuntionName } from './util/minecraftUtil'

const OLD_PROJECT = Project
// @ts-ignore
Project = { materials: {} }
export const TRANSPARENT_TEXTURE = new Texture(
{
id: `${PACKAGE.name}:transparent_texture`,
name: 'Transparent',
},
'797174ae-5c58-4a83-a630-eefd51007c80'
).fromDataURL(TransparentTexture)
export const TRANSPARENT_TEXTURE_MATERIAL = Project!.materials[TRANSPARENT_TEXTURE.uuid]
export const TRANSPARENT_TEXTURE_RESOURCE_LOCATION = 'animated_java:blueprint/transparent'
Project = OLD_PROJECT

export class TextureMap {
map: Map<string, string>

Expand Down Expand Up @@ -46,7 +30,6 @@ export class TextureMap {
*/
public getMappedTexture(texture: Texture | string): Texture | undefined {
const uuid = this.map.get(texture instanceof Texture ? texture.uuid : texture)
if (uuid === TRANSPARENT_TEXTURE.uuid) return TRANSPARENT_TEXTURE
return Texture.all.find(t => t.uuid === uuid)
}

Expand Down Expand Up @@ -74,7 +57,6 @@ export class TextureMap {

public verifyTextures() {
for (const [key, value] of this.map) {
if (value === TRANSPARENT_TEXTURE.uuid) continue
if (!Texture.all.some(t => t.uuid === value)) {
this.map.delete(key)
}
Expand Down
Loading

0 comments on commit 26a5af7

Please sign in to comment.