Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

On 10/10/2019 at 12:46 PM, MineModder2000 said:

as confirmed by println.

Post your println code.

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.

  • Replies 56
  • Views 20.1k
  • Created
  • Last Reply

Top Posters In This Topic

Most Popular Posts

  • So, just a few things (but not related to your issue, just code style problems): This is copy-pasted decompiled code. There's no reason to use Boolean.valueOf There's no reason for a cas

  • Animefan8888
    Animefan8888

    You can change that by calling setDefaultState in your constructor. IE setDefaultState(getDefaultState().with(...))

  • Animefan8888
    Animefan8888

    It's called on both sides from each of those methods I posted. That execute at "the same time".

  • Author
5 hours ago, Animefan8888 said:

Post your println code.

 

Spoiler

package mymod;

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.FireBlock;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Items;
import net.minecraft.particles.ParticleTypes;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties;
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.TickPriority;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

public class Copper extends Block {
	
	public static final BooleanProperty READY = BooleanProperty.create("ready");

	public Copper(Properties properties) {
		
		super(properties);
	}
	
	@Override
    @SuppressWarnings("deprecation")
	public void onBlockAdded(BlockState state, World worldIn, BlockPos pos, BlockState oldState, boolean isMoving) {
		
	    super.onBlockAdded(state, worldIn, pos, oldState, isMoving);
	    
	    worldIn.setBlockState(pos, state.with(READY, false), 3);
	}
	
	@Override
	public void tick(BlockState state, World worldIn, BlockPos pos, Random random) {	

                worldIn.setBlockState(pos, state.with(READY, true), 3);
                System.out.println(state.get(READY));
	}
	
	@Override
	public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
		
		if (!player.abilities.allowEdit) {
			 
	        return false;
	    } 
		 
		else {

			if (player.getHeldItemMainhand().getItem() == Items.TORCH) {
				
				worldIn.getPendingBlockTicks().scheduleTick(pos, this, 60, TickPriority.HIGH);
			}
		
	        return true;
	    }
	}
	
	@Override
	@OnlyIn(Dist.CLIENT)
	public void animateTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) {
		
		if (stateIn.get(READY) && rand.nextInt(5) == 0) {  
				
            for(int i = 0; i < rand.nextInt(1) + 1; ++i) {
            		
            	System.out.println("xyz968");
            	
                worldIn.addParticle(ParticleTypes.LAVA, (double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), (double)(rand.nextFloat() / 2.0F), 5.0E-5D, (double)(rand.nextFloat() / 2.0F));
                //worldIn.addParticle(ParticleTypes.LARGE_SMOKE, (double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), (double)(rand.nextFloat() / 2.0F), 5.0E-5D, (double)(rand.nextFloat() / 2.0F));
            }
        }
	}
	
	@Override
	protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
		
	    builder.add(READY);
	}
}

 

Edited by MineModder2000

1 minute ago, MineModder2000 said:

worldIn.setBlockState(pos, state.with(READY, true), 3);

This line of code doesn't change the state variable you have. It changes the state in the world. So your println should look like this.
worldIn.getBlockState(pos).get(READY);

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.

  • Author
1 hour ago, Animefan8888 said:

This line of code doesn't change the state variable you have. It changes the state in the world. So your println should look like this.
worldIn.getBlockState(pos).get(READY);

Well hell with the prinln(), what should I do instead to change the variable state. 

19 minutes ago, MineModder2000 said:

what should I do instead to change the variable state. 

state = state.with...

However that only changes the memory address of that variable it doesn't change anything else. BlockStates are singletons just like Blocks.

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.

  • Author
4 minutes ago, Animefan8888 said:

state = state.with...

However that only changes the memory address of that variable it doesn't change anything else. BlockStates are singletons just like Blocks.

Oh.. Well I did the new println() you gave me and it still shows false....

12 minutes ago, MineModder2000 said:

Oh.. Well I did the new println() you gave me and it still shows false....

I can't replicate your issue on my own block.

	@Override
	public void tick(BlockState state, World worldIn, BlockPos pos, Random random) {
		System.out.println(worldIn.getBlockState(pos).get(BlockStateProperties.HORIZONTAL_FACING));
		worldIn.setBlockState(pos, state.cycle(BlockStateProperties.HORIZONTAL_FACING));
		System.out.println(worldIn.getBlockState(pos).get(BlockStateProperties.HORIZONTAL_FACING));
	}

It prints as expected. I am unsure as to why it isn't working for you.

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.

  • Author
48 minutes ago, Animefan8888 said:

I can't replicate your issue on my own block.


	@Override
	public void tick(BlockState state, World worldIn, BlockPos pos, Random random) {
		System.out.println(worldIn.getBlockState(pos).get(BlockStateProperties.HORIZONTAL_FACING));
		worldIn.setBlockState(pos, state.cycle(BlockStateProperties.HORIZONTAL_FACING));
		System.out.println(worldIn.getBlockState(pos).get(BlockStateProperties.HORIZONTAL_FACING));
	}

It prints as expected. I am unsure as to why it isn't working for you.

Odd.... When I have this line :  worldIn.setBlockState(pos, state.with(READY, 'value'), 3); in my onBlockAdded method, I can change the variable to true or false, as confirmed by println(). It just won't change inside of tick method. My original println() actually works fine by the way. 

