Jump to content

Recommended Posts

Posted

I've been trying to mod in a new redstone component similar to the piston.  I've searched high and low on forums and YouTube, trying to figure out how to get this to work, but I can't seem to get any proper updates or read redstone signals like I'm expecting.  In all cases, it has either has ignored all redstone signals, or it doesn't function like it should (I've tested it with onBlockActivated. it does work)  Is there something I'm missing?  Do I need a TileEntity?  Am I overriding the wrong methods?  I should also mention that I'm just setting blocks in the world to test whether code is running, and it doesn't ever seem to.

package com.willtgd.testmod.blocks;

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class Teleporter extends Block {
	
	public Teleporter() {} // not important to the question at hand (i think)
	
	@Override
	public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
		if (world.isBlockPowered(pos.add(0, 0, 1))) {
			world.setBlockState(pos.add(1, 0, 0), Block.getBlockFromName("minecraft:stone").getDefaultState());
		}
	}
	
	@Override
	public void onNeighborChange(IBlockAccess access, BlockPos pos, BlockPos neighbor) {
		World world = Minecraft.getMinecraft().world;
		
		if (world.isBlockPowered(neighbor)) {
			world.setBlockState(neighbor, Block.getBlockFromName("minecraft:dirt").getDefaultState());
		}
	}
	
	@Override
	public void observedNeighborChange(IBlockState state, World world, BlockPos observerPos, Block changedBlock, BlockPos changePos) {
		if (world.isBlockPowered(changePos)) {
			world.setBlockState(changePos, Block.getBlockFromName("minecraft:dirt").getDefaultState());
		}
	}
	
	private void swapBlocks(World world, BlockPos pos) {
		BlockPos up = pos.add(0, 1, 0);
		BlockPos down = pos.add(0, -1, 0);
		
		IBlockState temp = world.getBlockState(up);
		
		world.setBlockState(up, world.getBlockState(down));
		world.setBlockState(down, temp);
	}
}
Posted
1 hour ago, WillTheGameDecoder said:

swapBlocks

Well, you aren't calling this method...

 

1 hour ago, WillTheGameDecoder said:

World world = Minecraft.getMinecraft().world;

Why are you doing this? Not only are you reaching across logical sides, but you were passed a world object in the parameters. It's the IBlockAccess (you know, to access block information about the world from? Take a look at what classes implement this interface...)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
42 minutes ago, Draco18s said:

Well, you aren't calling this method...

 

Why are you doing this? Not only are you reaching across logical sides, but you were passed a world object in the parameters. It's the IBlockAccess (you know, to access block information about the world from? Take a look at what classes implement this interface...)

1) I know I'm not calling the method.  I did forget to add it, yeah, but it doesn't work, even when I do add it.

2) IBlockAccess doesn't have the "isBlockPowered" method.  It only has "getStrongPower" which requires an EnumFacing as well, which I don't understand either...

Posted
6 hours ago, WillTheGameDecoder said:

requires an EnumFacing as well, which I don't understand either...

Then test values to understand it. Or look through the code and find out what that parameter does.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
9 hours ago, WillTheGameDecoder said:

IBlockAccess doesn't have the "isBlockPowered" method

Cast it.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
3 minutes ago, diesieben07 said:

No. It will not always be a World.

Doing a cast -> always check that it's valid first.

I figure that this is implied knowledge for the level of programming knowledge required to be posting here.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
8 minutes ago, diesieben07 said:

Not always the case either :P

I am not sure what you are getting at here. ?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
16 minutes ago, diesieben07 said:

In this case you do need to do the check before casting. But saying "you always need to check before casting" is not true.

Let me clarify then:

