Skip to content

Commit

Permalink
Added redstone output support.
Browse files Browse the repository at this point in the history
  • Loading branch information
winsock committed Feb 8, 2015
1 parent 357f4f2 commit 3731746
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/main/java/mods/quiddity/redux/ReduxBlock.java
Expand Up @@ -17,6 +17,7 @@
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.common.FMLCommonHandler;
Expand Down Expand Up @@ -145,6 +146,7 @@ public PropertyInteger getPropertyFromName(String name) {
return customBlockProperties.get(name);
}

@Override
public int getMetaFromState(IBlockState state) {
if (hasTileEntity(state) && !state.getPropertyNames().isEmpty()) {
return (Integer)state.getValue(SUCCESS_COUNT_META);
Expand Down Expand Up @@ -199,13 +201,15 @@ public boolean isFullCube() {
return reduxBlock.isFullCube();
}

@Override
public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, net.minecraft.block.Block neighborBlock) {
if (!worldIn.isRemote && !this.canPlaceBlockAt(worldIn, pos) && reduxBlock.isWeak()) {
this.dropBlockAsItem(worldIn, pos, state, 0);
worldIn.setBlockToAir(pos);
}
}

@Override
public boolean canPlaceBlockAt(World worldIn, BlockPos pos) {
return reduxBlock.isWeak() ? (World.doesBlockHaveSolidTopSurface(worldIn, pos.down()) || worldIn.getBlockState(pos.down()).getBlock() == Blocks.glowstone)
: super.canPlaceBlockAt(worldIn, pos);
Expand Down Expand Up @@ -235,6 +239,29 @@ public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state,
return false;
}

@Override
public boolean canProvidePower() {
return reduxBlock.getRedstoneOutputProperty() != null && !reduxBlock.getRedstoneOutputProperty().isEmpty();
}

@Override
public int isProvidingWeakPower(IBlockAccess worldIn, BlockPos pos, IBlockState state, EnumFacing side) {
if (customBlockProperties.get(reduxBlock.getRedstoneOutputProperty()) != null) {
PropertyInteger redstoneProperty = customBlockProperties.get(reduxBlock.getRedstoneOutputProperty());
return ((Integer)state.getValue(redstoneProperty)) > 15 ? 15 : ((Integer)state.getValue(redstoneProperty));
}
return 0;
}

@Override
public int isProvidingStrongPower(IBlockAccess worldIn, BlockPos pos, IBlockState state, EnumFacing side) {
if (customBlockProperties.get(reduxBlock.getRedstoneOutputProperty()) != null) {
PropertyInteger redstoneProperty = customBlockProperties.get(reduxBlock.getRedstoneOutputProperty());
return ((Integer)state.getValue(redstoneProperty)) > 15 ? 15 : ((Integer)state.getValue(redstoneProperty));
}
return 0;
}

/**
* Always render the item with full bounds.
* Andrew Querol: I cannot think of a need for anything else.
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/mods/quiddity/redux/json/model/Block.java
Expand Up @@ -24,6 +24,7 @@ public class Block {
private boolean directional;
private List<Flags<String, Integer>> custom_properties;
private List<String> ignored_properties;
private String redstone_output_property;
private String creative_tab;
private String creative_tab_icon;
private int tick_rate;
Expand Down Expand Up @@ -135,6 +136,10 @@ public List<String> getIgnoredProperties() {
return ImmutableList.copyOf(ignored_properties);
}

public String getRedstoneOutputProperty() {
return redstone_output_property;
}

@Override
public String toString() {
return id + " - " + description;
Expand Down

0 comments on commit 3731746

Please sign in to comment.