Jump to content

reasure

Members
  • Posts

    31
  • Joined

  • Last visited

Everything posted by reasure

  1. Ah, I should have bound InventoryMenu.BLOCK_ATLAS. Sorry.
  2. It still renders the same. private void renderFluid(@NotNull PoseStack matrixStack, FluidStack fluid, int maxFluid) { drawString(matrixStack, this.font, "fluid: " + fluid.getAmount() + " / " + maxFluid + " (" + fluid.getDisplayName().getString() + ")", 10, 25, 0xFFFFFF); if (!fluid.isEmpty() && this.minecraft != null) { int scaledHeight = Tools.scaled(fluid.getAmount(), maxFluid, 48); if (scaledHeight > 0) { FluidAttributes fluidAttributes = fluid.getFluid().getAttributes(); ResourceLocation fluidLoc = fluidAttributes.getStillTexture(fluid); TextureAtlasSprite sprite = minecraft.getTextureAtlas(InventoryMenu.BLOCK_ATLAS).apply(fluidLoc); int color = fluidAttributes.getColor(); int yCount = scaledHeight / 16; int yRemainder = scaledHeight % 16; RenderSystem.setShaderTexture(0, new ResourceLocation(fluidLoc.getNamespace(), "textures/" + fluidLoc.getPath() + ".png")); RenderSystem.setShaderColor(((color >> 16) & 0xFF) / 255f, ((color >> 8) & 0xFF) / 255f, (color & 0xFF) / 255f, ((color >> 24) & 0xFF) / 255f); for (int i = 1; i <= yCount; i++) { blit(matrixStack, this.leftPos + 98, this.topPos + 66 - 16 * i, 0, 16, 16, sprite); } blit(matrixStack, this.leftPos + 98, this.topPos + 66 - 16 * yCount - yRemainder, 0, 16, yRemainder, sprite); // reset color RenderSystem.setShaderColor(1f, 1f, 1f, 1f); } } } (TextureAtlasSprite sprite = minecraft.getTextureAtlas(InventoryMenu.BLOCK_ATLAS).apply(fluidLoc); The sprite height is just 16.)
  3. How can I get fluid texture's height? Ah, I got. TextureAtlasSprite fluidSprite = minecraft.getTextureAtlas(InventoryMenu.BLOCK_ATLAS).apply(fluidLoc); int textureHeight = fluidSprite.getHeight();
  4. Rendering was successful, but it's a bit different from what I intended. And what I intend is this. in RenderFluid() FluidAttributes fluidAttributes = fluid.getFluid().getAttributes(); ResourceLocation fluidLoc = fluidAttributes.getStillTexture(fluid); RenderSystem.setShaderTexture(0, new ResourceLocation(fluidLoc.getNamespace(), "textures/" + fluidLoc.getPath() + ".png")); int color = fluidAttributes.getColor(); RenderSystem.setShaderColor(((color >> 16) & 0xFF) / 255f, ((color >> 8) & 0xFF) / 255f, (color & 0xFF) / 255f, ((color >> 24) & 0xFF) / 255f); int scaledHeight = Tools.scaled(fluid.getAmount(), maxFluid, 48); blit(matrixStack, this.leftPos + 98, this.topPos + 66 - scaledHeight, 0, 17, 16, scaledHeight); Tools.scaled public static int scaled(float value, float maxValue, int height) { if (value <= 0 || maxValue <= 0) { return 0; } return (int) (value / maxValue * height); }
  5. I've been trying to render a fluid to the gui. And referenced here. But the result is this: public class LavaGeneratorScreen extends AbstractContainerScreen<LavaGeneratorMenu> { private final ResourceLocation GUI = new ResourceLocation(GeneratorMod.MODID, "textures/gui/lava_generator_gui.png"); public LavaGeneratorScreen(LavaGeneratorMenu menu, Inventory playerInv, Component title) { super(menu, playerInv, title); } @Override public void render(@NotNull PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) { this.renderBackground(matrixStack); super.render(matrixStack, mouseX, mouseY, partialTicks); FluidStack fluid = menu.getFluid().copy(); int maxFluid = menu.getMaxFluidAmount(); renderFluid(matrixStack, fluid, maxFluid); this.renderTooltip(matrixStack, mouseX, mouseY); } private void renderFluid(@NotNull PoseStack matrixStack, FluidStack fluid, int maxFluid) { drawString(matrixStack, this.font, "fluid: " + fluid.getAmount() + " / " + maxFluid + " (" + fluid.getDisplayName().getString() + ")", 10, 20, 0xFFFFFF); if (!fluid.isEmpty() && this.minecraft != null) { FluidAttributes fluidAttributes = fluid.getFluid().getAttributes(); ResourceLocation fluidLoc = fluidAttributes.getFlowingTexture(fluid); TextureAtlasSprite fluidSprite = minecraft.getTextureAtlas(InventoryMenu.BLOCK_ATLAS).apply(fluidLoc); minecraft.getTextureManager().bindForSetup(new ResourceLocation(fluidLoc.getNamespace(), "textures/" + fluidLoc.getPath() + ".png")); int color = fluidAttributes.getColor(); GlStateManager._clearColor(((color >> 16) & 0xFF) / 255f, ((color >> 8) & 0xFF) / 255f, (color & 0xFF) / 255f, ((color >> 24) & 0xFF) / 255f); int scaledHeight = Tools.scaled(fluid.getAmount(), maxFluid, 48); blit(matrixStack, this.leftPos + 98, this.topPos + 66 - scaledHeight, 0, 16, scaledHeight, fluidSprite); } } @Override protected void renderBg(@NotNull PoseStack matrixStack, float partialTick, int mouseX, int mouseY) { RenderSystem.setShaderTexture(0, GUI); this.blit(matrixStack, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight); } } What's wrong?
  6. In Container class, I change "this.fluid = newFluid;" -> "this.fluid = newFluid.copy();" And It works correctly. And I wonder if I should use fluid.copy() in Packet as well.
  7. It seems to have been solved by rewriting the code from scratch. thank you! Is it correct to do this? If this method is correct, I will post the code for other people to refer to as well. (For other parts, refer to mcjty's block entity and container tutorial.) there's a bug again. Real-time update doesn't work. Should the block entity also send packets? (Container Class) public class LavaGeneratorMenu extends AbstractContainerMenu { private final BlockEntity blockEntity; private final ContainerLevelAccess access; private final IItemHandler playerInventory; private FluidStack fluid; private final Player player; public LavaGeneratorMenu(int windowId, Inventory playerInv, BlockPos pos) { super(ModMenuTypes.LAVA_GENERATOR_CONTAINER.get(), windowId); this.playerInventory = new InvWrapper(playerInv); this.access = ContainerLevelAccess.create(playerInv.player.level, pos); this.player = playerInv.player; this.fluid = FluidStack.EMPTY; ... } public FluidStack getFluid() { return blockEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY).map(f -> f.getFluidInTank(0)).orElse(FluidStack.EMPTY); } @Override public boolean stillValid(@NotNull Player player) { return stillValid(access, player, ModBlocks.LAVA_GENERATOR.get()); } @Override public void broadcastChanges() { super.broadcastChanges(); if (player instanceof ServerPlayer sp) { FluidStack newFluid = getFluid(); if (fluid.getAmount() != newFluid.getAmount() || !fluid.isFluidEqual(newFluid)) { PacketHandler.INSTANCE.send(PacketDistributor.PLAYER.with(() -> sp), new FluidUpdatePacket(blockEntity.getBlockPos(), newFluid)); this.fluid = newFluid; } } } @Override public void sendAllDataToRemote() { super.sendAllDataToRemote(); if (player instanceof ServerPlayer sp) { PacketHandler.INSTANCE.send(PacketDistributor.PLAYER.with(() -> sp), new FluidUpdatePacket(blockEntity.getBlockPos(), getFluid())); } } } (FluidUpdatePacket) public class FluidUpdatePacket { public final BlockPos bePos; public final FluidStack fluid; public FluidUpdatePacket(BlockPos pos, FluidStack fluid) { this.bePos = pos; this.fluid = fluid; } public void encode(FriendlyByteBuf buffer) { buffer.writeBlockPos(bePos); buffer.writeFluidStack(fluid); } public static FluidUpdatePacket decode(FriendlyByteBuf buffer) { return new FluidUpdatePacket(buffer.readBlockPos(), buffer.readFluidStack()); } public static void handle(FluidUpdatePacket msg, Supplier<NetworkEvent.Context> ctx) { AtomicBoolean success = new AtomicBoolean(false); ctx.get().enqueueWork(() -> { DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> success.set(ClientAccess.updateFluid(msg.bePos, msg.fluid))); }); ctx.get().setPacketHandled(success.get()); } } (ClientAccess (needed in Packet)) public class ClientAccess { public static boolean updateFluid(BlockPos pos, FluidStack fluid) { AtomicBoolean success = new AtomicBoolean(false); if (Minecraft.getInstance().level != null) { final BlockEntity blockEntity = Minecraft.getInstance().level.getBlockEntity(pos); if (blockEntity != null) { blockEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY).ifPresent(h -> { if (h instanceof FluidTank tank) { tank.setFluid(fluid); success.set(true); } }); } } return success.get(); } } Edit) I removed the "if (fluid.getAmount() != newFluid.getAmount() || !fluid.isFluidEqual(newFluid)) {" which is part of the container class and synchronized it unconditionally, and it worked fine.
  8. Synchronization from server to client was successful. However, when I reconnected to the world, it was out of sync. (It says the fluid is empty.) What's wrong? (If the fluid changes again, it will resynchronize.) In MyBlockEntity.class @Override public void setChanged() { super.setChanged(); onFluidChanged(); } private void onFluidChanged() { if (level != null) { PacketHandler.INSTANCE.send(PacketDistributor.TRACKING_CHUNK.with(() -> level.getChunkAt(worldPosition)), new FluidUpdatePacket(worldPosition, fluidTank.getFluid())); } } @Override public void load(CompoundTag tag) { ... if (tag.contains("Fluid")) { fluidTank.readFromNBT(tag.getCompound("Fluid")); } super.load(tag); onFluidChanged(); }
  9. Sorry to keep asking basic questions. More specifically, after creating a packet from the server to the client, should I send this packet in sendAllDataToRemoted() of the Menu class?
  10. In the mcjty tutorial I saw, inventory was synchronized using slots and energy using data slots. But what about fluid?
  11. I choose 2nd. And like this? MyBlockEntity private final FluidTank fluidTank = createFluidTank(); private final LazyOptional<IFluidHandler> fluidHandler = LazyOptional.of(() -> fluidTank); ... public void loadClient(CompoundTag tag) { if (tag.contains("Fluid")) { fluidTank.readFromNBT(tag.getCompound("Fluid")); } } public void saveClient(CompoundTag tag) { CompoundTag fluid = new CompoundTag(); fluidTank.writeToNBT(fluid); tag.put("Fluid", fluid); } @NotNull @Override public CompoundTag getUpdateTag() { CompoundTag tag = super.getUpdateTag(); saveClient(tag); return tag; } @Override public void handleUpdateTag(CompoundTag tag) { if (tag != null) { loadClient(tag); } } ... private FluidTank createFluidTank() { return new FluidTank(FLUID_CAPACITY, (fluid -> fluid.getFluid().is(FluidTags.LAVA))) { @Override protected void onContentsChanged() { setChanged(); } }; } @Override public <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) { if (cap == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) { return fluidHandler.cast(); } else { return super.getCapability(cap, side); } } And MyContainerMenu public FluidStack getFluid() { return blockEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY).map(f -> f.getFluidInTank(0).copy()).orElse(null); } And In Screen: FluidStack fluid = menu.getFluid() The values are out of sync.
  12. I have created a fluid capability on the block entity. Now I want to display this liquid in the GUI. (Type and amount of liquid) But I have no idea how to synchronize this capability in container or screen.
  13. public static final RegistryObject<Potion> EXPLOSIVE_POTION = POTIONS.register("explosive", () -> new Potion(new EffectInstance(EXPLOSIVE_EFFECT.get(), 1200, 0))); public static final RegistryObject<Potion> LONG_EXPLOSIVE_POTION = POTIONS.register("long_explosive", () -> new Potion(new EffectInstance(EXPLOSIVE_EFFECT.get(), 2400, 0))); public static final RegistryObject<Potion> STRONG_EXPLOSIVEPOTION = POTIONS.register("strong_explosive", () -> new Potion(new EffectInstance(EXPLOSIVE_EFFECT.get(), 600, 2))); It worked! Thank you!
  14. public class ModEffects { public static final DeferredRegister<Effect> EFFECTS = DeferredRegister.create(ForgeRegistries.POTIONS, ReasureCraft.MOD_ID); public static final DeferredRegister<Potion> POTIONS = DeferredRegister.create(ForgeRegistries.POTION_TYPES, ReasureCraft.MOD_ID); public static final RegistryObject<Effect> EXPLOSIVE_EFFECT = EFFECTS.register("explosive", ExplosiveEffect::new); public static final RegistryObject<Potion> EXPLOSIVE_POTION = register("explosive", new EffectInstance(EXPLOSIVE_EFFECT.get(), 1200, 0)); public static final RegistryObject<Potion> LONG_EXPLOSIVE_POTION = register("long_explosive", new EffectInstance(EXPLOSIVE_EFFECT.get(), 2400, 0)); public static final RegistryObject<Potion> STRONG_EXPLOSIVEPOTION = register("strong_explosive", new EffectInstance(EXPLOSIVE_EFFECT.get(), 600, 2)); private static RegistryObject<Potion> register(String name, EffectInstance potion) { return POTIONS.register(name, () -> new Potion(potion)); } } It has same error
  15. public class ModEffects { private ModEffects() { } static void register() { Effects.register(); //at reasure.reasurecraft.init.ModEffects.register(ModEffects.java:23) ~[?:?] {re:classloading} Potions.register(); } public static class Effects { public static final RegistryObject<Effect> EXPLOSIVE = register("explosive", ExplosiveEffect::new); private Effects() { } static void register() { } private static <T extends Effect> RegistryObject<T> register(String name, Supplier<T> effect) { return Registration.EFFECTS.register(name, effect); } } public static class Potions { //at reasure.reasurecraft.init.ModEffects$Potions.<clinit>(ModEffects.java:47) ~[?:?] {re:classloading} public static final RegistryObject<Potion> EXPLOSIVE = register("explosive", new EffectInstance(Effects.EXPLOSIVE.get(), 1200, 0)); public static final RegistryObject<Potion> LONG_EXPLOSIVE = register("long_explosive", new EffectInstance(Effects.EXPLOSIVE.get(), 2400, 0)); public static final RegistryObject<Potion> STRONG_EXPLOSIVE = register("strong_explosive", new EffectInstance(Effects.EXPLOSIVE.get(), 600, 2)); private Potions() { } static void register() { } private static RegistryObject<Potion> register(String name, EffectInstance potion) { return Registration.POTIONS.register(name, () -> new Potion(potion)); } } } [21:48:59] [modloading-worker-6/ERROR] [ne.mi.fm.ja.FMLModContainer/LOADING]: Failed to create mod instance. ModID: reasurecraft, class reasure.reasurecraft.ReasureCraft java.lang.ExceptionInInitializerError: null at reasure.reasurecraft.init.ModEffects.register(ModEffects.java:23) ~[?:?] {re:classloading} at reasure.reasurecraft.init.Registration.register(Registration.java:47) ~[?:?] {re:classloading} at reasure.reasurecraft.ReasureCraft.<init>(ReasureCraft.java:32) ~[?:?] {re:classloading} at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_281] {} at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:1.8.0_281] {} at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_281] {} at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_281] {} at java.lang.Class.newInstance(Class.java:442) ~[?:1.8.0_281] {} at net.minecraftforge.fml.javafmlmod.FMLModContainer.constructMod(FMLModContainer.java:81) ~[forge:36.2] {re:classloading} at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$4(ModContainer.java:120) ~[forge:?] {re:classloading} at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1640) [?:1.8.0_281] {} at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1632) [?:1.8.0_281] {} at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) [?:1.8.0_281] {} at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1067) [?:1.8.0_281] {} at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1703) [?:1.8.0_281] {} at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:172) [?:1.8.0_281] {} Caused by: java.lang.NullPointerException: Registry Object not present: reasurecraft:explosive at java.util.Objects.requireNonNull(Objects.java:290) ~[?:1.8.0_281] {} at net.minecraftforge.fml.RegistryObject.get(RegistryObject.java:120) ~[forge:?] {re:classloading} at reasure.reasurecraft.init.ModEffects$Potions.<clinit>(ModEffects.java:47) ~[?:?] {re:classloading} ... 16 more [21:48:59] [main/FATAL] [ne.mi.fm.ModLoader/LOADING]: Failed to complete lifecycle event CONSTRUCT, 1 errors found [21:48:59] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException [21:48:59] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]: at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:39) [21:48:59] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]: at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [21:48:59] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]: at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [21:48:59] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]: at cpw.mods.modlauncher.Launcher.run(Launcher.java:82) [21:48:59] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]: at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [21:48:59] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1052]: at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:108) [21:48:59] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1061]: Caused by: java.lang.reflect.InvocationTargetException [21:48:59] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1061]: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [21:48:59] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1061]: at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [21:48:59] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1061]: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [21:48:59] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1061]: at java.lang.reflect.Method.invoke(Method.java:498) [21:48:59] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1061]: at net.minecraftforge.userdev.FMLUserdevDataLaunchProvider.lambda$launchService$0(FMLUserdevDataLaunchProvider.java:51) [21:48:59] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1061]: at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [21:48:59] [main/INFO] [STDERR/]: [java.lang.ThreadGroup:uncaughtException:1061]: ... 5 more [21:48:59] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:644]: Caused by: net.minecraftforge.fml.LoadingFailedException: Loading errors encountered: [ fml.modloading.failedtoloadmod ] [21:48:59] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:644]: at net.minecraftforge.fml.ModLoader.waitForTransition(ModLoader.java:269) [21:48:59] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:644]: at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:236) [21:48:59] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:644]: at net.minecraftforge.fml.ModLoader.gatherAndInitializeMods(ModLoader.java:194) [21:48:59] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:644]: at net.minecraftforge.fml.DatagenModLoader.begin(DatagenModLoader.java:60) [21:48:59] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:644]: at net.minecraft.data.Main.main(Main.java:45) [21:48:59] [main/INFO] [STDERR/]: [java.lang.Throwable:printStackTrace:644]: ... 11 more Exception in thread "main" Process finished with exit code 1 It has error
  16. if (player.isSneaking()) { No sneaking-related variables found in EntityPlayer. (official mapping)
  17. @SubscribeEvent public static void renderBlockOverlay(final RenderBlockOverlayEvent event) { if (event.getPlayer().level.getFluidState(event.getBlockPos()).is(ModTags.Fluids.RUBBER)) { ReasureCraft.LOGGER.info("render Event!"); // Render Overlay } } What should I do?
  18. If I go into lava, the screen turns red, but if I go into custom fluid, the screen changes as if I went into water. (Custom fluid has water tag to act like water) Is there a way to render a different color (white) when I go into the custom fluid? +) Is there a way to act like water without having a water tag? (For example, when an entity goes into custom fluid, it slows down.)
  19. Oh, I write RUBBER_PROPERTIES under RUBBER_FLOWING and it is solved.
  20. public class ModFluids { public static final ResourceLocation RUBBER_STILL_RL = new ResourceRocation(ReasureCraft.MOD_ID, "block/rubber_still")); public static final ResourceLocation RUBBER_FLOWING_RL = new ResourceRocation(ReasureCraft.MOD_ID, "block/rubber_flowing"); public static final ResourceLocation RUBBER_OVERLAY_RL = new ResourceRocation(ReasureCraft.MOD_ID, "block/rubber_overlay"); public static final ForgeFlowingFluid.Properties RUBBER_PROPERTIES = new ForgeFlowingFluid.Properties(ModFluids.RUBBER, ModFluids.RUBBER_FLOWING, FluidAttributes.builder(RUBBER_STILL_RL, RUBBER_FLOWING_RL).density(5).luminosity(10).rarity(Rarity.RARE).sound(SoundEvents.HONEY_DRINK) .overlay(RUBBER_OVERLAY_RL)).block(ModBlocks.RUBBER).bucket(ModItems.RUBBER_BUCKET).explosionResistance(100.0f); public static final RegistryObject<FlowingFluid> RUBBER = register("rubber_fluid", () -> new ForgeFlowingFluid.Source(ModFluids.RUBBER_PROPERTIES)); public static final RegistryObject<FlowingFluid> RUBBER_FLOWING = register("rubber_flowing", () -> new ForgeFlowingFluid.Flowing(ModFluids.RUBBER_PROPERTIES)); private ModFluids() { } private static <T extends Fluid> RegistryObject<T> register(String name, Supplier<T> item) { return Registration.FLUIDS.register(name, item); } static void register() { } } and Registraion.FLUIDS: public static final DeferredRegister<Fluid> FLUIDS = DeferredRegister.create(ForgeRegistries.FLUIDS, ReasureCraft.MOD_ID); and Rubber Block: public static final RegistryObject<FlowingFluidBlock> RUBBER = register("rubber", () -> new FlowingFluidBlock(ModFluids.RUBBER, AbstractBlock.Properties.of(Material.WATER).noCollission().randomTicks().strength(100.0F).noDrops())); and Rubber Bucket: public static final RegistryObject<BucketItem> RUBBER_BUCKET = register("rubber_bucket", () -> new BucketItem(ModFluids.RUBBER, defaultProperties().stacksTo(1).craftRemainder(Items.BUCKET))); and When I use Rubber Bucket, it throw error What is problem?
  21. I solved this problem by using return ActionResultType.CONSUME; in interactLivingEntity instead of using super.interactLivingEntity()
  22. public class BlazeAndSteel extends FlintAndSteelItem { public BlazeAndSteel(Properties properties) { super(properties.fireResistant().stacksTo(1).durability(128)); } @Override public ActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) { ItemStack item = player.getItemInHand(hand); if (!world.isClientSide()) { ActionResultType result = fireEntity(item, player, player, hand); return new ActionResult<>(result, item); } return super.use(world, player, hand); } @Override public ActionResultType interactLivingEntity(ItemStack item, PlayerEntity player, LivingEntity target, Hand hand) { if (!target.level.isClientSide()) { return fireEntity(item, player, target, hand); } return super.interactLivingEntity(item, player, target, hand); } protected ActionResultType fireEntity(ItemStack item, PlayerEntity player, LivingEntity target, Hand hand) { if (!target.fireImmune()) { item.hurtAndBreak(1, player, p -> p.broadcastBreakEvent(hand)); player.playSound(SoundEvents.FLINTANDSTEEL_USE, 1.0f, random.nextFloat() * 0.4f + 0.8f); int fireTick = random.nextInt(10 * 20 + 1) + 20; if (fireTick > target.getRemainingFireTicks()) { target.setSecondsOnFire(fireTick); } target.hurt(DamageSource.ON_FIRE, random.nextInt(4)); return ActionResultType.CONSUME; } return ActionResultType.FAIL; } } It has three actions 1. use on block -> act like flint and steel (useOn in FlintAndSteelItem.class) 2. use on entity -> light entity on fire (interactLivingEntity) 3. use on air -> light player on fire (use) When I use it on entity (case 2), it light both entity and player on fire. But I want to make it light only entity on fire. Give me help please.
×
×
  • Create New...

Important Information

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