Added changeling hive blocks

This commit is contained in:
Sollace 2019-03-02 12:16:23 +02:00
parent 761baf9f85
commit 412153cac4
22 changed files with 439 additions and 7 deletions

View file

@ -0,0 +1,351 @@
package com.minelittlepony.unicopia.block;
import java.util.Map;
import java.util.Random;
import com.google.common.collect.Maps;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.init.UMaterials;
import com.minelittlepony.unicopia.init.USounds;
import com.minelittlepony.unicopia.player.IPlayer;
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
import com.minelittlepony.util.PosHelper;
import com.minelittlepony.util.shape.IShape;
import com.minelittlepony.util.shape.Sphere;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFalling;
import net.minecraft.block.SoundType;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityFallingBlock;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
public class BlockHiveWall extends BlockFalling {
public static final PropertyEnum<State> STATE = PropertyEnum.create("state", State.class);
public static final PropertyEnum<Axis> AXIS = PropertyEnum.create("axis", Axis.class);
private static final IShape shape = new Sphere(false, 1.5);
public BlockHiveWall(String domain, String name) {
super(UMaterials.hive);
setTranslationKey(name);
setRegistryName(domain, name);
setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
setDefaultState(blockState.getBaseState().withProperty(STATE, State.GROWING).withProperty(AXIS, Axis.Y));
setHardness(2);
setSoundType(SoundType.SLIME);
setHarvestLevel("pickaxe", 1);
setResistance(2);
}
@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
if (rand.nextInt(300) == 0) {
world.playSound(null, pos, USounds.INSECT, SoundCategory.BLOCKS, 1, 1);
}
State type = getState(state);
Axis axis = getAxis(state);
int matchedNeighbours = countNeighbours(world, pos);
if (type == State.GROWING) {
if (testForAxis(world, pos, axis)) {
world.setBlockState(pos, state.withProperty(STATE, State.STABLE));
} else {
Axis newAxis = axis;
for (Axis i : Axis.VALUES) {
if (testForAxis(world, pos, i)) {
newAxis = i;
break;
}
}
if (newAxis != axis) {
world.setBlockState(pos, state.withProperty(AXIS, newAxis).withProperty(STATE, State.STABLE));
} else if (rand.nextInt(10) == 0) {
EnumFacing facing = axis.randomFacing(rand);
BlockPos other = pos.offset(facing);
if (canSpreadInto(world, other, axis)) {
world.playSound(null, pos, USounds.SLIME_RETRACT, SoundCategory.BLOCKS, 1, 1);
world.setBlockState(other, state);
world.setBlockState(pos, state.withProperty(STATE, State.STABLE));
}
}
}
} else if (type == State.DYING) {
if (matchedNeighbours > 1 && matchedNeighbours < 27) {
world.setBlockState(pos, state.withProperty(STATE, State.STABLE));
} else {
die(world, pos, rand);
}
} else {
if (!testForAxis(world, pos, axis)) {
world.setBlockState(pos, state.withProperty(STATE, State.GROWING));
} else if (matchedNeighbours >= 27) {
world.setBlockState(pos, state.withProperty(STATE, State.DYING));
} else {
return;
}
}
world.scheduleUpdate(pos, this, tickRate(world));
}
public State getState(IBlockState state) {
return state.getValue(STATE);
}
public Axis getAxis(IBlockState state) {
return state.getValue(AXIS);
}
@Override
public void onBlockAdded(World world, BlockPos pos, IBlockState state) {
if (state.getValue(STATE) != State.STABLE) {
world.scheduleUpdate(pos, this, 10);
}
}
protected boolean testForAxis(World world, BlockPos pos, Axis axis) {
return !PosHelper.some(pos, world::isAirBlock, axis.getFacings());
}
protected void die(World world, BlockPos pos, Random rand) {
world.destroyBlock(pos, false);
PosHelper.all(pos, p -> {
IBlockState s = world.getBlockState(p);
if (s.getBlock() == this) {
notifyDying(world, p, s, rand);
}
}, EnumFacing.VALUES);
}
protected void notifyDying(World world, BlockPos pos, IBlockState state, Random rand) {
State oldState = state.getValue(STATE);
State newState = oldState.downGrade();
if (newState != oldState) {
world.setBlockState(pos, state.withProperty(STATE, newState));
}
}
@Override
public void onEntityWalk(World world, BlockPos pos, Entity entity) {
this.setResistance(10);
if (entity instanceof EntityPlayer) {
IPlayer player = PlayerSpeciesList.instance().getPlayer((EntityPlayer)entity);
IBlockState state = world.getBlockState(pos);
if (player.getPlayerSpecies() != Race.CHANGELING) {
if (!world.isRemote) {
if (((world.isAirBlock(pos.down()) || canFallThrough(world.getBlockState(pos.down()))) && pos.getY() >= 0)) {
EntityFallingBlock faller = new EntityFallingBlock(world, pos.getX() + 0.5D, pos.getY(), pos.getZ() + 0.5D, state);
onStartFalling(faller);
world.spawnEntity(faller);
}
}
}
}
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (playerIn.getHeldItem(hand).isEmpty()) {
IPlayer player = PlayerSpeciesList.instance().getPlayer(playerIn);
if (player.getPlayerSpecies() == Race.CHANGELING) {
retreat(world, pos);
PosHelper.adjacentNeighbours(pos).forEach(p -> {
if (world.getBlockState(p).getBlock() == this) {
retreat(world, p);
}
});
return true;
}
}
return false;
}
@Override
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
return getDefaultState().withProperty(AXIS, Axis.fromVanilla(facing.getAxis()));
}
@Override
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand) {
if (rand.nextInt(16) == 0) {
Vec3d vel = shape.computePoint(rand);
Vec3d vec = vel.add(pos.getX(), pos.getY(), pos.getZ());
world.spawnParticle(EnumParticleTypes.BLOCK_DUST,
vec.x, vec.y, vec.z,
vel.x, vel.y, vel.z,
Block.getStateId(state));
}
}
public void retreat(World world, BlockPos pos) {
world.setBlockState(pos, Blocks.AIR.getDefaultState());
world.playSound(null, pos, USounds.SLIME_RETRACT, SoundCategory.BLOCKS, 1, 1);
}
protected int countNeighbours(World world, BlockPos pos) {
int count = 0;
for (BlockPos i : BlockPos.getAllInBoxMutable(pos.add(-1, -1, -1), pos.add(1, 1, 1))) {
if (world.getBlockState(i).getBlock() == this) {
count++;
}
}
return count;
}
protected boolean exposed(World world, BlockPos pos) {
return PosHelper.some(pos, world::isAirBlock, EnumFacing.VALUES);
}
protected boolean canSpreadInto(World world, BlockPos pos, Axis axis) {
if (world.isBlockLoaded(pos) && world.isAirBlock(pos)) {
boolean one = false;
for (EnumFacing facing : axis.getFacings()) {
BlockPos op = pos.offset(facing);
if (!world.isAirBlock(op) && !world.getBlockState(op).getMaterial().isLiquid()) {
if (one) {
return true;
}
one = true;
}
}
}
return false;
}
@Override
public IBlockState getStateFromMeta(int meta) {
return getDefaultState()
.withProperty(STATE, State.VALUES[meta % State.VALUES.length])
.withProperty(AXIS, Axis.VALUES[(meta << 2) % Axis.VALUES.length]);
}
@Override
public int getMetaFromState(IBlockState state) {
return getState(state).ordinal() | (getAxis(state).ordinal() >> 2);
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, STATE, AXIS);
}
public static enum State implements IStringSerializable {
GROWING,
STABLE,
DYING;
static final State[] VALUES = values();
@Override
public String toString() {
return getName();
}
@Override
public String getName() {
return name().toLowerCase();
}
public State upgrade() {
switch (this) {
case DYING: return STABLE;
default: return GROWING;
}
}
public State downGrade() {
switch (this) {
case GROWING: return STABLE;
default: return DYING;
}
}
}
public static enum Axis implements IStringSerializable {
X(EnumFacing.Axis.X, EnumFacing.EAST, EnumFacing.WEST, EnumFacing.UP, EnumFacing.DOWN),
Y(EnumFacing.Axis.Y, EnumFacing.EAST, EnumFacing.WEST, EnumFacing.NORTH, EnumFacing.SOUTH),
Z(EnumFacing.Axis.Z, EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.UP, EnumFacing.DOWN);
static final Axis[] VALUES = values();
static final Map<EnumFacing.Axis, Axis> AXIS_MAP = Maps.newEnumMap(EnumFacing.Axis.class);
private final EnumFacing.Axis vanilla;
private final EnumFacing[] facings;
static {
for (Axis i : VALUES) {
AXIS_MAP.put(i.vanilla, i);
}
}
Axis(EnumFacing.Axis vanilla, EnumFacing... facings) {
this.vanilla = vanilla;
this.facings = facings;
}
@Override
public String toString() {
return getName();
}
@Override
public String getName() {
return name().toLowerCase();
}
public EnumFacing randomFacing(Random rand) {
return facings[rand.nextInt(facings.length)];
}
public EnumFacing[] getFacings() {
return facings;
}
public static Axis fromVanilla(EnumFacing.Axis axis) {
return AXIS_MAP.get(axis);
}
}
}

