Skip to content

Commit

Permalink
Added support for custom item properties (MCreator#2000)
Browse files Browse the repository at this point in the history
* Added new UI components (initial)

* Added new fields to item GUI (still WIP)

* Added state editor and merged properties and models lists

* Updated some item templates

* Added all needed templates

* Some fixes to new list panel

* Procedure block and more improvements

* Added access to built-in properties, updated help tips and fixed templates

* Added new dialog test and improved item model class

* Another procedure block fix

* More improvements

* 1.16 fix

* Proper renaming and more template fixes

* Fixed tests

* A couple more stability improvements

* Added help context to entries and fixed properties renaming yet again
Also added some indentations to improve code quality

* Migrated to string type model keys

* Fixed reference

* Added help context to the dialog and improved error windows

* Some more fixes

* Changed validator text

* Removed unnecessary check

* Simplified another one

* Reordered state entry methods

* French tips, workspace JSON adapter and more

* Added 1.18.x templates + cleanup

* Minor fixes

* Improved states editing

* 1.18.x procedure block

* Stability improvements

* Renamed property index fix

* Further fixes

* Validation changes

* Fixes again

* New GUI components are now fully opaque

* Some updates

* Resolving conflict

* Resolving conflict

* Resolving conflict

* Added tests and improved entity checks

* Fixed tests

* Fix tests (pt. 2)

* Wrong reference

* Reverted indentations in 1.18.2 item registry

* Reverted code reformat in ProcedureSelector

* Updated to use recently added validator instead of its origin

* Removed 1.16.5 support (will not build)

* Fix tests?

* Fixed tests

* Some refactoring
- Migrated new components from state strings to state maps
- Removed string tokens from state editor
- Changed layout of new UI components to allow renaming properties in a proper way and to make state texts more human-readable

* Fixed tests

* Fixes a bunch of bugs

* Further restructuring

* Minor changes and fixes

* Just to re-run tests

* Marked buttons on new entry components as technical

* Minor fix

* Adapted to the recent changes to list templates system

* Cut down the number of files changed

* Slight improvement

* Once more

* Removed procedure block, moved built-in properties to a data list

* Added docs to procedure selector constructors

* Minor changes to the layout

* Removed unused variable to re-run tests

* Reverted some layout changes

* Refactored property data class

* Some optimizations

* Improved properties validation

* Some more things that could seem suboptimal

* Extra refactoring, minor improvements

* Improved validation and properties data list

* Improved the new data list usage

* Fixed tests

* Added forgotten warning to property data renaming method

* Put the new validator into use in place of a hardcoded one

* Future proofing

* 1.19.4 support

* 1.19.4 data list

* Unsupported properties handling

* 1.19.4 templates

* More validation, updated help tips

* Fixed an awful issue with tests

* UI optimizations, minor "backport"

* New HelpUtils method was in fact redundant

* UI strings/tips again

* More redundant things

* More correct keys

* Removed Minecraft 1.18.x support

* Removed Minecraft 1.18.x support 2

* Removed Minecraft 1.18.x support 3

* Removed Minecraft 1.18.x support 4

* Minor change

* Notes

* External properties can not be renamed anymore

* More layout changes

* Fixed tests

* Proper filtering + clearer code

* No bounds for "logic" properties

* Made UI more MCreator-ish (imatate other UI parts) + scroll panels need ticks defined + JPropertyNameFiled does not need to be JPanel

* Was that blindness or dumbness?

* Some more UI changes

* Removed button that could be confused for some sort of entry duplication

* Thinned state entries and removed collapsible panel so we can use grid layout

* These are no more relevant

* Clearer implementation of multitude of things

* Slightly simplified dialog test

* Import remove

* Shorter stats name

* Follow the way livingentitygui handles models

* Some minor renames

* Technical buttons invasion

* Proper decimal precision

* Namespaces

* Redundant extra key

* Number match types

* Namespaces 2

* Text

* New method, float to double, proper double infinity

* Few renames

* Integer -> Int

* Proper mappings

* BTS changes

* Tests fix

* Another rename

* Tests fix 2, minor changes

* Filtering

* Help tips

* Whole MCreator uses true/false not True/False

* Seems I will have to rename things myself + tests that also test cases with default and non-default values

* Templates fix

* Handy but obsolete

* Some renames

* Non-optimal naming, but follows the way we call it in Item

* Did not refactor too much I hope

* Default property name could create duplicate names in some cases so the system was removed as no one would or should name properties with same name but number applies anyways

* List templates entry is called now data, not item, so existing templates can be reused in list templates without too much hackerty and FTL expression overload

* Store states in Item as flat list of state definitions instead

* Slight javadoc

* GSON does not play well with annonymous classes, use logic data for logic and then in template, we can handle this in templates (replace true/false with 0.0 and 1.0)

* Fix serilization

* Example of how I envisioned the templates + minor change to Item.java so workspace does not need to be passed and same method can be used

* Another fix of template demo, but mappings indeed don't work

* CUSTOM: prefix everywhere expect UI, better doubles and test

* Serializer update, better border title

* Templates

* Wrong folders

* Seal IPropertyData from any insane things + serializer fix

* Slight change to deinifiton yaml

* Key and property should be in same line if possible for readability

* Match type for external properties

* Match type for state editor

* 5 extra symbols to fix tests

* Serialize property parameters too

* Fix OBJ models crashing in FTL in all cases

* Simplified FTL conditions

* Simpltified items code (also not passing entity from itemstack as this could cause unexpected behaviour + entity can be null and procedure could still run so removed this check)

* No initial name to indicate it requires definition

* Properties validation before editing state

* Missing documentation

* Property ID prefixes

* Prefixes in item models

* Minor indent. fix

* A bit nicer generated code

* Tests with CUSTOM: prefix

* Replaced FTL code with method that may come in handy later in the future (or not, but makes FTL bit shorter)

* Slight refactor

* Found fix for JSpinner

* Avoid static initializer

* Small refactor

* Tiny refactor

* Removing elements from list while forEach can cause CME

* Fix properties renaming (another time? :D)

* Sorry, but this IS used

* Seems we'll have to recreate maps to not reference wrong properties

* More null checks

* Help tips

* Revert "Seems we'll have to recreate maps to not reference wrong properties"

This reverts commit 26e26f7.

* Property data UUID

* Fill map with own properties as they are not compared by UUID

* One more tip

* Sleep tight, thanks for help

* These two are obsolete too

* Properties could have duplicate names

* Formatting, final attribute

* Not so careful

* Slight UI change

* Procedure template to imitate vanilla logic properties

* Procedure change listener

---------

Co-authored-by: Klemen <16374228+KlemenDEV@users.noreply.github.com>
  • Loading branch information
Defeatomizer and KlemenDEV authored Jun 25, 2023
1 parent a4bafc6 commit d9c9bf1
Show file tree
Hide file tree
Showing 51 changed files with 1,855 additions and 48 deletions.
25 changes: 25 additions & 0 deletions plugins/generator-1.19.2/forge-1.19.2/item.definition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,31 @@ templates:
condition: "renderType #= 2"
name: "@MODASSETSROOT/models/item/@registryname.json"

list_templates:
- name: "Item states"
listData: data.getModels()
forEach:
- template: json/item.json.ftl
writer: json
condition:
- "renderType #= 0"
- "hasNormalModel()"
name: "@MODASSETSROOT/models/item/@registryname_@itemindex.json"
- template: json/tool.json.ftl
writer: json
condition:
- "renderType #= 0"
- "hasToolModel()"
name: "@MODASSETSROOT/models/item/@registryname_@itemindex.json"
- template: json/item_cmodel.json.ftl
writer: json
condition: "renderType #= 1"
name: "@MODASSETSROOT/models/item/@registryname_@itemindex.json"
- template: json/item_cmodel_obj.json.ftl
writer: json
condition: "renderType #= 2"
name: "@MODASSETSROOT/models/item/@registryname_@itemindex.json"

localizationkeys:
- key: item.@modid.@registryname
mapto: name
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
_mcreator_prefix: "CUSTOM:"
_mcreator_map_template: "@modid:@name"
damaged: damaged
damage: damage
lefthanded: lefthanded
cooldown: cooldown
custom_model_data: custom_model_data
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
-->

<#-- @formatter:off -->
<#include "../procedures.java.ftl">

/*
* MCreator note: This file will be REGENERATED on each build.
Expand All @@ -39,6 +40,9 @@ package ${package}.init;
<#assign hasBlocks = false>
<#assign hasDoubleBlocks = false>

<#if w.hasItemsWithCustomProperties()>
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
</#if>
public class ${JavaModName}Items {

public static final DeferredRegister<Item> REGISTRY = DeferredRegister.create(ForgeRegistries.ITEMS, ${JavaModName}.MODID);
Expand Down Expand Up @@ -99,6 +103,36 @@ public class ${JavaModName}Items {
return REGISTRY.register(block.getId().getPath(), () -> new DoubleHighBlockItem(block.get(), new Item.Properties().tab(tab)));
}
</#if>

<#if w.hasItemsWithCustomProperties()>
<#compress>
@SubscribeEvent public static void clientLoad(FMLClientSetupEvent event) {
event.enqueueWork(() -> {
<#list items as item>
<#if item.getModElement().getTypeString() == "item">
<#list item.customProperties.entrySet() as property>
ItemProperties.register(${item.getModElement().getRegistryNameUpper()}.get(),
new ResourceLocation("${modid}:${item.getModElement().getRegistryName()}_${property.getKey()}"),
(itemStackToRender, clientWorld, entity, itemEntityId) ->
<#if hasProcedure(property.getValue())>
(float) <@procedureCode property.getValue(), {
"x": "entity != null ? entity.getX() : 0",
"y": "entity != null ? entity.getY() : 0",
"z": "entity != null ? entity.getZ() : 0",
"world": "entity != null ? entity.level : clientWorld",
"entity": "entity",
"itemstack": "itemStackToRender"
}, false/>
<#else>0</#if>
);
</#list>
</#if>
</#list>
});
}
</#compress>
</#if>

}

<#-- @formatter:on -->
15 changes: 15 additions & 0 deletions plugins/generator-1.19.2/forge-1.19.2/templates/json/item.json.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,19 @@
"layer0": "${modid}:items/${data.texture}"
</#if>
}
<#if data.getModels?? && data.getModels()?has_content>,
"overrides": [
<#list data.getModels() as model>
{
"predicate": {
<#list model.stateMap.keySet() as property>
<#assign value = model.stateMap.get(property)>
"${generator.map(property.getPrefixedName(registryname + "_"), "itemproperties")}": ${value?is_boolean?then(value?then("1", "0"), value)}<#sep>,
</#list>
},
"model": "${modid}:item/${registryname}_${model?index}"
}<#sep>,
</#list>
]
</#if>
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
"particle": "${modid}:items/${data.texture}"
}
</#if>
<#if data.getModels?? && data.getModels()?has_content>,
"overrides": [
<#list data.getModels() as model>
{
"predicate": {
<#list model.stateMap.keySet() as property>
<#assign value = model.stateMap.get(property)>
"${generator.map(property.getPrefixedName(registryname + "_"), "itemproperties")}": ${value?is_boolean?then(value?then("1", "0"), value)}<#sep>,
</#list>
},
"model": "${modid}:item/${registryname}_${model?index}"
}<#sep>,
</#list>
]
</#if>
}

<#macro textures textureMap>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@
"particle": "${modid}:items/${data.texture}"
</#if>
}
<#if data.getModels?? && data.getModels()?has_content>,
"overrides": [
<#list data.getModels() as model>
{
"predicate": {
<#list model.stateMap.keySet() as property>
<#assign value = model.stateMap.get(property)>
"${generator.map(property.getPrefixedName(registryname + "_"), "itemproperties")}": ${value?is_boolean?then(value?then("1", "0"), value)}<#sep>,
</#list>
},
"model": "${modid}:item/${registryname}_${model?index}"
}<#sep>,
</#list>
]
</#if>
}

<#macro textures textureMap>
Expand Down
15 changes: 15 additions & 0 deletions plugins/generator-1.19.2/forge-1.19.2/templates/json/tool.json.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,19 @@
"layer0": "${modid}:items/${data.texture}"
</#if>
}
<#if data.getModels?? && data.getModels()?has_content>,
"overrides": [
<#list data.getModels() as model>
{
"predicate": {
<#list model.stateMap.keySet() as property>
<#assign value = model.stateMap.get(property)>
"${generator.map(property.getPrefixedName(registryname + "_"), "itemproperties")}": ${value?is_boolean?then(value?then("1", "0"), value)}<#sep>,
</#list>
},
"model": "${modid}:item/${registryname}_${model?index}"
}<#sep>,
</#list>
]
</#if>
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<#list deps_filtered as value>${value}<#if value?has_next>,</#if></#list>
</#macro>

<#macro procedureCode object dependencies={}>
${object.getName()}Procedure.execute(<@procedureDependenciesCode object.getDependencies(generator.getWorkspace()) dependencies/>);
<#macro procedureCode object dependencies={} semicolon=true>
${object.getName()}Procedure.execute(<@procedureDependenciesCode object.getDependencies(generator.getWorkspace()) dependencies/>)<#if semicolon>;</#if>
</#macro>

<#macro procedureCodeWithOptResult object type defaultResult dependencies={}>
Expand Down
25 changes: 25 additions & 0 deletions plugins/generator-1.19.4/forge-1.19.4/item.definition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,31 @@ templates:
condition: "renderType #= 2"
name: "@MODASSETSROOT/models/item/@registryname.json"

list_templates:
- name: "Item states"
listData: data.getModels()
forEach:
- template: json/item.json.ftl
writer: json
condition:
- "renderType #= 0"
- "hasNormalModel()"
name: "@MODASSETSROOT/models/item/@registryname_@itemindex.json"
- template: json/tool.json.ftl
writer: json
condition:
- "renderType #= 0"
- "hasToolModel()"
name: "@MODASSETSROOT/models/item/@registryname_@itemindex.json"
- template: json/item_cmodel.json.ftl
writer: json
condition: "renderType #= 1"
name: "@MODASSETSROOT/models/item/@registryname_@itemindex.json"
- template: json/item_cmodel_obj.json.ftl
writer: json
condition: "renderType #= 2"
name: "@MODASSETSROOT/models/item/@registryname_@itemindex.json"

localizationkeys:
- key: item.@modid.@registryname
mapto: name
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
_mcreator_prefix: "CUSTOM:"
_mcreator_map_template: "@modid:@name"
damaged: damaged
damage: damage
lefthanded: lefthanded
cooldown: cooldown
custom_model_data: custom_model_data
trim_type: trim_type
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
-->

<#-- @formatter:off -->
<#include "../procedures.java.ftl">

/*
* MCreator note: This file will be REGENERATED on each build.
Expand All @@ -39,6 +40,9 @@ package ${package}.init;
<#assign hasBlocks = false>
<#assign hasDoubleBlocks = false>

<#if w.hasItemsWithCustomProperties()>
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
</#if>
public class ${JavaModName}Items {

public static final DeferredRegister<Item> REGISTRY = DeferredRegister.create(ForgeRegistries.ITEMS, ${JavaModName}.MODID);
Expand Down Expand Up @@ -99,6 +103,35 @@ public class ${JavaModName}Items {
}
</#if>

<#if w.hasItemsWithCustomProperties()>
<#compress>
@SubscribeEvent public static void clientLoad(FMLClientSetupEvent event) {
event.enqueueWork(() -> {
<#list items as item>
<#if item.getModElement().getTypeString() == "item">
<#list item.customProperties.entrySet() as property>
ItemProperties.register(${item.getModElement().getRegistryNameUpper()}.get(),
new ResourceLocation("${modid}:${item.getModElement().getRegistryName()}_${property.getKey()}"),
(itemStackToRender, clientWorld, entity, itemEntityId) ->
<#if hasProcedure(property.getValue())>
(float) <@procedureCode property.getValue(), {
"x": "entity != null ? entity.getX() : 0",
"y": "entity != null ? entity.getY() : 0",
"z": "entity != null ? entity.getZ() : 0",
"world": "entity != null ? entity.level : clientWorld",
"entity": "entity",
"itemstack": "itemStackToRender"
}, false/>
<#else>0</#if>
);
</#list>
</#if>
</#list>
});
}
</#compress>
</#if>

}

<#-- @formatter:on -->
15 changes: 15 additions & 0 deletions plugins/generator-1.19.4/forge-1.19.4/templates/json/item.json.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,19 @@
"layer0": "${modid}:item/${data.texture}"
</#if>
}
<#if data.getModels?? && data.getModels()?has_content>,
"overrides": [
<#list data.getModels() as model>
{
"predicate": {
<#list model.stateMap.keySet() as property>
<#assign value = model.stateMap.get(property)>
"${generator.map(property.getPrefixedName(registryname + "_"), "itemproperties")}": ${value?is_boolean?then(value?then("1", "0"), value)}<#sep>,
</#list>
},
"model": "${modid}:item/${registryname}_${model?index}"
}<#sep>,
</#list>
]
</#if>
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
"particle": "${modid}:item/${data.texture}"
}
</#if>
<#if data.getModels?? && data.getModels()?has_content>,
"overrides": [
<#list data.getModels() as model>
{
"predicate": {
<#list model.stateMap.keySet() as property>
<#assign value = model.stateMap.get(property)>
"${generator.map(property.getPrefixedName(registryname + "_"), "itemproperties")}": ${value?is_boolean?then(value?then("1", "0"), value)}<#sep>,
</#list>
},
"model": "${modid}:item/${registryname}_${model?index}"
}<#sep>,
</#list>
]
</#if>
}

<#macro textures textureMap>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@
"particle": "${modid}:item/${data.texture}"
</#if>
}
<#if data.getModels?? && data.getModels()?has_content>,
"overrides": [
<#list data.getModels() as model>
{
"predicate": {
<#list model.stateMap.keySet() as property>
<#assign value = model.stateMap.get(property)>
"${generator.map(property.getPrefixedName(registryname + "_"), "itemproperties")}": ${value?is_boolean?then(value?then("1", "0"), value)}<#sep>,
</#list>
},
"model": "${modid}:item/${registryname}_${model?index}"
}<#sep>,
</#list>
]
</#if>
}

<#macro textures textureMap>
Expand Down
15 changes: 15 additions & 0 deletions plugins/generator-1.19.4/forge-1.19.4/templates/json/tool.json.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,19 @@
"layer0": "${modid}:item/${data.texture}"
</#if>
}
<#if data.getModels?? && data.getModels()?has_content>,
"overrides": [
<#list data.getModels() as model>
{
"predicate": {
<#list model.stateMap.keySet() as property>
<#assign value = model.stateMap.get(property)>
"${generator.map(property.getPrefixedName(registryname + "_"), "itemproperties")}": ${value?is_boolean?then(value?then("1", "0"), value)}<#sep>,
</#list>
},
"model": "${modid}:item/${registryname}_${model?index}"
}<#sep>,
</#list>
]
</#if>
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<#list deps_filtered as value>${value}<#if value?has_next>,</#if></#list>
</#macro>

<#macro procedureCode object dependencies={}>
${object.getName()}Procedure.execute(<@procedureDependenciesCode object.getDependencies(generator.getWorkspace()) dependencies/>);
<#macro procedureCode object dependencies={} semicolon=true>
${object.getName()}Procedure.execute(<@procedureDependenciesCode object.getDependencies(generator.getWorkspace()) dependencies/>)<#if semicolon>;</#if>
</#macro>

<#macro procedureCodeWithOptResult object type defaultResult dependencies={}>
Expand Down
Loading

0 comments on commit d9c9bf1

Please sign in to comment.