Jump to content

Recommended Posts

Posted

So I make a Block,when player use it int Debug in BlockEntity add one and print it with System.out.println(entity.Debug);

For some reason the BlockEntity print 1 while BlockEntityRenderer print 0

Registration:

@Mod(ExtraSpicy.MOD_ID)
public class ExtraSpicy
{
    // Directly reference a log4j logger.
    public static final String MOD_ID = "extraspicy";
    private static final Logger LOGGER = LogManager.getLogger();

    public ExtraSpicy() {
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::AttributeRegister);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::ModelRegister);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::LayerRegister);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::RenderRegister);
        Registration.register();
        MinecraftForge.EVENT_BUS.register(this);
    }
    //Register Model Layer Render here!!!
    public void AttributeRegister(EntityAttributeCreationEvent event){
        event.put(Registration.Entity_exoft.get(), ExoFT.createMobAttributes().build());
    }
    public void ModelRegister(ModelRegistryEvent event)
    {
        ForgeModelBakery.addSpecialModel(new ResourceLocation(ExtraSpicy.MOD_ID,"effect/sphere"));
        ForgeModelBakery.addSpecialModel(new ResourceLocation(ExtraSpicy.MOD_ID,"effect/invsphere"));
    }
    public void LayerRegister(EntityRenderersEvent.RegisterLayerDefinitions event){
        event.registerLayerDefinition(ExoTridentModel.LAYER_LOCATION,ExoTridentModel::createBodyLayer);
        event.registerLayerDefinition(ExoFTModel.LAYER_LOCATION,ExoFTModel::createBodyLayer);
    }
    public void RenderRegister(EntityRenderersEvent.RegisterRenderers event)
    {
        event.registerBlockEntityRenderer(Registration.BlockEntity_electrolysis.get(), ElectrolysisRender::new);
        EntityRenderers.register(Registration.Entity_exotrident.get(), ExoTridentRender::new);
        EntityRenderers.register(Registration.Entity_exoft.get(), ExoFTRender::new);
    }
}
public class Registration {
    public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, ExtraSpicy.MOD_ID);
    public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, ExtraSpicy.MOD_ID);
    public static final DeferredRegister<EntityType<?>> ENTITY = DeferredRegister.create(ForgeRegistries.ENTITIES, ExtraSpicy.MOD_ID);
    public static final DeferredRegister<BlockEntityType<?>> Block_ENTITY = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITIES, ExtraSpicy.MOD_ID);

    public static void register(){
        IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
        BLOCKS.register(modEventBus);
        ITEMS.register(modEventBus);
        ENTITY.register(modEventBus);
        Block_ENTITY.register(modEventBus);
    }
    //Register Item Entity Tab here!!!
    public static final CreativeModeTab TAB = new CreativeModeTab(ExtraSpicy.MOD_ID) {
        @Nonnull
        @Override
        public ItemStack makeIcon() {
            return new ItemStack(Item_exocore.get());
        }
    };
    public static RegistryObject<Block> Block_electrolysis = BLOCKS.register("electrolysis",() -> new Electrolysis(BlockBehaviour.Properties.copy(Blocks.QUARTZ_BLOCK).noOcclusion().dynamicShape()));

    public static RegistryObject<Item> Item_coke = ITEMS.register("coke",() -> new Item(new Item.Properties().tab(TAB)));
    public static RegistryObject<Item> Item_quartzcoke = ITEMS.register("quartzcoke",() -> new Item(new Item.Properties().tab(TAB)));
    public static RegistryObject<Item> Item_silicon = ITEMS.register("silicon",() -> new Item(new Item.Properties().tab(TAB)));
    public static RegistryObject<Item> Item_exocoreshell = ITEMS.register("exo_core_shell",() -> new Item(new Item.Properties().tab(TAB)));
    public static RegistryObject<Item> Item_exocore = ITEMS.register("exo_core",() -> new Item(new Item.Properties().tab(TAB)));
    public static RegistryObject<Item> Item_exotrident = ITEMS.register("exo_trident", () -> new ExoTrident());
    public static RegistryObject<Item> Item_block_electrolysis = ITEMS.register("electrolysis",() -> new BlockItem(Block_electrolysis.get(), new Item.Properties().tab(TAB)));

    public static final RegistryObject<BlockEntityType<ElectrolysisEntity>> BlockEntity_electrolysis = Block_ENTITY.register("electrolysis",() -> BlockEntityType.Builder.of(ElectrolysisEntity::new, Registration.Block_electrolysis.get()).build(null));

    public static RegistryObject<EntityType<ExoTridentEntity>> Entity_exotrident = ENTITY.register("exo_trident_entity",() ->  EntityType.Builder.<ExoTridentEntity>of(ExoTridentEntity::new, MobCategory.MISC).sized(0.5F, 0.5F).clientTrackingRange(4).updateInterval(20).build(new ResourceLocation(ExtraSpicy.MOD_ID, "exo_trident_entity").toString()));
    public static RegistryObject<EntityType<ExoFT>> Entity_exoft = ENTITY.register("exo_ft",() -> EntityType.Builder.<ExoFT>of(ExoFT::new, MobCategory.MISC).sized(0.5F, 0.5F).fireImmune().build(new ResourceLocation(ExtraSpicy.MOD_ID, "exo_ft").toString()));
}