View file

@ -5,6 +5,7 @@ import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.block.BlockAlfalfa;
import com.minelittlepony.unicopia.block.BlockFruitLeaves;
import com.minelittlepony.unicopia.block.BlockGlowingGem;
import com.minelittlepony.unicopia.block.BlockHiveWall;
import com.minelittlepony.unicopia.block.BlockCloudAnvil;
import com.minelittlepony.unicopia.block.BlockCloudBanister;
import com.minelittlepony.unicopia.block.BlockCloudSlab;
@ -69,6 +70,8 @@ public class UBlocks {
public static final BlockCloudFarm cloud_farmland = new BlockCloudFarm(Unicopia.MODID, "cloud_farmland");
public static final BlockHiveWall hive = new BlockHiveWall(Unicopia.MODID, "hive");
public static final Block sugar_block = new BlockSugar(Unicopia.MODID, "sugar_block");
public static final UPot flower_pot = new UPot(Unicopia.MODID, "flower_pot");
@ -88,6 +91,7 @@ public class UBlocks {
packed_cloud_slab, packed_cloud_slab.doubleSlab,
cloud_fence, cloud_banister,
mist_door, library_door, bakery_door,
hive,
anvil, cloud_farmland,
sugar_block, flower_pot,
alfalfa,

View file

@ -95,6 +95,8 @@ public class UItems {
public static final Item anvil = new UItemBlock(UBlocks.anvil, INTERACT_WITH_CLOUDS).setTranslationKey("cloud_anvil");
public static final Item hive = new ItemBlock(UBlocks.hive).setRegistryName(Unicopia.MODID, "hive");
public static final Item mist_door = new ItemDoor(UBlocks.mist_door)
.setTranslationKey("mist_door")
.setRegistryName(Unicopia.MODID, "mist_door");
@ -230,6 +232,8 @@ public class UItems {
cloudsdale_tomato, tomato_seeds, tomato, moss,
hive,
apple_seeds, apple_leaves,
daffodil_daisy_sandwich, hay_burger, hay_fries, salad, wheat_worms,
@ -259,6 +263,8 @@ public class UItems {
cereal, sugar_cereal, sugar_block,
tomato_seeds,
hive,
apple_seeds, apple_leaves,
daffodil_daisy_sandwich, hay_burger, hay_fries, salad, wheat_worms,

View file

@ -5,4 +5,5 @@ import net.minecraft.block.material.Material;
public class UMaterials {
public static final Material cloud = new Material(MapColor.SNOW);
public static final Material hive = new Material(MapColor.NETHERRACK);
}

View file

@ -11,6 +11,10 @@ public class USounds {
public static final SoundEvent WING_FLAP = new USound(Unicopia.MODID, "wing_flap");
public static final SoundEvent WIND_RUSH = new USound(Unicopia.MODID, "wind_rush");
public static final SoundEvent INSECT = new USound(Unicopia.MODID, "insect");
public static final SoundEvent SLIME_ADVANCE = new USound(Unicopia.MODID, "slime_advance");
public static final SoundEvent SLIME_RETRACT = new USound(Unicopia.MODID, "slime_retract");
static void init(IForgeRegistry<SoundEvent> registry) {
registry.registerAll(WING_FLAP, WIND_RUSH);
}

View file

@ -172,11 +172,11 @@ class PlayerGravityDelegate implements IUpdatable, IGravity, InbtSerialisable, I
moveFlying(entity);
if (ticksInAir > 0 && ticksInAir % 12 == 0) {
entity.playSound(USounds.WING_FLAP, 0.5F, 1);
entity.playSound(getWingSound(), 0.5F, 1);
}
} else {
if (ticksInAir != 0) {
entity.playSound(USounds.WING_FLAP, 0.4F, 1);
entity.playSound(getWingSound(), 0.4F, 1);
}
ticksInAir = 0;
@ -185,6 +185,10 @@ class PlayerGravityDelegate implements IUpdatable, IGravity, InbtSerialisable, I
}
}
public SoundEvent getWingSound() {
return player.getPlayerSpecies() == Race.CHANGELING ? USounds.INSECT : USounds.WING_FLAP;
}
protected void moveFlying(EntityPlayer player) {
float forward = 0.00015F * flightExperience * player.moveForward;

View file

@ -2,7 +2,7 @@ package com.minelittlepony.util;
import java.util.Iterator;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;
import com.google.common.collect.Lists;
@ -22,9 +22,9 @@ public class PosHelper {
}
}
public static boolean some(BlockPos origin, Function<BlockPos, Boolean> consumer, EnumFacing... directions) {
public static boolean some(BlockPos origin, Predicate<BlockPos> consumer, EnumFacing... directions) {
for (EnumFacing facing : directions) {
if (consumer.apply(origin.offset(facing))) {
if (consumer.test(origin.offset(facing))) {
return true;
}
}
@ -33,7 +33,7 @@ public class PosHelper {
public static Iterators<MutableBlockPos> adjacentNeighbours(BlockPos origin) {
MutableBlockPos pos = new MutableBlockPos(origin);
Iterator<EnumFacing> directions = Lists.newArrayList(EnumFacing.values()).iterator();
Iterator<EnumFacing> directions = Lists.newArrayList(EnumFacing.VALUES).iterator();
return Iterators.iterate(() -> {
if (directions.hasNext()) {

View file

@ -0,0 +1,13 @@
{
"variants": {
"axis=x,state=growing": { "model": "unicopia:hive_growing" },
"axis=y,state=growing": { "model": "unicopia:hive_growing" },
"axis=z,state=growing": { "model": "unicopia:hive_growing" },
"axis=x,state=stable": { "model": "unicopia:hive_stable" },
"axis=y,state=stable": { "model": "unicopia:hive_stable" },
"axis=z,state=stable": { "model": "unicopia:hive_stable" },
"axis=x,state=dying": { "model": "unicopia:hive_dying" },
"axis=y,state=dying": { "model": "unicopia:hive_dying" },
"axis=z,state=dying": { "model": "unicopia:hive_dying" }
}
}

View file

@ -14,6 +14,8 @@ tile.cloud_fence.name=Cloud Fence
tile.cloud_banister.name=Banister
tile.cloud_farmland.name=Tilled Clouds
tile.hive.name=Hive Wall
tile.apple_leaves.name=Apple Leaves
tile.apple_sapling.name=Apple Seeds
@ -279,4 +281,7 @@ advancements.adventure.unicopia_beginning.description=Found your first gem, but
effect.food_poisoning=Food Poisoning
unicopia.subtitle.flap_wings=Wing Flaps
unicopia.subtitle.wind_rush=Wind Gust
unicopia.subtitle.wind_rush=Wind Gust
unicopia.subtitle.insects=Insects Scurrying
unicopia.subtitle.slime_advance=Squealch
unicopia.subtitle.slime_retract=Sqonk

View file

@ -0,0 +1,6 @@
{
"parent": "block/cube_all",
"textures": {
"all": "unicopia:blocks/hive_dying"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "block/cube_all",
"textures": {
"all": "unicopia:blocks/hive_growing"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "block/cube_all",
"textures": {
"all": "unicopia:blocks/hive_stable"
}
}

View file

@ -0,0 +1,3 @@
{
"parent": "unicopia:block/hive_growing"
}

View file

@ -16,5 +16,28 @@
"unicopia:wind/altitude_wind5",
"unicopia:wind/altitude_wind7"
]
},
"insect": {
"category": "blocks",
"subtitle": "unicopia.subtitle.insects",
"sounds": [
"unicopia:insect/insect_1",
"unicopia:insect/insect_2",
"unicopia:insect/insect_3"
]
},
"slime_advance": {
"category": "blocks",
"subtitle": "unicopia.subtitle.slime_advance",
"sounds": [
"unicopia:slime/advance"
]
},
"slime_retract": {
"category": "blocks",
"subtitle": "unicopia.subtitle.slime_retract",
"sounds": [
"unicopia:slime/retract"
]
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB