com.magistuarmory.item.PaviseItem Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of 1.20.2-epic-knights-common Show documentation
Show all versions of 1.20.2-epic-knights-common Show documentation
mod that adds medieval stuff to the game
package com.magistuarmory.item;
import com.magistuarmory.block.ModBlocks;
import net.minecraft.class_124;
import net.minecraft.class_1269;
import net.minecraft.class_1657;
import net.minecraft.class_174;
import net.minecraft.class_1750;
import net.minecraft.class_1799;
import net.minecraft.class_1836;
import net.minecraft.class_1838;
import net.minecraft.class_1937;
import net.minecraft.class_2246;
import net.minecraft.class_2248;
import net.minecraft.class_2338;
import net.minecraft.class_2350;
import net.minecraft.class_2487;
import net.minecraft.class_2498;
import net.minecraft.class_2499;
import net.minecraft.class_2561;
import net.minecraft.class_2586;
import net.minecraft.class_2591;
import net.minecraft.class_2680;
import net.minecraft.class_2689;
import net.minecraft.class_2769;
import net.minecraft.class_3222;
import net.minecraft.class_3414;
import net.minecraft.class_3419;
import net.minecraft.class_3726;
import net.minecraft.class_4538;
import net.minecraft.class_5712;
import net.minecraft.class_7699;
import net.minecraft.server.MinecraftServer;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Objects;
public class PaviseItem extends MedievalShieldItem
{
private final class_2350 attachmentDirection = class_2350.field_11033;
public PaviseItem(String id, String name, class_1793 properties, ModItemTier material, boolean paintable, boolean is3d, ShieldType type)
{
super(id, name, properties, material, paintable, is3d, type);
}
private static > class_2680 updateState(class_2680 blockstate, class_2769 property, String string)
{
return property.method_11900(string).map((comparable) -> blockstate.method_11657(property, comparable)).orElse(blockstate);
}
public static boolean updateCustomBlockEntityTag(class_1937 level, @Nullable class_1657 player, class_2338 blockpos, class_1799 stack)
{
MinecraftServer server = level.method_8503();
if (server != null)
{
class_2487 blockentitytag = getBlockEntityData(stack);
class_2586 blockentity = level.method_8321(blockpos);
if (blockentity != null)
{
if (!level.field_9236 && blockentity.method_11011() && (player == null || !player.method_7338()))
return false;
class_2487 tag2 = blockentity.method_38244();
class_2487 tag3 = tag2.method_10553();
if (stack.method_7969() != null)
tag2.method_10566("ItemStack", stack.method_7969());
tag2.method_10556("Enchanted", stack.method_7942());
tag2.method_10582("ShieldId", ((PaviseItem) stack.method_7909()).getId());
if (blockentitytag != null)
{
blockentitytag.method_10569("Base", PaviseItem.method_8013(stack).method_7789());
tag2.method_10543(blockentitytag);
}
if (!tag2.equals(tag3))
{
blockentity.method_11014(tag2);
blockentity.method_5431();
return true;
}
}
}
return false;
}
@Nullable
public static class_2487 getBlockEntityData(class_1799 stack)
{
return stack.method_7941("BlockEntityTag");
}
public static class_2499 getEnchantmentData(class_1799 stack)
{
return stack.method_7921();
}
public static void setBlockEntityData(class_1799 stack, class_2591> type, class_2487 tag)
{
if (tag.method_33133())
stack.method_7983("BlockEntityTag");
class_2586.method_38238(tag, type);
stack.method_7959("BlockEntityTag", tag);
}
@Override
public class_1269 method_7884(class_1838 context)
{
class_1269 result = super.method_7884(context);
if (result.method_23665() || (context.method_8036() != null && !context.method_8036().method_5715()))
return result;
result = this.place(new class_1750(context));
if (!result.method_23665() && this.method_19263())
{
class_1269 result2 = this.method_7836(context.method_8045(), context.method_8036(), context.method_20287()).method_5467();
return result2 == class_1269.field_21466 ? class_1269.field_33562 : result2;
}
return result;
}
public class_1269 place(class_1750 context)
{
if (!this.getBlock().method_45382(context.method_8045().method_45162()))
return class_1269.field_5814;
if (!context.method_7716())
return class_1269.field_5814;
class_1750 context2 = this.updatePlacementContext(context);
if (context2 == null)
return class_1269.field_5814;
class_2680 blockstate = this.getPlacementState(context2);
if (blockstate == null)
return class_1269.field_5814;
if (!this.placeBlock(context2, blockstate))
return class_1269.field_5814;
class_2338 blockpos = context2.method_8037();
class_1937 level = context2.method_8045();
class_1657 player = context2.method_8036();
class_1799 stack = context2.method_8041();
class_2680 blockstate2 = level.method_8320(blockpos);
if (blockstate2.method_27852(blockstate.method_26204()))
{
blockstate2 = this.updateBlockStateFromTag(blockpos, level, stack, blockstate2);
this.updateCustomBlockEntityTag(blockpos, level, player, stack, blockstate2);
blockstate2.method_26204().method_9567(level, blockpos, blockstate2, player, stack);
if (player instanceof class_3222)
class_174.field_1191.method_23889((class_3222) player, blockpos, stack);
}
class_2498 sound = blockstate2.method_26231();
level.method_8396(player, blockpos, this.getPlaceSound(blockstate2), class_3419.field_15245, (sound.method_10597() + 1.0F) / 2.0F, sound.method_10599() * 0.8F);
level.method_43276(class_5712.field_28164, blockpos, class_5712.class_7397.method_43286(player, blockstate2));
if (player == null || !player.method_31549().field_7477)
stack.method_7934(1);
return class_1269.method_29236(level.field_9236);
}
protected class_3414 getPlaceSound(class_2680 blockstate)
{
return blockstate.method_26231().method_10598();
}
@Nullable
public class_1750 updatePlacementContext(class_1750 context)
{
return context;
}
protected boolean updateCustomBlockEntityTag(class_2338 blockpos, class_1937 level, @Nullable class_1657 player, class_1799 stack, class_2680 blockstate)
{
return updateCustomBlockEntityTag(level, player, blockpos, stack);
}
private class_2680 updateBlockStateFromTag(class_2338 blockpos, class_1937 level, class_1799 stack, class_2680 blockstate)
{
class_2680 blockstate2 = blockstate;
class_2487 tag = stack.method_7969();
if (tag != null)
{
class_2487 tag2 = tag.method_10562("BlockStateTag");
class_2689 statedefinition = blockstate.method_26204().method_9595();
for (String string : tag2.method_10541())
{
class_2769> property = statedefinition.method_11663(string);
if (property != null)
{
String string2 = Objects.requireNonNull(tag2.method_10580(string)).method_10714();
blockstate2 = updateState(blockstate2, property, string2);
}
}
}
if (blockstate2 != blockstate)
level.method_8652(blockpos, blockstate2, 2);
return blockstate2;
}
protected boolean placeBlock(class_1750 context, class_2680 blockstate)
{
class_1937 level = context.method_8045();
class_2338 aboveblockpos = context.method_8037().method_10084();
if (level.method_16358(aboveblockpos, (state) -> state.method_26204() != class_2246.field_10124) && !level.method_22351(aboveblockpos))
return false;
if (!context.method_8045().method_8652(context.method_8037(), blockstate, 11))
return false;
level.method_8652(aboveblockpos, ModBlocks.PAVISE_UPPER_COLLISION.get().method_9564(), 27);
return true;
}
public String method_7876()
{
return this.getBlock().method_9539();
}
@Override
public void method_7851(class_1799 stack, @Nullable class_1937 level, List list, class_1836 tooltipflag)
{
super.method_7851(stack, level, list, tooltipflag);
list.add(class_2561.method_43471("canbeplacedonground").method_27692(class_124.field_1078));
}
public class_2248 getBlock()
{
return ModBlocks.PAVISE.get();
}
public class_7699 method_45322()
{
return this.getBlock().method_45322();
}
protected boolean canPlace(class_4538 levelreader, class_2680 blockstate, class_2338 blockpos)
{
return blockstate.method_26184(levelreader, blockpos);
}
@Nullable
protected class_2680 getPlacementState(class_1750 context)
{
class_2680 blockstate2 = null;
class_4538 levelreader = context.method_8045();
class_2338 blockpos = context.method_8037();
class_2350[] var6 = context.method_7718();
for (class_2350 direction : var6)
{
if (direction != this.attachmentDirection.method_10153())
{
class_2680 blockstate3 = this.getBlock().method_9605(context);
if (blockstate3 != null && this.canPlace(levelreader, blockstate3, blockpos))
{
blockstate2 = blockstate3;
break;
}
}
}
return blockstate2 != null && levelreader.method_8628(blockstate2, blockpos, class_3726.method_16194()) ? blockstate2 : null;
}
}