Block:

public class Electrolysis extends AbstractGlassBlock implements EntityBlock {
    protected static final VoxelShape SHAPE = Shapes.or(Block.box(1.0D, 0.0D, 1.0D, 14.0D, 13.0D, 14.0D));

    public Electrolysis(Properties properties){
        super(properties);
    }

    @Override
    public BlockEntity newBlockEntity(BlockPos pos, BlockState state){
        return new ElectrolysisEntity(pos,state);
    }

    @Override
    public RenderShape getRenderShape(BlockState state){
        return RenderShape.ENTITYBLOCK_ANIMATED;
    }    public VoxelShape getShape(BlockState p_50952_, BlockGetter p_50953_, BlockPos p_50954_, CollisionContext p_50955_) {
        return SHAPE;
    }
    @Override
    public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand,
                                 BlockHitResult result) {
        if (!level.isClientSide && level.getBlockEntity(pos) instanceof ElectrolysisEntity) {
            if (!player.isCrouching()) {
                if(player.getItemInHand(hand).getItem() == Items.AIR){
                    //Take item out
                    ((ElectrolysisEntity) level.getBlockEntity(pos)).prependItem(player);
                }else{
                    //Put item in
                    ((ElectrolysisEntity) level.getBlockEntity(pos)).appendItem(player.getItemInHand(hand));
                }
            }
        }

        return InteractionResult.SUCCESS;
    }
}

BlockEntity:


public class ElectrolysisEntity extends BlockEntity {
    int Debug = 0;
    public ElectrolysisEntity(BlockPos p_153215_, BlockState p_153216_) {
        super(Registration.BlockEntity_electrolysis.get(),p_153215_,p_153216_);
    }
    public void prependItem(Player player) {
        Debug += 1;
        requestModelDataUpdate();
        setChanged();
        load(getTileData());
        if (this.level != null) {
            this.level.setBlockAndUpdate(this.worldPosition, getBlockState());
        }
    }
    public void appendItem(ItemStack stack) {
        Debug -= 1;
        requestModelDataUpdate();
        setChanged();
        getTileData();
        if (this.level != null) {
            this.level.setBlockAndUpdate(this.worldPosition, getBlockState());
        }
    }
    @Override
    public void load(CompoundTag compound) {
        System.out.println("------------------------------------------------------------------");
        final CompoundTag inventory = compound.getCompound("Inventory");
        Debug = inventory.getInt("Int");
    }
    @Override
    public void saveAdditional(CompoundTag compound) {
        System.out.println("////////////////////////////////////////////////////////////////");
        final var inventory = new CompoundTag();
        inventory.putInt("Int", Debug);
        compound.put("Inventory", inventory);
    }

    @Override
    public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) {
        handleUpdateTag(pkt.getTag());
    }

    @Override
    public Packet<ClientGamePacketListener> getUpdatePacket() {
        return ClientboundBlockEntityDataPacket.create(this);
    }

    @Override
    public CompoundTag getUpdateTag() {
        return serializeNBT();
    }

    @Override
    public void handleUpdateTag(CompoundTag tag) {
        super.handleUpdateTag(tag);
        load(tag);
    }
}

BlockEntityRenderer:

