More fixes

This commit is contained in:
Sebastian Hartte
2020-06-29 21:23:50 +02:00
parent 0d63f560d3
commit ca104912d6
121 changed files with 2623 additions and 2563 deletions
@@ -1,202 +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.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.proxy.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,37 +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 net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import appeng.bootstrap.TileEntityRendering;
import appeng.bootstrap.TileEntityRenderingCustomizer;
import appeng.client.render.tesr.SkyCompassTESR;
import appeng.tile.misc.SkyCompassBlockEntity;
public class SkyCompassRendering implements TileEntityRenderingCustomizer<SkyCompassBlockEntity> {
@Override
@Environment(EnvType.CLIENT)
public void customize(TileEntityRendering<SkyCompassBlockEntity> rendering) {
rendering.tileEntityRenderer(SkyCompassTESR::new);
}
}
@@ -1,145 +0,0 @@
/*
* 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 onActivated(final World w, final BlockPos pos, final PlayerEntity player, final Hand hand,
final @Nullable ItemStack heldItem, final BlockHitResult hit) {
if (heldItem != null && 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.onActivated(w, pos, player, hand, heldItem, 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() + 0.5F, 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);
}
}
}