2 minutes ago, MineModder2000 said:

My original println() actually works fine by the way. 

It should not work. And if it does there is something very very wrong.

4 minutes ago, MineModder2000 said:

It just won't change inside of tick method.

Which doesn't any sense what so ever. And thus maybe a new world or new forge setup is needed.

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.

  • Author
8 minutes ago, Animefan8888 said:

It should not work. And if it does there is something very very wrong.

Which doesn't any sense what so ever. And thus maybe a new world or new forge setup is needed.

Actually Houston, I found the answer. I was able to get the variable to change in tick method, the problem is the onBlockAdded is called multiple times, four times or more I counted, so it resets the variable back to what I had it set to in there. I guess the solution is to not have it set in there, and just deal with it being true by default, easy adjustment. I'll call it UNREADY instead of READY. But anyways is multiple calls to that method with only one block created normal? 

9 minutes ago, MineModder2000 said:

and just deal with it being true by default

You can change that by calling setDefaultState in your constructor. IE
setDefaultState(getDefaultState().with(...))

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.

39 minutes ago, diesieben07 said:

two player hands. 2x2

This is wrong. It's called 4 times because it is executed in two separate places when a block(Chunk#setBlockState and ForgeHooks.onPlaceItemIntoWorld) is placed then we have both sides. Which comes out to be 4. 

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.

12 minutes ago, diesieben07 said:

Where is the 2 hands thing from?

I'm not sure maybe onBlockActivated or from an older version.

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.

  • Author
38 minutes ago, Animefan8888 said:

This is wrong. It's called 4 times because it is executed in two separate places when a block(Chunk#setBlockState and ForgeHooks.onPlaceItemIntoWorld) is placed then we have both sides. Which comes out to be 4. 

How does it come out to 4 if it's two sides... maybe i shouldn't ask. Well that means tick() will be called 4 times as, worldIn.getPendingBlockTicks().scheduleTick(pos, this, 360, TickPriority.HIGH); is in that method, but this shouldn't affect anything. 

 

14 hours ago, Animefan8888 said:

You can change that by calling setDefaultState in your constructor. IE
setDefaultState(getDefaultState().with(...))

Whoops forgot all about that, I was so focused on that method.

Edited by MineModder2000

36 minutes ago, MineModder2000 said:

4 if it's two sides

It's called on both sides from each of those methods I posted. That execute at "the same time".

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.

  • Author
36 minutes ago, Animefan8888 said:

It's called on both sides from each of those methods I posted. That execute at "the same time".

Oh gotcha. 

3 hours ago, diesieben07 said:

Huh. Have I got this mixed up? Where is the 2 hands thing from?

rightClick and related methods that have a hand parameter. Its still relevant, just maybe not for this situation.

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.

  • Author

New Q. How could I make custom flags for drops? For example, pigs and other animals drop cooked rather than raw meat if they die while on fire, which is done by a flag check for "is_on_fire". I want to do something similar, so my block only drops something when a certain condition is met. 

Implement (and register) your own ILootCondition

Edited by Draco18s

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.

  • Author
3 hours ago, Draco18s said:

Implement (and register) your own ILootCondition

I see the implementation examples in vanilla files, but I don't understand how to register. The docs say to use this method : LootConditionManager.registerCondition(), but it takes an instance of a class that cannot be instantiated. 

 

11 minutes ago, MineModder2000 said:

but it takes an instance of a class that cannot be instantiated.  

Hint: Inheritance. Vanilla has to do it somehow.

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.

  • Author

So I done diddly did this :

 

Spoiler

package mymod;

import javax.annotation.Nullable;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;

import net.minecraft.util.JSONUtils;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.storage.loot.LootContext;
import net.minecraft.world.storage.loot.conditions.ILootCondition;

public class Ready implements ILootCondition {
	
	private final Boolean hot;
	
	private Ready(@Nullable Boolean hot) {
		
	    this.hot = hot;
    }
	
	public static class Serializer extends ILootCondition.AbstractSerializer<Ready> {
	
	    public Serializer() {
	    		
	        super(new ResourceLocation("Ready"), Ready.class);
	    }

	    public void serialize(JsonObject json, Ready value, JsonSerializationContext context) {

	    	json.addProperty("hot", value.hot);
	    }

	    public Ready deserialize(JsonObject json, JsonDeserializationContext context) {
	    	
	    	Boolean obool = json.has("hot") ? JSONUtils.getBoolean(json, "hot") : null;
	        return new Ready(obool);
	    }
	}

	@Override
	public boolean test(LootContext t) {
		
		return false;
	} 

}

 

And this in my main mod class : LootConditionManager.registerCondition(new Ready.Serializer());

 

So now how do I actually use it so that the boolean here changes when I need it to from my block class?

Not having messed with Loot Conditions, I recommend you examine the existing loot condition classes and how they're used.

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.

  • Author
17 hours ago, Draco18s said:

Not having messed with Loot Conditions, I recommend you examine the existing loot condition classes and how they're used.

Well for example there is the Is_On_Fire flag for entities, where is the class that shows how this is used?

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.