public class ElectrolysisRender implements BlockEntityRenderer<ElectrolysisEntity> {
    private final BlockEntityRendererProvider.Context context;
    public ElectrolysisRender(BlockEntityRendererProvider.Context context){
        this.context = context;
    }
    @Override
    public void render(ElectrolysisEntity entity, float partialTicks, PoseStack matrixStack, MultiBufferSource buffer, int combinedOverlay, int packedLight) {
        final BlockRenderDispatcher dispatcher = this.context.getBlockRenderDispatcher();
        final ItemRenderer itemRender = Minecraft.getInstance().getItemRenderer();
        matrixStack.pushPose();
        matrixStack.scale(0.5F,0.5F,0.5F);
        matrixStack.translate(0.7F,1.5F,1F);
        matrixStack.mulPose(Vector3f.XN.rotationDegrees(180F));
        itemRender.renderStatic(Minecraft.getInstance().player,Items.GLASS_BOTTLE.getDefaultInstance(), ItemTransforms.TransformType.FIXED,false,matrixStack,buffer,Minecraft.getInstance().level,combinedOverlay,packedLight,packedLight);
        matrixStack.popPose();

        matrixStack.pushPose();
        matrixStack.scale(0.5F,0.5F,0.5F);
        matrixStack.translate(1.3F,1.5F,1F);
        matrixStack.mulPose(Vector3f.XN.rotationDegrees(180F));
        itemRender.renderStatic(Minecraft.getInstance().player,Items.GLASS_BOTTLE.getDefaultInstance(), ItemTransforms.TransformType.FIXED,false,matrixStack,buffer,Minecraft.getInstance().level,combinedOverlay,packedLight,packedLight);
        matrixStack.popPose();

        matrixStack.pushPose();
        matrixStack.scale(0.8F,0.8F,0.8F);
        matrixStack.translate(0.1F,0,0.1F);
        dispatcher.renderSingleBlock(Blocks.GLASS.defaultBlockState(),matrixStack,buffer,combinedOverlay,packedLight, EmptyModelData.INSTANCE);
        matrixStack.popPose();

        System.out.println(entity.Debug);
            matrixStack.pushPose();
            matrixStack.scale(0.75F,0.6F,0.75F);
            matrixStack.translate(0.15F,0,0.15F);
            dispatcher.renderSingleBlock(Blocks.ICE.defaultBlockState(),matrixStack,buffer,combinedOverlay,packedLight, EmptyModelData.INSTANCE);
            matrixStack.popPose();
    }
}

 

Posted (edited)

I remove the junk code you talk about but I still dont understand the load method thing

you mean something like this???

  Quote

@Override public void load(CompoundTag compound) { 

final CompoundTag inventory = compound.getCompound("Inventory"); Debug = inventory.getInt("Int");

super.load(compound);

}

Expand  

Any example?

Edited by Cyanki
Posted (edited)
public class ElectrolysisEntity extends BlockEntity {
    int Debug = 0;
    public ElectrolysisEntity(BlockPos p_153215_, BlockState p_153216_) {
        super(Registration.BlockEntity_electrolysis.get(),p_153215_,p_153216_);
    }
    public void prependItem(Player player) {
        Debug += 1;
        setChanged();
    }
    public void appendItem(ItemStack stack) {
        Debug -= 1;
        setChanged();
    }
    @Override
    public void load(CompoundTag compound) {
        final CompoundTag inventory = compound.getCompound("Inventory");
        Debug = inventory.getInt("Int");
        super.load(compound);
    }
    @Override
    public void saveAdditional(CompoundTag compound) {
        final var inventory = new CompoundTag();
        inventory.putInt("Int", Debug);
        compound.put("Inventory", inventory);
    }

    @Override
    public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) {
        handleUpdateTag(pkt.getTag());
    }

    @Override
    public Packet<ClientGamePacketListener> getUpdatePacket() {
        return ClientboundBlockEntityDataPacket.create(this);
    }
    @Override
    public void handleUpdateTag(CompoundTag tag) {
        super.handleUpdateTag(tag);
        load(tag);
    }
}
  On 2/22/2022 at 5:18 PM, diesieben07 said:

Please post updated code

Expand  

 

