Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
CreatureChat
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
Public
CreatureChat
Commits
655a6356
Commit
655a6356
authored
Nov 01, 2023
by
Jonathan Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removing textures.json files - not needed anymore. Simplify texture loading and error handling.
parent
7e853d9e
Pipeline
#11635
passed with stage
in 22 seconds
Changes
5
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
123 deletions
+16
-123
build.gradle
build.gradle
+0
-47
ExampleModClient.java
src/client/java/com/owlmaddie/ExampleModClient.java
+4
-4
TextureLoader.java
src/client/java/com/owlmaddie/TextureLoader.java
+12
-34
textures.json
...ain/resources/assets/mobgpt/textures/entity/textures.json
+0
-27
textures.json
src/main/resources/assets/mobgpt/textures/ui/textures.json
+0
-11
No files found.
build.gradle
View file @
655a6356
import
com.google.gson.Gson
import
com.google.gson.GsonBuilder
plugins
{
id
'fabric-loom'
version
'1.4-SNAPSHOT'
id
'maven-publish'
...
...
@@ -92,47 +89,3 @@ publishing {
// retrieving dependencies.
}
}
task
generateEntityJson
{
doLast
{
def
resourcesDir
=
new
File
(
'src/main/resources/assets/mobgpt/textures/entity'
)
// adjust the path
def
outputJson
=
new
File
(
'src/main/resources/assets/mobgpt/textures/entity/textures.json'
)
// output file
def
pngFiles
=
resourcesDir
.
listFiles
(
new
FilenameFilter
()
{
@Override
boolean
accept
(
File
dir
,
String
name
)
{
return
name
.
endsWith
(
'.png'
);
}
})
def
resourcesList
=
pngFiles
.
collect
{
it
.
name
}
// Using GSON to write the JSON
Gson
gson
=
new
GsonBuilder
().
setPrettyPrinting
().
create
()
outputJson
.
text
=
gson
.
toJson
(
resourcesList
)
}
}
task
generateUiJson
{
doLast
{
def
resourcesDir
=
new
File
(
'src/main/resources/assets/mobgpt/textures/ui'
)
// adjust the path
def
outputJson
=
new
File
(
'src/main/resources/assets/mobgpt/textures/ui/textures.json'
)
// output file
def
pngFiles
=
resourcesDir
.
listFiles
(
new
FilenameFilter
()
{
@Override
boolean
accept
(
File
dir
,
String
name
)
{
return
name
.
endsWith
(
'.png'
);
}
})
def
resourcesList
=
pngFiles
.
collect
{
it
.
name
}
// Using GSON to write the JSON
Gson
gson
=
new
GsonBuilder
().
setPrettyPrinting
().
create
()
outputJson
.
text
=
gson
.
toJson
(
resourcesList
)
}
}
// Ensure the task runs before the build
build
.
dependsOn
generateEntityJson
build
.
dependsOn
generateUiJson
src/client/java/com/owlmaddie/ExampleModClient.java
View file @
655a6356
...
...
@@ -184,13 +184,13 @@ public class ExampleModClient implements ClientModInitializer {
float
z
=
0.01
F
;
// Draw UI text background
RenderSystem
.
setShaderTexture
(
0
,
textures
.
Get
(
"text-top"
));
RenderSystem
.
setShaderTexture
(
0
,
textures
.
Get
(
"
ui"
,
"
text-top"
));
drawTexturePart
(
matrices
,
buffer
,
x
,
y
,
z
,
width
,
40
);
RenderSystem
.
setShaderTexture
(
0
,
textures
.
Get
(
"text-middle"
));
RenderSystem
.
setShaderTexture
(
0
,
textures
.
Get
(
"
ui"
,
"
text-middle"
));
drawTexturePart
(
matrices
,
buffer
,
x
,
y
+
40
,
z
,
width
,
height
);
RenderSystem
.
setShaderTexture
(
0
,
textures
.
Get
(
"text-bottom"
));
RenderSystem
.
setShaderTexture
(
0
,
textures
.
Get
(
"
ui"
,
"
text-bottom"
));
drawTexturePart
(
matrices
,
buffer
,
x
,
y
+
40
+
height
,
z
,
width
,
5
);
RenderSystem
.
disableBlend
();
...
...
@@ -209,7 +209,7 @@ public class ExampleModClient implements ClientModInitializer {
private
void
drawEntityIcon
(
MatrixStack
matrices
,
Entity
entity
,
float
x
,
float
y
,
float
width
,
float
height
)
{
// Draw face icon
String
entity_name
=
entity
.
getType
().
getUntranslatedName
().
toLowerCase
(
Locale
.
ROOT
);
Identifier
entity_id
=
textures
.
Get
(
entity_name
);
Identifier
entity_id
=
textures
.
Get
(
"entity"
,
entity_name
);
if
(
entity_id
==
null
)
{
return
;
}
...
...
src/client/java/com/owlmaddie/TextureLoader.java
View file @
655a6356
...
...
@@ -4,11 +4,12 @@ import net.minecraft.client.MinecraftClient;
import
net.minecraft.util.Identifier
;
import
java.util.Map
;
import
java.util.HashMap
;
import
java.
io.InputStreamReader
;
import
java.io.InputStream
;
import
java.
util.Optional
;
import
com.google.gson.Gson
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
net.minecraft.resource.Resource
;
public
class
TextureLoader
{
public
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
"mobgpt"
);
...
...
@@ -18,44 +19,21 @@ public class TextureLoader {
private
static
final
Map
<
String
,
Identifier
>
TEXTURE_MAP
=
new
HashMap
<>();
public
TextureLoader
()
{
// Load Entity Textures
InputStream
inputStream
=
TextureLoader
.
class
.
getResourceAsStream
(
ASSETS_PATH
+
ENTITY_TEXTURE_PATH
+
"textures.json"
);
Gson
gson
=
new
Gson
();
// Assuming your JSON is a list of strings, i.e., filenames.
String
[]
filenames
=
gson
.
fromJson
(
new
InputStreamReader
(
inputStream
),
String
[].
class
);
for
(
String
filename
:
filenames
)
{
String
texturePath
=
ENTITY_TEXTURE_PATH
+
filename
;
Identifier
textureId
=
new
Identifier
(
"mobgpt"
,
texturePath
);
TEXTURE_MAP
.
put
(
filename
.
replace
(
".png"
,
""
),
textureId
);
}
// Load UI Textures
inputStream
=
TextureLoader
.
class
.
getResourceAsStream
(
ASSETS_PATH
+
UI_TEXTURE_PATH
+
"textures.json"
);
gson
=
new
Gson
()
;
// Assuming your JSON is a list of strings, i.e., filenames.
filenames
=
gson
.
fromJson
(
new
InputStreamReader
(
inputStream
),
String
[].
class
);
public
Identifier
Get
(
String
folder
,
String
name
)
{
// Attempt to load texture resource
String
texture_path
=
"textures/"
+
folder
+
"/"
+
name
+
".png"
;
Identifier
textureId
=
new
Identifier
(
"mobgpt"
,
texture_path
);
Optional
<
Resource
>
resource
=
MinecraftClient
.
getInstance
().
getResourceManager
().
getResource
(
textureId
);
for
(
String
filename
:
filenames
)
{
String
texturePath
=
UI_TEXTURE_PATH
+
filename
;
Identifier
textureId
=
new
Identifier
(
"mobgpt"
,
texturePath
);
TEXTURE_MAP
.
put
(
filename
.
replace
(
".png"
,
""
),
textureId
);
}
}
public
Identifier
Get
(
String
name
)
{
Identifier
textureId
=
TEXTURE_MAP
.
get
(
name
);
if
(
textureId
!=
null
)
{
if
(!
resource
.
isEmpty
())
{
// Bind texture, and return Identity
MinecraftClient
.
getInstance
().
getTextureManager
().
bindTexture
(
textureId
);
return
textureId
;
}
else
{
// You can bind and return a default texture here if you have one
// textureManager.bindTexture(DEFAULT_TEXTURE_ID);
// return DEFAULT_TEXTURE_ID;
// Or just return null or handle the missing texture situation as needed
LOGGER
.
info
(
name
+
" was not found in mobgpt"
);
// Resource not found
LOGGER
.
info
(
texture_path
+
" was not found in mobgpt"
);
return
null
;
}
}
...
...
src/main/resources/assets/mobgpt/textures/entity/textures.json
deleted
100644 → 0
View file @
7e853d9e
[
"bee_angry.png"
,
"pig.png"
,
"rabbit_black.png"
,
"cow.png"
,
"zombie.png"
,
"rabbit_brown.png"
,
"villager.png"
,
"frog_gray.png"
,
"skeleton.png"
,
"rabbit_white_splotched.png"
,
"wolf_angry.png"
,
"frog_orange.png"
,
"wolf.png"
,
"rabbit_white.png"
,
"chicken.png"
,
"shulker.png"
,
"rabbit_gold.png"
,
"bee.png"
,
"creeper.png"
,
"rabbit_toast.png"
,
"rabbit_salt.png"
,
"enderman.png"
,
"frog_green.png"
,
"warden.png"
]
\ No newline at end of file
src/main/resources/assets/mobgpt/textures/ui/textures.json
deleted
100644 → 0
View file @
7e853d9e
[
"keyboard.png"
,
"text-middle.png"
,
"dotdot.png"
,
"button-chat.png"
,
"text-top.png"
,
"arrow1.png"
,
"arrow2.png"
,
"text-bottom.png"
]
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment