FledgeXu
Members-
Posts
12 -
Joined
-
Last visited
Everything posted by FledgeXu
-
@ChampionAsh5357 ,Thanks very mush. The most of your advise is useful and your review is amazing. However, I want to explain some things in this tutorial. 1. The useless Class I know these classes looks like useless for programmers who are experinced. But, as my practice I found that using separate class can help newcomers understand code better. So I will not change it. 2. The data generation Actually, I will introduce the Data generation in one chapter. I believe if people can not write json by hand and they will not understand the Data generation. Besides, In some case, people still need write json by hand. 3. About Event registry and other things The top consider for me is translation, I will add contexts and explains latter when I translated this tutorial. 4. About Code Styple. This tutorial actually be written in very short time. I will do full check about the code style. Anyway, Thank you for your advises.
-
Hey Everyone, this is FledgeShiu. I bring the 1.16.3 Modding Tutorial. This Tutorial is translated from my same name tutorial which written by Chinese. I’m not a native English Speaker. So that, this tutorial may have a lot of grammar and words problems. If you find any problem please tell me. If you have any question or feedback, welcome join my Discord Server . Notice: It's still in translation. Tutorial Link 1. Introducation 1.1. What is Forge? 1.2. How Minecraft Works? 1.3. Development Model 1.4. Core Concepetion 2. Development Environment 2.1. Setup Environment 2.2. Introduce Environment 2.3. Customize Mod Info 3. Item 3.1. First Item 3.2. Model and Texture 3.3. Item and ItemStack 3.4. Item Group 3.5. Food 3.6. Sword 3.7. Tool 3.8. Armor 3.9. Item Property Override 4. Localization 5. Block 5.1. First Block 5.2. Block and BlockState 5.3. Block's Model and Texture 5.4. Block with BlockState 5.5. Not Solid Block and custom model 5.6. Render Type 6. Special Model 6.1. Obj Model 7. TileEntity 7.1. First TileEntity and Data Storage 7.2. ITickableTileEntity 7.3. TileEntity's Data Sync 8. Special render 8.1. IBakedModel 8.2. TileEntityRneder 8.3. ItemStackTileEntityRenderer 9. Event System 10. Network 10.1. Network Packet 10.2. Network Security 11. Entity 11.1. First Entity and Data Sync 11.2. Animal and AI 12. Capability System 12.1. Capability from Scratch 12.2. Use Predefined Capability 12.3. Attach Capability provider 13. WorldSavedData 14. Gui 14.1. First Gui 14.2. Container 14.3. HUD 15. Fluid 16. World Generation 16.1. Ore Generation 16.2. Structure Generation 16.3. Customize Biome and World Type 16.4. Customize Dimension 17. Data Pack 17.1. Recipe 17.2. LootTable 18. Data Generator 19. Command 20. Advancements 21. Configure 22. Potion 23. Paticle 24. Sound 25. User Input 26. Compatibiilty 27. Access Transformer 28. CoreMod
-
I start a serial of Modding tutorial video, which will include Item, Block, TileEntity, special rendering, Entity, World Generation and so on. There is the link:YoutubePlayList. If you have any questions to ask, Welcome join my Discord Server. You can find the source code in there. context: Minecraft 1.16 Modding Tutorial - Setup Environment Minecraft 1.16 Modding Tutorial - Item
-
Thanks, BasicParticleType is a convenient class.
-
Maybe you are right, I should use the TexturedParticle. I want to create a lighting circle and don't think i need the TexturedParticle for this, that's why I don't use the TexturedParticle.
-
@hiotewdew Thanks for replying. I add the lineWidth to my IParticleRenderType. public class ObsidianParticleRenderType implements IParticleRenderType { public static final ObsidianParticleRenderType INSTANCE = new ObsidianParticleRenderType(); @Override public void beginRender(BufferBuilder bufferBuilder, TextureManager textureManager) { RenderSystem.lineWidth(10.0F); RenderSystem.disableLighting(); RenderSystem.disableDepthTest(); RenderSystem.disableCull(); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); bufferBuilder.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION_COLOR); } @Override public void finishRender(Tessellator tessellator) { tessellator.draw(); } } But It's still not working. Could you give some example code?
-
@TheGreyGhost, I want to render a particle which is just a simple line. But nothing shows in Game.
-
Introduce: I'm working on making a custom particle from scratch. I want to render a particle which is just a simple line, but nothing shows in game. There are my codes. ObsidianParticle.java public class ObsidianParticle extends Particle { protected ObsidianParticle(World worldIn, double posXIn, double posYIn, double posZIn) { super(worldIn, posXIn, posYIn, posZIn); } @Override public void renderParticle(IVertexBuilder buffer, ActiveRenderInfo renderInfo, float partialTicks) { buffer.pos(0, 0, 0) .color(1, 0, 0, 1) .endVertex(); buffer.pos(1, 0, 0) .color(1, 0, 0, 1) .endVertex(); buffer.pos(1, 1, 0) .color(1, 0, 0, 1) .endVertex(); buffer.pos(1, 1, 1) .color(1, 0, 0, 1) .endVertex(); } @Override public IParticleRenderType getRenderType() { return ObsidianParticleRenderType.INSTANCE; } } ObsidianParticleRenderType.java public class ObsidianParticleRenderType implements IParticleRenderType { public static final ObsidianParticleRenderType INSTANCE = new ObsidianParticleRenderType(); @Override public void beginRender(BufferBuilder bufferBuilder, TextureManager textureManager) { RenderSystem.disableLighting(); RenderSystem.disableDepthTest(); RenderSystem.disableCull(); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); bufferBuilder.begin(GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION_COLOR); } @Override public void finishRender(Tessellator tessellator) { tessellator.draw(); } } ClientSideRegistry.java @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) public class ClientSideRegistry { @SubscribeEvent public static void onParticleFactoryRegistration(ParticleFactoryRegisterEvent event) { Minecraft.getInstance().particles.registerFactory(ParticleTypeRegistry.obsidianParticleType.get(), new ObsidianParticleFactory()); } } ObsidianParticleData.java public class ObsidianParticleData implements IParticleData { public static final IParticleData.IDeserializer<ObsidianParticleData> DESERIALIZER = new IDeserializer<ObsidianParticleData>() { @Override public ObsidianParticleData deserialize(ParticleType<ObsidianParticleData> particleTypeIn, StringReader reader) { return new ObsidianParticleData(); } @Override public ObsidianParticleData read(ParticleType<ObsidianParticleData> particleTypeIn, PacketBuffer buffer) { return new ObsidianParticleData(); } }; @Override public ParticleType<?> getType() { return ParticleTypeRegistry.obsidianParticleType.get(); } @Override public void write(PacketBuffer buffer) { } @Override public String getParameters() { return ""; } } ObsidianParticleFactory.java public class ObsidianParticleFactory implements IParticleFactory<ObsidianParticleData> { @Nullable @Override public Particle makeParticle(ObsidianParticleData typeIn, World worldIn, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) { return new ObsidianParticle(worldIn, x, y, z); } } ParticleTypeRegistry.java public class ParticleTypeRegistry { public static final DeferredRegister<ParticleType<?>> PARTICLE_TYPE = new DeferredRegister<>(ForgeRegistries.PARTICLE_TYPES, ModConstants.MOD_ID); public static final RegistryObject<ObsidianParticleType> obsidianParticleType = PARTICLE_TYPE.register("obsidian_particle", ObsidianParticleType::new); } ObsidianParticleType.java public class ObsidianParticleType extends ParticleType<ObsidianParticleData> { public ObsidianParticleType() { super(false, ObsidianParticleData.DESERIALIZER); } }
-
[1.15.2] TileEntity in Client Side can't read the NBT Data.
FledgeXu replied to FledgeXu's topic in Modder Support
Thanks Grey. I just solved this problem. I forge to override the getUpdateTag. Thank you anyway -
I write a TileEntity which holds the data in Server side. The server side data sync to client side by getUpdatePacket and onDataPacket. If I exit the Game save and enter it again, The Client Side TileEntity can't get NBT data by read(CompoundNBT compound). But after l put or get Item from the TileEntity, the Data will be synced. How can I let the Client Side TileEntity get the NBT data when the Saves load. Here is my code. AlchemyFurnaceBlockEntity.java package com.otakusaikou.spiritcraft.block.blockentity; import com.otakusaikou.spiritcraft.registry.BlockEntityTypeRegistry; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.INBT; import net.minecraft.nbt.ListNBT; import net.minecraft.network.NetworkManager; import net.minecraft.network.play.server.SUpdateTileEntityPacket; import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; import net.minecraftforge.common.util.Constants; import javax.annotation.Nullable; import java.util.HashMap; import java.util.Map; public class AlchemyFurnaceBlockEntity extends TileEntity implements ITickableTileEntity { private final Map<Direction, ItemStack> itemStackMap = new HashMap<>(); private int i = 10; public AlchemyFurnaceBlockEntity() { super(BlockEntityTypeRegistry.alchemyFurnaceBlockEntityType.get()); } public Map<Direction, ItemStack> getItemStackMap() { return itemStackMap; } public boolean putItem(Direction direction, Item item) { if (itemStackMap.containsKey(direction)) { return false; } ItemStack itemStack = new ItemStack(item); itemStackMap.put(direction, itemStack); world.notifyBlockUpdate(pos, getBlockState(), getBlockState(), Constants.BlockFlags.BLOCK_UPDATE); markDirty(); return true; } public boolean isExist(Direction direction) { return itemStackMap.containsKey(direction); } public ItemStack getItem(Direction direction) { ItemStack itemStack = itemStackMap.get(direction); itemStackMap.remove(direction); world.notifyBlockUpdate(pos, getBlockState(), getBlockState(), Constants.BlockFlags.BLOCK_UPDATE); markDirty(); return itemStack; } @Nullable @Override public SUpdateTileEntityPacket getUpdatePacket() { ListNBT listNBT = new ListNBT(); for (Map.Entry<Direction, ItemStack> entry : itemStackMap.entrySet()) { CompoundNBT compoundNBT = new CompoundNBT(); compoundNBT.putString("direction", entry.getKey().getName()); compoundNBT.put("itemstack", entry.getValue().serializeNBT()); listNBT.add(compoundNBT); } CompoundNBT compoundNBT = new CompoundNBT(); compoundNBT.put("stacks", listNBT); return new SUpdateTileEntityPacket(pos, 1, compoundNBT); } @Override public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) { if (world.isRemote) { CompoundNBT compoundNBT = pkt.getNbtCompound(); INBT inbt = compoundNBT.get("stacks"); if (inbt instanceof ListNBT) { ListNBT listNBT = (ListNBT) inbt; for (int i = 0; i < listNBT.size(); i++) { CompoundNBT tag = (CompoundNBT) listNBT.get(i); Direction direction = getDirection(tag.getString("direction")); ItemStack itemStack = ItemStack.read(tag.getCompound("itemstack")); itemStackMap.put(direction, itemStack); markDirty(); } } } } private Direction getDirection(String name) { for (Direction direction : Direction.values()) { if (direction.toString().equals(name)) { return direction; } } throw new IllegalArgumentException("Not find the direction"); } @Override public void tick() { // if (!world.isRemote) { // if (i == 0) { // world.notifyBlockUpdate(pos, getBlockState(), getBlockState(), Constants.BlockFlags.BLOCK_UPDATE); // i = 10; // } // i--; // } } @Override public void read(CompoundNBT compound) { INBT inbt = compound.get("stacks"); if (inbt instanceof ListNBT) { ListNBT listNBT = (ListNBT) inbt; for (int i = 0; i < listNBT.size(); i++) { CompoundNBT tag = (CompoundNBT) listNBT.get(i); Direction direction = getDirection(tag.getString("direction")); ItemStack itemStack = ItemStack.read(tag.getCompound("itemstack")); itemStackMap.put(direction, itemStack); } } super.read(compound); } @Override public CompoundNBT write(CompoundNBT compound) { ListNBT listNBT = new ListNBT(); for (Map.Entry<Direction, ItemStack> entry : itemStackMap.entrySet()) { CompoundNBT compoundNBT = new CompoundNBT(); compoundNBT.putString("direction", entry.getKey().getName()); compoundNBT.put("itemstack", entry.getValue().serializeNBT()); listNBT.add(compoundNBT); } compound.put("stacks", listNBT); return super.write(compound); } } AlchemyFurnace.java package com.otakusaikou.spiritcraft.block; import com.otakusaikou.spiritcraft.block.blockentity.AlchemyFurnaceBlockEntity; import com.otakusaikou.spiritcraft.util.Utils; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.material.Material; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ActionResultType; import net.minecraft.util.Direction; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; import javax.annotation.Nullable; public class AlchemyFurnace extends Block { public AlchemyFurnace() { super(Properties.create(Material.ROCK).harvestLevel(0).hardnessAndResistance(5).notSolid()); } //TODO: change default the vertex shape @Override public boolean hasTileEntity(BlockState state) { return true; } @Nullable @Override public TileEntity createTileEntity(BlockState state, IBlockReader world) { return new AlchemyFurnaceBlockEntity(); } @Override public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) { if (Utils.isServerSide(worldIn) && handIn == Hand.MAIN_HAND) { TileEntity tileEntity = worldIn.getTileEntity(pos); Direction face = hit.getFace(); if (tileEntity instanceof AlchemyFurnaceBlockEntity) { AlchemyFurnaceBlockEntity alchemyFurnaceBlockEntity = (AlchemyFurnaceBlockEntity) tileEntity; ItemStack inputItemStack = player.getHeldItem(Hand.MAIN_HAND); if (inputItemStack.isEmpty()) { if (alchemyFurnaceBlockEntity.isExist(face)) { ItemStack itemStack = alchemyFurnaceBlockEntity.getItem(face); player.setHeldItem(Hand.MAIN_HAND, itemStack); } } else { ItemStack handItem = player.getHeldItem(Hand.MAIN_HAND); if (alchemyFurnaceBlockEntity.putItem(face, handItem.getItem())) { if (handItem.getCount() > 1) { handItem.setCount(handItem.getCount() - 1); player.setHeldItem(Hand.MAIN_HAND, handItem); } else { player.setHeldItem(Hand.MAIN_HAND, ItemStack.EMPTY); } } } } } return ActionResultType.SUCCESS; } }
-
Should Override hasTileEntity(BlockState state) not hasTileEntity()
- 1 reply
-
- 1
-
Minecraft Version: 1.14.4 Forge: 28.1.0 I've tried to set breakpoint in createTileEntity, But It didn't trigger. ModBlocks.java package com.otakusaikou.tour14.blocks; import net.minecraft.tileentity.TileEntityType; import net.minecraftforge.registries.ObjectHolder; public class ModBlocks { public static ObsidianBlock obsidianBlock = new ObsidianBlock(); @ObjectHolder("tour14:obsidian_block") public static TileEntityType<?> OBSIDIANBLOCK; } ObsidianBlock.java package com.otakusaikou.tour14.blocks; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.entity.LivingEntity; import net.minecraft.item.ItemStack; import net.minecraft.state.StateContainer; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; import net.minecraftforge.common.extensions.IForgeBlock; import javax.annotation.Nullable; public class ObsidianBlock extends Block { public ObsidianBlock() { super(Properties.create(Material.ROCK) .harvestLevel(3) .sound(SoundType.STONE) .hardnessAndResistance(5f) ); this.setRegistryName("obsidian_block"); } @Override public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) { super.onBlockPlacedBy(worldIn, pos, state, placer, stack); if(placer != null){ worldIn.setBlockState(pos, state.with(BlockStateProperties.FACING, getFacingFromEntity(pos, placer)),2); } } public static Direction getFacingFromEntity(BlockPos placedBlock, LivingEntity entity) { Vec3d vec = entity.getPositionVec(); return Direction.getFacingFromVector((float) (vec.x - placedBlock.getX()), (float) (vec.y - placedBlock.getY()), (float) (vec.z - placedBlock.getZ()) ); } @Override protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) { super.fillStateContainer(builder); builder.add(BlockStateProperties.FACING); } @Override public boolean hasTileEntity() { return true; } @Nullable @Override public TileEntity createTileEntity(BlockState state, IBlockReader world) { return new ObsidianBlockTileEntity(); } } ObsidianBlockTileEntity.java package com.otakusaikou.tour14.blocks; import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; public class ObsidianBlockTileEntity extends TileEntity implements ITickableTileEntity { public ObsidianBlockTileEntity() { super(ModBlocks.OBSIDIANBLOCK); } @Override public void tick() { System.out.println("It's test tick!"); } } RegistryHandler.java package com.otakusaikou.tour14.util; import com.otakusaikou.tour14.blocks.ModBlocks; import com.otakusaikou.tour14.blocks.ObsidianBlockTileEntity; import com.otakusaikou.tour14.items.ModItems; import net.minecraft.block.Block; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityType; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD) public class RegistryHandler { @SubscribeEvent public static void onBlocksRegistry(RegistryEvent.Register<Block> event) { event.getRegistry().register(ModBlocks.obsidianBlock); } @SubscribeEvent public static void onItemsRegistry(RegistryEvent.Register<Item> event){ event.getRegistry().register(ModItems.obsidianIngot); event.getRegistry().register(new BlockItem(ModBlocks.obsidianBlock, new Item.Properties().group(Utils.itemGroup)) .setRegistryName(ModBlocks.obsidianBlock.getRegistryName()) ); } @SubscribeEvent public static void onTileEntityRegistry(RegistryEvent.Register<TileEntityType<?>> event) { event.getRegistry().register(TileEntityType.Builder.create(ObsidianBlockTileEntity::new, ModBlocks.obsidianBlock).build(null).setRegistryName("obsidian_block")); } }