Edited by Cyanki
Posted
[01:20:59] [Render thread/FATAL]: Error executing task on Client
java.lang.NullPointerException: Cannot invoke "net.minecraft.nbt.CompoundTag.getCompound(String)" because "compound" is null
	at org.Tanki.extraspicy.common.Electrolysis.ElectrolysisEntity.load(ElectrolysisEntity.java:49) ~[%2381!:?]
	at net.minecraftforge.common.extensions.IForgeBlockEntity.handleUpdateTag(IForgeBlockEntity.java:88) ~[forge-1.18-38.0.17_mapped_official_1.18-recomp.jar%2376%2382!:?]
	at org.Tanki.extraspicy.common.Electrolysis.ElectrolysisEntity.handleUpdateTag(ElectrolysisEntity.java:71) ~[%2381!:?]
	at org.Tanki.extraspicy.common.Electrolysis.ElectrolysisEntity.onDataPacket(ElectrolysisEntity.java:62) ~[%2381!:?]
	at net.minecraft.client.multiplayer.ClientPacketListener.lambda$handleBlockEntityData$4(ClientPacketListener.java:999) ~[forge-1.18-38.0.17_mapped_official_1.18-recomp.jar%2377!:?]
	at java.util.Optional.ifPresent(Optional.java:178) ~[?:?]
	at net.minecraft.client.multiplayer.ClientPacketListener.handleBlockEntityData(ClientPacketListener.java:998) ~[forge-1.18-38.0.17_mapped_official_1.18-recomp.jar%2377!:?]
	at net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket.handle(ClientboundBlockEntityDataPacket.java:46) ~[forge-1.18-38.0.17_mapped_official_1.18-recomp.jar%2377!:?]
	at net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket.handle(ClientboundBlockEntityDataPacket.java:13) ~[forge-1.18-38.0.17_mapped_official_1.18-recomp.jar%2377!:?]
	at net.minecraft.network.protocol.PacketUtils.lambda$ensureRunningOnSameThread$0(PacketUtils.java:21) ~[forge-1.18-38.0.17_mapped_official_1.18-recomp.jar%2377!:?]
	at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:139) ~[forge-1.18-38.0.17_mapped_official_1.18-recomp.jar%2377!:?]
	at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:22) ~[forge-1.18-38.0.17_mapped_official_1.18-recomp.jar%2377!:?]
	at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:112) ~[forge-1.18-38.0.17_mapped_official_1.18-recomp.jar%2377!:?]
	at net.minecraft.util.thread.BlockableEventLoop.runAllTasks(BlockableEventLoop.java:100) ~[forge-1.18-38.0.17_mapped_official_1.18-recomp.jar%2377!:?]
	at net.minecraft.client.Minecraft.runTick(Minecraft.java:1009) ~[forge-1.18-38.0.17_mapped_official_1.18-recomp.jar%2377!:?]
	at net.minecraft.client.Minecraft.run(Minecraft.java:660) ~[forge-1.18-38.0.17_mapped_official_1.18-recomp.jar%2377!:?]
	at net.minecraft.client.main.Main.main(Main.java:205) ~[forge-1.18-38.0.17_mapped_official_1.18-recomp.jar%2377!:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?]
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]
	at net.minecraftforge.fml.loading.targets.ForgeClientUserdevLaunchHandler.lambda$launchService$0(ForgeClientUserdevLaunchHandler.java:38) ~[fmlloader-1.18-38.0.17.jar%230!:?]
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-9.0.24.jar%2310!:?]
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-9.0.24.jar%2310!:?]
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-9.0.24.jar%2310!:?]
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-9.0.24.jar%2310!:?]
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-9.0.24.jar%2310!:?]
	at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-9.0.24.jar%2310!:?]
	at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-9.0.24.jar%2310!:?]
	at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:90) [bootstraplauncher-0.1.17.jar:?]

Just see this in debug

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Betafort Recovery has emerged as a prominent figure in the realm of cryptocurrency recovery, gaining a reputation for their exceptional ability to retrieve lost Bitcoin (BTC) and other cryptocurrencies. Their expertise and track record have made them a beacon of hope for individuals facing the distressing situation of lost or inaccessible crypto assets.  
    • When you name a method like that, with no return value, it is a constructor. The constructor must have the same name as the class it constructs, in this case, ModItems. I would strongly advise reading up on some basic Java tutorials, because you will definitely be running into a lot more issues as you go along without the basics. *I should also add that the Forge documentation is a reference, not a tutorial. Even following tutorials, you should know Java basics, otherwise the smallest of mistakes will trip you up as you copy someone elses code.
    • so, I'm starting modding and I'm following the official documantation for forge: https://docs.minecraftforge.net, but in the registries part it is not working as it is in the docs:   public class ModItems { private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, DarkStarvation.MOD_ID); public static final RegistryObject<Item> TEST_ITEM = ITEMS.register("test_item", () -> new Item(new Item.Properties())); public DarkStarvation(FMLJavaModLoadingContext context) { ITEMS.register(context.getModEventBus()); } } in 'public DarkStarvation(...' the DarkStarvation has this error: Invalid method declaration; return type required and the getModEventBus(): Cannot resolve method 'getModEventBus' in 'FMLJavaModLoadingContext' please help, I asked gpt but it is saying that I'm using an old method, but I'm following the latest version of Forge Docs???
    • I merged your second post with the original , there is no need to post a new thread asking for an answer. If someone sees your post and can help, they will reply. If you are seeking a quicker response, you could try asking in the Minecraft Forge diacord.
    • Create a new instance and start with cobblemon - if this works, add the rest of your mods in groups   Maybe another mod is conflicting - like Sodium/Iris or Radical Cobblemon Trainers
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.