Permalink
Browse files

Added advanced time control IC.

  • Loading branch information...
me4502 committed Jun 29, 2017
1 parent abb08b5 commit b30c5b435b6aff89ced02c64ee72d09402b30ed1
@@ -46,6 +46,7 @@
import com.sk89q.craftbook.sponge.mechanics.ics.chips.world.miscellaneous.WirelessTransmitter;
import com.sk89q.craftbook.sponge.mechanics.ics.chips.world.miscellaneous.ZeusBolt;
import com.sk89q.craftbook.sponge.mechanics.ics.chips.world.sensor.DaySensor;
import com.sk89q.craftbook.sponge.mechanics.ics.chips.world.weather.TimeControlAdvanced;
import com.sk89q.craftbook.sponge.mechanics.ics.factory.ICFactory;
import com.sk89q.craftbook.sponge.mechanics.ics.factory.SerializedICFactory;
import org.spongepowered.api.Sponge;
@@ -106,6 +107,8 @@
registerICType(new ICType<>("MC3101", "DOWN COUNTER", "Down Counter", "Decrements on redstone signal, outputs high when reset.", new DownCounter.Factory(), "3ISO"));
registerICType(new ICType<>("MC3102", "COUNTER", "Counter", "Increments on redstone signal, outputs high when reset.", new Counter.Factory(), "3ISO"));
registerICType(new ICType<>("MC3231", "T CONTROL ADV", "Time Control Advanced", "Changes the time of day when the clock input goes from low to high.", new TimeControlAdvanced.Factory(), "3ISO"));
registerICType(new ICType<>("MC3300", "ROM SET", "ROM Set", "Sets the memory state for a file for usage in the MemorySetter/Access IC group.", new MemorySetter.Factory(), "3ISO"));
//3I3O
@@ -0,0 +1,69 @@
/*
* CraftBook Copyright (C) 2010-2017 sk89q <http://www.sk89q.com>
* CraftBook Copyright (C) 2011-2017 me4502 <http://www.me4502.com>
* CraftBook Copyright (C) Contributors
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not,
* see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.craftbook.sponge.mechanics.ics.chips.world.weather;
import com.sk89q.craftbook.sponge.mechanics.ics.IC;
import com.sk89q.craftbook.sponge.mechanics.ics.factory.ICFactory;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;
public class TimeControlAdvanced extends IC {
public TimeControlAdvanced(ICFactory<TimeControlAdvanced> icFactory, Location<World> block) {
super(icFactory, block);
}
@Override
public void trigger() {
if (getPinSet().isTriggered(0, this) && getPinSet().getInput(0, this)) {
int partialDayTime = (int) (getBlock().getExtent().getProperties().getWorldTime() % 24000);
int time = (int) (getBlock().getExtent().getProperties().getWorldTime() - partialDayTime);
int timeOffset; // Start off setting to the next day.
// Generate a time offset. This means that it'll always set the next time occurance.
if (getPinSet().getInput(1, this)) {
timeOffset = partialDayTime <= 1000 ? 1000 : (1000 + 24000);
} else {
timeOffset = partialDayTime <= 13000 ? 13000 : (13000 + 24000);
}
getBlock().getExtent().getProperties().setWorldTime(time + timeOffset);
}
}
public static class Factory implements ICFactory<TimeControlAdvanced> {
@Override
public TimeControlAdvanced createInstance(Location<World> location) {
return new TimeControlAdvanced(this, location);
}
@Override
public String[][] getPinHelp() {
return new String[][] {
new String[] {
"Set Time",
"Day on High, Night on Low",
"Nothing"
},
new String[] {
"Nothing"
}
};
}
}
}

0 comments on commit b30c5b4

Please sign in to comment.