#how to create a map

11 messages · Page 1 of 1 (latest)

pearl lotus
#

I have a map defined as a class attribute

import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Predicate;
public class BetterPaths implements ModInitializer {
    public static final String MOD_ID = "betterpaths";
    public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
    public static Map<BlockState, Pair<Predicate<ItemUsageContext>, Consumer<ItemUsageContext>>> TILLING_ACTIONS; // Here is the Map
@Override
public void onInitialize() {
    ModItemGroups.registerItemGroups();
    //ModItems.registerModItems();
    ModBlocks.registerModBlocks();
    TILLING_ACTIONS = // I want to assign to it here
}

I have these 2 key value pairs ready

ModBlocks.GRASS_SLAB.getDefaultState(), Pair.of(HoeItem::canTillFarmland, HoeItem.createTillAction(ModBlocks.FARMLAND_SLAB.getDefaultState())),

ModBlocks.GRASS_SLAB.getDefaultState().with(TYPE, SlabType.TOP), Pair.of(HoeItem::canTillFarmland, HoeItem.createTillAction(ModBlocks.FARMLAND_SLAB.getDefaultState().with(TYPE, SlabType.TOP)))
limber hullBOT
#

This post has been reserved for your question.

Hey @pearl lotus! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

rose pasture
#

whats the issue?

pearl lotus
#

I don't know what to put on the line TILLING_ACTIONS=

rose pasture
#

an implementation of Map, like new HashMap<>()

#

and then you can add your key-value pairs afterwards

#

otherwise you can also use Map.of(...) BUT that returns a immutable map, which means you cant add or remove stuff

pearl lotus
#

thanks

limber hullBOT
# pearl lotus thanks

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.

limber hullBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.