added new blocks and further axiom support #17
@ -9,7 +9,6 @@ import net.minecraft.entity.player.PlayerEntity;
|
|||||||
import net.minecraft.item.BlockItem;
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.ItemPlacementContext;
|
import net.minecraft.item.ItemPlacementContext;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.Items;
|
|
||||||
import net.minecraft.nbt.NbtCompound;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.nbt.NbtHelper;
|
import net.minecraft.nbt.NbtHelper;
|
||||||
import net.minecraft.registry.Registries;
|
import net.minecraft.registry.Registries;
|
||||||
@ -85,16 +84,6 @@ public class ReFramedBlock extends Block implements BlockEntityProvider {
|
|||||||
if(theme.getBlock() != Blocks.AIR) drops.add(new ItemStack(theme.getBlock()));
|
if(theme.getBlock() != Blocks.AIR) drops.add(new ItemStack(theme.getBlock()));
|
||||||
});
|
});
|
||||||
|
|
||||||
if(frame_entity.emitsRedstone()
|
|
||||||
&& themes.stream().noneMatch(theme -> theme.getWeakRedstonePower(world, pos, Direction.NORTH) != 0))
|
|
||||||
drops.add(new ItemStack(Items.REDSTONE_TORCH));
|
|
||||||
if(frame_entity.emitsLight()
|
|
||||||
&& themes.stream().noneMatch(theme -> theme.getLuminance() != 0))
|
|
||||||
drops.add(new ItemStack(Items.GLOWSTONE_DUST));
|
|
||||||
if(!frame_entity.isSolid()
|
|
||||||
&& themes.stream().anyMatch(AbstractBlockState::isSolid))
|
|
||||||
drops.add(new ItemStack(Items.POPPED_CHORUS_FRUIT));
|
|
||||||
|
|
||||||
ItemScatterer.spawn(world, pos, drops);
|
ItemScatterer.spawn(world, pos, drops);
|
||||||
}
|
}
|
||||||
super.onStateReplaced(state, world, pos, newState, moved);
|
super.onStateReplaced(state, world, pos, newState, moved);
|
||||||
|
@ -113,7 +113,7 @@ public class ReFramedDoorBlock extends WaterloggableReFramedBlock {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockState onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
|
public BlockState onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
|
||||||
if (!world.isClient() && (player.isCreative() || !player.canHarvest(state))) {
|
if (!world.isClient() && (player.isCreative() || player.canHarvest(state))) {
|
||||||
DoubleBlockHalf half = state.get(DOUBLE_BLOCK_HALF);
|
DoubleBlockHalf half = state.get(DOUBLE_BLOCK_HALF);
|
||||||
BlockPos other_pos = half == DoubleBlockHalf.LOWER ? pos.up() : pos.down();
|
BlockPos other_pos = half == DoubleBlockHalf.LOWER ? pos.up() : pos.down();
|
||||||
BlockState other_state = world.getBlockState(other_pos);
|
BlockState other_state = world.getBlockState(other_pos);
|
||||||
|
@ -6,6 +6,8 @@ import net.minecraft.block.BlockState;
|
|||||||
import net.minecraft.block.ShapeContext;
|
import net.minecraft.block.ShapeContext;
|
||||||
import net.minecraft.item.BlockItem;
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.item.ItemPlacementContext;
|
import net.minecraft.item.ItemPlacementContext;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.loot.context.LootContextParameterSet;
|
||||||
import net.minecraft.state.StateManager;
|
import net.minecraft.state.StateManager;
|
||||||
import net.minecraft.util.BlockMirror;
|
import net.minecraft.util.BlockMirror;
|
||||||
import net.minecraft.util.BlockRotation;
|
import net.minecraft.util.BlockRotation;
|
||||||
@ -14,6 +16,8 @@ import net.minecraft.util.shape.VoxelShape;
|
|||||||
import net.minecraft.world.BlockView;
|
import net.minecraft.world.BlockView;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static fr.adrien1106.reframed.util.VoxelHelper.VoxelListBuilder;
|
import static fr.adrien1106.reframed.util.VoxelHelper.VoxelListBuilder;
|
||||||
import static net.minecraft.state.property.Properties.FACING;
|
import static net.minecraft.state.property.Properties.FACING;
|
||||||
import static net.minecraft.state.property.Properties.LAYERS;
|
import static net.minecraft.state.property.Properties.LAYERS;
|
||||||
@ -27,6 +31,16 @@ public class ReFramedLayerBlock extends ReFramedSlabBlock {
|
|||||||
setDefaultState(getDefaultState().with(LAYERS, 1));
|
setDefaultState(getDefaultState().with(LAYERS, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ItemStack> getDroppedStacks(BlockState state, LootContextParameterSet.Builder builder) {
|
||||||
|
List<ItemStack> drops = super.getDroppedStacks(state, builder);
|
||||||
|
drops.forEach((stack) -> {
|
||||||
|
if (stack.getItem() instanceof BlockItem bi && bi.getBlock() instanceof ReFramedLayerBlock)
|
||||||
|
stack.setCount(state.get(LAYERS));
|
||||||
|
});
|
||||||
|
return drops;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||||
super.appendProperties(builder.add(LAYERS));
|
super.appendProperties(builder.add(LAYERS));
|
||||||
|
@ -2,6 +2,7 @@ package fr.adrien1106.reframed.mixin;
|
|||||||
|
|
||||||
import com.llamalad7.mixinextras.sugar.Local;
|
import com.llamalad7.mixinextras.sugar.Local;
|
||||||
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
|
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
|
||||||
|
import fr.adrien1106.reframed.block.ReFramedBlock;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockEntityProvider;
|
import net.minecraft.block.BlockEntityProvider;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
@ -9,6 +10,7 @@ import net.minecraft.item.BlockItem;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NbtCompound;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.nbt.NbtHelper;
|
import net.minecraft.nbt.NbtHelper;
|
||||||
|
import net.minecraft.state.property.Properties;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
@ -32,8 +34,12 @@ public class BlockItemMixin {
|
|||||||
private static void placeBlockWithOffHandCamo(World world, PlayerEntity player, BlockPos pos, ItemStack stack, CallbackInfoReturnable<Boolean> cir, @Local LocalRef<NbtCompound> compound) {
|
private static void placeBlockWithOffHandCamo(World world, PlayerEntity player, BlockPos pos, ItemStack stack, CallbackInfoReturnable<Boolean> cir, @Local LocalRef<NbtCompound> compound) {
|
||||||
if (compound.get() != null
|
if (compound.get() != null
|
||||||
|| player.getOffHandStack().isEmpty()
|
|| player.getOffHandStack().isEmpty()
|
||||||
|
|| player.getMainHandStack().isEmpty()
|
||||||
|
|| !(player.getMainHandStack().getItem() instanceof BlockItem frame)
|
||||||
|
|| !(frame.getBlock() instanceof ReFramedBlock)
|
||||||
|| !(player.getOffHandStack().getItem() instanceof BlockItem block)
|
|| !(player.getOffHandStack().getItem() instanceof BlockItem block)
|
||||||
|| block.getBlock() instanceof BlockEntityProvider
|
|| block.getBlock() instanceof BlockEntityProvider
|
||||||
|
|| (world.getBlockState(pos).contains(Properties.LAYERS) && world.getBlockState(pos).get(Properties.LAYERS) > 1)
|
||||||
|| !Block.isShapeFullCube(block.getBlock().getDefaultState().getCollisionShape(world, pos))
|
|| !Block.isShapeFullCube(block.getBlock().getDefaultState().getCollisionShape(world, pos))
|
||||||
) return;
|
) return;
|
||||||
NbtCompound new_comp = new NbtCompound();
|
NbtCompound new_comp = new NbtCompound();
|
||||||
|
@ -188,7 +188,6 @@ public class BlockHelper {
|
|||||||
if(!(world.getBlockEntity(pos) instanceof ReFramedEntity block_entity)) return ActionResult.PASS;
|
if(!(world.getBlockEntity(pos) instanceof ReFramedEntity block_entity)) return ActionResult.PASS;
|
||||||
|
|
||||||
ItemStack held = player.getStackInHand(hand);
|
ItemStack held = player.getStackInHand(hand);
|
||||||
ReframedInteractible ext = state.getBlock() instanceof ReframedInteractible e ? e : ReframedInteractible.Default.INSTANCE;
|
|
||||||
|
|
||||||
// frame will emit light if applied with glowstone
|
// frame will emit light if applied with glowstone
|
||||||
if(state.contains(LIGHT) && held.getItem() == Items.GLOWSTONE_DUST) {
|
if(state.contains(LIGHT) && held.getItem() == Items.GLOWSTONE_DUST) {
|
||||||
@ -199,14 +198,14 @@ public class BlockHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// frame will emit redstone if applied with redstone torch can deactivate redstone block camo emission
|
// frame will emit redstone if applied with redstone torch can deactivate redstone block camo emission
|
||||||
if(held.getItem() == Items.REDSTONE_TORCH && ext.canAddRedstoneEmission(state, world, pos)) {
|
if(held.getItem() == Items.REDSTONE_TORCH) {
|
||||||
block_entity.toggleRedstone();
|
block_entity.toggleRedstone();
|
||||||
world.playSound(player, pos, SoundEvents.BLOCK_LEVER_CLICK, SoundCategory.BLOCKS, 1f, 1f);
|
world.playSound(player, pos, SoundEvents.BLOCK_LEVER_CLICK, SoundCategory.BLOCKS, 1f, 1f);
|
||||||
return ActionResult.SUCCESS;
|
return ActionResult.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Frame will lose its collision if applied with popped chorus fruit
|
// Frame will lose its collision if applied with popped chorus fruit
|
||||||
if(held.getItem() == Items.POPPED_CHORUS_FRUIT && ext.canRemoveCollision(state, world, pos)) {
|
if(held.getItem() == Items.POPPED_CHORUS_FRUIT) {
|
||||||
block_entity.toggleSolidity();
|
block_entity.toggleSolidity();
|
||||||
world.playSound(player, pos, SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, SoundCategory.BLOCKS, 1f, 1f);
|
world.playSound(player, pos, SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, SoundCategory.BLOCKS, 1f, 1f);
|
||||||
return ActionResult.SUCCESS;
|
return ActionResult.SUCCESS;
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
package fr.adrien1106.reframed.util.blocks;
|
|
||||||
|
|
||||||
import net.minecraft.block.BlockState;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.Direction;
|
|
||||||
import net.minecraft.world.BlockView;
|
|
||||||
|
|
||||||
public interface ReframedInteractible {
|
|
||||||
default boolean canAddRedstoneEmission(BlockState state, BlockView view, BlockPos pos) {
|
|
||||||
return state.getWeakRedstonePower(view, pos, Direction.UP) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
default boolean canRemoveCollision(BlockState state, BlockView view, BlockPos pos) {
|
|
||||||
return !state.getCollisionShape(view, pos).isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
class Default implements ReframedInteractible {
|
|
||||||
public static final Default INSTANCE = new Default();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user