Skip to content

Commit

Permalink
Reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugman76 committed Sep 30, 2024
1 parent 8c05ab2 commit abbd053
Show file tree
Hide file tree
Showing 17 changed files with 388 additions and 406 deletions.
1 change: 0 additions & 1 deletion src/main/java/fr/hugman/mubble/Mubble.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import fr.hugman.mubble.sound.MubbleSounds;
import fr.hugman.mubble.world.MubbleGamerules;
import net.fabricmc.api.ModInitializer;
import net.minecraft.block.Blocks;
import net.minecraft.util.Identifier;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down
108 changes: 54 additions & 54 deletions src/main/java/fr/hugman/mubble/block/BumpableDropMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,58 @@
import net.minecraft.util.StringIdentifiable;

public enum BumpableDropMode implements StringIdentifiable {
ALL(0, "all"),
ONE(1, "one");

public static final Codec<BumpableDropMode> CODEC = StringIdentifiable.createCodec(BumpableDropMode::values);
private final int index;
private final String id;
private final Text name;
private final Text description;

BumpableDropMode(int index, String id) {
this.index = index;
this.id = id;
this.name = Text.translatable("block.mubble.bumpable.drop." + id);
this.description = Text.translatable("block.mubble.bumpable.drop." + id + ".description");
}

public static BumpableDropMode get(int index) {
for(BumpableDropMode mode : values()) {
if(mode.index == index) {
return mode;
}
}
return ALL;
}

public static BumpableDropMode get(String s) {
for(BumpableDropMode mode : values()) {
if(mode.id.equals(s)) {
return mode;
}
}
return ALL;
}

public BumpableDropMode next() {
return get((index + 1) % values().length);
}

public int getIndex() {
return index;
}

public Text getName() {
return name;
}

public Text getDescription() {
return description;
}

@Override
public String asString() {
return this.id;
}
ALL(0, "all"),
ONE(1, "one");

public static final Codec<BumpableDropMode> CODEC = StringIdentifiable.createCodec(BumpableDropMode::values);
private final int index;
private final String id;
private final Text name;
private final Text description;

BumpableDropMode(int index, String id) {
this.index = index;
this.id = id;
this.name = Text.translatable("block.mubble.bumpable.drop." + id);
this.description = Text.translatable("block.mubble.bumpable.drop." + id + ".description");
}

public static BumpableDropMode get(int index) {
for (BumpableDropMode mode : values()) {
if (mode.index == index) {
return mode;
}
}
return ALL;
}

public static BumpableDropMode get(String s) {
for (BumpableDropMode mode : values()) {
if (mode.id.equals(s)) {
return mode;
}
}
return ALL;
}

public BumpableDropMode next() {
return get((index + 1) % values().length);
}

public int getIndex() {
return index;
}

public Text getName() {
return name;
}

public Text getDescription() {
return description;
}

@Override
public String asString() {
return this.id;
}
}
103 changes: 51 additions & 52 deletions src/main/java/fr/hugman/mubble/block/DecoratedBumpableBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.mojang.serialization.codecs.RecordCodecBuilder;
import fr.hugman.mubble.block.entity.BumpableBlockEntity;
import fr.hugman.mubble.sound.MubbleSounds;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
Expand All @@ -28,64 +27,64 @@
* @since v4.0.0
*/
public class DecoratedBumpableBlock extends BumpableBlock {
public static final MapCodec<DecoratedBumpableBlock> CODEC = RecordCodecBuilder.mapCodec((instance) -> instance.group(
BlockState.CODEC.fieldOf("default_bumped_state").forGetter((block) -> block.defaultBumpedState),
createSettingsCodec()
).apply(instance, DecoratedBumpableBlock::new));
public static final MapCodec<DecoratedBumpableBlock> CODEC = RecordCodecBuilder.mapCodec((instance) -> instance.group(
BlockState.CODEC.fieldOf("default_bumped_state").forGetter((block) -> block.defaultBumpedState),
createSettingsCodec()
).apply(instance, DecoratedBumpableBlock::new));

public DecoratedBumpableBlock(@Nullable BlockState defaultBumpedState, Settings settings) {
super(defaultBumpedState, settings);
}
public DecoratedBumpableBlock(@Nullable BlockState defaultBumpedState, Settings settings) {
super(defaultBumpedState, settings);
}

public static Function<Settings, DecoratedBumpableBlock> of(BlockState defaultBumpedState) {
return s -> new DecoratedBumpableBlock(defaultBumpedState, s);
}
public static Function<Settings, DecoratedBumpableBlock> of(BlockState defaultBumpedState) {
return s -> new DecoratedBumpableBlock(defaultBumpedState, s);
}

public static Function<Settings, DecoratedBumpableBlock> of(Block block) {
return s -> new DecoratedBumpableBlock(block.getDefaultState(), s);
}
public static Function<Settings, DecoratedBumpableBlock> of(Block block) {
return s -> new DecoratedBumpableBlock(block.getDefaultState(), s);
}

@Override
protected MapCodec<? extends DecoratedBumpableBlock> getCodec() {
return CODEC;
}
@Override
protected MapCodec<? extends DecoratedBumpableBlock> getCodec() {
return CODEC;
}

@Override
public void onBump(World world, BlockPos pos, BlockState state, BumpableBlockEntity blockEntity) {
super.onBump(world, pos, state, blockEntity);
this.playGenericBumpSound(blockEntity);
}
@Override
public void onBump(World world, BlockPos pos, BlockState state, BumpableBlockEntity blockEntity) {
super.onBump(world, pos, state, blockEntity);
this.playGenericBumpSound(blockEntity);
}

@Override
public void onBumpMiddle(World world, BlockPos pos, BlockState state, BumpableBlockEntity blockEntity) {
super.onBumpMiddle(world, pos, state, blockEntity);
if(blockEntity.getWorld() != null && blockEntity.getBumpDirection() == Direction.UP) {
this.launchEntitiesOnTop(blockEntity.getWorld(), blockEntity.getPos());
}
}
@Override
public void onBumpMiddle(World world, BlockPos pos, BlockState state, BumpableBlockEntity blockEntity) {
super.onBumpMiddle(world, pos, state, blockEntity);
if (blockEntity.getWorld() != null && blockEntity.getBumpDirection() == Direction.UP) {
this.launchEntitiesOnTop(blockEntity.getWorld(), blockEntity.getPos());
}
}

public void playGenericBumpSound(BumpableBlockEntity entity) {
World world = entity.getWorld();
Vec3d pos = entity.getPos().toCenterPos();
if(world != null) {
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), MubbleSounds.BUMPABLE_BLOCK_BUMP, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
}
public void playGenericBumpSound(BumpableBlockEntity entity) {
World world = entity.getWorld();
Vec3d pos = entity.getPos().toCenterPos();
if (world != null) {
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), MubbleSounds.BUMPABLE_BLOCK_BUMP, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
}

/**
* Launches entities on top of the block.
*/
public void launchEntitiesOnTop(World world, BlockPos pos) {
List<Entity> entities = world.getOtherEntities(null, new Box(pos.up()));
for(Entity entity : entities) {
launchEntity(entity);
}
}
/**
* Launches entities on top of the block.
*/
public void launchEntitiesOnTop(World world, BlockPos pos) {
List<Entity> entities = world.getOtherEntities(null, new Box(pos.up()));
for (Entity entity : entities) {
launchEntity(entity);
}
}

public void launchEntity(Entity entity) {
Vec3d vec3d = entity.getVelocity();
entity.setVelocity(vec3d.x, 0.3D, vec3d.z);
entity.velocityDirty = true;
// TODO: add a damage type and a gamerule for harming entities
}
public void launchEntity(Entity entity) {
Vec3d vec3d = entity.getVelocity();
entity.setVelocity(vec3d.x, 0.3D, vec3d.z);
entity.velocityDirty = true;
// TODO: add a damage type and a gamerule for harming entities
}
}
20 changes: 10 additions & 10 deletions src/main/java/fr/hugman/mubble/block/EmptyBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
* @since v4.0.0
*/
public class EmptyBlock extends Block implements HittableBlock {
public EmptyBlock(Settings settings) {
super(settings);
}
public EmptyBlock(Settings settings) {
super(settings);
}

@Override
public void onHit(World world, BlockState state, Entity entity, BlockHitResult hit) {
var pos = hit.getPos();
if(world != null) {
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), MubbleSounds.BUMPABLE_BLOCK_BUMP, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
}
@Override
public void onHit(World world, BlockState state, Entity entity, BlockHitResult hit) {
var pos = hit.getPos();
if (world != null) {
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), MubbleSounds.BUMPABLE_BLOCK_BUMP, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
}
}
5 changes: 2 additions & 3 deletions src/main/java/fr/hugman/mubble/block/HittableBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

//TODO: move this to the Dawn API
Expand All @@ -21,7 +20,7 @@
* @since v4.0.0
*/
public interface HittableBlock {
double HIT_Y_OFFSET = 0.001;
double HIT_Y_OFFSET = 0.001;

void onHit(World world, BlockState state, Entity entity, BlockHitResult hit);
void onHit(World world, BlockState state, Entity entity, BlockHitResult hit);
}
Loading

0 comments on commit abbd053

Please sign in to comment.