//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package com.magistuarmory.block;
import com.magistuarmory.item.MedievalShieldItem;
import com.magistuarmory.item.ModItems;
import com.mojang.math.Axis;
import dev.architectury.registry.registries.RegistrySupplier;
import net.minecraft.core.BlockPos;
import net.minecraft.stats.Stats;
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.BannerBlock;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.BlockBehaviour.Properties;
import net.minecraft.world.level.block.state.properties.RotationSegment;
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;
import org.joml.Quaternionf;
import org.joml.Vector3d;
public class PaviseBlock extends BannerBlock {
static final AABB COLLISION_AABB = new AABB(0.0, 0.0, 0.46875, 1.0, 1.0, 0.53125);
static final Vector3d CENTER = new Vector3d(0.5, 0.5, 0.5);
static final Vector3d BOXMIN = new Vector3d(0.0, 0.0, 0.0);
static final Vector3d BOXMAX = new Vector3d(1.0, 1.0, 1.0);
public PaviseBlock() {
super(DyeColor.WHITE, Properties.of().dynamicShape().noParticlesOnBreak().sound(SoundType.WOOD).ignitedByLava());
}
public BlockEntity newBlockEntity(BlockPos blockpos, BlockState blockstate) {
return new PaviseBlockEntity(blockpos, blockstate);
}
public @NotNull Item asItem() {
RegistrySupplier<MedievalShieldItem> item = ModItems.PAVISES.wood;
return item != null ? (Item)item.get() : Items.AIR;
}
public BlockState getStateForPlacement(BlockPlaceContext blockPlaceContext) {
return (BlockState)this.defaultBlockState().setValue(ROTATION, RotationSegment.convertToSegment(blockPlaceContext.getRotation()));
}
public @NotNull ItemStack getCloneItemStack(BlockGetter blockgetter, BlockPos blockpos, BlockState blockstate) {
BlockEntity var5 = blockgetter.getBlockEntity(blockpos);
if (var5 instanceof PaviseBlockEntity pavise) {
return pavise.getItem();
} else {
return ItemStack.EMPTY;
}
}
public VoxelShape getShape(BlockState blockstate, BlockGetter blockgetter, BlockPos blockpos, CollisionContext context) {
AABB aabb = COLLISION_AABB;
float yrot = -RotationSegment.convertToDegrees((Integer)blockstate.getValue(BannerBlock.ROTATION));
aabb = rotateAABB(aabb, Axis.YP.rotationDegrees(yrot));
return Shapes.create(aabb);
}
public static AABB rotateAABB(AABB axisAlignedBB, Quaternionf quaternion) {
Vector3d mincoords = new Vector3d(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.minZ);
Vector3d maxcoords = new Vector3d(axisAlignedBB.maxX, axisAlignedBB.maxY, axisAlignedBB.maxZ);
mincoords.sub(CENTER);
maxcoords.sub(CENTER);
quaternion.transform(mincoords);
quaternion.transform(maxcoords);
mincoords.add(CENTER).max(BOXMIN);
maxcoords.add(CENTER).min(BOXMAX);
return new AABB(mincoords.x(), mincoords.y(), mincoords.z(), maxcoords.x(), maxcoords.y(), maxcoords.z());
}
public void playerDestroy(Level level, Player player, BlockPos blockpos, BlockState blockstate, @Nullable BlockEntity blockentity, ItemStack stack) {
player.awardStat(Stats.BLOCK_MINED.get(this));
player.causeFoodExhaustion(0.005F);
dropResources(blockstate, level, blockpos, blockentity, player, stack);
if (blockentity instanceof PaviseBlockEntity pavise) {
if (pavise.getLevel() != null) {
level.addFreshEntity(new ItemEntity(pavise.getLevel(), (double)blockpos.getX() + 0.5, (double)blockpos.getY() + 0.5, (double)blockpos.getZ() + 0.5, pavise.getItem()));
}
}
}
public void destroy(LevelAccessor accessor, BlockPos blockpos, BlockState blockstate) {
if (accessor.getBlockState(blockpos.above()).getBlock() == ModBlocks.PAVISE_UPPER_COLLISION.get()) {
accessor.destroyBlock(blockpos.above(), false);
}
super.destroy(accessor, blockpos, blockstate);
}
}