Jump to content

Recommended Posts

Posted (edited)

Do you mean setting the block to face the player when placed down?

Override Block#getStateForPlacement and return the blockstate of facing in the player's direction.

Also change the variants in the blockstates json to match your rotation.

 

For reference, look at how the vanilla furnace handles it.

Edited by DavidM

Some tips:

  Reveal hidden contents

 

  • 3 weeks later...
Posted
  On 3/20/2019 at 11:14 PM, DavidM said:

Do you mean setting the block to face the player when placed down?

Override Block#getStateForPlacement and return the blockstate of facing in the player's direction.

Also change the variants in the blockstates json to match your rotation.

 

For reference, look at how the vanilla furnace handles it.

Expand  

Hi! Sorry that it has been a while but do you mind if you could give me an example of 1.13 rotation on placement feature? I have tried messing with my code but I cannot get rotation to work in my block.

I checked the furnace code and got the rotation code from it but it does not work as some things come out as deprecated or just not working. Sorry to be annoying if I am, but thanks if I get any replies again.

Posted

How to do rotation:

 

1. Store the direction

Add this to your block class:
 

public static final PropertyDirection FACING = BlockHorizontal.FACING;

This just stores the direction.

 

2. Tell forge that direction is part of the state

You need to tell forge direction is part of the state, so it can load it from the blockstate.

Add this to your block's code:

