#Cancel block place

35 messages · Page 1 of 1 (latest)

maiden flame
#

Check out UseBlockCallback. If that doesn't work (it might have to be server-side, idk), feel free to copy the mixin from my mod here and modify it to check for name instead of custom model data.

#

It should work for 1.20-1.20.4, and there's branches going down to 1.15.x if you're going that low

past spindle
#

thx

maiden flame
#

@past spindle Are you trying to stop from placing a specific block, rather than just the name? If so, check what type the block is. No need to try and check names.

past spindle
maiden flame
#

+👍

past spindle
#

that why it's like an item

maiden flame
#

Not sure what you mean by that, but it's a lot safer (and probably faster) to just check if it's a pumpkin rather than testing if it's named "Pumpkin" in the same language. Especially if someone renames the item.

past spindle
#

and, do you now how to ignore capslock in string?

maiden flame
#

String#toLowerCase or something like that

#

Then you compare with a lower case string

past spindle
#

@maiden flame

#

sorry for asking again, but idk why this is again not working, if you have time, can you help me?

#

if (stack.getName() == null || !equalsIgnoreCase((stack.getName().toString()), (Text.translatable("item.cherrytown.gold_cherry_vision").toString()))){ return true; } else if (stack.getName() == null || !equalsIgnoreCase((stack.getName().toString()), (Text.translatable("item.gold_cherrytown.gold_cherry_vision").toString()))){ return true; } else if (stack.getName() == null || !equalsIgnoreCase((stack.getName().toString()), (Text.translatable("text.gold_cherrytown.gold_cherry_vision").toString()))){ return true; }

#

its comparing to string with equalsignorecase

#

no errors in ide*

#

if its identical no matter capslock, then true

#

so its reversed

#

and if item its not that = true

maiden flame
#

So you're trying to prevent yourself from placing everything except this gold_cherry_vision thing, right?

maiden flame
#

Ok, so only that? First off, you're trying to compare a strings for the objects, not the strings that are the names. Second, that's a strange way of doing it - you're making a lot more work for yourself.

#

Next, I don't know where equalsIgnoreCase came from, that's an instance method in String, but I suppose that doesn't matter since we don't need it.

#

You're needing stack.getItem().equals(*/ Wherever your item is*/.*/ITEM_NAME*/)

past spindle
#

That's all?

maiden flame
#

Yep.

#

How much java experience do you have?

past spindle
maiden flame
#

OK, well there's your problem :P

#

Here's some good resources to help you get started

#

Minecraft modding is a really hard place to start

#

!!learnjava

velvet patrolBOT
#

To start modding Minecraft using Fabric, it's strongly recommended to know Java.
Minecraft, in its codebase, and mods, using Fabric API, use more advanced Java concepts like lambdas, generics and polymorphism.
If you don't know all of these concepts, you may have some difficulties modding.

Here are some online resources that will help learning Java
JetBrains Academy (free online course): https://www.jetbrains.com/academy/
Codecademy (free online course): https://www.codecademy.com/learn/learn-java
University of Helsinki (free online course): https://java-programming.mooc.fi/
Basic Java Tutorials: https://docs.oracle.com/javase/tutorial/
Introduction to Programming using Java by David J. Eck (free online textbook): http://math.hws.edu/javanotes/

After Learning Java
For most mods you will want to make, you will have to use the Spongepowered Mixin Java library.
To learn more about Mixin, you can use the faq/mixin bot tag by typing !!faq/mixin in #bot-posting .