Jump to content

Triggering a dispenser-type block automatically? Plus GUI questions


LaDestitute

Recommended Posts

Okay, so main question first:
I have a custom block named an Arrow Trap that extends a custom ContainerBase (which implements BlockContainer) and the class itself uses dispenser code. I do have a tile entity to go with the trap (which extends dispenser for the TE) but due to an issue below, I'm just currently having the block partially use Dispenser instead as the TE for now until I can fix the issue. 

 

How do I get it to auto-trigger if any entity walks up to seven blocks away from it's south-face (if that's possible or if it's a limit of one block?), while accounting for blocks blocking line of sight (a block blocking in any portion of the range of line = no activation)? I have a hunch I'd have to use raytracing, probably, right? Not gonna post my TE code cause it's 95% vanilla code.


Now, regarding GUI:

 I do know how to override onBlockPlacedBy and createNewTileEntity and while that gives me the custom GUI name I needed, I can't figure out how to make it so the dispensing function works...even with overriding, the dispensing breaks. Either method is fine, whether overriding and using vanilla-derived guis or creating a new one altogether, assuming I can fix the dispensing issue, though a custom GUI would be nice.
 

How would I go about implementing a custom GUI/container, the GUI handler, etc without breaking how my arrow trap block is setup, code wise? I tried once (from Shadowfact's tutorial) and it did work once, at least to the point of being able to open the inventory and close it with no issues but due to how my mod registers blocks/items (with a static list and "ModBlocks.BLOCKS.add(this);" and "ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));" ), it kind of breaks the blockstates for my trap and the constructor/constructor values like Hardness.

GUI class works out fine but it's the GuiHandler that gives me errors with my code, other the aforementioned way of how I'm registering things. I know setting up a custom GUI/handler for things like furnaces and chests is easy as pie but I haven't seen many "dispenser"-like examples in the GUI tutorials I've found. Maybe an unique case, given there aren't really tutorials on custom dispenser-like blocks, short of odd old threads and online questions.


Arrow Trap code:

https://pastebin.com/A4MYmdbe

Link to comment
Share on other sites

12 minutes ago, LaDestitute said:

ContainerBase (which implements BlockContainer)

Don’t extend BlockContainer, it’s legacy vanilla code. Simply override Block#hasTileEntity(IBlockState) and Block#createTileEntity(IBlockState)

 

12 minutes ago, LaDestitute said:

How do I get it to auto-trigger if any entity walks up to seven blocks away from it's south-face (if that's possible or if it's a limit of one block?), while accounting for blocks blocking line of sight (a block blocking in any portion of the range of line = no activation)? I have a hunch I'd have to use raytracing, probably, right? Not gonna post my TE code cause it's 95% vanilla code.

Tickable tile entities can do whatever they want in their onUpdate method (renamed tick in 1.13). You can use TileEntity#getPos, BlockPos#offset(EnumFacing, int), AxisAlignedBB(BlockPos) and World#getEntitiesInsideAABB to find all entities up to 7 blocks away from your TE in any direction. As a general rule, don’t copy the vanilla code exactly, it’s usually not very good (vanilla operates in an “if it ain’t broke don’t fix it” way) and Forge usually has better ways of doing what you want. That said, vanilla is an excellent reference, but it’s not great to just copy paste vanilla code.

 

16 minutes ago, LaDestitute said:

due to how my mod registers blocks/items (with a static list and "ModBlocks.BLOCKS.add(this);" and "ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));" ), it kind of breaks the blockstates for my trap and the constructor/constructor values like Hardness.

This likely means you followed a sub-par YouTube tutorial about how to setup your mod. Don’t use static initialisers (see http://www.minecraftforge.net/forum/topic/70095-1122-custom-tree-problems/?do=findComment&comment=339598 for an explanation), your registration can be massively simplified and clean up (see https://gist.github.com/Cadiboo/b825d62fb46538e7b7b262c5612d62aa and https://gist.github.com/Cadiboo/3f5cdb785affc069af2fa5fdf2d70358)

  • Thanks 1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

Just now, Cadiboo said:

Don’t extend BlockContainer, it’s legacy vanilla code. Simply override Block#hasTileEntity(IBlockState) and Block#createTileEntity(IBlockState)

 

Tickable tile entities can do whatever they want in their onUpdate method (renamed tick in 1.13). You can use TileEntity#getPos, BlockPos#offset(EnumFacing, int), AxisAlignedBB(BlockPos) and World#getEntitiesInsideAABB to find all entities up to 7 blocks away from your TE in any direction. As a general rule, don’t copy the vanilla code exactly, it’s usually not very good (vanilla operates in an “if it ain’t broke don’t fix it” way) and Forge usually has better ways of doing what you want. That said, vanilla is an excellent reference, but it’s not great to just copy paste vanilla code.

 

This likely means you followed a sub-par YouTube tutorial about how to setup your mod. Don’t use static initialisers (see http://www.minecraftforge.net/forum/topic/70095-1122-custom-tree-problems/?do=findComment&comment=339598 for an explanation), your registration can be massively simplified and clean up (see https://gist.github.com/Cadiboo/b825d62fb46538e7b7b262c5612d62aa and https://gist.github.com/Cadiboo/3f5cdb785affc069af2fa5fdf2d70358)

Thanks for the advice. Also yeah, I was screwing around with AxisAlignedBB earlier. I was actually pondering if I should get rid of static initializers and IHas Model, just to make my code a bit cleaner. Also just so I'm correct, with the format of Thing#thing, the latter thing (such as TileEntity#getPos) refers to a method classed under that class, right?

Link to comment
Share on other sites

2 hours ago, LaDestitute said:

with the format of Thing#thing, the latter thing (such as TileEntity#getPos) refers to a method classed under that class, right?

It’s in the format

Class#instanceThing (Field or method)

or

Class#instanceMethod(args).

You might also see people use the format

Class::method

which means a static or instance method

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

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

    • Hi I have an issue with a server it solved deleting the ice and fire but my friends and me really want to use it does any of these mods are causing the issue due to incompatibility  Security craft Aquaculture Architectury Artifacts Astikorcarts Baubles BetterCaves yungs BetterStrongholds yungs BetterMineshafts yungs Bountiful Byg  Callablehorses Carry on Chococraft Citadel Clumps Collective Comforts Corailrecycler Craftable horse armor Comes alive Curios forge Decocraft Dungeonsarise  Open blocks elevator Expandability Farlanders Goblin traders Hwyla  Ice and fire Infernal expansion Jei Jump over fences Mantle  Macaws bridges Macaws doors Macaws fences Macaws furniture  Macaws fencesbyg Morpheus Mouse tweaks Mowzies mobs Obfuscate Paraglider Patchouli  Pick up notifier Random village names Spartan shields Small ships Sophisticated backpacks Spartan weaponry Storage drawers straw golem Structure gel Twilight forest  Tinkers construct Two players one horse  Valhesia core  Valhesia structures  Way stones  Vehicle mod  Wall jump Wings Wolves with armor Xptome  Xaeros minimap  Yungsapi  
    • { "type": "magic_overhaul:rune_inscribing", "base": { "item": "//base item" }, "template": { "item": "//template item" }, "output": { "count": 1, "item": "//output item" } } ^ Ok, where is your recipe JSON placed in your file structure? What's it called? And paste the actual JSON you're testing with, because it needs to be valid.
    • I'm trying to run Forge 1.12.2 on Minecraft  so I can use certain mods, but this error popped up. I've seen multiple errors but I just can't figure this one out. Unable to locate the Java runtime. Error details: 0x00000000 - system: The operation completed successfully. Filename on disk:  Path: . Exists: Directory
    • https://mclo.gs/b422RFc
    • Плагин и Приват
  • Topics

×
×
  • Create New...

Important Information

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