Initially add changes, god this will take a while

This commit is contained in:
Andrew-71 2023-08-13 22:25:32 +03:00
parent b43a0668aa
commit 0fad36a08c
272 changed files with 3438 additions and 197 deletions

View file

@ -1,6 +1,8 @@
package su.a71.new_soviet.blocks;
import net.minecraft.block.*;
import net.minecraft.particle.DustParticleEffect;
import net.minecraft.text.Text;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.fluid.FluidState;
@ -25,6 +27,7 @@ import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
import org.jetbrains.annotations.Nullable;
import su.a71.new_soviet.NewSoviet;
import su.a71.new_soviet.registration.NSE_Custom;
import su.a71.new_soviet.registration.NSE_Items;
@ -70,15 +73,28 @@ public class LightBulbBlock extends Block implements Waterloggable {
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (!world.isClient && state.get(BROKEN) && player.getInventory().getMainHandStack().getItem() == NSE_Items.LIGHT_BULB) {
if (!world.isClient && state.get(BROKEN) && player.getInventory().getMainHandStack().getItem() == NSE_Items.LIGHT_BULB && !world.isReceivingRedstonePower(pos)) {
if (!player.isCreative())
player.getInventory().getMainHandStack().decrement(1);
world.setBlockState(pos, (BlockState)state.with(BROKEN, false)
.with(ON, world.isReceivingRedstonePower(pos)), 2);
world.setBlockState(pos, (BlockState)state.with(BROKEN, false));
//.with(ON, world.isReceivingRedstonePower(pos)), 2);
} else if (!world.isClient && state.get(BROKEN) && player.getInventory().getMainHandStack().getItem() == NSE_Items.LIGHT_BULB) {
player.sendMessage(Text.translatable("block.new_soviet.light_bulb_block.energized"));
world.playSound((PlayerEntity)null, pos.getX(), pos.getY(), pos.getZ(), NSE_Custom.ELECTRIC_HIT, SoundCategory.AMBIENT, 0.8f, 1f);
if (!player.isCreative()) {
player.heal(-1 * NewSoviet.RANDOM.nextBetween(1, 4));
}
if (NewSoviet.RANDOM.nextBetween(1, 32) == 1){
if (!player.isCreative())
player.getInventory().getMainHandStack().decrement(1);
world.setBlockState(pos, (BlockState)state.with(BROKEN, false)
.with(ON, world.isReceivingRedstonePower(pos)), 2);
}
}
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)) {

View file

@ -0,0 +1,115 @@
package su.a71.new_soviet.blocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.*;
import net.minecraft.block.enums.WallMountLocation;
import net.minecraft.block.piston.PistonBehavior;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.particle.DustParticleEffect;
import net.minecraft.sound.BlockSoundGroup;
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.Properties;
import net.minecraft.util.ActionResult;
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.math.random.Random;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
import net.minecraft.world.event.GameEvent;
import su.a71.new_soviet.NewSoviet;
import su.a71.new_soviet.sounds.Sounds;
public class SwitchBlock extends LeverBlock {
public static final BooleanProperty POWERED = Properties.POWERED;
protected static final VoxelShape NORTH_WALL_SHAPE = Block.createCuboidShape(5.5, 5.5, 15, 10.5, 10.5, 16);
protected static final VoxelShape SOUTH_WALL_SHAPE = Block.createCuboidShape(5.5, 5.5, 0, 10.5, 10.5, 1);
protected static final VoxelShape WEST_WALL_SHAPE = Block.createCuboidShape(15, 5.5, 5.5, 16, 10.5, 10.5);
protected static final VoxelShape EAST_WALL_SHAPE = Block.createCuboidShape(0.0, 5.5, 5.5, 1, 10.5, 10.5);
protected static final VoxelShape FLOOR_Z_AXIS_SHAPE = Block.createCuboidShape(5.5, 0.0, 5.5, 10.5, 1, 10.5);
protected static final VoxelShape FLOOR_X_AXIS_SHAPE = Block.createCuboidShape(5.5, 0.0, 5.5, 10.5, 1, 10.5);
protected static final VoxelShape CEILING_Z_AXIS_SHAPE = Block.createCuboidShape(5.5, 15.0, 5.5, 10.5, 16.0, 10.5);
protected static final VoxelShape CEILING_X_AXIS_SHAPE = Block.createCuboidShape(5.5, 15.0, 5.5, 10.5, 16.0, 10.5);
public SwitchBlock(FabricBlockSettings fabricBlockSettings) {
super(FabricBlockSettings.create().sounds(BlockSoundGroup.METAL).notSolid().pistonBehavior(PistonBehavior.DESTROY).strength(1f, 2f).mapColor(MapColor.TERRACOTTA_WHITE).noCollision());
this.setDefaultState((BlockState)((BlockState)((BlockState)((BlockState)this.stateManager.getDefaultState()).with(FACING, Direction.NORTH)).with(POWERED, false)).with(FACE, WallMountLocation.WALL));
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
switch ((WallMountLocation)state.get(FACE)) {
case FLOOR: {
switch (state.get(FACING).getAxis()) {
case X: {
return FLOOR_X_AXIS_SHAPE;
}
}
return FLOOR_Z_AXIS_SHAPE;
}
case WALL: {
switch (state.get(FACING)) {
case EAST: {
return EAST_WALL_SHAPE;
}
case WEST: {
return WEST_WALL_SHAPE;
}
case SOUTH: {
return SOUTH_WALL_SHAPE;
}
}
return NORTH_WALL_SHAPE;
}
}
switch (state.get(FACING).getAxis()) {
case X: {
return CEILING_X_AXIS_SHAPE;
}
}
return CEILING_Z_AXIS_SHAPE;
}
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (world.isClient) {
BlockState blockState = (BlockState)state.cycle(POWERED);
return ActionResult.SUCCESS;
}
BlockState blockState = this.togglePower(state, world, pos);
float f = blockState.get(POWERED) != false ? 1f : 0.9f;
world.playSound(null, pos, Sounds.SWITCH_PRESS, SoundCategory.BLOCKS, 0.6f, f);
world.emitGameEvent((Entity)player, blockState.get(POWERED) != false ? GameEvent.BLOCK_ACTIVATE : GameEvent.BLOCK_DEACTIVATE, pos);
return ActionResult.CONSUME;
}
private static void spawnParticles(BlockState state, WorldAccess world, BlockPos pos, float alpha) {
Direction direction = state.get(FACING).getOpposite();
Direction direction2 = SwitchBlock.getDirection(state).getOpposite();
double d = (double)pos.getX() + 0.5 + 0.1 * (double)direction.getOffsetX() + 0.2 * (double)direction2.getOffsetX();
double e = (double)pos.getY() + 0.5 + 0.1 * (double)direction.getOffsetY() + 0.2 * (double)direction2.getOffsetY();
double f = (double)pos.getZ() + 0.5 + 0.1 * (double)direction.getOffsetZ() + 0.2 * (double)direction2.getOffsetZ();
world.addParticle(new DustParticleEffect(DustParticleEffect.RED, alpha), d, e, f, 0.0, 0.0, 0.0);
}
@Override
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
if (state.get(POWERED).booleanValue() && random.nextFloat() < 0.25f) {
//SwitchBlock.spawnParticles(state, world, pos, 0.5f);
}
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(FACE, FACING, POWERED);
}
}