#Texture and entity rendering

39 messages · Page 1 of 1 (latest)

mental ibex
#
  1. How can I render separate textures for the sides, top and bottom of a block? (like for TNT)
  2. I have a class (CustomTntBlock) that extends TntBlock, modified to expose explosionPower and handle the use of an accessor for said field behind the scenes. I then have a seperate class (CompressedTntBlock) that extends CustomTntBlock and runs the setExplosionPower function to set the power to 10 (the power I've chosen for compressed TNT). The only issue is that the CustomTntBlock is still summoning the builtin TntEntity entity, and thus it is rendered with the default TNT texture and not the same texture as the Compressed TNT block when it is unignited. How can I replace the texture of this entity, and have it extensible so the different classes that extend CustomTntBlock can each have their own texture for both the block and the entity?

Code for CustomTntBlock and CompressedTntBlock attached below. CustomTntBlockbasically just lets you set a custom explosion power and summons a regular TNT with that power when ignited

mental ibex
#

Solution that removes the need for the accessor and CustomTntBlock class. Not as extensible but like, idrc :D

neat mirage
# mental ibex 1. How can I render separate textures for the sides, top and bottom of a block? ...
  1. youd do that with just a simple block model, you can check out how the vanilla tnt one does it (assets/minecraft/models/block/tnt.json)
  2. the TntEntity has a public method to set the blockstate (setBlockState) to whatever you want (assuming youre on a new enough version), you can set this to the state of your custom tnt and it should render as that instead.
    you do need a reference to the TntEntity to call that method, id probably wrap operation the spawnEntity call in the TntBlock.primeTnt method. then you can check if this is an instance of your custom tnt and call the setBlockState method on the tnt entity
#

this is the method im talking about (its in mojmap sorry, but itd be the same)
PrimtedTnt is TntEntity
Level.addFreshEntity is World.spawnEntity

neat mirage
#

or if you do actually need a custom class, dont override every method just to put the vanilla code in there, only override what you need to

mental ibex
neat mirage
#

in that case you could also do that with a mixin, or if its easier an accesswidener to make that method public so you can override it

mental ibex
#

im assuming a mixin is better

neat mirage
#

for that youd mixin to the explosion using something like WrapMethod, check if this is your tnt block, and do whatever you need there, otherwise call original

mental ibex
#

ok thx <3

#

i got the textures working through the setBlockState thing btw so thanks for the help with that, im gonna setup the mixins for explosionpower now :D

neat mirage
#

awesome!

mental ibex
#

is there a way to access variables within the function? i need to use an accessor to change a value within the tntEntity object created in the function im mixing into and also call a function within it to change the block state

#

sry for asking a lot of questions btw im new to this

neat mirage
#

you can use @local to get method parameters or local variables

mental ibex
#

@At(value = "INVOKE", target = "Lsome/package/Player;isSneaking()Z") what exactly is that target path referring to? whats the formatting of that (like why is there L at beginning and Z at end, semicolon in the middle randomly etc)_

neat mirage
#

its called a method descriptor (i think), if youre using intellij then the mcdev plugin can autocomplete that for you (among other useful stuff)

#

!!mcdev

somber larkBOT
#
Minecraft Dev for IntelliJ (MCDEV)

MCDEV is an open source IntelliJ IDEA plugin that provides first class support for Minecraft development. It provides useful functionalities like Mixin method/target autocompletion, Mixin debugging capabilities and other common Fabric/Minecraft related inspections.

neat mirage
#

i think the Z at the end means it returns a boolean

mental ibex
#

ah ic it filled it in for me :D

#

i just had to tell it what func to look for

#

i got it working for flint and steel/lava/redstone detonation, i just have one last problem - if im hooking the onDestroyedByExplosion function the block has been destroyed - how would I check if it's my block and not normal tnt at that point?

neat mirage
#

this would still be a reference to the tnt block, so the same way as the primeTnt method

mental ibex
#

ah ic

neat mirage
#

its a bit unintuitive how it works, theres only ever 1 instance of each block in existence at all times. each block can have block states or block entities attached to them which is how they can have different states (like walls for example) or can store data unique to each block (like chests)

#

took me a while to get my head around that when i first started

mental ibex
#

when i use "this" in the mixin in comparison to a block class it uses this to refer to the mixin and not the block so they cant be compared, i dont know if it recognizes that im actually talking abt the TntBlock class im mixing in with

#

if(this == ModBlocks.COMPRESSED_TNT) incomparable types

neat mirage
#

that’s just because the ide and compiler don’t really know what a mixin is. At runtime this would be the actual TntBlock or your custom class, but not at compile time. You can get around it by casting like (Object) this instanceof CustomTntBlock for example

#

or (Object) this == ModBlocks.COMPRESSED_TNT

mental ibex
#

omg thank you so much i got everything working now <3

neat mirage
#

np :D

mental ibex
#

this is unrelated (loot table datagen) but for some reason i cant set seperate drops for silk touch and no silk touch? when i do

@Override
public void generate() {
    addDrop(ModBlocks.COMPRESSED_TNT, drops(Items.TNT)
            .apply(SetCountLootFunction.builder(ConstantLootNumberProvider.create(4))));

    addDropWithSilkTouch(ModBlocks.COMPRESSED_TNT);
}

it only applies the silk touch drop

#
{
  "type": "minecraft:block",
  "pools": [
    {
      "bonus_rolls": 0.0,
      "conditions": [
        {
          "condition": "minecraft:match_tool",
          "predicate": {
            "predicates": {
              "minecraft:enchantments": [
                {
                  "enchantments": "minecraft:silk_touch",
                  "levels": {
                    "min": 1
                  }
                }
              ]
            }
          }
        }
      ],
      "entries": [
        {
          "type": "minecraft:item",
          "name": "ekrimania:compressed_tnt"
        }
      ],
      "rolls": 1.0
    }
  ]
}

heres the output