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.19.2-epic-knights-common Show documentation
Show all versions of 1.19.2-epic-knights-common 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_1158;
import net.minecraft.class_1160;
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_3532;
import net.minecraft.class_3614;
import net.minecraft.class_3726;
import net.minecraft.class_4970;
import net.minecraft.world.level.block.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
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);
public static final class_1160 CENTER = new class_1160(0.5f, 0.5f, 0.5f);
public static final class_1160 BOXMIN = new class_1160(0.0f, 0.0f, 0.0f);
public static final class_1160 BOXMAX = new class_1160(1.0f, 1.0f, 1.0f);
public PaviseBlock()
{
super(class_1767.field_7952, class_4970.class_2251.method_9637(class_3614.field_15932).method_9624().method_9626(class_2498.field_11547));
}
@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 void method_33614(class_1937 level, class_1657 player, class_2338 blockPos, class_2680 blockstate)
{
}
@Override
public class_2680 method_9605(class_1750 blockPlaceContext)
{
return this.method_9564().method_11657(field_9924, class_3532.method_15357((double)((blockPlaceContext.method_8044()) * 16.0F / 360.0F) + 0.5) & 15);
}
@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 = -blockstate.method_11654(class_2215.field_9924) * 360.0F / 16.0F;
aabb = rotateAABB(aabb, class_1160.field_20705.method_23214(yrot));
return class_259.method_1078(aabb);
}
public static class_238 rotateAABB(class_238 axisAlignedBB, class_1158 quaternion)
{
// Extract the minimum and maximum coordinates of the AABB into vectors
final class_1160 mincoords = new class_1160((float) axisAlignedBB.field_1323, (float) axisAlignedBB.field_1322, (float) axisAlignedBB.field_1321);
final class_1160 maxcoords = new class_1160((float) axisAlignedBB.field_1320, (float) axisAlignedBB.field_1325, (float) axisAlignedBB.field_1324);
mincoords.method_4944(CENTER);
maxcoords.method_4944(CENTER);
mincoords.method_19262(quaternion);
maxcoords.method_19262(quaternion);
mincoords.method_23846(CENTER);
maxcoords.method_23846(CENTER);
float xmin = Math.max(mincoords.method_4943(), BOXMIN.method_4943());
float ymin = Math.max(mincoords.method_4945(), BOXMIN.method_4945());
float zmin = Math.max(mincoords.method_4947(), BOXMIN.method_4947());
float xmax = Math.min(maxcoords.method_4943(), BOXMAX.method_4943());
float ymax = Math.min(maxcoords.method_4945(), BOXMAX.method_4945());
float zmax = Math.min(maxcoords.method_4947(), BOXMAX.method_4947());
return new class_238(xmin, ymin, zmin, xmax, ymax, zmax);
}
@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);
}
}