2015-11-02 12:39:44 -08:00
|
|
|
package WayofTime.bloodmagic.block;
|
2015-10-30 21:20:23 -07:00
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
import WayofTime.bloodmagic.BloodMagic;
|
2018-02-15 18:49:01 -08:00
|
|
|
import WayofTime.bloodmagic.iface.IBindable;
|
2018-03-04 09:17:23 -08:00
|
|
|
import WayofTime.bloodmagic.ritual.imperfect.ImperfectRitualRegistry;
|
|
|
|
import WayofTime.bloodmagic.ritual.RitualRegistry;
|
|
|
|
import WayofTime.bloodmagic.ritual.Ritual;
|
|
|
|
import WayofTime.bloodmagic.ritual.imperfect.ImperfectRitual;
|
2018-02-15 18:49:01 -08:00
|
|
|
import WayofTime.bloodmagic.util.helper.RitualHelper;
|
2017-01-02 00:10:28 -08:00
|
|
|
import WayofTime.bloodmagic.block.base.BlockEnum;
|
2017-08-15 21:30:48 -07:00
|
|
|
import WayofTime.bloodmagic.block.enums.EnumRitualController;
|
|
|
|
import WayofTime.bloodmagic.core.RegistrarBloodMagicItems;
|
|
|
|
import WayofTime.bloodmagic.tile.TileImperfectRitualStone;
|
|
|
|
import WayofTime.bloodmagic.tile.TileMasterRitualStone;
|
|
|
|
import amerifrance.guideapi.api.IGuideLinked;
|
2016-03-18 13:16:38 -04:00
|
|
|
import net.minecraft.block.SoundType;
|
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraft.util.EnumHand;
|
2016-06-05 16:29:36 -07:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2016-03-18 13:16:38 -04:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2017-03-08 18:00:36 -08:00
|
|
|
import net.minecraft.util.text.TextComponentTranslation;
|
2016-03-18 13:16:38 -04:00
|
|
|
import net.minecraft.world.Explosion;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
import javax.annotation.Nullable;
|
2016-06-05 16:29:36 -07:00
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public class BlockRitualController extends BlockEnum<EnumRitualController> implements IGuideLinked {
|
2018-03-04 09:17:23 -08:00
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public BlockRitualController() {
|
2016-10-15 22:02:16 -04:00
|
|
|
super(Material.ROCK, EnumRitualController.class);
|
2015-10-30 21:20:23 -07:00
|
|
|
|
2017-08-14 20:53:42 -07:00
|
|
|
setUnlocalizedName(BloodMagic.MODID + ".stone.ritual.");
|
|
|
|
setCreativeTab(BloodMagic.TAB_BM);
|
2016-03-21 12:55:36 -07:00
|
|
|
setSoundType(SoundType.STONE);
|
2015-10-30 21:20:23 -07:00
|
|
|
setHardness(2.0F);
|
2015-11-02 19:18:53 -08:00
|
|
|
setResistance(5.0F);
|
2015-10-30 21:20:23 -07:00
|
|
|
setHarvestLevel("pickaxe", 2);
|
|
|
|
}
|
|
|
|
|
2015-11-02 17:45:11 -08:00
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
|
2017-01-02 00:10:28 -08:00
|
|
|
ItemStack heldItem = player.getHeldItem(hand);
|
2015-11-02 17:45:11 -08:00
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
if (state.getValue(getProperty()) != EnumRitualController.IMPERFECT && tile instanceof TileMasterRitualStone) {
|
|
|
|
if (heldItem.getItem() == RegistrarBloodMagicItems.ACTIVATION_CRYSTAL) {
|
2018-02-27 16:59:51 -08:00
|
|
|
if (((IBindable) heldItem.getItem()).getBinding(heldItem) == null)
|
2017-02-23 20:01:07 -08:00
|
|
|
return false;
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
String key = RitualHelper.getValidRitual(world, pos);
|
|
|
|
EnumFacing direction = RitualHelper.getDirectionOfRitual(world, pos, key);
|
2017-02-23 20:01:07 -08:00
|
|
|
// TODO: Give a message stating that this ritual is not a valid ritual.
|
2017-08-15 21:30:48 -07:00
|
|
|
if (!key.isEmpty() && direction != null && RitualHelper.checkValidRitual(world, pos, key, direction)) {
|
|
|
|
if (((TileMasterRitualStone) tile).activateRitual(heldItem, player, RitualRegistry.getRitualForId(key))) {
|
2015-12-30 15:34:40 -05:00
|
|
|
((TileMasterRitualStone) tile).setDirection(direction);
|
2017-02-13 19:35:14 -08:00
|
|
|
if (state.getValue(getProperty()) == EnumRitualController.INVERTED)
|
|
|
|
((TileMasterRitualStone) tile).setInverted(true);
|
2015-12-29 09:10:03 -05:00
|
|
|
}
|
2017-08-15 21:30:48 -07:00
|
|
|
} else {
|
2017-03-08 18:00:36 -08:00
|
|
|
player.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.ritual.notValid"), true);
|
2015-12-29 08:44:34 -05:00
|
|
|
}
|
2015-12-26 16:49:25 -08:00
|
|
|
}
|
2017-08-15 21:30:48 -07:00
|
|
|
} else if (state.getValue(getProperty()) == EnumRitualController.IMPERFECT && tile instanceof TileImperfectRitualStone) {
|
2015-11-02 17:45:11 -08:00
|
|
|
|
2018-03-04 09:17:23 -08:00
|
|
|
IBlockState ritualBlock = world.getBlockState(pos.up());
|
|
|
|
return ((TileImperfectRitualStone) tile).performRitual(world, pos, ImperfectRitualRegistry.getRitualForBlock(ritualBlock), player);
|
2015-11-02 17:45:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-26 16:49:25 -08:00
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public void onBlockHarvested(World world, BlockPos pos, IBlockState state, EntityPlayer player) {
|
2015-12-26 16:49:25 -08:00
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
|
|
|
|
|
|
if (getMetaFromState(state) == 0 && tile instanceof TileMasterRitualStone)
|
|
|
|
((TileMasterRitualStone) tile).stopRitual(Ritual.BreakType.BREAK_MRS);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public void onBlockDestroyedByExplosion(World world, BlockPos pos, Explosion explosion) {
|
2015-12-26 16:49:25 -08:00
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
|
|
|
2016-07-13 17:18:34 -04:00
|
|
|
if (tile instanceof TileMasterRitualStone)
|
2015-12-26 16:49:25 -08:00
|
|
|
((TileMasterRitualStone) tile).stopRitual(Ritual.BreakType.EXPLOSION);
|
|
|
|
}
|
|
|
|
|
2015-10-31 17:58:47 -07:00
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public boolean hasTileEntity(IBlockState state) {
|
2016-10-18 16:38:56 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public TileEntity createTileEntity(World world, IBlockState state) {
|
2017-02-13 19:35:14 -08:00
|
|
|
return state.getValue(getProperty()) != EnumRitualController.IMPERFECT ? new TileMasterRitualStone() : new TileImperfectRitualStone();
|
2015-10-31 17:58:47 -07:00
|
|
|
}
|
2016-06-05 16:29:36 -07:00
|
|
|
|
|
|
|
// IGuideLinked
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Nullable
|
2017-08-15 21:30:48 -07:00
|
|
|
public ResourceLocation getLinkedEntry(World world, BlockPos pos, EntityPlayer player, ItemStack stack) {
|
2016-06-05 16:29:36 -07:00
|
|
|
IBlockState state = world.getBlockState(pos);
|
2017-08-15 21:30:48 -07:00
|
|
|
if (state.getValue(getProperty()).equals(EnumRitualController.MASTER)) {
|
2016-06-05 16:29:36 -07:00
|
|
|
TileMasterRitualStone mrs = (TileMasterRitualStone) world.getTileEntity(pos);
|
|
|
|
if (mrs == null || mrs.getCurrentRitual() == null)
|
|
|
|
return null;
|
|
|
|
else
|
|
|
|
return new ResourceLocation("bloodmagic", "ritual_" + mrs.getCurrentRitual().getName());
|
2017-08-15 21:30:48 -07:00
|
|
|
} else if (state.getValue(getProperty()).equals(EnumRitualController.IMPERFECT)) {
|
2018-03-04 09:17:23 -08:00
|
|
|
ImperfectRitual imperfectRitual = ImperfectRitualRegistry.getRitualForBlock(world.getBlockState(pos.up()));
|
2016-06-05 16:29:36 -07:00
|
|
|
if (imperfectRitual != null)
|
|
|
|
return new ResourceLocation("bloodmagic", "ritual_" + imperfectRitual.getName());
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2015-10-30 21:20:23 -07:00
|
|
|
}
|