com.magistuarmory.block.PaviseBlock 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-fabric Show documentation
Show all versions of 1.20.2-epic-knights-fabric Show documentation
mod that adds medieval stuff to the game
The newest version!
package com.magistuarmory.block;
import com.magistuarmory.item.MedievalShieldItem;
import com.magistuarmory.item.ModItems;
import dev.architectury.registry.registries.RegistrySupplier;
import net.minecraft.class_1542;
import net.minecraft.class_1657;
import net.minecraft.class_1750;
import net.minecraft.class_1767;
import net.minecraft.class_1792;
import net.minecraft.class_1799;
import net.minecraft.class_1802;
import net.minecraft.class_1922;
import net.minecraft.class_1936;
import net.minecraft.class_1937;
import net.minecraft.class_2215;
import net.minecraft.class_2338;
import net.minecraft.class_238;
import net.minecraft.class_2498;
import net.minecraft.class_2586;
import net.minecraft.class_259;
import net.minecraft.class_265;
import net.minecraft.class_2680;
import net.minecraft.class_3468;
import net.minecraft.class_3726;
import net.minecraft.class_7718;
import net.minecraft.class_7833;
import net.minecraft.world.level.block.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.joml.Quaternionf;
import org.joml.Vector3d;
public class PaviseBlock extends class_2215
{
// static final VoxelShape SHAPE = Block.box(4.0, 0.0, 4.0, 12.0, 16.0, 12.0);
static final class_238 COLLISION_AABB = new class_238(0.0 / 16.0, 0.0, 7.5 / 16.0, 1.0, 1.0, 8.5 / 16.0);
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(class_1767.field_7952, class_2251.method_9637().method_9624().method_45477().method_9626(class_2498.field_11547).method_50013());
}
@Override
public class_2586 method_10123(class_2338 blockpos, class_2680 blockstate)
{
return new PaviseBlockEntity(blockpos, blockstate);
}
@Override
public @NotNull class_1792 method_8389()
{
RegistrySupplier item = ModItems.PAVISES.wood;
return item != null ? item.get() : class_1802.field_8162;
}
@Override
public class_2680 method_9605(class_1750 blockPlaceContext)
{
return this.method_9564().method_11657(field_9924, class_7718.method_45479(blockPlaceContext.method_8044()));
}
@Override
public @NotNull class_1799 method_9574(class_1922 blockgetter, class_2338 blockpos, class_2680 blockstate)
{
if (blockgetter.method_8321(blockpos) instanceof PaviseBlockEntity pavise)
return pavise.getItem();
return class_1799.field_8037;
}
@Override
public class_265 method_9530(class_2680 blockstate, class_1922 blockgetter, class_2338 blockpos, class_3726 context)
{
class_238 aabb = COLLISION_AABB;
float yrot = -class_7718.method_45482(blockstate.method_11654(class_2215.field_9924));
aabb = rotateAABB(aabb, class_7833.field_40716.rotationDegrees(yrot));
return class_259.method_1078(aabb);
}
public static class_238 rotateAABB(class_238 axisAlignedBB, Quaternionf quaternion)
{
// Extract the minimum and maximum coordinates of the AABB into vectors
final Vector3d mincoords = new Vector3d(axisAlignedBB.field_1323, axisAlignedBB.field_1322, axisAlignedBB.field_1321);
final Vector3d maxcoords = new Vector3d(axisAlignedBB.field_1320, axisAlignedBB.field_1325, axisAlignedBB.field_1324);
mincoords.sub(CENTER);
maxcoords.sub(CENTER);
// Rotate the vectors in-place
quaternion.transform(mincoords);
quaternion.transform(maxcoords);
mincoords.add(CENTER).max(BOXMIN);
maxcoords.add(CENTER).min(BOXMAX);
// Return an AABB with the new coordinates
return new class_238(mincoords.x(), mincoords.y(), mincoords.z(), maxcoords.x(), maxcoords.y(), maxcoords.z());
}
@Override
public void method_9556(class_1937 level, class_1657 player, class_2338 blockpos, class_2680 blockstate, @Nullable class_2586 blockentity, class_1799 stack)
{
player.method_7259(class_3468.field_15427.method_14956(this));
player.method_7322(0.005F);
method_9511(blockstate, level, blockpos, blockentity, player, stack);
if (blockentity instanceof PaviseBlockEntity pavise && pavise.method_10997() != null)
level.method_8649(new class_1542(pavise.method_10997(), blockpos.method_10263() + 0.5, blockpos.method_10264() + 0.5, blockpos.method_10260() + 0.5, pavise.getItem()));
}
@Override
public void method_9585(class_1936 accessor, class_2338 blockpos, class_2680 blockstate)
{
if (accessor.method_8320(blockpos.method_10084()).method_26204() == ModBlocks.PAVISE_UPPER_COLLISION.get())
accessor.method_22352(blockpos.method_10084(), false);
super.method_9585(accessor, blockpos, blockstate);
}
}