Added hanging cuccoons (WIP)

This commit is contained in:
Sollace 2019-03-02 18:45:28 +02:00
parent 62be8af297
commit e00f9850b3
16 changed files with 518 additions and 4 deletions

View file

@ -0,0 +1,286 @@
package com.minelittlepony.unicopia.block;
import java.util.List;
import java.util.Random;
import javax.annotation.Nullable;
import com.minelittlepony.unicopia.init.UBlocks;
import com.minelittlepony.unicopia.init.UMaterials;
import com.minelittlepony.unicopia.init.USounds;
import com.minelittlepony.util.PosHelper;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.properties.PropertyInteger;
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.init.Items;
import net.minecraft.item.Item;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockGrowingCuccoon extends Block {
public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 7);
public static final PropertyEnum<Shape> SHAPE = PropertyEnum.create("shape", Shape.class);
public static final AxisAlignedBB[] SHAFTS = new AxisAlignedBB[] {
new AxisAlignedBB(7/16F, 0, 7/16F, 9/16F, 1, 7/16F),
new AxisAlignedBB(6/16F, 0, 6/16F, 10/16F, 1, 10/16F),
new AxisAlignedBB(5/16F, 0, 5/16F, 11/16F, 1, 11/16F),
new AxisAlignedBB(4/16F, 0, 4/16F, 12/16F, 1, 12/16F)
};
public static final AxisAlignedBB[] BULBS = new AxisAlignedBB[] {
new AxisAlignedBB(6/16F, 1/16F, 6/16F, 10/16F, 8/16F, 10/16F),
new AxisAlignedBB(4/16F, 0, 4/16F, 12/16F, 9/16F, 12/16F),
new AxisAlignedBB(3/16F, 0, 3/16F, 13/16F, 10/16F, 13/16F),
new AxisAlignedBB(2/16F, 0, 2/16F, 14/16F, 12/16F, 14/16F),
};
public BlockGrowingCuccoon(String domain, String name) {
super(UMaterials.hive);
setTranslationKey(name);
setRegistryName(domain, name);
setResistance(0);
setSoundType(SoundType.SLIME);
setCreativeTab(CreativeTabs.MATERIALS);
setDefaultSlipperiness(0.5F);
setHarvestLevel("shovel", 2);
setLightLevel(0.6F);
setLightOpacity(0);
useNeighborBrightness = true;
setDefaultState(getBlockState().getBaseState()
.withProperty(AGE, 0)
.withProperty(SHAPE, Shape.BULB));
}
@Override
public boolean isTranslucent(IBlockState state) {
return true;
}
@Override
public boolean isOpaqueCube(IBlockState state) {
return false;
}
@Override
//Push player out of block
public boolean isFullCube(IBlockState state) {
return false;
}
@Override
public boolean isNormalCube(IBlockState state) {
return false;
}
@Override
public BlockRenderLayer getRenderLayer() {
return BlockRenderLayer.TRANSLUCENT;
}
@Deprecated
@Override
public AxisAlignedBB getCollisionBoundingBox(IBlockState state, IBlockAccess world, BlockPos pos) {
return getBoundingBox(state, world, pos);
}
@Override
public Block.EnumOffsetType getOffsetType() {
return Block.EnumOffsetType.XZ;
}
@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
if (!checkSupport(world, pos)) {
world.destroyBlock(pos, true);
return;
}
int age = state.getValue(AGE);
BlockPos below = pos.down();
if (world.isBlockLoaded(below)) {
boolean spaceBelow = world.isAirBlock(below);
Shape shape = state.getValue(SHAPE);
if (shape == Shape.STRING && spaceBelow) {
world.setBlockState(pos, state.withProperty(SHAPE, Shape.BULB).withProperty(AGE, age / 2));
} else if (shape == Shape.BULB && !spaceBelow) {
world.setBlockState(pos, state.withProperty(SHAPE, Shape.STRING).withProperty(AGE, age / 2));
} else if (age >= 7) {
if (rand.nextInt(12) == 0 && spaceBelow) {
world.setBlockState(below, state.withProperty(AGE, age / 2));
world.setBlockState(pos, getDefaultState().withProperty(AGE, age / 2).withProperty(SHAPE, Shape.STRING));
world.playSound(null, pos, USounds.SLIME_ADVANCE, SoundCategory.BLOCKS, 1, 1);
}
} else {
if (age < getMaximumAge(world, pos, state, spaceBelow)) {
if (rand.nextInt(5 * (age + 1)) == 0) {
world.setBlockState(pos, state.cycleProperty(AGE));
}
}
}
}
world.scheduleUpdate(pos, this, tickRate(world));
}
protected int getMaximumAge(World world, BlockPos pos, IBlockState state, boolean spaceBelow) {
if (state.getValue(SHAPE) == Shape.STRING) {
IBlockState higher = world.getBlockState(pos.up());
if (higher.getBlock() != this) {
return 7;
}
return ((BlockGrowingCuccoon)higher.getBlock()).getMaximumAge(world, pos.up(), higher, false) - 1;
}
if (!spaceBelow) {
return 0;
}
return 7;
}
@Override
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
return Items.SLIME_BALL;
}
@Override
public void dropBlockAsItemWithChance(World world, BlockPos pos, IBlockState state, float chance, int fortune) {
if (state.getValue(AGE) == 7) {
super.dropBlockAsItemWithChance(world, pos, state, chance, fortune);
}
}
@Override
public boolean canPlaceBlockAt(World world, BlockPos pos) {
return super.canPlaceBlockAt(world, pos) && checkSupport(world, pos);
}
@Override
public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor) {
if (world instanceof World && !checkSupport(world, pos)) {
((World)world).destroyBlock(pos, true);
}
}
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
world.notifyNeighborsOfStateChange(pos, this, true);
super.breakBlock(world, pos, state);
}
@Override
public void onBlockAdded(World world, BlockPos pos, IBlockState state) {
world.scheduleUpdate(pos, this, 10);
}
public boolean checkSupport(IBlockAccess world, BlockPos pos) {
if (PosHelper.some(pos, p -> !world.isAirBlock(p), EnumFacing.HORIZONTALS)) {
return false;
}
pos = pos.up();
IBlockState above = world.getBlockState(pos);
if (above.getBlock() == this || above.getBlock() == UBlocks.hive) {
return true;
}
switch (above.getBlockFaceShape(world, pos, EnumFacing.DOWN)) {
case SOLID:
case CENTER:
case CENTER_BIG:
case CENTER_SMALL: return true;
default: return false;
}
}
@Deprecated
@Override
public void addCollisionBoxToList(IBlockState state, World world, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entity, boolean isActualState) {
if (!isActualState) {
state = state.getActualState(world, pos);
}
int age = state.getValue(AGE) / 2;
Vec3d offset = state.getOffset(world, pos);
addCollisionBoxToList(pos, entityBox, collidingBoxes, SHAFTS[age % SHAFTS.length].offset(offset));
if (state.getValue(SHAPE) == Shape.BULB) {
addCollisionBoxToList(pos, entityBox, collidingBoxes, BULBS[age % BULBS.length].offset(offset));
}
}
@Deprecated
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
state = state.getActualState(source, pos);
if (state.getValue(SHAPE) == Shape.BULB) {
return BULBS[state.getValue(AGE) / 2].offset(state.getOffset(source, pos));
}
return SHAFTS[state.getValue(AGE) / 2].offset(state.getOffset(source, pos));
}
@Override
public IBlockState getStateFromMeta(int meta) {
return getDefaultState()
.withProperty(AGE, meta % 8)
.withProperty(SHAPE, Shape.VALUES[(meta >> 3) % Shape.VALUES.length]);
}
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(AGE) | (state.getValue(SHAPE).ordinal() << 3);
}
@Override
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, AGE, SHAPE);
}
static enum Shape implements IStringSerializable {
BULB,
STRING;
static final Shape[] VALUES = values();
@Override
public String toString() {
return getName();
}
@Override
public String getName() {
return name().toLowerCase();
}
}
}

