Moving to source sets

This commit is contained in:
Sebastian Hartte
2020-07-01 23:36:51 +02:00
parent f2e3d81fd7
commit 2642ced86b
2924 changed files with 794 additions and 796 deletions
@@ -1,60 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.block.misc;
import javax.annotation.Nullable;
import net.minecraft.block.Material;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.world.World;
import appeng.block.AEBaseTileBlock;
import appeng.container.ContainerLocator;
import appeng.container.implementations.CellWorkbenchContainer;
import appeng.tile.misc.CellWorkbenchBlockEntity;
import appeng.util.Platform;
public class CellWorkbenchBlock extends AEBaseTileBlock<CellWorkbenchBlockEntity> {
public CellWorkbenchBlock() {
super(defaultProps(Material.METAL));
}
@Override
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity p, final Hand hand,
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
if (p.isInSneakingPose()) {
return ActionResult.PASS;
}
final CellWorkbenchBlockEntity tg = this.getBlockEntity(w, pos);
if (tg != null) {
if (Platform.isServer()) {
CellWorkbenchContainer.open(p, ContainerLocator.forTileEntity(tg));
}
return ActionResult.SUCCESS;
}
return ActionResult.PASS;
}
}
@@ -1,190 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.block.misc;
import java.util.Random;
import java.util.function.Function;
import javax.annotation.Nullable;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.render.model.json.Transformation;
import net.minecraft.client.util.math.AffineTransformation;
import net.minecraft.util.math.Box;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.math.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.block.ShapeContext;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import appeng.api.AEApi;
import appeng.api.util.AEAxisAlignedBB;
import appeng.block.AEBaseTileBlock;
import appeng.client.render.effects.ParticleTypes;
import appeng.client.render.renderable.ItemRenderable;
import appeng.client.render.tesr.ModularTESR;
import appeng.core.AEConfig;
import appeng.core.AppEng;
import appeng.tile.misc.ChargerBlockEntity;
import appeng.util.Platform;
public class ChargerBlock extends AEBaseTileBlock<ChargerBlockEntity> {
public ChargerBlock() {
super(defaultProps(Material.METAL));
}
@Override
public int getOpacity(BlockState state, BlockView worldIn, BlockPos pos) {
return 2; // FIXME Double check this (esp. value range)
}
@Override
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity player, final Hand hand,
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
if (player.isInSneakingPose()) {
return ActionResult.PASS;
}
if (Platform.isServer()) {
final ChargerBlockEntity tc = this.getBlockEntity(w, pos);
if (tc != null) {
tc.activate(player);
}
}
return ActionResult.SUCCESS;
}
@Override
@Environment(EnvType.CLIENT)
public void randomDisplayTick(final BlockState state, final World w, final BlockPos pos, final Random r) {
if (!AEConfig.instance().isEnableEffects()) {
return;
}
if (r.nextFloat() < 0.98) {
return;
}
final ChargerBlockEntity tile = this.getBlockEntity(w, pos);
if (tile != null) {
if (AEApi.instance().definitions().materials().certusQuartzCrystalCharged()
.isSameAs(tile.getInternalInventory().getInvStack(0))) {
final double xOff = 0.0;
final double yOff = 0.0;
final double zOff = 0.0;
for (int bolts = 0; bolts < 3; bolts++) {
if (AppEng.instance().shouldAddParticles(r)) {
MinecraftClient.getInstance().particleManager.addParticle(ParticleTypes.LIGHTNING, xOff + 0.5 + pos.getX(),
yOff + 0.5 + pos.getY(), zOff + 0.5 + pos.getZ(), 0.0, 0.0, 0.0);
}
}
}
}
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView w, BlockPos pos, ShapeContext context) {
final ChargerBlockEntity tile = this.getBlockEntity(w, pos);
if (tile != null) {
final double twoPixels = 2.0 / 16.0;
final Direction up = tile.getUp();
final Direction forward = tile.getForward();
final AEAxisAlignedBB bb = new AEAxisAlignedBB(twoPixels, twoPixels, twoPixels, 1.0 - twoPixels,
1.0 - twoPixels, 1.0 - twoPixels);
if (up.getOffsetX() != 0) {
bb.minX = 0;
bb.maxX = 1;
}
if (up.getOffsetY() != 0) {
bb.minY = 0;
bb.maxY = 1;
}
if (up.getOffsetZ() != 0) {
bb.minZ = 0;
bb.maxZ = 1;
}
switch (forward) {
case DOWN:
bb.maxY = 1;
break;
case UP:
bb.minY = 0;
break;
case NORTH:
bb.maxZ = 1;
break;
case SOUTH:
bb.minZ = 0;
break;
case EAST:
bb.minX = 0;
break;
case WEST:
bb.maxX = 1;
break;
default:
break;
}
return VoxelShapes.cuboid(bb.getBoundingBox());
}
return VoxelShapes.cuboid(new Box(0.0, 0, 0.0, 1.0, 1.0, 1.0));
}
@Override
public VoxelShape getCollisionShape(BlockState state, BlockView worldIn, BlockPos pos,
ShapeContext context) {
return VoxelShapes.cuboid(new Box(0.0, 0.0, 0.0, 1.0, 1.0, 1.0));
}
@Environment(EnvType.CLIENT)
public static Function<BlockEntityRenderDispatcher, BlockEntityRenderer<ChargerBlockEntity>> createTesr() {
return dispatcher -> new ModularTESR<>(dispatcher, new ItemRenderable<>(ChargerBlock::getRenderedItem));
}
@Environment(EnvType.CLIENT)
private static Pair<ItemStack, Transformation> getRenderedItem(ChargerBlockEntity tile) {
Transformation transform = new Transformation(new Vector3f(), new Vector3f(0.5f, 0.375f, 0.5f), new Vector3f(1f, 1f, 1f));
return new ImmutablePair<>(tile.getInternalInventory().getInvStack(0), transform);
}
}
@@ -1,63 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.block.misc;
import javax.annotation.Nullable;
import net.minecraft.block.Material;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
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.world.World;
import appeng.block.AEBaseTileBlock;
import appeng.container.ContainerLocator;
import appeng.container.ContainerOpener;
import appeng.container.implementations.CondenserContainer;
import appeng.tile.misc.CondenserBlockEntity;
import appeng.util.Platform;
public class CondenserBlock extends AEBaseTileBlock<CondenserBlockEntity> {
public CondenserBlock() {
super(defaultProps(Material.METAL));
}
@Override
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity player, final Hand hand,
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
if (player.isInSneakingPose()) {
return ActionResult.PASS;
}
if (Platform.isServer()) {
final CondenserBlockEntity tc = this.getBlockEntity(w, pos);
if (tc != null && !player.isInSneakingPose()) {
ContainerOpener.openContainer(CondenserContainer.TYPE, player,
ContainerLocator.forTileEntitySide(tc, hit.getSide()));
return ActionResult.SUCCESS;
}
}
return ActionResult.SUCCESS;
}
}
@@ -1,68 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.block.misc;
import javax.annotation.Nullable;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
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.world.BlockView;
import net.minecraft.world.World;
import appeng.block.AEBaseTileBlock;
import appeng.container.ContainerLocator;
import appeng.container.ContainerOpener;
import appeng.container.implementations.InscriberContainer;
import appeng.tile.misc.InscriberBlockEntity;
public class InscriberBlock extends AEBaseTileBlock<InscriberBlockEntity> {
public InscriberBlock(Settings props) {
super(props);
}
@Override
public int getOpacity(BlockState state, BlockView worldIn, BlockPos pos) {
return 2; // FIXME validate this. a) possibly not required because of getShape b) value
// range. was 2 in 1.10
}
@Override
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity p, final Hand hand,
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
if (!p.isInSneakingPose()) {
final InscriberBlockEntity tg = this.getBlockEntity(w, pos);
if (tg != null) {
if (!tg.isClient()) {
ContainerOpener.openContainer(InscriberContainer.TYPE, p,
ContainerLocator.forTileEntitySide(tg, hit.getSide()));
}
return ActionResult.SUCCESS;
}
}
return ActionResult.PASS;
}
}
@@ -1,20 +0,0 @@
package appeng.block.misc;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import appeng.bootstrap.TileEntityRendering;
import appeng.bootstrap.TileEntityRenderingCustomizer;
import appeng.client.render.tesr.InscriberTESR;
import appeng.tile.misc.InscriberBlockEntity;
public class InscriberRendering implements TileEntityRenderingCustomizer<InscriberBlockEntity> {
@Environment(EnvType.CLIENT)
@Override
public void customize(TileEntityRendering<InscriberBlockEntity> rendering) {
rendering.tileEntityRenderer(InscriberTESR::new);
}
}
@@ -1,93 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.block.misc;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.StateManager;
import net.minecraft.util.ActionResult;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import appeng.api.util.IOrientable;
import appeng.block.AEBaseTileBlock;
import appeng.container.ContainerLocator;
import appeng.container.ContainerOpener;
import appeng.container.implementations.InterfaceContainer;
import appeng.tile.misc.InterfaceBlockEntity;
import appeng.util.Platform;
public class InterfaceBlock extends AEBaseTileBlock<InterfaceBlockEntity> {
private static final BooleanProperty OMNIDIRECTIONAL = BooleanProperty.of("omnidirectional");
public InterfaceBlock() {
super(defaultProps(Material.METAL));
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
super.appendProperties(builder);
builder.add(OMNIDIRECTIONAL);
}
@Override
protected BlockState updateBlockStateFromTileEntity(BlockState currentState, InterfaceBlockEntity te) {
return currentState.with(OMNIDIRECTIONAL, te.isOmniDirectional());
}
@Override
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity p, final Hand hand,
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
if (p.isInSneakingPose()) {
return ActionResult.PASS;
}
final InterfaceBlockEntity tg = this.getBlockEntity(w, pos);
if (tg != null) {
if (Platform.isServer()) {
ContainerOpener.openContainer(InterfaceContainer.TYPE, p,
ContainerLocator.forTileEntitySide(tg, hit.getSide()));
}
return ActionResult.SUCCESS;
}
return ActionResult.PASS;
}
@Override
protected boolean hasCustomRotation() {
return true;
}
@Override
protected void customRotateBlock(final IOrientable rotatable, final Direction axis) {
if (rotatable instanceof InterfaceBlockEntity) {
((InterfaceBlockEntity) rotatable).setSide(axis);
}
}
}
@@ -0,0 +1,134 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.block.misc;
import net.minecraft.block.*;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
import net.minecraft.world.World;
import appeng.api.util.IOrientable;
import appeng.api.util.IOrientableBlock;
import appeng.block.AEBaseTileBlock;
import appeng.helpers.MetaRotation;
import appeng.tile.misc.LightDetectorBlockEntity;
public class LightDetectorBlock extends AEBaseTileBlock<LightDetectorBlockEntity> implements IOrientableBlock {
// Used to alternate between two variants of the fixture on adjacent blocks
public static final BooleanProperty ODD = BooleanProperty.of("odd");
public LightDetectorBlock() {
super(defaultProps(Material.SUPPORTED));
this.setDefaultState(this.getDefaultState().with(Properties.FACING, Direction.UP).with(ODD, false));
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
super.appendProperties(builder);
builder.add(Properties.FACING);
builder.add(ODD);
}
@Override
public int getWeakRedstonePower(final BlockState state, final BlockView w, final BlockPos pos, final Direction side) {
if (w instanceof World && this.getBlockEntity(w, pos).isReady()) {
// FIXME: This is ... uhm... fishy
return ((World) w).getLightLevel(pos) - 6;
}
return 0;
}
@Override
public boolean emitsRedstonePower(BlockState state) {
return true;
}
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, WorldAccess world, BlockPos pos, BlockPos posFrom) {
final Direction up = this.getOrientable(world, pos).getUp();
if (!this.canPlaceAt(world, pos, up.getOpposite())) {
// FIXME: Double check that this actually updates neighbors
return Blocks.AIR.getDefaultState();
}
final LightDetectorBlockEntity tld = this.getBlockEntity(world, pos);
if (tld != null) {
tld.updateLight();
}
return state;
}
@Override
public boolean isValidOrientation(final WorldAccess w, final BlockPos pos, final Direction forward, final Direction up) {
return this.canPlaceAt(w, pos, up.getOpposite());
}
private boolean canPlaceAt(final BlockView w, final BlockPos pos, final Direction dir) {
final BlockPos test = pos.offset(dir);
BlockState blockstate = w.getBlockState(test);
return blockstate.isSideSolidFullSquare(w, test, dir.getOpposite());
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView w, BlockPos pos, ShapeContext context) {
// FIXME: We should / rather MUST use state here because at startup, this gets
// called without a world
final Direction up = this.getOrientable(w, pos).getUp();
final double xOff = -0.3 * up.getOffsetX();
final double yOff = -0.3 * up.getOffsetY();
final double zOff = -0.3 * up.getOffsetZ();
return VoxelShapes
.cuboid(new Box(xOff + 0.3, yOff + 0.3, zOff + 0.3, xOff + 0.7, yOff + 0.7, zOff + 0.7));
}
@Override
public VoxelShape getCollisionShape(BlockState state, BlockView worldIn, BlockPos pos,
ShapeContext context) {
return VoxelShapes.empty();
}
@Override
public boolean canPlaceAt(BlockState state, WorldView w, BlockPos pos) {
for (final Direction dir : Direction.values()) {
if (this.canPlaceAt(w, pos, dir)) {
return true;
}
}
return false;
}
@Override
public IOrientable getOrientable(final BlockView w, final BlockPos pos) {
return new MetaRotation(w, pos, Properties.FACING);
}
}
@@ -0,0 +1,202 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.block.misc;
import java.util.EnumMap;
import java.util.Map;
import java.util.Random;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.block.Material;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.block.ShapeContext;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
import net.minecraft.world.World;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import appeng.api.util.IOrientable;
import appeng.api.util.IOrientableBlock;
import appeng.block.AEBaseBlock;
import appeng.client.render.effects.ParticleTypes;
import appeng.core.AEConfig;
import appeng.core.AppEng;
import appeng.helpers.MetaRotation;
public class QuartzFixtureBlock extends AEBaseBlock implements IOrientableBlock {
// Cache VoxelShapes for each facing
private static final Map<Direction, VoxelShape> SHAPES;
static {
SHAPES = new EnumMap<>(Direction.class);
for (Direction facing : Direction.values()) {
final double xOff = -0.3 * facing.getOffsetX();
final double yOff = -0.3 * facing.getOffsetY();
final double zOff = -0.3 * facing.getOffsetZ();
VoxelShape shape = VoxelShapes
.cuboid(new Box(xOff + 0.3, yOff + 0.3, zOff + 0.3, xOff + 0.7, yOff + 0.7, zOff + 0.7));
SHAPES.put(facing, shape);
}
}
// Cannot use the vanilla FACING property here because it excludes facing DOWN
public static final DirectionProperty FACING = Properties.FACING;
// Used to alternate between two variants of the fixture on adjacent blocks
public static final BooleanProperty ODD = BooleanProperty.of("odd");
public QuartzFixtureBlock() {
super(defaultProps(Material.SUPPORTED).noCollision().strength(0).lightLevel(14)
.sounds(BlockSoundGroup.GLASS));
this.setDefaultState(getDefaultState().with(FACING, Direction.UP).with(ODD, false));
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(FACING, ODD);
}
// For reference, see WallTorchBlock
@Override
@Nullable
public BlockState getPlacementState(ItemPlacementContext context) {
BlockState blockstate = super.getPlacementState(context);
BlockPos pos = context.getBlockPos();
// Set the even/odd property
boolean oddPlacement = ((pos.getX() + pos.getY() + pos.getZ()) % 2) != 0;
blockstate = blockstate.with(ODD, oddPlacement);
WorldView iworldreader = context.getWorld();
Direction[] adirection = context.getPlacementDirections();
for (Direction direction : adirection) {
if (canPlaceAt(iworldreader, pos, direction)) {
return blockstate.with(FACING, direction.getOpposite());
}
}
return null;
}
// Break the fixture if the block it is attached to is changed so that it could
// no longer be placed
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction facing, BlockState facingState, WorldAccess worldIn,
BlockPos pos, BlockPos facingPos) {
Direction fixtureFacing = state.get(FACING);
if (facing.getOpposite() == fixtureFacing && !canPlaceAt(worldIn, pos, facing)) {
return Blocks.AIR.getDefaultState();
}
return state;
}
@Override
public boolean isValidOrientation(final WorldAccess w, final BlockPos pos, final Direction forward, final Direction up) {
// FIXME: I think this entire method -> not required, but not sure... are quartz
// fixtures rotateable???
return this.canPlaceAt(w, pos, up.getOpposite());
}
private boolean canPlaceAt(final WorldView w, final BlockPos pos, final Direction dir) {
final BlockPos test = pos.offset(dir);
BlockState blockstate = w.getBlockState(test);
return blockstate.isSideSolidFullSquare(w, test, dir.getOpposite());
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView worldIn, BlockPos pos, ShapeContext context) {
Direction facing = state.get(FACING);
return SHAPES.get(facing);
}
@Override
@Environment(EnvType.CLIENT)
public void randomDisplayTick(final BlockState state, final World w, final BlockPos pos, final Random r) {
if (!AEConfig.instance().isEnableEffects()) {
return;
}
if (r.nextFloat() < 0.98) {
return;
}
final Direction up = this.getOrientable(w, pos).getUp();
final double xOff = -0.3 * up.getOffsetX();
final double yOff = -0.3 * up.getOffsetY();
final double zOff = -0.3 * up.getOffsetZ();
for (int bolts = 0; bolts < 3; bolts++) {
if (AppEng.instance().shouldAddParticles(r)) {
w.addParticle(ParticleTypes.LIGHTNING, xOff + 0.5 + pos.getX(), yOff + 0.5 + pos.getY(),
zOff + 0.5 + pos.getZ(), 0, 0, 0);
}
}
}
// FIXME: Replaced by the postPlaceupdate stuff above, but check item drops!
@Override
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos,
boolean isMoving) {
final Direction up = this.getOrientable(world, pos).getUp();
if (!this.canPlaceAt(world, pos, up.getOpposite())) {
this.dropTorch(world, pos);
}
}
private void dropTorch(final World w, final BlockPos pos) {
final BlockState prev = w.getBlockState(pos);
w.breakBlock(pos, true);
w.updateListeners(pos, prev, w.getBlockState(pos), 3);
}
@Override
public boolean canPlaceAt(BlockState state, WorldView w, BlockPos pos) {
for (final Direction dir : Direction.values()) {
if (this.canPlaceAt(w, pos, dir)) {
return true;
}
}
return false;
}
@Override
public IOrientable getOrientable(final BlockView w, final BlockPos pos) {
return new MetaRotation(w, pos, FACING);
}
}
@@ -1,141 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.block.misc;
import java.util.Random;
import net.fabricmc.api.EnvType;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.block.Material;
import net.minecraft.client.MinecraftClient;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.StateManager;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.fabricmc.api.Environment;
import appeng.api.util.IOrientableBlock;
import appeng.block.AEBaseTileBlock;
import appeng.client.render.effects.ParticleTypes;
import appeng.core.AEConfig;
import appeng.core.AppEng;
import appeng.tile.misc.QuartzGrowthAcceleratorBlockEntity;
import appeng.util.Platform;
public class QuartzGrowthAcceleratorBlock extends AEBaseTileBlock<QuartzGrowthAcceleratorBlockEntity>
implements IOrientableBlock {
private static final BooleanProperty POWERED = BooleanProperty.of("powered");
public QuartzGrowthAcceleratorBlock() {
super(defaultProps(Material.STONE).sounds(BlockSoundGroup.METAL));
this.setDefaultState(this.getDefaultState().with(POWERED, false));
}
@Override
protected BlockState updateBlockStateFromTileEntity(BlockState currentState, QuartzGrowthAcceleratorBlockEntity te) {
return currentState.with(POWERED, te.isPowered());
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
super.appendProperties(builder);
builder.add(POWERED);
}
@Environment(EnvType.CLIENT)
@Override
public void randomDisplayTick(final BlockState state, final World w, final BlockPos pos, final Random r) {
if (!AEConfig.instance().isEnableEffects()) {
return;
}
final QuartzGrowthAcceleratorBlockEntity cga = this.getBlockEntity(w, pos);
if (cga != null && cga.isPowered() && AppEng.instance().shouldAddParticles(r)) {
final double d0 = r.nextFloat() - 0.5F;
final double d1 = r.nextFloat() - 0.5F;
final Direction up = cga.getUp();
final Direction forward = cga.getForward();
final Direction west = Platform.crossProduct(forward, up);
double rx = 0.5 + pos.getX();
double ry = 0.5 + pos.getY();
double rz = 0.5 + pos.getZ();
rx += up.getOffsetX() * d0;
ry += up.getOffsetY() * d0;
rz += up.getOffsetZ() * d0;
final int x = pos.getX();
final int y = pos.getY();
final int z = pos.getZ();
double dz = 0;
double dx = 0;
BlockPos pt = null;
switch (r.nextInt(4)) {
case 0:
dx = 0.6;
dz = d1;
pt = new BlockPos(x + west.getOffsetX(), y + west.getOffsetY(), z + west.getOffsetZ());
break;
case 1:
dx = d1;
dz += 0.6;
pt = new BlockPos(x + forward.getOffsetX(), y + forward.getOffsetY(), z + forward.getOffsetZ());
break;
case 2:
dx = d1;
dz = -0.6;
pt = new BlockPos(x - forward.getOffsetX(), y - forward.getOffsetY(), z - forward.getOffsetZ());
break;
case 3:
dx = -0.6;
dz = d1;
pt = new BlockPos(x - west.getOffsetX(), y - west.getOffsetY(), z - west.getOffsetZ());
break;
}
if (!w.getBlockState(pt).isAir()) {
return;
}
rx += dx * west.getOffsetX();
ry += dx * west.getOffsetY();
rz += dx * west.getOffsetZ();
rx += dz * forward.getOffsetX();
ry += dz * forward.getOffsetY();
rz += dz * forward.getOffsetZ();
MinecraftClient.getInstance().particleManager.addParticle(ParticleTypes.LIGHTNING, rx, ry, rz, 0.0D, 0.0D, 0.0D);
}
}
}
@@ -1,82 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.block.misc;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.StateManager;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.world.World;
import appeng.block.AEBaseTileBlock;
import appeng.container.ContainerLocator;
import appeng.container.ContainerOpener;
import appeng.container.implementations.SecurityStationContainer;
import appeng.tile.misc.SecurityStationBlockEntity;
public class SecurityStationBlock extends AEBaseTileBlock<SecurityStationBlockEntity> {
private static final BooleanProperty POWERED = BooleanProperty.of("powered");
public SecurityStationBlock() {
super(defaultProps(Material.METAL));
this.setDefaultState(this.getDefaultState().with(POWERED, false));
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
super.appendProperties(builder);
builder.add(POWERED);
}
@Override
protected BlockState updateBlockStateFromTileEntity(BlockState currentState, SecurityStationBlockEntity te) {
return currentState.with(POWERED, te.isActive());
}
@Override
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity p, final Hand hand,
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
if (p.isInSneakingPose()) {
return ActionResult.PASS;
}
final SecurityStationBlockEntity tg = this.getBlockEntity(w, pos);
if (tg != null) {
if (w.isClient()) {
return ActionResult.SUCCESS;
}
ContainerOpener.openContainer(SecurityStationContainer.TYPE, p,
ContainerLocator.forTileEntitySide(tg, hit.getSide()));
return ActionResult.SUCCESS;
}
return ActionResult.PASS;
}
}
@@ -0,0 +1,158 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.block.misc;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.BlockPos;
import net.minecraft.block.ShapeContext;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
import net.minecraft.world.World;
import appeng.block.AEBaseTileBlock;
import appeng.tile.misc.SkyCompassBlockEntity;
public class SkyCompassBlock extends AEBaseTileBlock<SkyCompassBlockEntity> {
public SkyCompassBlock(Settings props) {
super(props);
}
@Override
public boolean isValidOrientation(final WorldAccess w, final BlockPos pos, final Direction forward, final Direction up) {
final SkyCompassBlockEntity sc = this.getBlockEntity(w, pos);
if (sc != null) {
return false;
}
return this.canPlaceAt(w, pos, forward.getOpposite());
}
private boolean canPlaceAt(final BlockView w, final BlockPos pos, final Direction dir) {
final BlockPos test = pos.offset(dir);
BlockState blockstate = w.getBlockState(test);
return blockstate.isSideSolidFullSquare(w, test, dir.getOpposite());
}
@Override
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos,
boolean isMoving) {
final SkyCompassBlockEntity sc = this.getBlockEntity(world, pos);
final Direction forward = sc.getForward();
if (!this.canPlaceAt(world, pos, forward.getOpposite())) {
this.dropTorch(world, pos);
}
}
private void dropTorch(final World w, final BlockPos pos) {
final BlockState prev = w.getBlockState(pos);
w.breakBlock(pos, true);
w.updateListeners(pos, prev, w.getBlockState(pos), 3);
}
@Override
public boolean canPlaceAt(BlockState state, WorldView w, BlockPos pos) {
for (final Direction dir : Direction.values()) {
if (this.canPlaceAt(w, pos, dir)) {
return true;
}
}
return false;
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView w, BlockPos pos, ShapeContext context) {
// TODO: This definitely needs to be memoized
final SkyCompassBlockEntity tile = this.getBlockEntity(w, pos);
if (tile != null) {
final Direction forward = tile.getForward();
double minX = 0;
double minY = 0;
double minZ = 0;
double maxX = 1;
double maxY = 1;
double maxZ = 1;
switch (forward) {
case DOWN:
minZ = minX = 5.0 / 16.0;
maxZ = maxX = 11.0 / 16.0;
maxY = 1.0;
minY = 14.0 / 16.0;
break;
case EAST:
minZ = minY = 5.0 / 16.0;
maxZ = maxY = 11.0 / 16.0;
maxX = 2.0 / 16.0;
minX = 0.0;
break;
case NORTH:
minY = minX = 5.0 / 16.0;
maxY = maxX = 11.0 / 16.0;
maxZ = 1.0;
minZ = 14.0 / 16.0;
break;
case SOUTH:
minY = minX = 5.0 / 16.0;
maxY = maxX = 11.0 / 16.0;
maxZ = 2.0 / 16.0;
minZ = 0.0;
break;
case UP:
minZ = minX = 5.0 / 16.0;
maxZ = maxX = 11.0 / 16.0;
maxY = 2.0 / 16.0;
minY = 0.0;
break;
case WEST:
minZ = minY = 5.0 / 16.0;
maxZ = maxY = 11.0 / 16.0;
maxX = 1.0;
minX = 14.0 / 16.0;
break;
default:
break;
}
return VoxelShapes.cuboid(new Box(minX, minY, minZ, maxX, maxY, maxZ));
}
return VoxelShapes.empty();
}
@Override
public VoxelShape getCollisionShape(BlockState state, BlockView worldIn, BlockPos pos,
ShapeContext context) {
return VoxelShapes.empty();
}
@Override
public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.ENTITYBLOCK_ANIMATED;
}
}
@@ -19,23 +19,19 @@
package appeng.block.misc;
import net.fabricmc.api.EnvType;
import net.minecraft.client.render.RenderLayer;
import net.fabricmc.api.Environment;
import appeng.api.util.AEColor;
import appeng.bootstrap.BlockRenderingCustomizer;
import appeng.bootstrap.IBlockRendering;
import appeng.bootstrap.IItemRendering;
import appeng.client.render.ColorableTileBlockColor;
import appeng.client.render.StaticItemColor;
import appeng.bootstrap.TileEntityRendering;
import appeng.bootstrap.TileEntityRenderingCustomizer;
import appeng.client.render.tesr.SkyCompassTESR;
import appeng.tile.misc.SkyCompassBlockEntity;
public class SecurityStationRendering extends BlockRenderingCustomizer {
public class SkyCompassRendering implements TileEntityRenderingCustomizer<SkyCompassBlockEntity> {
@Override
@Environment(EnvType.CLIENT)
public void customize(IBlockRendering rendering, IItemRendering itemRendering) {
rendering.renderType(RenderLayer.getCutout());
rendering.blockColor(ColorableTileBlockColor.INSTANCE);
itemRendering.color(new StaticItemColor(AEColor.TRANSPARENT));
public void customize(TileEntityRendering<SkyCompassBlockEntity> rendering) {
rendering.tileEntityRenderer(SkyCompassTESR::new);
}
}
@@ -0,0 +1,146 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.block.misc;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.PersistentProjectileEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.block.ShapeContext;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.explosion.Explosion;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import appeng.block.AEBaseBlock;
import appeng.entity.TinyTNTPrimedEntity;
public class TinyTNTBlock extends AEBaseBlock {
private static final VoxelShape SHAPE = VoxelShapes
.cuboid(new Box(0.25f, 0.0f, 0.25f, 0.75f, 0.5f, 0.75f));
public TinyTNTBlock(Settings props) {
super(props);
}
@Override
public int getOpacity(BlockState state, BlockView worldIn, BlockPos pos) {
return 2; // FIXME: Validate that this is the correct value range
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView worldIn, BlockPos pos, ShapeContext context) {
return SHAPE;
}
@Override
public ActionResult onUse(BlockState state, World w, BlockPos pos, PlayerEntity player, Hand hand,
final BlockHitResult hit) {
ItemStack heldItem = player.getStackInHand(hand);
if (heldItem.getItem() == Items.FLINT_AND_STEEL) {
this.startFuse(w, pos, player);
w.removeBlock(pos, false);
heldItem.damage(1, player, p -> {
p.sendToolBreakStatus(hand);
}); // FIXME Check if onBroken is equivalent
return ActionResult.SUCCESS;
} else {
return super.onUse(state, w, pos, player, hand, hit);
}
}
public void startFuse(final World w, final BlockPos pos, final LivingEntity igniter) {
if (!w.isClient) {
final TinyTNTPrimedEntity primedTinyTNTEntity = new TinyTNTPrimedEntity(w, pos.getX() + 0.5F,
pos.getY(), pos.getZ() + 0.5F, igniter);
w.spawnEntity(primedTinyTNTEntity);
w.playSound(null, primedTinyTNTEntity.getX(), primedTinyTNTEntity.getY(),
primedTinyTNTEntity.getZ(), SoundEvents.ENTITY_TNT_PRIMED, SoundCategory.BLOCKS, 1, 1);
}
}
@Override
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos, boolean notify) {
if (world.isReceivingRedstonePower(pos)) {
this.startFuse(world, pos, null);
world.removeBlock(pos, false);
}
}
@Override
public void onBlockAdded(BlockState state, World w, BlockPos pos, BlockState oldState, boolean isMoving) {
super.onBlockAdded(state, w, pos, oldState, isMoving);
if (w.getReceivedStrongRedstonePower(pos) > 0) {
this.startFuse(w, pos, null);
w.removeBlock(pos, false);
}
}
@Override
public void onSteppedOn(final World w, final BlockPos pos, final Entity entity) {
if (entity instanceof PersistentProjectileEntity && !w.isClient) {
final PersistentProjectileEntity entityarrow = (PersistentProjectileEntity) entity;
if (entityarrow.isOnFire()) {
LivingEntity igniter = null;
// Check if the shooter still exists
Entity shooter = entityarrow.getOwner();
if (shooter instanceof LivingEntity) {
igniter = (LivingEntity) shooter;
}
this.startFuse(w, pos, igniter);
w.removeBlock(pos, false);
}
}
}
@Override
public boolean shouldDropItemsOnExplosion(final Explosion exp) {
return false;
}
@Override
public void onDestroyedByExplosion(final World w, final BlockPos pos, final Explosion exp) {
super.onDestroyedByExplosion(w, pos, exp);
if (!w.isClient) {
final TinyTNTPrimedEntity primedTinyTNTEntity = new TinyTNTPrimedEntity(w, pos.getX() + 0.5F,
pos.getY() + 0.5F, pos.getZ() + 0.5F, exp.getCausingEntity());
primedTinyTNTEntity
.setFuse(w.random.nextInt(primedTinyTNTEntity.getFuse() / 4) + primedTinyTNTEntity.getFuse() / 8);
w.spawnEntity(primedTinyTNTEntity);
}
}
}
@@ -1,126 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.block.misc;
import java.util.Random;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Material;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.StateManager;
import net.minecraft.util.ActionResult;
import net.minecraft.util.math.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.world.World;
import appeng.block.AEBaseTileBlock;
import appeng.container.ContainerLocator;
import appeng.container.ContainerOpener;
import appeng.container.implementations.VibrationChamberContainer;
import appeng.core.AEConfig;
import appeng.tile.misc.VibrationChamberBlockEntity;
import appeng.util.Platform;
public final class VibrationChamberBlock extends AEBaseTileBlock<VibrationChamberBlockEntity> {
// Indicates that the vibration chamber is currently working
private static final BooleanProperty ACTIVE = BooleanProperty.of("active");
public VibrationChamberBlock() {
super(defaultProps(Material.METAL).strength(4.2F));
this.setDefaultState(this.getDefaultState().with(ACTIVE, false));
}
@Override
protected BlockState updateBlockStateFromTileEntity(BlockState currentState, VibrationChamberBlockEntity te) {
return currentState.with(ACTIVE, te.isOn);
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
super.appendProperties(builder);
builder.add(ACTIVE);
}
@Override
public ActionResult onActivated(final World w, final BlockPos pos, final PlayerEntity player, final Hand hand,
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
if (player.isInSneakingPose()) {
return ActionResult.PASS;
}
if (Platform.isServer()) {
final VibrationChamberBlockEntity tc = this.getBlockEntity(w, pos);
if (tc != null && !player.isInSneakingPose()) {
ContainerOpener.openContainer(VibrationChamberContainer.TYPE, player,
ContainerLocator.forTileEntitySide(tc, hit.getSide()));
return ActionResult.SUCCESS;
}
}
return ActionResult.SUCCESS;
}
@Override
public void randomDisplayTick(final BlockState state, final World w, final BlockPos pos, final Random r) {
if (!AEConfig.instance().isEnableEffects()) {
return;
}
final VibrationChamberBlockEntity tile = this.getBlockEntity(w, pos);
if (tile != null && tile.isOn) {
double f1 = pos.getX() + 0.5F;
double f2 = pos.getY() + 0.5F;
double f3 = pos.getZ() + 0.5F;
final Direction forward = tile.getForward();
final Direction up = tile.getUp();
final int west_x = forward.getOffsetY() * up.getOffsetZ() - forward.getOffsetZ() * up.getOffsetY();
final int west_y = forward.getOffsetZ() * up.getOffsetX() - forward.getOffsetX() * up.getOffsetZ();
final int west_z = forward.getOffsetX() * up.getOffsetY() - forward.getOffsetY() * up.getOffsetX();
f1 += forward.getOffsetX() * 0.6;
f2 += forward.getOffsetY() * 0.6;
f3 += forward.getOffsetZ() * 0.6;
final double ox = r.nextDouble();
final double oy = r.nextDouble() * 0.2f;
f1 += up.getOffsetX() * (-0.3 + oy);
f2 += up.getOffsetY() * (-0.3 + oy);
f3 += up.getOffsetZ() * (-0.3 + oy);
f1 += west_x * (0.3 * ox - 0.15);
f2 += west_y * (0.3 * ox - 0.15);
f3 += west_z * (0.3 * ox - 0.15);
w.addParticle(ParticleTypes.SMOKE, f1, f2, f3, 0.0D, 0.0D, 0.0D);
w.addParticle(ParticleTypes.FLAME, f1, f2, f3, 0.0D, 0.0D, 0.0D);
}
}
}