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:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

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

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)
17 hours ago, 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)

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)
6 hours ago, 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?

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

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)

Posted
13 hours ago, 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.

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/10/2019 at 12:22 AM, Big_Bad_E said:

assert placer != null;

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
37 minutes ago, 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. 

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
4 hours ago, Billy Playz said:

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

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.

 

4 hours ago, Billy Playz said:

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

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.

 

4 hours ago, Billy Playz said:

What do I extend if I need to?

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

 

4 hours ago, Billy Playz said:

What do I implement if I need to?

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

 

4 hours ago, Billy Playz said:

What is the code for the placement?

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

 

4 hours ago, Billy Playz said:

What is the code for checking the player?

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

 

4 hours ago, Billy Playz said:

Where do I put the code?

...in your block class.

 

4 hours ago, Billy Playz said:

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

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.

 

4 hours ago, Billy Playz said:

Is my code correct?

Your IDE tells you that.

 

4 hours ago, Billy Playz said:

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

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)
6 hours ago, 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. 

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

    • So am trying to make a custom 1.19.2 modpack and everything works until I add Oculus. I have tried Oculus+Embedium and Oculus+Rubdium and by themselves they work but as soon as I add anything it crashes no matter what it is. The modpack works fine with just Embedium and Rubdium. Can you help me to see if this is something i can fix or do i just have to deal with not having shaders. Here is the crash log. Thank you for your time. https://paste.ee/p/WXfNZ24K
    • New users at Temureceive a 40 Off discount on orders over 40 Off Use the code [{acx318439}]] during checkout to get TemuDiscount 40 Off For New Users. You n save 40 Off off your first order with the Promo Code available for a limited time only. Extra 30% off for new and existing customers + Up to $40 Off % off & more. Temu Promo Codes for New users- [{acx318439}]] Temudiscount code for New customers- [{acx318439}]] Temu $40 Off Promo Code- [{acx318439}]] what are Temu codes- acx318439 does Temu give you $40 Off - [{acx318439}]] Yes Verified Temu Promo Code january 2025- {acx318439} TemuNew customer offer {acx318439} Temudiscount codejanuary 2025 {acx318439} 40 off Promo Code Temu {acx318439} Temu 40% off any order {acx318439} 40 dollar off Temu code {acx318439} TemuCoupon $40 Off off for New customers There are a number of discounts and deals shoppers n take advantage of with the Teemu Coupon Bundle [{acx318439}]]. TemuCoupon $40 Off off for New customers [{acx318439}]] will save you $40 Off on your order. To get a discount, click on the item to purchase and enter the code. You n think of it as a supercharged savings pack for all your shopping needs Temu Promo Code 80% off – [{acx318439}]] Free Temu codes 50% off – [{acx318439}]] TemuCoupon $40 Off off – [{acx318439}]] Temu buy to get ₱39 – [{acx318439}]] Temu 129 coupon bundle – [{acx318439}]] Temu buy 3 to get €99 – [{acx318439}]] Exclusive $40 Off Off TemuDiscount Code Temu $40 Off Off Promo Code : (acx318439) Temu Discount Code $40 Off Bundle acx318439) acx318439 Temu $40 Off off Promo Code for Exsting users : acx318439) Temu Promo Code $40 Off off Temu 40 Off coupon code (acx318439) will save you 40 Off on your order. To get a discount, click on the item to purchase and enter the code. Yes, Temu offers 40 Off Coupon Code “acx318439” for Existing Customers.  You can get a 40 Off bonus plus 30% off any purchase at Temu with the 40 Off Coupon Bundle at Temu if you sign up with the referral code [{acx318439}]] and make a first purchase of $40 Off or more. Temu Promo Code 40 off-{acx318439} Temu Promo Code -{acx318439} Temu Promo Code $40 Off off-{acx318439} kubonus code -{acx318439} Get ready to unlock a world of savings with our free Temu UK coupons! We’ve got you covered with a wide range of Temu UK coupon code options that will help you maximize your shopping experience.30% Off Temu UK Coupons, Promo Codes + 25% Cash Back [ acx318439]   Yes, Temu offers 40 off coupon code {acx318439} for first-time users. You can get a $40 bonus plus 40% off any purchase at Temu with the $40 Coupon Bundle if you sign up with the referral code [{acx318439}]] and make a first purchase of $40 or more. If you are who wish to join Temu, then you should use this exclusive TemuCoupon code 40 off (acx318439) and get 40 off on your purchase with Temu. You can get a 40% discount with TemuCoupon code {acx318439}. This exclusive offer is for existing customers and can be used for a 40 reduction on your total purchase. Enter coupon code {acx318439} at checkout to avail of the discount. You can use the code {acx318439} to get a 40 off TemuCoupon as a new customer. Apply this TemuCoupon code $40 off (acx318439) to get a $40 discount on your shopping with Temu. If you’re a first-time user and looking for a TemuCoupon code $40 first time user(acx318439) then using this code will give you a flat $40 Off and a 90% discount on your Temu shopping.     •    acx318439: Enjoy flat 40% off on your first Temu order.     •    acx318439: Download the Temu app and get an additional 40% off.     •    acx318439: Celebrate spring with up to 90% discount on selected items.     •    acx318439: Score up to 90% off on clearance items.     •    acx318439: Beat the heat with hot summer savings of up to 90% off.     •    acx318439: Temu UK Coupon Code to 40% off on Appliances at Temu. How to Apply Temu Coupon Code? Using the TemuCoupon code $40 off is a breeze. All you need to do is follow these simple steps:     1    Visit the Temu website or app and browse through the vast collection of products.     2    Once you’ve added the items you wish to purchase to your cart, proceed to the checkout page.     3    During the checkout process, you’ll be prompted to enter a coupon code or promo code.     4    Type in the coupon code: [{acx318439}]] and click “Apply.”     5    Voila! You’ll instantly see the $40 discount reflected in your total purchase amount. Temu New User Coupon: Up To 90% OFF For Existing Customers Temu Existing customer’s coupon codes are designed just for new customers, offering the biggest discounts 90% and the best deals currently available on Temu. To maximize your savings, download the Temu app and apply our Temu new user coupon during checkout.     •    acx318439: New users can get up to 80% extra off.     •    acx318439: Get a massive 40% off your first order!     •    acx318439: Get 20% off on your first order; no minimum spending required.     •    acx318439: Take an extra 15% off your first order on top of existing discounts.     •    acx318439: Temu UK Enjoy a 40% discount on your entire first purchase.  
    • What do I do now when it says "1 error"?
    • Hello everyone new here how are you all?
    • I haven't tested it but under https://minecraft.wiki/w/Items_model_definition it says now:   So I guess the resource location must have changed with 1.24.4, which means you need to move your models/item/ to the new source. But as I said I haven't tested this so it also may be that this wont work. Nevertheless give it a try      EDIT (important) So now I tested it and found out how it works   Let the model files (e.g. the .json from blockbench) within "assets/<your_mod_id>/models/item" In addition to that do the following: Every model you added will need a new file under "assets/<your_mod_id>/items" That file is also a JSON and looks like this: { "model": { "type": "minecraft:model", "model": "your_mod_id:item/custom_item" } } - "type" can be minecraft:model, minecraft:composite, minecraft:condition, minecraft:select, minecraft:range_dispatch, minecraft:empty, minecraft:bundle/selected_item or minecraft:special. (In most cases you would need minecraft:model) - "model" is the path to your actual model for this item. For example the value above would point to "assets/your_mod_id/models/item/custom_item"
  • Topics

×
×
  • Create New...

Important Information

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