Skip to content

Commit

Permalink
Made it possible to spawn pharaohs depending on God Torch placed arou…
Browse files Browse the repository at this point in the history
…nd Sarcophagus

Added Quandary Block
Removed Chest Spawner block
  • Loading branch information
GirafiStudios committed Dec 17, 2020
1 parent 6e477ca commit 77f1a24
Show file tree
Hide file tree
Showing 40 changed files with 345 additions and 365 deletions.
146 changes: 146 additions & 0 deletions src/main/java/com/teammetallurgy/atum/blocks/QuandaryBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package com.teammetallurgy.atum.blocks;

import com.teammetallurgy.atum.Atum;
import com.teammetallurgy.atum.api.God;
import com.teammetallurgy.atum.blocks.lighting.INebuTorch;
import com.teammetallurgy.atum.blocks.stone.limestone.LimestoneBrickBlock;
import com.teammetallurgy.atum.blocks.stone.limestone.chest.tileentity.SarcophagusTileEntity;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.DirectionalBlock;
import net.minecraft.block.material.Material;
import net.minecraft.block.material.MaterialColor;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.ItemStack;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.DirectionProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.Explosion;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import net.minecraftforge.common.ToolType;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import javax.annotation.Nonnull;

@Mod.EventBusSubscriber(modid = Atum.MOD_ID)
public class QuandaryBlock extends Block {
public static final DirectionProperty FACING = DirectionalBlock.FACING;
private static final BooleanProperty ACTIVATED = BooleanProperty.create("activated");
public static final BooleanProperty UNBREAKABLE = BooleanProperty.create("unbreakable");

public QuandaryBlock() {
super(Block.Properties.create(Material.ROCK, MaterialColor.SAND).hardnessAndResistance(1.5F, 8.0F).setRequiresTool().harvestTool(ToolType.PICKAXE).harvestLevel(1));
this.setDefaultState(this.stateContainer.getBaseState().with(FACING, Direction.NORTH).with(ACTIVATED, false).with(UNBREAKABLE, false));
}

@SubscribeEvent
public static void onBlockBreak(BlockEvent.BreakEvent event) {
BlockState state = event.getState();
if (state.getBlock() instanceof LimestoneBrickBlock && state.get(LimestoneBrickBlock.UNBREAKABLE) && !event.getPlayer().isCreative()) {
event.setCanceled(true);
}
}

@Override
@Nonnull
public ActionResultType onBlockActivated(@Nonnull BlockState state, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull PlayerEntity player, @Nonnull Hand hand, @Nonnull BlockRayTraceResult hit) {
ItemStack heldStack = player.getHeldItem(Hand.MAIN_HAND);
Block heldBlock = Block.getBlockFromItem(heldStack.getItem());
if (hit.getFace() == state.get(FACING) && heldBlock instanceof INebuTorch && ((INebuTorch) (heldBlock)).isNebuTorch()) {
world.setBlockState(pos, state.with(ACTIVATED, true));
}
return super.onBlockActivated(state, world, pos, player, hand, hit);
}

@Override
public void neighborChanged(@Nonnull BlockState state, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Block block, @Nonnull BlockPos fromPos, boolean isMoving) {
super.neighborChanged(state, world, pos, block, fromPos, isMoving);
if (state.get(ACTIVATED) && !(world.getBlockState(pos.offset(state.get(FACING))).getBlock() instanceof INebuTorch)) {
world.setBlockState(pos, state.with(ACTIVATED, false), 2);
}
}

@Override
public float getExplosionResistance(BlockState state, IBlockReader world, BlockPos pos, Explosion explosion) {
return world.getBlockState(pos).get(UNBREAKABLE) ? 6000000.0F : super.getExplosionResistance(state, world, pos, explosion);
}

@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {
return this.getDefaultState().with(FACING, context.getNearestLookingDirection().getOpposite());
}

@Override
public boolean canProvidePower(@Nonnull BlockState state) {
return true;
}

@Override
public int getStrongPower(BlockState blockState, @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull Direction direction) {
return blockState.getWeakPower(world, pos, direction);
}

@Override
public int getWeakPower(BlockState state, @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull Direction direction) {
return !state.get(ACTIVATED) ? 0 : 15;
}

@Override
public BlockState rotate(BlockState state, IWorld world, BlockPos pos, Rotation rotation) {
return state.with(FACING, rotation.rotate(state.get(FACING)));
}

@Override
@Nonnull
public BlockState mirror(@Nonnull BlockState state, Mirror mirror) {
return state.rotate(mirror.toRotation(state.get(FACING)));
}

@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> container) {
container.add(FACING, ACTIVATED, UNBREAKABLE);
}

