注册卓越物品接口
This commit is contained in:
parent
92e12f9eeb
commit
6c80f5af7f
6 changed files with 228 additions and 9 deletions
|
@ -0,0 +1,144 @@
|
|||
package com.atsuishio.superbwarfare.block;
|
||||
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.stats.Stats;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.BaseEntityBlock;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.RenderShape;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.HopperBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||
import net.minecraft.world.level.material.MapColor;
|
||||
import net.minecraft.world.level.pathfinder.PathComputationType;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class SuperbItemInterfaceBlock extends BaseEntityBlock {
|
||||
|
||||
public static final BooleanProperty ENABLED = BlockStateProperties.ENABLED;
|
||||
|
||||
public SuperbItemInterfaceBlock() {
|
||||
this(BlockBehaviour.Properties.of().mapColor(MapColor.STONE).requiresCorrectToolForDrops().strength(3.0F, 4.8F).sound(SoundType.METAL));
|
||||
}
|
||||
|
||||
public SuperbItemInterfaceBlock(BlockBehaviour.Properties properties) {
|
||||
super(properties);
|
||||
this.registerDefaultState(this.stateDefinition.any().setValue(ENABLED, true));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlacedBy(@NotNull Level pLevel, @NotNull BlockPos pPos, @NotNull BlockState pState, LivingEntity pPlacer, ItemStack pStack) {
|
||||
if (pStack.get(DataComponents.CUSTOM_NAME) != null) {
|
||||
BlockEntity blockentity = pLevel.getBlockEntity(pPos);
|
||||
// if (blockentity instanceof HopperBlockEntity) {
|
||||
// ((HopperBlockEntity) blockentity).setCustomName(pStack.getHoverName());
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlace(BlockState pState, @NotNull Level pLevel, @NotNull BlockPos pPos, BlockState pOldState, boolean pIsMoving) {
|
||||
if (!pOldState.is(pState.getBlock())) {
|
||||
this.checkPoweredState(pLevel, pPos, pState, 2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
protected @NotNull InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hitResult) {
|
||||
if (level.isClientSide) {
|
||||
return InteractionResult.SUCCESS;
|
||||
} else {
|
||||
BlockEntity blockentity = level.getBlockEntity(pos);
|
||||
if (blockentity instanceof HopperBlockEntity) {
|
||||
player.openMenu((HopperBlockEntity) blockentity);
|
||||
player.awardStat(Stats.INSPECT_HOPPER);
|
||||
}
|
||||
|
||||
return InteractionResult.CONSUME;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
public void neighborChanged(BlockState pState, Level pLevel, BlockPos pPos, Block pBlock, BlockPos pFromPos, boolean pIsMoving) {
|
||||
this.checkPoweredState(pLevel, pPos, pState, 4);
|
||||
}
|
||||
|
||||
private void checkPoweredState(Level pLevel, BlockPos pPos, BlockState pState, int pFlags) {
|
||||
boolean flag = !pLevel.hasNeighborSignal(pPos);
|
||||
if (flag != pState.getValue(ENABLED)) {
|
||||
pLevel.setBlock(pPos, pState.setValue(ENABLED, flag), pFlags);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(BlockState pState, @NotNull Level pLevel, @NotNull BlockPos pPos, BlockState pNewState, boolean pIsMoving) {
|
||||
if (!pState.is(pNewState.getBlock())) {
|
||||
BlockEntity blockentity = pLevel.getBlockEntity(pPos);
|
||||
// if (blockentity instanceof HopperBlockEntity) {
|
||||
// Containers.dropContents(pLevel, pPos, (HopperBlockEntity)blockentity);
|
||||
// pLevel.updateNeighbourForOutputSignal(pPos, this);
|
||||
// }
|
||||
|
||||
super.onRemove(pState, pLevel, pPos, pNewState, pIsMoving);
|
||||
}
|
||||
}
|
||||
|
||||
private static final MapCodec<SuperbItemInterfaceBlock> CODEC = BlockBehaviour.simpleCodec(SuperbItemInterfaceBlock::new);
|
||||
|
||||
@Override
|
||||
protected @NotNull MapCodec<? extends BaseEntityBlock> codec() {
|
||||
return CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull RenderShape getRenderShape(@NotNull BlockState pState) {
|
||||
return RenderShape.MODEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasAnalogOutputSignal(@NotNull BlockState pState) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAnalogOutputSignal(@NotNull BlockState pBlockState, Level pLevel, @NotNull BlockPos pPos) {
|
||||
return AbstractContainerMenu.getRedstoneSignalFromBlockEntity(pLevel.getBlockEntity(pPos));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> pBuilder) {
|
||||
pBuilder.add(ENABLED);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
protected boolean isPathfindable(BlockState state, PathComputationType pathComputationType) {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package com.atsuishio.superbwarfare.block.entity;
|
||||
|
||||
import com.atsuishio.superbwarfare.init.ModBlockEntities;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.network.chat.Component;
|
||||
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.level.block.entity.BaseContainerBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SuperbItemInterfaceBlockEntity extends BaseContainerBlockEntity {
|
||||
|
||||
public SuperbItemInterfaceBlockEntity(BlockPos pPos, BlockState pBlockState) {
|
||||
super(ModBlockEntities.SUPERB_ITEM_INTERFACE.get(), pPos, pBlockState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull Component getDefaultName() {
|
||||
return Component.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull NonNullList<ItemStack> getItems() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setItems(@NotNull NonNullList<ItemStack> items) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull AbstractContainerMenu createMenu(int pContainerId, @NotNull Inventory pInventory) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getContainerSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ItemStack removeItem(int pSlot, int pAmount) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ItemStack removeItemNoUpdate(int pSlot) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean stillValid(@NotNull Player pPlayer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearContent() {
|
||||
|
||||
}
|
||||
}
|
|
@ -227,7 +227,7 @@ public class ModItemModelProvider extends ItemModelProvider {
|
|||
.texture("layer0", Mod.loc("item/" + location + item.getId().getPath())).renderType(renderType);
|
||||
}
|
||||
|
||||
public void evenSimplerBlockItem(DeferredHolder<Block, Block> block) {
|
||||
public <T extends Block> void evenSimplerBlockItem(DeferredHolder<Block, T> block) {
|
||||
this.withExistingParent(Mod.MODID + ":" + BuiltInRegistries.BLOCK.getKey(block.get()).getPath(),
|
||||
modLoc("block/" + BuiltInRegistries.BLOCK.getKey(block.get()).getPath()));
|
||||
}
|
||||
|
|
|
@ -28,4 +28,6 @@ public class ModBlockEntities {
|
|||
|
||||
public static final DeferredHolder<BlockEntityType<?>, BlockEntityType<VehicleDeployerBlockEntity>> VEHICLE_DEPLOYER = REGISTRY.register("vehicle_deployer",
|
||||
() -> BlockEntityType.Builder.of(VehicleDeployerBlockEntity::new, ModBlocks.VEHICLE_DEPLOYER.get()).build(null));
|
||||
public static final DeferredHolder<BlockEntityType<?>, BlockEntityType<SuperbItemInterfaceBlockEntity>> SUPERB_ITEM_INTERFACE = REGISTRY.register("superb_item_interface",
|
||||
() -> BlockEntityType.Builder.of(SuperbItemInterfaceBlockEntity::new, ModBlocks.SUPERB_ITEM_INTERFACE.get()).build(null));
|
||||
}
|
||||
|
|
|
@ -43,11 +43,12 @@ public class ModBlocks {
|
|||
() -> new Block(BlockBehaviour.Properties.of().instrument(NoteBlockInstrument.BASEDRUM).sound(SoundType.METAL).strength(5f, 6f).requiresCorrectToolForDrops()));
|
||||
public static final DeferredHolder<Block, Block> CEMENTED_CARBIDE_BLOCK = REGISTRY.register("cemented_carbide_block",
|
||||
() -> new Block(BlockBehaviour.Properties.of().instrument(NoteBlockInstrument.BASEDRUM).sound(SoundType.METAL).strength(5f, 6f).requiresCorrectToolForDrops()));
|
||||
public static final DeferredHolder<Block, Block> CONTAINER = REGISTRY.register("container", () -> new ContainerBlock());
|
||||
public static final DeferredHolder<Block, Block> SMALL_CONTAINER = REGISTRY.register("small_container", () -> new SmallContainerBlock());
|
||||
public static final DeferredHolder<Block, Block> CHARGING_STATION = REGISTRY.register("charging_station", ChargingStationBlock::new);
|
||||
public static final DeferredHolder<Block, Block> CREATIVE_CHARGING_STATION = REGISTRY.register("creative_charging_station", () -> new CreativeChargingStationBlock());
|
||||
public static final DeferredHolder<Block, Block> FUMO_25 = REGISTRY.register("fumo_25", FuMO25Block::new);
|
||||
public static final DeferredHolder<Block, Block> VEHICLE_DEPLOYER = REGISTRY.register("vehicle_deployer", VehicleDeployerBlock::new);
|
||||
public static final DeferredHolder<Block, Block> AIRCRAFT_CATAPULT = REGISTRY.register("aircraft_catapult", AircraftCatapultBlock::new);
|
||||
public static final DeferredHolder<Block, ContainerBlock> CONTAINER = REGISTRY.register("container", () -> new ContainerBlock());
|
||||
public static final DeferredHolder<Block, ChargingStationBlock> CHARGING_STATION = REGISTRY.register("charging_station", ChargingStationBlock::new);
|
||||
public static final DeferredHolder<Block, CreativeChargingStationBlock> CREATIVE_CHARGING_STATION = REGISTRY.register("creative_charging_station", () -> new CreativeChargingStationBlock());
|
||||
public static final DeferredHolder<Block, FuMO25Block> FUMO_25 = REGISTRY.register("fumo_25", FuMO25Block::new);
|
||||
public static final DeferredHolder<Block, SmallContainerBlock> SMALL_CONTAINER = REGISTRY.register("small_container", () -> new SmallContainerBlock());
|
||||
public static final DeferredHolder<Block, VehicleDeployerBlock> VEHICLE_DEPLOYER = REGISTRY.register("vehicle_deployer", VehicleDeployerBlock::new);
|
||||
public static final DeferredHolder<Block, AircraftCatapultBlock> AIRCRAFT_CATAPULT = REGISTRY.register("aircraft_catapult", AircraftCatapultBlock::new);
|
||||
public static final DeferredHolder<Block, SuperbItemInterfaceBlock> SUPERB_ITEM_INTERFACE = REGISTRY.register("superb_item_interface", () -> new SuperbItemInterfaceBlock());
|
||||
}
|
||||
|
|
|
@ -285,6 +285,7 @@ public class ModItems {
|
|||
public static final DeferredHolder<Item, SmallContainerBlockItem> SMALL_CONTAINER = BLOCKS.register("small_container", SmallContainerBlockItem::new);
|
||||
public static final DeferredHolder<Item, VehicleDeployerBlockItem> VEHICLE_DEPLOYER = BLOCKS.register("vehicle_deployer", VehicleDeployerBlockItem::new);
|
||||
public static final DeferredHolder<Item, BlockItem> AIRCRAFT_CATAPULT = block(ModBlocks.AIRCRAFT_CATAPULT);
|
||||
public static final DeferredHolder<Item, BlockItem> SUPERB_ITEM_INTERFACE = block(ModBlocks.SUPERB_ITEM_INTERFACE);
|
||||
|
||||
public record Materials(
|
||||
String name,
|
||||
|
@ -324,7 +325,7 @@ public class ModItems {
|
|||
*/
|
||||
public static final DeferredHolder<Item, Item> AP_BULLET = PERKS.register("ap_bullet", () -> new PerkItem<>(ModPerks.AP_BULLET));
|
||||
|
||||
private static DeferredHolder<Item, BlockItem> block(DeferredHolder<Block, Block> block) {
|
||||
private static <T extends Block> DeferredHolder<Item, BlockItem> block(DeferredHolder<Block, T> block) {
|
||||
return BLOCKS.register(block.getId().getPath(), () -> new BlockItem(block.get(), new Item.Properties()));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue