use of net.minecraft.world.level.block.state.properties.DirectionProperty in project Beyond-Earth by MrScautHD.
the class CoalTorchEvents method onBlockPlace.
@SubscribeEvent
public static void onBlockPlace(BlockEvent event) {
Level world = (Level) event.getWorld();
if (Methods.isSpaceWorldWithoutOxygen(world)) {
BlockPos pos = event.getPos();
BlockState blockState = world.getBlockState(pos);
Block block = blockState.getBlock();
/**
* FIRE
*/
if (block == Blocks.FIRE.defaultBlockState().getBlock()) {
world.setBlock(pos, Blocks.AIR.defaultBlockState(), 3);
} else /**
* WALL TORCH
*/
if (block == Blocks.WALL_TORCH) {
DirectionProperty property = (DirectionProperty) blockState.getBlock().getStateDefinition().getProperty("facing");
world.setBlock(pos, ModInit.WALL_COAL_TORCH_BLOCK.get().defaultBlockState().setValue(property, blockState.getValue(property)), 3);
playFireExtinguish(pos, world);
} else /**
* TORCH
*/
if (block == Blocks.TORCH) {
world.setBlock(pos, ModInit.COAL_TORCH_BLOCK.get().defaultBlockState(), 3);
playFireExtinguish(pos, world);
} else /**
* LANTERN
*/
if (block == Blocks.LANTERN) {
boolean isHanging = blockState.getValue(LanternBlock.HANGING);
if (isHanging) {
world.setBlock(pos, ModInit.COAL_LANTERN_BLOCK.get().defaultBlockState().setValue(CoalLanternBlock.HANGING, true), 3);
} else {
world.setBlock(pos, ModInit.COAL_LANTERN_BLOCK.get().defaultBlockState(), 3);
}
playFireExtinguish(pos, world);
} else /**
* CAMPFIRE
*/
if (block == Blocks.CAMPFIRE && blockState.getValue(CampfireBlock.LIT)) {
BooleanProperty property = (BooleanProperty) world.getBlockState(pos).getBlock().getStateDefinition().getProperty("lit");
world.setBlock(pos, world.getBlockState(pos).setValue(property, false), 3);
playFireExtinguish(pos, world);
}
}
}
use of net.minecraft.world.level.block.state.properties.DirectionProperty in project FastAsyncWorldEdit by IntellectualSites.
the class PaperweightAdapter method getProperties.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Map<String, ? extends Property<?>> getProperties(BlockType blockType) {
Map<String, Property<?>> properties = Maps.newTreeMap(String::compareTo);
Block block = getBlockFromType(blockType);
StateDefinition<Block, net.minecraft.world.level.block.state.BlockState> blockStateList = block.getStateDefinition();
for (net.minecraft.world.level.block.state.properties.Property state : blockStateList.getProperties()) {
Property property;
if (state instanceof net.minecraft.world.level.block.state.properties.BooleanProperty) {
property = new BooleanProperty(state.getName(), ImmutableList.copyOf(state.getPossibleValues()));
} else if (state instanceof DirectionProperty) {
property = new DirectionalProperty(state.getName(), (List<Direction>) state.getPossibleValues().stream().map(e -> Direction.valueOf(((StringRepresentable) e).getSerializedName().toUpperCase(Locale.ROOT))).collect(Collectors.toList()));
} else if (state instanceof net.minecraft.world.level.block.state.properties.EnumProperty) {
property = new EnumProperty(state.getName(), (List<String>) state.getPossibleValues().stream().map(e -> ((StringRepresentable) e).getSerializedName()).collect(Collectors.toList()));
} else if (state instanceof net.minecraft.world.level.block.state.properties.IntegerProperty) {
property = new IntegerProperty(state.getName(), ImmutableList.copyOf(state.getPossibleValues()));
} else {
throw new IllegalArgumentException("FastAsyncWorldEdit needs an update to support " + state.getClass().getSimpleName());
}
properties.put(property.getName(), property);
}
return properties;
}
use of net.minecraft.world.level.block.state.properties.DirectionProperty in project Create by Creators-of-Create.
the class StructureTransform method apply.
/**
* Minecraft does not support blockstate rotation around axes other than y. Add
* specific cases here for blockstates, that should react to rotations around
* horizontal axes
*/
public BlockState apply(BlockState state) {
if (mirror != null)
state = state.mirror(mirror);
Block block = state.getBlock();
if (rotationAxis == Axis.Y) {
if (block instanceof BellBlock) {
if (state.getValue(BlockStateProperties.BELL_ATTACHMENT) == BellAttachType.DOUBLE_WALL)
state = state.setValue(BlockStateProperties.BELL_ATTACHMENT, BellAttachType.SINGLE_WALL);
return state.setValue(BellBlock.FACING, rotation.rotate(state.getValue(BellBlock.FACING)));
}
return state.rotate(rotation);
}
if (block instanceof AbstractChassisBlock)
return rotateChassis(state);
if (block instanceof FaceAttachedHorizontalDirectionalBlock) {
DirectionProperty facingProperty = FaceAttachedHorizontalDirectionalBlock.FACING;
EnumProperty<AttachFace> faceProperty = FaceAttachedHorizontalDirectionalBlock.FACE;
Direction stateFacing = state.getValue(facingProperty);
AttachFace stateFace = state.getValue(faceProperty);
Direction forcedAxis = rotationAxis == Axis.Z ? Direction.EAST : Direction.SOUTH;
if (stateFacing.getAxis() == rotationAxis && stateFace == AttachFace.WALL)
return state;
for (int i = 0; i < rotation.ordinal(); i++) {
stateFace = state.getValue(faceProperty);
stateFacing = state.getValue(facingProperty);
boolean b = state.getValue(faceProperty) == AttachFace.CEILING;
state = state.setValue(facingProperty, b ? forcedAxis : forcedAxis.getOpposite());
if (stateFace != AttachFace.WALL) {
state = state.setValue(faceProperty, AttachFace.WALL);
continue;
}
if (stateFacing.getAxisDirection() == AxisDirection.POSITIVE) {
state = state.setValue(faceProperty, AttachFace.FLOOR);
continue;
}
state = state.setValue(faceProperty, AttachFace.CEILING);
}
return state;
}
boolean halfTurn = rotation == Rotation.CLOCKWISE_180;
if (block instanceof StairBlock) {
state = transformStairs(state, halfTurn);
return state;
}
if (AllBlocks.BELT.has(state)) {
state = transformBelt(state, halfTurn);
return state;
}
if (state.hasProperty(FACING)) {
Direction newFacing = transformFacing(state.getValue(FACING));
if (state.hasProperty(DirectionalAxisKineticBlock.AXIS_ALONG_FIRST_COORDINATE)) {
if (rotationAxis == newFacing.getAxis() && rotation.ordinal() % 2 == 1)
state = state.cycle(DirectionalAxisKineticBlock.AXIS_ALONG_FIRST_COORDINATE);
}
state = state.setValue(FACING, newFacing);
} else if (state.hasProperty(AXIS)) {
state = state.setValue(AXIS, transformAxis(state.getValue(AXIS)));
} else if (halfTurn) {
if (state.hasProperty(FACING)) {
Direction stateFacing = state.getValue(FACING);
if (stateFacing.getAxis() == rotationAxis)
return state;
}
if (state.hasProperty(HORIZONTAL_FACING)) {
Direction stateFacing = state.getValue(HORIZONTAL_FACING);
if (stateFacing.getAxis() == rotationAxis)
return state;
}
state = state.rotate(rotation);
if (state.hasProperty(SlabBlock.TYPE) && state.getValue(SlabBlock.TYPE) != SlabType.DOUBLE)
state = state.setValue(SlabBlock.TYPE, state.getValue(SlabBlock.TYPE) == SlabType.BOTTOM ? SlabType.TOP : SlabType.BOTTOM);
}
return state;
}
use of net.minecraft.world.level.block.state.properties.DirectionProperty in project FastAsyncWorldEdit by IntellectualSites.
the class PaperweightAdapter method applyProperties.
@SuppressWarnings({ "rawtypes", "unchecked" })
private net.minecraft.world.level.block.state.BlockState applyProperties(StateDefinition<Block, net.minecraft.world.level.block.state.BlockState> stateContainer, net.minecraft.world.level.block.state.BlockState newState, Map<Property<?>, Object> states) {
for (Map.Entry<Property<?>, Object> state : states.entrySet()) {
net.minecraft.world.level.block.state.properties.Property<?> property = stateContainer.getProperty(state.getKey().getName());
Comparable<?> value = (Comparable) state.getValue();
// we may need to adapt this value, depending on the source prop
if (property instanceof DirectionProperty) {
Direction dir = (Direction) value;
value = adapt(dir);
} else if (property instanceof net.minecraft.world.level.block.state.properties.EnumProperty) {
String enumName = (String) value;
value = ((net.minecraft.world.level.block.state.properties.EnumProperty<?>) property).getValue(enumName).orElseThrow(() -> new IllegalStateException("Enum property " + property.getName() + " does not contain " + enumName));
}
newState = newState.setValue((net.minecraft.world.level.block.state.properties.Property) property, (Comparable) value);
}
return newState;
}
use of net.minecraft.world.level.block.state.properties.DirectionProperty in project Beyond-Earth by MrScautHD.
the class CoalTorchBlock method use.
@Override
public InteractionResult use(BlockState p_51274_, Level p_51275_, BlockPos p_51276_, Player p_51277_, InteractionHand p_51278_, BlockHitResult p_51279_) {
ItemStack itemstack = p_51277_.getItemInHand(p_51278_);
if (p_51275_.getBlockState(p_51276_).getBlock() == ModInit.WALL_COAL_TORCH_BLOCK.get() && !Methods.isSpaceWorldWithoutOxygen(p_51275_) && (itemstack.getItem() == Items.FLINT_AND_STEEL || itemstack.getItem() == Items.FIRE_CHARGE)) {
if (!p_51275_.isClientSide) {
BlockState bs = p_51275_.getBlockState(p_51276_);
DirectionProperty property = (DirectionProperty) bs.getBlock().getStateDefinition().getProperty("facing");
p_51275_.setBlock(p_51276_, Blocks.WALL_TORCH.defaultBlockState().setValue(property, bs.getValue(property)), 3);
flintManager(itemstack, p_51277_, p_51278_, p_51276_, p_51275_);
return InteractionResult.SUCCESS;
}
}
if (p_51275_.getBlockState(p_51276_).getBlock() == ModInit.COAL_TORCH_BLOCK.get() && !Methods.isSpaceWorldWithoutOxygen(p_51275_) && (itemstack.getItem() == Items.FLINT_AND_STEEL || itemstack.getItem() == Items.FIRE_CHARGE)) {
if (!p_51275_.isClientSide) {
p_51275_.setBlock(p_51276_, Blocks.TORCH.defaultBlockState(), 3);
flintManager(itemstack, p_51277_, p_51278_, p_51276_, p_51275_);
return InteractionResult.SUCCESS;
}
}
if (itemstack.getItem() == Items.FLINT_AND_STEEL || itemstack.getItem() == Items.FIRE_CHARGE) {
return InteractionResult.SUCCESS;
}
return InteractionResult.PASS;
}
Aggregations