public static class Helper {

public static boolean canSpawnPharaoh(World world, BlockPos pos, Direction facing, PlayerEntity player, SarcophagusTileEntity sarcophagus) {
Block topLeftCorner = world.getBlockState(pos.offset(facing.rotateY(), 2).offset(facing.getOpposite(), 1)).getBlock();
Block bottomLeftCorner = world.getBlockState(pos.offset(facing.rotateY(), 2).offset(facing, 2)).getBlock();
Block topRightCorner = world.getBlockState(pos.offset(facing.rotateYCCW(), 3).offset(facing.getOpposite(), 1)).getBlock();
Block bottomRightCorner = world.getBlockState(pos.offset(facing.rotateYCCW(), 3).offset(facing, 2)).getBlock();

if (topLeftCorner instanceof INebuTorch && bottomLeftCorner instanceof INebuTorch && topRightCorner instanceof INebuTorch && bottomRightCorner instanceof INebuTorch) {
INebuTorch torchTopLeftCorner = (INebuTorch) topLeftCorner;
INebuTorch torchBottomLeftCorner = (INebuTorch) bottomLeftCorner;
INebuTorch torchTopRightCorner = (INebuTorch) topRightCorner;
INebuTorch torchBottomRightCorner = (INebuTorch) bottomRightCorner;

if (torchTopLeftCorner.isNebuTorch() && torchBottomLeftCorner.isNebuTorch() && torchTopRightCorner.isNebuTorch() && torchBottomRightCorner.isNebuTorch()) {
playRewardDing(world, pos);

God god = torchTopLeftCorner.getGod();
if (god == torchBottomLeftCorner.getGod() && god == torchTopRightCorner.getGod() && god == torchBottomRightCorner.getGod()) {
sarcophagus.spawn(player, world.getDifficultyForLocation(pos), god);
} else {
sarcophagus.spawn(player, world.getDifficultyForLocation(pos), null);
}
return true;
}
return false;
}
return false;
}

public static void playRewardDing(World world, BlockPos pos) {
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.BLOCK_NOTE_BLOCK_CHIME, SoundCategory.BLOCKS, 1.3F, 1.0F);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.teammetallurgy.atum.blocks.base;
package com.teammetallurgy.atum.blocks.lighting;

import net.minecraft.block.AbstractBlock;
import net.minecraft.block.LanternBlock;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.teammetallurgy.atum.blocks.base;
package com.teammetallurgy.atum.blocks.lighting;

import com.google.common.collect.Maps;
import com.teammetallurgy.atum.api.God;
Expand All @@ -8,21 +8,20 @@
import net.minecraft.block.SoundType;
import net.minecraft.block.TorchBlock;
import net.minecraft.block.material.Material;
import net.minecraft.particles.BasicParticleType;
import net.minecraft.particles.IParticleData;
import net.minecraft.particles.ParticleTypes;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class AtumTorchBlock extends TorchBlock {
public class AtumTorchBlock extends TorchBlock implements INebuTorch {
public static final List<Block> ALL_TORCHES = new ArrayList<>();
public static final Map<Block, Block> UNLIT = Maps.newHashMap();
public static final Map<Block, Block> LIT = Maps.newHashMap();
private BasicParticleType particleType = ParticleTypes.FLAME;

public AtumTorchBlock(int lightValue, BasicParticleType particleType) {
public AtumTorchBlock(int lightValue, IParticleData particleType) {
super(Block.Properties.create(Material.MISCELLANEOUS).doesNotBlockMovement().hardnessAndResistance(0.0F).setLightLevel(s -> lightValue).sound(SoundType.WOOD), particleType);
}

Expand All @@ -32,10 +31,19 @@ public AtumTorchBlock(int lightValue) {

public AtumTorchBlock(@Nullable God god) {
this(14, god == null ? AtumParticles.NEBU_FLAME : NebuFlameParticle.GOD_FLAMES.get(god));
this.particleType = god == null ? AtumParticles.NEBU_FLAME : NebuFlameParticle.GOD_FLAMES.get(god);
}

public BasicParticleType getParticleType() {
return particleType;
public IParticleData getParticleType() {
return this.particleData;
}

@Override
public boolean isNebuTorch() {
return this.getParticleType() != ParticleTypes.FLAME;
}

@Override
public God getGod() {
return NebuFlameParticle.GODS.get(this.getParticleType());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.teammetallurgy.atum.blocks.wood;
package com.teammetallurgy.atum.blocks.lighting;

import com.teammetallurgy.atum.Atum;
import com.teammetallurgy.atum.blocks.base.AtumTorchBlock;
import com.teammetallurgy.atum.misc.StackHelper;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.teammetallurgy.atum.blocks.lighting;

import com.teammetallurgy.atum.api.God;
import com.teammetallurgy.atum.blocks.lighting.INebuTorch;
import com.teammetallurgy.atum.client.particle.NebuFlameParticle;
import net.minecraft.block.WallTorchBlock;
import net.minecraft.particles.BasicParticleType;
import net.minecraft.particles.IParticleData;
import net.minecraft.particles.ParticleTypes;

public class AtumWallTorch extends WallTorchBlock implements INebuTorch {

public AtumWallTorch(Properties properties) {
super(properties, ParticleTypes.FLAME);
}

public AtumWallTorch(Properties properties, IParticleData particleType) {
super(properties, particleType);
}

@Override
public boolean isNebuTorch() {
return this.particleData != ParticleTypes.FLAME;
}

@Override
public God getGod() {
return NebuFlameParticle.GODS.get(this.particleData);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.teammetallurgy.atum.blocks.wood;
package com.teammetallurgy.atum.blocks.lighting;

import com.google.common.collect.Maps;
import net.minecraft.block.Block;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.teammetallurgy.atum.blocks.lighting;

import com.teammetallurgy.atum.api.God;

public interface INebuTorch {

boolean isNebuTorch();

/**
* Make sure to have isNebuTorch check, before calling this.
*/
God getGod();
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.teammetallurgy.atum.blocks.stone.limestone.chest;

import com.teammetallurgy.atum.Atum;
import com.teammetallurgy.atum.blocks.QuandaryBlock;
import com.teammetallurgy.atum.blocks.base.ChestBaseBlock;
import com.teammetallurgy.atum.blocks.stone.limestone.chest.tileentity.SarcophagusTileEntity;
import com.teammetallurgy.atum.init.AtumBlocks;
Expand Down Expand Up @@ -83,15 +84,7 @@ public ActionResultType onBlockActivated(BlockState state, World world, @Nonnull
if (tileEntity instanceof SarcophagusTileEntity) {
SarcophagusTileEntity sarcophagus = (SarcophagusTileEntity) tileEntity;
if (!sarcophagus.hasSpawned) {
if (this.canSpawnPharaoh(world, pos, facing)) {
for (Direction horizontal : Direction.Plane.HORIZONTAL) {
TileEntity tileEntityOffset = world.getTileEntity(pos.offset(horizontal));
if (tileEntityOffset instanceof SarcophagusTileEntity) {
((SarcophagusTileEntity) tileEntityOffset).hasSpawned = true;
}
}
sarcophagus.spawn(player, world.getDifficultyForLocation(pos));
sarcophagus.hasSpawned = true;
if (QuandaryBlock.Helper.canSpawnPharaoh(world, pos, facing, player, sarcophagus)) {
return ActionResultType.PASS;
} else if (!sarcophagus.isOpenable) {
player.sendStatusMessage(new TranslationTextComponent("chat.atum.cannot_spawn_pharaoh").mergeStyle(TextFormatting.RED), true);
Expand All @@ -103,14 +96,6 @@ public ActionResultType onBlockActivated(BlockState state, World world, @Nonnull
return super.onBlockActivated(state, world, pos, player, hand, hit);
}

private boolean canSpawnPharaoh(World world, BlockPos pos, Direction facing) {
boolean isTopLeftCorner = world.getBlockState(pos.offset(facing.rotateY(), 2).offset(facing.getOpposite(), 1)).getBlock() == AtumBlocks.NEBU_TORCH;
boolean isBottomLeftCorner = world.getBlockState(pos.offset(facing.rotateY(), 2).offset(facing, 2)).getBlock() == AtumBlocks.NEBU_TORCH;
boolean isTopRightCorner = world.getBlockState(pos.offset(facing.rotateYCCW(), 3).offset(facing.getOpposite(), 1)).getBlock() == AtumBlocks.NEBU_TORCH;
boolean isBottomRightCorner = world.getBlockState(pos.offset(facing.rotateYCCW(), 3).offset(facing, 2)).getBlock() == AtumBlocks.NEBU_TORCH;
return isTopLeftCorner && isBottomLeftCorner && isTopRightCorner && isBottomRightCorner;
}

@Override
public void onBlockPlacedBy(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nonnull LivingEntity placer, @Nonnull ItemStack stack) {
super.onBlockPlacedBy(world, pos, state, placer, stack);
Expand Down

0 comments on commit 77f1a24

Please sign in to comment.