Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ org.gradle.jvmargs=-Xmx1G
carpet_core_version=1.4.50+v211021

# Mod Properties
mod_version = 1.4.43
mod_version = 1.4.46
maven_group = carpet-extra
archives_base_name = carpet-extra

Expand All @@ -22,12 +22,12 @@ org.gradle.jvmargs=-Xmx1G
# The Curseforge versions "names" or ids for the main branch (comma separated: 1.16.4,1.16.5)
# This is needed because CF uses too vague names for prereleases and release candidates
# Can also be the version ID directly coming from https://minecraft.curseforge.com/api/game/versions?token=[API_TOKEN]
release-curse-versions = 1.16.4,1.16.5
#release-curse-versions = 1.16.4,1.16.5
# Whether or not to build another branch on release
release-extra-branch = true
#release-extra-branch = true
# The name of the second branch to release
release-extra-branch-name = 1.17
#release-extra-branch-name = 1.17
# The "name" or id of the Curseforge version for the secondary branch
# This is needed because CF uses too vague names for snapshots
# Can also be the version ID directly coming from https://minecraft.curseforge.com/api/game/versions?token=[API_TOKEN]
release-extra-curse-version = 1.17.1
#release-extra-curse-version = 1.17.1
Comment on lines +25 to +33
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why comment those?

Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
223 changes: 118 additions & 105 deletions src/main/java/carpetextra/utils/BlockPlacer.java
Original file line number Diff line number Diff line change
@@ -1,118 +1,131 @@
package carpetextra.utils;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.ComparatorBlock;
import net.minecraft.block.DispenserBlock;
import net.minecraft.block.FacingBlock;
import net.minecraft.block.GlazedTerracottaBlock;
import net.minecraft.block.HorizontalFacingBlock;
import net.minecraft.block.ObserverBlock;
import net.minecraft.block.PistonBlock;
import net.minecraft.block.RepeaterBlock;
import net.minecraft.block.StairsBlock;
import net.minecraft.block.TrapdoorBlock;
import net.minecraft.block.enums.BlockHalf;
import net.minecraft.block.enums.ComparatorMode;
import net.minecraft.block.*;
import net.minecraft.block.enums.*;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.Property;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;