setDefaultState(getDefaultState().withProperty(FACING, EnumFacing.NORTH)

(Add it to the constructor)

 

3. Set the state when the block is placed.

You have to set the state when the block is placed. Add this to your block class:

@Override
    @Nonnull
    public IBlockState getStateForPlacement(@Nullable World world, @Nullable BlockPos pos, @Nullable EnumFacing facing, float hitX, float hitY, float hitZ, int meta, @Nullable EntityLivingBase placer, EnumHand hand) {
        assert placer != null;
        return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
    }

The code

placer.getHorizontalFacing().getOpposite()

Just gets the horizontal facing direction (where you are looking along the x and z axis) then gets the opposite so the block faces you.

 

4. Add it to your blockstate

This is an example of a blockstate with facing (works in 1.12.2):

{
  "variants": {
    "facing=north": { "model": "modid:model" },
    "facing=west": { "model": "modid:model", "y": 90 },
    "facing=south": { "model": "modid:model", "y": 180 },
    "facing=east": { "model": "modid:model", "y": 270 }
  }
}

(replace modid with your modid, model with the model resource location)

Posted (edited)
  On 4/9/2019 at 9:22 PM, Big_Bad_E said:

How to do rotation:

 

1. Store the direction

Add this to your block class:
 

public static final PropertyDirection FACING = BlockHorizontal.FACING;

This just stores the direction.

 

2. Tell forge that direction is part of the state

You need to tell forge direction is part of the state, so it can load it from the blockstate.

Add this to your block's code:

setDefaultState(getDefaultState().withProperty(FACING, EnumFacing.NORTH)

(Add it to the constructor)

 

3. Set the state when the block is placed.

You have to set the state when the block is placed. Add this to your block class:

@Override
    @Nonnull
    public IBlockState getStateForPlacement(@Nullable World world, @Nullable BlockPos pos, @Nullable EnumFacing facing, float hitX, float hitY, float hitZ, int meta, @Nullable EntityLivingBase placer, EnumHand hand) {
        assert placer != null;
        return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
    }

The code

placer.getHorizontalFacing().getOpposite()

Just gets the horizontal facing direction (where you are looking along the x and z axis) then gets the opposite so the block faces you.

 

4. Add it to your blockstate

This is an example of a blockstate with facing (works in 1.12.2):

{
  "variants": {
    "facing=north": { "model": "modid:model" },
    "facing=west": { "model": "modid:model", "y": 90 },
    "facing=south": { "model": "modid:model", "y": 180 },
    "facing=east": { "model": "modid:model", "y": 270 }
  }
}

(replace modid with your modid, model with the model resource location)

Expand  
6

Hi, sorry but I am looking for 1.13.2 as it says in the title as I am trying to update my mod from 1.12.2 to 1.13.2. I know from 1.12.2, but 1.13.2 I still need to figure out. Thanks for replying anyway.

Though if this is for 1.13.2 (though you do say 1.12.2 in the blockstate) please can you tell me how my workspace should look?

Edited by Billy Playz
Posted (edited)
  On 4/10/2019 at 3:14 PM, Billy Playz said:

Hi, sorry but I am looking for 1.13.2 as it says in the title as I am trying to update my mod from 1.12.2 to 1.13.2. I know from 1.12.2, but 1.13.2 I still need to figure out. Thanks for replying anyway.

Though if this is for 1.13.2 (though you do say 1.12.2 in the blockstate) please can you tell me how my workspace should look?

Expand  

Sorry totally managed to misread that!
I currently cannot test for 1.13.2 (gradle hates me :/), but the code should not change to my knowledge. If it does not work, what methods are missing/what is the error?

I have read through the notes and have not seen any changes to IProperty or any non-deprecated methods.

Edited by Big_Bad_E
  • Like 1
Posted

Everything is the same except #2 which has been moved to its own method (fillStateContainer)

About Me

  Reveal hidden contents

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)

Posted
  On 4/10/2019 at 9:52 PM, Big_Bad_E said:

Sorry totally managed to misread that!
I currently cannot test for 1.13.2 (gradle hates me :/), but the code should not change to my knowledge. If it does not work, what methods are missing/what is the error? 

I have read through the notes and have not seen any changes to IProperty or any non-deprecated methods.

Expand  

Hi! This is what my Eclipse workspace area looks like when I tried your code. TY.

Xh2Vo7o.png

Posted

Don't just blindly copy the code others provide. For that matter never blindly copy other's code. In this case you are trying to use 1.12 code in a 1.13 environment.

You can always see how this is done in vanilla, something like BlockDispenser for example should be exactly what you need.

 

  On 4/9/2019 at 9:22 PM, Big_Bad_E said:

assert placer != null;

Expand  

I don't really see the point of this assertion. If the placer is null you will crash anyway one line later with a NPE. 

Posted
  On 4/11/2019 at 3:41 PM, V0idWa1k3r said:

Don't just blindly copy the code others provide. For that matter never blindly copy other's code. In this case you are trying to use 1.12 code in a 1.13 environment. 

You can always see how this is done in vanilla, something like BlockDispenser for example should be exactly what you need.

 

I don't really see the point of this assertion. If the placer is null you will crash anyway one line later with a NPE. 

Expand  
3

I do understand, it is just he asked what errors showed up as he could not figure out why it does not work as he could not see any notes saying it has been changed (and I know it has changed, hence why I am wanting to have some help on how to do it). I am aware that copying code blindly is bad, I have learnt. I am asking for rotating code in a java class as the vanilla code does not work and I have no idea what I am doing with it in 1.13.2 as the code has changed. What do I extend if I need to? What do I implement if I need to? What is the code for the placement? What is the code for checking the player? Where do I put the code? Can the code be in a class file, or does it have to be where I have set the properties? Is my code correct? The only answer I know is that I have no idea how to do it, and I cannot find any help on this. This is why I have turned to the forums - for answers.

Posted
  On 4/11/2019 at 4:28 PM, Billy Playz said:

I am asking for rotating code in a java class as the vanilla code does not work

Expand  

Why? Vanilla code works perfectly fine for vanilla. In this case it should work perfectly for your use-case aswell as long as you implement it correctly.

 

  On 4/11/2019 at 4:28 PM, Billy Playz said:

I have no idea what I am doing with it in 1.13.2 as the code has changed.

Expand  

If you have no idea what the code does you can look at vanilla's class and figure it out. Sure it changed but that doesn't stop you from figuring out how it works. You are not looking at magical spaghetti code of 10000+ lines after all.

 

  On 4/11/2019 at 4:28 PM, Billy Playz said:

What do I extend if I need to?

Expand  

Since you are making a block you need to extend Block.

 

  On 4/11/2019 at 4:28 PM, Billy Playz said:

What do I implement if I need to?

Expand  

Depends on what you want your block to do. Again, see vanilla for examples.

 

  On 4/11/2019 at 4:28 PM, Billy Playz said:

What is the code for the placement?

Expand  

Again, you can see it for yourself in vanilla classes like BlockFurnace, BlockDispenser, BlockPiston, etc.

 

  On 4/11/2019 at 4:28 PM, Billy Playz said:

What is the code for checking the player?

Expand  

What does this question even mean? Why do you need to be "checking" the player?

 

  On 4/11/2019 at 4:28 PM, Billy Playz said:

Where do I put the code?

Expand  

...in your block class.

 

  On 4/11/2019 at 4:28 PM, Billy Playz said:

Can the code be in a class file, or does it have to be where I have set the properties?

Expand  

I am sorry but if you are asking questons like these you need to learn basic java. You can't make a minecraft mod without understanding the fundamentals of the programming language you are using.

 

  On 4/11/2019 at 4:28 PM, Billy Playz said:

Is my code correct?

Expand  

Your IDE tells you that.

 

  On 4/11/2019 at 4:28 PM, Billy Playz said:

This is why I have turned to the forums - for answers.

Expand  

Well, here are your answers - learn java(at least the basics of it) and look at how vanilla does things. Then you can come back with more specific questions we would be able to answer without telling you to look at vanilla's code.

Posted (edited)
placer.getHorizontalFacing().getOpposite()

That line is what "checks the player" (checks where they are facing).

It seems a remap might of changed it, try using:

PropertyEnum<EnumFacing>

instead of

PropertyDirection

and set it to be:

new PropertyEnum<EnumFacing>("facing", EnumFacing.class, Collections2.filter(Lists.newArrayList(EnumFacing.values()), EnumFacing.Plane.HORIZONTAL);

 

 

Edited by Big_Bad_E
Posted (edited)
  On 4/11/2019 at 3:41 PM, V0idWa1k3r said:

Don't just blindly copy the code others provide. For that matter never blindly copy other's code. In this case you are trying to use 1.12 code in a 1.13 environment.

You can always see how this is done in vanilla, something like BlockDispenser for example should be exactly what you need.

 

I don't really see the point of this assertion. If the placer is null you will crash anyway one line later with a NPE. 

Expand  

Because Intellij is annoying, and you never know. Makes it easier to debug I guess, also personal preference.

 

Also, yes, never blindly copy paste code, and if you are stuck you can always get code from vanilla blocks (that is where that code is from anyways)

 

I would suggest playing around in Java with other things, Forge is one of the hardest libraries out there. If you want to stick with Minecraft, Spigot is a lot easier. You could also mess around with Discord bots (https://github.com/DV8FromTheWorld/JDA/releases) or make games/software.

Edited by Big_Bad_E

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

    • Working $200 Off Temu Coupon Code [acu639380] First Order Exclusive Temu Coupon Code (acu639380) – Save Big on Your Shopping! Temu has become a go-to online marketplace for shoppers looking for high-quality products at unbeatable prices. With millions of trending items, fast delivery, and free shipping available in 67 countries, Temu ensures a seamless shopping experience for its users. Now, you can make your purchases even more rewarding by using the Temu coupon code (acu639380) to unlock huge discounts of up to $200 and exclusive deals. Why Use the Temu Coupon Code (acu639380)? By applying the Temu discount code (acu639380) at checkout, you can enjoy massive savings of up to $200 on a wide range of categories, including electronics, fashion, home essentials, beauty products, and more. This special offer is available to both new and existing users, ensuring that everyone gets a chance to save big on their favorite items What Discounts Can You Get with Temu Coupon Code (acu639380)? Here’s what you can unlock with the Temu promo code (acu639380): $200 Off for New Users – First-time shoppers can enjoy a flat $200 discount on their initial order. $200 Off for Existing Users – Loyal customers can also claim $200 off their purchases with the same code. Extra 40% Off – The Temu discount code (acu639380) provides an additional 40% off on select items, maximizing your savings. $200 Coupon Bundle – Both new and existing users can receive a $200 coupon bundle, perfect for future purchases. Free Gifts for New Users – If you’re shopping on Temu for the first time, you June receive free gifts with your order. Temu Coupons for Different Countries Temu caters to shoppers worldwide, offering incredible discounts based on your location. Here’s how the Temu coupon code (acu639380) benefits users across different regions: United States – Get $200 off your first order using the Temu coupon code (acu639380). Canada – Enjoy $200 off on your first-time purchase. United Kingdom – Use the Temu promo code (acu639380) to get $200 off your first order. Japan – Japanese shoppers can claim $200 off their initial purchase. Mexico – Get an extra 40% discount on select products with the Temu coupon (acu639380). Brazil – Shoppers in Brazil can also save 40% on select items. Germany – Receive a 40% discount on eligible products with the Temu promo code (acu639380). How to Use the Temu Coupon Code (acu639380)? Applying the Temu discount code (acu639380) is simple and hassle-free. Follow these easy steps to redeem your discount: Sign Up or Log In – Create a new account or log in to your existing Temu account. Shop for Your Favorite Items – Browse through Temu’s vast collection and add products to your cart. Enter the Coupon Code – At checkout, apply the Temu promo code (acu639380) in the designated field. Enjoy Your Discount – See the discount applied to your order and proceed with payment. Why Shop on Temu? Apart from huge discounts, Temu offers several benefits that make shopping more exciting and budget-friendly: Up to 90% Off on Select Products – Temu regularly offers massive discounts on top-selling items. Fast & Free Shipping – Get your products delivered quickly with free shipping to 67 countries. Wide Product Selection – Shop from a vast range of categories, including electronics, fashion, home essentials, and more. Safe & Secure Payments – Temu ensures a secure checkout process for a smooth shopping experience. Exclusive App Deals – Download the Temu app for extra discounts and app-only promotions. Final Thoughts With Temu’s exclusive coupon code (acu639380), you can unlock huge savings and enjoy a premium shopping experience at an affordable price. Whether you are a new user looking for a $200 discount or an existing customer wanting an extra 40% off, Temu has something for everyone. Don't forget to claim your $200 coupon bundle and free gifts before these amazing deals expire! Start shopping today on Temu and use the Temu coupon code (acu639380) to maximize your savings!  
    • Temu Coupon Code $100 Off [acu639380] First Time User Unlock Huge Savings: Temu Coupon Code (acu639380) for June 2025 Temu is transforming the way the world shops—and June 2025 delivers its boldest offers yet. With the exclusive Temu coupon code (acu639380), you're entering a world of rewards: from a $100 discount to premium coupon bundles, it's your passport to smart, stylish savings. The Temu Advantage in June 2025 Temu is known for redefining affordability and access. With unbeatable prices across trending categories—from fashion to electronics—it now delivers to 67 countries with speed and reliability. But this month, it’s not just about what you buy. It’s about how much you save. With Temu coupon code (acu639380) in hand, your savings soar. Instant Rewards with Temu Coupon Code (acu639380) If you haven't activated this exclusive code, here's what you're missing: $100 Off for first-time users $100 Off for returning customers 40% Off on sitewide items Free gifts for new sign-ups $100 Coupon Bundle available for all users What Makes Temu Coupon Code (acu639380) Unique? This code is designed to reward all shoppers—first-timers and loyal fans alike. Here’s how each discount delivers: Temu coupon code (acu639380) $100 off: Best for newcomers stocking up. Temu coupon code (acu639380) $100 off for existing users: Returning shoppers save big. Temu coupon code (acu639380) 40% off: Big savings on trending picks. Temu $100 coupon bundle: Split savings across several purchases. Temu first time user coupon: Ideal to kickstart your shopping spree. Global Value, Personalized Access Temu isn't just generous—it’s international. Whether you're in a Toronto high-rise or a Yorkshire farmhouse, the Temu promo code (acu639380) unlocks smart deals and chic finds. Coupon Code Highlights by Country Temu coupon code $100 off for USA – (acu639380) Temu coupon code $100 off for Canada – (acu639380) Temu coupon code $100 off for UK – (acu639380) Temu coupon code $100 off for Japan – (acu639380) Temu coupon code 40% off for Mexico – (acu639380) Temu coupon code 40% off for Brazil – (acu639380) Why Temu is the Marketplace of the Moment Unbeatable prices: Save up to 90% every day Worldwide reach: Ships to 67 countries New promotions: Fresh Temu new offers in June 2025 Fast, free delivery: No matter where you are FAQ: Maximize Your Temu Experience What’s the best Temu discount in June 2025? The top offer is Temu coupon code (acu639380) $100 off, for both new and existing users. Can I use these deals worldwide? Yes. The Temu discount code (acu639380) for June 2025 is valid in North America, South America, Europe, and Asia. Can I combine discounts? Absolutely. Pair your Temu $100 coupon bundle with seasonal deals for extra savings. Final Takeaway Smart shopping isn’t just about what you add to your cart—it’s about how you unlock value. With Temu coupon codes for new users, Temu coupon codes for existing users, and exciting June 2025 promotions, the best time to save is now. Don’t wait. Use Temu coupon code (acu639380) today to claim your rewards and transform the way you shop. New offers, global access, and exclusive savings await.  
    • Maybe it refers to an issue with the system - check for CPU/GPU driver updates
    • I haven't tried any other launchers, but I was getting the same results when I tried using forge with the vanilla launcher.
    • Make a test without sodiumextras
  • Topics

×
×
  • Create New...

Important Information

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