filename:
common/src/main/java/rearth/oritech/block/blocks/addons/InventoryProxyAddonBlock.java
branch:
1.21
back to repo
package rearth.oritech.block.blocks.addons;
import dev.architectury.registry.menu.ExtendedMenuProvider;
import dev.architectury.registry.menu.MenuRegistry;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.jetbrains.annotations.NotNull;
import rearth.oritech.block.entity.addons.InventoryProxyAddonBlockEntity;
public class InventoryProxyAddonBlock extends MachineAddonBlock {
public InventoryProxyAddonBlock(Settings settings, AddonSettings addonSettings) {
super(settings, addonSettings);
}
@Override
public @NotNull Class<? extends BlockEntity> getBlockEntityType() {
return InventoryProxyAddonBlockEntity.class;
}
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
if (!world.isClient && state.get(ADDON_USED)) {
var handler = (ExtendedMenuProvider) world.getBlockEntity(pos);
MenuRegistry.openExtendedMenu((ServerPlayerEntity) player, handler);
}
return ActionResult.SUCCESS;
}
}