c907454be9
* Make Encasing utilize Interfaces * Add Javadoc to IEncasable and IEncased interfaces * Fix Weird block.block issues (No clue where those came from) * Final Touch ups for now and made requirement for casing normal Block instead of CasingBlock * Make requested changes * Add more parameters for tryEncasing, for use in handleEncasing Move handleEncasing to Encased Interface for more flexability * Simplify and organize - Rename: - Encasable -> EncasableBlock - Encased -> EncasedBlock - EncasableRegistry -> EncasingRegistry - Remove EncasedBlock#setCasing - Remove encasedBlock argument from EncasedBlock#handleEncasing - Add Registrate builder transformer to EncasingRegistry for easy use --------- Co-authored-by: PepperCode1 <44146161+PepperCode1@users.noreply.github.com>
40 lines
1.4 KiB
Java
40 lines
1.4 KiB
Java
package com.simibubi.create.content.contraptions.relays.elementary;
|
|
|
|
import java.util.List;
|
|
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.InteractionHand;
|
|
import net.minecraft.world.InteractionResult;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.block.Block;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.phys.BlockHitResult;
|
|
|
|
/**
|
|
* Implement this interface to indicate that this block is encasable.
|
|
*/
|
|
public interface EncasableBlock {
|
|
/**
|
|
* This method should be called in the {@link Block#use(BlockState, Level, BlockPos, Player, InteractionHand, BlockHitResult)} method.
|
|
*/
|
|
default InteractionResult tryEncase(BlockState state, Level level, BlockPos pos, ItemStack heldItem, Player player, InteractionHand hand,
|
|
BlockHitResult ray) {
|
|
List<Block> encasedVariants = EncasingRegistry.getVariants(state.getBlock());
|
|
for (Block block : encasedVariants) {
|
|
if (block instanceof EncasedBlock encased) {
|
|
if (encased.getCasing().asItem() != heldItem.getItem())
|
|
continue;
|
|
|
|
if (level.isClientSide)
|
|
return InteractionResult.SUCCESS;
|
|
|
|
encased.handleEncasing(state, level, pos, heldItem, player, hand, ray);
|
|
return InteractionResult.SUCCESS;
|
|
}
|
|
}
|
|
return InteractionResult.PASS;
|
|
}
|
|
}
|