Fixed the torch

This commit is contained in:
Sollace 2020-04-26 20:26:00 +02:00
parent e1cfe99659
commit 23ce3f27ca
13 changed files with 179 additions and 97 deletions

View file

@ -5,11 +5,10 @@ import java.util.Random;
import com.minelittlepony.unicopia.gas.GasState;
import com.minelittlepony.unicopia.gas.Gas;
import com.minelittlepony.unicopia.particles.MagicParticleEffect;
import com.minelittlepony.unicopia.util.PosHelper;
import net.fabricmc.fabric.api.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.block.TorchBlock;
import net.minecraft.entity.EntityContext;
import net.minecraft.entity.player.PlayerEntity;
@ -17,87 +16,64 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldView;
public class GlowingGemBlock extends TorchBlock implements Gas {
public class GemTorchBlock extends TorchBlock implements Gas {
private static final VoxelShape STANDING = createCuboidShape(7, 0, 7, 9, 16, 9);
public static BooleanProperty ON = BooleanProperty.of("on");
private static final double A = 5/16D;
private static final double B = 6/16D;
private static final double C = 10/16D;
// tiltedOffWall
private static final double F = 10/16D;
// tiltedMinY
private static final double E = 3/16D;
protected static final VoxelShape STANDING_AABB = VoxelShapes.cuboid(new Box(
7/16D, 0, 7/16D,
9/16D, 1, 9/16D
));
protected static final VoxelShape TORCH_NORTH_AABB = VoxelShapes.cuboid(new Box(B, E, F, C, 1, 1));
protected static final VoxelShape TORCH_SOUTH_AABB = VoxelShapes.cuboid(new Box(B, E, 0, C, 1, A));
protected static final VoxelShape TORCH_WEST_AABB = VoxelShapes.cuboid(new Box(F, E, B, 1, 1, C));
protected static final VoxelShape TORCH_EAST_AABB = VoxelShapes.cuboid(new Box(0, E, B, A, 1, C));
public GlowingGemBlock() {
super(FabricBlockSettings.of(Material.PART)
.noCollision()
.strength(0, 0)
.ticksRandomly()
.lightLevel(1)
.sounds(BlockSoundGroup.GLASS)
.build()
);
setDefaultState(stateManager.getDefaultState()
.with(Properties.FACING, Direction.UP)
.with(ON, true)
);
public GemTorchBlock(Settings settings) {
super(settings);
setDefaultState(stateManager.getDefaultState().with(Properties.LIT, true));
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(Properties.FACING).add(ON);
builder.add(Properties.LIT);
}
@Override
public int getTickRate(WorldView worldView) {
return 2;
}
@Override
public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean moved) {
PosHelper.all(pos, p -> world.updateNeighborsAlways(p, this), Direction.values());
}
@Override
public void onBlockRemoved(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
if (!moved) {
PosHelper.all(pos, p -> world.updateNeighborsAlways(p, this), Direction.values());
}
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView source, BlockPos pos, EntityContext context) {
switch (state.get(Properties.FACING)) {
case EAST: return TORCH_EAST_AABB;
case WEST: return TORCH_WEST_AABB;
case SOUTH: return TORCH_SOUTH_AABB;
case NORTH: return TORCH_NORTH_AABB;
default: return STANDING_AABB;
}
return STANDING;
}
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (!state.get(ON)) {
if (!state.get(Properties.LIT)) {
ItemStack held = player.getStackInHand(hand);
if (!held.isEmpty() && (held.getItem() == Items.FLINT_AND_STEEL || held.getItem() == Items.FIRE_CHARGE)) {
world.playSound(null, pos, SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.BLOCKS, 0.5F, 2.6F + (world.random.nextFloat() - world.random.nextFloat()) * 0.8F);
world.setBlockState(pos, state.with(ON, true));
world.setBlockState(pos, state.with(Properties.LIT, true));
if (held.getItem() == Items.FLINT_AND_STEEL) {
held.damage(1, player, p -> p.sendToolBreakStatus(hand));
@ -114,24 +90,25 @@ public class GlowingGemBlock extends TorchBlock implements Gas {
@Override
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random rand) {
Direction facing = state.get(Properties.FACING);
double x = pos.getX() + 0.5;
double y = pos.getY() + 1;
double z = pos.getZ() + 0.5;
double drop = 0.22D;
double variance = 0.27D;
Direction facing = getDirection(state);
if (facing.getAxis().isHorizontal()) {
double drop = 0.22D;
double offsetDistance = 0.27D;
facing = facing.getOpposite();
x += variance * facing.getOffsetX();
x += offsetDistance * facing.getOffsetX();
y += drop;
z += variance * facing.getOffsetZ();
z += offsetDistance * facing.getOffsetZ();
}
if (state.get(ON)) {
if (state.get(Properties.LIT)) {
for (int i = 0; i < 3; i++) {
world.addParticle(MagicParticleEffect.UNICORN,
x - 0.3, y - 0.3, z - 0.3,
@ -142,42 +119,42 @@ public class GlowingGemBlock extends TorchBlock implements Gas {
}
}
protected Direction getDirection(BlockState state) {
return Direction.UP;
}
@Override
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if (world.hasRain(pos)) {
if (state.get(ON)) {
if (state.get(Properties.LIT)) {
world.playSound(null, pos, SoundEvents.BLOCK_REDSTONE_TORCH_BURNOUT, SoundCategory.BLOCKS, 0.5F, 2.6F + (world.random.nextFloat() - world.random.nextFloat()) * 0.8F);
world.setBlockState(pos, state.with(ON, false));
world.setBlockState(pos, state.with(Properties.LIT, false));
}
} else {
if (!state.get(ON)) {
if (!state.get(Properties.LIT)) {
world.playSound(null, pos, SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.BLOCKS, 0.5F, 2.6F + (world.random.nextFloat() - world.random.nextFloat()) * 0.8F);
world.setBlockState(pos, state.with(ON, true));
world.setBlockState(pos, state.with(Properties.LIT, true));
}
}
}
@Override
public int getStrongRedstonePower(BlockState state, BlockView world, BlockPos pos, Direction side) {
return state.get(ON) && side == Direction.DOWN ? state.getWeakRedstonePower(world, pos, side) : 0;
}
@Override
public int getWeakRedstonePower(BlockState state, BlockView world, BlockPos pos, Direction side) {
return state.get(ON) && state.get(Properties.FACING) != side ? 12 : 0;
}
@Override
public GasState getGasState(BlockState blockState) {
return GasState.ENCHANTED;
}
@Override
public int getLuminance(BlockState state) {
if (state.get(ON)) {
return super.getLuminance(state);
public int getStrongRedstonePower(BlockState state, BlockView world, BlockPos pos, Direction side) {
return side == Direction.DOWN ? state.getWeakRedstonePower(world, pos, side) : 0;
}
return 0;
@Override
public int getWeakRedstonePower(BlockState state, BlockView world, BlockPos pos, Direction side) {
return state.get(Properties.LIT) ? 12 : 0;
}
@Override
public int getLuminance(BlockState state) {
return state.get(Properties.LIT) ? super.getLuminance(state) : 0;
}
}

View file

@ -39,7 +39,16 @@ public interface UBlocks {
DutchDoorBlock BAKERY_DOOR = register(new DutchDoorBlock(FabricBlockSettings.of(Material.WOOD).sounds(BlockSoundGroup.WOOD).hardness(3).build()), "bakery_door");
DiamondDoorBlock DIAMOND_DOOR = register(new DiamondDoorBlock(), "diamond_door");
GlowingGemBlock ENCHANTED_TORCH = register(new GlowingGemBlock(), "enchanted_torch");
GemTorchBlock ENCHANTED_TORCH = register(new GemTorchBlock(FabricBlockSettings.of(Material.PART)
.noCollision()
.breakInstantly()
.ticksRandomly()
.lightLevel(1).sounds(BlockSoundGroup.GLASS).build()), "enchanted_torch");
GemTorchBlock ENCHANTED_WALL_TORCH = register(new WallGemTorchBlock(FabricBlockSettings.of(Material.PART)
.noCollision()
.breakInstantly()
.ticksRandomly()
.lightLevel(1).sounds(BlockSoundGroup.GLASS).build()), "enchanted_wall_torch");
CloudAnvilBlock CLOUD_ANVIL = register(new CloudAnvilBlock(), "cloud_anvil");

View file

@ -0,0 +1,93 @@
package com.minelittlepony.unicopia.block;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.EntityContext;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.Properties;
import net.minecraft.util.BlockMirror;
import net.minecraft.util.BlockRotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.IWorld;
import net.minecraft.world.WorldView;
public class WallGemTorchBlock extends GemTorchBlock {
private static final VoxelShape NORTH = createCuboidShape(6, 3, 10, 10, 16, 16);
private static final VoxelShape SOUTH = createCuboidShape(6, 3, 0, 10, 16, 5);
private static final VoxelShape WEST = createCuboidShape(10, 3, 6, 16, 16, 10);
private static final VoxelShape EAST = createCuboidShape(0, 3, 6, 5, 16, 10);
public WallGemTorchBlock(Settings settings) {
super(settings);
setDefaultState(stateManager.getDefaultState()
.with(Properties.HORIZONTAL_FACING, Direction.NORTH)
.with(Properties.LIT, true)
);
}
@Override
@Nullable
public BlockState getPlacementState(ItemPlacementContext ctx) {
BlockState blockState = Blocks.WALL_TORCH.getPlacementState(ctx);
if (blockState != null) {
return getDefaultState().with(Properties.HORIZONTAL_FACING, blockState.get(Properties.HORIZONTAL_FACING));
}
return null;
}
@Override
protected Direction getDirection(BlockState state) {
return state.get(Properties.HORIZONTAL_FACING);
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
return Blocks.WALL_TORCH.canPlaceAt(state, world, pos);
}
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction facing, BlockState neighborState, IWorld world, BlockPos pos, BlockPos neighborPos) {
return Blocks.WALL_TORCH.getStateForNeighborUpdate(state, facing, neighborState, world, pos, neighborPos);
}
@Override
public BlockState rotate(BlockState state, BlockRotation rotation) {
return Blocks.WALL_TORCH.rotate(state, rotation);
}
@Override
public BlockState mirror(BlockState state, BlockMirror mirror) {
return Blocks.WALL_TORCH.mirror(state, mirror);
}
@Override
public int getWeakRedstonePower(BlockState state, BlockView view, BlockPos pos, Direction facing) {
return state.get(Properties.LIT) && state.get(Properties.HORIZONTAL_FACING) != facing ? 12 : 0;
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
super.appendProperties(builder);
builder.add(Properties.HORIZONTAL_FACING);
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView source, BlockPos pos, EntityContext context) {
switch (state.get(Properties.HORIZONTAL_FACING)) {
case EAST: return EAST;
case WEST: return WEST;
case SOUTH: return SOUTH;
case NORTH: return NORTH;
default: return super.getOutlineShape(state, source, pos, context);
}
}
}

View file

@ -21,6 +21,7 @@ import net.minecraft.item.Items;
import net.minecraft.item.MusicDiscItem;
import net.minecraft.item.SpawnEggItem;
import net.minecraft.item.TallBlockItem;
import net.minecraft.item.WallStandingBlockItem;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;
import net.minecraft.util.Rarity;
@ -93,7 +94,7 @@ public interface UItems {
Item ALFALFA_SEEDS = register(new AliasedBlockItem(UBlocks.ALFALFA_CROPS, new Settings().group(ItemGroup.MATERIALS).food(UFoodComponents.ALFALFA_SEEDS)), "alfalfa_seeds");
Item ALFALFA_LEAVES = register(new Item(new Settings().group(ItemGroup.FOOD).food(UFoodComponents.ALFALFA_LEAVES)), "alfalfa_leaves");
Item ENCHANTED_TORCH = register(new BlockItem(UBlocks.ENCHANTED_TORCH, new Settings().group(ItemGroup.DECORATIONS)), "enchanted_torch");
Item ENCHANTED_TORCH = register(new WallStandingBlockItem(UBlocks.ENCHANTED_TORCH, UBlocks.ENCHANTED_WALL_TORCH, new Settings().group(ItemGroup.DECORATIONS)), "enchanted_torch");
Item CEREAL = register(new SugaryItem(new Settings()
.group(ItemGroup.FOOD)

View file

@ -1,16 +1,6 @@
{
"variants": {
"facing=up,on=true": { "model": "unicopia:block/enchanted_torch_on" },
"facing=down,on=true": { "model": "unicopia:block/enchanted_torch_on" },
"facing=east,on=true": { "model": "unicopia:block/enchanted_torch_wall_on" },
"facing=south,on=true": { "model": "unicopia:block/enchanted_torch_wall_on", "y": 90 },
"facing=west,on=true": { "model": "unicopia:block/enchanted_torch_wall_on", "y": 180 },
"facing=north,on=true": { "model": "unicopia:block/enchanted_torch_wall_on", "y": 270 },
"facing=up,on=false": { "model": "unicopia:block/enchanted_torch_off" },
"facing=down,on=false": { "model": "unicopia:block/enchanted_torch_off" },
"facing=east,on=false": { "model": "unicopia:block/enchanted_torch_wall_off" },
"facing=south,on=false": { "model": "unicopia:block/enchanted_torch_wall_off", "y": 90 },
"facing=west,on=false": { "model": "unicopia:block/enchanted_torch_wall_off", "y": 180 },
"facing=north,on=false": { "model": "unicopia:block/enchanted_torch_wall_off", "y": 270 }
"lit=true": { "model": "unicopia:block/enchanted_torch_lit" },
"lit=false": { "model": "unicopia:block/enchanted_torch" }
}
}

View file

@ -0,0 +1,12 @@
{
"variants": {
"facing=east,lit=true": { "model": "unicopia:block/enchanted_wall_torch_lit" },
"facing=south,lit=true": { "model": "unicopia:block/enchanted_wall_torch_lit", "y": 90 },
"facing=west,lit=true": { "model": "unicopia:block/enchanted_wall_torch_lit", "y": 180 },
"facing=north,lit=true": { "model": "unicopia:block/enchanted_wall_torch_lit", "y": 270 },
"facing=east,lit=false": { "model": "unicopia:block/enchanted_wall_torch" },
"facing=south,lit=false": { "model": "unicopia:block/enchanted_wall_torch", "y": 90 },
"facing=west,lit=false": { "model": "unicopia:block/enchanted_wall_torch", "y": 180 },
"facing=north,lit=false": { "model": "unicopia:block/enchanted_wall_torch", "y": 270 }
}
}

View file

@ -1,6 +1,6 @@
{
"parent": "unicopia:block/torch_tall",
"textures": {
"torch": "unicopia:blocks/enchanted_torch_on"
"torch": "unicopia:blocks/enchanted_torch"
}
}

View file

@ -1,6 +1,6 @@
{
"parent": "unicopia:block/torch_tall",
"textures": {
"torch": "unicopia:blocks/enchanted_torch_off"
"torch": "unicopia:blocks/enchanted_torch_lit"
}
}

View file

@ -1,6 +1,6 @@
{
"parent": "unicopia:block/torch_tall_wall",
"textures": {
"torch": "unicopia:blocks/enchanted_torch_on"
"torch": "unicopia:blocks/enchanted_torch"
}
}

View file

@ -1,6 +1,6 @@
{
"parent": "unicopia:block/torch_tall_wall",
"textures": {
"torch": "unicopia:blocks/enchanted_torch_off"
"torch": "unicopia:blocks/enchanted_torch_lit"
}
}

View file

@ -1,6 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "unicopia:blocks/enchanted_torch_on"
"layer0": "unicopia:blocks/enchanted_torch_lit"
}
}