22 # MCreator (https://mcreator.net/)
33 # Copyright (C) 2012-2020, Pylo
44 # Copyright (C) 2020-2023, Pylo, opensource contributors
5- #
5+ #
66 # This program is free software: you can redistribute it and/or modify
77 # it under the terms of the GNU General Public License as published by
88 # the Free Software Foundation, either version 3 of the License, or
99 # (at your option) any later version.
10- #
10+ #
1111 # This program is distributed in the hope that it will be useful,
1212 # but WITHOUT ANY WARRANTY; without even the implied warranty of
1313 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414 # GNU General Public License for more details.
15- #
15+ #
1616 # You should have received a copy of the GNU General Public License
1717 # along with this program. If not, see <https://www.gnu.org/licenses/>.
18- #
18+ #
1919 # Additional permission for code generator templates (*.ftl files)
20- #
21- # As a special exception, you may create a larger work that contains part or
22- # all of the MCreator code generator templates (*.ftl files) and distribute
23- # that work under terms of your choice, so long as that work isn't itself a
24- # template for code generation. Alternatively, if you modify or redistribute
25- # the template itself, you may (at your option) remove this special exception,
26- # which will cause the template and the resulting code generator output files
27- # to be licensed under the GNU General Public License without this special
20+ #
21+ # As a special exception, you may create a larger work that contains part or
22+ # all of the MCreator code generator templates (*.ftl files) and distribute
23+ # that work under terms of your choice, so long as that work isn't itself a
24+ # template for code generation. Alternatively, if you modify or redistribute
25+ # the template itself, you may (at your option) remove this special exception,
26+ # which will cause the template and the resulting code generator output files
27+ # to be licensed under the GNU General Public License without this special
2828 # exception.
2929-->
3030
@@ -36,10 +36,10 @@ package ${package}.entity;
3636import net.minecraft.network.datasync.DataParameter;
3737<#assign interfaces = [ ]>
3838<#assign extendsClass = "Creature" >
39- <#if data.aiBase != "(none)" >
39+ <#if data.aiBase != "(none)" >
4040 <#assign extendsClass = data.aiBase >
4141<#else >
42- <#assign extendsClass = data.mobBehaviourType. replace("Mob", "Monster"). replace("Raider", "AbstractRaider") >
42+ <#assign extendsClass = data.mobBehaviourType? replace("Mob", "Monster")? replace("Raider", "AbstractRaider") >
4343</#if >
4444<#if data.breedable >
4545 <#assign extendsClass = "Animal" >
@@ -53,6 +53,22 @@ import net.minecraft.network.datasync.DataParameter;
5353
5454public class ${name} Entity extends ${extendsClass} Entity <#if interfaces?size gt 0 >implements ${interfaces?join(",") } </#if > {
5555
56+ <#if data.spawnThisMob >
57+ private static final Set<ResourceLocation > SPAWN_BIOMES =
58+ <#if data.restrictionBiomes?has_content >
59+ ImmutableSet.of(
60+ <#list w.filterBrokenReferences(data.restrictionBiomes) as restrictionBiome >
61+ <#assign expandedBiomes = expandBiomeTag(restrictionBiome) >
62+ <#list expandedBiomes as expandedBiome >
63+ new ResourceLocation("${expandedBiome} ")<#sep >,
64+ </#list ><#sep >,
65+ </#list >
66+ )
67+ <#else >
68+ null
69+ </#if >;
70+ </#if >
71+
5672 <#list data.entityDataEntries as entry >
5773 <#if entry.value().getClass().getSimpleName() == "Integer" >
5874 public static final DataParameter<Integer > DATA_${entry.property().getName()} = EntityDataManager.createKey(${name} Entity.class, DataSerializers.VARINT);
@@ -69,23 +85,23 @@ public class ${name}Entity extends ${extendsClass}Entity <#if interfaces?size gt
6985 </#if >
7086
7187 public ${name} Entity(FMLPlayMessages.SpawnEntity packet, World world) {
72- this(${JavaModName} Entities.${REGISTRYNAME} .get(), world);
73- }
88+ this(${JavaModName} Entities.${REGISTRYNAME} .get(), world);
89+ }
7490
7591 public ${name} Entity(EntityType<${name} Entity> type, World world) {
7692 super(type, world);
7793 stepHeight = ${data.stepHeight} f;
7894 experienceValue = ${data.xpAmount} ;
7995 setNoAI(${(!data.hasAI)});
8096
81- <#if data.mobLabel?has_content >
97+ <#if data.mobLabel?has_content >
8298 setCustomName(new StringTextComponent("${data.mobLabel} "));
8399 setCustomNameVisible(true);
84- </#if >
100+ </#if >
85101
86102 <#if !data.doesDespawnWhenIdle >
87103 enablePersistence();
88- </#if >
104+ </#if >
89105
90106 <#if !data.equipmentMainHand.isEmpty() >
91107 this.setItemStackToSlot(EquipmentSlotType.MAINHAND, ${mappedMCItemToItemStackCode(data.equipmentMainHand, 1) } );
@@ -130,7 +146,7 @@ public class ${name}Entity extends ${extendsClass}Entity <#if interfaces?size gt
130146 if (${name} Entity.this.isInWater()) {
131147 ${name} Entity.this.setAIMoveSpeed((float) ${name} Entity.this.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).getValue());
132148
133- float f2 = - (float) (MathHelper.atan2(dy, (float) Math .sqrt(dx * dx + dz * dz)) * (180 / Math.PI));
149+ float f2 = - (float) (MathHelper.atan2(dy, (float) MathHelper .sqrt(dx * dx + dz * dz)) * (180 / Math.PI));
134150 f2 = MathHelper.clamp(MathHelper.wrapDegrees(f2), -85, 85);
135151 ${name} Entity.this.rotationPitch = this.limitAngle(${name} Entity.this.rotationPitch, f2, 5);
136152 float f3 = MathHelper.cos(${name} Entity.this.rotationPitch * (float) (Math.PI / 180.0));
@@ -235,7 +251,7 @@ public class ${name}Entity extends ${extendsClass}Entity <#if interfaces?size gt
235251 <#if !data.mobDrop.isEmpty() >
236252 protected void dropSpecialItems(DamageSource source, int looting, boolean recentlyHitIn) {
237253 super.dropSpecialItems(source, looting, recentlyHitIn);
238- this.entityDropItem(${mappedMCItemToItemStackCode(data.mobDrop, 1) } );
254+ this.entityDropItem(${mappedMCItemToItemStackCode(data.mobDrop, 1) } );
239255 }
240256 </#if >
241257
@@ -460,7 +476,7 @@ public class ${name}Entity extends ${extendsClass}Entity <#if interfaces?size gt
460476 }
461477
462478 @Override public void readAdditional(CompoundNBT compound) {
463- super.readAdditional(compound);
479+ super.readAdditional(compound);
464480 <#list data.entityDataEntries as entry >
465481 if (compound.contains("Data${entry.property().getName()} "))
466482 <#if entry.value().getClass().getSimpleName() == "Integer" >
@@ -481,11 +497,11 @@ public class ${name}Entity extends ${extendsClass}Entity <#if interfaces?size gt
481497 <#if hasProcedure(data.onRightClickedOn) || data.ridable || (data.tameable && data.breedable) || data.guiBoundTo?has_content >
482498 @Override public boolean processInteract(PlayerEntity sourceentity, Hand hand) {
483499 ItemStack itemstack = sourceentity.getHeldItem(hand);
484- boolean retval = this.world.isRemote;
500+ ActionResultType retval = ActionResult.newResult( this.world.isRemote()).getType() ;
485501
486502 <#if data.guiBoundTo?has_content >
487503 <#if data.ridable >
488- if (sourceentity.isSecondaryUseActive ()) {
504+ if (sourceentity.isSneaking ()) {
489505 </#if >
490506 if(sourceentity instanceof ServerPlayerEntity) {
491507 NetworkHooks.openGui((ServerPlayerEntity) sourceentity, new INamedContainerProvider() {
@@ -509,31 +525,31 @@ public class ${name}Entity extends ${extendsClass}Entity <#if interfaces?size gt
509525 });
510526 }
511527 <#if data.ridable >
512- return this.world.isRemote;
528+ return this.world.isRemote() ;
513529 }
514530 </#if >
515531 </#if >
516532
517533 <#if (data.tameable && data.breedable) >
518534 Item item = itemstack.getItem();
519535 if (itemstack.getItem() instanceof SpawnEggItem) {
520- retval = super.processInteract(sourceentity, hand);
536+ retval = ActionResult.newResult( super.processInteract(sourceentity, hand)).getType( );
521537 } else if (this.world.isRemote()) {
522538 retval = (this.isTamed() && this.isOwner(sourceentity) || this.isBreedingItem(itemstack))
523- ? this.world.isRemote() : true ;
539+ ? ActionResult.newResult( this.world.isRemote()).getType() : ActionResultType.PASS ;
524540 } else {
525541 if (this.isTamed()) {
526542 if (this.isOwner(sourceentity)) {
527543 if (item.isFood() && this.isBreedingItem(itemstack) && this.getHealth() < this.getMaxHealth()) {
528544 this.consumeItemFromStack(sourceentity, itemstack);
529545 this.heal((float)item.getFood().getHealing());
530- retval = this.world.isRemote;
546+ retval = ActionResult.newResult( this.world.isRemote()).getType() ;
531547 } else if (this.isBreedingItem(itemstack) && this.getHealth() < this.getMaxHealth()) {
532548 this.consumeItemFromStack(sourceentity, itemstack);
533549 this.heal(4);
534- retval = this.world.isRemote;
550+ retval = ActionResult.newResult( this.world.isRemote()).getType() ;
535551 } else {
536- retval = super.processInteract(sourceentity, hand);
552+ retval = ActionResult.newResult( super.processInteract(sourceentity, hand)).getType( );
537553 }
538554 }
539555 } else if (this.isBreedingItem(itemstack)) {
@@ -546,10 +562,10 @@ public class ${name}Entity extends ${extendsClass}Entity <#if interfaces?size gt
546562 }
547563
548564 this.enablePersistence();
549- retval = this.world.isRemote;
565+ retval = ActionResult.newResult( this.world.isRemote()).getType() ;
550566 } else {
551- retval = super.processInteract(sourceentity, hand);
552- if (retval)
567+ retval = ActionResult.newResult( super.processInteract(sourceentity, hand)).getType( );
568+ if (retval == ActionResultType.SUCCESS )
553569 this.enablePersistence();
554570 }
555571 }
@@ -571,10 +587,10 @@ public class ${name}Entity extends ${extendsClass}Entity <#if interfaces?size gt
571587 return <@procedureOBJToInteractionResultCode data.onRightClickedOn/ > != ActionResultType.FAIL;
572588 <#else >
573589 <@procedureOBJToCode data.onRightClickedOn/ >
574- return retval;
590+ return retval != ActionResultType.FAIL ;
575591 </#if >
576592 <#else >
577- return retval;
593+ return retval != ActionResultType.FAIL ;
578594 </#if >
579595 }
580596 </#if >
@@ -649,7 +665,7 @@ public class ${name}Entity extends ${extendsClass}Entity <#if interfaces?size gt
649665 <#if data.breedable >
650666 @Override public AgeableEntity createChild(AgeableEntity ageable) {
651667 ${name} Entity retval = ${JavaModName} Entities.${REGISTRYNAME} .get().create(this.world);
652- retval.onInitialSpawn(this.world, this.world.getDifficultyForLocation(new BlockPos( retval)), SpawnReason.BREEDING, null, null);
668+ retval.onInitialSpawn(this.world, this.world.getDifficultyForLocation(retval.getPosition( )), SpawnReason.BREEDING, null, null);
653669 return retval;
654670 }
655671
@@ -659,7 +675,7 @@ public class ${name}Entity extends ${extendsClass}Entity <#if interfaces?size gt
659675 </#if >
660676
661677 <#if data.waterMob >
662- @Override public boolean isNotColliding(IWorldReader world) {
678+ @Override public boolean isNotColliding(IWorldReader world) {
663679 return world.checkNoEntityCollision(this);
664680 }
665681 </#if >
@@ -797,8 +813,7 @@ public class ${name}Entity extends ${extendsClass}Entity <#if interfaces?size gt
797813 </#if >
798814
799815 <#if data.flyingMob >
800- @Override protected void updateFallState(double y, boolean onGroundIn, BlockState state, BlockPos pos) {
801- }
816+ @Override protected void updateFallState(double y, boolean onGroundIn, BlockState state, BlockPos pos) {}
802817
803818 @Override public void setNoGravity(boolean ignored) {
804819 super.setNoGravity(true);
@@ -813,22 +828,6 @@ public class ${name}Entity extends ${extendsClass}Entity <#if interfaces?size gt
813828 }
814829 </#if >
815830
816- <#if data.spawnThisMob >
817- private static final Set<ResourceLocation > SPAWN_BIOMES =
818- <#if data.restrictionBiomes?has_content >
819- ImmutableSet.of(
820- <#list w.filterBrokenReferences(data.restrictionBiomes) as restrictionBiome >
821- <#assign expandedBiomes = expandBiomeTag(restrictionBiome) >
822- <#list expandedBiomes as expandedBiome >
823- new ResourceLocation("${expandedBiome} ")<#sep >,
824- </#list ><#sep >,
825- </#list >
826- )
827- <#else >
828- null
829- </#if >;
830- </#if >
831-
832831 public static void init() {
833832 <#if data.spawnThisMob >
834833 for (Biome biome : ForgeRegistries.BIOMES.getValues()) {
@@ -1011,6 +1010,4 @@ public class ${name}Entity extends ${extendsClass}Entity <#if interfaces?size gt
10111010 <#assign result = "minecraft:" + noHash / >
10121011 <#return input?starts_with("#")?then("#" + result, result)/ >
10131012 </#if >
1014- </#function >
1015-
1016-
1013+ </#function >
0 commit comments