View file

@ -5,6 +5,7 @@ import java.util.Random;
import com.google.common.collect.Maps;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.init.UBlocks;
import com.minelittlepony.unicopia.init.UMaterials;
import com.minelittlepony.unicopia.init.USounds;
import com.minelittlepony.unicopia.player.IPlayer;
@ -103,7 +104,9 @@ public class BlockHiveWall extends BlockFalling {
}
} else {
if (!testForAxis(world, pos, axis)) {
if (pos.getX() % 3 == 0 && pos.getZ() % 4 == 0 && world.isAirBlock(pos.down()) && UBlocks.cuccoon.canPlaceBlockAt(world, pos.down())) {
world.setBlockState(pos.down(), UBlocks.cuccoon.getDefaultState());
} 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));

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.BlockGrowingCuccoon;
import com.minelittlepony.unicopia.block.BlockHiveWall;
import com.minelittlepony.unicopia.block.BlockCloudAnvil;
import com.minelittlepony.unicopia.block.BlockCloudBanister;
@ -71,6 +72,7 @@ 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 BlockGrowingCuccoon cuccoon = new BlockGrowingCuccoon(Unicopia.MODID, "cuccoon");
public static final Block sugar_block = new BlockSugar(Unicopia.MODID, "sugar_block");
public static final UPot flower_pot = new UPot(Unicopia.MODID, "flower_pot");
@ -91,7 +93,7 @@ public class UBlocks {
packed_cloud_slab, packed_cloud_slab.doubleSlab,
cloud_fence, cloud_banister,
mist_door, library_door, bakery_door,
hive,
hive, cuccoon,
anvil, cloud_farmland,
sugar_block, flower_pot,
alfalfa,

View file

@ -96,6 +96,7 @@ 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 cuccoon = new ItemBlock(UBlocks.cuccoon).setRegistryName(Unicopia.MODID, "cuccoon");
public static final Item mist_door = new ItemDoor(UBlocks.mist_door)
.setTranslationKey("mist_door")
@ -232,7 +233,7 @@ public class UItems {
cloudsdale_tomato, tomato_seeds, tomato, moss,
hive,
hive, cuccoon,
apple_seeds, apple_leaves,
@ -263,7 +264,7 @@ public class UItems {
cereal, sugar_cereal, sugar_block,
tomato_seeds,
hive,
hive, cuccoon,
apple_seeds, apple_leaves,

View file

@ -0,0 +1,20 @@
{
"variants": {
"age=0,shape=bulb": { "model": "unicopia:cuccoon/bulb_stage0" },
"age=1,shape=bulb": { "model": "unicopia:cuccoon/bulb_stage0" },
"age=2,shape=bulb": { "model": "unicopia:cuccoon/bulb_stage1" },
"age=3,shape=bulb": { "model": "unicopia:cuccoon/bulb_stage1" },
"age=4,shape=bulb": { "model": "unicopia:cuccoon/bulb_stage2" },
"age=5,shape=bulb": { "model": "unicopia:cuccoon/bulb_stage2" },
"age=6,shape=bulb": { "model": "unicopia:cuccoon/bulb_stage3" },
"age=7,shape=bulb": { "model": "unicopia:cuccoon/bulb_stage3" },
"age=0,shape=string": { "model": "unicopia:cuccoon/string_stage0" },
"age=1,shape=string": { "model": "unicopia:cuccoon/string_stage0" },
"age=2,shape=string": { "model": "unicopia:cuccoon/string_stage1" },
"age=3,shape=string": { "model": "unicopia:cuccoon/string_stage1" },
"age=4,shape=string": { "model": "unicopia:cuccoon/string_stage2" },
"age=5,shape=string": { "model": "unicopia:cuccoon/string_stage2" },
"age=6,shape=string": { "model": "unicopia:cuccoon/string_stage3" },
"age=7,shape=string": { "model": "unicopia:cuccoon/string_stage3" }
}
}

View file

@ -0,0 +1,30 @@
{
"textures": {
"bulb": "unicopia:blocks/cuccoon_bulb",
"tail": "unicopia:blocks/cuccoon_tail",
"particle": "unicopia:blocks/cuccoon_bulb"
},
"elements": [
{ "from": [ 7, 8, 7 ],
"to": [ 9, 16, 9 ],
"faces": {
"up": { "uv": [ 7, 7, 9, 9 ], "texture": "#tail", "cullface": "up" },
"north": { "uv": [ 7, 8, 9, 16 ], "texture": "#tail", "cullface": "north" },
"south": { "uv": [ 7, 8, 9, 16 ], "texture": "#tail", "cullface": "south" },
"west": { "uv": [ 7, 8, 9, 16 ], "texture": "#tail", "cullface": "west" },
"east": { "uv": [ 7, 8, 9, 16 ], "texture": "#tail", "cullface": "east" }
}
},
{ "from": [ 6, 1, 6 ],
"to": [ 10, 8, 10 ],
"faces": {
"up": { "uv": [ 6, 6, 10, 10 ], "texture": "#bulb" },
"down": { "uv": [ 6, 6, 10, 10 ], "texture": "#bulb" },
"north": { "uv": [ 6, 1, 10, 8 ], "texture": "#bulb" },
"south": { "uv": [ 6, 1, 10, 8 ], "texture": "#bulb" },
"west": { "uv": [ 6, 1, 10, 8 ], "texture": "#bulb" },
"east": { "uv": [ 6, 1, 10, 8 ], "texture": "#bulb" }
}
}
]
}

View file

@ -0,0 +1,30 @@
{
"textures": {
"bulb": "unicopia:blocks/cuccoon_bulb",
"tail": "unicopia:blocks/cuccoon_tail",
"particle": "unicopia:blocks/cuccoon_bulb"
},
"elements": [
{ "from": [ 6, 8, 6 ],
"to": [ 10, 16, 10 ],
"faces": {
"up": { "uv": [ 6, 6, 10, 10 ], "texture": "#tail", "cullface": "up" },
"north": { "uv": [ 6, 8, 10, 16 ], "texture": "#tail", "cullface": "north" },
"south": { "uv": [ 6, 8, 10, 16 ], "texture": "#tail", "cullface": "south" },
"west": { "uv": [ 6, 8, 10, 16 ], "texture": "#tail", "cullface": "west" },
"east": { "uv": [ 6, 8, 10, 16 ], "texture": "#tail", "cullface": "east" }
}
},
{ "from": [ 4, 0, 4 ],
"to": [ 12, 9, 12 ],
"faces": {
"up": { "uv": [ 4, 4, 12, 12 ], "texture": "#bulb" },
"down": { "uv": [ 4, 4, 12, 12 ], "texture": "#bulb" },
"north": { "uv": [ 4, 0, 12, 9 ], "texture": "#bulb" },
"south": { "uv": [ 4, 0, 12, 9 ], "texture": "#bulb" },
"west": { "uv": [ 4, 0, 12, 9 ], "texture": "#bulb" },
"east": { "uv": [ 4, 0, 12, 9 ], "texture": "#bulb" }
}
}
]
}

View file

@ -0,0 +1,30 @@
{
"textures": {
"bulb": "unicopia:blocks/cuccoon_bulb",
"tail": "unicopia:blocks/cuccoon_tail",
"particle": "unicopia:blocks/cuccoon_bulb"
},
"elements": [
{ "from": [ 5, 8, 5 ],
"to": [ 11, 16, 11 ],
"faces": {
"up": { "uv": [ 5, 5, 11, 11 ], "texture": "#tail", "cullface": "up" },
"north": { "uv": [ 5, 8, 11, 16 ], "texture": "#tail", "cullface": "north" },
"south": { "uv": [ 5, 8, 11, 16 ], "texture": "#tail", "cullface": "south" },
"west": { "uv": [ 5, 8, 11, 16 ], "texture": "#tail", "cullface": "west" },
"east": { "uv": [ 5, 8, 11, 16 ], "texture": "#tail", "cullface": "east" }
}
},
{ "from": [ 3, 0, 3 ],
"to": [ 13, 10, 13 ],
"faces": {
"up": { "uv": [ 3, 3, 13, 13 ], "texture": "#bulb" },
"down": { "uv": [ 3, 3, 13, 13 ], "texture": "#bulb" },
"north": { "uv": [ 3, 0, 13, 10 ], "texture": "#bulb" },
"south": { "uv": [ 3, 0, 13, 10 ], "texture": "#bulb" },
"west": { "uv": [ 3, 0, 13, 10 ], "texture": "#bulb" },
"east": { "uv": [ 3, 0, 13, 10 ], "texture": "#bulb" }
}
}
]
}

View file

@ -0,0 +1,30 @@
{
"textures": {
"bulb": "unicopia:blocks/cuccoon_bulb",
"tail": "unicopia:blocks/cuccoon_tail",
"particle": "unicopia:blocks/cuccoon_bulb"
},
"elements": [
{ "from": [ 4, 8, 4 ],
"to": [ 12, 16, 12 ],
"faces": {
"up": { "uv": [ 4, 4, 12, 12 ], "texture": "#tail", "cullface": "up" },
"north": { "uv": [ 4, 8, 12, 16 ], "texture": "#tail", "cullface": "north" },
"south": { "uv": [ 4, 8, 12, 16 ], "texture": "#tail", "cullface": "south" },
"west": { "uv": [ 4, 8, 12, 16 ], "texture": "#tail", "cullface": "west" },
"east": { "uv": [ 4, 8, 12, 16 ], "texture": "#tail", "cullface": "east" }
}
},
{ "from": [ 2, 0, 2 ],
"to": [ 14, 12, 14 ],
"faces": {
"up": { "uv": [ 2, 2, 14, 14 ], "texture": "#bulb" },
"down": { "uv": [ 2, 2, 14, 14 ], "texture": "#bulb" },
"north": { "uv": [ 2, 0, 14, 12 ], "texture": "#bulb" },
"south": { "uv": [ 2, 0, 14, 12 ], "texture": "#bulb" },
"west": { "uv": [ 2, 0, 14, 12 ], "texture": "#bulb" },
"east": { "uv": [ 2, 0, 14, 12 ], "texture": "#bulb" }
}
}
]
}

View file

@ -0,0 +1,19 @@
{
"textures": {
"tail": "unicopia:blocks/cuccoon_tail",
"particle": "unicopia:blocks/cuccoon_tail"
},
"elements": [
{ "from": [ 7, 0, 7 ],
"to": [ 9, 16, 9 ],
"faces": {
"up": { "uv": [ 7, 7, 9, 9 ], "texture": "#tail", "cullface": "up" },
"down": { "uv": [ 7, 7, 9, 9 ], "texture": "#tail", "cullface": "down" },
"north": { "uv": [ 7, 0, 9, 16 ], "texture": "#tail", "cullface": "north" },
"south": { "uv": [ 7, 0, 9, 16 ], "texture": "#tail", "cullface": "south" },
"west": { "uv": [ 7, 0, 9, 16 ], "texture": "#tail", "cullface": "west" },
"east": { "uv": [ 7, 0, 9, 16 ], "texture": "#tail", "cullface": "east" }
}
}
]
}

View file

@ -0,0 +1,19 @@
{
"textures": {
"tail": "unicopia:blocks/cuccoon_tail",
"particle": "unicopia:blocks/cuccoon_tail"
},
"elements": [
{ "from": [ 6, 0, 6 ],
"to": [ 10, 16, 10 ],
"faces": {
"up": { "uv": [ 6, 6, 10, 10 ], "texture": "#tail", "cullface": "up" },
"down": { "uv": [ 6, 6, 10, 10 ], "texture": "#tail", "cullface": "down" },
"north": { "uv": [ 6, 0, 10, 16 ], "texture": "#tail", "cullface": "north" },
"south": { "uv": [ 6, 0, 10, 16 ], "texture": "#tail", "cullface": "south" },
"west": { "uv": [ 6, 0, 10, 16 ], "texture": "#tail", "cullface": "west" },
"east": { "uv": [ 6, 0, 10, 16 ], "texture": "#tail", "cullface": "east" }
}
}
]
}

View file

@ -0,0 +1,19 @@
{
"textures": {
"tail": "unicopia:blocks/cuccoon_tail",
"particle": "unicopia:blocks/cuccoon_tail"
},
"elements": [
{ "from": [ 5, 0, 5 ],
"to": [ 11, 16, 11 ],
"faces": {
"up": { "uv": [ 5, 5, 11, 11 ], "texture": "#tail", "cullface": "up" },
"down": { "uv": [ 5, 5, 11, 11 ], "texture": "#tail", "cullface": "down" },
"north": { "uv": [ 5, 0, 11, 16 ], "texture": "#tail", "cullface": "north" },
"south": { "uv": [ 5, 0, 11, 16 ], "texture": "#tail", "cullface": "south" },
"west": { "uv": [ 5, 0, 11, 16 ], "texture": "#tail", "cullface": "west" },
"east": { "uv": [ 5, 0, 11, 16 ], "texture": "#tail", "cullface": "east" }
}
}
]
}

View file

@ -0,0 +1,19 @@
{
"textures": {
"tail": "unicopia:blocks/cuccoon_tail",
"particle": "unicopia:blocks/cuccoon_tail"
},
"elements": [
{ "from": [ 4, 0, 4 ],
"to": [ 12, 16, 12 ],
"faces": {
"up": { "uv": [ 4, 4, 12, 12 ], "texture": "#tail", "cullface": "up" },
"down": { "uv": [ 4, 4, 12, 12 ], "texture": "#tail", "cullface": "down" },
"north": { "uv": [ 4, 0, 12, 16 ], "texture": "#tail", "cullface": "north" },
"south": { "uv": [ 4, 0, 12, 16 ], "texture": "#tail", "cullface": "south" },
"west": { "uv": [ 4, 0, 12, 16 ], "texture": "#tail", "cullface": "west" },
"east": { "uv": [ 4, 0, 12, 16 ], "texture": "#tail", "cullface": "east" }
}
}
]
}

View file

@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "minecraft:items/apple"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB