You can now stomp apple pies. You monster

This commit is contained in:
Sollace 2022-09-30 00:23:16 +02:00
parent 3839a3e17f
commit e1659c32b2
11 changed files with 146 additions and 18 deletions

View file

@ -8,18 +8,18 @@ import net.minecraft.world.World;
public class AwaitTickQueue {
public static void scheduleTask(World reference, Consumer<World> task, int ticksLater) {
if (reference instanceof ServerWorld) {
if (reference instanceof ServerWorld serverWorld) {
CompletableFuture.runAsync(() -> {
task.accept(reference);
}, CompletableFuture.delayedExecutor(ticksLater * 100, TimeUnit.MILLISECONDS, reference.getServer()));
task.accept(serverWorld);
}, CompletableFuture.delayedExecutor(ticksLater * 100, TimeUnit.MILLISECONDS, serverWorld.getServer()));
}
}
public static void scheduleTask(World reference, Consumer<World> task) {
if (reference instanceof ServerWorld) {
if (reference instanceof ServerWorld serverWorld) {
CompletableFuture.runAsync(() -> {
task.accept(reference);
}, reference.getServer());
task.accept(serverWorld);
}, serverWorld.getServer());
}
}
}

View file

@ -0,0 +1,18 @@
package com.minelittlepony.unicopia;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.event.GameEvent;
public interface UGameEvents {
GameEvent PIE_STOMP = register("pie_stomp", 5);
static GameEvent register(String name, int range) {
Identifier id = Unicopia.id(name);
return Registry.register(Registry.GAME_EVENT, id, new GameEvent(id.toString(), range));
}
static void bootstrap() {
}
}

View file