Upcasting does not require a check (and, in some respects, the cast isn't needed at all, as the parent attributes and definition should already be available)
Downcasting does, as there may be multiple implementations or subclasses

 

Now, if there's an exception by where downcasting does not require an instanceof check, that is not specific to a given implementation (e.g. "EntityFoo is only ever extended by EntityFooBar") I'd be happy to learn about it.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
2 hours ago, Draco18s said:

Cast it.

Well, that certainly helps in that aspect, but my original question still stands.  My block isn't being updated when receiving weak power, and the code is still breaking, in spite of it working 100% in the "onBlockActivated" method

Posted
56 minutes ago, WillTheGameDecoder said:

breaking

Define breaking.

58 minutes ago, WillTheGameDecoder said:

Well, that certainly helps in that aspect, but my original question still stands.

Post updated code, preferably the whole class.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
1 hour ago, diesieben07 said:

One such place is block methods getting their tile entity. A downcast to the actual tile entity implementation does not need a check there.

Ok, in general, I can agree with you, due to the way the scope works there.

 

There's still, tecnically, the possibility that it could crash, but only in cases where someone else fucked up somewhere.

There's the blockBroken method that I think is called after the block is removed that messed with a whole ton of people's code during a major update (1.10 -> 1.12?), and there's the "if someone fucks up their shouldRefresh method."

 

But you are correct in general that when things are working the way they're supposed to, no instanceof is needed. However, this is a very specific scenario that I'd argue is specific to the implementation detail of TileEntities within Minecraft and in not a general rule of programming.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
2 minutes ago, WillTheGameDecoder said:

No.  "onNeighborChange" doesn't get triggered at all, as far as I'm aware.  I forgot to delete that code

Does observedNeighborChange get called?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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

    • Minecraft 1.21.4 requires a new model definition file for each item, which you don't have. These can be created through Data Generation, specifically the ModelProvider, BlockModelGenerators and ItemModelGenerators classes.
    • Hi,  I'm using Forge 47.3.0 for Minecraft 1.20.1 I apologise if this is obvious I am very new to modding for Minecraft. I sucessfully made a mod that launched without errors or crashes (without it doing anything) but in order to add the features I need, I need to add "Custom Portal API [Forge]" as a dependency. However no matter the way I've tried to acheive this, it crashes. I am pretty sure it's not the way I'm putting it in the repositories, the dependencies or the way I'm refrencing it, as I've a hundred diffrent combinations and multiple Maven methods. And on all those diffrent variations I still get this crash: pastebin.com/UhumzZCZ Any tips would be invaluable as I've been loosing my mind over this!
    • Hi, i'm really having problems trying to set the texture to my custom item. I thought i'm doing everything correctly, but all i see is the missing texture block for my item. I am trying this for over a week now and getting really frustrated. The only time i could make the texture work, was when i used an older Forge version (52.0.1) for Minecraft (1.21.4). Was there a fundamental change for textures and models somewhere between versions that i'm missing? I started with Forge 54.1.0 and had this problem, so in my frustration i tried many things: Upgrading to Forge 54.1.1, created multiple new projects, workspaces, redownloaded everything and setting things up multiple times, as it was suggested in an older thread. Therea are no errors in the console logs, but maybe i'm blind, so i pasted the console logs to pastebin anyway: https://pastebin.com/zAM8RiUN The only time i see an error is when i change the models JSON file to an incorrect JSON which makes sense and that suggests to me it is actually reading the JSON file.   I set the github repository to public, i would be so thankful if anyone could take a look and tell me what i did wrong: https://github.com/xLorkin/teleport_pug_forge   As a note: i'm pretty new to modding, this is my first mod ever. But i'm used to programming. I had some up and downs, but through reading the documentation, using google and experimenting, i could solve all other problems. I only started modding for Minecraft because my son is such a big fan and wanted this mod.
    • Please read the FAQ (link in orange bar at top of page), and post logs as described there.
    • Hello fellow Minecrafters! I recently returned to Minecraft and realized I needed a wiki that displays basic information easily and had great user navigation. That’s why I decided to build: MinecraftSearch — a site by a Minecraft fan, for Minecraft fans. Key Features So Far Straight-to-the-Point Info: No extra fluff; just the essentials on items, mobs, recipes, loot and more. Clean & Intuitive Layout: Easy navigation so you spend less time scrolling and more time playing. Optimized Search: Search for anything—items, mobs, blocks—and get results instantly. What I’m Thinking of Adding More data/information: Catch chances for fishing rod, traveling villager trades, biomes info and a lot more. The website is still under development and need a lot more data added. Community Contributions: Potential for user-uploaded tips for items/mobs/blocks in the future. Feature Requests Welcome: Your ideas could shape how the wiki evolves! You can see my roadmap at the About page https://minecraftsearch.com/about I’d love for you to check out MinecraftSearch and see if it helps you find the info you need faster. Feedback is crucial—I want to develop this further based on what the community needs most, so please let me know what you think. Thanks, and happy crafting!
  • Topics

×
×
  • Create New...

Important Information

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