mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-06 00:49:09 +01:00
Tiny torch implementation
This commit is contained in:
parent
5eec8071d0
commit
ca67ccfc45
11 changed files with 199 additions and 17 deletions
|
@ -40,6 +40,7 @@ public class AABlocks {
|
|||
public static final ColoredLampBlock GREEN_LAMP = null;
|
||||
public static final ColoredLampBlock RED_LAMP = null;
|
||||
public static final ColoredLampBlock BLACK_LAMP = null;
|
||||
public static final TinyTorchBlock TINY_TORCH = null;
|
||||
|
||||
@SubscribeEvent
|
||||
public static void register(Register<Block> e) {
|
||||
|
@ -65,7 +66,8 @@ public class AABlocks {
|
|||
new ColoredLampBlock(LampColor.BROWN).setRegistryName("brown_lamp"),
|
||||
new ColoredLampBlock(LampColor.GREEN).setRegistryName("green_lamp"),
|
||||
new ColoredLampBlock(LampColor.RED).setRegistryName("red_lamp"),
|
||||
new ColoredLampBlock(LampColor.BLACK).setRegistryName("black_lamp")
|
||||
new ColoredLampBlock(LampColor.BLACK).setRegistryName("black_lamp"),
|
||||
new TinyTorchBlock()
|
||||
);
|
||||
//Formatter::on
|
||||
}
|
||||
|
@ -78,7 +80,8 @@ public class AABlocks {
|
|||
new BlockItem(BLACK_QUARTZ_BLOCK, new Item.Properties().group(ActuallyAdditions.GROUP)).setRegistryName(BLACK_QUARTZ_BLOCK.getRegistryName()),
|
||||
new BlockItem(CHISELED_BLACK_QUARTZ_BLOCK, new Item.Properties().group(ActuallyAdditions.GROUP)).setRegistryName(CHISELED_BLACK_QUARTZ_BLOCK.getRegistryName()),
|
||||
new BlockItem(BLACK_QUARTZ_PILLAR, new Item.Properties().group(ActuallyAdditions.GROUP)).setRegistryName(BLACK_QUARTZ_PILLAR.getRegistryName()),
|
||||
new BlockItem(BLACK_QUARTZ_SLAB, new Item.Properties().group(ActuallyAdditions.GROUP)).setRegistryName(BLACK_QUARTZ_SLAB.getRegistryName())
|
||||
new BlockItem(BLACK_QUARTZ_SLAB, new Item.Properties().group(ActuallyAdditions.GROUP)).setRegistryName(BLACK_QUARTZ_SLAB.getRegistryName()),
|
||||
new BlockItem(TINY_TORCH, new Item.Properties().group(ActuallyAdditions.GROUP)).setRegistryName(TINY_TORCH.getRegistryName())
|
||||
);
|
||||
//Formatter::on
|
||||
for (Block b : ColoredLampBlock.LAMPS.values()) {
|
||||
|
|
|
@ -0,0 +1,159 @@
|
|||
package de.ellpeck.actuallyadditions.mod.block;
|
||||
|
||||
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.item.ItemEntity;
|
||||
import net.minecraft.item.BlockItemUseContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.particles.ParticleTypes;
|
||||
import net.minecraft.state.DirectionProperty;
|
||||
import net.minecraft.state.StateContainer;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.Mirror;
|
||||
import net.minecraft.util.Rotation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.shapes.ISelectionContext;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
import net.minecraft.util.math.shapes.VoxelShapes;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
import net.minecraft.world.IWorldReader;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Random;
|
||||
|
||||
public class TinyTorchBlock extends Block {
|
||||
|
||||
public static final DirectionProperty FACING_EXCEPT_DOWN = DirectionProperty.create("facing", direction -> direction != Direction.DOWN);
|
||||
|
||||
private static final Properties PROPERTIES = Properties.create(Material.MISCELLANEOUS).hardnessAndResistance(0).lightValue(11).sound(SoundType.WOOD).tickRandomly();
|
||||
private static final VoxelShape STANDING_SHAPE = VoxelShapes.create(0.4375D, 0.0D, 0.4375D, 0.5625D, 0.3125D, 0.5625D);
|
||||
private static final VoxelShape TORCH_NORTH_SHAPE = VoxelShapes.create(0.4375D, 0.25D, 0.8125D, 0.5625D, 0.5625D, 1.0D);
|
||||
private static final VoxelShape TORCH_SOUTH_SHAPE = VoxelShapes.create(0.4375D, 0.25D, 0.0D, 0.5625D, 0.5625D, 0.1875D);
|
||||
private static final VoxelShape TORCH_WEST_SHAPE = VoxelShapes.create(0.8125D, 0.25D, 0.4375D, 1.0D, 0.5625D, 0.5625D);
|
||||
private static final VoxelShape TORCH_EAST_SHAPE = VoxelShapes.create(0.0D, 0.25D, 0.4375D, 0.1875D, 0.5625D, 0.5625D);
|
||||
|
||||
public TinyTorchBlock(){
|
||||
super(PROPERTIES);
|
||||
|
||||
this.setRegistryName(ActuallyAdditions.MODID, "tiny_torch");
|
||||
this.setDefaultState(this.getStateContainer().getBaseState().with(FACING_EXCEPT_DOWN, Direction.UP));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public VoxelShape getShape(@Nonnull BlockState state, @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull ISelectionContext context){
|
||||
switch(state.get(FACING_EXCEPT_DOWN)){
|
||||
case EAST:
|
||||
return TORCH_EAST_SHAPE;
|
||||
case WEST:
|
||||
return TORCH_WEST_SHAPE;
|
||||
case SOUTH:
|
||||
return TORCH_SOUTH_SHAPE;
|
||||
case NORTH:
|
||||
return TORCH_NORTH_SHAPE;
|
||||
default:
|
||||
return STANDING_SHAPE;
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public VoxelShape getCollisionShape(@Nonnull BlockState state, @Nonnull IBlockReader worldIn, @Nonnull BlockPos pos, @Nonnull ISelectionContext context){
|
||||
return VoxelShapes.empty();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public BlockRenderLayer getRenderLayer(){
|
||||
return BlockRenderLayer.CUTOUT;
|
||||
}
|
||||
|
||||
private boolean canPlaceAt(@Nonnull IWorldReader world, @Nonnull BlockPos pos, @Nonnull Direction direction){
|
||||
BlockPos blockpos = pos.offset(direction.getOpposite());
|
||||
return (direction.getAxis().isHorizontal() && hasSolidSide(world.getBlockState(blockpos), world, blockpos, direction)) || (direction.equals(Direction.UP) && hasSolidSideOnTop(world, blockpos));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidPosition(@Nonnull BlockState state, @Nonnull IWorldReader world, @Nonnull BlockPos pos){
|
||||
for(Direction direction : FACING_EXCEPT_DOWN.getAllowedValues()){
|
||||
if(this.canPlaceAt(world, pos, direction)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BlockState getStateForPlacement(@Nonnull BlockItemUseContext context){
|
||||
World world = context.getWorld();
|
||||
BlockPos pos = context.getPos();
|
||||
Direction placementDirection = context.getFace();
|
||||
if(this.canPlaceAt(world, pos, placementDirection)){
|
||||
return this.getDefaultState().with(FACING_EXCEPT_DOWN, placementDirection);
|
||||
} else{
|
||||
for(Direction direction : Direction.Plane.HORIZONTAL){
|
||||
if(hasSolidSide(world.getBlockState(pos), world, pos.offset(direction.getOpposite()), direction)){
|
||||
return this.getDefaultState().with(FACING_EXCEPT_DOWN, direction);
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.getStateForPlacement(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void neighborChanged(@Nonnull BlockState state, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Block block, @Nonnull BlockPos fromPos, boolean isMoving){
|
||||
Direction direction = state.get(FACING_EXCEPT_DOWN);
|
||||
if(!this.canPlaceAt(world, pos, direction)){
|
||||
world.addEntity(new ItemEntity(world, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, new ItemStack(this)));
|
||||
world.setBlockState(pos, Blocks.AIR.getDefaultState());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void animateTick(@Nonnull BlockState state, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Random rand){
|
||||
if(rand.nextBoolean()){
|
||||
Direction direction = state.get(FACING_EXCEPT_DOWN);
|
||||
double d0 = pos.getX() + 0.5D;
|
||||
double d1 = pos.getY() + 0.4D;
|
||||
double d2 = pos.getZ() + 0.5D;
|
||||
|
||||
if(direction.getAxis().isHorizontal()){
|
||||
Direction direction1 = direction.getOpposite();
|
||||
world.addParticle(ParticleTypes.SMOKE, d0 + 0.35D * direction1.getXOffset(), d1 + 0.22D, d2 + 0.35D * direction1.getZOffset(), 0.0D, 0.0D, 0.0D);
|
||||
world.addParticle(ParticleTypes.FLAME, d0 + 0.35D * direction1.getXOffset(), d1 + 0.22D, d2 + 0.35D * direction1.getZOffset(), 0.0D, 0.0D, 0.0D);
|
||||
} else{
|
||||
world.addParticle(ParticleTypes.SMOKE, d0, d1, d2, 0.0D, 0.0D, 0.0D);
|
||||
world.addParticle(ParticleTypes.FLAME, d0, d1, d2, 0.0D, 0.0D, 0.0D);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public BlockState rotate(@Nonnull BlockState state, @Nonnull Rotation rot){
|
||||
return state.with(FACING_EXCEPT_DOWN, rot.rotate(state.get(FACING_EXCEPT_DOWN)));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public BlockState mirror(@Nonnull BlockState state, @Nonnull Mirror mirrorIn){
|
||||
return state.rotate(mirrorIn.toRotation(state.get(FACING_EXCEPT_DOWN)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillStateContainer(@Nonnull StateContainer.Builder<Block, BlockState> builder){
|
||||
builder.add(FACING_EXCEPT_DOWN);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"variants": {
|
||||
"facing=up": { "model": "actuallyadditions:block/tiny_torch_block" },
|
||||
"facing=east": { "model": "actuallyadditions:block/tiny_torch_wall_block" },
|
||||
"facing=south": { "model": "actuallyadditions:block/tiny_torch_wall_block", "y": 90 },
|
||||
"facing=west": { "model": "actuallyadditions:block/tiny_torch_wall_block", "y": 180 },
|
||||
"facing=north": { "model": "actuallyadditions:block/tiny_torch_wall_block", "y": 270 }
|
||||
}
|
||||
}
|
|
@ -21,6 +21,7 @@
|
|||
"block.actuallyadditions.brown_lamp": "Brown Lamp",
|
||||
"block.actuallyadditions.green_lamp": "Green Lamp",
|
||||
"block.actuallyadditions.red_lamp": "Red Lamp",
|
||||
"block.actuallyadditions.black_lamp": "Black Lamp"
|
||||
"block.actuallyadditions.black_lamp": "Black Lamp",
|
||||
"block.actuallyadditions.tiny_torch": "Tiny Torch"
|
||||
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"ambientocclusion": false,
|
||||
"textures": {
|
||||
"particle": "actuallyadditions:blocks/block_tiny_torch",
|
||||
"torch": "actuallyadditions:blocks/block_tiny_torch"
|
||||
"particle": "actuallyadditions:block/tiny_torch_block",
|
||||
"torch": "actuallyadditions:block/tiny_torch_block"
|
||||
},
|
||||
"elements": [
|
||||
{ "from": [ 7, 0, 7 ],
|
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"ambientocclusion": false,
|
||||
"textures": {
|
||||
"particle": "actuallyadditions:blocks/block_tiny_torch",
|
||||
"torch": "actuallyadditions:blocks/block_tiny_torch"
|
||||
"particle": "actuallyadditions:block/tiny_torch_block",
|
||||
"torch": "actuallyadditions:block/tiny_torch_block"
|
||||
},
|
||||
"elements": [
|
||||
{ "from": [ -1, 3.5, 7 ],
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"parent": "actuallyadditions:item/standard_item",
|
||||
"textures": {
|
||||
"layer0": "actuallyadditions:blocks/block_tiny_torch"
|
||||
"layer0": "actuallyadditions:block/tiny_torch_block"
|
||||
}
|
||||
}
|
Before Width: | Height: | Size: 232 B After Width: | Height: | Size: 232 B |
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"rolls": 1,
|
||||
"entries": [
|
||||
{
|
||||
"type": "minecraft:item",
|
||||
"name": "actuallyadditions:tiny_torch"
|
||||
}
|
||||
],
|
||||
"conditions": [
|
||||
{
|
||||
"condition": "minecraft:survives_explosion"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
{
|
||||
"variants": {
|
||||
"facing=up": { "model": "actuallyadditions:block_tiny_torch" },
|
||||
"facing=east": { "model": "actuallyadditions:block_tiny_torch_wall" },
|
||||
"facing=south": { "model": "actuallyadditions:block_tiny_torch_wall", "y": 90 },
|
||||
"facing=west": { "model": "actuallyadditions:block_tiny_torch_wall", "y": 180 },
|
||||
"facing=north": { "model": "actuallyadditions:block_tiny_torch_wall", "y": 270 }
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue