Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.11] Block with two properties?


Awesome_Spider
 Share

Recommended Posts

A while ago I was having trouble with a block always facing north. This is fixed now, however now I'm on to a new block which requires two properties: Facing and Active. Facing is an EnumFacing and Active is a boolean. I am stuck with what to do with Block#getMetaFromState and Block#getStateFromMeta.

 

My block code so far:

public class BlockPurifier extends BlockTileEntity<TileEntityPurifier> {

    public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
    public static final PropertyBool ACTIVE = PropertyBool.create("active");

    public BlockPurifier() {
        super(Material.ROCK, "purifier");

        IBlockState defaultState = this.blockState.getBaseState();
        defaultState.withProperty(FACING, EnumFacing.NORTH);
        defaultState.withProperty(ACTIVE, false);

        this.setDefaultState(defaultState);

        setHardness(3f);
        setResistance(5f);
        setHarvestLevel("pickaxe", 0);
    }

    @Override
    public Class<TileEntityPurifier> getTileEntityClass() {
        return TileEntityPurifier.class;
    }

    @Nullable
    @Override
    public TileEntityPurifier createTileEntity(World world, IBlockState state) {
        return new TileEntityPurifier();
    }

    @Override
    public BlockStateContainer createBlockState() {
        return new BlockStateContainer(this, FACING);
    }

    @Override
    public int getMetaFromState(IBlockState state) {
        return ((EnumFacing)state.getValue(FACING)).getHorizontalIndex(); //How do I add a boolean to this?
    }

    @Override
    public IBlockState getStateFromMeta(int meta) {
        return getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta)); //How do I add a boolean to this?
    }

    @Override
    public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase entity, ItemStack stack) {
        EnumFacing entityFacing = entity.getHorizontalFacing();

        if(!world.isRemote) {
            if(entityFacing == EnumFacing.NORTH) {
                entityFacing = EnumFacing.SOUTH;
            } else if(entityFacing == EnumFacing.EAST) {
                entityFacing = EnumFacing.WEST;
            } else if(entityFacing == EnumFacing.SOUTH) {
                entityFacing = EnumFacing.NORTH;
            } else if(entityFacing == EnumFacing.WEST) {
                entityFacing = EnumFacing.EAST;
            }

            world.setBlockState(pos, state.withProperty(FACING, entityFacing), 2);
        }
    }
}

Link to comment
Share on other sites

You need to add 4 to the meta when it is off or on your preference, and then decode that your self in the getStateFromMeta.

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.

Link to comment
Share on other sites

If your block has 6 facings, you need to add 8 (or better yet, boolean-or with 8 ) when getting the meta.

If it has 4 (BlockHorizontal) then you can get away with adding 4.

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.

Link to comment
Share on other sites

What those worthies are saying is that meta has 4 bits, and facing is going to use up 2 or 3 of them. That leaves you at least the 1 bit needed for a boolean value. With that much Forge knowledge, you should be able to figure out a way to pack both values into the 4-bit meta and then unpack them again (that's fundamental programming technique, sometimes taught here, but you should get into the habit of finding external references for standard techniques).

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

On 2/7/2017 at 8:17 PM, Daeruin said:

See definition #2: https://www.merriam-webster.com/dictionary/worthies

"a worthy or prominent person"

I looked at that guess i didn't scroll down far enough; thanks.

Edited by Animefan8888
Typo

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.

Link to comment
Share on other sites

Does your block have 4 facings (like the furnace) or 6 (like the piston)? If you have 4 facings, you can add/subtract 4 to get the other value, if you need 6 you'd have to add 8. Or better, use bitwise operators (look at BlockOldLeaves for an example in Block#getStateFromMeta and Block#getMetaFromState).

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Don't subtract. Wrong. Bad.

 

int eightBit = (meta & 7);

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.

Link to comment
Share on other sites

Ok. So would this work? I can't test it because the models/textures aren't finished.

 

@Override
    public int getMetaFromState(IBlockState state) {
        int meta = 0;
        
        meta = meta | ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();

        if (!state.getValue(ACTIVE)) {
            meta |= 4;
        }

        return meta;
    }

    @Override
    public IBlockState getStateFromMeta(int meta) {
        return getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta)).withProperty(ACTIVE, (meta & 4) == 0);
    }

 

Edited by Awesome_Spider
Link to comment
Share on other sites

Man, if only the forums worked and I could view spoilers...

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.

Link to comment
Share on other sites

You can't? Here:

@Override
    public int getMetaFromState(IBlockState state) {
        int meta = 0;

        meta = meta | ((EnumFacing)state.getValue(FACING)).getHorizontalIndex();

        if (!state.getValue(ACTIVE)) {
            meta |= 4;
        }

        return meta;
    }

    @Override
    public IBlockState getStateFromMeta(int meta) {
        return getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta)).withProperty(ACTIVE, (meta & 4) == 0);
    }

 

Link to comment
Share on other sites

Won't work when ACTIVE is false, because your meta -> facing will pass in a value greater than 4, which the enum won't know what to do with.  You need to &3 that bit to strip off the 4th bit.

 

(And no, I can't view spoilers, I don't know why. The JS on this forum is broken as all getout for me: I can't start new threads, I can't use post preview, and I can't open spoilers)

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.

Link to comment
Share on other sites

9 hours ago, Draco18s said:

(And no, I can't view spoilers, I don't know why. The JS on this forum is broken as all getout for me: I can't start new threads, I can't use post preview, and I can't open spoilers)

 

I had this issue on another site once, and it resolved once I removed a Chrome extension related to pop-ups. Do you maybe have a Firefox (?) extension installed blocking it? Or try disabling each extension one-by-one and see if that fixes it.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

1 hour ago, larsgerrits said:

I had this issue on another site once, and it resolved once I removed a Chrome extension related to pop-ups. Do you maybe have a Firefox (?) extension installed blocking it? Or try disabling each extension one-by-one and see if that fixes it.

That gives me a result that a Greasemonkey script that I had to strip out the image in someone's (annoyingly large) signature is at fault.

 

By which I mean, an empty Greasemonkey script breaks everything (as in, only comments, and disabling it makes spoilers work). Which makes no fucking sense.  At all.  And tells me, once again, that this forum's javascript is shitty.  The infinite recursion trying to start a new thread was the first red flag.

 

Huh, turns out the infinite recursion is also because of the greasemonkey script.

 

That's fucking idiotic.

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.

Link to comment
Share on other sites

1 hour ago, Draco18s said:

That gives me a result that a Greasemonkey script that I had to strip out the image in someone's (annoyingly large) signature is at fault.

 

By which I mean, an empty Greasemonkey script breaks everything (as in, only comments, and disabling it makes spoilers work). Which makes no fucking sense.  At all.  And tells me, once again, that this forum's javascript is shitty.  The infinite recursion trying to start a new thread was the first red flag.

 

Huh, turns out the infinite recursion is also because of the greasemonkey script.

 

That's fucking idiotic.

Wow. That language.

YouTube:

https://www.youtube.com/channel/UCaK5oRw4yd7PurBWww9tVhA

Kuribo64 (where I am most active):

http://kuribo64.net/board/profile.php?id=1423

 

Thanks for your answer!

 

Current projects:

 

3D Geometry Dash: 13%

Terracraft (MC Mod): 8%

New Super Kaizo Bros DS: 100% (no download for now :'( )

New Super Kaizo Bros. Wii: 12%

Super Mario Galaxy 1.5: 96%

New Super Mario Bros Galaxy: 85%

Kerbal Space Program Advance: 47%

MC CREATE: 20%

Mystery Projects: 10%, 40%, 13%, and 94%

Link to comment
Share on other sites

I went over to Invision Power Services to complain/file a bug report, only to not know the password to my existing account (I can't make an account because my username AND email are in use by an existing account) but I can't reset my password because there are no user accounts using that email address.  What.

 

Oh, and despite my language and apparent distaste for this forum software, it's not the worst forum software I've had the displeasure of using.  Nope, that'd be the wreck that is the Dungeon Defenders 2 forums, built by Duxter. Everything uses AJAX, which means navigating pages skips over your browser history.  It also means they had to hack together a way to link to specific pages/posts, using redirects (further fucking over the browser history).  Page numbers above 10 display as the number 10.  There's no "report to moderator" feature.  At one point removing the flag that marks someone as a troll (moderator feature, muting that person's posts) also made that person a moderator.  I'm not making that up.

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.

Link to comment
Share on other sites

Just now, Leomelonseeds said:

What are you using the active boolean for? My custom furnace has a boolean isBurning that is not encoded into the metadata but still works.

"And still works" covers a lot of ways it could be handled. Vanilla's furnace uses two whole blocks for it, whereas a TE could store the value and it could be retrieved using getActualState, so that statement by itself isn't actually helpful.  Or even necessarily related.  There's lots of reasons one might want to have two properties on their block.

 

I've got one with three.

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.

Link to comment
Share on other sites

Ok. Thanks. Now how would I change my blockstate json file to incorporate this extra property? I have an animated texture for when "active" is true and a normal one when "active" is false.

 

{
  "forge_marker": 1,
  "defaults": {
    "textures": {
      "front": "roboticraft:blocks/purifier_front_inactive",
      "top": "roboticraft:blocks/purifier_side",
      "side": "roboticraft:blocks/steam_engine_side",
      "particle": "roboticraft:blocks/steam_engine_side"
    }
  },
  "variants": {
    "normal": {
      "model": "orientable"
    },
    "inventory": {
      "model": "orientable"
    },
    "facing=north": {
      "model": "orientable"
    },
    "facing=south": {
      "model": "orientable",
      "y": 180
    },
    "facing=west": {
      "model": "orientable",
      "y": 270
    },
    "facing=east": {
      "model": "orientable",
      "y": 90
    }
  }
}

 

Btw, I understand you not liking this new software. I have this issue when visiting the site on IPad, for a while we couldn't edit posts, the BBCode capabilities are lacking, putting any text after spoilers puts the text in the spoiler instead of on the outside, the forum doesn't notify through email anymore, etc. They are working it out I'm sure, it is a new software after all.

Link to comment
Share on other sites

1 minute ago, Awesome_Spider said:

the forum doesn't notify through email anymore

 
 

You can change every notification setting here: http://www.minecraftforge.net/forum/notifications/options/

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

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

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • okay thank you for clarifying! I'll try to implement the setup method and event listeners as an extra class, maybe this works!
    • Show your code. You do not have to draw the entire texture (see above). You do not have to draw the texture at 1:1 scale.
    • MC version :1.16.5 Forge version :36.2.20 I added "MeleeAttackGoal" in my entity,and then I can‘t summon this entity.what's wrong in my code? //the entity's code package net.fsmc.classmates.animals; import net.minecraft.entity.AgeableEntity; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.ai.attributes.Attributes; import net.minecraft.entity.ai.goal.*; import net.minecraft.entity.merchant.villager.AbstractVillagerEntity; import net.minecraft.entity.monster.ZombifiedPiglinEntity; import net.minecraft.entity.passive.AnimalEntity; import net.minecraft.entity.passive.IronGolemEntity; import net.minecraft.entity.passive.TurtleEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.world.World; import net.minecraft.world.server.ServerWorld; import javax.annotation.Nullable; public class n7Yjy extends AnimalEntity  {          public n7Yjy(EntityType<? extends AnimalEntity> type, World worldIn) {         super(type, worldIn);     }          public static AttributeModifierMap.@NotNull MutableAttribute registerAttributes() {          return MobEntity.func_233666_p_()                  .createMutableAttribute(Attributes.MOVEMENT_SPEED, 0.23000000417232513D)                  .createMutableAttribute(Attributes.ATTACK_DAMAGE, 7.0D)                  .createMutableAttribute(Attributes.FOLLOW_RANGE, 40.0D)                  .createMutableAttribute(Attributes.MAX_HEALTH, 30.0D);      }          @Override     protected void registerGoals(){         this.goalSelector.addGoal(2, new RandomWalkingGoal(this , 1D,1));         this.goalSelector.addGoal(3, new LookAtGoal(this,PlayerEntity.class,8.0f));         this.goalSelector.addGoal(3,new MeleeAttackGoal(this,0.3,true));         this.Target();     }     public void Target(){         this.targetSelector.addGoal(2, (new HurtByTargetGoal(this,new Class[0])).setCallsForHelp(new Class[]{ZombifiedPiglinEntity.class}));         this.targetSelector.addGoal(1, new NearestAttackableTargetGoal<>(this, PlayerEntity.class, true));         this.targetSelector.addGoal(1, new NearestAttackableTargetGoal<>(this, AbstractVillagerEntity.class, false));         this.targetSelector.addGoal(1, new NearestAttackableTargetGoal<>(this, IronGolemEntity.class, true));         this.targetSelector.addGoal(1, new NearestAttackableTargetGoal<>(this, TurtleEntity.class, 10, true, false, TurtleEntity.TARGET_DRY_BABY));     }     @Nullable     @Override     public AgeableEntity createChild(ServerWorld serverWorld, AgeableEntity ageableEntity) {         return null;     } }
    • I am trying to set up my first project and it says this: Unsupported Java.  Your build is currently configured to use Java 16.0.1 and Gradle 6.8.1. Possible solution:  - Use Java 15 as Gradle JVM: Open Gradle settings   - Upgrade Gradle wrapper to 7.0 version and re-import the project I know I am using Java 15 already because in the gradle settings it says gradle JVM: 15 version 15.0.2 So my question is how do I upgrade the gradle wrapper? Sorry if this is a noobie question, trying to set up my first project.  
    • Yes, I don't think you want this as a mod jar. I am not 100% on the details, but ModLauncher implements a multi-module-layer system and you need to load into a specific layer.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.