All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.magistuarmory.item.MedievalBagItem Maven / Gradle / Ivy

There is a newer version: 8.10
Show newest version
package com.magistuarmory.item;

import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.class_124;
import net.minecraft.class_1268;
import net.minecraft.class_1269;
import net.minecraft.class_1271;
import net.minecraft.class_1542;
import net.minecraft.class_1657;
import net.minecraft.class_1792;
import net.minecraft.class_1799;
import net.minecraft.class_1836;
import net.minecraft.class_1937;
import net.minecraft.class_2487;
import net.minecraft.class_2499;
import net.minecraft.class_2561;


public class MedievalBagItem extends class_1792
{
	public MedievalBagItem()
	{
		super(new class_1793().method_7889(1));
	}
	
	@Override
	public class_1271 method_7836(class_1937 level, class_1657 player, class_1268 hand)
	{
		class_1271 result = super.method_7836(level, player, hand);
		if (level.method_8608() || result.method_5467().method_23665())
			return result;
		
		class_1799 bagstack = player.method_5998(hand);
		player.method_31548().method_5447(player.method_31548().method_7395(bagstack), class_1799.field_8037);
		
		for (class_1799 stack : getContents(bagstack))
		{
			if (!player.method_7270(stack))
				level.method_8649(new class_1542(level, player.method_23317(), player.method_23318(), player.method_23321(), stack));
		}
		
		return new class_1271<>(class_1269.field_5812, bagstack);
	}
	
	@Override
	public void method_7851(class_1799 stack, @Nullable class_1937 level, List list, class_1836 tooltipflag)
	{
		list.add(class_2561.method_43471("medieval_bag.rightclick").method_27692(class_124.field_1078));
	}
		
	public static void setContents(class_1799 bagstack, List stacks)
	{
		class_2499 listtag = new class_2499();
		for (class_1799 stack : stacks)
			listtag.add(stack.method_7953(new class_2487()));
		
		bagstack.method_7959("Contents", listtag);
	}
	
	public static List getContents(class_1799 bagstack)
	{
		List stacks = new ArrayList<>();
		class_2487 compound = bagstack.method_7969();
		class_2499 listtag = compound != null ? bagstack.method_7969().method_10554("Contents", 10) : new class_2499();
		for (int i = 0; i < listtag.size(); ++i)
			stacks.add(class_1799.method_7915(listtag.method_10602(i)));
		
		return stacks;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy