mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-07 22:16:44 +01:00
You can now stomp apple pies. You monster
This commit is contained in:
parent
3839a3e17f
commit
e1659c32b2
11 changed files with 146 additions and 18 deletions
|
@ -8,18 +8,18 @@ import net.minecraft.world.World;
|
||||||
|
|
||||||
public class AwaitTickQueue {
|
public class AwaitTickQueue {
|
||||||
public static void scheduleTask(World reference, Consumer<World> task, int ticksLater) {
|
public static void scheduleTask(World reference, Consumer<World> task, int ticksLater) {
|
||||||
if (reference instanceof ServerWorld) {
|
if (reference instanceof ServerWorld serverWorld) {
|
||||||
CompletableFuture.runAsync(() -> {
|
CompletableFuture.runAsync(() -> {
|
||||||
task.accept(reference);
|
task.accept(serverWorld);
|
||||||
}, CompletableFuture.delayedExecutor(ticksLater * 100, TimeUnit.MILLISECONDS, reference.getServer()));
|
}, CompletableFuture.delayedExecutor(ticksLater * 100, TimeUnit.MILLISECONDS, serverWorld.getServer()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void scheduleTask(World reference, Consumer<World> task) {
|
public static void scheduleTask(World reference, Consumer<World> task) {
|
||||||
if (reference instanceof ServerWorld) {
|
if (reference instanceof ServerWorld serverWorld) {
|
||||||
CompletableFuture.runAsync(() -> {
|
CompletableFuture.runAsync(() -> {
|
||||||
task.accept(reference);
|
task.accept(serverWorld);
|
||||||
}, reference.getServer());
|
}, serverWorld.getServer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
18
src/main/java/com/minelittlepony/unicopia/UGameEvents.java
Normal file
18
src/main/java/com/minelittlepony/unicopia/UGameEvents.java
Normal 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() {
|
||||||
|
}
|
||||||
|
}
|
|
@ -72,6 +72,7 @@ public class Unicopia implements ModInitializer {
|
||||||
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(StateMapLoader.INSTANCE);
|
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(StateMapLoader.INSTANCE);
|
||||||
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(SpellbookChapterLoader.INSTANCE);
|
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(SpellbookChapterLoader.INSTANCE);
|
||||||
|
|
||||||
|
UGameEvents.bootstrap();
|
||||||
UBlocks.bootstrap();
|
UBlocks.bootstrap();
|
||||||
UItems.bootstrap();
|
UItems.bootstrap();
|
||||||
UPotions.bootstrap();
|
UPotions.bootstrap();
|
||||||
|
|
|
@ -1,27 +1,37 @@
|
||||||
package com.minelittlepony.unicopia.block;
|
package com.minelittlepony.unicopia.block;
|
||||||
|
|
||||||
|
import com.minelittlepony.unicopia.AwaitTickQueue;
|
||||||
|
import com.minelittlepony.unicopia.UGameEvents;
|
||||||
import com.minelittlepony.unicopia.util.SoundEmitter;
|
import com.minelittlepony.unicopia.util.SoundEmitter;
|
||||||
|
|
||||||
import net.minecraft.block.*;
|
import net.minecraft.block.*;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.ai.pathing.NavigationType;
|
import net.minecraft.entity.ai.pathing.NavigationType;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.fluid.FluidState;
|
||||||
|
import net.minecraft.fluid.Fluids;
|
||||||
import net.minecraft.item.*;
|
import net.minecraft.item.*;
|
||||||
|
import net.minecraft.particle.ParticleTypes;
|
||||||
import net.minecraft.sound.SoundEvents;
|
import net.minecraft.sound.SoundEvents;
|
||||||
import net.minecraft.stat.Stats;
|
import net.minecraft.stat.Stats;
|
||||||
import net.minecraft.state.StateManager;
|
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.ActionResult;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.hit.BlockHitResult;
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
import net.minecraft.util.math.*;
|
import net.minecraft.util.math.*;
|
||||||
|
import net.minecraft.util.math.random.Random;
|
||||||
import net.minecraft.util.shape.VoxelShape;
|
import net.minecraft.util.shape.VoxelShape;
|
||||||
import net.minecraft.util.shape.VoxelShapes;
|
import net.minecraft.util.shape.VoxelShapes;
|
||||||
import net.minecraft.world.*;
|
import net.minecraft.world.*;
|
||||||
import net.minecraft.world.event.GameEvent;
|
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 int MAX_BITES = 3;
|
||||||
public static final IntProperty BITES = IntProperty.of("bites", 0, MAX_BITES);
|
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;
|
private static final VoxelShape[] SHAPES;
|
||||||
static {
|
static {
|
||||||
final int PIE_HEIGHT = 5;
|
final int PIE_HEIGHT = 5;
|
||||||
|
@ -37,7 +47,7 @@ public class PieBlock extends Block {
|
||||||
|
|
||||||
public PieBlock(Settings settings) {
|
public PieBlock(Settings settings) {
|
||||||
super(settings);
|
super(settings);
|
||||||
setDefaultState(getDefaultState().with(BITES, 0));
|
setDefaultState(getDefaultState().with(STOMPED, false).with(WATERLOGGED, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
@ -69,10 +79,15 @@ public class PieBlock extends Block {
|
||||||
return ActionResult.PASS;
|
return ActionResult.PASS;
|
||||||
}
|
}
|
||||||
player.incrementStat(Stats.EAT_CAKE_SLICE);
|
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);
|
int bites = state.get(BITES);
|
||||||
world.emitGameEvent(player, GameEvent.EAT, pos);
|
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) {
|
if (bites < MAX_BITES) {
|
||||||
world.setBlockState(pos, state.with(BITES, bites + 1), Block.NOTIFY_ALL);
|
world.setBlockState(pos, state.with(BITES, bites + 1), Block.NOTIFY_ALL);
|
||||||
|
@ -83,24 +98,78 @@ public class PieBlock extends Block {
|
||||||
return ActionResult.SUCCESS;
|
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
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
|
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
|
||||||
if (direction == Direction.DOWN && !state.canPlaceAt(world, pos)) {
|
if (direction == Direction.DOWN && !state.canPlaceAt(world, pos)) {
|
||||||
return Blocks.AIR.getDefaultState();
|
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);
|
return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
|
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
|
@Override
|
||||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||||
builder.add(BITES);
|
builder.add(BITES, STOMPED, WATERLOGGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -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 = 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 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 = 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));
|
SegmentedCropBlock OATS_STEM = register("oats_stem", OATS.createNext(5));
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
{
|
{
|
||||||
"variants": {
|
"variants": {
|
||||||
"bites=0": { "model": "unicopia:block/apple_pie" },
|
"bites=0,stomped=false": { "model": "unicopia:block/apple_pie" },
|
||||||
"bites=1": { "model": "unicopia:block/apple_pie_elbow" },
|
"bites=1,stomped=false": { "model": "unicopia:block/apple_pie_elbow" },
|
||||||
"bites=2": { "model": "unicopia:block/apple_pie_straight" },
|
"bites=2,stomped=false": { "model": "unicopia:block/apple_pie_straight" },
|
||||||
"bites=3": { "model": "unicopia:block/apple_pie_corner" }
|
"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" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
|
@ -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 |
Loading…
Reference in a new issue