Remove unused files, simplify func in CigaretteItem

This commit is contained in:
Andrew-71 2024-03-12 21:47:45 +03:00
parent daef439632
commit 38446def2e
5 changed files with 8 additions and 74 deletions

View file

@ -76,6 +76,7 @@ Due to sheer amount of changes, some may be undocumented. We hope you enjoy this
* Added a questionable sound option
* At least 2 new advancements
* Bug fixes
* Added some missing crafting recipes
* Stone-cutting recipe for slabs now gives 2 blocks
* Fixed typos in Russian translation
* Fixed a few missing drops/tags/recipes related to concrete

View file

@ -1,66 +0,0 @@
package su.a71.new_soviet.blocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.piston.PistonBehavior;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.BlockMirror;
import net.minecraft.util.BlockRotation;
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 org.jetbrains.annotations.Nullable;
public class StoveBlock extends BlockWithEntity {
public static final DirectionProperty FACING;
public StoveBlock() {
super(FabricBlockSettings.create().sounds(BlockSoundGroup.METAL).notSolid().pistonBehavior(PistonBehavior.BLOCK));
setDefaultState(getDefaultState().with(Properties.HORIZONTAL_FACING, Direction.NORTH));
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(Properties.HORIZONTAL_FACING);
}
@Nullable
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return null;
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext ctx) {
return switch (state.get(FACING)) {
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();
};
}
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return super.getPlacementState(ctx).with(Properties.HORIZONTAL_FACING, ctx.getHorizontalPlayerFacing().getOpposite());
}
public BlockState rotate(BlockState state, BlockRotation rotation) {
return state.with(FACING, rotation.rotate(state.get(FACING)));
}
public BlockState mirror(BlockState state, BlockMirror mirror) {
return state.rotate(mirror.getRotation(state.get(FACING)));
}
static {
FACING = Properties.HORIZONTAL_FACING;
}
}

View file

@ -83,10 +83,11 @@ public class WindowBlock extends HorizontalFacingBlock {
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), NSE_Sounds.SCREWDRIVER_SOUND, SoundCategory.BLOCKS, 1.0f, (float)NewSoviet.RANDOM.nextBetween(8, 11) / 10);
if (!state.get(CLOSED)) {
player.sendMessage(Text.translatable("block.new_soviet.window.fixed").formatted(Formatting.BOLD), true);
} else if (state.get(CLOSED)) {
} else {
player.sendMessage(Text.translatable("block.new_soviet.window.unfixed").formatted(Formatting.BOLD), true);
}
world.setBlockState(pos, state.with(CLOSED, !state.get(CLOSED)), 2);
player.getItemCooldownManager().set(NSE_Items.SCREWDRIVER, 10);
player.incrementStat(Stats.USED.getOrCreateStat(NSE_Items.SCREWDRIVER));
return ActionResult.SUCCESS;
}

View file

@ -20,6 +20,7 @@ import su.a71.new_soviet.registration.NSE_Sounds;
import java.util.List;
// FIXME: 26.08.2023 This whole class is making my head hurt, fix!!!
// UPD 12.03.2024 Its *slightly* better at this point
public class CigaretteItem extends Item {
private final int durationInTicks;
private final Item returnedItem;
@ -45,16 +46,14 @@ public class CigaretteItem extends Item {
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
ItemStack itemStack = user.getStackInHand(hand);
if (user.getInventory().getStack(40).getItem() == Items.FLINT_AND_STEEL && user.getInventory().getMainHandStack().getDamage() == 0) {
if (itemStack.getItem() != this) return TypedActionResult.fail(itemStack); // This is stupid, but just in case
if (user.getOffHandStack().getItem() == Items.FLINT_AND_STEEL && !user.getMainHandStack().isDamaged()) {
world.playSound(user, BlockPos.ofFloored(user.getPos()), NSE_Sounds.CIGARETTE_START, SoundCategory.PLAYERS, 1.0f, 1.0f);
user.incrementStat(Stats.USED.getOrCreateStat(this));
itemStack.damage(1, user, e -> e.sendEquipmentBreakStatus(EquipmentSlot.OFFHAND));
return ItemUsage.consumeHeldItem(world, user, hand);
} else if (user.getInventory().getMainHandStack().getDamage() != 0) {
world.playSound(user, BlockPos.ofFloored(user.getPos()), NSE_Sounds.CIGARETTE_RESTART, SoundCategory.PLAYERS, 1.0f, 1.0f);
user.incrementStat(Stats.USED.getOrCreateStat(this));
return ItemUsage.consumeHeldItem(world, user, hand);
} else if (user.isCreative()) {
} else if (user.getInventory().getMainHandStack().isDamaged() || user.isCreative()) {
world.playSound(user, BlockPos.ofFloored(user.getPos()), NSE_Sounds.CIGARETTE_RESTART, SoundCategory.PLAYERS, 1.0f, 1.0f);
user.incrementStat(Stats.USED.getOrCreateStat(this));
return ItemUsage.consumeHeldItem(world, user, hand);
@ -96,7 +95,6 @@ public class CigaretteItem extends Item {
stack.damage(1, user, e -> e.sendEquipmentBreakStatus(!(user.getMainHandStack() == stack) ? EquipmentSlot.OFFHAND : EquipmentSlot.MAINHAND));
world.playSound(user, BlockPos.ofFloored(user.getPos()), NSE_Sounds.CIGARETTE_PAUSE, SoundCategory.PLAYERS, 1.0f, 1.0f);
} else if (stack.getDamage() >= (durationInTicks - 2)) {
user.equipStack((!(user.getMainHandStack() == stack) ? EquipmentSlot.OFFHAND : EquipmentSlot.MAINHAND), new ItemStack(returnedItem));
world.playSound(user, BlockPos.ofFloored(user.getPos()), NSE_Sounds.CIGARETTE_STOPPED, SoundCategory.PLAYERS, 1.0f, 1.0f);
}