Implement tillable, properly register the structures, move cloud blocks a "gas" package

This commit is contained in:
Sollace 2020-04-15 17:11:37 +02:00
parent 7a6b0aabb5
commit c8a216ef24
35 changed files with 194 additions and 254 deletions

View file

@ -2,7 +2,6 @@ package com.minelittlepony.unicopia;
import java.util.List; import java.util.List;
import com.minelittlepony.unicopia.block.ITillable;
import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.item.UItems;
import com.minelittlepony.unicopia.magic.spell.SpellRegistry; import com.minelittlepony.unicopia.magic.spell.SpellRegistry;
@ -10,30 +9,12 @@ import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.block.GrassBlock; import net.minecraft.block.GrassBlock;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
// TODO: forge events // TODO: forge events
public class BlockInteractions { public class BlockInteractions {
public boolean onBlockTilled(World world, BlockPos pos, PlayerEntity player, ItemStack hoe) {
BlockState state = world.getBlockState(pos);
if (!(state.getBlock() instanceof ITillable)) {
return false;
}
ITillable farm = ((ITillable)state.getBlock());
if (!farm.canBeTilled(hoe, player, world, state, pos)) {
return false;
}
world.setBlockState(pos, farm.getFarmlandState(hoe, player, world, state, pos));
return true;
}
public void addAuxiliaryDrops(World world, BlockState state, BlockPos pos, List<ItemStack> drops, int fortune) { public void addAuxiliaryDrops(World world, BlockState state, BlockPos pos, List<ItemStack> drops, int fortune) {
Block block = state.getBlock(); Block block = state.getBlock();

View file

@ -1,36 +0,0 @@
package com.minelittlepony.unicopia;
/*
package com.minelittlepony.unicopia.world;
import com.minelittlepony.unicopia.Unicopia;
import net.minecraft.util.ActionResult;
public class Hooks {
public static void onPlayerRightClickBlock(PlayerInteractEvent.RightClickBlock event) {
if (event.isCanceled()) {
return;
}
ActionResult result = UWorld.instance().getBlocks().onBlockInteract(
event.getWorld(), event.getWorld().getBlockState(event.getPos()), event.getPos(), event.getPlayerEntity(), event.getItemStack(), event.getFace(), event.getHand());
if (result != ActionResult.PASS) {
event.setCanceled(true);
event.setCancellationResult(result);
}
}
public static void onBlockHarvested(BlockEvent.HarvestDropsEvent event) {
UWorld.instance().getBlocks().addAuxiliaryDrops(event.getWorld(), event.getState(), event.getPos(), event.getDrops(), event.getFortuneLevel());
}
public static void onWorldTick(TickEvent.WorldTickEvent event) {
if (event.phase == Phase.START) {
UWorld.instance().onUpdate(event.world);
}
}
}
*/

View file

@ -4,7 +4,7 @@ import java.util.Optional;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.minelittlepony.unicopia.Config; import com.minelittlepony.unicopia.Config;
import com.minelittlepony.unicopia.ducks.IRaceContainerHolder; import com.minelittlepony.unicopia.ducks.RaceContainerHolder;
import com.minelittlepony.unicopia.entity.IEntity; import com.minelittlepony.unicopia.entity.IEntity;
import com.minelittlepony.unicopia.entity.player.IPlayer; import com.minelittlepony.unicopia.entity.player.IPlayer;
@ -63,14 +63,14 @@ public class SpeciesList {
@Nullable @Nullable
public <T extends IEntity> T getEntity(Entity entity) { public <T extends IEntity> T getEntity(Entity entity) {
return this.<Entity, T>getForEntity(entity) return this.<Entity, T>getForEntity(entity)
.map(IRaceContainerHolder::getRaceContainer) .map(RaceContainerHolder::getRaceContainer)
.orElse(null); .orElse(null);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <E extends Entity, T extends IEntity> Optional<IRaceContainerHolder<T>> getForEntity(Entity entity) { public <E extends Entity, T extends IEntity> Optional<RaceContainerHolder<T>> getForEntity(Entity entity) {
if (entity instanceof IRaceContainerHolder) { if (entity instanceof RaceContainerHolder) {
return Optional.of(((IRaceContainerHolder<T>)entity)); return Optional.of(((RaceContainerHolder<T>)entity));
} }
return Optional.empty(); return Optional.empty();
} }

View file

@ -1,16 +1,16 @@
package com.minelittlepony.unicopia; package com.minelittlepony.unicopia;
import com.minelittlepony.unicopia.block.CloudDoorBlock;
import com.minelittlepony.unicopia.block.BlockGrowingCuccoon; import com.minelittlepony.unicopia.block.BlockGrowingCuccoon;
import com.minelittlepony.unicopia.block.TomatoPlantBlock; import com.minelittlepony.unicopia.block.TomatoPlantBlock;
import com.minelittlepony.unicopia.gas.CloudAnvilBlock;
import com.minelittlepony.unicopia.gas.CloudBlock;
import com.minelittlepony.unicopia.gas.CloudDoorBlock;
import com.minelittlepony.unicopia.gas.CloudFarmlandBlock;
import com.minelittlepony.unicopia.gas.CloudFenceBlock;
import com.minelittlepony.unicopia.gas.CloudSlabBlock;
import com.minelittlepony.unicopia.gas.CloudStairsBlock;
import com.minelittlepony.unicopia.block.ChiselledChitinBlock; import com.minelittlepony.unicopia.block.ChiselledChitinBlock;
import com.minelittlepony.unicopia.block.ChitinBlock; import com.minelittlepony.unicopia.block.ChitinBlock;
import com.minelittlepony.unicopia.block.CloudAnvilBlock;
import com.minelittlepony.unicopia.block.CloudBlock;
import com.minelittlepony.unicopia.block.CloudFarmlandBlock;
import com.minelittlepony.unicopia.block.CloudFenceBlock;
import com.minelittlepony.unicopia.block.CloudSlabBlock;
import com.minelittlepony.unicopia.block.CloudStairsBlock;
import com.minelittlepony.unicopia.block.DiamondDoorBlock; import com.minelittlepony.unicopia.block.DiamondDoorBlock;
import com.minelittlepony.unicopia.block.DutchDoorBlock; import com.minelittlepony.unicopia.block.DutchDoorBlock;
import com.minelittlepony.unicopia.block.FruitLeavesBlock; import com.minelittlepony.unicopia.block.FruitLeavesBlock;

View file

@ -6,6 +6,7 @@ import java.util.function.Function;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import com.minelittlepony.unicopia.SpeciesList; import com.minelittlepony.unicopia.SpeciesList;
import com.minelittlepony.unicopia.ducks.Colourful;
import net.fabricmc.fabric.api.block.FabricBlockSettings; import net.fabricmc.fabric.api.block.FabricBlockSettings;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -27,7 +28,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.biome.Biome.TemperatureGroup; import net.minecraft.world.biome.Biome.TemperatureGroup;
public class FruitLeavesBlock extends LeavesBlock implements IColourful { public class FruitLeavesBlock extends LeavesBlock implements Colourful {
public static final BooleanProperty HEAVY = BooleanProperty.of("heavy"); public static final BooleanProperty HEAVY = BooleanProperty.of("heavy");

View file

@ -4,6 +4,7 @@ import java.util.Random;
import com.minelittlepony.unicopia.CloudType; import com.minelittlepony.unicopia.CloudType;
import com.minelittlepony.unicopia.UParticles; import com.minelittlepony.unicopia.UParticles;
import com.minelittlepony.unicopia.gas.Gas;
import net.fabricmc.fabric.api.block.FabricBlockSettings; import net.fabricmc.fabric.api.block.FabricBlockSettings;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -31,7 +32,7 @@ import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView; import net.minecraft.world.BlockView;
import net.minecraft.world.World; import net.minecraft.world.World;
public class GlowingGemBlock extends TorchBlock implements ICloudBlock { public class GlowingGemBlock extends TorchBlock implements Gas {
public static BooleanProperty ON = BooleanProperty.of("on"); public static BooleanProperty ON = BooleanProperty.of("on");

View file

@ -1,24 +0,0 @@
package com.minelittlepony.unicopia.block;
import javax.annotation.Nonnull;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
* Blocks that can be turned into farmland when tilled.
*/
public interface ITillable {
/**
* Gets the farmland/tilled state for this block when attacked by a hoe.
*/
@Nonnull
BlockState getFarmlandState(ItemStack hoe, PlayerEntity player, World world, BlockState state, BlockPos pos);
default boolean canBeTilled(ItemStack hoe, PlayerEntity player, World world, BlockState state, BlockPos pos) {
return world.isAir(pos.up());
}
}

View file

@ -2,6 +2,7 @@ package com.minelittlepony.unicopia.block;
import java.util.List; import java.util.List;
import com.minelittlepony.unicopia.UBlocks; import com.minelittlepony.unicopia.UBlocks;
import com.minelittlepony.unicopia.gas.CloudFarmlandBlock;
import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.item.UItems;
import net.fabricmc.fabric.api.block.FabricBlockSettings; import net.fabricmc.fabric.api.block.FabricBlockSettings;

View file

@ -14,8 +14,8 @@ import com.minelittlepony.unicopia.SpeciesList;
import com.minelittlepony.unicopia.UBlocks; import com.minelittlepony.unicopia.UBlocks;
import com.minelittlepony.unicopia.UnicopiaCore; import com.minelittlepony.unicopia.UnicopiaCore;
import com.minelittlepony.unicopia.ability.PowersRegistry; import com.minelittlepony.unicopia.ability.PowersRegistry;
import com.minelittlepony.unicopia.block.IColourful;
import com.minelittlepony.unicopia.client.render.DisguiseRenderer; import com.minelittlepony.unicopia.client.render.DisguiseRenderer;
import com.minelittlepony.unicopia.ducks.Colourful;
import com.minelittlepony.unicopia.entity.player.IPlayer; import com.minelittlepony.unicopia.entity.player.IPlayer;
import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.item.UItems;
import com.minelittlepony.unicopia.magic.spell.SpellRegistry; import com.minelittlepony.unicopia.magic.spell.SpellRegistry;
@ -163,8 +163,8 @@ public class UnicopiaCoreClient extends InteractionManager implements ClientModI
private static int getLeavesColor(BlockState state, @Nullable ExtendedBlockView world, @Nullable BlockPos pos, int tint) { private static int getLeavesColor(BlockState state, @Nullable ExtendedBlockView world, @Nullable BlockPos pos, int tint) {
Block block = state.getBlock(); Block block = state.getBlock();
if (block instanceof IColourful) { if (block instanceof Colourful) {
return ((IColourful)block).getCustomTint(state, tint); return ((Colourful)block).getCustomTint(state, tint);
} }
if (world != null && pos != null) { if (world != null && pos != null) {

View file

@ -1,8 +1,8 @@
package com.minelittlepony.unicopia.block; package com.minelittlepony.unicopia.ducks;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
@FunctionalInterface @FunctionalInterface
public interface IColourful { public interface Colourful {
int getCustomTint(BlockState state, int tint); int getCustomTint(BlockState state, int tint);
} }

View file

@ -4,7 +4,7 @@ import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
public interface IFarmland { public interface Farmland {
/** /**
* Gets the state used to represent this block as a piece of dirt. * Gets the state used to represent this block as a piece of dirt.
*/ */

View file

@ -2,7 +2,7 @@ package com.minelittlepony.unicopia.ducks;
import com.minelittlepony.unicopia.entity.ItemEntityCapabilities; import com.minelittlepony.unicopia.entity.ItemEntityCapabilities;
public interface IItemEntity extends IRaceContainerHolder<ItemEntityCapabilities> { public interface IItemEntity extends RaceContainerHolder<ItemEntityCapabilities> {
int getAge(); int getAge();

View file

@ -7,7 +7,7 @@ import com.minelittlepony.unicopia.magic.ICaster;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
public interface IRaceContainerHolder<T extends IEntity> { public interface RaceContainerHolder<T extends IEntity> {
T getRaceContainer(); T getRaceContainer();
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View file

@ -5,7 +5,7 @@ import java.util.function.Function;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import com.minelittlepony.unicopia.network.ITransmittable; import com.minelittlepony.unicopia.network.Transmittable;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
@ -13,7 +13,7 @@ import net.minecraft.util.Identifier;
* Interface for things that own and can unlock pages. * Interface for things that own and can unlock pages.
* *
*/ */
public interface IPageOwner extends ITransmittable { public interface IPageOwner extends Transmittable {
@Nonnull @Nonnull
Map<Identifier, PageState> getPageStates(); Map<Identifier, PageState> getPageStates();

View file

@ -9,7 +9,7 @@ import com.minelittlepony.unicopia.entity.FlightControl;
import com.minelittlepony.unicopia.entity.RaceContainer; import com.minelittlepony.unicopia.entity.RaceContainer;
import com.minelittlepony.unicopia.magic.ICaster; import com.minelittlepony.unicopia.magic.ICaster;
import com.minelittlepony.unicopia.magic.IHeldEffect; import com.minelittlepony.unicopia.magic.IHeldEffect;
import com.minelittlepony.unicopia.network.ITransmittable; import com.minelittlepony.unicopia.network.Transmittable;
import com.minelittlepony.util.IInterpolator; import com.minelittlepony.util.IInterpolator;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.datafixers.util.Either; import com.mojang.datafixers.util.Either;
@ -24,7 +24,7 @@ import net.minecraft.util.math.BlockPos;
* *
* This is the core of unicopia. * This is the core of unicopia.
*/ */
public interface IPlayer extends ICaster<PlayerEntity>, RaceContainer<PlayerEntity>, ITransmittable, IPageOwner { public interface IPlayer extends ICaster<PlayerEntity>, RaceContainer<PlayerEntity>, Transmittable, IPageOwner {
/** /**
* Gets the player's magical abilities delegate responsible for all spell casting and persisting/updating. * Gets the player's magical abilities delegate responsible for all spell casting and persisting/updating.

View file

@ -1,4 +1,4 @@
package com.minelittlepony.unicopia.block; package com.minelittlepony.unicopia.gas;
import java.util.Random; import java.util.Random;
@ -19,7 +19,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView; import net.minecraft.world.BlockView;
import net.minecraft.world.World; import net.minecraft.world.World;
public class CloudAnvilBlock extends AnvilBlock implements ICloudBlock { public class CloudAnvilBlock extends AnvilBlock implements Gas {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public CloudAnvilBlock() { public CloudAnvilBlock() {
super(FabricBlockSettings.of(Material.WOOL) super(FabricBlockSettings.of(Material.WOOL)
@ -70,8 +70,8 @@ public class CloudAnvilBlock extends AnvilBlock implements ICloudBlock {
public void onScheduledTick(BlockState state, World world, BlockPos pos, Random rand) { public void onScheduledTick(BlockState state, World world, BlockPos pos, Random rand) {
BlockState below = world.getBlockState(pos.down()); BlockState below = world.getBlockState(pos.down());
if (below.getBlock() instanceof ICloudBlock) { if (below.getBlock() instanceof Gas) {
if (((ICloudBlock)below.getBlock()).isDense(below)) { if (((Gas)below.getBlock()).isDense(below)) {
return; return;
} }
} }

View file

@ -1,4 +1,4 @@
package com.minelittlepony.unicopia.block; package com.minelittlepony.unicopia.gas;
import java.util.Random; import java.util.Random;
@ -6,6 +6,7 @@ import com.minelittlepony.unicopia.CloudType;
import com.minelittlepony.unicopia.SpeciesList; import com.minelittlepony.unicopia.SpeciesList;
import com.minelittlepony.unicopia.UBlocks; import com.minelittlepony.unicopia.UBlocks;
import com.minelittlepony.unicopia.item.MossItem; import com.minelittlepony.unicopia.item.MossItem;
import com.minelittlepony.unicopia.util.HoeUtil;
import net.fabricmc.fabric.api.block.FabricBlockSettings; import net.fabricmc.fabric.api.block.FabricBlockSettings;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -14,14 +15,14 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.Material; import net.minecraft.block.Material;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemUsageContext;
import net.minecraft.sound.BlockSoundGroup; import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView; import net.minecraft.world.BlockView;
import net.minecraft.world.World; import net.minecraft.world.World;
public class CloudBlock extends Block implements ICloudBlock, ITillable { public class CloudBlock extends Block implements Gas, HoeUtil.Tillable {
private final CloudType variant; private final CloudType variant;
@ -33,6 +34,7 @@ public class CloudBlock extends Block implements ICloudBlock, ITillable {
.build() .build()
); );
this.variant = variant; this.variant = variant;
HoeUtil.registerTillingAction(this, UBlocks.cloud_farmland.getDefaultState());
} }
@Override @Override
@ -66,8 +68,8 @@ public class CloudBlock extends Block implements ICloudBlock, ITillable {
@Override @Override
public boolean isSideInvisible(BlockState state, BlockState beside, Direction face) { public boolean isSideInvisible(BlockState state, BlockState beside, Direction face) {
if (beside.getBlock() instanceof ICloudBlock) { if (beside.getBlock() instanceof Gas) {
ICloudBlock cloud = ((ICloudBlock)beside.getBlock()); Gas cloud = ((Gas)beside.getBlock());
if (cloud.getCloudMaterialType(beside) == getCloudMaterialType(state)) { if (cloud.getCloudMaterialType(beside) == getCloudMaterialType(state)) {
return true; return true;
@ -113,14 +115,7 @@ public class CloudBlock extends Block implements ICloudBlock, ITillable {
} }
@Override @Override
public boolean canBeTilled(ItemStack hoe, PlayerEntity player, World world, BlockState state, BlockPos pos) { public boolean canTill(ItemUsageContext context) {
return SpeciesList.instance().getPlayer(player).getSpecies().canInteractWithClouds() return context.getPlayer() == null || SpeciesList.instance().getPlayer(context.getPlayer()).getSpecies().canInteractWithClouds();
&& ITillable.super.canBeTilled(hoe, player, world, state, pos);
} }
@Override
public BlockState getFarmlandState(ItemStack hoe, PlayerEntity player, World world, BlockState state, BlockPos pos) {
return UBlocks.cloud_farmland.getDefaultState();
}
} }

View file

@ -1,7 +1,8 @@
package com.minelittlepony.unicopia.block; package com.minelittlepony.unicopia.gas;
import com.minelittlepony.unicopia.CloudType; import com.minelittlepony.unicopia.CloudType;
import com.minelittlepony.unicopia.UMaterials; import com.minelittlepony.unicopia.UMaterials;
import com.minelittlepony.unicopia.block.AbstractDoorBlock;
import net.fabricmc.fabric.api.block.FabricBlockSettings; import net.fabricmc.fabric.api.block.FabricBlockSettings;
import net.minecraft.block.BlockRenderLayer; import net.minecraft.block.BlockRenderLayer;
@ -15,7 +16,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView; import net.minecraft.world.BlockView;
import net.minecraft.world.World; import net.minecraft.world.World;
public class CloudDoorBlock extends AbstractDoorBlock implements ICloudBlock { public class CloudDoorBlock extends AbstractDoorBlock implements Gas {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public CloudDoorBlock() { public CloudDoorBlock() {

View file

@ -1,8 +1,8 @@
package com.minelittlepony.unicopia.block; package com.minelittlepony.unicopia.gas;
import com.minelittlepony.unicopia.CloudType; import com.minelittlepony.unicopia.CloudType;
import com.minelittlepony.unicopia.UBlocks; import com.minelittlepony.unicopia.UBlocks;
import com.minelittlepony.unicopia.ducks.IFarmland; import com.minelittlepony.unicopia.ducks.Farmland;
import net.minecraft.block.BlockRenderLayer; import net.minecraft.block.BlockRenderLayer;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
@ -15,7 +15,7 @@ import net.minecraft.util.math.Direction.Axis;
import net.minecraft.world.BlockView; import net.minecraft.world.BlockView;
import net.minecraft.world.World; import net.minecraft.world.World;
public class CloudFarmlandBlock extends FarmlandBlock implements IFarmland, ICloudBlock { public class CloudFarmlandBlock extends FarmlandBlock implements Farmland, Gas {
public CloudFarmlandBlock(Settings settings) { public CloudFarmlandBlock(Settings settings) {
super(settings); super(settings);
@ -29,8 +29,8 @@ public class CloudFarmlandBlock extends FarmlandBlock implements IFarmland, IClo
@Override @Override
public boolean isSideInvisible(BlockState state, BlockState beside, Direction face) { public boolean isSideInvisible(BlockState state, BlockState beside, Direction face) {
if (beside.getBlock() instanceof ICloudBlock) { if (beside.getBlock() instanceof Gas) {
ICloudBlock cloud = ((ICloudBlock)beside.getBlock()); Gas cloud = ((Gas)beside.getBlock());
if (face.getAxis() == Axis.Y || cloud == this) { if (face.getAxis() == Axis.Y || cloud == this) {
if (cloud.getCloudMaterialType(beside) == getCloudMaterialType(state)) { if (cloud.getCloudMaterialType(beside) == getCloudMaterialType(state)) {

View file

@ -1,4 +1,4 @@
package com.minelittlepony.unicopia.block; package com.minelittlepony.unicopia.gas;
import com.minelittlepony.unicopia.CloudType; import com.minelittlepony.unicopia.CloudType;
@ -14,7 +14,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView; import net.minecraft.world.BlockView;
import net.minecraft.world.World; import net.minecraft.world.World;
public class CloudFenceBlock extends FenceBlock implements ICloudBlock { public class CloudFenceBlock extends FenceBlock implements Gas {
private final CloudType variant; private final CloudType variant;

View file

@ -1,6 +1,7 @@
package com.minelittlepony.unicopia.block; package com.minelittlepony.unicopia.gas;
import com.minelittlepony.unicopia.CloudType; import com.minelittlepony.unicopia.CloudType;
import com.minelittlepony.unicopia.block.USlab;
import net.fabricmc.fabric.api.block.FabricBlockSettings; import net.fabricmc.fabric.api.block.FabricBlockSettings;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -11,7 +12,7 @@ import net.minecraft.block.enums.SlabType;
import net.minecraft.state.property.Properties; import net.minecraft.state.property.Properties;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
public class CloudSlabBlock<T extends Block & ICloudBlock> extends USlab<T> implements ICloudBlock { public class CloudSlabBlock<T extends Block & Gas> extends USlab<T> implements Gas {
public CloudSlabBlock(T modelBlock, Material material) { public CloudSlabBlock(T modelBlock, Material material) {
super(modelBlock, FabricBlockSettings.of(material).build()); super(modelBlock, FabricBlockSettings.of(material).build());
@ -25,8 +26,8 @@ public class CloudSlabBlock<T extends Block & ICloudBlock> extends USlab<T> impl
@Override @Override
public boolean isSideInvisible(BlockState state, BlockState beside, Direction face) { public boolean isSideInvisible(BlockState state, BlockState beside, Direction face) {
if (isDouble(state)) { if (isDouble(state)) {
if (beside.getBlock() instanceof ICloudBlock) { if (beside.getBlock() instanceof Gas) {
ICloudBlock cloud = ((ICloudBlock)beside.getBlock()); Gas cloud = ((Gas)beside.getBlock());
if (cloud.getCloudMaterialType(beside) == getCloudMaterialType(state)) { if (cloud.getCloudMaterialType(beside) == getCloudMaterialType(state)) {
return true; return true;
@ -35,8 +36,8 @@ public class CloudSlabBlock<T extends Block & ICloudBlock> extends USlab<T> impl
return false; return false;
} else { } else {
if (beside.getBlock() instanceof ICloudBlock) { if (beside.getBlock() instanceof Gas) {
ICloudBlock cloud = ((ICloudBlock)beside.getBlock()); Gas cloud = ((Gas)beside.getBlock());
if (cloud.getCloudMaterialType(beside) == getCloudMaterialType(state)) { if (cloud.getCloudMaterialType(beside) == getCloudMaterialType(state)) {

View file

@ -1,6 +1,7 @@
package com.minelittlepony.unicopia.block; package com.minelittlepony.unicopia.gas;
import com.minelittlepony.unicopia.CloudType; import com.minelittlepony.unicopia.CloudType;
import com.minelittlepony.unicopia.block.UStairs;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
@ -11,7 +12,7 @@ import net.minecraft.entity.EntityContext;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape; import net.minecraft.util.shape.VoxelShape;
public class CloudStairsBlock extends UStairs implements ICloudBlock { public class CloudStairsBlock extends UStairs implements Gas {
public CloudStairsBlock(BlockState inherited, Settings settings) { public CloudStairsBlock(BlockState inherited, Settings settings) {
super(inherited, settings); super(inherited, settings);
@ -19,8 +20,8 @@ public class CloudStairsBlock extends UStairs implements ICloudBlock {
@Override @Override
public boolean isSideInvisible(BlockState state, BlockState beside, Direction face) { public boolean isSideInvisible(BlockState state, BlockState beside, Direction face) {
if (beside.getBlock() instanceof ICloudBlock) { if (beside.getBlock() instanceof Gas) {
ICloudBlock cloud = ((ICloudBlock)beside.getBlock()); Gas cloud = ((Gas)beside.getBlock());
if (cloud.getCloudMaterialType(beside) == getCloudMaterialType(state)) { if (cloud.getCloudMaterialType(beside) == getCloudMaterialType(state)) {
Direction front = state.get(FACING); Direction front = state.get(FACING);

View file

@ -1,4 +1,4 @@
package com.minelittlepony.unicopia.block; package com.minelittlepony.unicopia.gas;
import com.minelittlepony.unicopia.CloudType; import com.minelittlepony.unicopia.CloudType;
import com.minelittlepony.unicopia.EquinePredicates; import com.minelittlepony.unicopia.EquinePredicates;
@ -20,7 +20,7 @@ import net.minecraft.util.math.Vec3d;
import net.minecraft.world.BlockView; import net.minecraft.world.BlockView;
import net.minecraft.world.World; import net.minecraft.world.World;
public interface ICloudBlock { public interface Gas {
CloudType getCloudMaterialType(BlockState blockState); CloudType getCloudMaterialType(BlockState blockState);
@ -51,8 +51,8 @@ public interface ICloudBlock {
return false; return false;
} }
if (block instanceof ICloudBlock) { if (block instanceof Gas) {
CloudType other = ((ICloudBlock)block).getCloudMaterialType(heldState); CloudType other = ((Gas)block).getCloudMaterialType(heldState);
if (other.canInteract(player)) { if (other.canInteract(player)) {
return false; return false;
@ -158,6 +158,6 @@ public interface ICloudBlock {
} }
Block above = world.getBlockState(pos.up()).getBlock(); Block above = world.getBlockState(pos.up()).getBlock();
return !(above instanceof ICloudBlock) && above instanceof FallingBlock; return !(above instanceof Gas) && above instanceof FallingBlock;
} }
} }

View file

@ -8,7 +8,7 @@ import javax.annotation.Nullable;
import com.google.common.collect.Streams; import com.google.common.collect.Streams;
import com.minelittlepony.unicopia.EquinePredicates; import com.minelittlepony.unicopia.EquinePredicates;
import com.minelittlepony.unicopia.SpeciesList; import com.minelittlepony.unicopia.SpeciesList;
import com.minelittlepony.unicopia.ducks.IRaceContainerHolder; import com.minelittlepony.unicopia.ducks.RaceContainerHolder;
import com.minelittlepony.unicopia.entity.IMagicals; import com.minelittlepony.unicopia.entity.IMagicals;
import com.minelittlepony.unicopia.magic.spell.SpellRegistry; import com.minelittlepony.unicopia.magic.spell.SpellRegistry;
@ -78,7 +78,7 @@ public class CasterUtils {
if (entity instanceof LivingEntity && !(entity instanceof IMagicals)) { if (entity instanceof LivingEntity && !(entity instanceof IMagicals)) {
return SpeciesList.instance().getForEntity(entity) return SpeciesList.instance().getForEntity(entity)
.map(IRaceContainerHolder::getCaster); .map(RaceContainerHolder::getCaster);
} }
return Optional.empty(); return Optional.empty();

View file

@ -4,7 +4,7 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import com.minelittlepony.unicopia.ducks.IFarmland; import com.minelittlepony.unicopia.ducks.Farmland;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
@ -20,8 +20,8 @@ abstract class MixinFarmlandBlock extends Block {
at = @At("HEAD"), at = @At("HEAD"),
cancellable = true) cancellable = true)
public static void setToDirt(BlockState state, World world, BlockPos pos) { public static void setToDirt(BlockState state, World world, BlockPos pos) {
if (state.getBlock() instanceof IFarmland) { if (state.getBlock() instanceof Farmland) {
BlockState dirtState = ((IFarmland)state.getBlock()).getDirtState(state, world, pos); BlockState dirtState = ((Farmland)state.getBlock()).getDirtState(state, world, pos);
world.setBlockState(pos, pushEntitiesUpBeforeBlockChange(state, dirtState, world, pos)); world.setBlockState(pos, pushEntitiesUpBeforeBlockChange(state, dirtState, world, pos));
} }
} }

View file

@ -0,0 +1,31 @@
package com.minelittlepony.unicopia.mixin;
import org.spongepowered.asm.mixin.Mixin;
import com.minelittlepony.unicopia.util.HoeUtil;
import net.minecraft.block.BlockState;
import net.minecraft.item.HoeItem;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.item.ToolItem;
import net.minecraft.util.ActionResult;
@Mixin(HoeItem.class)
abstract class MixinHoeItem extends ToolItem {
MixinHoeItem() {super(null, null);}
@Override
public ActionResult useOnBlock(ItemUsageContext context) {
BlockState state = context.getWorld().getBlockState(context.getBlockPos());
if (state.getBlock() instanceof HoeUtil.Tillable) {
if (!((HoeUtil.Tillable)state.getBlock()).canTill(context)) {
return ActionResult.PASS;
}
}
return null;
}
}

View file

@ -6,7 +6,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.minelittlepony.unicopia.ducks.IRaceContainerHolder; import com.minelittlepony.unicopia.ducks.RaceContainerHolder;
import com.minelittlepony.unicopia.entity.IEntity; import com.minelittlepony.unicopia.entity.IEntity;
import com.minelittlepony.unicopia.entity.LivingEntityCapabilities; import com.minelittlepony.unicopia.entity.LivingEntityCapabilities;
@ -14,7 +14,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
@Mixin(LivingEntity.class) @Mixin(LivingEntity.class)
public abstract class MixinLivingEntity extends Entity implements IRaceContainerHolder<IEntity> { public abstract class MixinLivingEntity extends Entity implements RaceContainerHolder<IEntity> {
private final IEntity caster = createRaceContainer(); private final IEntity caster = createRaceContainer();

View file

@ -8,7 +8,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.minelittlepony.unicopia.SpeciesList; import com.minelittlepony.unicopia.SpeciesList;
import com.minelittlepony.unicopia.ducks.IRaceContainerHolder; import com.minelittlepony.unicopia.ducks.RaceContainerHolder;
import com.minelittlepony.unicopia.entity.IEntity; import com.minelittlepony.unicopia.entity.IEntity;
import com.minelittlepony.unicopia.entity.player.IPlayer; import com.minelittlepony.unicopia.entity.player.IPlayer;
import com.minelittlepony.unicopia.entity.player.PlayerCapabilities; import com.minelittlepony.unicopia.entity.player.PlayerCapabilities;
@ -23,7 +23,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.GameMode; import net.minecraft.world.GameMode;
@Mixin(PlayerEntity.class) @Mixin(PlayerEntity.class)
public abstract class MixinPlayerEntity extends LivingEntity implements IRaceContainerHolder<IPlayer> { public abstract class MixinPlayerEntity extends LivingEntity implements RaceContainerHolder<IPlayer> {
private MixinPlayerEntity() { super(null, null); } private MixinPlayerEntity() { super(null, null); }
@Override @Override

View file

@ -1,5 +1,5 @@
package com.minelittlepony.unicopia.network; package com.minelittlepony.unicopia.network;
public interface ITransmittable { public interface Transmittable {
void sendCapabilities(boolean full); void sendCapabilities(boolean full);
} }

View file

@ -1,39 +0,0 @@
package com.minelittlepony.unicopia.structure;
import java.util.Random;
import java.util.function.Function;
import javax.annotation.Nonnull;
import com.mojang.datafixers.Dynamic;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.feature.AbstractTempleFeature;
import net.minecraft.world.gen.feature.FeatureConfig;
public abstract class BiomeWhitelistedFeature<C extends FeatureConfig> extends AbstractTempleFeature<C> {
public BiomeWhitelistedFeature(Function<Dynamic<?>, ? extends C> function_1) {
super(function_1);
}
@Override
public boolean shouldStartAt(ChunkGenerator<?> generator, Random rand, int x, int z) {
ChunkPos pos = getStart(generator, rand, x, z, 0, 0);
if (x == pos.x && z == pos.z) {
Biome biome = generator.getBiomeSource().getBiome(new BlockPos(x * 16 + 9, 0, z * 16 + 9));
if (canSpawnInBiome(biome)) {
return true;
}
}
return false;
}
protected abstract boolean canSpawnInBiome(@Nonnull Biome biome);
}

View file

@ -1,12 +1,9 @@
package com.minelittlepony.unicopia.structure; package com.minelittlepony.unicopia.structure;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.function.Function; import java.util.function.Function;
import javax.annotation.Nonnull;
import com.minelittlepony.unicopia.UnicopiaCore; import com.minelittlepony.unicopia.UnicopiaCore;
import com.mojang.datafixers.Dynamic; import com.mojang.datafixers.Dynamic;
@ -24,35 +21,40 @@ import net.minecraft.util.math.MutableIntBoundingBox;
import net.minecraft.world.IWorld; import net.minecraft.world.IWorld;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes; import net.minecraft.world.biome.Biomes;
import net.minecraft.world.gen.GenerationStep;
import net.minecraft.world.gen.chunk.ChunkGenerator; import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.decorator.Decorator;
import net.minecraft.world.gen.decorator.DecoratorConfig;
import net.minecraft.world.gen.feature.AbstractTempleFeature;
import net.minecraft.world.gen.feature.DefaultFeatureConfig; import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import net.minecraft.world.gen.feature.FeatureConfig;
import net.minecraft.world.gen.feature.StructureFeature; import net.minecraft.world.gen.feature.StructureFeature;
public class CloudDungeonFeature extends BiomeWhitelistedFeature<DefaultFeatureConfig> { class CloudDungeonFeature extends AbstractTempleFeature<DefaultFeatureConfig> {
private static final BlockPos POS = new BlockPos(4, 0, 15); private static final BlockPos POS = new BlockPos(4, 0, 15);
private static final Identifier[] VARIANTS = new Identifier[] { private static final Identifier[] VARIANTS = new Identifier[] {
new Identifier(UnicopiaCore.MODID, "cloud/temple_small"), new Identifier(UnicopiaCore.MODID, "cloud/temple_small"),
new Identifier(UnicopiaCore.MODID, "cloud/house_small"), new Identifier(UnicopiaCore.MODID, "cloud/house_small"),
new Identifier(UnicopiaCore.MODID, "cloud/island_small") new Identifier(UnicopiaCore.MODID, "cloud/island_small")
}; };
private static final List<Biome> ALLOWED_BIOMES = Arrays.<Biome>asList(
Biomes.OCEAN,
Biomes.WOODED_BADLANDS_PLATEAU,
Biomes.DESERT,
Biomes.DESERT_HILLS,
Biomes.JUNGLE,
Biomes.JUNGLE_HILLS,
Biomes.SWAMP,
Biomes.SWAMP_HILLS,
Biomes.ICE_SPIKES,
Biomes.TAIGA
);
public CloudDungeonFeature(Function<Dynamic<?>, ? extends DefaultFeatureConfig> func) { public CloudDungeonFeature(Function<Dynamic<?>, ? extends DefaultFeatureConfig> func) {
super(func); super(func);
Arrays.asList(
Biomes.OCEAN,
Biomes.WOODED_BADLANDS_PLATEAU,
Biomes.DESERT,
Biomes.DESERT_HILLS,
Biomes.JUNGLE,
Biomes.JUNGLE_HILLS,
Biomes.SWAMP,
Biomes.SWAMP_HILLS,
Biomes.ICE_SPIKES,
Biomes.TAIGA
).forEach(biome -> {
biome.addFeature(GenerationStep.Feature.LOCAL_MODIFICATIONS, Biome.configureFeature(UStructures.CLOUD_HOUSE, FeatureConfig.DEFAULT, Decorator.NOPE, DecoratorConfig.DEFAULT));
});
} }
@Override @Override
@ -70,11 +72,6 @@ public class CloudDungeonFeature extends BiomeWhitelistedFeature<DefaultFeatureC
return 12; return 12;
} }
@Override
protected boolean canSpawnInBiome(@Nonnull Biome biome) {
return ALLOWED_BIOMES.contains(biome);
}
@Override @Override
public StructureStartFactory getStructureStartFactory() { public StructureStartFactory getStructureStartFactory() {
return Start::new; return Start::new;
@ -103,7 +100,7 @@ public class CloudDungeonFeature extends BiomeWhitelistedFeature<DefaultFeatureC
private final Identifier template; private final Identifier template;
public Piece(StructureManager manager, Identifier template, BlockPos pos, BlockRotation rotation) { public Piece(StructureManager manager, Identifier template, BlockPos pos, BlockRotation rotation) {
super(UStructures.CLOUD_HOUSE, 0); super(UStructures.CLOUD_HOUSE_PART, 0);
this.pos = pos; this.pos = pos;
this.rotation = rotation; this.rotation = rotation;
this.template = template; this.template = template;
@ -112,7 +109,7 @@ public class CloudDungeonFeature extends BiomeWhitelistedFeature<DefaultFeatureC
} }
public Piece(StructureManager manager, CompoundTag tag) { public Piece(StructureManager manager, CompoundTag tag) {
super(UStructures.CLOUD_HOUSE, tag); super(UStructures.CLOUD_HOUSE_PART, tag);
this.template = new Identifier(tag.getString("Template")); this.template = new Identifier(tag.getString("Template"));
this.rotation = BlockRotation.valueOf(tag.getString("Rot")); this.rotation = BlockRotation.valueOf(tag.getString("Rot"));
init(manager); init(manager);

View file

@ -1,7 +1,6 @@
package com.minelittlepony.unicopia.structure; package com.minelittlepony.unicopia.structure;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.function.Function; import java.util.function.Function;
@ -22,14 +21,17 @@ import net.minecraft.util.math.MutableIntBoundingBox;
import net.minecraft.world.IWorld; import net.minecraft.world.IWorld;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes; import net.minecraft.world.biome.Biomes;
import net.minecraft.world.gen.GenerationStep;
import net.minecraft.world.gen.chunk.ChunkGenerator; import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.decorator.Decorator;
import net.minecraft.world.gen.decorator.DecoratorConfig;
import net.minecraft.world.gen.feature.AbstractTempleFeature;
import net.minecraft.world.gen.feature.DefaultFeatureConfig; import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import net.minecraft.world.gen.feature.FeatureConfig;
import net.minecraft.world.gen.feature.StructureFeature; import net.minecraft.world.gen.feature.StructureFeature;
public class RuinFeature extends BiomeWhitelistedFeature<DefaultFeatureConfig> { class RuinFeature extends AbstractTempleFeature<DefaultFeatureConfig> {
private static final BlockPos POS = new BlockPos(4, 0, 15); private static final BlockPos POS = new BlockPos(4, 0, 15);
private static final Identifier[] VARIANTS = new Identifier[] { private static final Identifier[] VARIANTS = new Identifier[] {
new Identifier(UnicopiaCore.MODID, "ground/tower"), new Identifier(UnicopiaCore.MODID, "ground/tower"),
new Identifier(UnicopiaCore.MODID, "ground/temple_with_book"), new Identifier(UnicopiaCore.MODID, "ground/temple_with_book"),
@ -38,22 +40,24 @@ public class RuinFeature extends BiomeWhitelistedFeature<DefaultFeatureConfig> {
new Identifier(UnicopiaCore.MODID, "ground/wizard_tower_blue") new Identifier(UnicopiaCore.MODID, "ground/wizard_tower_blue")
}; };
private static final List<Biome> BIOMELIST = Arrays.<Biome>asList(
Biomes.TAIGA,
Biomes.TAIGA_HILLS,
Biomes.GIANT_TREE_TAIGA,
Biomes.GIANT_TREE_TAIGA_HILLS,
Biomes.SNOWY_TAIGA,
Biomes.SNOWY_TAIGA_HILLS,
Biomes.GIANT_SPRUCE_TAIGA,
Biomes.GIANT_TREE_TAIGA_HILLS,
Biomes.SNOWY_TAIGA_MOUNTAINS,
Biomes.DARK_FOREST,
Biomes.DARK_FOREST_HILLS
);
public RuinFeature(Function<Dynamic<?>, ? extends DefaultFeatureConfig> func) { public RuinFeature(Function<Dynamic<?>, ? extends DefaultFeatureConfig> func) {
super(func); super(func);
Arrays.asList(
Biomes.TAIGA,
Biomes.TAIGA_HILLS,
Biomes.GIANT_TREE_TAIGA,
Biomes.GIANT_TREE_TAIGA_HILLS,
Biomes.SNOWY_TAIGA,
Biomes.SNOWY_TAIGA_HILLS,
Biomes.GIANT_SPRUCE_TAIGA,
Biomes.GIANT_TREE_TAIGA_HILLS,
Biomes.SNOWY_TAIGA_MOUNTAINS,
Biomes.DARK_FOREST,
Biomes.DARK_FOREST_HILLS
).forEach(biome -> {
biome.addFeature(GenerationStep.Feature.SURFACE_STRUCTURES, Biome.configureFeature(UStructures.CLOUD_HOUSE, FeatureConfig.DEFAULT, Decorator.NOPE, DecoratorConfig.DEFAULT));
});
} }
@Override @Override
@ -71,11 +75,6 @@ public class RuinFeature extends BiomeWhitelistedFeature<DefaultFeatureConfig> {
return 39548; return 39548;
} }
@Override
protected boolean canSpawnInBiome(Biome biome) {
return BIOMELIST.contains(biome);
}
@Override @Override
public StructureStartFactory getStructureStartFactory() { public StructureStartFactory getStructureStartFactory() {
return Start::new; return Start::new;
@ -104,7 +103,7 @@ public class RuinFeature extends BiomeWhitelistedFeature<DefaultFeatureConfig> {
private final Identifier template; private final Identifier template;
public Piece(StructureManager manager, Identifier template, BlockPos pos, BlockRotation rotation) { public Piece(StructureManager manager, Identifier template, BlockPos pos, BlockRotation rotation) {
super(UStructures.RUIN, 0); super(UStructures.RUIN_PART, 0);
this.pos = pos; this.pos = pos;
this.rotation = rotation; this.rotation = rotation;
this.template = template; this.template = template;
@ -113,7 +112,7 @@ public class RuinFeature extends BiomeWhitelistedFeature<DefaultFeatureConfig> {
} }
public Piece(StructureManager manager, CompoundTag tag) { public Piece(StructureManager manager, CompoundTag tag) {
super(UStructures.RUIN, tag); super(UStructures.RUIN_PART, tag);
this.template = new Identifier(tag.getString("Template")); this.template = new Identifier(tag.getString("Template"));
this.rotation = BlockRotation.valueOf(tag.getString("Rot")); this.rotation = BlockRotation.valueOf(tag.getString("Rot"));
init(manager); init(manager);

View file

@ -5,16 +5,25 @@ import com.minelittlepony.unicopia.UnicopiaCore;
import net.minecraft.structure.StructurePieceType; import net.minecraft.structure.StructurePieceType;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import net.minecraft.world.gen.feature.DefaultFeatureConfig;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.FeatureConfig;
import net.minecraft.world.gen.feature.StructureFeature;
public interface UStructures { public interface UStructures {
StructurePieceType CLOUD_HOUSE_PART = part("cloud_house", CloudDungeonFeature.Piece::new);
StructurePieceType RUIN_PART = part("ruin", RuinFeature.Piece::new);
StructurePieceType CLOUD_HOUSE = register(CloudDungeonFeature.Piece::new, new Identifier(UnicopiaCore.MODID, "cloud_house")); StructureFeature<DefaultFeatureConfig> CLOUD_HOUSE = feature("cloud_house", new CloudDungeonFeature(DefaultFeatureConfig::deserialize));
StructurePieceType RUIN = register(RuinFeature.Piece::new, new Identifier(UnicopiaCore.MODID, "ruin")); StructureFeature<DefaultFeatureConfig> RUIN = feature("ruin", new RuinFeature(DefaultFeatureConfig::deserialize));
static StructurePieceType part(String id, StructurePieceType type) {
static StructurePieceType register(StructurePieceType type, Identifier id) { return Registry.register(Registry.STRUCTURE_PIECE, new Identifier(UnicopiaCore.MODID, id), type);
return Registry.register(Registry.STRUCTURE_PIECE, id, type);
} }
static void bootstrap() {} static <C extends FeatureConfig, F extends Feature<C>> F feature(String id, F feature) {
return Registry.register(Registry.FEATURE, new Identifier(UnicopiaCore.MODID, id), feature);
}
static void bootstrap() { }
} }

View file

@ -30,7 +30,7 @@ public class AwaitTickQueue {
} }
} }
public void onUpdate(World world) { public void tick(World world) {
synchronized (locker) { synchronized (locker) {
delayedTasks = delayedTasks.stream().filter(DelayedTask::tick).collect(Collectors.toList()); delayedTasks = delayedTasks.stream().filter(DelayedTask::tick).collect(Collectors.toList());

View file

@ -0,0 +1,21 @@
package com.minelittlepony.unicopia.util;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.item.HoeItem;
import net.minecraft.item.ItemUsageContext;
public final class HoeUtil extends HoeItem {
private HoeUtil() {
super(null, 0, null);
}
public static void registerTillingAction(Block block, BlockState tilledState) {
TILLED_BLOCKS.put(block, tilledState);
}
@FunctionalInterface
public interface Tillable {
boolean canTill(ItemUsageContext context);
}
}