Add windows, wallpaper and bruh.ogg
This commit is contained in:
parent
5bbb26ce81
commit
02cdf8fa63
225 changed files with 4833 additions and 61 deletions
54
src/main/java/su/a71/new_soviet/blocks/WallpaperBlock.java
Normal file
54
src/main/java/su/a71/new_soviet/blocks/WallpaperBlock.java
Normal file
|
@ -0,0 +1,54 @@
|
|||
package su.a71.new_soviet.blocks;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.DoorBlock;
|
||||
import net.minecraft.block.TrapdoorBlock;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.BooleanProperty;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
|
||||
public class WallpaperBlock extends Block {
|
||||
public static final BooleanProperty HAS_BASEBOARD = BooleanProperty.of("has_baseboard");
|
||||
|
||||
public WallpaperBlock(Settings settings) {
|
||||
super(settings);
|
||||
this.setDefaultState(this.stateManager.getDefaultState().with(HAS_BASEBOARD, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
builder.add(HAS_BASEBOARD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||
BlockPos pos = ctx.getBlockPos();
|
||||
BlockState blockBelow = ctx.getWorld().getBlockState(pos);
|
||||
Block block = blockBelow.getBlock();
|
||||
|
||||
boolean hasBaseboard = isFullBlock(ctx.getWorld(), pos);
|
||||
return this.getDefaultState().with(HAS_BASEBOARD, hasBaseboard);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos, boolean notify) {
|
||||
|
||||
BlockState updatedBlockState = state.with(HAS_BASEBOARD, isFullBlock(world, pos));
|
||||
world.setBlockState(pos, updatedBlockState);
|
||||
|
||||
}
|
||||
|
||||
private boolean isFullBlock(WorldAccess world, BlockPos pos) {
|
||||
pos = pos.down();
|
||||
BlockState state = world.getBlockState(pos);
|
||||
Block block = state.getBlock();
|
||||
//return (!state.getCollisionShape(world, pos).getFace(Direction.UP).isEmpty() || state.isSideSolidFullSquare(world, pos, Direction.UP)) && !(block instanceof WallpaperBlock);
|
||||
return block.isShapeFullCube(state, world, pos) && !(block instanceof WallpaperBlock) && (!block.isTransparent(state, world, pos));
|
||||
}
|
||||
}
|
|
@ -1,60 +1,410 @@
|
|||
package su.a71.new_soviet.blocks;
|
||||
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.block.enums.DoorHinge;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.projectile.ProjectileEntity;
|
||||
import net.minecraft.fluid.FluidState;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.BooleanProperty;
|
||||
import net.minecraft.state.property.EnumProperty;
|
||||
import net.minecraft.state.property.IntProperty;
|
||||
import net.minecraft.state.property.Properties;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import su.a71.new_soviet.registration.NSE_Items;
|
||||
import su.a71.new_soviet.registration.NSE_Sounds;
|
||||
import su.a71.new_soviet.util.Shapes;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class WindowBlock extends HorizontalFacingBlock {
|
||||
public static final IntProperty WIN_TYPE = IntProperty.of("window_type", 0, 2);
|
||||
public static final IntProperty WINDOW_TYPE = IntProperty.of("window_type", 0, 3);
|
||||
public static final BooleanProperty BROKEN = Properties.CRACKED;
|
||||
public static final BooleanProperty CLOSED = BooleanProperty.of("closed");
|
||||
public static final IntProperty BROKEN_GLASS_TYPE = IntProperty.of("broken_glass_type", 0, 3);
|
||||
public static final BooleanProperty WATERLOGGED = BooleanProperty.of("waterlogged");
|
||||
public static final EnumProperty<DoorHinge> HINGE = Properties.DOOR_HINGE;
|
||||
public static final Shapes.HorizontalShape SHAPE;
|
||||
public static final Shapes.HorizontalShape FRAME_SHAPE_BOTTOM;
|
||||
public static final Shapes.HorizontalShape FRAME_SHAPE_TOP;
|
||||
public static final Shapes.HorizontalShape FRAME_SHAPE_RIGHT;
|
||||
public static final Shapes.HorizontalShape FRAME_SHAPE_LEFT;
|
||||
public static final Shapes.HorizontalShape PANE_FRAME_SHAPE;
|
||||
private final boolean pane;
|
||||
|
||||
public WindowBlock(Settings settings) {
|
||||
@Nullable
|
||||
private Item cachedItem;
|
||||
|
||||
public WindowBlock(Settings settings, boolean pane) {
|
||||
super(settings);
|
||||
this.pane = pane;
|
||||
setDefaultState(getDefaultState()
|
||||
.with(Properties.HORIZONTAL_FACING, Direction.NORTH)
|
||||
.with(BROKEN, false)
|
||||
.with(WIN_TYPE, 0));
|
||||
.with(WINDOW_TYPE, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
builder.add(Properties.HORIZONTAL_FACING, WIN_TYPE, Properties.CRACKED);
|
||||
builder.add(Properties.HORIZONTAL_FACING, WINDOW_TYPE, Properties.CRACKED, WATERLOGGED, HINGE, BROKEN_GLASS_TYPE, CLOSED);
|
||||
}
|
||||
|
||||
public void onEntityCollision(World world, BlockPos pos, Entity entity) {
|
||||
if (entity instanceof ProjectileEntity) {
|
||||
world.getBlockState(pos);
|
||||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
||||
if (state.get(BROKEN)) {
|
||||
if (player.getInventory().getMainHandStack().getItem() == Blocks.GLASS_PANE.asItem() && !player.getItemCooldownManager().isCoolingDown(Blocks.GLASS_PANE.asItem())) {
|
||||
if (!player.isCreative())
|
||||
player.getInventory().getMainHandStack().decrement(1);
|
||||
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.BLOCK_GLASS_PLACE, SoundCategory.BLOCKS, 0.8f, 1f);
|
||||
world.setBlockState(pos, state.with(BROKEN, false));
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
} if (player.getInventory().getMainHandStack().getItem() == NSE_Items.SCREWDRIVER && !player.getItemCooldownManager().isCoolingDown(NSE_Items.SCREWDRIVER)) {
|
||||
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), NSE_Sounds.SCREWDRIVER_SOUND, SoundCategory.BLOCKS, 1.0f, 1f);
|
||||
if (!state.get(CLOSED)) {
|
||||
player.sendMessage(Text.translatable("block.new_soviet.window.fixed").formatted(Formatting.BOLD), true);
|
||||
} else if (state.get(CLOSED)) {
|
||||
player.sendMessage(Text.translatable("block.new_soviet.window.unfixed").formatted(Formatting.BOLD), true);
|
||||
}
|
||||
world.setBlockState(pos, state.with(CLOSED, !state.get(CLOSED)), 2);
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
return super.onUse(state, world, pos, player, hand, hit);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onProjectileHit(World world, BlockState state, BlockHitResult hit, ProjectileEntity projectile) {
|
||||
if (!state.get(BROKEN)) {
|
||||
world.playSound(null, hit.getBlockPos().getX(), hit.getBlockPos().getY(), hit.getBlockPos().getZ(), SoundEvents.BLOCK_GLASS_BREAK, SoundCategory.BLOCKS, 0.8f, 1f);
|
||||
if (projectile.getOwner().isPlayer()) {
|
||||
PlayerEntity player = (PlayerEntity) projectile.getOwner();
|
||||
world.syncWorldEvent(player, 2001, hit.getBlockPos(), getRawIdFromState(Blocks.GLASS.getDefaultState()));
|
||||
world.syncWorldEvent(player, 2001, hit.getBlockPos(), getRawIdFromState(Blocks.GLASS.getDefaultState()));
|
||||
}
|
||||
}
|
||||
BlockPos pos = hit.getBlockPos();
|
||||
BlockState above = world.getBlockState(pos.up());
|
||||
BlockState below = world.getBlockState(pos.down());
|
||||
boolean waterlogged = world.getFluidState(pos).getFluid() == Fluids.WATER;
|
||||
int broken_glass_type = 0;
|
||||
if (((can_be_connected(below) && bottom_connected(below)) && below.get(FACING) == state.get(FACING)) && ((can_be_connected(above) && top_connected(above)) && above.get(FACING) == state.get(FACING))) {
|
||||
int below_broken_glass = below.get(BROKEN_GLASS_TYPE);
|
||||
if (below_broken_glass == 3) {world.setBlockState(pos.down(), below.with(BROKEN_GLASS_TYPE, 1));}
|
||||
else if (below_broken_glass == 2) {world.setBlockState(pos.down(), below.with(BROKEN_GLASS_TYPE, 0));}
|
||||
int above_broken_glass = above.get(BROKEN_GLASS_TYPE);
|
||||
if (above_broken_glass == 3) {world.setBlockState(pos.up(), above.with(BROKEN_GLASS_TYPE, 2), 2);}
|
||||
else if (above_broken_glass == 1) {world.setBlockState(pos.up(), above.with(BROKEN_GLASS_TYPE, 0), 2);}
|
||||
if (!below.get(BROKEN) && state.get(WINDOW_TYPE) != 0 && !above.get(BROKEN)) {
|
||||
broken_glass_type = 3;
|
||||
}
|
||||
else if (!below.get(BROKEN) && state.get(WINDOW_TYPE) != 1 && above.get(BROKEN)) {
|
||||
broken_glass_type = 1;
|
||||
}
|
||||
else if (below.get(BROKEN) && state.get(WINDOW_TYPE) != 3 && !above.get(BROKEN)) {
|
||||
broken_glass_type = 2;
|
||||
}
|
||||
} else if (((can_be_connected(below) && bottom_connected(below)) && below.get(FACING) == state.get(FACING)) && (!(can_be_connected(above)) || !top_connected(above))) {
|
||||
if (!below.get(BROKEN) && state.get(WINDOW_TYPE) != 1) {
|
||||
broken_glass_type = 1;
|
||||
} else {
|
||||
int below_broken_glass = below.get(BROKEN_GLASS_TYPE);
|
||||
if (below_broken_glass == 3) {world.setBlockState(pos.down(), below.with(BROKEN_GLASS_TYPE, 1));}
|
||||
else if (below_broken_glass == 2) {world.setBlockState(pos.down(), below.with(BROKEN_GLASS_TYPE, 0));}
|
||||
}
|
||||
} else if ((!(can_be_connected(below)) || !bottom_connected(below)) && ((can_be_connected(above) && top_connected(above)) && above.get(FACING) == state.get(FACING))) {
|
||||
if (!above.get(BROKEN) && state.get(WINDOW_TYPE) != 3) {
|
||||
broken_glass_type = 2;
|
||||
} else {
|
||||
int above_broken_glass = above.get(BROKEN_GLASS_TYPE);
|
||||
if (above_broken_glass == 3) {world.setBlockState(pos.up(), above.with(BROKEN_GLASS_TYPE, 2), 2);}
|
||||
else if (above_broken_glass == 1) {world.setBlockState(pos.up(), above.with(BROKEN_GLASS_TYPE, 0), 2);}
|
||||
}
|
||||
}
|
||||
BlockState updatedBlockState = state
|
||||
.with(WATERLOGGED, waterlogged)
|
||||
.with(BROKEN_GLASS_TYPE, broken_glass_type)
|
||||
.with(BROKEN, true);
|
||||
world.setBlockState(pos, updatedBlockState);
|
||||
super.onProjectileHit(world, state, hit, projectile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
|
||||
this.spawnBreakParticles(world, player, pos, state);
|
||||
if (!world.isClient && !player.isCreative()) {
|
||||
super.onBreak(world, pos, state, player);
|
||||
|
||||
ItemStack itemStack = new ItemStack(this);
|
||||
itemStack.getOrCreateNbt().putBoolean("broken", state.get(BROKEN));
|
||||
|
||||
world.spawnEntity(new ItemEntity(world, pos.getX(), pos.getY(), pos.getZ(), itemStack));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext ctx) {
|
||||
Direction dir = state.get(FACING);
|
||||
return switch (dir) {
|
||||
case NORTH, SOUTH -> VoxelShapes.cuboid(0.0625f, 0.0f, 0.3125f, 0.9375f, 0.5625f, 0.6875f);
|
||||
case EAST, WEST -> VoxelShapes.cuboid(0.3125f, 0.0f, 0.0625f, 0.6875f, 0.5625f, 0.9375f);
|
||||
default -> VoxelShapes.fullCube();
|
||||
};
|
||||
int type = state.get(WINDOW_TYPE);
|
||||
if (!state.get(BROKEN)) {
|
||||
return switch (dir) {
|
||||
case NORTH -> SHAPE.north();
|
||||
case SOUTH -> SHAPE.south();
|
||||
case WEST -> SHAPE.west();
|
||||
case EAST -> SHAPE.east();
|
||||
default -> VoxelShapes.fullCube();
|
||||
};
|
||||
}
|
||||
else {
|
||||
if (!this.pane) {
|
||||
return switch (dir) {
|
||||
case NORTH -> switch (type) {
|
||||
case 1 -> VoxelShapes.union(FRAME_SHAPE_BOTTOM.north(), FRAME_SHAPE_RIGHT.north(), FRAME_SHAPE_LEFT.north());
|
||||
case 2 -> VoxelShapes.union(FRAME_SHAPE_RIGHT.north(), FRAME_SHAPE_LEFT.north());
|
||||
case 3 -> VoxelShapes.union(FRAME_SHAPE_TOP.north(), FRAME_SHAPE_RIGHT.north(), FRAME_SHAPE_LEFT.north());
|
||||
default -> VoxelShapes.union(FRAME_SHAPE_BOTTOM.north(), FRAME_SHAPE_RIGHT.north(), FRAME_SHAPE_LEFT.north(), FRAME_SHAPE_TOP.north());
|
||||
};
|
||||
case SOUTH -> switch (type) {
|
||||
case 1 -> VoxelShapes.union(FRAME_SHAPE_BOTTOM.south(), FRAME_SHAPE_RIGHT.south(), FRAME_SHAPE_LEFT.south());
|
||||
case 2 -> VoxelShapes.union(FRAME_SHAPE_RIGHT.south(), FRAME_SHAPE_LEFT.south());
|
||||
case 3 -> VoxelShapes.union(FRAME_SHAPE_TOP.south(), FRAME_SHAPE_RIGHT.south(), FRAME_SHAPE_LEFT.south());
|
||||
default -> VoxelShapes.union(FRAME_SHAPE_BOTTOM.south(), FRAME_SHAPE_RIGHT.south(), FRAME_SHAPE_LEFT.south(), FRAME_SHAPE_TOP.south());
|
||||
};
|
||||
case WEST -> switch (type) {
|
||||
case 1 -> VoxelShapes.union(FRAME_SHAPE_BOTTOM.west(), FRAME_SHAPE_RIGHT.west(), FRAME_SHAPE_LEFT.west());
|
||||
case 2 -> VoxelShapes.union(FRAME_SHAPE_RIGHT.west(), FRAME_SHAPE_LEFT.west());
|
||||
case 3 -> VoxelShapes.union(FRAME_SHAPE_TOP.west(), FRAME_SHAPE_RIGHT.west(), FRAME_SHAPE_LEFT.west());
|
||||
default -> VoxelShapes.union(FRAME_SHAPE_BOTTOM.west(), FRAME_SHAPE_RIGHT.west(), FRAME_SHAPE_LEFT.west(), FRAME_SHAPE_TOP.west());
|
||||
};
|
||||
case EAST -> switch (type) {
|
||||
case 1 -> VoxelShapes.union(FRAME_SHAPE_BOTTOM.east(), FRAME_SHAPE_RIGHT.east(), FRAME_SHAPE_LEFT.east());
|
||||
case 2 -> VoxelShapes.union(FRAME_SHAPE_RIGHT.east(), FRAME_SHAPE_LEFT.east());
|
||||
case 3 -> VoxelShapes.union(FRAME_SHAPE_TOP.east(), FRAME_SHAPE_RIGHT.east(), FRAME_SHAPE_LEFT.east());
|
||||
default -> VoxelShapes.union(FRAME_SHAPE_BOTTOM.east(), FRAME_SHAPE_RIGHT.east(), FRAME_SHAPE_LEFT.east(), FRAME_SHAPE_TOP.east());
|
||||
};
|
||||
default -> VoxelShapes.fullCube();
|
||||
};
|
||||
} else {
|
||||
return switch (dir) {
|
||||
case NORTH -> switch (type) {
|
||||
case 1 -> VoxelShapes.union(FRAME_SHAPE_BOTTOM.north(), FRAME_SHAPE_RIGHT.north(), FRAME_SHAPE_LEFT.north(), PANE_FRAME_SHAPE.north());
|
||||
case 2 -> VoxelShapes.union(FRAME_SHAPE_RIGHT.north(), FRAME_SHAPE_LEFT.north(), PANE_FRAME_SHAPE.north());
|
||||
case 3 -> VoxelShapes.union(FRAME_SHAPE_TOP.north(), FRAME_SHAPE_RIGHT.north(), FRAME_SHAPE_LEFT.north(), PANE_FRAME_SHAPE.north());
|
||||
default -> VoxelShapes.union(FRAME_SHAPE_BOTTOM.north(), FRAME_SHAPE_RIGHT.north(), FRAME_SHAPE_LEFT.north(), FRAME_SHAPE_TOP.north(), PANE_FRAME_SHAPE.north());
|
||||
};
|
||||
case SOUTH -> switch (type) {
|
||||
case 1 -> VoxelShapes.union(FRAME_SHAPE_BOTTOM.south(), FRAME_SHAPE_RIGHT.south(), FRAME_SHAPE_LEFT.south(), PANE_FRAME_SHAPE.south());
|
||||
case 2 -> VoxelShapes.union(FRAME_SHAPE_RIGHT.south(), FRAME_SHAPE_LEFT.south(), PANE_FRAME_SHAPE.south());
|
||||
case 3 -> VoxelShapes.union(FRAME_SHAPE_TOP.south(), FRAME_SHAPE_RIGHT.south(), FRAME_SHAPE_LEFT.south(), PANE_FRAME_SHAPE.south());
|
||||
default -> VoxelShapes.union(FRAME_SHAPE_BOTTOM.south(), FRAME_SHAPE_RIGHT.south(), FRAME_SHAPE_LEFT.south(), FRAME_SHAPE_TOP.south(), PANE_FRAME_SHAPE.south());
|
||||
};
|
||||
case WEST -> switch (type) {
|
||||
case 1 -> VoxelShapes.union(FRAME_SHAPE_BOTTOM.west(), FRAME_SHAPE_RIGHT.west(), FRAME_SHAPE_LEFT.west(), PANE_FRAME_SHAPE.west());
|
||||
case 2 -> VoxelShapes.union(FRAME_SHAPE_RIGHT.west(), FRAME_SHAPE_LEFT.west(), PANE_FRAME_SHAPE.west());
|
||||
case 3 -> VoxelShapes.union(FRAME_SHAPE_TOP.west(), FRAME_SHAPE_RIGHT.west(), FRAME_SHAPE_LEFT.west(), PANE_FRAME_SHAPE.west());
|
||||
default -> VoxelShapes.union(FRAME_SHAPE_BOTTOM.west(), FRAME_SHAPE_RIGHT.west(), FRAME_SHAPE_LEFT.west(), FRAME_SHAPE_TOP.west(), PANE_FRAME_SHAPE.west());
|
||||
};
|
||||
case EAST -> switch (type) {
|
||||
case 1 -> VoxelShapes.union(FRAME_SHAPE_BOTTOM.east(), FRAME_SHAPE_RIGHT.east(), FRAME_SHAPE_LEFT.east(), PANE_FRAME_SHAPE.east());
|
||||
case 2 -> VoxelShapes.union(FRAME_SHAPE_RIGHT.east(), FRAME_SHAPE_LEFT.east(), PANE_FRAME_SHAPE.east());
|
||||
case 3 -> VoxelShapes.union(FRAME_SHAPE_TOP.east(), FRAME_SHAPE_RIGHT.east(), FRAME_SHAPE_LEFT.east(), PANE_FRAME_SHAPE.east());
|
||||
default -> VoxelShapes.union(FRAME_SHAPE_BOTTOM.east(), FRAME_SHAPE_RIGHT.east(), FRAME_SHAPE_LEFT.east(), FRAME_SHAPE_TOP.east(), PANE_FRAME_SHAPE.east());
|
||||
};
|
||||
default -> VoxelShapes.fullCube();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||
ItemStack itemStack = ctx.getStack();
|
||||
boolean broken = itemStack.getOrCreateNbt().getBoolean("broken");
|
||||
BlockState above = ctx.getWorld().getBlockState(ctx.getBlockPos().up());
|
||||
BlockState below = ctx.getWorld().getBlockState(ctx.getBlockPos().down());
|
||||
if ((above.getBlock() instanceof WindowBlock && ((WindowBlock)above.getBlock()).getStateManager().getProperty("broken").equals(true)) || (below.getBlock() instanceof WindowBlock)) {
|
||||
|
||||
boolean waterlogged = ctx.getWorld().getFluidState(ctx.getBlockPos()).getFluid() == Fluids.WATER;
|
||||
DoorHinge hinge = this.getHinge(ctx);
|
||||
int window_type = 0;
|
||||
if ((can_be_connected(below) && !below.get(CLOSED)) && (can_be_connected(above) && !above.get(CLOSED))) {
|
||||
window_type = 2;
|
||||
if (!below.get(CLOSED)) {
|
||||
hinge = below.get(HINGE);
|
||||
} else if (!above.get(CLOSED)) {
|
||||
hinge = above.get(HINGE);
|
||||
}
|
||||
} else if ((can_be_connected(below) && !below.get(CLOSED)) && (!(can_be_connected(above)) ||above.get(CLOSED))) {
|
||||
window_type = 3;
|
||||
hinge = below.get(HINGE);
|
||||
} else if ((!(can_be_connected(below)) || below.get(CLOSED)) && (can_be_connected(above) && !above.get(CLOSED))) {
|
||||
window_type = 1;
|
||||
hinge = above.get(HINGE);
|
||||
}
|
||||
return super.getPlacementState(ctx).with(Properties.HORIZONTAL_FACING, ctx.getHorizontalPlayerFacing().getOpposite());
|
||||
return Objects.requireNonNull(super.getPlacementState(ctx)).with(Properties.HORIZONTAL_FACING, ctx.getHorizontalPlayerFacing().getOpposite())
|
||||
.with(WINDOW_TYPE, window_type)
|
||||
.with(WATERLOGGED, waterlogged)
|
||||
.with(HINGE, hinge)
|
||||
.with(BROKEN, broken)
|
||||
.with(CLOSED, false);
|
||||
}
|
||||
}
|
||||
|
||||
private DoorHinge getHinge(ItemPlacementContext ctx) {
|
||||
BlockPos blockPos = ctx.getBlockPos();
|
||||
double hitX = ctx.getHitPos().getX() - blockPos.getX();
|
||||
double hitZ = ctx.getHitPos().getZ() - blockPos.getZ();
|
||||
|
||||
if (ctx.getHorizontalPlayerFacing().getOpposite() == Direction.SOUTH) {
|
||||
if (hitX < 0.5) {
|
||||
return DoorHinge.LEFT;
|
||||
} else {
|
||||
return DoorHinge.RIGHT;
|
||||
}
|
||||
}
|
||||
else if (ctx.getHorizontalPlayerFacing().getOpposite() == Direction.NORTH) {
|
||||
if (hitX < 0.5) {
|
||||
return DoorHinge.RIGHT;
|
||||
} else {
|
||||
return DoorHinge.LEFT;
|
||||
}
|
||||
}
|
||||
else if (ctx.getHorizontalPlayerFacing().getOpposite() == Direction.WEST) {
|
||||
if (hitZ > 0.5) {
|
||||
return DoorHinge.RIGHT;
|
||||
} else {
|
||||
return DoorHinge.LEFT;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (hitZ < 0.5) {
|
||||
return DoorHinge.RIGHT;
|
||||
} else {
|
||||
return DoorHinge.LEFT;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos, boolean notify) {
|
||||
BlockState above = world.getBlockState(pos.up());
|
||||
BlockState below = world.getBlockState(pos.down());
|
||||
boolean waterlogged = world.getFluidState(pos).getFluid() == Fluids.WATER;
|
||||
int window_type = 0;
|
||||
int broken_glass_type = 0;
|
||||
if (((can_be_connected(below) && !below.get(CLOSED)) && below.get(FACING) == state.get(FACING)) && ((can_be_connected(above) && !above.get(CLOSED)) && above.get(FACING) == state.get(FACING))) {
|
||||
if (!state.get(CLOSED)) {
|
||||
window_type = 2;
|
||||
}
|
||||
} else if (((can_be_connected(below) && !below.get(CLOSED)) && below.get(FACING) == state.get(FACING)) && (!(can_be_connected(above)) || above.get(CLOSED))) {
|
||||
if (!state.get(CLOSED)) {
|
||||
window_type = 3;
|
||||
}
|
||||
} else if ((!(can_be_connected(below)) || below.get(CLOSED)) && ((can_be_connected(above) && !above.get(CLOSED)) && above.get(FACING) == state.get(FACING))) {
|
||||
if (!state.get(CLOSED)) {
|
||||
window_type = 1;
|
||||
}
|
||||
}
|
||||
if (((can_be_connected(below) && bottom_connected(below)) && below.get(FACING) == state.get(FACING)) && ((can_be_connected(above) && top_connected(above)) && above.get(FACING) == state.get(FACING))) {
|
||||
if (state.get(BROKEN)) {
|
||||
if (!below.get(BROKEN) && window_type != 0 && !above.get(BROKEN)) {
|
||||
broken_glass_type = 3;
|
||||
}
|
||||
else if (!below.get(BROKEN) && window_type != 1 && above.get(BROKEN)) {
|
||||
broken_glass_type = 1;
|
||||
}
|
||||
else if (below.get(BROKEN) && window_type != 3 && !above.get(BROKEN)) {
|
||||
broken_glass_type = 2;
|
||||
}
|
||||
}
|
||||
} else if (((can_be_connected(below) && bottom_connected(below)) && below.get(FACING) == state.get(FACING)) && (!(can_be_connected(above)) || !top_connected(above))) {
|
||||
if (state.get(BROKEN)) {
|
||||
if (!below.get(BROKEN) && state.get(WINDOW_TYPE) != 1) {
|
||||
broken_glass_type = 1;
|
||||
}
|
||||
}
|
||||
} else if ((!(can_be_connected(below)) || !bottom_connected(below)) && ((can_be_connected(above) && top_connected(above)) && above.get(FACING) == state.get(FACING))) {
|
||||
if (state.get(BROKEN)) {
|
||||
if (!above.get(BROKEN) && state.get(WINDOW_TYPE) != 3) {
|
||||
broken_glass_type = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
BlockState updatedBlockState = state;
|
||||
if (!state.get(CLOSED)) {
|
||||
updatedBlockState = state
|
||||
.with(WINDOW_TYPE, window_type)
|
||||
.with(WATERLOGGED, waterlogged)
|
||||
.with(BROKEN_GLASS_TYPE, broken_glass_type);
|
||||
} else {
|
||||
int window_type_closed = state.get(WINDOW_TYPE);
|
||||
if (window_type_closed == 1 && !(can_be_connected(above))) {window_type_closed=0;}
|
||||
else if (window_type_closed == 3 && !(can_be_connected(below))) {window_type_closed=0;}
|
||||
else if (window_type_closed == 2) {
|
||||
if (!(can_be_connected(above)) && !(can_be_connected(below))) {
|
||||
window_type_closed = 0;
|
||||
} else if (!(can_be_connected(below))) {
|
||||
window_type_closed = 1;
|
||||
} else if (!(can_be_connected(above))) {
|
||||
window_type_closed = 3;
|
||||
}
|
||||
}
|
||||
updatedBlockState = state
|
||||
.with(WINDOW_TYPE, window_type_closed)
|
||||
.with(WATERLOGGED, waterlogged)
|
||||
.with(BROKEN_GLASS_TYPE, broken_glass_type);
|
||||
}
|
||||
world.setBlockState(pos, updatedBlockState);
|
||||
|
||||
}
|
||||
|
||||
public FluidState getFluidState(BlockState state) {
|
||||
return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
|
||||
}
|
||||
|
||||
public boolean bottom_connected(BlockState state) {
|
||||
int type = state.get(WINDOW_TYPE);
|
||||
if (type == 0 || type == 3) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean top_connected(BlockState state) {
|
||||
int type = state.get(WINDOW_TYPE);
|
||||
if (type == 0 || type == 1) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean can_be_connected(BlockState state) {
|
||||
return state.getBlock() instanceof WindowBlock;
|
||||
}
|
||||
|
||||
static {
|
||||
SHAPE = new Shapes.HorizontalShape(List.of(List.of(0.0, 0.0, 13.0, 16.0, 16.0, 15.99)));
|
||||
FRAME_SHAPE_BOTTOM = new Shapes.HorizontalShape(List.of(List.of(0.0, 0.0, 13.0, 16.0, 2.0, 15.99)));
|
||||
FRAME_SHAPE_TOP = new Shapes.HorizontalShape(List.of(List.of(0.0, 14.0, 13.0, 16.0, 16.0, 15.99)));
|
||||
FRAME_SHAPE_RIGHT = new Shapes.HorizontalShape(List.of(List.of(0.0, 0.0, 13.0, 2.0, 16.0, 15.99)));
|
||||
FRAME_SHAPE_LEFT = new Shapes.HorizontalShape(List.of(List.of(14.0, 0.0, 13.0, 16.0, 16.0, 15.99)));
|
||||
PANE_FRAME_SHAPE = new Shapes.HorizontalShape(List.of(List.of(2.0, 7.0, 13.5, 14.0, 8.0, 15.5)));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue