71 lines
2.8 KiB
Java
71 lines
2.8 KiB
Java
package net.mcreator.target.block;
|
|
|
|
import io.netty.buffer.Unpooled;
|
|
import net.mcreator.target.world.inventory.GunRecycleGuiMenu;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.network.FriendlyByteBuf;
|
|
import net.minecraft.network.chat.Component;
|
|
import net.minecraft.server.level.ServerPlayer;
|
|
import net.minecraft.world.InteractionHand;
|
|
import net.minecraft.world.InteractionResult;
|
|
import net.minecraft.world.MenuProvider;
|
|
import net.minecraft.world.entity.player.Inventory;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.item.TooltipFlag;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.block.Block;
|
|
import net.minecraft.world.level.block.SoundType;
|
|
import net.minecraft.world.level.block.state.BlockBehaviour;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.storage.loot.LootParams;
|
|
import net.minecraft.world.phys.BlockHitResult;
|
|
import net.minecraftforge.network.NetworkHooks;
|
|
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
|
|
public class GunRecycleBlock extends Block {
|
|
public GunRecycleBlock() {
|
|
super(BlockBehaviour.Properties.of().sound(SoundType.METAL).strength(1f, 10f));
|
|
}
|
|
|
|
@Override
|
|
public void appendHoverText(ItemStack itemstack, BlockGetter world, List<Component> list, TooltipFlag flag) {
|
|
super.appendHoverText(itemstack, world, list, flag);
|
|
}
|
|
|
|
@Override
|
|
public int getLightBlock(BlockState state, BlockGetter worldIn, BlockPos pos) {
|
|
return 15;
|
|
}
|
|
|
|
@Override
|
|
public List<ItemStack> getDrops(BlockState state, LootParams.Builder builder) {
|
|
List<ItemStack> dropsOriginal = super.getDrops(state, builder);
|
|
if (!dropsOriginal.isEmpty())
|
|
return dropsOriginal;
|
|
return Collections.singletonList(new ItemStack(this, 1));
|
|
}
|
|
|
|
@Override
|
|
public InteractionResult use(BlockState blockstate, Level world, BlockPos pos, Player entity, InteractionHand hand, BlockHitResult hit) {
|
|
super.use(blockstate, world, pos, entity, hand, hit);
|
|
if (entity instanceof ServerPlayer player) {
|
|
NetworkHooks.openScreen(player, new MenuProvider() {
|
|
@Override
|
|
public Component getDisplayName() {
|
|
return Component.literal("Gun Recycle");
|
|
}
|
|
|
|
@Override
|
|
public AbstractContainerMenu createMenu(int id, Inventory inventory, Player player) {
|
|
return new GunRecycleGuiMenu(id, inventory, new FriendlyByteBuf(Unpooled.buffer()).writeBlockPos(pos));
|
|
}
|
|
}, pos);
|
|
}
|
|
return InteractionResult.SUCCESS;
|
|
}
|
|
}
|