下面列出了net.minecraft.util.shape.VoxelShape#net.minecraft.util.math.Direction 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected ItemStack dispenseSilently(BlockPointer source, ItemStack stack) {
if(!CarpetExtraSettings.dispensersToggleThings) {
return super.dispenseSilently(source, stack);
}
World world = source.getWorld();
Direction direction = (Direction) source.getBlockState().get(DispenserBlock.FACING);
BlockPos pos = source.getBlockPos().offset(direction);
BlockState state = world.getBlockState(pos);
if(toggleable.contains(state.getBlock())) {
ActionResult result = state.onUse(
world,
null,
Hand.MAIN_HAND,
new BlockHitResult(
new Vec3d(new Vec3i(pos.getX(), pos.getY(), pos.getZ())),
direction,
pos,
false
)
);
if(result.isAccepted()) return stack; // success or consume
}
return super.dispenseSilently(source, stack);
}
public BakedModel bakeModel(JsonUnbakedModel model, Function<SpriteIdentifier, Sprite> textureGetter, ModelBakeSettings settings, Identifier id, boolean hasDepth) {
Sprite sprite = textureGetter.apply(model.resolveSprite("particle"));
if (model.getRootModel() == ModelLoader.BLOCK_ENTITY_MARKER) {
return new BuiltinBakedModel(model.getTransformations(), ModelOverrideList.EMPTY, sprite, model.getGuiLight().isSide());
} else {
BasicBakedModel.Builder builder = (new BasicBakedModel.Builder(model, ModelOverrideList.EMPTY, hasDepth)).setParticle(sprite);
for (ModelElement modelElement : model.getElements()) {
for (Direction direction : modelElement.faces.keySet()) {
ModelElementFace modelElementFace = modelElement.faces.get(direction);
Sprite sprite2 = textureGetter.apply(model.resolveSprite(modelElementFace.textureId));
if (modelElementFace.cullFace == null) {
builder.addQuad(createQuad(modelElement, modelElementFace, sprite2, direction, settings, id));
} else {
builder.addQuad(Direction.transform(settings.getRotation().getMatrix(), modelElementFace.cullFace), createQuad(modelElement, modelElementFace, sprite2, direction, settings, id));
}
}
}
return builder.build();
}
}
private BooleanProperty getPropForDirection(Direction dir) {
switch (dir) {
case SOUTH:
return ATTACHED_SOUTH;
case EAST:
return ATTACHED_EAST;
case WEST:
return ATTACHED_WEST;
case NORTH:
return ATTACHED_NORTH;
case UP:
return ATTACHED_UP;
case DOWN:
return ATTACHED_DOWN;
default:
throw new IllegalArgumentException("cannot be null");
}
}
/**
* Handles blocks besides the slimeblock that are sticky. Currently only supports blocks that are sticky on one side.
* Currently the only additional sticky block is the double chest, which sticks to its other chest half.
* @param blockPos_1 location of a block that moves and needs to stick other blocks to it
* @author 2No2Name
*/
private boolean stickToStickySide(BlockPos blockPos_1){
if(!CarpetSettings.movableBlockEntities)
return true;
BlockState blockState_1 = this.world.getBlockState(blockPos_1);
Block block = blockState_1.getBlock();
Direction stickyDirection = null;
if(block == Blocks.CHEST || block == Blocks.TRAPPED_CHEST) {
stickyDirection = getDirectionToOtherChestHalf(blockState_1);
}
//example how you could make sticky pistons have a sticky side:
//else if(block == Blocks.STICKY_PISTON){
// stickyDirection = blockState_1.get(FacingBlock.FACING);
//}
return stickyDirection == null || this.tryMove(blockPos_1.offset(stickyDirection), stickyDirection);
}
protected int getShapeIndex(BlockState state) {
return this.SHAPE_INDEX_CACHE.computeIntIfAbsent(state, (blockState) -> {
int i = 0;
if (blockState.get(NORTH)) {
i |= getDirectionMask(Direction.NORTH);
}
if (blockState.get(EAST)) {
i |= getDirectionMask(Direction.EAST);
}
if (blockState.get(SOUTH)) {
i |= getDirectionMask(Direction.SOUTH);
}
if (blockState.get(WEST)) {
i |= getDirectionMask(Direction.WEST);
}
return i;
});
}
static void handleRotation(MatrixStack stack, @Nullable Direction direction) {
if (direction == null) {
stack.translate(0.5, 0, 0.5);
return;
}
switch (direction) {
case NORTH:
stack.translate(0.5, 0.25, 0.74);
break;
case SOUTH:
stack.translate(0.5, 0.25, 0.26);
break;
case WEST:
stack.translate(0.74, 0.25, 0.5);
break;
case EAST:
default:
stack.translate(0.26, 0.25, 0.5);
break;
}
}
@Inject(method = "canPlace", at = @At("HEAD"), cancellable = true)
private void onCanPlace(ItemPlacementContext context, BlockState state, CallbackInfoReturnable<Boolean> ci) {
if (ConnectionInfo.protocolVersion <= Protocols.V1_12_2) {
Block block = state.getBlock();
if (block == Blocks.CHEST || block == Blocks.TRAPPED_CHEST) {
World world = context.getWorld();
BlockPos pos = context.getBlockPos();
boolean foundAdjChest = false;
for (Direction dir : Direction.Type.HORIZONTAL) {
BlockState otherState = world.getBlockState(pos.offset(dir));
if (otherState.getBlock() == block) {
if (foundAdjChest) {
ci.setReturnValue(false);
return;
}
foundAdjChest = true;
if (otherState.get(ChestBlock.CHEST_TYPE) != ChestType.SINGLE) {
ci.setReturnValue(false);
return;
}
}
}
}
}
}
@Override
public Direction[] getPlacementDirections() {
switch(this.facing) {
case DOWN:
default:
return new Direction[]{Direction.DOWN, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST, Direction.UP};
case UP:
return new Direction[]{Direction.DOWN, Direction.UP, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST};
case NORTH:
return new Direction[]{Direction.DOWN, Direction.NORTH, Direction.EAST, Direction.WEST, Direction.UP, Direction.SOUTH};
case SOUTH:
return new Direction[]{Direction.DOWN, Direction.SOUTH, Direction.EAST, Direction.WEST, Direction.UP, Direction.NORTH};
case WEST:
return new Direction[]{Direction.DOWN, Direction.WEST, Direction.SOUTH, Direction.UP, Direction.NORTH, Direction.EAST};
case EAST:
return new Direction[]{Direction.DOWN, Direction.EAST, Direction.SOUTH, Direction.UP, Direction.NORTH, Direction.WEST};
}
}
@Override
protected ItemStack dispenseSilently(BlockPointer source, ItemStack stack)
{
if (!CarpetExtraSettings.dispensersPlayRecords)
return super.dispenseSilently(source, stack);
Direction direction = source.getBlockState().get(DispenserBlock.FACING);
BlockPos pos = source.getBlockPos().offset(direction);
World world = source.getWorld();
BlockState state = world.getBlockState(pos);
if (state.getBlock() == Blocks.JUKEBOX)
{
JukeboxBlockEntity jukebox = (JukeboxBlockEntity) world.getBlockEntity(pos);
if (jukebox != null)
{
ItemStack itemStack = jukebox.getRecord();
((JukeboxBlock) state.getBlock()).setRecord(world, pos, state, stack);
world.playLevelEvent(null, 1010, pos, Item.getRawId(stack.getItem()));
return itemStack;
}
}
return super.dispenseSilently(source, stack);
}
@Override
@Nonnull
public SpriteIdentifier getDefaultSpriteId(@Nonnull BasicSolarPanelBlockEntity entity, @Nonnull Direction direction) {
switch (direction) {
case NORTH:
return new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/basic_solar_panel"));
case SOUTH:
new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/machine_side"));
case EAST:
new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/machine_side"));
case WEST:
new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/machine_side"));
case UP:
new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/solar_panel"));
case DOWN:
new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/machine"));
}
return new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/machine"));
}
@Nonnull
@Override
public SpriteIdentifier getDefaultSpriteId(@Nonnull RefineryBlockEntity entity, @Nonnull Direction direction) {
switch (direction) {
case NORTH:
return new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/refinery_front"));
case SOUTH:
return new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/refinery_side"));
case EAST:
case WEST:
return new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/machine_side"));
case UP:
case DOWN:
return new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/machine"));
}
return new SpriteIdentifier(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, new Identifier(Constants.MOD_ID, "block/machine"));
}
/**
* Re-colors this block in the world.
*
* @param state The current state
* @param world The world
* @param pos Block position
* @param facing ??? (this method has no usages)
* @param color Color to recolor to.
* @return if the block was affected
*/
@SuppressWarnings("unchecked")
default boolean recolorBlock(BlockState state, IWorld world, BlockPos pos, Direction facing, DyeColor color) {
for (Property<?> prop : state.getProperties()) {
if (prop.getName().equals("color") && prop.getType() == DyeColor.class) {
DyeColor current = (DyeColor) state.get(prop);
if (current != color && prop.getValues().contains(color)) {
world.setBlockState(pos, state.with(((Property<DyeColor>) prop), color), 3);
return true;
}
}
}
return false;
}
protected boolean generateBranch(Set<BlockPos> set, ModifiableTestableWorld world, Random random, BlockPos pos, BlockBox mibb, int maxBranchouts, Direction lastDir) {
int baseHeight = random.nextInt(4) + 2;
for (int int_4 = 0; int_4 < baseHeight; ++int_4) {
BlockPos blockPos = pos.up(int_4 + 1);
if (!isSurroundedByAir(world, blockPos, null)) {
return true;
}
addLog(set, world, blockPos, Direction.Axis.Y, mibb);
}
int int_5 = random.nextInt(4) + 1;
int int_1 = 8;
if (maxBranchouts > 0)
for (int int_6 = 0; int_6 < int_5; ++int_6) {
Direction direction_1 = Direction.Type.HORIZONTAL.random(random);
if (direction_1 == lastDir) continue;
BlockPos blockPos_4 = pos.up(baseHeight).offset(direction_1);
if (Math.abs(blockPos_4.getX() - pos.getX()) < int_1 && Math.abs(blockPos_4.getZ() - pos.getZ()) < int_1 && isAir(world, blockPos_4) && isAir(world, blockPos_4.down()) && isSurroundedByAir(world, blockPos_4, direction_1.getOpposite())) {
addLog(set, world, blockPos_4, direction_1.getAxis(), mibb);
generateBranch(set, world, random, blockPos_4, mibb, maxBranchouts - 1, direction_1.getOpposite());
}
}
return true;
}
private ItemStack defaultBehaviour(BlockPointer source, ItemStack stack)
{
if (this.minecartType == AbstractMinecartEntity.Type.TNT)
{
World world = source.getWorld();
BlockPos pos = source.getBlockPos().offset((Direction) source.getBlockState().get(DispenserBlock.FACING));
TntEntity tntEntity = new TntEntity(world, (double)pos.getX() + 0.5D, (double)pos.getY(), (double)pos.getZ() + 0.5D, (LivingEntity)null);
world.spawnEntity(tntEntity);
world.playSound((PlayerEntity)null, tntEntity.getX(), tntEntity.getY(), tntEntity.getZ(), SoundEvents.ENTITY_TNT_PRIMED, SoundCategory.BLOCKS, 1.0F, 1.0F);
stack.decrement(1);
return stack;
}
else
{
return super.dispenseSilently(source, stack);
}
}
protected int[] getAvailableSlots(Direction side) {
int[] ints = new int[getInventorySize()];
for (int i = 0; i < getInventorySize(); i++) {
ints[i] = i;
}
return ints;
}
@Override
void inactiveTick(ServerPlayerEntity player, Action action)
{
EntityPlayerActionPack ap = ((ServerPlayerEntityInterface) player).getActionPack();
if (ap.currentBlock == null) return;
player.world.setBlockBreakingInfo(-1, ap.currentBlock, -1);
player.interactionManager.processBlockBreakingAction(ap.currentBlock, PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, Direction.DOWN, player.server.getWorldHeight());
ap.currentBlock = null;
}
@Override
public Set<ComponentType<?>> getComponentTypes(BlockView blockView, BlockPos pos, @Nullable Direction side) {
Set<ComponentType<?>> set = new HashSet<>();
BlockState state = blockView.getBlockState(pos);
SideOption option = ((ConfigurableElectricMachineBlock) state.getBlock()).getOption(state, ConfigurableElectricMachineBlock.BlockFace.toFace(state.get(ConfigurableElectricMachineBlock.FACING), side));
if (option == SideOption.POWER_OUTPUT || option == SideOption.POWER_INPUT) {
set.add(UniversalComponents.CAPACITOR_COMPONENT);
}
return set;
}
@Nonnull
@Override
public WireConnectionType canWireConnect(WorldAccess world, Direction opposite, BlockPos connectionSourcePos, BlockPos connectionTargetPos) {
BlockState state = world.getBlockState(connectionTargetPos);
SideOption option = getOption(state, BlockFace.toFace(state.get(FACING), opposite));
if (option == SideOption.POWER_INPUT) {
return WireConnectionType.ENERGY_INPUT;
} else if (option == SideOption.POWER_OUTPUT) {
return WireConnectionType.ENERGY_OUTPUT;
}
return WireConnectionType.NONE;
}
private boolean rightClickBlockLegit(BlockPos pos)
{
Vec3d eyesPos = RotationUtils.getEyesPos();
Vec3d posVec = Vec3d.ofCenter(pos);
double distanceSqPosVec = eyesPos.squaredDistanceTo(posVec);
for(Direction side : Direction.values())
{
Vec3d hitVec = posVec.add(Vec3d.of(side.getVector()).multiply(0.5));
double distanceSqHitVec = eyesPos.squaredDistanceTo(hitVec);
// check if hitVec is within range (4.25 blocks)
if(distanceSqHitVec > 18.0625)
continue;
// check if side is facing towards player
if(distanceSqHitVec >= distanceSqPosVec)
continue;
// check line of sight
if(MC.world
.rayTrace(new RayTraceContext(eyesPos, hitVec,
RayTraceContext.ShapeType.COLLIDER,
RayTraceContext.FluidHandling.NONE, MC.player))
.getType() != HitResult.Type.MISS)
continue;
// face block
WURST.getRotationFaker().faceVectorPacket(hitVec);
// place block
IMC.getInteractionManager().rightClickBlock(pos, side, hitVec);
MC.player.swingHand(Hand.MAIN_HAND);
IMC.setItemUseCooldown(4);
return true;
}
return false;
}
@Inject(method = "shouldDrawSide", at = @At("HEAD"), cancellable = true)
private static void shouldDrawSide(BlockState blockState_1, BlockView blockView_1, BlockPos blockPos_1, Direction direction_1, CallbackInfoReturnable<Boolean> callback) {
try {
Xray xray = (Xray) ModuleManager.getModule(Xray.class);
if (xray.isToggled()) {
callback.setReturnValue(xray.isVisible(blockState_1.getBlock()));
callback.cancel();
}
} catch (Exception ignored) {}
}
@Override
protected void init(Map<String, Value> options)
{
super.init(options);
center = vecFromValue(options.get("center"));
radius = NumericValue.asNumber(options.get("radius")).getFloat();
level = NumericValue.asNumber(options.getOrDefault("level", optional.get("level"))).getInt();
subdivisions = level;
if (subdivisions <= 0)
{
subdivisions = Math.max(10, (int)(10*Math.sqrt(radius)));
}
height = NumericValue.asNumber(options.getOrDefault("height", optional.get("height"))).getFloat();
axis = Direction.Axis.fromName(options.getOrDefault("axis", optional.get("axis")).getString());
}
/**
* Currently only called by fire when it is on top of this block.
* Returning true will prevent the fire from naturally dying during updating.
* Also prevents firing from dying from rain.
*
* @param state The current state
* @param world The current world
* @param pos Block position in world
* @param side The face that the fire is coming from
* @return True if this block sustains fire, meaning it will never go out.
*/
default boolean isFireSource(BlockState state, BlockView world, BlockPos pos, Direction side) {
if (side != Direction.UP) {
return false;
}
if (getBlock() == Blocks.NETHERRACK || getBlock() == Blocks.MAGMA_BLOCK) {
return true;
}
return world instanceof CollisionView && ((CollisionView) world).getDimension() instanceof TheEndDimension && getBlock() == Blocks.BEDROCK;
}
@Override
public BlockState getPlacementState(ItemPlacementContext context) {
BlockState state = this.getDefaultState();
for (Direction direction : Direction.values()) {
Block block = context.getWorld().getBlockState(context.getBlockPos().offset(direction)).getBlock();
if (block instanceof FluidPipeBlock)
state = state.with(propFromDirection(direction), true);
}
return state;
}
@Inject(method = "isMovable", at = @At(value = "RETURN", ordinal = 3, shift = At.Shift.BEFORE))
private static void movableCMD(BlockState blockState_1, World world_1, BlockPos blockPos_1,
Direction direction_1, boolean boolean_1, Direction direction_2, CallbackInfoReturnable<Boolean> cir)
{
Block block_1 = blockState_1.getBlock();
//Make CommandBlocks movable, either use instanceof CommandBlock or the 3 cmd block objects,
if (CarpetSettings.movableBlockEntities && block_1 instanceof CommandBlock)
{
cir.setReturnValue(true);
}
}
@Inject(at = {@At("HEAD")},
method = {
"isSideCovered(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/Direction;F)Z"},
cancellable = true)
private static void onIsSideCovered(BlockView blockView_1,
BlockPos blockPos_1, Direction direction_1, float float_1,
CallbackInfoReturnable<Boolean> cir)
{
BlockState state = blockView_1.getBlockState(blockPos_1);
ShouldDrawSideEvent event = new ShouldDrawSideEvent(state);
WurstClient.INSTANCE.getEventManager().fire(event);
if(event.isRendered() != null)
cir.setReturnValue(!event.isRendered());
}
private BooleanProperty getPropForDir(Direction direction) {
switch (direction) {
case NORTH:
return NORTH;
case WEST:
return WEST;
case EAST:
return EAST;
case SOUTH:
return SOUTH;
}
throw new IllegalArgumentException();
}
@Subscribe
public void onTick(EventTick event) {
for (int i = 0; i < getSettings().get(0).toSlider().getValue(); i++) {
mc.player.networkHandler.sendPacket(new PlayerActionC2SPacket(Action.SWAP_ITEM_WITH_OFFHAND, BlockPos.ORIGIN, Direction.UP));
if (getSettings().get(1).toToggle().state) mc.player.networkHandler.sendPacket(new PlayerMoveC2SPacket(true));
}
}
@Override
public BlockState getStateForNeighborUpdate(BlockState blockState_1, Direction direction_1, BlockState blockState_2, IWorld iWorld_1, BlockPos blockPos_1, BlockPos blockPos_2) {
return WrappingUtil.convert(block.updateOnNeighborChanged(
(org.sandboxpowered.sandbox.api.state.BlockState) blockState_1,
WrappingUtil.convert(direction_1),
(org.sandboxpowered.sandbox.api.state.BlockState) blockState_2,
(org.sandboxpowered.sandbox.api.world.World) iWorld_1.getWorld(), (Position) blockPos_1,
(Position) blockPos_2
));
}
@Inject(method = "canPlaceAt", at = @At("HEAD"), cancellable = true)
private void onCanPlaceAt(BlockState state, CollisionView world, BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
BlockState soil = world.getBlockState(pos.down());
if (((IForgeBlockState) soil).canSustainPlant(world, pos.down(), Direction.UP, this)) {
cir.cancel();
cir.setReturnValue(true);
}
}
@Inject(method = "hasCrop", cancellable = true, at = @At("HEAD"))
private static void onHasCrop(BlockView world, BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
final BlockState ourState = world.getBlockState(pos);
final BlockState cropState = world.getBlockState(pos.up());
if (cropState.getBlock() instanceof IPlantable && ((IForgeBlockState) ourState).canSustainPlant(world, pos, Direction.UP, (IPlantable) cropState.getBlock())) {
cir.setReturnValue(true);
cir.cancel();
}
}