Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.magistuarmory.block.PaviseBlock Maven / Gradle / Ivy
package com.magistuarmory.block;
import com.magistuarmory.item.MedievalShieldItem;
import com.magistuarmory.item.ModItems;
import com.mojang.math.Quaternion;
import com.mojang.math.Vector3f;
import dev.architectury.registry.registries.RegistrySupplier;
import net.minecraft.core.BlockPos;
import net.minecraft.stats.Stats;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class PaviseBlock extends BannerBlock
{
// static final VoxelShape SHAPE = Block.box(4.0, 0.0, 4.0, 12.0, 16.0, 12.0);
static final AABB COLLISION_AABB = new AABB(0.0 / 16.0, 0.0, 7.5 / 16.0, 1.0, 1.0, 8.5 / 16.0);
public static final Vector3f CENTER = new Vector3f(0.5f, 0.5f, 0.5f);
public static final Vector3f BOXMIN = new Vector3f(0.0f, 0.0f, 0.0f);
public static final Vector3f BOXMAX = new Vector3f(1.0f, 1.0f, 1.0f);
public PaviseBlock()
{
super(DyeColor.WHITE, BlockBehaviour.Properties.m_60939_(Material.f_76320_).m_60988_().m_60918_(SoundType.f_56736_));
}
@Override
public BlockEntity m_142194_(BlockPos blockpos, BlockState blockstate)
{
return new PaviseBlockEntity(blockpos, blockstate);
}
@Override
public @NotNull Item m_5456_()
{
RegistrySupplier item = ModItems.PAVISES.wood;
return item != null ? item.get() : Items.f_41852_;
}
@Override
public void m_142387_(Level level, Player player, BlockPos blockPos, BlockState blockstate)
{
}
@Override
public BlockState m_5573_(BlockPlaceContext blockPlaceContext)
{
return this.m_49966_().m_61124_(f_49007_, Mth.m_14107_((double)((blockPlaceContext.m_7074_()) * 16.0F / 360.0F) + 0.5) & 15);
}
@Override
public @NotNull ItemStack m_7397_(BlockGetter blockgetter, BlockPos blockpos, BlockState blockstate)
{
if (blockgetter.m_7702_(blockpos) instanceof PaviseBlockEntity pavise)
return pavise.getItem();
return ItemStack.f_41583_;
}
@Override
public VoxelShape m_5940_(BlockState blockstate, BlockGetter blockgetter, BlockPos blockpos, CollisionContext context)
{
AABB aabb = COLLISION_AABB;
float yrot = -blockstate.m_61143_(BannerBlock.f_49007_) * 360.0F / 16.0F;
aabb = rotateAABB(aabb, Vector3f.f_122225_.m_122240_(yrot));
return Shapes.m_83064_(aabb);
}
public static AABB rotateAABB(AABB axisAlignedBB, Quaternion quaternion)
{
// Extract the minimum and maximum coordinates of the AABB into vectors
final Vector3f mincoords = new Vector3f((float) axisAlignedBB.f_82288_, (float) axisAlignedBB.f_82289_, (float) axisAlignedBB.f_82290_);
final Vector3f maxcoords = new Vector3f((float) axisAlignedBB.f_82291_, (float) axisAlignedBB.f_82292_, (float) axisAlignedBB.f_82293_);
mincoords.m_122267_(CENTER);
maxcoords.m_122267_(CENTER);
mincoords.m_122251_(quaternion);
maxcoords.m_122251_(quaternion);
mincoords.m_122253_(CENTER);
maxcoords.m_122253_(CENTER);
float xmin = Math.max(mincoords.m_122239_(), BOXMIN.m_122239_());
float ymin = Math.max(mincoords.m_122260_(), BOXMIN.m_122260_());
float zmin = Math.max(mincoords.m_122269_(), BOXMIN.m_122269_());
float xmax = Math.min(maxcoords.m_122239_(), BOXMAX.m_122239_());
float ymax = Math.min(maxcoords.m_122260_(), BOXMAX.m_122260_());
float zmax = Math.min(maxcoords.m_122269_(), BOXMAX.m_122269_());
return new AABB(xmin, ymin, zmin, xmax, ymax, zmax);
}
@Override
public void m_6240_(Level level, Player player, BlockPos blockpos, BlockState blockstate, @Nullable BlockEntity blockentity, ItemStack stack)
{
player.m_36246_(Stats.f_12949_.m_12902_(this));
player.m_36399_(0.005F);
m_49881_(blockstate, level, blockpos, blockentity, player, stack);
if (blockentity instanceof PaviseBlockEntity pavise && pavise.m_58904_() != null)
level.m_7967_(new ItemEntity(pavise.m_58904_(), blockpos.m_123341_() + 0.5, blockpos.m_123342_() + 0.5, blockpos.m_123343_() + 0.5, pavise.getItem()));
}
@Override
public void m_6786_(LevelAccessor accessor, BlockPos blockpos, BlockState blockstate)
{
if (accessor.m_8055_(blockpos.m_7494_()).m_60734_() == ModBlocks.PAVISE_UPPER_COLLISION.get())
accessor.m_46961_(blockpos.m_7494_(), false);
super.m_6786_(accessor, blockpos, blockstate);
}
}