Made the Lamp Controller toggle entire areas

Closes #242
This commit is contained in:
Ellpeck 2016-09-12 16:44:53 +02:00
parent ce63aafe3f
commit 0853860810
3 changed files with 37 additions and 13 deletions

View file

@ -22,9 +22,13 @@ import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.List;
public class BlockLampPowerer extends BlockBase{
private static final PropertyInteger META = PropertyInteger.create("meta", 0, 5);
@ -59,20 +63,38 @@ public class BlockLampPowerer extends BlockBase{
if(!world.isRemote){
IBlockState state = world.getBlockState(pos);
BlockPos coords = pos.offset(WorldUtil.getDirectionByPistonRotation(state.getBlock().getMetaFromState(state)));
IBlockState coordsState = world.getBlockState(coords);
if(coordsState.getBlock() instanceof BlockColoredLamp){
int meta = coordsState.getBlock().getMetaFromState(coordsState);
if(world.isBlockIndirectlyGettingPowered(pos) > 0){
if(!((BlockColoredLamp)coordsState.getBlock()).isOn){
world.setBlockState(coords, InitBlocks.blockColoredLampOn.getStateFromMeta(meta), 2);
}
this.updateLampsAtPos(world, coords, world.isBlockIndirectlyGettingPowered(pos) > 0, new ArrayList<BlockPos>());
}
}
private void updateLampsAtPos(World world, BlockPos pos, boolean powered, List<BlockPos> updatedAlready){
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if(block instanceof BlockColoredLamp){
boolean isOn = ((BlockColoredLamp)block).isOn;
int meta = block.getMetaFromState(state);
if(powered){
if(!isOn){
world.setBlockState(pos, InitBlocks.blockColoredLampOn.getStateFromMeta(meta), 2);
}
else{
if(((BlockColoredLamp)coordsState.getBlock()).isOn){
world.setBlockState(coords, InitBlocks.blockColoredLamp.getStateFromMeta(meta), 2);
}
}
else{
if(isOn){
world.setBlockState(pos, InitBlocks.blockColoredLamp.getStateFromMeta(meta), 2);
}
}
this.updateSurrounding(world, pos, powered, updatedAlready);
}
}
private void updateSurrounding(World world, BlockPos pos, boolean powered, List<BlockPos> updatedAlready){
for(EnumFacing side : EnumFacing.values()){
BlockPos offset = pos.offset(side);
if(!updatedAlready.contains(offset)){
updatedAlready.add(pos);
this.updateLampsAtPos(world, offset, powered, updatedAlready);
}
}
}

View file

@ -93,7 +93,8 @@ public final class InitBooklet{
new BookletChapter("coalStuff", ActuallyAdditionsAPI.entryMisc, new ItemStack(InitItems.itemMisc, 1, TheMiscItems.TINY_COAL.ordinal()), new PageTextOnly(1), new PageCrafting(2, ItemCrafting.recipeTinyCoal).setNoText(), new PageCrafting(3, ItemCrafting.recipeTinyChar).setNoText(), new PageCrafting(4, BlockCrafting.recipeBlockChar).setNoText());
ArrayList<BookletPage> lampPages = new ArrayList<BookletPage>();
lampPages.add(new PageTextOnly(lampPages.size()+1));
lampPages.add(new PageCrafting(lampPages.size()+1, BlockCrafting.recipePowerer).setNoText());
lampPages.add(new PageTextOnly(lampPages.size()+1));
lampPages.add(new PageCrafting(lampPages.size()+1, BlockCrafting.recipePowerer).setNoText().setPageStacksWildcard());
for(IRecipe recipe : BlockCrafting.RECIPES_LAMPS){
lampPages.add(new PageCrafting(lampPages.size()+1, recipe).setNoText());
}

View file

@ -752,7 +752,8 @@ booklet.actuallyadditions.chapter.coalStuff.name=Coal Stuff
booklet.actuallyadditions.chapter.coalStuff.text.1=Sometimes your <item>Coal<r> just <imp>burns for too long or too short<r>, you know what I mean? <n>For that, you can now craft <item>Tiny Coal<r>, <item>Tiny Charcoal<r> and <item>Blocks of Charcoal<r> for using them in a furnace. <n>While the <item>Block of Charcoal<r> burns for as long as a <item>Block of Coal<r>, the <item>Tiny Coal<r> and <item>Tiny Charcoal<r> will burn for <imp>one eighth of a piece of coal<r>, meaning it will <imp>smelt one item in a normal furnace<r>.
booklet.actuallyadditions.chapter.lamps.name=Lamps
booklet.actuallyadditions.chapter.lamps.text.1=<item>Lamps<r> are a block providing lots of light, similar to the mystic Glowstone or Torches, but they can be <imp>dyed with all of the 16 different colors<r> either by <imp>crafting them<r> or by placing them on the ground and <imp>right-clicking them with a piece of dye<r>. <n>When <imp>right-clicking<r> them with an empty hand, they will <imp>turn on and off<r>. If you want them, however, to be toggled using <item>Redstone<r> Power, just place a <item>Lamp Controller<r> next to one.
booklet.actuallyadditions.chapter.lamps.text.1=<item>Lamps<r> are a block providing lots of light, similar to the mystic Glowstone or Torches, but they can be <imp>dyed with all of the 16 different colors<r> either by <imp>crafting them<r> or by placing them on the ground and <imp>right-clicking them with a piece of dye<r>. <n>When <imp>right-clicking<r> them with an empty hand, they will <imp>turn on and off<r>.
booklet.actuallyadditions.chapter.lamps.text.2=There is a way to toggle them with <imp>Redstone<r>, however. If you place a <item>Lamp Controller<r> facing into one and give it a <imp>redstone signal<r>, it will turn the lamp in front of it on and off. <n>The thing that makes this very expandable, though, is that it also <imp>toggles every lamp adjacent to that lamp<r> and every other lamp that gets touched. <n>That means you can have a huge field of lamps and toggle them all with <imp>just one<r> <item>Lamp Controller<r>.
booklet.actuallyadditions.chapter.treasureChest.name=Treasure Chests
booklet.actuallyadditions.chapter.treasureChest.text.1=A <item>Treasure Chest<r> found underwater.