public class BlockPlacer
{
public static BlockState alternativeBlockPlacement(Block block, ItemPlacementContext context)//World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
//actual alternative block placement code
public class BlockPlacer {
private static DirectionProperty getFirstDirectionProperty(BlockState state) {
for (Property<?> prop : state.getProperties()) {
if (prop instanceof DirectionProperty) {
return (DirectionProperty) prop;
}
}
return null;
}
private static boolean isBlockAttachableChest(Block originBlock, Direction facing, BlockPos checkPos, World world) {
BlockState checkState = world.getBlockState(checkPos);
if (checkState == null) {
return false;
}
if (originBlock.equals(checkState.getBlock())) {
return checkState.get(ChestBlock.FACING).equals(facing) && checkState.get(ChestBlock.CHEST_TYPE) == ChestType.SINGLE;
}
return false;
}
private static boolean isBlockOffsetNotReplaceableBlock(BlockPos checkPos, Direction facing, World world){
return !world.getBlockState(checkPos.offset(facing)).getMaterial().isReplaceable();
}

Direction facing;
Vec3d vec3d = context.getHitPos();
BlockPos pos = context.getBlockPos();
double hitX = vec3d.x - pos.getX();
if (hitX<2) // vanilla
return null;
int code = (int)(hitX-2)/2;
//
// now it would be great if hitX was adjusted in context to original range from 0.0 to 1.0
// since its actually using it. Its private - maybe with Reflections?
//
PlayerEntity placer = context.getPlayer();
World world = context.getWorld();
public static BlockState alternativeBlockPlacement(Block block, ItemPlacementContext context)//World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
//actual alternative block placement code

if (block instanceof GlazedTerracottaBlock)
{
facing = Direction.byId(code);
if(facing == Direction.UP || facing == Direction.DOWN)
{
facing = placer.getHorizontalFacing().getOpposite();
}
return block.getDefaultState().with(HorizontalFacingBlock.FACING, facing);
}
else if (block instanceof ObserverBlock)
{
return block.getDefaultState()
.with(FacingBlock.FACING, Direction.byId(code))
.with(ObserverBlock.POWERED, true);
}
else if (block instanceof RepeaterBlock)
{
facing = Direction.byId(code % 16);
if(facing == Direction.UP || facing == Direction.DOWN)
{
facing = placer.getHorizontalFacing().getOpposite();
}
return block.getDefaultState()
.with(HorizontalFacingBlock.FACING, facing)
.with(RepeaterBlock.DELAY, MathHelper.clamp(code / 16, 1, 4))
.with(RepeaterBlock.LOCKED, Boolean.FALSE);
}
else if (block instanceof TrapdoorBlock)
{
facing = Direction.byId(code % 16);
if(facing == Direction.UP || facing == Direction.DOWN)
{
facing = placer.getHorizontalFacing().getOpposite();
}
return block.getDefaultState()
.with(TrapdoorBlock.FACING, facing)
.with(TrapdoorBlock.OPEN, Boolean.FALSE)
.with(TrapdoorBlock.HALF, (code >= 16) ? BlockHalf.TOP : BlockHalf.BOTTOM)
.with(TrapdoorBlock.OPEN, world.isReceivingRedstonePower(pos));
}
else if (block instanceof ComparatorBlock)
{
facing = Direction.byId(code % 16);
if((facing == Direction.UP) || (facing == Direction.DOWN))
{
facing = placer.getHorizontalFacing().getOpposite();
}
ComparatorMode m = (hitX >= 16)?ComparatorMode.SUBTRACT: ComparatorMode.COMPARE;
return block.getDefaultState()
.with(HorizontalFacingBlock.FACING, facing)
.with(ComparatorBlock.POWERED, Boolean.FALSE)
.with(ComparatorBlock.MODE, m);
}
else if (block instanceof DispenserBlock)
{
return block.getDefaultState()
.with(DispenserBlock.FACING, Direction.byId(code))
.with(DispenserBlock.TRIGGERED, Boolean.FALSE);
}
else if (block instanceof PistonBlock)
{
return block.getDefaultState()
.with(FacingBlock.FACING, Direction.byId(code))
.with(PistonBlock.EXTENDED, Boolean.FALSE);
}
else if (block instanceof StairsBlock)
{
return block.getPlacementState(context)//worldIn, pos, facing, hitX, hitY, hitZ, meta, placer)
.with(StairsBlock.FACING, Direction.byId(code % 16))
.with(StairsBlock.HALF, ( hitX >= 16)?BlockHalf.TOP : BlockHalf.BOTTOM);
}
return null;
}
Direction facing;
Vec3d vec3d = context.getHitPos();
BlockPos pos = context.getBlockPos();
double hitX = vec3d.x - pos.getX();
BlockState state = block.getDefaultState();
DirectionProperty directionProperty = getFirstDirectionProperty(state);
if (hitX < 2 || !(block instanceof AbstractRailBlock || block instanceof PillarBlock) && directionProperty == null) // vanilla
return null;
int code = (int) (hitX - 2) / 2;

//
// now it would be great if hitX was adjusted in context to original range from 0.0 to 1.0
// since its actually using it. Its private - maybe with Reflections?
//
PlayerEntity placer = context.getPlayer();
World world = context.getWorld();
if (block instanceof AbstractRailBlock){
RailShape shapeEnumFound = RailShape.values()[code%RailShape.values().length]; //avoid NPE
if (block instanceof RailBlock)
{
return state.with(RailBlock.SHAPE,shapeEnumFound);
}
else if (block instanceof DetectorRailBlock)
{
return state.with(DetectorRailBlock.SHAPE,shapeEnumFound);
}
else
{
return state.with(PoweredRailBlock.SHAPE,shapeEnumFound);
}
} else if (block instanceof PillarBlock) {
return state.with(PillarBlock.AXIS, Direction.Axis.values()[code % Direction.Axis.VALUES.length]);
}
else
{
int FacingId = code % 16;
facing = Direction.byId(FacingId);
if (!directionProperty.getValues().contains(facing)) {
if (placer == null){
facing = Direction.NORTH;
} else {
facing = placer.getHorizontalFacing().getOpposite();
}
}
state = state.with(directionProperty, facing);
}
//check blocks with additional states first
if (block instanceof RepeaterBlock) {
state = state
.with(RepeaterBlock.DELAY, MathHelper.clamp(code / 16, 1, 4))
.with(RepeaterBlock.LOCKED, Boolean.FALSE);
} else if (block instanceof TrapdoorBlock) {
state = state
.with(TrapdoorBlock.OPEN, Boolean.FALSE)
.with(TrapdoorBlock.HALF, (code >= 16) ? BlockHalf.TOP : BlockHalf.BOTTOM)
.with(TrapdoorBlock.OPEN, world.isReceivingRedstonePower(pos));
} else if (block instanceof ComparatorBlock) {
ComparatorMode m = (hitX >= 16) ? ComparatorMode.SUBTRACT : ComparatorMode.COMPARE;
state = state
.with(ComparatorBlock.POWERED, Boolean.FALSE)
.with(ComparatorBlock.MODE, m);
} else if (block instanceof StairsBlock) {
state = block.getPlacementState(context); //worldIn, pos, facing, hitX, hitY, hitZ, meta, placer)
if(state == null) {return null;}
return state.with(StairsBlock.FACING, facing)
.with(StairsBlock.HALF, (hitX >= 16) ? BlockHalf.TOP : BlockHalf.BOTTOM);
} else if (block instanceof WallMountedBlock) {
return state.with(WallMountedBlock.FACE, (code >= 32) ? WallMountLocation.CEILING: (code >= 16) ? WallMountLocation.WALL : WallMountLocation.FLOOR).
with(WallMountedBlock.FACING, facing);
} else if (block instanceof WallSkullBlock){
return state.with(WallMountedBlock.FACING, facing);
}
else if (block instanceof ChestBlock)
{
if (isBlockAttachableChest(block, facing, pos.offset(facing.rotateYClockwise()), world)) {
return state.with(ChestBlock.CHEST_TYPE, ChestType.LEFT);
}
else if (isBlockAttachableChest(block, facing, pos.offset(facing.rotateYCounterclockwise()), world)) {
return state.with(ChestBlock.CHEST_TYPE, ChestType.RIGHT);
}
return state.with(ChestBlock.CHEST_TYPE, ChestType.SINGLE);
} else if (block instanceof BedBlock && isBlockOffsetNotReplaceableBlock(pos, facing, world)) {
return null;
} else if (block instanceof DoorBlock && isBlockOffsetNotReplaceableBlock(pos, Direction.UP, world)) {
return null;
}
return state;
}
}