Implemented BloodAltar modification with redstone lamp below altar (#1635)

* Implemented BloodAltar modification with redstone lamp below altar

- strong and weak Redstone signal of power 15 (similar to BlockLever)
- activates when crafting finishes and a BlockRedstoneLight is directly below the altar
- deactivates when the next crafting cycle is about to begin

Use case:

- Redstone-controlled automatic ejection of crafted goods

* Removed Docs

* Meta to use 0 for off, 1 for on

* Syntactic sugar & storing value
This commit is contained in:
Tobias 2019-09-05 03:55:53 +02:00 committed by Nick Ignoffo
parent 4f1308874d
commit a23cd35556
3 changed files with 67 additions and 1 deletions

View file

@ -3,8 +3,10 @@ package WayofTime.bloodmagic.altar;
import WayofTime.bloodmagic.api.event.BloodMagicCraftedEvent;
import WayofTime.bloodmagic.api.impl.BloodMagicAPI;
import WayofTime.bloodmagic.api.impl.recipe.RecipeBloodAltar;
import WayofTime.bloodmagic.block.BlockAltar;
import WayofTime.bloodmagic.block.BlockLifeEssence;
import WayofTime.bloodmagic.block.enums.BloodRuneType;
import WayofTime.bloodmagic.core.RegistrarBloodMagicBlocks;
import WayofTime.bloodmagic.core.data.Binding;
import WayofTime.bloodmagic.core.data.SoulTicket;
import WayofTime.bloodmagic.iface.IBindable;
@ -14,6 +16,7 @@ import WayofTime.bloodmagic.tile.TileAltar;
import WayofTime.bloodmagic.util.Constants;
import WayofTime.bloodmagic.util.helper.NetworkHelper;
import com.google.common.base.Enums;
import net.minecraft.block.BlockRedstoneLight;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -239,8 +242,15 @@ public class BloodAltar implements IFluidHandler {
tileAltar.getWorld().notifyBlockUpdate(tileAltar.getPos(), tileAltar.getWorld().getBlockState(tileAltar.getPos()), tileAltar.getWorld().getBlockState(tileAltar.getPos()), 3);
}
if (internalCounter % 100 == 0 && (this.isActive || this.cooldownAfterCrafting <= 0))
if (internalCounter % 100 == 0 && (this.isActive || this.cooldownAfterCrafting <= 0)) {
/* Redstone Lamp below altar: Switch Off */
IBlockState state = world.getBlockState(pos);
if (state.getValue(BlockAltar.POWERED)) {
world.setBlockState(pos, state.cycleProperty(BlockAltar.POWERED), 3);
world.notifyNeighborsOfStateChange(pos, RegistrarBloodMagicBlocks.ALTAR, false);
}
startCycle();
}
updateAltar();
}
@ -319,6 +329,13 @@ public class BloodAltar implements IFluidHandler {
server.spawnParticle(EnumParticleTypes.REDSTONE, pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, 40, 0.3, 0, 0.3, 0);
}
/* Redstone Lamp below altar: Switch On */
/* Switches on when crafting finishes */
if (world.getBlockState(pos.down()).getBlock() instanceof BlockRedstoneLight) {
world.setBlockState(pos, world.getBlockState(pos).cycleProperty(BlockAltar.POWERED), 3);
world.notifyNeighborsOfStateChange(pos, RegistrarBloodMagicBlocks.ALTAR, false);
}
this.cooldownAfterCrafting = 30;
this.isActive = false;
}

View file

@ -18,7 +18,10 @@ import WayofTime.bloodmagic.util.Utils;
import WayofTime.bloodmagic.util.helper.NetworkHelper;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
@ -39,10 +42,13 @@ import java.util.ArrayList;
import java.util.List;
public class BlockAltar extends Block implements IVariantProvider, IDocumentedBlock, IBMBlock {
public static final PropertyBool POWERED = PropertyBool.create("powered");
private static final AxisAlignedBB BODY = new AxisAlignedBB(0, 0, 0, 16 / 16F, 12 / 16F, 16 / 16F);
public BlockAltar() {
super(Material.ROCK);
this.setDefaultState(this.blockState.getBaseState().withProperty(POWERED, false));
setTranslationKey(BloodMagic.MODID + ".altar");
setCreativeTab(BloodMagic.TAB_BM);
@ -180,4 +186,39 @@ public class BlockAltar extends Block implements IVariantProvider, IDocumentedBl
public ItemBlock getItem() {
return new ItemBlock(this);
}
/* Redstone code, taken from BlockLever */
public int getWeakPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
return blockState.getValue(POWERED) ? 15 : 0;
}
public int getStrongPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) {
if (!blockState.getValue(POWERED)) {
return 0;
} else {
return 15;
}
}
public boolean canProvidePower(IBlockState state) {
return true;
}
public IBlockState getStateFromMeta(int meta) {
return this.getDefaultState().withProperty(POWERED, meta > 0);
}
public int getMetaFromState(IBlockState state) {
return state.getValue(POWERED) ? 1 : 0;
}
protected BlockStateContainer createBlockState() {
return new BlockStateContainer(this, POWERED);
}
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
return this.getDefaultState().withProperty(POWERED, false);
}
}

View file

@ -8,6 +8,14 @@
},
"variants": {
"normal": [{
}
],
"powered=true": [
{
}
],
"powered=false": [
{
}]
}