@ -72,6 +72,7 @@ public class Unicopia implements ModInitializer {
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(StateMapLoader.INSTANCE);
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(SpellbookChapterLoader.INSTANCE);
UGameEvents.bootstrap();
UBlocks.bootstrap();
UItems.bootstrap();
UPotions.bootstrap();

View file

@ -1,27 +1,37 @@
package com.minelittlepony.unicopia.block;
import com.minelittlepony.unicopia.AwaitTickQueue;
import com.minelittlepony.unicopia.UGameEvents;
import com.minelittlepony.unicopia.util.SoundEmitter;
import net.minecraft.block.*;
import net.minecraft.entity.Entity;
import net.minecraft.entity.ai.pathing.NavigationType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.*;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.sound.SoundEvents;
import net.minecraft.stat.Stats;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.IntProperty;
import net.minecraft.state.property.*;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.*;
import net.minecraft.util.math.random.Random;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.*;
import net.minecraft.world.event.GameEvent;
public class PieBlock extends Block {
public class PieBlock extends Block implements Waterloggable {
public static final int MAX_BITES = 3;
public static final IntProperty BITES = IntProperty.of("bites", 0, MAX_BITES);
public static final BooleanProperty STOMPED = BooleanProperty.of("stomped");
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
private static final VoxelShape[] SHAPES;
static {
final int PIE_HEIGHT = 5;
@ -37,7 +47,7 @@ public class PieBlock extends Block {
public PieBlock(Settings settings) {
super(settings);
setDefaultState(getDefaultState().with(BITES, 0));
setDefaultState(getDefaultState().with(STOMPED, false).with(WATERLOGGED, false));
}
@Deprecated
@ -69,10 +79,15 @@ public class PieBlock extends Block {
return ActionResult.PASS;
}
player.incrementStat(Stats.EAT_CAKE_SLICE);
player.getHungerManager().add(2, 0.1f);
player.getHungerManager().add(state.get(STOMPED) ? 1 : 2, 0.1f);
int bites = state.get(BITES);
world.emitGameEvent(player, GameEvent.EAT, pos);
SoundEmitter.playSoundAt(player, SoundEvents.ENTITY_PLAYER_BURP, 0.5F, world.getRandom().nextFloat() * 0.1F + 0.9F);
SoundEmitter.playSoundAt(player, SoundEvents.ENTITY_GENERIC_EAT, 0.5F, world.getRandom().nextFloat() * 0.1F + 0.9F);
if (world instanceof World ww && (!player.canConsume(false) || world.getRandom().nextInt(10) == 0)) {
AwaitTickQueue.scheduleTask(ww, w -> {
SoundEmitter.playSoundAt(player, SoundEvents.ENTITY_PLAYER_BURP, 0.5F, world.getRandom().nextFloat() * 0.1F + 0.9F);
}, 5);
}
if (bites < MAX_BITES) {
world.setBlockState(pos, state.with(BITES, bites + 1), Block.NOTIFY_ALL);
@ -83,24 +98,78 @@ public class PieBlock extends Block {
return ActionResult.SUCCESS;
}
@Override
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
if (state.get(STOMPED)) {
Vec3d center = Vec3d.ofCenter(pos);
world.addParticle(ParticleTypes.SNEEZE,
random.nextTriangular(center.getX(), 0.9),
random.nextTriangular(center.getY(), 0.9),
random.nextTriangular(center.getZ(), 0.9),
0,
0,
0
);
} else {
if (world.random.nextInt(10) == 0) {
Vec3d center = Vec3d.ofCenter(pos);
world.addParticle(ParticleTypes.SNEEZE,
random.nextTriangular(center.getX(), 0.2),
random.nextTriangular(center.getY(), 0.2),
random.nextTriangular(center.getZ(), 0.2),
0,
0.01F,
0
);
}
}
}
@Override
public void onSteppedOn(World world, BlockPos pos, BlockState state, Entity entity) {
if (!state.get(STOMPED)) {
world.setBlockState(pos, state.cycle(STOMPED));
world.syncWorldEvent(WorldEvents.BLOCK_BROKEN, pos, Block.getRawIdFromState(state));
world.emitGameEvent(UGameEvents.PIE_STOMP, pos, GameEvent.Emitter.of(entity, state));
}
}
@Deprecated
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (direction == Direction.DOWN && !state.canPlaceAt(world, pos)) {
return Blocks.AIR.getDefaultState();
}
if (state.get(WATERLOGGED)) {
world.createAndScheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
}
return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
}
@Deprecated
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
return world.getBlockState(pos.down()).getMaterial().isSolid();
return world.getBlockState(pos.down()).isSideSolidFullSquare(world, pos, Direction.UP);
}
@Deprecated
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return super.getDefaultState().with(WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).getFluid() == Fluids.WATER);
}
@Deprecated
@Override
public FluidState getFluidState(BlockState state) {
if (state.get(WATERLOGGED)) {
return Fluids.WATER.getStill(false);
}
return super.getFluidState(state);
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(BITES);
builder.add(BITES, STOMPED, WATERLOGGED);
}
@Override

View file

@ -66,7 +66,7 @@ public interface UBlocks {
Block SOUR_APPLE = register("sour_apple", new FruitBlock(FabricBlockSettings.of(Material.GOURD, MapColor.GREEN).sounds(BlockSoundGroup.WOOD), Direction.DOWN, SOUR_APPLE_LEAVES, FruitBlock.DEFAULT_SHAPE));
Block SOUR_APPLE_SPROUT = register("sour_apple_sprout", new SproutBlock(0xE5FFCC88, () -> UItems.SOUR_APPLE_SEEDS, () -> UTreeGen.SOUR_APPLE_TREE.sapling().map(Block::getDefaultState).get()));
Block APPLE_PIE = register("apple_pie", new PieBlock(FabricBlockSettings.of(Material.CAKE, MapColor.ORANGE).strength(0.5F).sounds(BlockSoundGroup.WOOL)));
Block APPLE_PIE = register("apple_pie", new PieBlock(FabricBlockSettings.of(Material.CAKE, MapColor.ORANGE).strength(0.5F).sounds(BlockSoundGroup.WET_GRASS)));
SegmentedCropBlock OATS = register("oats", SegmentedCropBlock.create(11, 5, AbstractBlock.Settings.copy(Blocks.WHEAT), () -> UItems.OAT_SEEDS, null, () -> UBlocks.OATS_STEM));
SegmentedCropBlock OATS_STEM = register("oats_stem", OATS.createNext(5));

View file

@ -1,8 +1,12 @@
{
"variants": {
"bites=0": { "model": "unicopia:block/apple_pie" },
"bites=1": { "model": "unicopia:block/apple_pie_elbow" },
"bites=2": { "model": "unicopia:block/apple_pie_straight" },
"bites=3": { "model": "unicopia:block/apple_pie_corner" }
"bites=0,stomped=false": { "model": "unicopia:block/apple_pie" },
"bites=1,stomped=false": { "model": "unicopia:block/apple_pie_elbow" },
"bites=2,stomped=false": { "model": "unicopia:block/apple_pie_straight" },
"bites=3,stomped=false": { "model": "unicopia:block/apple_pie_corner" },
"bites=0,stomped=true": { "model": "unicopia:block/stomped_apple_pie" },
"bites=1,stomped=true": { "model": "unicopia:block/stomped_apple_pie_elbow" },
"bites=2,stomped=true": { "model": "unicopia:block/stomped_apple_pie_straight" },
"bites=3,stomped=true": { "model": "unicopia:block/stomped_apple_pie_corner" }
}
}

View file

@ -0,0 +1,9 @@
{
"parent": "unicopia:block/pie_full",
"textures": {
"top": "unicopia:block/apple_pie_top_stomped",
"bottom": "unicopia:block/apple_pie_bottom",
"sides": "unicopia:block/apple_pie_side",
"inner": "unicopia:block/apple_pie_inner"
}
}

View file

@ -0,0 +1,9 @@
{
"parent": "unicopia:block/pie_corner",
"textures": {
"top": "unicopia:block/apple_pie_top_stomped",
"bottom": "unicopia:block/apple_pie_bottom",
"sides": "unicopia:block/apple_pie_side",
"inner": "unicopia:block/apple_pie_inner"
}
}

View file

@ -0,0 +1,9 @@
{
"parent": "unicopia:block/pie_elbow",
"textures": {
"top": "unicopia:block/apple_pie_top_stomped",
"bottom": "unicopia:block/apple_pie_bottom",
"sides": "unicopia:block/apple_pie_side",
"inner": "unicopia:block/apple_pie_inner"
}
}

View file

@ -0,0 +1,9 @@
{
"parent": "unicopia:block/pie_straight",
"textures": {
"top": "unicopia:block/apple_pie_top_stomped",
"bottom": "unicopia:block/apple_pie_bottom",
"sides": "unicopia:block/apple_pie_side",
"inner": "unicopia:block/apple_pie_inner"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB