com.magistuarmory.block.PaviseUpperCollisionBlock Maven / Gradle / Ivy
package com.magistuarmory.block;
import com.mojang.math.Vector3f;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
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.BannerBlock;
import net.minecraft.world.level.block.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;
public class PaviseUpperCollisionBlock extends Block
{
static final AABB COLLISION_AABB = new AABB(0.0 / 16.0, 0.0, 7.5 / 16.0, 1.0, 8.0 / 16.0, 8.5 / 16.0);
public PaviseUpperCollisionBlock()
{
super(BlockBehaviour.Properties.m_60939_(Material.f_76320_).m_60988_());
}
@Override
public BlockState m_5573_(BlockPlaceContext context)
{
return this.m_49966_();
}
@Override
public @NotNull ItemStack m_7397_(BlockGetter blockgetter, BlockPos blockpos, BlockState blockstate)
{
if (blockgetter.m_7702_(blockpos.m_7495_()) instanceof PaviseBlockEntity pavise)
return pavise.getItem();
return ItemStack.f_41583_;
}
@Override
public void m_142387_(Level level, Player player, BlockPos blockPos, BlockState blockstate)
{
}
@Override
public VoxelShape m_5940_(BlockState blockstate, BlockGetter blockgetter, BlockPos blockpos, CollisionContext context)
{
AABB aabb = COLLISION_AABB;
if (blockgetter.m_7702_(blockpos.m_7495_()) instanceof PaviseBlockEntity pavise)
{
BlockState blockstate2 = pavise.m_58900_();
float yrot = -blockstate2.m_61143_(BannerBlock.f_49007_) * 360.0F / 16.0F;
aabb = PaviseBlock.rotateAABB(aabb, Vector3f.f_122225_.m_122240_(yrot));
}
return Shapes.m_83064_(aabb);
}
@Override
public void m_6786_(LevelAccessor accessor, BlockPos blockpos, BlockState blockstate)
{
BlockEntity blockentity = accessor.m_7702_(blockpos.m_7495_());
if (blockentity instanceof PaviseBlockEntity pavise && pavise.m_58904_() != null)
accessor.m_7967_(new ItemEntity(pavise.m_58904_(), blockpos.m_123341_() + 0.5, blockpos.m_123342_() - 0.5, blockpos.m_123343_() + 0.5, pavise.getItem()));
if (accessor.m_8055_(blockpos.m_7495_()).m_60734_() == ModBlocks.PAVISE.get())
accessor.m_46961_(blockpos.m_7495_(), false);
super.m_6786_(accessor, blockpos, blockstate);
}
}