-
Posts
10 -
Joined
-
Last visited
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
TheRealJaws's Achievements

Tree Puncher (2/8)
0
Reputation
-
SOLVED [1.19.2] How to attach a custom renderer to an item?
TheRealJaws replied to TheRealJaws's topic in Modder Support
Thanks for the help! Didn't know I could search github in this way, thats a huge help -
SOLVED [1.19.2] How to attach a custom renderer to an item?
TheRealJaws replied to TheRealJaws's topic in Modder Support
So I need a line like this correct? itemRenderer = new ItemRenderer(Minecraft.getInstance().getBlockEntityRenderDispatcher(),Minecraft.getInstance().getEntityModels()); and then a model with is isCustomRenderer set to true, with @Override public void initializeClient(Consumer<IClientItemExtensions> consumer) { consumer.accept(new IClientItemExtensions() { @Override public @Nullable Font getFont(ItemStack stack, FontContext context) { return IClientItemExtensions.super.getFont(stack, context); } @Override public BlockEntityWithoutLevelRenderer getCustomRenderer() { return workoutmc.itemRenderer; } }); on my item, and then where do I attach the model to the item? -
SOLVED [1.19.2] How to attach a custom renderer to an item?
TheRealJaws replied to TheRealJaws's topic in Modder Support
Thanks, yeah this should work, where should I create the instance for this, just in my main class? -
Hi there, I've been trying to figure this out but no luck so far, how do I attach a custom renderer to an item in 1.19? Do I need to do it indirectly by attaching an entity to the item and rendering that instead or something? I won't be able to accomplish what I want to do in the render with a .json model. Thanks
-
src/main/resources/data/xolcore/structures/test_schem.nbt is the location, full file is below, this is an item for placing structures that I am porting from 1.12, the use function is the function of note here package xol.core.item.basic; import net.minecraft.client.Minecraft; import net.minecraft.client.particle.Particle; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Rotations; import net.minecraft.core.Vec3i; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtIo; import net.minecraft.nbt.Tag; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.packs.resources.Resource; import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundSource; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Mirror; import net.minecraft.world.level.block.Rotation; import net.minecraft.world.level.levelgen.structure.BoundingBox; import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings; import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplateManager; import xol.core.XolCore; import xol.core.util.item.XolItemConfig; import java.io.IOException; import java.util.ArrayList; import java.util.Optional; import java.util.function.Predicate; public class ItemSchematicPlacer extends ItemBasic { public static final StructurePlaceSettings settings = (new StructurePlaceSettings()).setIgnoreEntities(true).setMirror(Mirror.NONE).setRotation(Rotation.NONE); private String schematic = ""; private int xOffset = 0; private int yOffset = 0; private int zOffset = 0; private ArrayList<Integer> heights = null; private SoundEvent playSound = null; private Particle particle = null; public ItemSchematicPlacer(XolItemConfig config, String schem){ super(config); config.stacksTo(1); this.schematic = schem; } public ItemSchematicPlacer(XolItemConfig config, String schem,int x, int y, int z) { this(config,schem); this.xOffset = x; this.yOffset = y; this.zOffset = z; } public ItemSchematicPlacer(XolItemConfig config, String schem,int x, int y, int z,ArrayList<Integer> heights) { this(config,schem,x,y,z); this.heights = heights; } public ItemSchematicPlacer(XolItemConfig config, String schem,ArrayList<Integer> heights) { this(config,schem); this.heights = heights; } public ItemSchematicPlacer(XolItemConfig config, String schem,int x, int y, int z,ArrayList<Integer> heights, SoundEvent sound, Particle particle) { this(config,schem,x,y,z,heights); this.playSound = sound; this.particle = particle; } @Override public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) { ItemStack stack = pPlayer.getItemInHand(pUsedHand); if (!pLevel.isClientSide() && !schematic.equals("")){ MinecraftServer mcServer = pLevel.getServer(); ServerLevel serverLevel = pLevel.getServer().getLevel(Level.OVERWORLD); StructureTemplateManager manager = serverLevel.getStructureManager(); ResourceLocation location = new ResourceLocation(XolCore.modId(), "structures/" +schematic); Optional<StructureTemplate> templatecheck= manager.get(location); CompoundTag tag; try { ResourceManager resourceManager = mcServer.getResourceManager(); Optional<Resource> rs = resourceManager.getResource(location); tag = NbtIo.readCompressed(rs.get().open()); } catch (Exception e) { return super.use(pLevel, pPlayer, pUsedHand); } StructureTemplate template = manager.readStructure(tag); if (template == null){ return super.use(pLevel, pPlayer, pUsedHand); } if (!stack.hasTag()){ stack.setTag(new CompoundTag()); } Direction facing = pPlayer.getDirection(); BlockPos pos = pPlayer.blockPosition(); Rotation rot = Rotation.NONE; if(stack.getTag().contains("rot")) { switch(stack.getTag().getInt("rot")) { case 0: rot = Rotation.NONE; break; case 1: rot = Rotation.CLOCKWISE_180; break; case 2: rot = Rotation.CLOCKWISE_90; break; case 3: rot = Rotation.COUNTERCLOCKWISE_90; break; default: rot = Rotation.NONE; } } else { int rotSet; switch (facing) { case NORTH: rot = Rotation.NONE; rotSet = 0; break; case SOUTH: rot = Rotation.CLOCKWISE_180; rotSet = 1; break; case EAST: rot = Rotation.CLOCKWISE_90; rotSet = 2; break; case WEST: rotSet = 3; rot = Rotation.COUNTERCLOCKWISE_90; break; default: rotSet = 0; rot = Rotation.NONE; break; } stack.getTag().putInt("rot", rotSet); } if (stack.getTag().contains("posX")) { pos = new BlockPos(stack.getTag().getInt("posX"),stack.getTag().getInt("posY"),stack.getTag().getInt("posZ")); }else { pos = pos.offset(xOffset, yOffset, zOffset); stack.getTag().putInt("posX",pos.getX()); stack.getTag().putInt("posY",pos.getY()); stack.getTag().putInt("posZ",pos.getZ()); } settings.setRotation(rot); if (this.heights == null) { template.placeInWorld(serverLevel.getLevel(),pos,new BlockPos(0,0,0),settings,pLevel.random,0); if (particle!=null) { Vec3i size = template.getSize(); BlockPos lowerBound; BlockPos upperBound; switch(rot) { case NONE: lowerBound = pos; upperBound = pos.offset(size.getX(),size.getY(),size.getZ()); break; case CLOCKWISE_180: lowerBound = pos.offset(-size.getX(),0,-size.getZ()); upperBound = pos.offset(0,size.getY(),0); break; case CLOCKWISE_90: lowerBound = pos.offset(-size.getX(),0,0); upperBound = pos.offset(0,size.getY(),size.getZ()); break; case COUNTERCLOCKWISE_90: lowerBound = pos.offset(0,0,-size.getZ()); upperBound = pos.offset(size.getX(),size.getY(),0); break; default: lowerBound = pos; upperBound = pos.offset(size.getX(),size.getY(),size.getZ()); break; } for (BlockPos templatePos: BlockPos.betweenClosed(lowerBound,upperBound)){ if (pLevel.random.nextInt(10)==0) { /* CustomParticleConfig config = new CustomParticleConfig(); config.createInstance() .setSpread(0.0F, 0.0F, 0.0F) .setParticle(particle) .setCount(1) .setIgnoreRange(true); ParticleSource.spawnParticle(worldIn, config, templatePos.getX(), templatePos.getY(), templatePos.getZ());*/ } } } if (playSound != null) { pLevel.playSound(null, pPlayer.blockPosition(), playSound, SoundSource.PLAYERS, 1, 1); } }else { CompoundTag compound = stack.getTag(); int curHeight = compound.getInt("height"); int index = compound.getInt("index"); if (index < this.heights.size()) { int height = this.heights.get(index); Vec3i size = template.getSize(); BoundingBox newBounds =new BoundingBox(pos.getX()-size.getX()*2,pos.getY()+curHeight,pos.getZ()-size.getZ()*2, size.getX()*2+pos.getX(),curHeight+height+pos.getY(),size.getZ()*2+pos.getZ()); settings.setBoundingBox(newBounds); if (particle!=null) { BlockPos lowerBound; BlockPos upperBound; switch(rot) { case NONE: lowerBound = pos; upperBound = pos.offset(size.getX(),0,size.getZ()); break; case CLOCKWISE_180: lowerBound = pos.offset(-size.getX(),0,-size.getZ()); upperBound = pos.offset(0,0,0); break; case CLOCKWISE_90: lowerBound = pos.offset(-size.getX(),0,0); upperBound = pos.offset(0,0,size.getZ()); break; case COUNTERCLOCKWISE_90: lowerBound = pos.offset(0,0,-size.getZ()); upperBound = pos.offset(size.getX(),0,0); break; default: lowerBound = pos; upperBound = pos.offset(size.getX(),0,size.getZ()); break; } for (BlockPos templatePos: BlockPos.betweenClosed(lowerBound.offset(0,curHeight,0),upperBound.offset(0,curHeight+height,0))){ if (pLevel.random.nextInt(30)==0) { /* CustomParticleConfig config = new CustomParticleConfig(); config.createInstance() .setSpread(0.0F, 0.0F, 0.0F) .setParticle(particle) .setCount(1) .setIgnoreRange(true); ParticleSource.spawnParticle(worldIn, config, templatePos.getX(), templatePos.getY(), templatePos.getZ());*/ } } } template.placeInWorld(serverLevel.getLevel(),pos,new BlockPos(0,0,0),settings,pLevel.random,0); compound.putInt("height", height+curHeight); compound.putInt("index", index+1); } pLevel.playSound(null, pPlayer.blockPosition(), playSound, SoundSource.PLAYERS, 1, 1); } } return super.use(pLevel, pPlayer, pUsedHand); } }
-
Hi there, I was hoping someone may be able to help, I have some fairly straightforward( I think?) code to attempt to read a structure template from an nbt resource. Getting Optional.empty returned from the getResource() call, and I can't figure out why I've triple checked the resource location, it is correct (and it worked when getting from Minecraft.getInstance().getResourceManager().getResource(location) on the client side, but I need this to work server side) Is there something im missing in terms of getting the server side Resource Manager? I previously tried what used to be the method when I was working in 1.12.2 which was using the StructureTemplateManager.get(location) to directly load the template from the resource location but this also returned Optional.empty for me. MinecraftServer mcServer = pLevel.getServer(); ServerLevel serverLevel = pLevel.getServer().getLevel(Level.OVERWORLD); StructureTemplateManager manager = serverLevel.getStructureManager(); ResourceLocation location = new ResourceLocation(XolCore.modId() + ":structures/" +schematic); CompoundTag tag; try { ResourceManager resourceManager = mcServer.getResourceManager(); Optional<Resource> rs = resourceManager.getResource(location); tag = NbtIo.readCompressed(rs.get().open()); } catch (Exception e) { return super.use(pLevel, pPlayer, pUsedHand); }