Skocz do zawartości
  • 👋 Witaj na MPCForum!

    Przeglądasz forum jako gość, co oznacza, że wiele świetnych funkcji jest jeszcze przed Tobą! 😎

    • Pełny dostęp do działów i ukrytych treści
    • Możliwość pisania i odpowiadania w tematach
    • System prywatnych wiadomości
    • Zbieranie reputacji i rozwijanie swojego profilu
    • Członkostwo w jednej z największych społeczności graczy

    👉 Dołączenie zajmie Ci mniej niż minutę – a zyskasz znacznie więcej!

    Zarejestruj się teraz

Rekomendowane odpowiedzi

Opublikowano

package com.sk89q.jchronic.handlers;

import com.sk89q.jchronic.Options;
import com.sk89q.jchronic.repeaters.EnumRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.IntegerRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.Repeater;
import com.sk89q.jchronic.repeaters.RepeaterDayName;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion.DayPortion;
import com.sk89q.jchronic.repeaters.RepeaterMonthName;
import com.sk89q.jchronic.repeaters.RepeaterTime;
import com.sk89q.jchronic.tags.Grabber;
import com.sk89q.jchronic.tags.Grabber.Relative;
import com.sk89q.jchronic.tags.Ordinal;
import com.sk89q.jchronic.tags.OrdinalDay;
import com.sk89q.jchronic.tags.Pointer;
import com.sk89q.jchronic.tags.Pointer.PointerType;
import com.sk89q.jchronic.tags.Scalar;
import com.sk89q.jchronic.tags.ScalarDay;
import com.sk89q.jchronic.tags.ScalarMonth;
import com.sk89q.jchronic.tags.ScalarYear;
import com.sk89q.jchronic.tags.Separator;
import com.sk89q.jchronic.tags.SeparatorAt;
import com.sk89q.jchronic.tags.SeparatorComma;
import com.sk89q.jchronic.tags.SeparatorIn;
import com.sk89q.jchronic.tags.SeparatorSlashOrDash;
import com.sk89q.jchronic.tags.Tag;
import com.sk89q.jchronic.tags.TimeZone;
import com.sk89q.jchronic.utils.Span;
import com.sk89q.jchronic.utils.Tick;
import com.sk89q.jchronic.utils.Time;
import com.sk89q.jchronic.utils.Token;
import java.io.PrintStream;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class Handler
{
private static Map<Handler.HandlerType, List<Handler>> _definitions;
private HandlerPattern[] _patterns;
private IHandler _handler;
private boolean _compatible;

public Handler(IHandler handler, HandlerPattern[] patterns)
{
this(handler, true, patterns);
}

public Handler(IHandler handler, boolean compatible, HandlerPattern[] patterns) {
this._handler = handler;
this._compatible = compatible;
this._patterns = patterns;
}

public boolean isCompatible(Options options) {
return (!options.isCompatibilityMode()) || (this._compatible);
}

public IHandler getHandler() {
return this._handler;
}

public boolean match(List<Token> tokens, Map<Handler.HandlerType, List<Handler>> definitions)
{
int tokenIndex = 0;
for (HandlerPattern pattern : this._patterns) {
boolean optional = pattern.isOptional();
if ((pattern instanceof TagPattern)) {
boolean match = (tokenIndex < tokens.size()) && (((Token)tokens.get(tokenIndex)).getTags(((TagPattern)pattern).getTagClass()).size() > 0);

if ((!match) && (!optional)) {
return false;
}
if (match) {
tokenIndex++;
}

}
else if ((pattern instanceof HandlerTypePattern)) {
if ((optional) && (tokenIndex == tokens.size())) {
return true;
}
List subHandlers = (List)definitions.get(((HandlerTypePattern)pattern).getType());
for (Handler subHandler : subHandlers) {
if (subHandler.match(tokens.subList(tokenIndex, tokens.size()), definitions)) {
return true;
}
}
return false;
}
}

return tokenIndex == tokens.size();
}

public String toString()
{
return "[Handler: " + this._handler + "]";
}

public static synchronized Map<Handler.HandlerType, List<Handler>> definitions() {
if (_definitions == null) {
Map definitions = new HashMap();

List timeHandlers = new LinkedList();
timeHandlers.add(new Handler(null, new HandlerPattern[] { new TagPattern(RepeaterTime.class), new TagPattern(RepeaterDayPortion.class, true) }));
definitions.put(Handler.HandlerType.TIME, timeHandlers);

List dateHandlers = new LinkedList();
dateHandlers.add(new Handler(new RdnRmnSdTTzSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterDayName.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(RepeaterTime.class), new TagPattern(TimeZone.class), new TagPattern(ScalarYear.class) }));

dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorComma.class, true), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnOdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(OrdinalDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new SdRmnSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SmSdSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SdSmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SySmSdHandler(), new HandlerPattern[] { new TagPattern(ScalarYear.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));

dateHandlers.add(new Handler(new SmSdHandler(), false, new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class) }));
dateHandlers.add(new Handler(new SmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class) }));
definitions.put(Handler.HandlerType.DATE, dateHandlers);

List anchorHandlers = new LinkedList();
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RGRHandler(), new HandlerPattern[] { new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.ANCHOR, anchorHandlers);

List arrowHandlers = new LinkedList();
arrowHandlers.add(new Handler(new SRPHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class) }));
arrowHandlers.add(new Handler(new PSRHandler(), new HandlerPattern[] { new TagPattern(Pointer.class), new TagPattern(Scalar.class), new TagPattern(Repeater.class) }));
arrowHandlers.add(new Handler(new SRPAHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class), new HandlerTypePattern(Handler.HandlerType.ANCHOR) }));
definitions.put(Handler.HandlerType.ARROW, arrowHandlers);

List narrowHandlers = new LinkedList();
narrowHandlers.add(new Handler(new ORSRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(SeparatorIn.class), new TagPattern(Repeater.class) }));
narrowHandlers.add(new Handler(new ORGRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.NARROW, narrowHandlers);
_definitions = definitions;
}
return _definitions;
}

public static Span tokensToSpan(List<Token> tokens, Options options) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: " + tokens);
}

Map definitions = definitions();
for (Handler handler : (List)definitions.get(Handler.HandlerType.DATE)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: date");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ANCHOR)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: anchor");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: arrow");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if ((token.getTag(SeparatorAt.class) == null) && (token.getTag(SeparatorSlashOrDash.class) == null) && (token.getTag(SeparatorComma.class) == null)) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.NARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: narrow");
}

return handler.getHandler().handle(tokens, options);
}

}

if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: none");
}
return null;
}

public static List<Repeater<?>> getRepeaters(List<Token> tokens) {
List repeaters = new LinkedList();
for (Token token : tokens) {
Repeater tag = (Repeater)token.getTag(Repeater.class);
if (tag != null) {
repeaters.add(tag);
}
}
Collections.sort(repeaters);
Collections.reverse(repeaters);
return repeaters;
}

public static Span getAnchor(List<Token> tokens, Options options) {
Grabber grabber = new Grabber(Grabber.Relative.THIS);
Pointer.PointerType pointer = Pointer.PointerType.FUTURE;

List repeaters = getRepeaters(tokens);
for (int i = 0; i < repeaters.size(); i++) {
tokens.remove(tokens.size() - 1);
}

if ((!tokens.isEmpty()) && (((Token)tokens.get(0)).getTag(Grabber.class) != null)) {
grabber = (Grabber)((Token)tokens.get(0)).getTag(Grabber.class);
tokens.remove(tokens.size() - 1);
}

Repeater head = (Repeater)repeaters.remove(0);
head.setStart((Calendar)options.getNow().clone());

Grabber.Relative grabberType = (Grabber.Relative)grabber.getType();
Span outerSpan;
if (grabberType == Grabber.Relative.LAST) {
outerSpan = head.nextSpan(Pointer.PointerType.PAST);
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.THIS)
{
Span outerSpan;
if (repeaters.size() > 0) {
outerSpan = head.thisSpan(Pointer.PointerType.NONE);
}
else
outerSpan = head.thisSpan(options.getContext());
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.NEXT) {
outerSpan = head.nextSpan(Pointer.PointerType.FUTURE);
}
else
throw new IllegalArgumentException("Invalid grabber type " + grabberType + ".");
}
}
Span outerSpan;
if (options.isDebug()) {
System.out.println("Chronic.getAnchor: outerSpan = " + outerSpan + "; repeaters = " + repeaters);
}

Span anchor = findWithin(repeaters, outerSpan, pointer, options);
return anchor;
}

public static Span dayOrTime(Calendar dayStart, List<Token> timeTokens, Options options) {
Span outerSpan = new Span(dayStart, Time.cloneAndAdd(dayStart, 5, 1L));
if (!timeTokens.isEmpty())
{
options.setNow(outerSpan.getBeginCalendar());
Span time = getAnchor(dealiasAndDisambiguateTimes(timeTokens, options), options);
return time;
}
return outerSpan;
}

public static Span findWithin(List<Repeater<?>> tags, Span span, Pointer.PointerType pointer, Options options)
{
if (options.isDebug()) {
System.out.println("Chronic.findWithin: " + tags + " in " + span);
}
if (tags.isEmpty()) {
return span;
}
Repeater head = (Repeater)tags.get(0);
List rest = tags.size() > 1 ? tags.subList(1, tags.size()) : new LinkedList();
head.setStart(pointer == Pointer.PointerType.FUTURE ? span.getBeginCalendar() : span.getEndCalendar());
Span h = head.thisSpan(Pointer.PointerType.NONE);

if ((span.contains(h.getBegin())) || (span.contains(h.getEnd()))) {
return findWithin(rest, h, pointer, options);
}
return null;
}

public static List<Token> dealiasAndDisambiguateTimes(List<Token> tokens, Options options)
{
int dayPortionIndex = -1;
int tokenSize = tokens.size();
for (int i = 0; (dayPortionIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterDayPortion.class) != null) {
dayPortionIndex = i;
}
}

int timeIndex = -1;
for (int i = 0; (timeIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterTime.class) != null) {
timeIndex = i;
}
}

if ((dayPortionIndex != -1) && (timeIndex != -1)) {
Token t1 = (Token)tokens.get(dayPortionIndex);
Tag t1Tag = t1.getTag(RepeaterDayPortion.class);

Object t1TagType = t1Tag.getType();
if (RepeaterDayPortion.DayPortion.MORNING.equals(t1TagType)) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: morning->am");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.AM));
}
else if ((RepeaterDayPortion.DayPortion.AFTERNOON.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.EVENING.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.NIGHT.equals(t1TagType))) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + t1TagType + "->pm");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.PM));
}

}

if (options.getAmbiguousTimeRange() != 0) {
List ttokens = new LinkedList();
for (int i = 0; i < tokenSize; i++) {
Token t0 = (Token)tokens.get(i);
ttokens.add(t0);
Token t1 = null;
if (i < tokenSize - 1) {
t1 = (Token)tokens.get(i + 1);
}
if ((t0.getTag(RepeaterTime.class) != null) && (((Tick)((RepeaterTime)t0.getTag(RepeaterTime.class)).getType()).isAmbiguous()) && ((t1 == null) || (t1.getTag(RepeaterDayPortion.class) == null))) {
Token distoken = new Token("disambiguator");
distoken.tag(new IntegerRepeaterDayPortion(Integer.valueOf(options.getAmbiguousTimeRange())));
ttokens.add(distoken);
}
}
tokens = ttokens;
}

if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + tokens);
}

return tokens;
}
}
package com.sk89q.jchronic.handlers;

import com.sk89q.jchronic.Options;
import com.sk89q.jchronic.repeaters.EnumRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.IntegerRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.Repeater;
import com.sk89q.jchronic.repeaters.RepeaterDayName;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion.DayPortion;
import com.sk89q.jchronic.repeaters.RepeaterMonthName;
import com.sk89q.jchronic.repeaters.RepeaterTime;
import com.sk89q.jchronic.tags.Grabber;
import com.sk89q.jchronic.tags.Grabber.Relative;
import com.sk89q.jchronic.tags.Ordinal;
import com.sk89q.jchronic.tags.OrdinalDay;
import com.sk89q.jchronic.tags.Pointer;
import com.sk89q.jchronic.tags.Pointer.PointerType;
import com.sk89q.jchronic.tags.Scalar;
import com.sk89q.jchronic.tags.ScalarDay;
import com.sk89q.jchronic.tags.ScalarMonth;
import com.sk89q.jchronic.tags.ScalarYear;
import com.sk89q.jchronic.tags.Separator;
import com.sk89q.jchronic.tags.SeparatorAt;
import com.sk89q.jchronic.tags.SeparatorComma;
import com.sk89q.jchronic.tags.SeparatorIn;
import com.sk89q.jchronic.tags.SeparatorSlashOrDash;
import com.sk89q.jchronic.tags.Tag;
import com.sk89q.jchronic.tags.TimeZone;
import com.sk89q.jchronic.utils.Span;
import com.sk89q.jchronic.utils.Tick;
import com.sk89q.jchronic.utils.Time;
import com.sk89q.jchronic.utils.Token;
import java.io.PrintStream;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class Handler
{
private static Map<Handler.HandlerType, List<Handler>> _definitions;
private HandlerPattern[] _patterns;
private IHandler _handler;
private boolean _compatible;

public Handler(IHandler handler, HandlerPattern[] patterns)
{
this(handler, true, patterns);
}

public Handler(IHandler handler, boolean compatible, HandlerPattern[] patterns) {
this._handler = handler;
this._compatible = compatible;
this._patterns = patterns;
}

public boolean isCompatible(Options options) {
return (!options.isCompatibilityMode()) || (this._compatible);
}

public IHandler getHandler() {
return this._handler;
}

public boolean match(List<Token> tokens, Map<Handler.HandlerType, List<Handler>> definitions)
{
int tokenIndex = 0;
for (HandlerPattern pattern : this._patterns) {
boolean optional = pattern.isOptional();
if ((pattern instanceof TagPattern)) {
boolean match = (tokenIndex < tokens.size()) && (((Token)tokens.get(tokenIndex)).getTags(((TagPattern)pattern).getTagClass()).size() > 0);

if ((!match) && (!optional)) {
return false;
}
if (match) {
tokenIndex++;
}

}
else if ((pattern instanceof HandlerTypePattern)) {
if ((optional) && (tokenIndex == tokens.size())) {
return true;
}
List subHandlers = (List)definitions.get(((HandlerTypePattern)pattern).getType());
for (Handler subHandler : subHandlers) {
if (subHandler.match(tokens.subList(tokenIndex, tokens.size()), definitions)) {
return true;
}
}
return false;
}
}

return tokenIndex == tokens.size();
}

public String toString()
{
return "[Handler: " + this._handler + "]";
}

public static synchronized Map<Handler.HandlerType, List<Handler>> definitions() {
if (_definitions == null) {
Map definitions = new HashMap();

List timeHandlers = new LinkedList();
timeHandlers.add(new Handler(null, new HandlerPattern[] { new TagPattern(RepeaterTime.class), new TagPattern(RepeaterDayPortion.class, true) }));
definitions.put(Handler.HandlerType.TIME, timeHandlers);

List dateHandlers = new LinkedList();
dateHandlers.add(new Handler(new RdnRmnSdTTzSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterDayName.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(RepeaterTime.class), new TagPattern(TimeZone.class), new TagPattern(ScalarYear.class) }));

dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorComma.class, true), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnOdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(OrdinalDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new SdRmnSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SmSdSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SdSmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SySmSdHandler(), new HandlerPattern[] { new TagPattern(ScalarYear.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));

dateHandlers.add(new Handler(new SmSdHandler(), false, new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class) }));
dateHandlers.add(new Handler(new SmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class) }));
definitions.put(Handler.HandlerType.DATE, dateHandlers);

List anchorHandlers = new LinkedList();
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RGRHandler(), new HandlerPattern[] { new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.ANCHOR, anchorHandlers);

List arrowHandlers = new LinkedList();
arrowHandlers.add(new Handler(new SRPHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class) }));
arrowHandlers.add(new Handler(new PSRHandler(), new HandlerPattern[] { new TagPattern(Pointer.class), new TagPattern(Scalar.class), new TagPattern(Repeater.class) }));
arrowHandlers.add(new Handler(new SRPAHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class), new HandlerTypePattern(Handler.HandlerType.ANCHOR) }));
definitions.put(Handler.HandlerType.ARROW, arrowHandlers);

List narrowHandlers = new LinkedList();
narrowHandlers.add(new Handler(new ORSRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(SeparatorIn.class), new TagPattern(Repeater.class) }));
narrowHandlers.add(new Handler(new ORGRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.NARROW, narrowHandlers);
_definitions = definitions;
}
return _definitions;
}

public static Span tokensToSpan(List<Token> tokens, Options options) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: " + tokens);
}

Map definitions = definitions();
for (Handler handler : (List)definitions.get(Handler.HandlerType.DATE)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: date");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ANCHOR)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: anchor");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: arrow");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if ((token.getTag(SeparatorAt.class) == null) && (token.getTag(SeparatorSlashOrDash.class) == null) && (token.getTag(SeparatorComma.class) == null)) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.NARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: narrow");
}

return handler.getHandler().handle(tokens, options);
}

}

if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: none");
}
return null;
}

public static List<Repeater<?>> getRepeaters(List<Token> tokens) {
List repeaters = new LinkedList();
for (Token token : tokens) {
Repeater tag = (Repeater)token.getTag(Repeater.class);
if (tag != null) {
repeaters.add(tag);
}
}
Collections.sort(repeaters);
Collections.reverse(repeaters);
return repeaters;
}

public static Span getAnchor(List<Token> tokens, Options options) {
Grabber grabber = new Grabber(Grabber.Relative.THIS);
Pointer.PointerType pointer = Pointer.PointerType.FUTURE;

List repeaters = getRepeaters(tokens);
for (int i = 0; i < repeaters.size(); i++) {
tokens.remove(tokens.size() - 1);
}

if ((!tokens.isEmpty()) && (((Token)tokens.get(0)).getTag(Grabber.class) != null)) {
grabber = (Grabber)((Token)tokens.get(0)).getTag(Grabber.class);
tokens.remove(tokens.size() - 1);
}

Repeater head = (Repeater)repeaters.remove(0);
head.setStart((Calendar)options.getNow().clone());

Grabber.Relative grabberType = (Grabber.Relative)grabber.getType();
Span outerSpan;
if (grabberType == Grabber.Relative.LAST) {
outerSpan = head.nextSpan(Pointer.PointerType.PAST);
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.THIS)
{
Span outerSpan;
if (repeaters.size() > 0) {
outerSpan = head.thisSpan(Pointer.PointerType.NONE);
}
else
outerSpan = head.thisSpan(options.getContext());
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.NEXT) {
outerSpan = head.nextSpan(Pointer.PointerType.FUTURE);
}
else
throw new IllegalArgumentException("Invalid grabber type " + grabberType + ".");
}
}
Span outerSpan;
if (options.isDebug()) {
System.out.println("Chronic.getAnchor: outerSpan = " + outerSpan + "; repeaters = " + repeaters);
}

Span anchor = findWithin(repeaters, outerSpan, pointer, options);
return anchor;
}

public static Span dayOrTime(Calendar dayStart, List<Token> timeTokens, Options options) {
Span outerSpan = new Span(dayStart, Time.cloneAndAdd(dayStart, 5, 1L));
if (!timeTokens.isEmpty())
{
options.setNow(outerSpan.getBeginCalendar());
Span time = getAnchor(dealiasAndDisambiguateTimes(timeTokens, options), options);
return time;
}
return outerSpan;
}

public static Span findWithin(List<Repeater<?>> tags, Span span, Pointer.PointerType pointer, Options options)
{
if (options.isDebug()) {
System.out.println("Chronic.findWithin: " + tags + " in " + span);
}
if (tags.isEmpty()) {
return span;
}
Repeater head = (Repeater)tags.get(0);
List rest = tags.size() > 1 ? tags.subList(1, tags.size()) : new LinkedList();
head.setStart(pointer == Pointer.PointerType.FUTURE ? span.getBeginCalendar() : span.getEndCalendar());
Span h = head.thisSpan(Pointer.PointerType.NONE);

if ((span.contains(h.getBegin())) || (span.contains(h.getEnd()))) {
return findWithin(rest, h, pointer, options);
}
return null;
}

public static List<Token> dealiasAndDisambiguateTimes(List<Token> tokens, Options options)
{
int dayPortionIndex = -1;
int tokenSize = tokens.size();
for (int i = 0; (dayPortionIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterDayPortion.class) != null) {
dayPortionIndex = i;
}
}

int timeIndex = -1;
for (int i = 0; (timeIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterTime.class) != null) {
timeIndex = i;
}
}

if ((dayPortionIndex != -1) && (timeIndex != -1)) {
Token t1 = (Token)tokens.get(dayPortionIndex);
Tag t1Tag = t1.getTag(RepeaterDayPortion.class);

Object t1TagType = t1Tag.getType();
if (RepeaterDayPortion.DayPortion.MORNING.equals(t1TagType)) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: morning->am");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.AM));
}
else if ((RepeaterDayPortion.DayPortion.AFTERNOON.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.EVENING.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.NIGHT.equals(t1TagType))) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + t1TagType + "->pm");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.PM));
}

}

if (options.getAmbiguousTimeRange() != 0) {
List ttokens = new LinkedList();
for (int i = 0; i < tokenSize; i++) {
Token t0 = (Token)tokens.get(i);
ttokens.add(t0);
Token t1 = null;
if (i < tokenSize - 1) {
t1 = (Token)tokens.get(i + 1);
}
if ((t0.getTag(RepeaterTime.class) != null) && (((Tick)((RepeaterTime)t0.getTag(RepeaterTime.class)).getType()).isAmbiguous()) && ((t1 == null) || (t1.getTag(RepeaterDayPortion.class) == null))) {
Token distoken = new Token("disambiguator");
distoken.tag(new IntegerRepeaterDayPortion(Integer.valueOf(options.getAmbiguousTimeRange())));
ttokens.add(distoken);
}
}
tokens = ttokens;
}

if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + tokens);
}

return tokens;
}
}
package com.sk89q.jchronic.handlers;

import com.sk89q.jchronic.Options;
import com.sk89q.jchronic.repeaters.EnumRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.IntegerRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.Repeater;
import com.sk89q.jchronic.repeaters.RepeaterDayName;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion.DayPortion;
import com.sk89q.jchronic.repeaters.RepeaterMonthName;
import com.sk89q.jchronic.repeaters.RepeaterTime;
import com.sk89q.jchronic.tags.Grabber;
import com.sk89q.jchronic.tags.Grabber.Relative;
import com.sk89q.jchronic.tags.Ordinal;
import com.sk89q.jchronic.tags.OrdinalDay;
import com.sk89q.jchronic.tags.Pointer;
import com.sk89q.jchronic.tags.Pointer.PointerType;
import com.sk89q.jchronic.tags.Scalar;
import com.sk89q.jchronic.tags.ScalarDay;
import com.sk89q.jchronic.tags.ScalarMonth;
import com.sk89q.jchronic.tags.ScalarYear;
import com.sk89q.jchronic.tags.Separator;
import com.sk89q.jchronic.tags.SeparatorAt;
import com.sk89q.jchronic.tags.SeparatorComma;
import com.sk89q.jchronic.tags.SeparatorIn;
import com.sk89q.jchronic.tags.SeparatorSlashOrDash;
import com.sk89q.jchronic.tags.Tag;
import com.sk89q.jchronic.tags.TimeZone;
import com.sk89q.jchronic.utils.Span;
import com.sk89q.jchronic.utils.Tick;
import com.sk89q.jchronic.utils.Time;
import com.sk89q.jchronic.utils.Token;
import java.io.PrintStream;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class Handler
{
private static Map<Handler.HandlerType, List<Handler>> _definitions;
private HandlerPattern[] _patterns;
private IHandler _handler;
private boolean _compatible;

public Handler(IHandler handler, HandlerPattern[] patterns)
{
this(handler, true, patterns);
}

public Handler(IHandler handler, boolean compatible, HandlerPattern[] patterns) {
this._handler = handler;
this._compatible = compatible;
this._patterns = patterns;
}

public boolean isCompatible(Options options) {
return (!options.isCompatibilityMode()) || (this._compatible);
}

public IHandler getHandler() {
return this._handler;
}

public boolean match(List<Token> tokens, Map<Handler.HandlerType, List<Handler>> definitions)
{
int tokenIndex = 0;
for (HandlerPattern pattern : this._patterns) {
boolean optional = pattern.isOptional();
if ((pattern instanceof TagPattern)) {
boolean match = (tokenIndex < tokens.size()) && (((Token)tokens.get(tokenIndex)).getTags(((TagPattern)pattern).getTagClass()).size() > 0);

if ((!match) && (!optional)) {
return false;
}
if (match) {
tokenIndex++;
}

}
else if ((pattern instanceof HandlerTypePattern)) {
if ((optional) && (tokenIndex == tokens.size())) {
return true;
}
List subHandlers = (List)definitions.get(((HandlerTypePattern)pattern).getType());
for (Handler subHandler : subHandlers) {
if (subHandler.match(tokens.subList(tokenIndex, tokens.size()), definitions)) {
return true;
}
}
return false;
}
}

return tokenIndex == tokens.size();
}

public String toString()
{
return "[Handler: " + this._handler + "]";
}

public static synchronized Map<Handler.HandlerType, List<Handler>> definitions() {
if (_definitions == null) {
Map definitions = new HashMap();

List timeHandlers = new LinkedList();
timeHandlers.add(new Handler(null, new HandlerPattern[] { new TagPattern(RepeaterTime.class), new TagPattern(RepeaterDayPortion.class, true) }));
definitions.put(Handler.HandlerType.TIME, timeHandlers);

List dateHandlers = new LinkedList();
dateHandlers.add(new Handler(new RdnRmnSdTTzSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterDayName.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(RepeaterTime.class), new TagPattern(TimeZone.class), new TagPattern(ScalarYear.class) }));

dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorComma.class, true), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnOdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(OrdinalDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new SdRmnSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SmSdSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SdSmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SySmSdHandler(), new HandlerPattern[] { new TagPattern(ScalarYear.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));

dateHandlers.add(new Handler(new SmSdHandler(), false, new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class) }));
dateHandlers.add(new Handler(new SmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class) }));
definitions.put(Handler.HandlerType.DATE, dateHandlers);

List anchorHandlers = new LinkedList();
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RGRHandler(), new HandlerPattern[] { new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.ANCHOR, anchorHandlers);

List arrowHandlers = new LinkedList();
arrowHandlers.add(new Handler(new SRPHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class) }));
arrowHandlers.add(new Handler(new PSRHandler(), new HandlerPattern[] { new TagPattern(Pointer.class), new TagPattern(Scalar.class), new TagPattern(Repeater.class) }));
arrowHandlers.add(new Handler(new SRPAHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class), new HandlerTypePattern(Handler.HandlerType.ANCHOR) }));
definitions.put(Handler.HandlerType.ARROW, arrowHandlers);

List narrowHandlers = new LinkedList();
narrowHandlers.add(new Handler(new ORSRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(SeparatorIn.class), new TagPattern(Repeater.class) }));
narrowHandlers.add(new Handler(new ORGRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.NARROW, narrowHandlers);
_definitions = definitions;
}
return _definitions;
}

public static Span tokensToSpan(List<Token> tokens, Options options) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: " + tokens);
}

Map definitions = definitions();
for (Handler handler : (List)definitions.get(Handler.HandlerType.DATE)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: date");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ANCHOR)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: anchor");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: arrow");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if ((token.getTag(SeparatorAt.class) == null) && (token.getTag(SeparatorSlashOrDash.class) == null) && (token.getTag(SeparatorComma.class) == null)) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.NARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: narrow");
}

return handler.getHandler().handle(tokens, options);
}

}

if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: none");
}
return null;
}

public static List<Repeater<?>> getRepeaters(List<Token> tokens) {
List repeaters = new LinkedList();
for (Token token : tokens) {
Repeater tag = (Repeater)token.getTag(Repeater.class);
if (tag != null) {
repeaters.add(tag);
}
}
Collections.sort(repeaters);
Collections.reverse(repeaters);
return repeaters;
}

public static Span getAnchor(List<Token> tokens, Options options) {
Grabber grabber = new Grabber(Grabber.Relative.THIS);
Pointer.PointerType pointer = Pointer.PointerType.FUTURE;

List repeaters = getRepeaters(tokens);
for (int i = 0; i < repeaters.size(); i++) {
tokens.remove(tokens.size() - 1);
}

if ((!tokens.isEmpty()) && (((Token)tokens.get(0)).getTag(Grabber.class) != null)) {
grabber = (Grabber)((Token)tokens.get(0)).getTag(Grabber.class);
tokens.remove(tokens.size() - 1);
}

Repeater head = (Repeater)repeaters.remove(0);
head.setStart((Calendar)options.getNow().clone());

Grabber.Relative grabberType = (Grabber.Relative)grabber.getType();
Span outerSpan;
if (grabberType == Grabber.Relative.LAST) {
outerSpan = head.nextSpan(Pointer.PointerType.PAST);
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.THIS)
{
Span outerSpan;
if (repeaters.size() > 0) {
outerSpan = head.thisSpan(Pointer.PointerType.NONE);
}
else
outerSpan = head.thisSpan(options.getContext());
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.NEXT) {
outerSpan = head.nextSpan(Pointer.PointerType.FUTURE);
}
else
throw new IllegalArgumentException("Invalid grabber type " + grabberType + ".");
}
}
Span outerSpan;
if (options.isDebug()) {
System.out.println("Chronic.getAnchor: outerSpan = " + outerSpan + "; repeaters = " + repeaters);
}

Span anchor = findWithin(repeaters, outerSpan, pointer, options);
return anchor;
}

public static Span dayOrTime(Calendar dayStart, List<Token> timeTokens, Options options) {
Span outerSpan = new Span(dayStart, Time.cloneAndAdd(dayStart, 5, 1L));
if (!timeTokens.isEmpty())
{
options.setNow(outerSpan.getBeginCalendar());
Span time = getAnchor(dealiasAndDisambiguateTimes(timeTokens, options), options);
return time;
}
return outerSpan;
}

public static Span findWithin(List<Repeater<?>> tags, Span span, Pointer.PointerType pointer, Options options)
{
if (options.isDebug()) {
System.out.println("Chronic.findWithin: " + tags + " in " + span);
}
if (tags.isEmpty()) {
return span;
}
Repeater head = (Repeater)tags.get(0);
List rest = tags.size() > 1 ? tags.subList(1, tags.size()) : new LinkedList();
head.setStart(pointer == Pointer.PointerType.FUTURE ? span.getBeginCalendar() : span.getEndCalendar());
Span h = head.thisSpan(Pointer.PointerType.NONE);

if ((span.contains(h.getBegin())) || (span.contains(h.getEnd()))) {
return findWithin(rest, h, pointer, options);
}
return null;
}

public static List<Token> dealiasAndDisambiguateTimes(List<Token> tokens, Options options)
{
int dayPortionIndex = -1;
int tokenSize = tokens.size();
for (int i = 0; (dayPortionIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterDayPortion.class) != null) {
dayPortionIndex = i;
}
}

int timeIndex = -1;
for (int i = 0; (timeIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterTime.class) != null) {
timeIndex = i;
}
}

if ((dayPortionIndex != -1) && (timeIndex != -1)) {
Token t1 = (Token)tokens.get(dayPortionIndex);
Tag t1Tag = t1.getTag(RepeaterDayPortion.class);

Object t1TagType = t1Tag.getType();
if (RepeaterDayPortion.DayPortion.MORNING.equals(t1TagType)) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: morning->am");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.AM));
}
else if ((RepeaterDayPortion.DayPortion.AFTERNOON.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.EVENING.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.NIGHT.equals(t1TagType))) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + t1TagType + "->pm");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.PM));
}

}

if (options.getAmbiguousTimeRange() != 0) {
List ttokens = new LinkedList();
for (int i = 0; i < tokenSize; i++) {
Token t0 = (Token)tokens.get(i);
ttokens.add(t0);
Token t1 = null;
if (i < tokenSize - 1) {
t1 = (Token)tokens.get(i + 1);
}
if ((t0.getTag(RepeaterTime.class) != null) && (((Tick)((RepeaterTime)t0.getTag(RepeaterTime.class)).getType()).isAmbiguous()) && ((t1 == null) || (t1.getTag(RepeaterDayPortion.class) == null))) {
Token distoken = new Token("disambiguator");
distoken.tag(new IntegerRepeaterDayPortion(Integer.valueOf(options.getAmbiguousTimeRange())));
ttokens.add(distoken);
}
}
tokens = ttokens;
}

if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + tokens);
}

return tokens;
}
}
package com.sk89q.jchronic.handlers;

import com.sk89q.jchronic.Options;
import com.sk89q.jchronic.repeaters.EnumRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.IntegerRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.Repeater;
import com.sk89q.jchronic.repeaters.RepeaterDayName;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion.DayPortion;
import com.sk89q.jchronic.repeaters.RepeaterMonthName;
import com.sk89q.jchronic.repeaters.RepeaterTime;
import com.sk89q.jchronic.tags.Grabber;
import com.sk89q.jchronic.tags.Grabber.Relative;
import com.sk89q.jchronic.tags.Ordinal;
import com.sk89q.jchronic.tags.OrdinalDay;
import com.sk89q.jchronic.tags.Pointer;
import com.sk89q.jchronic.tags.Pointer.PointerType;
import com.sk89q.jchronic.tags.Scalar;
import com.sk89q.jchronic.tags.ScalarDay;
import com.sk89q.jchronic.tags.ScalarMonth;
import com.sk89q.jchronic.tags.ScalarYear;
import com.sk89q.jchronic.tags.Separator;
import com.sk89q.jchronic.tags.SeparatorAt;
import com.sk89q.jchronic.tags.SeparatorComma;
import com.sk89q.jchronic.tags.SeparatorIn;
import com.sk89q.jchronic.tags.SeparatorSlashOrDash;
import com.sk89q.jchronic.tags.Tag;
import com.sk89q.jchronic.tags.TimeZone;
import com.sk89q.jchronic.utils.Span;
import com.sk89q.jchronic.utils.Tick;
import com.sk89q.jchronic.utils.Time;
import com.sk89q.jchronic.utils.Token;
import java.io.PrintStream;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class Handler
{
private static Map<Handler.HandlerType, List<Handler>> _definitions;
private HandlerPattern[] _patterns;
private IHandler _handler;
private boolean _compatible;

public Handler(IHandler handler, HandlerPattern[] patterns)
{
this(handler, true, patterns);
}

public Handler(IHandler handler, boolean compatible, HandlerPattern[] patterns) {
this._handler = handler;
this._compatible = compatible;
this._patterns = patterns;
}

public boolean isCompatible(Options options) {
return (!options.isCompatibilityMode()) || (this._compatible);
}

public IHandler getHandler() {
return this._handler;
}

public boolean match(List<Token> tokens, Map<Handler.HandlerType, List<Handler>> definitions)
{
int tokenIndex = 0;
for (HandlerPattern pattern : this._patterns) {
boolean optional = pattern.isOptional();
if ((pattern instanceof TagPattern)) {
boolean match = (tokenIndex < tokens.size()) && (((Token)tokens.get(tokenIndex)).getTags(((TagPattern)pattern).getTagClass()).size() > 0);

if ((!match) && (!optional)) {
return false;
}
if (match) {
tokenIndex++;
}

}
else if ((pattern instanceof HandlerTypePattern)) {
if ((optional) && (tokenIndex == tokens.size())) {
return true;
}
List subHandlers = (List)definitions.get(((HandlerTypePattern)pattern).getType());
for (Handler subHandler : subHandlers) {
if (subHandler.match(tokens.subList(tokenIndex, tokens.size()), definitions)) {
return true;
}
}
return false;
}
}

return tokenIndex == tokens.size();
}

public String toString()
{
return "[Handler: " + this._handler + "]";
}

public static synchronized Map<Handler.HandlerType, List<Handler>> definitions() {
if (_definitions == null) {
Map definitions = new HashMap();

List timeHandlers = new LinkedList();
timeHandlers.add(new Handler(null, new HandlerPattern[] { new TagPattern(RepeaterTime.class), new TagPattern(RepeaterDayPortion.class, true) }));
definitions.put(Handler.HandlerType.TIME, timeHandlers);

List dateHandlers = new LinkedList();
dateHandlers.add(new Handler(new RdnRmnSdTTzSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterDayName.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(RepeaterTime.class), new TagPattern(TimeZone.class), new TagPattern(ScalarYear.class) }));

dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorComma.class, true), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnOdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(OrdinalDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new SdRmnSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SmSdSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SdSmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SySmSdHandler(), new HandlerPattern[] { new TagPattern(ScalarYear.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));

dateHandlers.add(new Handler(new SmSdHandler(), false, new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class) }));
dateHandlers.add(new Handler(new SmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class) }));
definitions.put(Handler.HandlerType.DATE, dateHandlers);

List anchorHandlers = new LinkedList();
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RGRHandler(), new HandlerPattern[] { new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.ANCHOR, anchorHandlers);

List arrowHandlers = new LinkedList();
arrowHandlers.add(new Handler(new SRPHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class) }));
arrowHandlers.add(new Handler(new PSRHandler(), new HandlerPattern[] { new TagPattern(Pointer.class), new TagPattern(Scalar.class), new TagPattern(Repeater.class) }));
arrowHandlers.add(new Handler(new SRPAHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class), new HandlerTypePattern(Handler.HandlerType.ANCHOR) }));
definitions.put(Handler.HandlerType.ARROW, arrowHandlers);

List narrowHandlers = new LinkedList();
narrowHandlers.add(new Handler(new ORSRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(SeparatorIn.class), new TagPattern(Repeater.class) }));
narrowHandlers.add(new Handler(new ORGRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.NARROW, narrowHandlers);
_definitions = definitions;
}
return _definitions;
}

public static Span tokensToSpan(List<Token> tokens, Options options) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: " + tokens);
}

Map definitions = definitions();
for (Handler handler : (List)definitions.get(Handler.HandlerType.DATE)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: date");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ANCHOR)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: anchor");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: arrow");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if ((token.getTag(SeparatorAt.class) == null) && (token.getTag(SeparatorSlashOrDash.class) == null) && (token.getTag(SeparatorComma.class) == null)) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.NARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: narrow");
}

return handler.getHandler().handle(tokens, options);
}

}

if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: none");
}
return null;
}

public static List<Repeater<?>> getRepeaters(List<Token> tokens) {
List repeaters = new LinkedList();
for (Token token : tokens) {
Repeater tag = (Repeater)token.getTag(Repeater.class);
if (tag != null) {
repeaters.add(tag);
}
}
Collections.sort(repeaters);
Collections.reverse(repeaters);
return repeaters;
}

public static Span getAnchor(List<Token> tokens, Options options) {
Grabber grabber = new Grabber(Grabber.Relative.THIS);
Pointer.PointerType pointer = Pointer.PointerType.FUTURE;

List repeaters = getRepeaters(tokens);
for (int i = 0; i < repeaters.size(); i++) {
tokens.remove(tokens.size() - 1);
}

if ((!tokens.isEmpty()) && (((Token)tokens.get(0)).getTag(Grabber.class) != null)) {
grabber = (Grabber)((Token)tokens.get(0)).getTag(Grabber.class);
tokens.remove(tokens.size() - 1);
}

Repeater head = (Repeater)repeaters.remove(0);
head.setStart((Calendar)options.getNow().clone());

Grabber.Relative grabberType = (Grabber.Relative)grabber.getType();
Span outerSpan;
if (grabberType == Grabber.Relative.LAST) {
outerSpan = head.nextSpan(Pointer.PointerType.PAST);
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.THIS)
{
Span outerSpan;
if (repeaters.size() > 0) {
outerSpan = head.thisSpan(Pointer.PointerType.NONE);
}
else
outerSpan = head.thisSpan(options.getContext());
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.NEXT) {
outerSpan = head.nextSpan(Pointer.PointerType.FUTURE);
}
else
throw new IllegalArgumentException("Invalid grabber type " + grabberType + ".");
}
}
Span outerSpan;
if (options.isDebug()) {
System.out.println("Chronic.getAnchor: outerSpan = " + outerSpan + "; repeaters = " + repeaters);
}

Span anchor = findWithin(repeaters, outerSpan, pointer, options);
return anchor;
}

public static Span dayOrTime(Calendar dayStart, List<Token> timeTokens, Options options) {
Span outerSpan = new Span(dayStart, Time.cloneAndAdd(dayStart, 5, 1L));
if (!timeTokens.isEmpty())
{
options.setNow(outerSpan.getBeginCalendar());
Span time = getAnchor(dealiasAndDisambiguateTimes(timeTokens, options), options);
return time;
}
return outerSpan;
}

public static Span findWithin(List<Repeater<?>> tags, Span span, Pointer.PointerType pointer, Options options)
{
if (options.isDebug()) {
System.out.println("Chronic.findWithin: " + tags + " in " + span);
}
if (tags.isEmpty()) {
return span;
}
Repeater head = (Repeater)tags.get(0);
List rest = tags.size() > 1 ? tags.subList(1, tags.size()) : new LinkedList();
head.setStart(pointer == Pointer.PointerType.FUTURE ? span.getBeginCalendar() : span.getEndCalendar());
Span h = head.thisSpan(Pointer.PointerType.NONE);

if ((span.contains(h.getBegin())) || (span.contains(h.getEnd()))) {
return findWithin(rest, h, pointer, options);
}
return null;
}

public static List<Token> dealiasAndDisambiguateTimes(List<Token> tokens, Options options)
{
int dayPortionIndex = -1;
int tokenSize = tokens.size();
for (int i = 0; (dayPortionIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterDayPortion.class) != null) {
dayPortionIndex = i;
}
}

int timeIndex = -1;
for (int i = 0; (timeIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterTime.class) != null) {
timeIndex = i;
}
}

if ((dayPortionIndex != -1) && (timeIndex != -1)) {
Token t1 = (Token)tokens.get(dayPortionIndex);
Tag t1Tag = t1.getTag(RepeaterDayPortion.class);

Object t1TagType = t1Tag.getType();
if (RepeaterDayPortion.DayPortion.MORNING.equals(t1TagType)) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: morning->am");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.AM));
}
else if ((RepeaterDayPortion.DayPortion.AFTERNOON.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.EVENING.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.NIGHT.equals(t1TagType))) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + t1TagType + "->pm");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.PM));
}

}

if (options.getAmbiguousTimeRange() != 0) {
List ttokens = new LinkedList();
for (int i = 0; i < tokenSize; i++) {
Token t0 = (Token)tokens.get(i);
ttokens.add(t0);
Token t1 = null;
if (i < tokenSize - 1) {
t1 = (Token)tokens.get(i + 1);
}
if ((t0.getTag(RepeaterTime.class) != null) && (((Tick)((RepeaterTime)t0.getTag(RepeaterTime.class)).getType()).isAmbiguous()) && ((t1 == null) || (t1.getTag(RepeaterDayPortion.class) == null))) {
Token distoken = new Token("disambiguator");
distoken.tag(new IntegerRepeaterDayPortion(Integer.valueOf(options.getAmbiguousTimeRange())));
ttokens.add(distoken);
}
}
tokens = ttokens;
}

if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + tokens);
}

return tokens;
}
}
package com.sk89q.jchronic.handlers;

import com.sk89q.jchronic.Options;
import com.sk89q.jchronic.repeaters.EnumRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.IntegerRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.Repeater;
import com.sk89q.jchronic.repeaters.RepeaterDayName;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion.DayPortion;
import com.sk89q.jchronic.repeaters.RepeaterMonthName;
import com.sk89q.jchronic.repeaters.RepeaterTime;
import com.sk89q.jchronic.tags.Grabber;
import com.sk89q.jchronic.tags.Grabber.Relative;
import com.sk89q.jchronic.tags.Ordinal;
import com.sk89q.jchronic.tags.OrdinalDay;
import com.sk89q.jchronic.tags.Pointer;
import com.sk89q.jchronic.tags.Pointer.PointerType;
import com.sk89q.jchronic.tags.Scalar;
import com.sk89q.jchronic.tags.ScalarDay;
import com.sk89q.jchronic.tags.ScalarMonth;
import com.sk89q.jchronic.tags.ScalarYear;
import com.sk89q.jchronic.tags.Separator;
import com.sk89q.jchronic.tags.SeparatorAt;
import com.sk89q.jchronic.tags.SeparatorComma;
import com.sk89q.jchronic.tags.SeparatorIn;
import com.sk89q.jchronic.tags.SeparatorSlashOrDash;
import com.sk89q.jchronic.tags.Tag;
import com.sk89q.jchronic.tags.TimeZone;
import com.sk89q.jchronic.utils.Span;
import com.sk89q.jchronic.utils.Tick;
import com.sk89q.jchronic.utils.Time;
import com.sk89q.jchronic.utils.Token;
import java.io.PrintStream;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class Handler
{
private static Map<Handler.HandlerType, List<Handler>> _definitions;
private HandlerPattern[] _patterns;
private IHandler _handler;
private boolean _compatible;

public Handler(IHandler handler, HandlerPattern[] patterns)
{
this(handler, true, patterns);
}

public Handler(IHandler handler, boolean compatible, HandlerPattern[] patterns) {
this._handler = handler;
this._compatible = compatible;
this._patterns = patterns;
}

public boolean isCompatible(Options options) {
return (!options.isCompatibilityMode()) || (this._compatible);
}

public IHandler getHandler() {
return this._handler;
}

public boolean match(List<Token> tokens, Map<Handler.HandlerType, List<Handler>> definitions)
{
int tokenIndex = 0;
for (HandlerPattern pattern : this._patterns) {
boolean optional = pattern.isOptional();
if ((pattern instanceof TagPattern)) {
boolean match = (tokenIndex < tokens.size()) && (((Token)tokens.get(tokenIndex)).getTags(((TagPattern)pattern).getTagClass()).size() > 0);

if ((!match) && (!optional)) {
return false;
}
if (match) {
tokenIndex++;
}

}
else if ((pattern instanceof HandlerTypePattern)) {
if ((optional) && (tokenIndex == tokens.size())) {
return true;
}
List subHandlers = (List)definitions.get(((HandlerTypePattern)pattern).getType());
for (Handler subHandler : subHandlers) {
if (subHandler.match(tokens.subList(tokenIndex, tokens.size()), definitions)) {
return true;
}
}
return false;
}
}

return tokenIndex == tokens.size();
}

public String toString()
{
return "[Handler: " + this._handler + "]";
}

public static synchronized Map<Handler.HandlerType, List<Handler>> definitions() {
if (_definitions == null) {
Map definitions = new HashMap();

List timeHandlers = new LinkedList();
timeHandlers.add(new Handler(null, new HandlerPattern[] { new TagPattern(RepeaterTime.class), new TagPattern(RepeaterDayPortion.class, true) }));
definitions.put(Handler.HandlerType.TIME, timeHandlers);

List dateHandlers = new LinkedList();
dateHandlers.add(new Handler(new RdnRmnSdTTzSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterDayName.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(RepeaterTime.class), new TagPattern(TimeZone.class), new TagPattern(ScalarYear.class) }));

dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorComma.class, true), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnOdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(OrdinalDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new SdRmnSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SmSdSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SdSmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SySmSdHandler(), new HandlerPattern[] { new TagPattern(ScalarYear.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));

dateHandlers.add(new Handler(new SmSdHandler(), false, new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class) }));
dateHandlers.add(new Handler(new SmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class) }));
definitions.put(Handler.HandlerType.DATE, dateHandlers);

List anchorHandlers = new LinkedList();
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RGRHandler(), new HandlerPattern[] { new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.ANCHOR, anchorHandlers);

List arrowHandlers = new LinkedList();
arrowHandlers.add(new Handler(new SRPHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class) }));
arrowHandlers.add(new Handler(new PSRHandler(), new HandlerPattern[] { new TagPattern(Pointer.class), new TagPattern(Scalar.class), new TagPattern(Repeater.class) }));
arrowHandlers.add(new Handler(new SRPAHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class), new HandlerTypePattern(Handler.HandlerType.ANCHOR) }));
definitions.put(Handler.HandlerType.ARROW, arrowHandlers);

List narrowHandlers = new LinkedList();
narrowHandlers.add(new Handler(new ORSRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(SeparatorIn.class), new TagPattern(Repeater.class) }));
narrowHandlers.add(new Handler(new ORGRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.NARROW, narrowHandlers);
_definitions = definitions;
}
return _definitions;
}

public static Span tokensToSpan(List<Token> tokens, Options options) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: " + tokens);
}

Map definitions = definitions();
for (Handler handler : (List)definitions.get(Handler.HandlerType.DATE)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: date");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ANCHOR)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: anchor");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: arrow");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if ((token.getTag(SeparatorAt.class) == null) && (token.getTag(SeparatorSlashOrDash.class) == null) && (token.getTag(SeparatorComma.class) == null)) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.NARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: narrow");
}

return handler.getHandler().handle(tokens, options);
}

}

if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: none");
}
return null;
}

public static List<Repeater<?>> getRepeaters(List<Token> tokens) {
List repeaters = new LinkedList();
for (Token token : tokens) {
Repeater tag = (Repeater)token.getTag(Repeater.class);
if (tag != null) {
repeaters.add(tag);
}
}
Collections.sort(repeaters);
Collections.reverse(repeaters);
return repeaters;
}

public static Span getAnchor(List<Token> tokens, Options options) {
Grabber grabber = new Grabber(Grabber.Relative.THIS);
Pointer.PointerType pointer = Pointer.PointerType.FUTURE;

List repeaters = getRepeaters(tokens);
for (int i = 0; i < repeaters.size(); i++) {
tokens.remove(tokens.size() - 1);
}

if ((!tokens.isEmpty()) && (((Token)tokens.get(0)).getTag(Grabber.class) != null)) {
grabber = (Grabber)((Token)tokens.get(0)).getTag(Grabber.class);
tokens.remove(tokens.size() - 1);
}

Repeater head = (Repeater)repeaters.remove(0);
head.setStart((Calendar)options.getNow().clone());

Grabber.Relative grabberType = (Grabber.Relative)grabber.getType();
Span outerSpan;
if (grabberType == Grabber.Relative.LAST) {
outerSpan = head.nextSpan(Pointer.PointerType.PAST);
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.THIS)
{
Span outerSpan;
if (repeaters.size() > 0) {
outerSpan = head.thisSpan(Pointer.PointerType.NONE);
}
else
outerSpan = head.thisSpan(options.getContext());
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.NEXT) {
outerSpan = head.nextSpan(Pointer.PointerType.FUTURE);
}
else
throw new IllegalArgumentException("Invalid grabber type " + grabberType + ".");
}
}
Span outerSpan;
if (options.isDebug()) {
System.out.println("Chronic.getAnchor: outerSpan = " + outerSpan + "; repeaters = " + repeaters);
}

Span anchor = findWithin(repeaters, outerSpan, pointer, options);
return anchor;
}

public static Span dayOrTime(Calendar dayStart, List<Token> timeTokens, Options options) {
Span outerSpan = new Span(dayStart, Time.cloneAndAdd(dayStart, 5, 1L));
if (!timeTokens.isEmpty())
{
options.setNow(outerSpan.getBeginCalendar());
Span time = getAnchor(dealiasAndDisambiguateTimes(timeTokens, options), options);
return time;
}
return outerSpan;
}

public static Span findWithin(List<Repeater<?>> tags, Span span, Pointer.PointerType pointer, Options options)
{
if (options.isDebug()) {
System.out.println("Chronic.findWithin: " + tags + " in " + span);
}
if (tags.isEmpty()) {
return span;
}
Repeater head = (Repeater)tags.get(0);
List rest = tags.size() > 1 ? tags.subList(1, tags.size()) : new LinkedList();
head.setStart(pointer == Pointer.PointerType.FUTURE ? span.getBeginCalendar() : span.getEndCalendar());
Span h = head.thisSpan(Pointer.PointerType.NONE);

if ((span.contains(h.getBegin())) || (span.contains(h.getEnd()))) {
return findWithin(rest, h, pointer, options);
}
return null;
}

public static List<Token> dealiasAndDisambiguateTimes(List<Token> tokens, Options options)
{
int dayPortionIndex = -1;
int tokenSize = tokens.size();
for (int i = 0; (dayPortionIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterDayPortion.class) != null) {
dayPortionIndex = i;
}
}

int timeIndex = -1;
for (int i = 0; (timeIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterTime.class) != null) {
timeIndex = i;
}
}

if ((dayPortionIndex != -1) && (timeIndex != -1)) {
Token t1 = (Token)tokens.get(dayPortionIndex);
Tag t1Tag = t1.getTag(RepeaterDayPortion.class);

Object t1TagType = t1Tag.getType();
if (RepeaterDayPortion.DayPortion.MORNING.equals(t1TagType)) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: morning->am");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.AM));
}
else if ((RepeaterDayPortion.DayPortion.AFTERNOON.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.EVENING.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.NIGHT.equals(t1TagType))) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + t1TagType + "->pm");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.PM));
}

}

if (options.getAmbiguousTimeRange() != 0) {
List ttokens = new LinkedList();
for (int i = 0; i < tokenSize; i++) {
Token t0 = (Token)tokens.get(i);
ttokens.add(t0);
Token t1 = null;
if (i < tokenSize - 1) {
t1 = (Token)tokens.get(i + 1);
}
if ((t0.getTag(RepeaterTime.class) != null) && (((Tick)((RepeaterTime)t0.getTag(RepeaterTime.class)).getType()).isAmbiguous()) && ((t1 == null) || (t1.getTag(RepeaterDayPortion.class) == null))) {
Token distoken = new Token("disambiguator");
distoken.tag(new IntegerRepeaterDayPortion(Integer.valueOf(options.getAmbiguousTimeRange())));
ttokens.add(distoken);
}
}
tokens = ttokens;
}

if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + tokens);
}

return tokens;
}
}
package com.sk89q.jchronic.handlers;

import com.sk89q.jchronic.Options;
import com.sk89q.jchronic.repeaters.EnumRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.IntegerRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.Repeater;
import com.sk89q.jchronic.repeaters.RepeaterDayName;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion.DayPortion;
import com.sk89q.jchronic.repeaters.RepeaterMonthName;
import com.sk89q.jchronic.repeaters.RepeaterTime;
import com.sk89q.jchronic.tags.Grabber;
import com.sk89q.jchronic.tags.Grabber.Relative;
import com.sk89q.jchronic.tags.Ordinal;
import com.sk89q.jchronic.tags.OrdinalDay;
import com.sk89q.jchronic.tags.Pointer;
import com.sk89q.jchronic.tags.Pointer.PointerType;
import com.sk89q.jchronic.tags.Scalar;
import com.sk89q.jchronic.tags.ScalarDay;
import com.sk89q.jchronic.tags.ScalarMonth;
import com.sk89q.jchronic.tags.ScalarYear;
import com.sk89q.jchronic.tags.Separator;
import com.sk89q.jchronic.tags.SeparatorAt;
import com.sk89q.jchronic.tags.SeparatorComma;
import com.sk89q.jchronic.tags.SeparatorIn;
import com.sk89q.jchronic.tags.SeparatorSlashOrDash;
import com.sk89q.jchronic.tags.Tag;
import com.sk89q.jchronic.tags.TimeZone;
import com.sk89q.jchronic.utils.Span;
import com.sk89q.jchronic.utils.Tick;
import com.sk89q.jchronic.utils.Time;
import com.sk89q.jchronic.utils.Token;
import java.io.PrintStream;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class Handler
{
private static Map<Handler.HandlerType, List<Handler>> _definitions;
private HandlerPattern[] _patterns;
private IHandler _handler;
private boolean _compatible;

public Handler(IHandler handler, HandlerPattern[] patterns)
{
this(handler, true, patterns);
}

public Handler(IHandler handler, boolean compatible, HandlerPattern[] patterns) {
this._handler = handler;
this._compatible = compatible;
this._patterns = patterns;
}

public boolean isCompatible(Options options) {
return (!options.isCompatibilityMode()) || (this._compatible);
}

public IHandler getHandler() {
return this._handler;
}

public boolean match(List<Token> tokens, Map<Handler.HandlerType, List<Handler>> definitions)
{
int tokenIndex = 0;
for (HandlerPattern pattern : this._patterns) {
boolean optional = pattern.isOptional();
if ((pattern instanceof TagPattern)) {
boolean match = (tokenIndex < tokens.size()) && (((Token)tokens.get(tokenIndex)).getTags(((TagPattern)pattern).getTagClass()).size() > 0);

if ((!match) && (!optional)) {
return false;
}
if (match) {
tokenIndex++;
}

}
else if ((pattern instanceof HandlerTypePattern)) {
if ((optional) && (tokenIndex == tokens.size())) {
return true;
}
List subHandlers = (List)definitions.get(((HandlerTypePattern)pattern).getType());
for (Handler subHandler : subHandlers) {
if (subHandler.match(tokens.subList(tokenIndex, tokens.size()), definitions)) {
return true;
}
}
return false;
}
}

return tokenIndex == tokens.size();
}

public String toString()
{
return "[Handler: " + this._handler + "]";
}

public static synchronized Map<Handler.HandlerType, List<Handler>> definitions() {
if (_definitions == null) {
Map definitions = new HashMap();

List timeHandlers = new LinkedList();
timeHandlers.add(new Handler(null, new HandlerPattern[] { new TagPattern(RepeaterTime.class), new TagPattern(RepeaterDayPortion.class, true) }));
definitions.put(Handler.HandlerType.TIME, timeHandlers);

List dateHandlers = new LinkedList();
dateHandlers.add(new Handler(new RdnRmnSdTTzSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterDayName.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(RepeaterTime.class), new TagPattern(TimeZone.class), new TagPattern(ScalarYear.class) }));

dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorComma.class, true), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnOdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(OrdinalDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new SdRmnSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SmSdSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SdSmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SySmSdHandler(), new HandlerPattern[] { new TagPattern(ScalarYear.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));

dateHandlers.add(new Handler(new SmSdHandler(), false, new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class) }));
dateHandlers.add(new Handler(new SmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class) }));
definitions.put(Handler.HandlerType.DATE, dateHandlers);

List anchorHandlers = new LinkedList();
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RGRHandler(), new HandlerPattern[] { new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.ANCHOR, anchorHandlers);

List arrowHandlers = new LinkedList();
arrowHandlers.add(new Handler(new SRPHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class) }));
arrowHandlers.add(new Handler(new PSRHandler(), new HandlerPattern[] { new TagPattern(Pointer.class), new TagPattern(Scalar.class), new TagPattern(Repeater.class) }));
arrowHandlers.add(new Handler(new SRPAHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class), new HandlerTypePattern(Handler.HandlerType.ANCHOR) }));
definitions.put(Handler.HandlerType.ARROW, arrowHandlers);

List narrowHandlers = new LinkedList();
narrowHandlers.add(new Handler(new ORSRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(SeparatorIn.class), new TagPattern(Repeater.class) }));
narrowHandlers.add(new Handler(new ORGRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.NARROW, narrowHandlers);
_definitions = definitions;
}
return _definitions;
}

public static Span tokensToSpan(List<Token> tokens, Options options) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: " + tokens);
}

Map definitions = definitions();
for (Handler handler : (List)definitions.get(Handler.HandlerType.DATE)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: date");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ANCHOR)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: anchor");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: arrow");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if ((token.getTag(SeparatorAt.class) == null) && (token.getTag(SeparatorSlashOrDash.class) == null) && (token.getTag(SeparatorComma.class) == null)) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.NARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: narrow");
}

return handler.getHandler().handle(tokens, options);
}

}

if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: none");
}
return null;
}

public static List<Repeater<?>> getRepeaters(List<Token> tokens) {
List repeaters = new LinkedList();
for (Token token : tokens) {
Repeater tag = (Repeater)token.getTag(Repeater.class);
if (tag != null) {
repeaters.add(tag);
}
}
Collections.sort(repeaters);
Collections.reverse(repeaters);
return repeaters;
}

public static Span getAnchor(List<Token> tokens, Options options) {
Grabber grabber = new Grabber(Grabber.Relative.THIS);
Pointer.PointerType pointer = Pointer.PointerType.FUTURE;

List repeaters = getRepeaters(tokens);
for (int i = 0; i < repeaters.size(); i++) {
tokens.remove(tokens.size() - 1);
}

if ((!tokens.isEmpty()) && (((Token)tokens.get(0)).getTag(Grabber.class) != null)) {
grabber = (Grabber)((Token)tokens.get(0)).getTag(Grabber.class);
tokens.remove(tokens.size() - 1);
}

Repeater head = (Repeater)repeaters.remove(0);
head.setStart((Calendar)options.getNow().clone());

Grabber.Relative grabberType = (Grabber.Relative)grabber.getType();
Span outerSpan;
if (grabberType == Grabber.Relative.LAST) {
outerSpan = head.nextSpan(Pointer.PointerType.PAST);
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.THIS)
{
Span outerSpan;
if (repeaters.size() > 0) {
outerSpan = head.thisSpan(Pointer.PointerType.NONE);
}
else
outerSpan = head.thisSpan(options.getContext());
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.NEXT) {
outerSpan = head.nextSpan(Pointer.PointerType.FUTURE);
}
else
throw new IllegalArgumentException("Invalid grabber type " + grabberType + ".");
}
}
Span outerSpan;
if (options.isDebug()) {
System.out.println("Chronic.getAnchor: outerSpan = " + outerSpan + "; repeaters = " + repeaters);
}

Span anchor = findWithin(repeaters, outerSpan, pointer, options);
return anchor;
}

public static Span dayOrTime(Calendar dayStart, List<Token> timeTokens, Options options) {
Span outerSpan = new Span(dayStart, Time.cloneAndAdd(dayStart, 5, 1L));
if (!timeTokens.isEmpty())
{
options.setNow(outerSpan.getBeginCalendar());
Span time = getAnchor(dealiasAndDisambiguateTimes(timeTokens, options), options);
return time;
}
return outerSpan;
}

public static Span findWithin(List<Repeater<?>> tags, Span span, Pointer.PointerType pointer, Options options)
{
if (options.isDebug()) {
System.out.println("Chronic.findWithin: " + tags + " in " + span);
}
if (tags.isEmpty()) {
return span;
}
Repeater head = (Repeater)tags.get(0);
List rest = tags.size() > 1 ? tags.subList(1, tags.size()) : new LinkedList();
head.setStart(pointer == Pointer.PointerType.FUTURE ? span.getBeginCalendar() : span.getEndCalendar());
Span h = head.thisSpan(Pointer.PointerType.NONE);

if ((span.contains(h.getBegin())) || (span.contains(h.getEnd()))) {
return findWithin(rest, h, pointer, options);
}
return null;
}

public static List<Token> dealiasAndDisambiguateTimes(List<Token> tokens, Options options)
{
int dayPortionIndex = -1;
int tokenSize = tokens.size();
for (int i = 0; (dayPortionIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterDayPortion.class) != null) {
dayPortionIndex = i;
}
}

int timeIndex = -1;
for (int i = 0; (timeIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterTime.class) != null) {
timeIndex = i;
}
}

if ((dayPortionIndex != -1) && (timeIndex != -1)) {
Token t1 = (Token)tokens.get(dayPortionIndex);
Tag t1Tag = t1.getTag(RepeaterDayPortion.class);

Object t1TagType = t1Tag.getType();
if (RepeaterDayPortion.DayPortion.MORNING.equals(t1TagType)) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: morning->am");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.AM));
}
else if ((RepeaterDayPortion.DayPortion.AFTERNOON.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.EVENING.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.NIGHT.equals(t1TagType))) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + t1TagType + "->pm");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.PM));
}

}

if (options.getAmbiguousTimeRange() != 0) {
List ttokens = new LinkedList();
for (int i = 0; i < tokenSize; i++) {
Token t0 = (Token)tokens.get(i);
ttokens.add(t0);
Token t1 = null;
if (i < tokenSize - 1) {
t1 = (Token)tokens.get(i + 1);
}
if ((t0.getTag(RepeaterTime.class) != null) && (((Tick)((RepeaterTime)t0.getTag(RepeaterTime.class)).getType()).isAmbiguous()) && ((t1 == null) || (t1.getTag(RepeaterDayPortion.class) == null))) {
Token distoken = new Token("disambiguator");
distoken.tag(new IntegerRepeaterDayPortion(Integer.valueOf(options.getAmbiguousTimeRange())));
ttokens.add(distoken);
}
}
tokens = ttokens;
}

if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + tokens);
}

return tokens;
}
}
package com.sk89q.jchronic.handlers;

import com.sk89q.jchronic.Options;
import com.sk89q.jchronic.repeaters.EnumRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.IntegerRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.Repeater;
import com.sk89q.jchronic.repeaters.RepeaterDayName;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion.DayPortion;
import com.sk89q.jchronic.repeaters.RepeaterMonthName;
import com.sk89q.jchronic.repeaters.RepeaterTime;
import com.sk89q.jchronic.tags.Grabber;
import com.sk89q.jchronic.tags.Grabber.Relative;
import com.sk89q.jchronic.tags.Ordinal;
import com.sk89q.jchronic.tags.OrdinalDay;
import com.sk89q.jchronic.tags.Pointer;
import com.sk89q.jchronic.tags.Pointer.PointerType;
import com.sk89q.jchronic.tags.Scalar;
import com.sk89q.jchronic.tags.ScalarDay;
import com.sk89q.jchronic.tags.ScalarMonth;
import com.sk89q.jchronic.tags.ScalarYear;
import com.sk89q.jchronic.tags.Separator;
import com.sk89q.jchronic.tags.SeparatorAt;
import com.sk89q.jchronic.tags.SeparatorComma;
import com.sk89q.jchronic.tags.SeparatorIn;
import com.sk89q.jchronic.tags.SeparatorSlashOrDash;
import com.sk89q.jchronic.tags.Tag;
import com.sk89q.jchronic.tags.TimeZone;
import com.sk89q.jchronic.utils.Span;
import com.sk89q.jchronic.utils.Tick;
import com.sk89q.jchronic.utils.Time;
import com.sk89q.jchronic.utils.Token;
import java.io.PrintStream;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class Handler
{
private static Map<Handler.HandlerType, List<Handler>> _definitions;
private HandlerPattern[] _patterns;
private IHandler _handler;
private boolean _compatible;

public Handler(IHandler handler, HandlerPattern[] patterns)
{
this(handler, true, patterns);
}

public Handler(IHandler handler, boolean compatible, HandlerPattern[] patterns) {
this._handler = handler;
this._compatible = compatible;
this._patterns = patterns;
}

public boolean isCompatible(Options options) {
return (!options.isCompatibilityMode()) || (this._compatible);
}

public IHandler getHandler() {
return this._handler;
}

public boolean match(List<Token> tokens, Map<Handler.HandlerType, List<Handler>> definitions)
{
int tokenIndex = 0;
for (HandlerPattern pattern : this._patterns) {
boolean optional = pattern.isOptional();
if ((pattern instanceof TagPattern)) {
boolean match = (tokenIndex < tokens.size()) && (((Token)tokens.get(tokenIndex)).getTags(((TagPattern)pattern).getTagClass()).size() > 0);

if ((!match) && (!optional)) {
return false;
}
if (match) {
tokenIndex++;
}

}
else if ((pattern instanceof HandlerTypePattern)) {
if ((optional) && (tokenIndex == tokens.size())) {
return true;
}
List subHandlers = (List)definitions.get(((HandlerTypePattern)pattern).getType());
for (Handler subHandler : subHandlers) {
if (subHandler.match(tokens.subList(tokenIndex, tokens.size()), definitions)) {
return true;
}
}
return false;
}
}

return tokenIndex == tokens.size();
}

public String toString()
{
return "[Handler: " + this._handler + "]";
}

public static synchronized Map<Handler.HandlerType, List<Handler>> definitions() {
if (_definitions == null) {
Map definitions = new HashMap();

List timeHandlers = new LinkedList();
timeHandlers.add(new Handler(null, new HandlerPattern[] { new TagPattern(RepeaterTime.class), new TagPattern(RepeaterDayPortion.class, true) }));
definitions.put(Handler.HandlerType.TIME, timeHandlers);

List dateHandlers = new LinkedList();
dateHandlers.add(new Handler(new RdnRmnSdTTzSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterDayName.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(RepeaterTime.class), new TagPattern(TimeZone.class), new TagPattern(ScalarYear.class) }));

dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorComma.class, true), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnOdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(OrdinalDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new SdRmnSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SmSdSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SdSmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SySmSdHandler(), new HandlerPattern[] { new TagPattern(ScalarYear.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));

dateHandlers.add(new Handler(new SmSdHandler(), false, new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class) }));
dateHandlers.add(new Handler(new SmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class) }));
definitions.put(Handler.HandlerType.DATE, dateHandlers);

List anchorHandlers = new LinkedList();
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RGRHandler(), new HandlerPattern[] { new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.ANCHOR, anchorHandlers);

List arrowHandlers = new LinkedList();
arrowHandlers.add(new Handler(new SRPHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class) }));
arrowHandlers.add(new Handler(new PSRHandler(), new HandlerPattern[] { new TagPattern(Pointer.class), new TagPattern(Scalar.class), new TagPattern(Repeater.class) }));
arrowHandlers.add(new Handler(new SRPAHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class), new HandlerTypePattern(Handler.HandlerType.ANCHOR) }));
definitions.put(Handler.HandlerType.ARROW, arrowHandlers);

List narrowHandlers = new LinkedList();
narrowHandlers.add(new Handler(new ORSRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(SeparatorIn.class), new TagPattern(Repeater.class) }));
narrowHandlers.add(new Handler(new ORGRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.NARROW, narrowHandlers);
_definitions = definitions;
}
return _definitions;
}

public static Span tokensToSpan(List<Token> tokens, Options options) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: " + tokens);
}

Map definitions = definitions();
for (Handler handler : (List)definitions.get(Handler.HandlerType.DATE)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: date");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ANCHOR)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: anchor");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: arrow");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if ((token.getTag(SeparatorAt.class) == null) && (token.getTag(SeparatorSlashOrDash.class) == null) && (token.getTag(SeparatorComma.class) == null)) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.NARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: narrow");
}

return handler.getHandler().handle(tokens, options);
}

}

if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: none");
}
return null;
}

public static List<Repeater<?>> getRepeaters(List<Token> tokens) {
List repeaters = new LinkedList();
for (Token token : tokens) {
Repeater tag = (Repeater)token.getTag(Repeater.class);
if (tag != null) {
repeaters.add(tag);
}
}
Collections.sort(repeaters);
Collections.reverse(repeaters);
return repeaters;
}

public static Span getAnchor(List<Token> tokens, Options options) {
Grabber grabber = new Grabber(Grabber.Relative.THIS);
Pointer.PointerType pointer = Pointer.PointerType.FUTURE;

List repeaters = getRepeaters(tokens);
for (int i = 0; i < repeaters.size(); i++) {
tokens.remove(tokens.size() - 1);
}

if ((!tokens.isEmpty()) && (((Token)tokens.get(0)).getTag(Grabber.class) != null)) {
grabber = (Grabber)((Token)tokens.get(0)).getTag(Grabber.class);
tokens.remove(tokens.size() - 1);
}

Repeater head = (Repeater)repeaters.remove(0);
head.setStart((Calendar)options.getNow().clone());

Grabber.Relative grabberType = (Grabber.Relative)grabber.getType();
Span outerSpan;
if (grabberType == Grabber.Relative.LAST) {
outerSpan = head.nextSpan(Pointer.PointerType.PAST);
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.THIS)
{
Span outerSpan;
if (repeaters.size() > 0) {
outerSpan = head.thisSpan(Pointer.PointerType.NONE);
}
else
outerSpan = head.thisSpan(options.getContext());
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.NEXT) {
outerSpan = head.nextSpan(Pointer.PointerType.FUTURE);
}
else
throw new IllegalArgumentException("Invalid grabber type " + grabberType + ".");
}
}
Span outerSpan;
if (options.isDebug()) {
System.out.println("Chronic.getAnchor: outerSpan = " + outerSpan + "; repeaters = " + repeaters);
}

Span anchor = findWithin(repeaters, outerSpan, pointer, options);
return anchor;
}

public static Span dayOrTime(Calendar dayStart, List<Token> timeTokens, Options options) {
Span outerSpan = new Span(dayStart, Time.cloneAndAdd(dayStart, 5, 1L));
if (!timeTokens.isEmpty())
{
options.setNow(outerSpan.getBeginCalendar());
Span time = getAnchor(dealiasAndDisambiguateTimes(timeTokens, options), options);
return time;
}
return outerSpan;
}

public static Span findWithin(List<Repeater<?>> tags, Span span, Pointer.PointerType pointer, Options options)
{
if (options.isDebug()) {
System.out.println("Chronic.findWithin: " + tags + " in " + span);
}
if (tags.isEmpty()) {
return span;
}
Repeater head = (Repeater)tags.get(0);
List rest = tags.size() > 1 ? tags.subList(1, tags.size()) : new LinkedList();
head.setStart(pointer == Pointer.PointerType.FUTURE ? span.getBeginCalendar() : span.getEndCalendar());
Span h = head.thisSpan(Pointer.PointerType.NONE);

if ((span.contains(h.getBegin())) || (span.contains(h.getEnd()))) {
return findWithin(rest, h, pointer, options);
}
return null;
}

public static List<Token> dealiasAndDisambiguateTimes(List<Token> tokens, Options options)
{
int dayPortionIndex = -1;
int tokenSize = tokens.size();
for (int i = 0; (dayPortionIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterDayPortion.class) != null) {
dayPortionIndex = i;
}
}

int timeIndex = -1;
for (int i = 0; (timeIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterTime.class) != null) {
timeIndex = i;
}
}

if ((dayPortionIndex != -1) && (timeIndex != -1)) {
Token t1 = (Token)tokens.get(dayPortionIndex);
Tag t1Tag = t1.getTag(RepeaterDayPortion.class);

Object t1TagType = t1Tag.getType();
if (RepeaterDayPortion.DayPortion.MORNING.equals(t1TagType)) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: morning->am");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.AM));
}
else if ((RepeaterDayPortion.DayPortion.AFTERNOON.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.EVENING.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.NIGHT.equals(t1TagType))) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + t1TagType + "->pm");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.PM));
}

}

if (options.getAmbiguousTimeRange() != 0) {
List ttokens = new LinkedList();
for (int i = 0; i < tokenSize; i++) {
Token t0 = (Token)tokens.get(i);
ttokens.add(t0);
Token t1 = null;
if (i < tokenSize - 1) {
t1 = (Token)tokens.get(i + 1);
}
if ((t0.getTag(RepeaterTime.class) != null) && (((Tick)((RepeaterTime)t0.getTag(RepeaterTime.class)).getType()).isAmbiguous()) && ((t1 == null) || (t1.getTag(RepeaterDayPortion.class) == null))) {
Token distoken = new Token("disambiguator");
distoken.tag(new IntegerRepeaterDayPortion(Integer.valueOf(options.getAmbiguousTimeRange())));
ttokens.add(distoken);
}
}
tokens = ttokens;
}

if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + tokens);
}

return tokens;
}
}
package com.sk89q.jchronic.handlers;

import com.sk89q.jchronic.Options;
import com.sk89q.jchronic.repeaters.EnumRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.IntegerRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.Repeater;
import com.sk89q.jchronic.repeaters.RepeaterDayName;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion.DayPortion;
import com.sk89q.jchronic.repeaters.RepeaterMonthName;
import com.sk89q.jchronic.repeaters.RepeaterTime;
import com.sk89q.jchronic.tags.Grabber;
import com.sk89q.jchronic.tags.Grabber.Relative;
import com.sk89q.jchronic.tags.Ordinal;
import com.sk89q.jchronic.tags.OrdinalDay;
import com.sk89q.jchronic.tags.Pointer;
import com.sk89q.jchronic.tags.Pointer.PointerType;
import com.sk89q.jchronic.tags.Scalar;
import com.sk89q.jchronic.tags.ScalarDay;
import com.sk89q.jchronic.tags.ScalarMonth;
import com.sk89q.jchronic.tags.ScalarYear;
import com.sk89q.jchronic.tags.Separator;
import com.sk89q.jchronic.tags.SeparatorAt;
import com.sk89q.jchronic.tags.SeparatorComma;
import com.sk89q.jchronic.tags.SeparatorIn;
import com.sk89q.jchronic.tags.SeparatorSlashOrDash;
import com.sk89q.jchronic.tags.Tag;
import com.sk89q.jchronic.tags.TimeZone;
import com.sk89q.jchronic.utils.Span;
import com.sk89q.jchronic.utils.Tick;
import com.sk89q.jchronic.utils.Time;
import com.sk89q.jchronic.utils.Token;
import java.io.PrintStream;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class Handler
{
private static Map<Handler.HandlerType, List<Handler>> _definitions;
private HandlerPattern[] _patterns;
private IHandler _handler;
private boolean _compatible;

public Handler(IHandler handler, HandlerPattern[] patterns)
{
this(handler, true, patterns);
}

public Handler(IHandler handler, boolean compatible, HandlerPattern[] patterns) {
this._handler = handler;
this._compatible = compatible;
this._patterns = patterns;
}

public boolean isCompatible(Options options) {
return (!options.isCompatibilityMode()) || (this._compatible);
}

public IHandler getHandler() {
return this._handler;
}

public boolean match(List<Token> tokens, Map<Handler.HandlerType, List<Handler>> definitions)
{
int tokenIndex = 0;
for (HandlerPattern pattern : this._patterns) {
boolean optional = pattern.isOptional();
if ((pattern instanceof TagPattern)) {
boolean match = (tokenIndex < tokens.size()) && (((Token)tokens.get(tokenIndex)).getTags(((TagPattern)pattern).getTagClass()).size() > 0);

if ((!match) && (!optional)) {
return false;
}
if (match) {
tokenIndex++;
}

}
else if ((pattern instanceof HandlerTypePattern)) {
if ((optional) && (tokenIndex == tokens.size())) {
return true;
}
List subHandlers = (List)definitions.get(((HandlerTypePattern)pattern).getType());
for (Handler subHandler : subHandlers) {
if (subHandler.match(tokens.subList(tokenIndex, tokens.size()), definitions)) {
return true;
}
}
return false;
}
}

return tokenIndex == tokens.size();
}

public String toString()
{
return "[Handler: " + this._handler + "]";
}

public static synchronized Map<Handler.HandlerType, List<Handler>> definitions() {
if (_definitions == null) {
Map definitions = new HashMap();

List timeHandlers = new LinkedList();
timeHandlers.add(new Handler(null, new HandlerPattern[] { new TagPattern(RepeaterTime.class), new TagPattern(RepeaterDayPortion.class, true) }));
definitions.put(Handler.HandlerType.TIME, timeHandlers);

List dateHandlers = new LinkedList();
dateHandlers.add(new Handler(new RdnRmnSdTTzSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterDayName.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(RepeaterTime.class), new TagPattern(TimeZone.class), new TagPattern(ScalarYear.class) }));

dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorComma.class, true), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnOdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(OrdinalDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new SdRmnSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SmSdSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SdSmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SySmSdHandler(), new HandlerPattern[] { new TagPattern(ScalarYear.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));

dateHandlers.add(new Handler(new SmSdHandler(), false, new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class) }));
dateHandlers.add(new Handler(new SmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class) }));
definitions.put(Handler.HandlerType.DATE, dateHandlers);

List anchorHandlers = new LinkedList();
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RGRHandler(), new HandlerPattern[] { new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.ANCHOR, anchorHandlers);

List arrowHandlers = new LinkedList();
arrowHandlers.add(new Handler(new SRPHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class) }));
arrowHandlers.add(new Handler(new PSRHandler(), new HandlerPattern[] { new TagPattern(Pointer.class), new TagPattern(Scalar.class), new TagPattern(Repeater.class) }));
arrowHandlers.add(new Handler(new SRPAHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class), new HandlerTypePattern(Handler.HandlerType.ANCHOR) }));
definitions.put(Handler.HandlerType.ARROW, arrowHandlers);

List narrowHandlers = new LinkedList();
narrowHandlers.add(new Handler(new ORSRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(SeparatorIn.class), new TagPattern(Repeater.class) }));
narrowHandlers.add(new Handler(new ORGRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.NARROW, narrowHandlers);
_definitions = definitions;
}
return _definitions;
}

public static Span tokensToSpan(List<Token> tokens, Options options) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: " + tokens);
}

Map definitions = definitions();
for (Handler handler : (List)definitions.get(Handler.HandlerType.DATE)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: date");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ANCHOR)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: anchor");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: arrow");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if ((token.getTag(SeparatorAt.class) == null) && (token.getTag(SeparatorSlashOrDash.class) == null) && (token.getTag(SeparatorComma.class) == null)) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.NARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: narrow");
}

return handler.getHandler().handle(tokens, options);
}

}

if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: none");
}
return null;
}

public static List<Repeater<?>> getRepeaters(List<Token> tokens) {
List repeaters = new LinkedList();
for (Token token : tokens) {
Repeater tag = (Repeater)token.getTag(Repeater.class);
if (tag != null) {
repeaters.add(tag);
}
}
Collections.sort(repeaters);
Collections.reverse(repeaters);
return repeaters;
}

public static Span getAnchor(List<Token> tokens, Options options) {
Grabber grabber = new Grabber(Grabber.Relative.THIS);
Pointer.PointerType pointer = Pointer.PointerType.FUTURE;

List repeaters = getRepeaters(tokens);
for (int i = 0; i < repeaters.size(); i++) {
tokens.remove(tokens.size() - 1);
}

if ((!tokens.isEmpty()) && (((Token)tokens.get(0)).getTag(Grabber.class) != null)) {
grabber = (Grabber)((Token)tokens.get(0)).getTag(Grabber.class);
tokens.remove(tokens.size() - 1);
}

Repeater head = (Repeater)repeaters.remove(0);
head.setStart((Calendar)options.getNow().clone());

Grabber.Relative grabberType = (Grabber.Relative)grabber.getType();
Span outerSpan;
if (grabberType == Grabber.Relative.LAST) {
outerSpan = head.nextSpan(Pointer.PointerType.PAST);
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.THIS)
{
Span outerSpan;
if (repeaters.size() > 0) {
outerSpan = head.thisSpan(Pointer.PointerType.NONE);
}
else
outerSpan = head.thisSpan(options.getContext());
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.NEXT) {
outerSpan = head.nextSpan(Pointer.PointerType.FUTURE);
}
else
throw new IllegalArgumentException("Invalid grabber type " + grabberType + ".");
}
}
Span outerSpan;
if (options.isDebug()) {
System.out.println("Chronic.getAnchor: outerSpan = " + outerSpan + "; repeaters = " + repeaters);
}

Span anchor = findWithin(repeaters, outerSpan, pointer, options);
return anchor;
}

public static Span dayOrTime(Calendar dayStart, List<Token> timeTokens, Options options) {
Span outerSpan = new Span(dayStart, Time.cloneAndAdd(dayStart, 5, 1L));
if (!timeTokens.isEmpty())
{
options.setNow(outerSpan.getBeginCalendar());
Span time = getAnchor(dealiasAndDisambiguateTimes(timeTokens, options), options);
return time;
}
return outerSpan;
}

public static Span findWithin(List<Repeater<?>> tags, Span span, Pointer.PointerType pointer, Options options)
{
if (options.isDebug()) {
System.out.println("Chronic.findWithin: " + tags + " in " + span);
}
if (tags.isEmpty()) {
return span;
}
Repeater head = (Repeater)tags.get(0);
List rest = tags.size() > 1 ? tags.subList(1, tags.size()) : new LinkedList();
head.setStart(pointer == Pointer.PointerType.FUTURE ? span.getBeginCalendar() : span.getEndCalendar());
Span h = head.thisSpan(Pointer.PointerType.NONE);

if ((span.contains(h.getBegin())) || (span.contains(h.getEnd()))) {
return findWithin(rest, h, pointer, options);
}
return null;
}

public static List<Token> dealiasAndDisambiguateTimes(List<Token> tokens, Options options)
{
int dayPortionIndex = -1;
int tokenSize = tokens.size();
for (int i = 0; (dayPortionIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterDayPortion.class) != null) {
dayPortionIndex = i;
}
}

int timeIndex = -1;
for (int i = 0; (timeIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterTime.class) != null) {
timeIndex = i;
}
}

if ((dayPortionIndex != -1) && (timeIndex != -1)) {
Token t1 = (Token)tokens.get(dayPortionIndex);
Tag t1Tag = t1.getTag(RepeaterDayPortion.class);

Object t1TagType = t1Tag.getType();
if (RepeaterDayPortion.DayPortion.MORNING.equals(t1TagType)) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: morning->am");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.AM));
}
else if ((RepeaterDayPortion.DayPortion.AFTERNOON.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.EVENING.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.NIGHT.equals(t1TagType))) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + t1TagType + "->pm");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.PM));
}

}

if (options.getAmbiguousTimeRange() != 0) {
List ttokens = new LinkedList();
for (int i = 0; i < tokenSize; i++) {
Token t0 = (Token)tokens.get(i);
ttokens.add(t0);
Token t1 = null;
if (i < tokenSize - 1) {
t1 = (Token)tokens.get(i + 1);
}
if ((t0.getTag(RepeaterTime.class) != null) && (((Tick)((RepeaterTime)t0.getTag(RepeaterTime.class)).getType()).isAmbiguous()) && ((t1 == null) || (t1.getTag(RepeaterDayPortion.class) == null))) {
Token distoken = new Token("disambiguator");
distoken.tag(new IntegerRepeaterDayPortion(Integer.valueOf(options.getAmbiguousTimeRange())));
ttokens.add(distoken);
}
}
tokens = ttokens;
}

if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + tokens);
}

return tokens;
}
}
package com.sk89q.jchronic.handlers;

import com.sk89q.jchronic.Options;
import com.sk89q.jchronic.repeaters.EnumRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.IntegerRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.Repeater;
import com.sk89q.jchronic.repeaters.RepeaterDayName;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion.DayPortion;
import com.sk89q.jchronic.repeaters.RepeaterMonthName;
import com.sk89q.jchronic.repeaters.RepeaterTime;
import com.sk89q.jchronic.tags.Grabber;
import com.sk89q.jchronic.tags.Grabber.Relative;
import com.sk89q.jchronic.tags.Ordinal;
import com.sk89q.jchronic.tags.OrdinalDay;
import com.sk89q.jchronic.tags.Pointer;
import com.sk89q.jchronic.tags.Pointer.PointerType;
import com.sk89q.jchronic.tags.Scalar;
import com.sk89q.jchronic.tags.ScalarDay;
import com.sk89q.jchronic.tags.ScalarMonth;
import com.sk89q.jchronic.tags.ScalarYear;
import com.sk89q.jchronic.tags.Separator;
import com.sk89q.jchronic.tags.SeparatorAt;
import com.sk89q.jchronic.tags.SeparatorComma;
import com.sk89q.jchronic.tags.SeparatorIn;
import com.sk89q.jchronic.tags.SeparatorSlashOrDash;
import com.sk89q.jchronic.tags.Tag;
import com.sk89q.jchronic.tags.TimeZone;
import com.sk89q.jchronic.utils.Span;
import com.sk89q.jchronic.utils.Tick;
import com.sk89q.jchronic.utils.Time;
import com.sk89q.jchronic.utils.Token;
import java.io.PrintStream;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class Handler
{
private static Map<Handler.HandlerType, List<Handler>> _definitions;
private HandlerPattern[] _patterns;
private IHandler _handler;
private boolean _compatible;

public Handler(IHandler handler, HandlerPattern[] patterns)
{
this(handler, true, patterns);
}

public Handler(IHandler handler, boolean compatible, HandlerPattern[] patterns) {
this._handler = handler;
this._compatible = compatible;
this._patterns = patterns;
}

public boolean isCompatible(Options options) {
return (!options.isCompatibilityMode()) || (this._compatible);
}

public IHandler getHandler() {
return this._handler;
}

public boolean match(List<Token> tokens, Map<Handler.HandlerType, List<Handler>> definitions)
{
int tokenIndex = 0;
for (HandlerPattern pattern : this._patterns) {
boolean optional = pattern.isOptional();
if ((pattern instanceof TagPattern)) {
boolean match = (tokenIndex < tokens.size()) && (((Token)tokens.get(tokenIndex)).getTags(((TagPattern)pattern).getTagClass()).size() > 0);

if ((!match) && (!optional)) {
return false;
}
if (match) {
tokenIndex++;
}

}
else if ((pattern instanceof HandlerTypePattern)) {
if ((optional) && (tokenIndex == tokens.size())) {
return true;
}
List subHandlers = (List)definitions.get(((HandlerTypePattern)pattern).getType());
for (Handler subHandler : subHandlers) {
if (subHandler.match(tokens.subList(tokenIndex, tokens.size()), definitions)) {
return true;
}
}
return false;
}
}

return tokenIndex == tokens.size();
}

public String toString()
{
return "[Handler: " + this._handler + "]";
}

public static synchronized Map<Handler.HandlerType, List<Handler>> definitions() {
if (_definitions == null) {
Map definitions = new HashMap();

List timeHandlers = new LinkedList();
timeHandlers.add(new Handler(null, new HandlerPattern[] { new TagPattern(RepeaterTime.class), new TagPattern(RepeaterDayPortion.class, true) }));
definitions.put(Handler.HandlerType.TIME, timeHandlers);

List dateHandlers = new LinkedList();
dateHandlers.add(new Handler(new RdnRmnSdTTzSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterDayName.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(RepeaterTime.class), new TagPattern(TimeZone.class), new TagPattern(ScalarYear.class) }));

dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorComma.class, true), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnOdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(OrdinalDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new SdRmnSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SmSdSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SdSmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SySmSdHandler(), new HandlerPattern[] { new TagPattern(ScalarYear.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));

dateHandlers.add(new Handler(new SmSdHandler(), false, new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class) }));
dateHandlers.add(new Handler(new SmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class) }));
definitions.put(Handler.HandlerType.DATE, dateHandlers);

List anchorHandlers = new LinkedList();
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RGRHandler(), new HandlerPattern[] { new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.ANCHOR, anchorHandlers);

List arrowHandlers = new LinkedList();
arrowHandlers.add(new Handler(new SRPHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class) }));
arrowHandlers.add(new Handler(new PSRHandler(), new HandlerPattern[] { new TagPattern(Pointer.class), new TagPattern(Scalar.class), new TagPattern(Repeater.class) }));
arrowHandlers.add(new Handler(new SRPAHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class), new HandlerTypePattern(Handler.HandlerType.ANCHOR) }));
definitions.put(Handler.HandlerType.ARROW, arrowHandlers);

List narrowHandlers = new LinkedList();
narrowHandlers.add(new Handler(new ORSRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(SeparatorIn.class), new TagPattern(Repeater.class) }));
narrowHandlers.add(new Handler(new ORGRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.NARROW, narrowHandlers);
_definitions = definitions;
}
return _definitions;
}

public static Span tokensToSpan(List<Token> tokens, Options options) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: " + tokens);
}

Map definitions = definitions();
for (Handler handler : (List)definitions.get(Handler.HandlerType.DATE)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: date");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ANCHOR)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: anchor");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: arrow");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if ((token.getTag(SeparatorAt.class) == null) && (token.getTag(SeparatorSlashOrDash.class) == null) && (token.getTag(SeparatorComma.class) == null)) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.NARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: narrow");
}

return handler.getHandler().handle(tokens, options);
}

}

if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: none");
}
return null;
}

public static List<Repeater<?>> getRepeaters(List<Token> tokens) {
List repeaters = new LinkedList();
for (Token token : tokens) {
Repeater tag = (Repeater)token.getTag(Repeater.class);
if (tag != null) {
repeaters.add(tag);
}
}
Collections.sort(repeaters);
Collections.reverse(repeaters);
return repeaters;
}

public static Span getAnchor(List<Token> tokens, Options options) {
Grabber grabber = new Grabber(Grabber.Relative.THIS);
Pointer.PointerType pointer = Pointer.PointerType.FUTURE;

List repeaters = getRepeaters(tokens);
for (int i = 0; i < repeaters.size(); i++) {
tokens.remove(tokens.size() - 1);
}

if ((!tokens.isEmpty()) && (((Token)tokens.get(0)).getTag(Grabber.class) != null)) {
grabber = (Grabber)((Token)tokens.get(0)).getTag(Grabber.class);
tokens.remove(tokens.size() - 1);
}

Repeater head = (Repeater)repeaters.remove(0);
head.setStart((Calendar)options.getNow().clone());

Grabber.Relative grabberType = (Grabber.Relative)grabber.getType();
Span outerSpan;
if (grabberType == Grabber.Relative.LAST) {
outerSpan = head.nextSpan(Pointer.PointerType.PAST);
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.THIS)
{
Span outerSpan;
if (repeaters.size() > 0) {
outerSpan = head.thisSpan(Pointer.PointerType.NONE);
}
else
outerSpan = head.thisSpan(options.getContext());
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.NEXT) {
outerSpan = head.nextSpan(Pointer.PointerType.FUTURE);
}
else
throw new IllegalArgumentException("Invalid grabber type " + grabberType + ".");
}
}
Span outerSpan;
if (options.isDebug()) {
System.out.println("Chronic.getAnchor: outerSpan = " + outerSpan + "; repeaters = " + repeaters);
}

Span anchor = findWithin(repeaters, outerSpan, pointer, options);
return anchor;
}

public static Span dayOrTime(Calendar dayStart, List<Token> timeTokens, Options options) {
Span outerSpan = new Span(dayStart, Time.cloneAndAdd(dayStart, 5, 1L));
if (!timeTokens.isEmpty())
{
options.setNow(outerSpan.getBeginCalendar());
Span time = getAnchor(dealiasAndDisambiguateTimes(timeTokens, options), options);
return time;
}
return outerSpan;
}

public static Span findWithin(List<Repeater<?>> tags, Span span, Pointer.PointerType pointer, Options options)
{
if (options.isDebug()) {
System.out.println("Chronic.findWithin: " + tags + " in " + span);
}
if (tags.isEmpty()) {
return span;
}
Repeater head = (Repeater)tags.get(0);
List rest = tags.size() > 1 ? tags.subList(1, tags.size()) : new LinkedList();
head.setStart(pointer == Pointer.PointerType.FUTURE ? span.getBeginCalendar() : span.getEndCalendar());
Span h = head.thisSpan(Pointer.PointerType.NONE);

if ((span.contains(h.getBegin())) || (span.contains(h.getEnd()))) {
return findWithin(rest, h, pointer, options);
}
return null;
}

public static List<Token> dealiasAndDisambiguateTimes(List<Token> tokens, Options options)
{
int dayPortionIndex = -1;
int tokenSize = tokens.size();
for (int i = 0; (dayPortionIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterDayPortion.class) != null) {
dayPortionIndex = i;
}
}

int timeIndex = -1;
for (int i = 0; (timeIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterTime.class) != null) {
timeIndex = i;
}
}

if ((dayPortionIndex != -1) && (timeIndex != -1)) {
Token t1 = (Token)tokens.get(dayPortionIndex);
Tag t1Tag = t1.getTag(RepeaterDayPortion.class);

Object t1TagType = t1Tag.getType();
if (RepeaterDayPortion.DayPortion.MORNING.equals(t1TagType)) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: morning->am");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.AM));
}
else if ((RepeaterDayPortion.DayPortion.AFTERNOON.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.EVENING.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.NIGHT.equals(t1TagType))) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + t1TagType + "->pm");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.PM));
}

}

if (options.getAmbiguousTimeRange() != 0) {
List ttokens = new LinkedList();
for (int i = 0; i < tokenSize; i++) {
Token t0 = (Token)tokens.get(i);
ttokens.add(t0);
Token t1 = null;
if (i < tokenSize - 1) {
t1 = (Token)tokens.get(i + 1);
}
if ((t0.getTag(RepeaterTime.class) != null) && (((Tick)((RepeaterTime)t0.getTag(RepeaterTime.class)).getType()).isAmbiguous()) && ((t1 == null) || (t1.getTag(RepeaterDayPortion.class) == null))) {
Token distoken = new Token("disambiguator");
distoken.tag(new IntegerRepeaterDayPortion(Integer.valueOf(options.getAmbiguousTimeRange())));
ttokens.add(distoken);
}
}
tokens = ttokens;
}

if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + tokens);
}

return tokens;
}
}
package com.sk89q.jchronic.handlers;

import com.sk89q.jchronic.Options;
import com.sk89q.jchronic.repeaters.EnumRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.IntegerRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.Repeater;
import com.sk89q.jchronic.repeaters.RepeaterDayName;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion.DayPortion;
import com.sk89q.jchronic.repeaters.RepeaterMonthName;
import com.sk89q.jchronic.repeaters.RepeaterTime;
import com.sk89q.jchronic.tags.Grabber;
import com.sk89q.jchronic.tags.Grabber.Relative;
import com.sk89q.jchronic.tags.Ordinal;
import com.sk89q.jchronic.tags.OrdinalDay;
import com.sk89q.jchronic.tags.Pointer;
import com.sk89q.jchronic.tags.Pointer.PointerType;
import com.sk89q.jchronic.tags.Scalar;
import com.sk89q.jchronic.tags.ScalarDay;
import com.sk89q.jchronic.tags.ScalarMonth;
import com.sk89q.jchronic.tags.ScalarYear;
import com.sk89q.jchronic.tags.Separator;
import com.sk89q.jchronic.tags.SeparatorAt;
import com.sk89q.jchronic.tags.SeparatorComma;
import com.sk89q.jchronic.tags.SeparatorIn;
import com.sk89q.jchronic.tags.SeparatorSlashOrDash;
import com.sk89q.jchronic.tags.Tag;
import com.sk89q.jchronic.tags.TimeZone;
import com.sk89q.jchronic.utils.Span;
import com.sk89q.jchronic.utils.Tick;
import com.sk89q.jchronic.utils.Time;
import com.sk89q.jchronic.utils.Token;
import java.io.PrintStream;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class Handler
{
private static Map<Handler.HandlerType, List<Handler>> _definitions;
private HandlerPattern[] _patterns;
private IHandler _handler;
private boolean _compatible;

public Handler(IHandler handler, HandlerPattern[] patterns)
{
this(handler, true, patterns);
}

public Handler(IHandler handler, boolean compatible, HandlerPattern[] patterns) {
this._handler = handler;
this._compatible = compatible;
this._patterns = patterns;
}

public boolean isCompatible(Options options) {
return (!options.isCompatibilityMode()) || (this._compatible);
}

public IHandler getHandler() {
return this._handler;
}

public boolean match(List<Token> tokens, Map<Handler.HandlerType, List<Handler>> definitions)
{
int tokenIndex = 0;
for (HandlerPattern pattern : this._patterns) {
boolean optional = pattern.isOptional();
if ((pattern instanceof TagPattern)) {
boolean match = (tokenIndex < tokens.size()) && (((Token)tokens.get(tokenIndex)).getTags(((TagPattern)pattern).getTagClass()).size() > 0);

if ((!match) && (!optional)) {
return false;
}
if (match) {
tokenIndex++;
}

}
else if ((pattern instanceof HandlerTypePattern)) {
if ((optional) && (tokenIndex == tokens.size())) {
return true;
}
List subHandlers = (List)definitions.get(((HandlerTypePattern)pattern).getType());
for (Handler subHandler : subHandlers) {
if (subHandler.match(tokens.subList(tokenIndex, tokens.size()), definitions)) {
return true;
}
}
return false;
}
}

return tokenIndex == tokens.size();
}

public String toString()
{
return "[Handler: " + this._handler + "]";
}

public static synchronized Map<Handler.HandlerType, List<Handler>> definitions() {
if (_definitions == null) {
Map definitions = new HashMap();

List timeHandlers = new LinkedList();
timeHandlers.add(new Handler(null, new HandlerPattern[] { new TagPattern(RepeaterTime.class), new TagPattern(RepeaterDayPortion.class, true) }));
definitions.put(Handler.HandlerType.TIME, timeHandlers);

List dateHandlers = new LinkedList();
dateHandlers.add(new Handler(new RdnRmnSdTTzSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterDayName.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(RepeaterTime.class), new TagPattern(TimeZone.class), new TagPattern(ScalarYear.class) }));

dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorComma.class, true), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnOdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(OrdinalDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new SdRmnSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SmSdSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SdSmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SySmSdHandler(), new HandlerPattern[] { new TagPattern(ScalarYear.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));

dateHandlers.add(new Handler(new SmSdHandler(), false, new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class) }));
dateHandlers.add(new Handler(new SmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class) }));
definitions.put(Handler.HandlerType.DATE, dateHandlers);

List anchorHandlers = new LinkedList();
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RGRHandler(), new HandlerPattern[] { new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.ANCHOR, anchorHandlers);

List arrowHandlers = new LinkedList();
arrowHandlers.add(new Handler(new SRPHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class) }));
arrowHandlers.add(new Handler(new PSRHandler(), new HandlerPattern[] { new TagPattern(Pointer.class), new TagPattern(Scalar.class), new TagPattern(Repeater.class) }));
arrowHandlers.add(new Handler(new SRPAHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class), new HandlerTypePattern(Handler.HandlerType.ANCHOR) }));
definitions.put(Handler.HandlerType.ARROW, arrowHandlers);

List narrowHandlers = new LinkedList();
narrowHandlers.add(new Handler(new ORSRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(SeparatorIn.class), new TagPattern(Repeater.class) }));
narrowHandlers.add(new Handler(new ORGRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.NARROW, narrowHandlers);
_definitions = definitions;
}
return _definitions;
}

public static Span tokensToSpan(List<Token> tokens, Options options) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: " + tokens);
}

Map definitions = definitions();
for (Handler handler : (List)definitions.get(Handler.HandlerType.DATE)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: date");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ANCHOR)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: anchor");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: arrow");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if ((token.getTag(SeparatorAt.class) == null) && (token.getTag(SeparatorSlashOrDash.class) == null) && (token.getTag(SeparatorComma.class) == null)) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.NARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: narrow");
}

return handler.getHandler().handle(tokens, options);
}

}

if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: none");
}
return null;
}

public static List<Repeater<?>> getRepeaters(List<Token> tokens) {
List repeaters = new LinkedList();
for (Token token : tokens) {
Repeater tag = (Repeater)token.getTag(Repeater.class);
if (tag != null) {
repeaters.add(tag);
}
}
Collections.sort(repeaters);
Collections.reverse(repeaters);
return repeaters;
}

public static Span getAnchor(List<Token> tokens, Options options) {
Grabber grabber = new Grabber(Grabber.Relative.THIS);
Pointer.PointerType pointer = Pointer.PointerType.FUTURE;

List repeaters = getRepeaters(tokens);
for (int i = 0; i < repeaters.size(); i++) {
tokens.remove(tokens.size() - 1);
}

if ((!tokens.isEmpty()) && (((Token)tokens.get(0)).getTag(Grabber.class) != null)) {
grabber = (Grabber)((Token)tokens.get(0)).getTag(Grabber.class);
tokens.remove(tokens.size() - 1);
}

Repeater head = (Repeater)repeaters.remove(0);
head.setStart((Calendar)options.getNow().clone());

Grabber.Relative grabberType = (Grabber.Relative)grabber.getType();
Span outerSpan;
if (grabberType == Grabber.Relative.LAST) {
outerSpan = head.nextSpan(Pointer.PointerType.PAST);
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.THIS)
{
Span outerSpan;
if (repeaters.size() > 0) {
outerSpan = head.thisSpan(Pointer.PointerType.NONE);
}
else
outerSpan = head.thisSpan(options.getContext());
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.NEXT) {
outerSpan = head.nextSpan(Pointer.PointerType.FUTURE);
}
else
throw new IllegalArgumentException("Invalid grabber type " + grabberType + ".");
}
}
Span outerSpan;
if (options.isDebug()) {
System.out.println("Chronic.getAnchor: outerSpan = " + outerSpan + "; repeaters = " + repeaters);
}

Span anchor = findWithin(repeaters, outerSpan, pointer, options);
return anchor;
}

public static Span dayOrTime(Calendar dayStart, List<Token> timeTokens, Options options) {
Span outerSpan = new Span(dayStart, Time.cloneAndAdd(dayStart, 5, 1L));
if (!timeTokens.isEmpty())
{
options.setNow(outerSpan.getBeginCalendar());
Span time = getAnchor(dealiasAndDisambiguateTimes(timeTokens, options), options);
return time;
}
return outerSpan;
}

public static Span findWithin(List<Repeater<?>> tags, Span span, Pointer.PointerType pointer, Options options)
{
if (options.isDebug()) {
System.out.println("Chronic.findWithin: " + tags + " in " + span);
}
if (tags.isEmpty()) {
return span;
}
Repeater head = (Repeater)tags.get(0);
List rest = tags.size() > 1 ? tags.subList(1, tags.size()) : new LinkedList();
head.setStart(pointer == Pointer.PointerType.FUTURE ? span.getBeginCalendar() : span.getEndCalendar());
Span h = head.thisSpan(Pointer.PointerType.NONE);

if ((span.contains(h.getBegin())) || (span.contains(h.getEnd()))) {
return findWithin(rest, h, pointer, options);
}
return null;
}

public static List<Token> dealiasAndDisambiguateTimes(List<Token> tokens, Options options)
{
int dayPortionIndex = -1;
int tokenSize = tokens.size();
for (int i = 0; (dayPortionIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterDayPortion.class) != null) {
dayPortionIndex = i;
}
}

int timeIndex = -1;
for (int i = 0; (timeIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterTime.class) != null) {
timeIndex = i;
}
}

if ((dayPortionIndex != -1) && (timeIndex != -1)) {
Token t1 = (Token)tokens.get(dayPortionIndex);
Tag t1Tag = t1.getTag(RepeaterDayPortion.class);

Object t1TagType = t1Tag.getType();
if (RepeaterDayPortion.DayPortion.MORNING.equals(t1TagType)) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: morning->am");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.AM));
}
else if ((RepeaterDayPortion.DayPortion.AFTERNOON.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.EVENING.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.NIGHT.equals(t1TagType))) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + t1TagType + "->pm");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.PM));
}

}

if (options.getAmbiguousTimeRange() != 0) {
List ttokens = new LinkedList();
for (int i = 0; i < tokenSize; i++) {
Token t0 = (Token)tokens.get(i);
ttokens.add(t0);
Token t1 = null;
if (i < tokenSize - 1) {
t1 = (Token)tokens.get(i + 1);
}
if ((t0.getTag(RepeaterTime.class) != null) && (((Tick)((RepeaterTime)t0.getTag(RepeaterTime.class)).getType()).isAmbiguous()) && ((t1 == null) || (t1.getTag(RepeaterDayPortion.class) == null))) {
Token distoken = new Token("disambiguator");
distoken.tag(new IntegerRepeaterDayPortion(Integer.valueOf(options.getAmbiguousTimeRange())));
ttokens.add(distoken);
}
}
tokens = ttokens;
}

if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + tokens);
}

return tokens;
}
}
package com.sk89q.jchronic.handlers;

import com.sk89q.jchronic.Options;
import com.sk89q.jchronic.repeaters.EnumRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.IntegerRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.Repeater;
import com.sk89q.jchronic.repeaters.RepeaterDayName;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion.DayPortion;
import com.sk89q.jchronic.repeaters.RepeaterMonthName;
import com.sk89q.jchronic.repeaters.RepeaterTime;
import com.sk89q.jchronic.tags.Grabber;
import com.sk89q.jchronic.tags.Grabber.Relative;
import com.sk89q.jchronic.tags.Ordinal;
import com.sk89q.jchronic.tags.OrdinalDay;
import com.sk89q.jchronic.tags.Pointer;
import com.sk89q.jchronic.tags.Pointer.PointerType;
import com.sk89q.jchronic.tags.Scalar;
import com.sk89q.jchronic.tags.ScalarDay;
import com.sk89q.jchronic.tags.ScalarMonth;
import com.sk89q.jchronic.tags.ScalarYear;
import com.sk89q.jchronic.tags.Separator;
import com.sk89q.jchronic.tags.SeparatorAt;
import com.sk89q.jchronic.tags.SeparatorComma;
import com.sk89q.jchronic.tags.SeparatorIn;
import com.sk89q.jchronic.tags.SeparatorSlashOrDash;
import com.sk89q.jchronic.tags.Tag;
import com.sk89q.jchronic.tags.TimeZone;
import com.sk89q.jchronic.utils.Span;
import com.sk89q.jchronic.utils.Tick;
import com.sk89q.jchronic.utils.Time;
import com.sk89q.jchronic.utils.Token;
import java.io.PrintStream;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class Handler
{
private static Map<Handler.HandlerType, List<Handler>> _definitions;
private HandlerPattern[] _patterns;
private IHandler _handler;
private boolean _compatible;

public Handler(IHandler handler, HandlerPattern[] patterns)
{
this(handler, true, patterns);
}

public Handler(IHandler handler, boolean compatible, HandlerPattern[] patterns) {
this._handler = handler;
this._compatible = compatible;
this._patterns = patterns;
}

public boolean isCompatible(Options options) {
return (!options.isCompatibilityMode()) || (this._compatible);
}

public IHandler getHandler() {
return this._handler;
}

public boolean match(List<Token> tokens, Map<Handler.HandlerType, List<Handler>> definitions)
{
int tokenIndex = 0;
for (HandlerPattern pattern : this._patterns) {
boolean optional = pattern.isOptional();
if ((pattern instanceof TagPattern)) {
boolean match = (tokenIndex < tokens.size()) && (((Token)tokens.get(tokenIndex)).getTags(((TagPattern)pattern).getTagClass()).size() > 0);

if ((!match) && (!optional)) {
return false;
}
if (match) {
tokenIndex++;
}

}
else if ((pattern instanceof HandlerTypePattern)) {
if ((optional) && (tokenIndex == tokens.size())) {
return true;
}
List subHandlers = (List)definitions.get(((HandlerTypePattern)pattern).getType());
for (Handler subHandler : subHandlers) {
if (subHandler.match(tokens.subList(tokenIndex, tokens.size()), definitions)) {
return true;
}
}
return false;
}
}

return tokenIndex == tokens.size();
}

public String toString()
{
return "[Handler: " + this._handler + "]";
}

public static synchronized Map<Handler.HandlerType, List<Handler>> definitions() {
if (_definitions == null) {
Map definitions = new HashMap();

List timeHandlers = new LinkedList();
timeHandlers.add(new Handler(null, new HandlerPattern[] { new TagPattern(RepeaterTime.class), new TagPattern(RepeaterDayPortion.class, true) }));
definitions.put(Handler.HandlerType.TIME, timeHandlers);

List dateHandlers = new LinkedList();
dateHandlers.add(new Handler(new RdnRmnSdTTzSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterDayName.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(RepeaterTime.class), new TagPattern(TimeZone.class), new TagPattern(ScalarYear.class) }));

dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorComma.class, true), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnOdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(OrdinalDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new SdRmnSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SmSdSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SdSmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SySmSdHandler(), new HandlerPattern[] { new TagPattern(ScalarYear.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));

dateHandlers.add(new Handler(new SmSdHandler(), false, new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class) }));
dateHandlers.add(new Handler(new SmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class) }));
definitions.put(Handler.HandlerType.DATE, dateHandlers);

List anchorHandlers = new LinkedList();
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RGRHandler(), new HandlerPattern[] { new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.ANCHOR, anchorHandlers);

List arrowHandlers = new LinkedList();
arrowHandlers.add(new Handler(new SRPHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class) }));
arrowHandlers.add(new Handler(new PSRHandler(), new HandlerPattern[] { new TagPattern(Pointer.class), new TagPattern(Scalar.class), new TagPattern(Repeater.class) }));
arrowHandlers.add(new Handler(new SRPAHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class), new HandlerTypePattern(Handler.HandlerType.ANCHOR) }));
definitions.put(Handler.HandlerType.ARROW, arrowHandlers);

List narrowHandlers = new LinkedList();
narrowHandlers.add(new Handler(new ORSRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(SeparatorIn.class), new TagPattern(Repeater.class) }));
narrowHandlers.add(new Handler(new ORGRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.NARROW, narrowHandlers);
_definitions = definitions;
}
return _definitions;
}

public static Span tokensToSpan(List<Token> tokens, Options options) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: " + tokens);
}

Map definitions = definitions();
for (Handler handler : (List)definitions.get(Handler.HandlerType.DATE)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: date");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ANCHOR)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: anchor");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: arrow");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if ((token.getTag(SeparatorAt.class) == null) && (token.getTag(SeparatorSlashOrDash.class) == null) && (token.getTag(SeparatorComma.class) == null)) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.NARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: narrow");
}

return handler.getHandler().handle(tokens, options);
}

}

if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: none");
}
return null;
}

public static List<Repeater<?>> getRepeaters(List<Token> tokens) {
List repeaters = new LinkedList();
for (Token token : tokens) {
Repeater tag = (Repeater)token.getTag(Repeater.class);
if (tag != null) {
repeaters.add(tag);
}
}
Collections.sort(repeaters);
Collections.reverse(repeaters);
return repeaters;
}

public static Span getAnchor(List<Token> tokens, Options options) {
Grabber grabber = new Grabber(Grabber.Relative.THIS);
Pointer.PointerType pointer = Pointer.PointerType.FUTURE;

List repeaters = getRepeaters(tokens);
for (int i = 0; i < repeaters.size(); i++) {
tokens.remove(tokens.size() - 1);
}

if ((!tokens.isEmpty()) && (((Token)tokens.get(0)).getTag(Grabber.class) != null)) {
grabber = (Grabber)((Token)tokens.get(0)).getTag(Grabber.class);
tokens.remove(tokens.size() - 1);
}

Repeater head = (Repeater)repeaters.remove(0);
head.setStart((Calendar)options.getNow().clone());

Grabber.Relative grabberType = (Grabber.Relative)grabber.getType();
Span outerSpan;
if (grabberType == Grabber.Relative.LAST) {
outerSpan = head.nextSpan(Pointer.PointerType.PAST);
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.THIS)
{
Span outerSpan;
if (repeaters.size() > 0) {
outerSpan = head.thisSpan(Pointer.PointerType.NONE);
}
else
outerSpan = head.thisSpan(options.getContext());
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.NEXT) {
outerSpan = head.nextSpan(Pointer.PointerType.FUTURE);
}
else
throw new IllegalArgumentException("Invalid grabber type " + grabberType + ".");
}
}
Span outerSpan;
if (options.isDebug()) {
System.out.println("Chronic.getAnchor: outerSpan = " + outerSpan + "; repeaters = " + repeaters);
}

Span anchor = findWithin(repeaters, outerSpan, pointer, options);
return anchor;
}

public static Span dayOrTime(Calendar dayStart, List<Token> timeTokens, Options options) {
Span outerSpan = new Span(dayStart, Time.cloneAndAdd(dayStart, 5, 1L));
if (!timeTokens.isEmpty())
{
options.setNow(outerSpan.getBeginCalendar());
Span time = getAnchor(dealiasAndDisambiguateTimes(timeTokens, options), options);
return time;
}
return outerSpan;
}

public static Span findWithin(List<Repeater<?>> tags, Span span, Pointer.PointerType pointer, Options options)
{
if (options.isDebug()) {
System.out.println("Chronic.findWithin: " + tags + " in " + span);
}
if (tags.isEmpty()) {
return span;
}
Repeater head = (Repeater)tags.get(0);
List rest = tags.size() > 1 ? tags.subList(1, tags.size()) : new LinkedList();
head.setStart(pointer == Pointer.PointerType.FUTURE ? span.getBeginCalendar() : span.getEndCalendar());
Span h = head.thisSpan(Pointer.PointerType.NONE);

if ((span.contains(h.getBegin())) || (span.contains(h.getEnd()))) {
return findWithin(rest, h, pointer, options);
}
return null;
}

public static List<Token> dealiasAndDisambiguateTimes(List<Token> tokens, Options options)
{
int dayPortionIndex = -1;
int tokenSize = tokens.size();
for (int i = 0; (dayPortionIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterDayPortion.class) != null) {
dayPortionIndex = i;
}
}

int timeIndex = -1;
for (int i = 0; (timeIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterTime.class) != null) {
timeIndex = i;
}
}

if ((dayPortionIndex != -1) && (timeIndex != -1)) {
Token t1 = (Token)tokens.get(dayPortionIndex);
Tag t1Tag = t1.getTag(RepeaterDayPortion.class);

Object t1TagType = t1Tag.getType();
if (RepeaterDayPortion.DayPortion.MORNING.equals(t1TagType)) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: morning->am");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.AM));
}
else if ((RepeaterDayPortion.DayPortion.AFTERNOON.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.EVENING.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.NIGHT.equals(t1TagType))) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + t1TagType + "->pm");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.PM));
}

}

if (options.getAmbiguousTimeRange() != 0) {
List ttokens = new LinkedList();
for (int i = 0; i < tokenSize; i++) {
Token t0 = (Token)tokens.get(i);
ttokens.add(t0);
Token t1 = null;
if (i < tokenSize - 1) {
t1 = (Token)tokens.get(i + 1);
}
if ((t0.getTag(RepeaterTime.class) != null) && (((Tick)((RepeaterTime)t0.getTag(RepeaterTime.class)).getType()).isAmbiguous()) && ((t1 == null) || (t1.getTag(RepeaterDayPortion.class) == null))) {
Token distoken = new Token("disambiguator");
distoken.tag(new IntegerRepeaterDayPortion(Integer.valueOf(options.getAmbiguousTimeRange())));
ttokens.add(distoken);
}
}
tokens = ttokens;
}

if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + tokens);
}

return tokens;
}
}
package com.sk89q.jchronic.handlers;

import com.sk89q.jchronic.Options;
import com.sk89q.jchronic.repeaters.EnumRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.IntegerRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.Repeater;
import com.sk89q.jchronic.repeaters.RepeaterDayName;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion.DayPortion;
import com.sk89q.jchronic.repeaters.RepeaterMonthName;
import com.sk89q.jchronic.repeaters.RepeaterTime;
import com.sk89q.jchronic.tags.Grabber;
import com.sk89q.jchronic.tags.Grabber.Relative;
import com.sk89q.jchronic.tags.Ordinal;
import com.sk89q.jchronic.tags.OrdinalDay;
import com.sk89q.jchronic.tags.Pointer;
import com.sk89q.jchronic.tags.Pointer.PointerType;
import com.sk89q.jchronic.tags.Scalar;
import com.sk89q.jchronic.tags.ScalarDay;
import com.sk89q.jchronic.tags.ScalarMonth;
import com.sk89q.jchronic.tags.ScalarYear;
import com.sk89q.jchronic.tags.Separator;
import com.sk89q.jchronic.tags.SeparatorAt;
import com.sk89q.jchronic.tags.SeparatorComma;
import com.sk89q.jchronic.tags.SeparatorIn;
import com.sk89q.jchronic.tags.SeparatorSlashOrDash;
import com.sk89q.jchronic.tags.Tag;
import com.sk89q.jchronic.tags.TimeZone;
import com.sk89q.jchronic.utils.Span;
import com.sk89q.jchronic.utils.Tick;
import com.sk89q.jchronic.utils.Time;
import com.sk89q.jchronic.utils.Token;
import java.io.PrintStream;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class Handler
{
private static Map<Handler.HandlerType, List<Handler>> _definitions;
private HandlerPattern[] _patterns;
private IHandler _handler;
private boolean _compatible;

public Handler(IHandler handler, HandlerPattern[] patterns)
{
this(handler, true, patterns);
}

public Handler(IHandler handler, boolean compatible, HandlerPattern[] patterns) {
this._handler = handler;
this._compatible = compatible;
this._patterns = patterns;
}

public boolean isCompatible(Options options) {
return (!options.isCompatibilityMode()) || (this._compatible);
}

public IHandler getHandler() {
return this._handler;
}

public boolean match(List<Token> tokens, Map<Handler.HandlerType, List<Handler>> definitions)
{
int tokenIndex = 0;
for (HandlerPattern pattern : this._patterns) {
boolean optional = pattern.isOptional();
if ((pattern instanceof TagPattern)) {
boolean match = (tokenIndex < tokens.size()) && (((Token)tokens.get(tokenIndex)).getTags(((TagPattern)pattern).getTagClass()).size() > 0);

if ((!match) && (!optional)) {
return false;
}
if (match) {
tokenIndex++;
}

}
else if ((pattern instanceof HandlerTypePattern)) {
if ((optional) && (tokenIndex == tokens.size())) {
return true;
}
List subHandlers = (List)definitions.get(((HandlerTypePattern)pattern).getType());
for (Handler subHandler : subHandlers) {
if (subHandler.match(tokens.subList(tokenIndex, tokens.size()), definitions)) {
return true;
}
}
return false;
}
}

return tokenIndex == tokens.size();
}

public String toString()
{
return "[Handler: " + this._handler + "]";
}

public static synchronized Map<Handler.HandlerType, List<Handler>> definitions() {
if (_definitions == null) {
Map definitions = new HashMap();

List timeHandlers = new LinkedList();
timeHandlers.add(new Handler(null, new HandlerPattern[] { new TagPattern(RepeaterTime.class), new TagPattern(RepeaterDayPortion.class, true) }));
definitions.put(Handler.HandlerType.TIME, timeHandlers);

List dateHandlers = new LinkedList();
dateHandlers.add(new Handler(new RdnRmnSdTTzSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterDayName.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(RepeaterTime.class), new TagPattern(TimeZone.class), new TagPattern(ScalarYear.class) }));

dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorComma.class, true), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnOdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(OrdinalDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new SdRmnSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SmSdSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SdSmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SySmSdHandler(), new HandlerPattern[] { new TagPattern(ScalarYear.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));

dateHandlers.add(new Handler(new SmSdHandler(), false, new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class) }));
dateHandlers.add(new Handler(new SmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class) }));
definitions.put(Handler.HandlerType.DATE, dateHandlers);

List anchorHandlers = new LinkedList();
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RGRHandler(), new HandlerPattern[] { new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.ANCHOR, anchorHandlers);

List arrowHandlers = new LinkedList();
arrowHandlers.add(new Handler(new SRPHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class) }));
arrowHandlers.add(new Handler(new PSRHandler(), new HandlerPattern[] { new TagPattern(Pointer.class), new TagPattern(Scalar.class), new TagPattern(Repeater.class) }));
arrowHandlers.add(new Handler(new SRPAHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class), new HandlerTypePattern(Handler.HandlerType.ANCHOR) }));
definitions.put(Handler.HandlerType.ARROW, arrowHandlers);

List narrowHandlers = new LinkedList();
narrowHandlers.add(new Handler(new ORSRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(SeparatorIn.class), new TagPattern(Repeater.class) }));
narrowHandlers.add(new Handler(new ORGRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.NARROW, narrowHandlers);
_definitions = definitions;
}
return _definitions;
}

public static Span tokensToSpan(List<Token> tokens, Options options) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: " + tokens);
}

Map definitions = definitions();
for (Handler handler : (List)definitions.get(Handler.HandlerType.DATE)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: date");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ANCHOR)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: anchor");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: arrow");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if ((token.getTag(SeparatorAt.class) == null) && (token.getTag(SeparatorSlashOrDash.class) == null) && (token.getTag(SeparatorComma.class) == null)) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.NARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: narrow");
}

return handler.getHandler().handle(tokens, options);
}

}

if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: none");
}
return null;
}

public static List<Repeater<?>> getRepeaters(List<Token> tokens) {
List repeaters = new LinkedList();
for (Token token : tokens) {
Repeater tag = (Repeater)token.getTag(Repeater.class);
if (tag != null) {
repeaters.add(tag);
}
}
Collections.sort(repeaters);
Collections.reverse(repeaters);
return repeaters;
}

public static Span getAnchor(List<Token> tokens, Options options) {
Grabber grabber = new Grabber(Grabber.Relative.THIS);
Pointer.PointerType pointer = Pointer.PointerType.FUTURE;

List repeaters = getRepeaters(tokens);
for (int i = 0; i < repeaters.size(); i++) {
tokens.remove(tokens.size() - 1);
}

if ((!tokens.isEmpty()) && (((Token)tokens.get(0)).getTag(Grabber.class) != null)) {
grabber = (Grabber)((Token)tokens.get(0)).getTag(Grabber.class);
tokens.remove(tokens.size() - 1);
}

Repeater head = (Repeater)repeaters.remove(0);
head.setStart((Calendar)options.getNow().clone());

Grabber.Relative grabberType = (Grabber.Relative)grabber.getType();
Span outerSpan;
if (grabberType == Grabber.Relative.LAST) {
outerSpan = head.nextSpan(Pointer.PointerType.PAST);
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.THIS)
{
Span outerSpan;
if (repeaters.size() > 0) {
outerSpan = head.thisSpan(Pointer.PointerType.NONE);
}
else
outerSpan = head.thisSpan(options.getContext());
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.NEXT) {
outerSpan = head.nextSpan(Pointer.PointerType.FUTURE);
}
else
throw new IllegalArgumentException("Invalid grabber type " + grabberType + ".");
}
}
Span outerSpan;
if (options.isDebug()) {
System.out.println("Chronic.getAnchor: outerSpan = " + outerSpan + "; repeaters = " + repeaters);
}

Span anchor = findWithin(repeaters, outerSpan, pointer, options);
return anchor;
}

public static Span dayOrTime(Calendar dayStart, List<Token> timeTokens, Options options) {
Span outerSpan = new Span(dayStart, Time.cloneAndAdd(dayStart, 5, 1L));
if (!timeTokens.isEmpty())
{
options.setNow(outerSpan.getBeginCalendar());
Span time = getAnchor(dealiasAndDisambiguateTimes(timeTokens, options), options);
return time;
}
return outerSpan;
}

public static Span findWithin(List<Repeater<?>> tags, Span span, Pointer.PointerType pointer, Options options)
{
if (options.isDebug()) {
System.out.println("Chronic.findWithin: " + tags + " in " + span);
}
if (tags.isEmpty()) {
return span;
}
Repeater head = (Repeater)tags.get(0);
List rest = tags.size() > 1 ? tags.subList(1, tags.size()) : new LinkedList();
head.setStart(pointer == Pointer.PointerType.FUTURE ? span.getBeginCalendar() : span.getEndCalendar());
Span h = head.thisSpan(Pointer.PointerType.NONE);

if ((span.contains(h.getBegin())) || (span.contains(h.getEnd()))) {
return findWithin(rest, h, pointer, options);
}
return null;
}

public static List<Token> dealiasAndDisambiguateTimes(List<Token> tokens, Options options)
{
int dayPortionIndex = -1;
int tokenSize = tokens.size();
for (int i = 0; (dayPortionIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterDayPortion.class) != null) {
dayPortionIndex = i;
}
}

int timeIndex = -1;
for (int i = 0; (timeIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterTime.class) != null) {
timeIndex = i;
}
}

if ((dayPortionIndex != -1) && (timeIndex != -1)) {
Token t1 = (Token)tokens.get(dayPortionIndex);
Tag t1Tag = t1.getTag(RepeaterDayPortion.class);

Object t1TagType = t1Tag.getType();
if (RepeaterDayPortion.DayPortion.MORNING.equals(t1TagType)) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: morning->am");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.AM));
}
else if ((RepeaterDayPortion.DayPortion.AFTERNOON.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.EVENING.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.NIGHT.equals(t1TagType))) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + t1TagType + "->pm");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.PM));
}

}

if (options.getAmbiguousTimeRange() != 0) {
List ttokens = new LinkedList();
for (int i = 0; i < tokenSize; i++) {
Token t0 = (Token)tokens.get(i);
ttokens.add(t0);
Token t1 = null;
if (i < tokenSize - 1) {
t1 = (Token)tokens.get(i + 1);
}
if ((t0.getTag(RepeaterTime.class) != null) && (((Tick)((RepeaterTime)t0.getTag(RepeaterTime.class)).getType()).isAmbiguous()) && ((t1 == null) || (t1.getTag(RepeaterDayPortion.class) == null))) {
Token distoken = new Token("disambiguator");
distoken.tag(new IntegerRepeaterDayPortion(Integer.valueOf(options.getAmbiguousTimeRange())));
ttokens.add(distoken);
}
}
tokens = ttokens;
}

if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + tokens);
}

return tokens;
}
}
package com.sk89q.jchronic.handlers;

import com.sk89q.jchronic.Options;
import com.sk89q.jchronic.repeaters.EnumRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.IntegerRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.Repeater;
import com.sk89q.jchronic.repeaters.RepeaterDayName;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion.DayPortion;
import com.sk89q.jchronic.repeaters.RepeaterMonthName;
import com.sk89q.jchronic.repeaters.RepeaterTime;
import com.sk89q.jchronic.tags.Grabber;
import com.sk89q.jchronic.tags.Grabber.Relative;
import com.sk89q.jchronic.tags.Ordinal;
import com.sk89q.jchronic.tags.OrdinalDay;
import com.sk89q.jchronic.tags.Pointer;
import com.sk89q.jchronic.tags.Pointer.PointerType;
import com.sk89q.jchronic.tags.Scalar;
import com.sk89q.jchronic.tags.ScalarDay;
import com.sk89q.jchronic.tags.ScalarMonth;
import com.sk89q.jchronic.tags.ScalarYear;
import com.sk89q.jchronic.tags.Separator;
import com.sk89q.jchronic.tags.SeparatorAt;
import com.sk89q.jchronic.tags.SeparatorComma;
import com.sk89q.jchronic.tags.SeparatorIn;
import com.sk89q.jchronic.tags.SeparatorSlashOrDash;
import com.sk89q.jchronic.tags.Tag;
import com.sk89q.jchronic.tags.TimeZone;
import com.sk89q.jchronic.utils.Span;
import com.sk89q.jchronic.utils.Tick;
import com.sk89q.jchronic.utils.Time;
import com.sk89q.jchronic.utils.Token;
import java.io.PrintStream;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class Handler
{
private static Map<Handler.HandlerType, List<Handler>> _definitions;
private HandlerPattern[] _patterns;
private IHandler _handler;
private boolean _compatible;

public Handler(IHandler handler, HandlerPattern[] patterns)
{
this(handler, true, patterns);
}

public Handler(IHandler handler, boolean compatible, HandlerPattern[] patterns) {
this._handler = handler;
this._compatible = compatible;
this._patterns = patterns;
}

public boolean isCompatible(Options options) {
return (!options.isCompatibilityMode()) || (this._compatible);
}

public IHandler getHandler() {
return this._handler;
}

public boolean match(List<Token> tokens, Map<Handler.HandlerType, List<Handler>> definitions)
{
int tokenIndex = 0;
for (HandlerPattern pattern : this._patterns) {
boolean optional = pattern.isOptional();
if ((pattern instanceof TagPattern)) {
boolean match = (tokenIndex < tokens.size()) && (((Token)tokens.get(tokenIndex)).getTags(((TagPattern)pattern).getTagClass()).size() > 0);

if ((!match) && (!optional)) {
return false;
}
if (match) {
tokenIndex++;
}

}
else if ((pattern instanceof HandlerTypePattern)) {
if ((optional) && (tokenIndex == tokens.size())) {
return true;
}
List subHandlers = (List)definitions.get(((HandlerTypePattern)pattern).getType());
for (Handler subHandler : subHandlers) {
if (subHandler.match(tokens.subList(tokenIndex, tokens.size()), definitions)) {
return true;
}
}
return false;
}
}

return tokenIndex == tokens.size();
}

public String toString()
{
return "[Handler: " + this._handler + "]";
}

public static synchronized Map<Handler.HandlerType, List<Handler>> definitions() {
if (_definitions == null) {
Map definitions = new HashMap();

List timeHandlers = new LinkedList();
timeHandlers.add(new Handler(null, new HandlerPattern[] { new TagPattern(RepeaterTime.class), new TagPattern(RepeaterDayPortion.class, true) }));
definitions.put(Handler.HandlerType.TIME, timeHandlers);

List dateHandlers = new LinkedList();
dateHandlers.add(new Handler(new RdnRmnSdTTzSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterDayName.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(RepeaterTime.class), new TagPattern(TimeZone.class), new TagPattern(ScalarYear.class) }));

dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorComma.class, true), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnOdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(OrdinalDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new SdRmnSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SmSdSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SdSmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SySmSdHandler(), new HandlerPattern[] { new TagPattern(ScalarYear.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));

dateHandlers.add(new Handler(new SmSdHandler(), false, new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class) }));
dateHandlers.add(new Handler(new SmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class) }));
definitions.put(Handler.HandlerType.DATE, dateHandlers);

List anchorHandlers = new LinkedList();
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RGRHandler(), new HandlerPattern[] { new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.ANCHOR, anchorHandlers);

List arrowHandlers = new LinkedList();
arrowHandlers.add(new Handler(new SRPHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class) }));
arrowHandlers.add(new Handler(new PSRHandler(), new HandlerPattern[] { new TagPattern(Pointer.class), new TagPattern(Scalar.class), new TagPattern(Repeater.class) }));
arrowHandlers.add(new Handler(new SRPAHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class), new HandlerTypePattern(Handler.HandlerType.ANCHOR) }));
definitions.put(Handler.HandlerType.ARROW, arrowHandlers);

List narrowHandlers = new LinkedList();
narrowHandlers.add(new Handler(new ORSRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(SeparatorIn.class), new TagPattern(Repeater.class) }));
narrowHandlers.add(new Handler(new ORGRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.NARROW, narrowHandlers);
_definitions = definitions;
}
return _definitions;
}

public static Span tokensToSpan(List<Token> tokens, Options options) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: " + tokens);
}

Map definitions = definitions();
for (Handler handler : (List)definitions.get(Handler.HandlerType.DATE)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: date");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ANCHOR)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: anchor");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: arrow");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if ((token.getTag(SeparatorAt.class) == null) && (token.getTag(SeparatorSlashOrDash.class) == null) && (token.getTag(SeparatorComma.class) == null)) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.NARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: narrow");
}

return handler.getHandler().handle(tokens, options);
}

}

if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: none");
}
return null;
}

public static List<Repeater<?>> getRepeaters(List<Token> tokens) {
List repeaters = new LinkedList();
for (Token token : tokens) {
Repeater tag = (Repeater)token.getTag(Repeater.class);
if (tag != null) {
repeaters.add(tag);
}
}
Collections.sort(repeaters);
Collections.reverse(repeaters);
return repeaters;
}

public static Span getAnchor(List<Token> tokens, Options options) {
Grabber grabber = new Grabber(Grabber.Relative.THIS);
Pointer.PointerType pointer = Pointer.PointerType.FUTURE;

List repeaters = getRepeaters(tokens);
for (int i = 0; i < repeaters.size(); i++) {
tokens.remove(tokens.size() - 1);
}

if ((!tokens.isEmpty()) && (((Token)tokens.get(0)).getTag(Grabber.class) != null)) {
grabber = (Grabber)((Token)tokens.get(0)).getTag(Grabber.class);
tokens.remove(tokens.size() - 1);
}

Repeater head = (Repeater)repeaters.remove(0);
head.setStart((Calendar)options.getNow().clone());

Grabber.Relative grabberType = (Grabber.Relative)grabber.getType();
Span outerSpan;
if (grabberType == Grabber.Relative.LAST) {
outerSpan = head.nextSpan(Pointer.PointerType.PAST);
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.THIS)
{
Span outerSpan;
if (repeaters.size() > 0) {
outerSpan = head.thisSpan(Pointer.PointerType.NONE);
}
else
outerSpan = head.thisSpan(options.getContext());
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.NEXT) {
outerSpan = head.nextSpan(Pointer.PointerType.FUTURE);
}
else
throw new IllegalArgumentException("Invalid grabber type " + grabberType + ".");
}
}
Span outerSpan;
if (options.isDebug()) {
System.out.println("Chronic.getAnchor: outerSpan = " + outerSpan + "; repeaters = " + repeaters);
}

Span anchor = findWithin(repeaters, outerSpan, pointer, options);
return anchor;
}

public static Span dayOrTime(Calendar dayStart, List<Token> timeTokens, Options options) {
Span outerSpan = new Span(dayStart, Time.cloneAndAdd(dayStart, 5, 1L));
if (!timeTokens.isEmpty())
{
options.setNow(outerSpan.getBeginCalendar());
Span time = getAnchor(dealiasAndDisambiguateTimes(timeTokens, options), options);
return time;
}
return outerSpan;
}

public static Span findWithin(List<Repeater<?>> tags, Span span, Pointer.PointerType pointer, Options options)
{
if (options.isDebug()) {
System.out.println("Chronic.findWithin: " + tags + " in " + span);
}
if (tags.isEmpty()) {
return span;
}
Repeater head = (Repeater)tags.get(0);
List rest = tags.size() > 1 ? tags.subList(1, tags.size()) : new LinkedList();
head.setStart(pointer == Pointer.PointerType.FUTURE ? span.getBeginCalendar() : span.getEndCalendar());
Span h = head.thisSpan(Pointer.PointerType.NONE);

if ((span.contains(h.getBegin())) || (span.contains(h.getEnd()))) {
return findWithin(rest, h, pointer, options);
}
return null;
}

public static List<Token> dealiasAndDisambiguateTimes(List<Token> tokens, Options options)
{
int dayPortionIndex = -1;
int tokenSize = tokens.size();
for (int i = 0; (dayPortionIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterDayPortion.class) != null) {
dayPortionIndex = i;
}
}

int timeIndex = -1;
for (int i = 0; (timeIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterTime.class) != null) {
timeIndex = i;
}
}

if ((dayPortionIndex != -1) && (timeIndex != -1)) {
Token t1 = (Token)tokens.get(dayPortionIndex);
Tag t1Tag = t1.getTag(RepeaterDayPortion.class);

Object t1TagType = t1Tag.getType();
if (RepeaterDayPortion.DayPortion.MORNING.equals(t1TagType)) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: morning->am");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.AM));
}
else if ((RepeaterDayPortion.DayPortion.AFTERNOON.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.EVENING.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.NIGHT.equals(t1TagType))) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + t1TagType + "->pm");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.PM));
}

}

if (options.getAmbiguousTimeRange() != 0) {
List ttokens = new LinkedList();
for (int i = 0; i < tokenSize; i++) {
Token t0 = (Token)tokens.get(i);
ttokens.add(t0);
Token t1 = null;
if (i < tokenSize - 1) {
t1 = (Token)tokens.get(i + 1);
}
if ((t0.getTag(RepeaterTime.class) != null) && (((Tick)((RepeaterTime)t0.getTag(RepeaterTime.class)).getType()).isAmbiguous()) && ((t1 == null) || (t1.getTag(RepeaterDayPortion.class) == null))) {
Token distoken = new Token("disambiguator");
distoken.tag(new IntegerRepeaterDayPortion(Integer.valueOf(options.getAmbiguousTimeRange())));
ttokens.add(distoken);
}
}
tokens = ttokens;
}

if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + tokens);
}

return tokens;
}
}
package com.sk89q.jchronic.handlers;

import com.sk89q.jchronic.Options;
import com.sk89q.jchronic.repeaters.EnumRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.IntegerRepeaterDayPortion;
import com.sk89q.jchronic.repeaters.Repeater;
import com.sk89q.jchronic.repeaters.RepeaterDayName;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion;
import com.sk89q.jchronic.repeaters.RepeaterDayPortion.DayPortion;
import com.sk89q.jchronic.repeaters.RepeaterMonthName;
import com.sk89q.jchronic.repeaters.RepeaterTime;
import com.sk89q.jchronic.tags.Grabber;
import com.sk89q.jchronic.tags.Grabber.Relative;
import com.sk89q.jchronic.tags.Ordinal;
import com.sk89q.jchronic.tags.OrdinalDay;
import com.sk89q.jchronic.tags.Pointer;
import com.sk89q.jchronic.tags.Pointer.PointerType;
import com.sk89q.jchronic.tags.Scalar;
import com.sk89q.jchronic.tags.ScalarDay;
import com.sk89q.jchronic.tags.ScalarMonth;
import com.sk89q.jchronic.tags.ScalarYear;
import com.sk89q.jchronic.tags.Separator;
import com.sk89q.jchronic.tags.SeparatorAt;
import com.sk89q.jchronic.tags.SeparatorComma;
import com.sk89q.jchronic.tags.SeparatorIn;
import com.sk89q.jchronic.tags.SeparatorSlashOrDash;
import com.sk89q.jchronic.tags.Tag;
import com.sk89q.jchronic.tags.TimeZone;
import com.sk89q.jchronic.utils.Span;
import com.sk89q.jchronic.utils.Tick;
import com.sk89q.jchronic.utils.Time;
import com.sk89q.jchronic.utils.Token;
import java.io.PrintStream;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class Handler
{
private static Map<Handler.HandlerType, List<Handler>> _definitions;
private HandlerPattern[] _patterns;
private IHandler _handler;
private boolean _compatible;

public Handler(IHandler handler, HandlerPattern[] patterns)
{
this(handler, true, patterns);
}

public Handler(IHandler handler, boolean compatible, HandlerPattern[] patterns) {
this._handler = handler;
this._compatible = compatible;
this._patterns = patterns;
}

public boolean isCompatible(Options options) {
return (!options.isCompatibilityMode()) || (this._compatible);
}

public IHandler getHandler() {
return this._handler;
}

public boolean match(List<Token> tokens, Map<Handler.HandlerType, List<Handler>> definitions)
{
int tokenIndex = 0;
for (HandlerPattern pattern : this._patterns) {
boolean optional = pattern.isOptional();
if ((pattern instanceof TagPattern)) {
boolean match = (tokenIndex < tokens.size()) && (((Token)tokens.get(tokenIndex)).getTags(((TagPattern)pattern).getTagClass()).size() > 0);

if ((!match) && (!optional)) {
return false;
}
if (match) {
tokenIndex++;
}

}
else if ((pattern instanceof HandlerTypePattern)) {
if ((optional) && (tokenIndex == tokens.size())) {
return true;
}
List subHandlers = (List)definitions.get(((HandlerTypePattern)pattern).getType());
for (Handler subHandler : subHandlers) {
if (subHandler.match(tokens.subList(tokenIndex, tokens.size()), definitions)) {
return true;
}
}
return false;
}
}

return tokenIndex == tokens.size();
}

public String toString()
{
return "[Handler: " + this._handler + "]";
}

public static synchronized Map<Handler.HandlerType, List<Handler>> definitions() {
if (_definitions == null) {
Map definitions = new HashMap();

List timeHandlers = new LinkedList();
timeHandlers.add(new Handler(null, new HandlerPattern[] { new TagPattern(RepeaterTime.class), new TagPattern(RepeaterDayPortion.class, true) }));
definitions.put(Handler.HandlerType.TIME, timeHandlers);

List dateHandlers = new LinkedList();
dateHandlers.add(new Handler(new RdnRmnSdTTzSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterDayName.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(RepeaterTime.class), new TagPattern(TimeZone.class), new TagPattern(ScalarYear.class) }));

dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorComma.class, true), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new RmnSdSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnOdHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(OrdinalDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new RmnSyHandler(), new HandlerPattern[] { new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class) }));
dateHandlers.add(new Handler(new SdRmnSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(RepeaterMonthName.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SmSdSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SdSmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarDay.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));
dateHandlers.add(new Handler(new SySmSdHandler(), new HandlerPattern[] { new TagPattern(ScalarYear.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class), new TagPattern(SeparatorAt.class, true), new HandlerTypePattern(Handler.HandlerType.TIME, true) }));

dateHandlers.add(new Handler(new SmSdHandler(), false, new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarDay.class) }));
dateHandlers.add(new Handler(new SmSyHandler(), new HandlerPattern[] { new TagPattern(ScalarMonth.class), new TagPattern(SeparatorSlashOrDash.class), new TagPattern(ScalarYear.class) }));
definitions.put(Handler.HandlerType.DATE, dateHandlers);

List anchorHandlers = new LinkedList();
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RHandler(), new HandlerPattern[] { new TagPattern(Grabber.class, true), new TagPattern(Repeater.class), new TagPattern(Repeater.class), new TagPattern(SeparatorAt.class, true), new TagPattern(Repeater.class, true), new TagPattern(Repeater.class, true) }));
anchorHandlers.add(new Handler(new RGRHandler(), new HandlerPattern[] { new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.ANCHOR, anchorHandlers);

List arrowHandlers = new LinkedList();
arrowHandlers.add(new Handler(new SRPHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class) }));
arrowHandlers.add(new Handler(new PSRHandler(), new HandlerPattern[] { new TagPattern(Pointer.class), new TagPattern(Scalar.class), new TagPattern(Repeater.class) }));
arrowHandlers.add(new Handler(new SRPAHandler(), new HandlerPattern[] { new TagPattern(Scalar.class), new TagPattern(Repeater.class), new TagPattern(Pointer.class), new HandlerTypePattern(Handler.HandlerType.ANCHOR) }));
definitions.put(Handler.HandlerType.ARROW, arrowHandlers);

List narrowHandlers = new LinkedList();
narrowHandlers.add(new Handler(new ORSRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(SeparatorIn.class), new TagPattern(Repeater.class) }));
narrowHandlers.add(new Handler(new ORGRHandler(), new HandlerPattern[] { new TagPattern(Ordinal.class), new TagPattern(Repeater.class), new TagPattern(Grabber.class), new TagPattern(Repeater.class) }));
definitions.put(Handler.HandlerType.NARROW, narrowHandlers);
_definitions = definitions;
}
return _definitions;
}

public static Span tokensToSpan(List<Token> tokens, Options options) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: " + tokens);
}

Map definitions = definitions();
for (Handler handler : (List)definitions.get(Handler.HandlerType.DATE)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: date");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ANCHOR)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: anchor");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if (token.getTag(Separator.class) == null) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.ARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: arrow");
}
List goodTokens = new LinkedList();
for (Token token : tokens) {
if ((token.getTag(SeparatorAt.class) == null) && (token.getTag(SeparatorSlashOrDash.class) == null) && (token.getTag(SeparatorComma.class) == null)) {
goodTokens.add(token);
}
}
return handler.getHandler().handle(goodTokens, options);
}

}

for (Handler handler : (List)definitions.get(Handler.HandlerType.NARROW)) {
if ((handler.isCompatible(options)) && (handler.match(tokens, definitions))) {
if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: narrow");
}

return handler.getHandler().handle(tokens, options);
}

}

if (options.isDebug()) {
System.out.println("Chronic.tokensToSpan: none");
}
return null;
}

public static List<Repeater<?>> getRepeaters(List<Token> tokens) {
List repeaters = new LinkedList();
for (Token token : tokens) {
Repeater tag = (Repeater)token.getTag(Repeater.class);
if (tag != null) {
repeaters.add(tag);
}
}
Collections.sort(repeaters);
Collections.reverse(repeaters);
return repeaters;
}

public static Span getAnchor(List<Token> tokens, Options options) {
Grabber grabber = new Grabber(Grabber.Relative.THIS);
Pointer.PointerType pointer = Pointer.PointerType.FUTURE;

List repeaters = getRepeaters(tokens);
for (int i = 0; i < repeaters.size(); i++) {
tokens.remove(tokens.size() - 1);
}

if ((!tokens.isEmpty()) && (((Token)tokens.get(0)).getTag(Grabber.class) != null)) {
grabber = (Grabber)((Token)tokens.get(0)).getTag(Grabber.class);
tokens.remove(tokens.size() - 1);
}

Repeater head = (Repeater)repeaters.remove(0);
head.setStart((Calendar)options.getNow().clone());

Grabber.Relative grabberType = (Grabber.Relative)grabber.getType();
Span outerSpan;
if (grabberType == Grabber.Relative.LAST) {
outerSpan = head.nextSpan(Pointer.PointerType.PAST);
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.THIS)
{
Span outerSpan;
if (repeaters.size() > 0) {
outerSpan = head.thisSpan(Pointer.PointerType.NONE);
}
else
outerSpan = head.thisSpan(options.getContext());
}
else
{
Span outerSpan;
if (grabberType == Grabber.Relative.NEXT) {
outerSpan = head.nextSpan(Pointer.PointerType.FUTURE);
}
else
throw new IllegalArgumentException("Invalid grabber type " + grabberType + ".");
}
}
Span outerSpan;
if (options.isDebug()) {
System.out.println("Chronic.getAnchor: outerSpan = " + outerSpan + "; repeaters = " + repeaters);
}

Span anchor = findWithin(repeaters, outerSpan, pointer, options);
return anchor;
}

public static Span dayOrTime(Calendar dayStart, List<Token> timeTokens, Options options) {
Span outerSpan = new Span(dayStart, Time.cloneAndAdd(dayStart, 5, 1L));
if (!timeTokens.isEmpty())
{
options.setNow(outerSpan.getBeginCalendar());
Span time = getAnchor(dealiasAndDisambiguateTimes(timeTokens, options), options);
return time;
}
return outerSpan;
}

public static Span findWithin(List<Repeater<?>> tags, Span span, Pointer.PointerType pointer, Options options)
{
if (options.isDebug()) {
System.out.println("Chronic.findWithin: " + tags + " in " + span);
}
if (tags.isEmpty()) {
return span;
}
Repeater head = (Repeater)tags.get(0);
List rest = tags.size() > 1 ? tags.subList(1, tags.size()) : new LinkedList();
head.setStart(pointer == Pointer.PointerType.FUTURE ? span.getBeginCalendar() : span.getEndCalendar());
Span h = head.thisSpan(Pointer.PointerType.NONE);

if ((span.contains(h.getBegin())) || (span.contains(h.getEnd()))) {
return findWithin(rest, h, pointer, options);
}
return null;
}

public static List<Token> dealiasAndDisambiguateTimes(List<Token> tokens, Options options)
{
int dayPortionIndex = -1;
int tokenSize = tokens.size();
for (int i = 0; (dayPortionIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterDayPortion.class) != null) {
dayPortionIndex = i;
}
}

int timeIndex = -1;
for (int i = 0; (timeIndex == -1) && (i < tokenSize); i++) {
Token t = (Token)tokens.get(i);
if (t.getTag(RepeaterTime.class) != null) {
timeIndex = i;
}
}

if ((dayPortionIndex != -1) && (timeIndex != -1)) {
Token t1 = (Token)tokens.get(dayPortionIndex);
Tag t1Tag = t1.getTag(RepeaterDayPortion.class);

Object t1TagType = t1Tag.getType();
if (RepeaterDayPortion.DayPortion.MORNING.equals(t1TagType)) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: morning->am");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.AM));
}
else if ((RepeaterDayPortion.DayPortion.AFTERNOON.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.EVENING.equals(t1TagType)) || (RepeaterDayPortion.DayPortion.NIGHT.equals(t1TagType))) {
if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + t1TagType + "->pm");
}
t1.untag(RepeaterDayPortion.class);
t1.tag(new EnumRepeaterDayPortion(RepeaterDayPortion.DayPortion.PM));
}

}

if (options.getAmbiguousTimeRange() != 0) {
List ttokens = new LinkedList();
for (int i = 0; i < tokenSize; i++) {
Token t0 = (Token)tokens.get(i);
ttokens.add(t0);
Token t1 = null;
if (i < tokenSize - 1) {
t1 = (Token)tokens.get(i + 1);
}
if ((t0.getTag(RepeaterTime.class) != null) && (((Tick)((RepeaterTime)t0.getTag(RepeaterTime.class)).getType()).isAmbiguous()) && ((t1 == null) || (t1.getTag(RepeaterDayPortion.class) == null))) {
Token distoken = new Token("disambiguator");
distoken.tag(new IntegerRepeaterDayPortion(Integer.valueOf(options.getAmbiguousTimeRange())));
ttokens.add(distoken);
}
}
tokens = ttokens;
}

if (options.isDebug()) {
System.out.println("Chronic.dealiasAndDisambiguateTimes: " + tokens);
}

return tokens;
}
}

Ponieważ post wyszedł długi dodaje 2 część pluginu

public class ju extends sn
{
public int a;
public int b;

public ju(fd world)
{
super(world);
this.b = 0;
}

public ju(fd world, double d, double d1, double d2, int i)
{
super(world);
this.b = 0;
this.a = i;
this.aF = true;
b(0.98F, 0.98F);
this.bf = (this.bh / 2.0F);
e(d, d1, d2);
this.aP = 0.0D;
this.aQ = 0.0D;
this.aR = 0.0D;
this.aJ = d;
this.aK = d1;
this.aL = d2;
}

protected boolean n()
{
return false;
}

protected void b()
{
}

public boolean h_()
{
return !this.be;
}

public void w_()
{
if (this.a == 0)
{
K();
return;
}
this.aJ = this.aM;
this.aK = this.aN;
this.aL = this.aO;
this.b += 1;
this.aQ -= 0.03999999910593033D;
b(this.aP, this.aQ, this.aR);
this.aP *= 0.9800000190734863D;
this.aQ *= 0.9800000190734863D;
this.aR *= 0.9800000190734863D;
int i = in.b(this.aM);
int j = in.b(this.aN);
int k = in.b(this.aO);
if (this.aI.a(i, j, k) == this.a)
{
this.aI.f(i, j, k, 0);
}
if (this.aX)
{
this.aP *= 0.699999988079071D;
this.aR *= 0.699999988079071D;
this.aQ *= -0.5D;
K();

mod_NWater.dealWithPistonWater(this.aI, mod_NWater.isPistonWater(this.aI.a(i, j, k), this.aI.e(i, j, k)), -1, i, j, k);
if (((!mod_NWater.canBlockBePlacedAt(this.aI, this.a, i, j, k, true)) || (gk.c_(this.aI, i, j - 1, k)) || (!this.aI.f(i, j, k, this.a))) && (!this.aI.B))
{
b(this.a, 1);
}
}
else if ((this.b > 100) && (!this.aI.B))
{
b(this.a, 1);
K();
}
}

protected void b(nu nbttagcompound)
{
nbttagcompound.a("Tile", (byte)this.a);
}

protected void a(nu nbttagcompound)
{
this.a = (nbttagcompound.c("Tile") & 0xFF);
}

public float x_()
{
return 0.0F;
}

public fd k()
{
return this.aI;
}
}
public class ju extends sn
{
public int a;
public int b;

public ju(fd world)
{
super(world);
this.b = 0;
}

public ju(fd world, double d, double d1, double d2, int i)
{
super(world);
this.b = 0;
this.a = i;
this.aF = true;
b(0.98F, 0.98F);
this.bf = (this.bh / 2.0F);
e(d, d1, d2);
this.aP = 0.0D;
this.aQ = 0.0D;
this.aR = 0.0D;
this.aJ = d;
this.aK = d1;
this.aL = d2;
}

protected boolean n()
{
return false;
}

protected void b()
{
}

public boolean h_()
{
return !this.be;
}

public void w_()
{
if (this.a == 0)
{
K();
return;
}
this.aJ = this.aM;
this.aK = this.aN;
this.aL = this.aO;
this.b += 1;
this.aQ -= 0.03999999910593033D;
b(this.aP, this.aQ, this.aR);
this.aP *= 0.9800000190734863D;
this.aQ *= 0.9800000190734863D;
this.aR *= 0.9800000190734863D;
int i = in.b(this.aM);
int j = in.b(this.aN);
int k = in.b(this.aO);
if (this.aI.a(i, j, k) == this.a)
{
this.aI.f(i, j, k, 0);
}
if (this.aX)
{
this.aP *= 0.699999988079071D;
this.aR *= 0.699999988079071D;
this.aQ *= -0.5D;
K();

mod_NWater.dealWithPistonWater(this.aI, mod_NWater.isPistonWater(this.aI.a(i, j, k), this.aI.e(i, j, k)), -1, i, j, k);
if (((!mod_NWater.canBlockBePlacedAt(this.aI, this.a, i, j, k, true)) || (gk.c_(this.aI, i, j - 1, k)) || (!this.aI.f(i, j, k, this.a))) && (!this.aI.B))
{
b(this.a, 1);
}
}
else if ((this.b > 100) && (!this.aI.B))
{
b(this.a, 1);
K();
}
}

protected void b(nu nbttagcompound)
{
nbttagcompound.a("Tile", (byte)this.a);
}

protected void a(nu nbttagcompound)
{
this.a = (nbttagcompound.c("Tile") & 0xFF);
}

public float x_()
{
return 0.0F;
}

public fd k()
{
return this.aI;
}
}
public class ju extends sn
{
public int a;
public int b;

public ju(fd world)
{
super(world);
this.b = 0;
}

public ju(fd world, double d, double d1, double d2, int i)
{
super(world);
this.b = 0;
this.a = i;
this.aF = true;
b(0.98F, 0.98F);
this.bf = (this.bh / 2.0F);
e(d, d1, d2);
this.aP = 0.0D;
this.aQ = 0.0D;
this.aR = 0.0D;
this.aJ = d;
this.aK = d1;
this.aL = d2;
}

protected boolean n()
{
return false;
}

protected void b()
{
}

public boolean h_()
{
return !this.be;
}

public void w_()
{
if (this.a == 0)
{
K();
return;
}
this.aJ = this.aM;
this.aK = this.aN;
this.aL = this.aO;
this.b += 1;
this.aQ -= 0.03999999910593033D;
b(this.aP, this.aQ, this.aR);
this.aP *= 0.9800000190734863D;
this.aQ *= 0.9800000190734863D;
this.aR *= 0.9800000190734863D;
int i = in.b(this.aM);
int j = in.b(this.aN);
int k = in.b(this.aO);
if (this.aI.a(i, j, k) == this.a)
{
this.aI.f(i, j, k, 0);
}
if (this.aX)
{
this.aP *= 0.699999988079071D;
this.aR *= 0.699999988079071D;
this.aQ *= -0.5D;
K();

mod_NWater.dealWithPistonWater(this.aI, mod_NWater.isPistonWater(this.aI.a(i, j, k), this.aI.e(i, j, k)), -1, i, j, k);
if (((!mod_NWater.canBlockBePlacedAt(this.aI, this.a, i, j, k, true)) || (gk.c_(this.aI, i, j - 1, k)) || (!this.aI.f(i, j, k, this.a))) && (!this.aI.B))
{
b(this.a, 1);
}
}
else if ((this.b > 100) && (!this.aI.B))
{
b(this.a, 1);
K();
}
}

protected void b(nu nbttagcompound)
{
nbttagcompound.a("Tile", (byte)this.a);
}

protected void a(nu nbttagcompound)
{
this.a = (nbttagcompound.c("Tile") & 0xFF);
}

public float x_()
{
return 0.0F;
}

public fd k()
{
return this.aI;
}
}
public class ju extends sn
{
public int a;
public int b;

public ju(fd world)
{
super(world);
this.b = 0;
}

public ju(fd world, double d, double d1, double d2, int i)
{
super(world);
this.b = 0;
this.a = i;
this.aF = true;
b(0.98F, 0.98F);
this.bf = (this.bh / 2.0F);
e(d, d1, d2);
this.aP = 0.0D;
this.aQ = 0.0D;
this.aR = 0.0D;
this.aJ = d;
this.aK = d1;
this.aL = d2;
}

protected boolean n()
{
return false;
}

protected void b()
{
}

public boolean h_()
{
return !this.be;
}

public void w_()
{
if (this.a == 0)
{
K();
return;
}
this.aJ = this.aM;
this.aK = this.aN;
this.aL = this.aO;
this.b += 1;
this.aQ -= 0.03999999910593033D;
b(this.aP, this.aQ, this.aR);
this.aP *= 0.9800000190734863D;
this.aQ *= 0.9800000190734863D;
this.aR *= 0.9800000190734863D;
int i = in.b(this.aM);
int j = in.b(this.aN);
int k = in.b(this.aO);
if (this.aI.a(i, j, k) == this.a)
{
this.aI.f(i, j, k, 0);
}
if (this.aX)
{
this.aP *= 0.699999988079071D;
this.aR *= 0.699999988079071D;
this.aQ *= -0.5D;
K();

mod_NWater.dealWithPistonWater(this.aI, mod_NWater.isPistonWater(this.aI.a(i, j, k), this.aI.e(i, j, k)), -1, i, j, k);
if (((!mod_NWater.canBlockBePlacedAt(this.aI, this.a, i, j, k, true)) || (gk.c_(this.aI, i, j - 1, k)) || (!this.aI.f(i, j, k, this.a))) && (!this.aI.B))
{
b(this.a, 1);
}
}
else if ((this.b > 100) && (!this.aI.B))
{
b(this.a, 1);
K();
}
}

protected void b(nu nbttagcompound)
{
nbttagcompound.a("Tile", (byte)this.a);
}

protected void a(nu nbttagcompound)
{
this.a = (nbttagcompound.c("Tile") & 0xFF);
}

public float x_()
{
return 0.0F;
}

public fd k()
{
return this.aI;
}
}
public class ju extends sn
{
public int a;
public int b;

public ju(fd world)
{
super(world);
this.b = 0;
}

public ju(fd world, double d, double d1, double d2, int i)
{
super(world);
this.b = 0;
this.a = i;
this.aF = true;
b(0.98F, 0.98F);
this.bf = (this.bh / 2.0F);
e(d, d1, d2);
this.aP = 0.0D;
this.aQ = 0.0D;
this.aR = 0.0D;
this.aJ = d;
this.aK = d1;
this.aL = d2;
}

protected boolean n()
{
return false;
}

protected void b()
{
}

public boolean h_()
{
return !this.be;
}

public void w_()
{
if (this.a == 0)
{
K();
return;
}
this.aJ = this.aM;
this.aK = this.aN;
this.aL = this.aO;
this.b += 1;
this.aQ -= 0.03999999910593033D;
b(this.aP, this.aQ, this.aR);
this.aP *= 0.9800000190734863D;
this.aQ *= 0.9800000190734863D;
this.aR *= 0.9800000190734863D;
int i = in.b(this.aM);
int j = in.b(this.aN);
int k = in.b(this.aO);
if (this.aI.a(i, j, k) == this.a)
{
this.aI.f(i, j, k, 0);
}
if (this.aX)
{
this.aP *= 0.699999988079071D;
this.aR *= 0.699999988079071D;
this.aQ *= -0.5D;
K();

mod_NWater.dealWithPistonWater(this.aI, mod_NWater.isPistonWater(this.aI.a(i, j, k), this.aI.e(i, j, k)), -1, i, j, k);
if (((!mod_NWater.canBlockBePlacedAt(this.aI, this.a, i, j, k, true)) || (gk.c_(this.aI, i, j - 1, k)) || (!this.aI.f(i, j, k, this.a))) && (!this.aI.B))
{
b(this.a, 1);
}
}
else if ((this.b > 100) && (!this.aI.B))
{
b(this.a, 1);
K();
}
}

protected void b(nu nbttagcompound)
{
nbttagcompound.a("Tile", (byte)this.a);
}

protected void a(nu nbttagcompound)
{
this.a = (nbttagcompound.c("Tile") & 0xFF);
}

public float x_()
{
return 0.0F;
}

public fd k()
{
return this.aI;
}
}
public class ju extends sn
{
public int a;
public int b;

public ju(fd world)
{
super(world);
this.b = 0;
}

public ju(fd world, double d, double d1, double d2, int i)
{
super(world);
this.b = 0;
this.a = i;
this.aF = true;
b(0.98F, 0.98F);
this.bf = (this.bh / 2.0F);
e(d, d1, d2);
this.aP = 0.0D;
this.aQ = 0.0D;
this.aR = 0.0D;
this.aJ = d;
this.aK = d1;
this.aL = d2;
}

protected boolean n()
{
return false;
}

protected void b()
{
}

public boolean h_()
{
return !this.be;
}

public void w_()
{
if (this.a == 0)
{
K();
return;
}
this.aJ = this.aM;
this.aK = this.aN;
this.aL = this.aO;
this.b += 1;
this.aQ -= 0.03999999910593033D;
b(this.aP, this.aQ, this.aR);
this.aP *= 0.9800000190734863D;
this.aQ *= 0.9800000190734863D;
this.aR *= 0.9800000190734863D;
int i = in.b(this.aM);
int j = in.b(this.aN);
int k = in.b(this.aO);
if (this.aI.a(i, j, k) == this.a)
{
this.aI.f(i, j, k, 0);
}
if (this.aX)
{
this.aP *= 0.699999988079071D;
this.aR *= 0.699999988079071D;
this.aQ *= -0.5D;
K();

mod_NWater.dealWithPistonWater(this.aI, mod_NWater.isPistonWater(this.aI.a(i, j, k), this.aI.e(i, j, k)), -1, i, j, k);
if (((!mod_NWater.canBlockBePlacedAt(this.aI, this.a, i, j, k, true)) || (gk.c_(this.aI, i, j - 1, k)) || (!this.aI.f(i, j, k, this.a))) && (!this.aI.B))
{
b(this.a, 1);
}
}
else if ((this.b > 100) && (!this.aI.B))
{
b(this.a, 1);
K();
}
}

protected void b(nu nbttagcompound)
{
nbttagcompound.a("Tile", (byte)this.a);
}

protected void a(nu nbttagcompound)
{
this.a = (nbttagcompound.c("Tile") & 0xFF);
}

public float x_()
{
return 0.0F;
}

public fd k()
{
return this.aI;
}
}
public class ju extends sn
{
public int a;
public int b;

public ju(fd world)
{
super(world);
this.b = 0;
}

public ju(fd world, double d, double d1, double d2, int i)
{
super(world);
this.b = 0;
this.a = i;
this.aF = true;
b(0.98F, 0.98F);
this.bf = (this.bh / 2.0F);
e(d, d1, d2);
this.aP = 0.0D;
this.aQ = 0.0D;
this.aR = 0.0D;
this.aJ = d;
this.aK = d1;
this.aL = d2;
}

protected boolean n()
{
return false;
}

protected void b()
{
}

public boolean h_()
{
return !this.be;
}

public void w_()
{
if (this.a == 0)
{
K();
return;
}
this.aJ = this.aM;
this.aK = this.aN;
this.aL = this.aO;
this.b += 1;
this.aQ -= 0.03999999910593033D;
b(this.aP, this.aQ, this.aR);
this.aP *= 0.9800000190734863D;
this.aQ *= 0.9800000190734863D;
this.aR *= 0.9800000190734863D;
int i = in.b(this.aM);
int j = in.b(this.aN);
int k = in.b(this.aO);
if (this.aI.a(i, j, k) == this.a)
{
this.aI.f(i, j, k, 0);
}
if (this.aX)
{
this.aP *= 0.699999988079071D;
this.aR *= 0.699999988079071D;
this.aQ *= -0.5D;
K();

mod_NWater.dealWithPistonWater(this.aI, mod_NWater.isPistonWater(this.aI.a(i, j, k), this.aI.e(i, j, k)), -1, i, j, k);
if (((!mod_NWater.canBlockBePlacedAt(this.aI, this.a, i, j, k, true)) || (gk.c_(this.aI, i, j - 1, k)) || (!this.aI.f(i, j, k, this.a))) && (!this.aI.B))
{
b(this.a, 1);
}
}
else if ((this.b > 100) && (!this.aI.B))
{
b(this.a, 1);
K();
}
}

protected void b(nu nbttagcompound)
{
nbttagcompound.a("Tile", (byte)this.a);
}

protected void a(nu nbttagcompound)
{
this.a = (nbttagcompound.c("Tile") & 0xFF);
}

public float x_()
{
return 0.0F;
}

public fd k()
{
return this.aI;
}
}
public class ju extends sn
{
public int a;
public int b;

public ju(fd world)
{
super(world);
this.b = 0;
}

public ju(fd world, double d, double d1, double d2, int i)
{
super(world);
this.b = 0;
this.a = i;
this.aF = true;
b(0.98F, 0.98F);
this.bf = (this.bh / 2.0F);
e(d, d1, d2);
this.aP = 0.0D;
this.aQ = 0.0D;
this.aR = 0.0D;
this.aJ = d;
this.aK = d1;
this.aL = d2;
}

protected boolean n()
{
return false;
}

protected void b()
{
}

public boolean h_()
{
return !this.be;
}

public void w_()
{
if (this.a == 0)
{
K();
return;
}
this.aJ = this.aM;
this.aK = this.aN;
this.aL = this.aO;
this.b += 1;
this.aQ -= 0.03999999910593033D;
b(this.aP, this.aQ, this.aR);
this.aP *= 0.9800000190734863D;
this.aQ *= 0.9800000190734863D;
this.aR *= 0.9800000190734863D;
int i = in.b(this.aM);
int j = in.b(this.aN);
int k = in.b(this.aO);
if (this.aI.a(i, j, k) == this.a)
{
this.aI.f(i, j, k, 0);
}
if (this.aX)
{
this.aP *= 0.699999988079071D;
this.aR *= 0.699999988079071D;
this.aQ *= -0.5D;
K();

mod_NWater.dealWithPistonWater(this.aI, mod_NWater.isPistonWater(this.aI.a(i, j, k), this.aI.e(i, j, k)), -1, i, j, k);
if (((!mod_NWater.canBlockBePlacedAt(this.aI, this.a, i, j, k, true)) || (gk.c_(this.aI, i, j - 1, k)) || (!this.aI.f(i, j, k, this.a))) && (!this.aI.B))
{
b(this.a, 1);
}
}
else if ((this.b > 100) && (!this.aI.B))
{
b(this.a, 1);
K();
}
}

protected void b(nu nbttagcompound)
{
nbttagcompound.a("Tile", (byte)this.a);
}

protected void a(nu nbttagcompound)
{
this.a = (nbttagcompound.c("Tile") & 0xFF);
}

public float x_()
{
return 0.0F;
}

public fd k()
{
return this.aI;
}
}
public class ju extends sn
{
public int a;
public int b;

public ju(fd world)
{
super(world);
this.b = 0;
}

public ju(fd world, double d, double d1, double d2, int i)
{
super(world);
this.b = 0;
this.a = i;
this.aF = true;
b(0.98F, 0.98F);
this.bf = (this.bh / 2.0F);
e(d, d1, d2);
this.aP = 0.0D;
this.aQ = 0.0D;
this.aR = 0.0D;
this.aJ = d;
this.aK = d1;
this.aL = d2;
}

protected boolean n()
{
return false;
}

protected void b()
{
}

public boolean h_()
{
return !this.be;
}

public void w_()
{
if (this.a == 0)
{
K();
return;
}
this.aJ = this.aM;
this.aK = this.aN;
this.aL = this.aO;
this.b += 1;
this.aQ -= 0.03999999910593033D;
b(this.aP, this.aQ, this.aR);
this.aP *= 0.9800000190734863D;
this.aQ *= 0.9800000190734863D;
this.aR *= 0.9800000190734863D;
int i = in.b(this.aM);
int j = in.b(this.aN);
int k = in.b(this.aO);
if (this.aI.a(i, j, k) == this.a)
{
this.aI.f(i, j, k, 0);
}
if (this.aX)
{
this.aP *= 0.699999988079071D;
this.aR *= 0.699999988079071D;
this.aQ *= -0.5D;
K();

mod_NWater.dealWithPistonWater(this.aI, mod_NWater.isPistonWater(this.aI.a(i, j, k), this.aI.e(i, j, k)), -1, i, j, k);
if (((!mod_NWater.canBlockBePlacedAt(this.aI, this.a, i, j, k, true)) || (gk.c_(this.aI, i, j - 1, k)) || (!this.aI.f(i, j, k, this.a))) && (!this.aI.B))
{
b(this.a, 1);
}
}
else if ((this.b > 100) && (!this.aI.B))
{
b(this.a, 1);
K();
}
}

protected void b(nu nbttagcompound)
{
nbttagcompound.a("Tile", (byte)this.a);
}

protected void a(nu nbttagcompound)
{
this.a = (nbttagcompound.c("Tile") & 0xFF);
}

public float x_()
{
return 0.0F;
}

public fd k()
{
return this.aI;
}
}
public class ju extends sn
{
public int a;
public int b;

public ju(fd world)
{
super(world);
this.b = 0;
}

public ju(fd world, double d, double d1, double d2, int i)
{
super(world);
this.b = 0;
this.a = i;
this.aF = true;
b(0.98F, 0.98F);
this.bf = (this.bh / 2.0F);
e(d, d1, d2);
this.aP = 0.0D;
this.aQ = 0.0D;
this.aR = 0.0D;
this.aJ = d;
this.aK = d1;
this.aL = d2;
}

protected boolean n()
{
return false;
}

protected void b()
{
}

public boolean h_()
{
return !this.be;
}

public void w_()
{
if (this.a == 0)
{
K();
return;
}
this.aJ = this.aM;
this.aK = this.aN;
this.aL = this.aO;
this.b += 1;
this.aQ -= 0.03999999910593033D;
b(this.aP, this.aQ, this.aR);
this.aP *= 0.9800000190734863D;
this.aQ *= 0.9800000190734863D;
this.aR *= 0.9800000190734863D;
int i = in.b(this.aM);
int j = in.b(this.aN);
int k = in.b(this.aO);
if (this.aI.a(i, j, k) == this.a)
{
this.aI.f(i, j, k, 0);
}
if (this.aX)
{
this.aP *= 0.699999988079071D;
this.aR *= 0.699999988079071D;
this.aQ *= -0.5D;
K();

mod_NWater.dealWithPistonWater(this.aI, mod_NWater.isPistonWater(this.aI.a(i, j, k), this.aI.e(i, j, k)), -1, i, j, k);
if (((!mod_NWater.canBlockBePlacedAt(this.aI, this.a, i, j, k, true)) || (gk.c_(this.aI, i, j - 1, k)) || (!this.aI.f(i, j, k, this.a))) && (!this.aI.B))
{
b(this.a, 1);
}
}
else if ((this.b > 100) && (!this.aI.B))
{
b(this.a, 1);
K();
}
}

protected void b(nu nbttagcompound)
{
nbttagcompound.a("Tile", (byte)this.a);
}

protected void a(nu nbttagcompound)
{
this.a = (nbttagcompound.c("Tile") & 0xFF);
}

public float x_()
{
return 0.0F;
}

public fd k()
{
return this.aI;
}
}
public class ju extends sn
{
public int a;
public int b;

public ju(fd world)
{
super(world);
this.b = 0;
}

public ju(fd world, double d, double d1, double d2, int i)
{
super(world);
this.b = 0;
this.a = i;
this.aF = true;
b(0.98F, 0.98F);
this.bf = (this.bh / 2.0F);
e(d, d1, d2);
this.aP = 0.0D;
this.aQ = 0.0D;
this.aR = 0.0D;
this.aJ = d;
this.aK = d1;
this.aL = d2;
}

protected boolean n()
{
return false;
}

protected void b()
{
}

public boolean h_()
{
return !this.be;
}

public void w_()
{
if (this.a == 0)
{
K();
return;
}
this.aJ = this.aM;
this.aK = this.aN;
this.aL = this.aO;
this.b += 1;
this.aQ -= 0.03999999910593033D;
b(this.aP, this.aQ, this.aR);
this.aP *= 0.9800000190734863D;
this.aQ *= 0.9800000190734863D;
this.aR *= 0.9800000190734863D;
int i = in.b(this.aM);
int j = in.b(this.aN);
int k = in.b(this.aO);
if (this.aI.a(i, j, k) == this.a)
{
this.aI.f(i, j, k, 0);
}
if (this.aX)
{
this.aP *= 0.699999988079071D;
this.aR *= 0.699999988079071D;
this.aQ *= -0.5D;
K();

mod_NWater.dealWithPistonWater(this.aI, mod_NWater.isPistonWater(this.aI.a(i, j, k), this.aI.e(i, j, k)), -1, i, j, k);
if (((!mod_NWater.canBlockBePlacedAt(this.aI, this.a, i, j, k, true)) || (gk.c_(this.aI, i, j - 1, k)) || (!this.aI.f(i, j, k, this.a))) && (!this.aI.B))
{
b(this.a, 1);
}
}
else if ((this.b > 100) && (!this.aI.B))
{
b(this.a, 1);
K();
}
}

protected void b(nu nbttagcompound)
{
nbttagcompound.a("Tile", (byte)this.a);
}

protected void a(nu nbttagcompound)
{
this.a = (nbttagcompound.c("Tile") & 0xFF);
}

public float x_()
{
return 0.0F;
}

public fd k()
{
return this.aI;
}
}
public class ju extends sn
{
public int a;
public int b;

public ju(fd world)
{
super(world);
this.b = 0;
}

public ju(fd world, double d, double d1, double d2, int i)
{
super(world);
this.b = 0;
this.a = i;
this.aF = true;
b(0.98F, 0.98F);
this.bf = (this.bh / 2.0F);
e(d, d1, d2);
this.aP = 0.0D;
this.aQ = 0.0D;
this.aR = 0.0D;
this.aJ = d;
this.aK = d1;
this.aL = d2;
}

protected boolean n()
{
return false;
}

protected void b()
{
}

public boolean h_()
{
return !this.be;
}

public void w_()
{
if (this.a == 0)
{
K();
return;
}
this.aJ = this.aM;
this.aK = this.aN;
this.aL = this.aO;
this.b += 1;
this.aQ -= 0.03999999910593033D;
b(this.aP, this.aQ, this.aR);
this.aP *= 0.9800000190734863D;
this.aQ *= 0.9800000190734863D;
this.aR *= 0.9800000190734863D;
int i = in.b(this.aM);
int j = in.b(this.aN);
int k = in.b(this.aO);
if (this.aI.a(i, j, k) == this.a)
{
this.aI.f(i, j, k, 0);
}
if (this.aX)
{
this.aP *= 0.699999988079071D;
this.aR *= 0.699999988079071D;
this.aQ *= -0.5D;
K();

mod_NWater.dealWithPistonWater(this.aI, mod_NWater.isPistonWater(this.aI.a(i, j, k), this.aI.e(i, j, k)), -1, i, j, k);
if (((!mod_NWater.canBlockBePlacedAt(this.aI, this.a, i, j, k, true)) || (gk.c_(this.aI, i, j - 1, k)) || (!this.aI.f(i, j, k, this.a))) && (!this.aI.B))
{
b(this.a, 1);
}
}
else if ((this.b > 100) && (!this.aI.B))
{
b(this.a, 1);
K();
}
}

protected void b(nu nbttagcompound)
{
nbttagcompound.a("Tile", (byte)this.a);
}

protected void a(nu nbttagcompound)
{
this.a = (nbttagcompound.c("Tile") & 0xFF);
}

public float x_()
{
return 0.0F;
}

public fd k()
{
return this.aI;
}
}
public class ju extends sn
{
public int a;
public int b;

public ju(fd world)
{
super(world);
this.b = 0;
}

public ju(fd world, double d, double d1, double d2, int i)
{
super(world);
this.b = 0;
this.a = i;
this.aF = true;
b(0.98F, 0.98F);
this.bf = (this.bh / 2.0F);
e(d, d1, d2);
this.aP = 0.0D;
this.aQ = 0.0D;
this.aR = 0.0D;
this.aJ = d;
this.aK = d1;
this.aL = d2;
}

protected boolean n()
{
return false;
}

protected void b()
{
}

public boolean h_()
{
return !this.be;
}

public void w_()
{
if (this.a == 0)
{
K();
return;
}
this.aJ = this.aM;
this.aK = this.aN;
this.aL = this.aO;
this.b += 1;
this.aQ -= 0.03999999910593033D;
b(this.aP, this.aQ, this.aR);
this.aP *= 0.9800000190734863D;
this.aQ *= 0.9800000190734863D;
this.aR *= 0.9800000190734863D;
int i = in.b(this.aM);
int j = in.b(this.aN);
int k = in.b(this.aO);
if (this.aI.a(i, j, k) == this.a)
{
this.aI.f(i, j, k, 0);
}
if (this.aX)
{
this.aP *= 0.699999988079071D;
this.aR *= 0.699999988079071D;
this.aQ *= -0.5D;
K();

mod_NWater.dealWithPistonWater(this.aI, mod_NWater.isPistonWater(this.aI.a(i, j, k), this.aI.e(i, j, k)), -1, i, j, k);
if (((!mod_NWater.canBlockBePlacedAt(this.aI, this.a, i, j, k, true)) || (gk.c_(this.aI, i, j - 1, k)) || (!this.aI.f(i, j, k, this.a))) && (!this.aI.B))
{
b(this.a, 1);
}
}
else if ((this.b > 100) && (!this.aI.B))
{
b(this.a, 1);
K();
}
}

protected void b(nu nbttagcompound)
{
nbttagcompound.a("Tile", (byte)this.a);
}

protected void a(nu nbttagcompound)
{
this.a = (nbttagcompound.c("Tile") & 0xFF);
}

public float x_()
{
return 0.0F;
}

public fd k()
{
return this.aI;
}
}
public class ju extends sn
{
public int a;
public int b;

public ju(fd world)
{
super(world);
this.b = 0;
}

public ju(fd world, double d, double d1, double d2, int i)
{
super(world);
this.b = 0;
this.a = i;
this.aF = true;
b(0.98F, 0.98F);
this.bf = (this.bh / 2.0F);
e(d, d1, d2);
this.aP = 0.0D;
this.aQ = 0.0D;
this.aR = 0.0D;
this.aJ = d;
this.aK = d1;
this.aL = d2;
}

protected boolean n()
{
return false;
}

protected void b()
{
}

public boolean h_()
{
return !this.be;
}

public void w_()
{
if (this.a == 0)
{
K();
return;
}
this.aJ = this.aM;
this.aK = this.aN;
this.aL = this.aO;
this.b += 1;
this.aQ -= 0.03999999910593033D;
b(this.aP, this.aQ, this.aR);
this.aP *= 0.9800000190734863D;
this.aQ *= 0.9800000190734863D;
this.aR *= 0.9800000190734863D;
int i = in.b(this.aM);
int j = in.b(this.aN);
int k = in.b(this.aO);
if (this.aI.a(i, j, k) == this.a)
{
this.aI.f(i, j, k, 0);
}
if (this.aX)
{
this.aP *= 0.699999988079071D;
this.aR *= 0.699999988079071D;
this.aQ *= -0.5D;
K();

mod_NWater.dealWithPistonWater(this.aI, mod_NWater.isPistonWater(this.aI.a(i, j, k), this.aI.e(i, j, k)), -1, i, j, k);
if (((!mod_NWater.canBlockBePlacedAt(this.aI, this.a, i, j, k, true)) || (gk.c_(this.aI, i, j - 1, k)) || (!this.aI.f(i, j, k, this.a))) && (!this.aI.B))
{
b(this.a, 1);
}
}
else if ((this.b > 100) && (!this.aI.B))
{
b(this.a, 1);
K();
}
}

protected void b(nu nbttagcompound)
{
nbttagcompound.a("Tile", (byte)this.a);
}

protected void a(nu nbttagcompound)
{
this.a = (nbttagcompound.c("Tile") & 0xFF);
}

public float x_()
{
return 0.0F;
}

public fd k()
{
return this.aI;
}
}
public class ju extends sn
{
public int a;
public int b;

public ju(fd world)
{
super(world);
this.b = 0;
}

public ju(fd world, double d, double d1, double d2, int i)
{
super(world);
this.b = 0;
this.a = i;
this.aF = true;
b(0.98F, 0.98F);
this.bf = (this.bh / 2.0F);
e(d, d1, d2);
this.aP = 0.0D;
this.aQ = 0.0D;
this.aR = 0.0D;
this.aJ = d;
this.aK = d1;
this.aL = d2;
}

protected boolean n()
{
return false;
}

protected void b()
{
}

public boolean h_()
{
return !this.be;
}

public void w_()
{
if (this.a == 0)
{
K();
return;
}
this.aJ = this.aM;
this.aK = this.aN;
this.aL = this.aO;
this.b += 1;
this.aQ -= 0.03999999910593033D;
b(this.aP, this.aQ, this.aR);
this.aP *= 0.9800000190734863D;
this.aQ *= 0.9800000190734863D;
this.aR *= 0.9800000190734863D;
int i = in.b(this.aM);
int j = in.b(this.aN);
int k = in.b(this.aO);
if (this.aI.a(i, j, k) == this.a)
{
this.aI.f(i, j, k, 0);
}
if (this.aX)
{
this.aP *= 0.699999988079071D;
this.aR *= 0.699999988079071D;
this.aQ *= -0.5D;
K();

mod_NWater.dealWithPistonWater(this.aI, mod_NWater.isPistonWater(this.aI.a(i, j, k), this.aI.e(i, j, k)), -1, i, j, k);
if (((!mod_NWater.canBlockBePlacedAt(this.aI, this.a, i, j, k, true)) || (gk.c_(this.aI, i, j - 1, k)) || (!this.aI.f(i, j, k, this.a))) && (!this.aI.B))
{
b(this.a, 1);
}
}
else if ((this.b > 100) && (!this.aI.B))
{
b(this.a, 1);
K();
}
}

protected void b(nu nbttagcompound)
{
nbttagcompound.a("Tile", (byte)this.a);
}

protected void a(nu nbttagcompound)
{
this.a = (nbttagcompound.c("Tile") & 0xFF);
}

public float x_()
{
return 0.0F;
}

public fd k()
{
return this.aI;
}
}
public class ju extends sn
{
public int a;
public int b;

public ju(fd world)
{
super(world);
this.b = 0;
}

public ju(fd world, double d, double d1, double d2, int i)
{
super(world);
this.b = 0;
this.a = i;
this.aF = true;
b(0.98F, 0.98F);
this.bf = (this.bh / 2.0F);
e(d, d1, d2);
this.aP = 0.0D;
this.aQ = 0.0D;
this.aR = 0.0D;
this.aJ = d;
this.aK = d1;
this.aL = d2;
}

protected boolean n()
{
return false;
}

protected void b()
{
}

public boolean h_()
{
return !this.be;
}

public void w_()
{
if (this.a == 0)
{
K();
return;
}
this.aJ = this.aM;
this.aK = this.aN;
this.aL = this.aO;
this.b += 1;
this.aQ -= 0.03999999910593033D;
b(this.aP, this.aQ, this.aR);
this.aP *= 0.9800000190734863D;
this.aQ *= 0.9800000190734863D;
this.aR *= 0.9800000190734863D;
int i = in.b(this.aM);
int j = in.b(this.aN);
int k = in.b(this.aO);
if (this.aI.a(i, j, k) == this.a)
{
this.aI.f(i, j, k, 0);
}
if (this.aX)
{
this.aP *= 0.699999988079071D;
this.aR *= 0.699999988079071D;
this.aQ *= -0.5D;
K();

mod_NWater.dealWithPistonWater(this.aI, mod_NWater.isPistonWater(this.aI.a(i, j, k), this.aI.e(i, j, k)), -1, i, j, k);
if (((!mod_NWater.canBlockBePlacedAt(this.aI, this.a, i, j, k, true)) || (gk.c_(this.aI, i, j - 1, k)) || (!this.aI.f(i, j, k, this.a))) && (!this.aI.B))
{
b(this.a, 1);
}
}
else if ((this.b > 100) && (!this.aI.B))
{
b(this.a, 1);
K();
}
}

protected void b(nu nbttagcompound)
{
nbttagcompound.a("Tile", (byte)this.a);
}

protected void a(nu nbttagcompound)
{
this.a = (nbttagcompound.c("Tile") & 0xFF);
}

public float x_()
{
return 0.0F;
}

public fd k()
{
return this.aI;
}
}
public class ju extends sn
{
public int a;
public int b;

public ju(fd world)
{
super(world);
this.b = 0;
}

public ju(fd world, double d, double d1, double d2, int i)
{
super(world);
this.b = 0;
this.a = i;
this.aF = true;
b(0.98F, 0.98F);
this.bf = (this.bh / 2.0F);
e(d, d1, d2);
this.aP = 0.0D;
this.aQ = 0.0D;
this.aR = 0.0D;
this.aJ = d;
this.aK = d1;
this.aL = d2;
}

protected boolean n()
{
return false;
}

protected void b()
{
}

public boolean h_()
{
return !this.be;
}

public void w_()
{
if (this.a == 0)
{
K();
return;
}
this.aJ = this.aM;
this.aK = this.aN;
this.aL = this.aO;
this.b += 1;
this.aQ -= 0.03999999910593033D;
b(this.aP, this.aQ, this.aR);
this.aP *= 0.9800000190734863D;
this.aQ *= 0.9800000190734863D;
this.aR *= 0.9800000190734863D;
int i = in.b(this.aM);
int j = in.b(this.aN);
int k = in.b(this.aO);
if (this.aI.a(i, j, k) == this.a)
{
this.aI.f(i, j, k, 0);
}
if (this.aX)
{
this.aP *= 0.699999988079071D;
this.aR *= 0.699999988079071D;
this.aQ *= -0.5D;
K();

mod_NWater.dealWithPistonWater(this.aI, mod_NWater.isPistonWater(this.aI.a(i, j, k), this.aI.e(i, j, k)), -1, i, j, k);
if (((!mod_NWater.canBlockBePlacedAt(this.aI, this.a, i, j, k, true)) || (gk.c_(this.aI, i, j - 1, k)) || (!this.aI.f(i, j, k, this.a))) && (!this.aI.B))
{
b(this.a, 1);
}
}
else if ((this.b > 100) && (!this.aI.B))
{
b(this.a, 1);
K();
}
}

protected void b(nu nbttagcompound)
{
nbttagcompound.a("Tile", (byte)this.a);
}

protected void a(nu nbttagcompound)
{
this.a = (nbttagcompound.c("Tile") & 0xFF);
}

public float x_()
{
return 0.0F;
}

public fd k()
{
return this.aI;
}
}
public class ju extends sn
{
public int a;
public int b;

public ju(fd world)
{
super(world);
this.b = 0;
}

public ju(fd world, double d, double d1, double d2, int i)
{
super(world);
this.b = 0;
this.a = i;
this.aF = true;
b(0.98F, 0.98F);
this.bf = (this.bh / 2.0F);
e(d, d1, d2);
this.aP = 0.0D;
this.aQ = 0.0D;
this.aR = 0.0D;
this.aJ = d;
this.aK = d1;
this.aL = d2;
}

protected boolean n()
{
return false;
}

protected void b()
{
}

public boolean h_()
{
return !this.be;
}

public void w_()
{
if (this.a == 0)
{
K();
return;
}
this.aJ = this.aM;
this.aK = this.aN;
this.aL = this.aO;
this.b += 1;
this.aQ -= 0.03999999910593033D;
b(this.aP, this.aQ, this.aR);
this.aP *= 0.9800000190734863D;
this.aQ *= 0.9800000190734863D;
this.aR *= 0.9800000190734863D;
int i = in.b(this.aM);
int j = in.b(this.aN);
int k = in.b(this.aO);
if (this.aI.a(i, j, k) == this.a)
{
this.aI.f(i, j, k, 0);
}
if (this.aX)
{
this.aP *= 0.699999988079071D;
this.aR *= 0.699999988079071D;
this.aQ *= -0.5D;
K();

mod_NWater.dealWithPistonWater(this.aI, mod_NWater.isPistonWater(this.aI.a(i, j, k), this.aI.e(i, j, k)), -1, i, j, k);
if (((!mod_NWater.canBlockBePlacedAt(this.aI, this.a, i, j, k, true)) || (gk.c_(this.aI, i, j - 1, k)) || (!this.aI.f(i, j, k, this.a))) && (!this.aI.B))
{
b(this.a, 1);
}
}
else if ((this.b > 100) && (!this.aI.B))
{
b(this.a, 1);
K();
}
}

protected void b(nu nbttagcompound)
{
nbttagcompound.a("Tile", (byte)this.a);
}

protected void a(nu nbttagcompound)
{
this.a = (nbttagcompound.c("Tile") & 0xFF);
}

public float x_()
{
return 0.0F;
}

public fd k()
{
return this.aI;
}
}
import java.util.ArrayList;
import java.util.Random;

public class jq extends uu
{
private static int dealingWith;
private static boolean dealingB;
private boolean a;
private boolean b;

public jq(int i, int j, boolean flag)
{
super(i, j, ln.B);
this.a = flag;
a(h);
c(0.5F);
}

public int i()
{
return !this.a ? 107 : 106;
}

public int a(int i, int j)
{
int k = d(j);
if (k > 5)
{
return this.bm;
}
if (i == k)
{
if ((e(j)) || (this.bs > 0.0D) || (this.bt > 0.0D) || (this.bu > 0.0D) || (this.bv < 1.0D) || (this.bw < 1.0D) || (this.bx < 1.0D))
{
return 110;
}

return this.bm;
}

return i != wj.a[k] ? 108 : 109;
}

public int b()
{
return 16;
}

public boolean c()
{
return false;
}

public boolean a(fd world, int i, int j, int k, gs entityplayer)
{
return false;
}

public void a(fd world, int i, int j, int k, ls entityliving)
{
int l = c(world, i, j, k, (gs)entityliving);
world.d(i, j, k, l);
if (!world.B)
{
h(world, i, j, k);
}
}

public void b(fd world, int i, int j, int k, int l)
{
if ((!world.B) && (!this.B))
{
dealingB = false;
h(world, i, j, k);
dealingB = true;
}
}

public void c(fd world, int i, int j, int k)
{
if ((!world.B) && (world.b(i, j, k) == null))
{
h(world, i, j, k);
}
}

private void h(fd world, int i, int j, int k)
{
int l = world.e(i, j, k);
int i1 = d(l);
boolean flag = f(world, i, j, k, i1);
if (l == 7)
{
return;
}
if ((flag) && (!e(l)))
{
if (h(world, i, j, k, i1))
{
world.e(i, j, k, i1 | 0x8 );
world.d(i, j, k, 0, i1);
}
}
else if ((!flag) && (e(l)))
{
world.e(i, j, k, i1);
world.d(i, j, k, 1, i1);
}
}

private boolean f(fd world, int i, int j, int k, int l)
{
if ((l != 0) && (world.k(i, j - 1, k, 0)))
{
return true;
}
if ((l != 1) && (world.k(i, j + 1, k, 1)))
{
return true;
}
if ((l != 2) && (world.k(i, j, k - 1, 2)))
{
return true;
}
if ((l != 3) && (world.k(i, j, k + 1, 3)))
{
return true;
}
if ((l != 5) && (world.k(i + 1, j, k, 5)))
{
return true;
}
if ((l != 4) && (world.k(i - 1, j, k, 4)))
{
return true;
}
if (world.k(i, j, k, 0))
{
return true;
}
if (world.k(i, j + 2, k, 1))
{
return true;
}
if (world.k(i, j + 1, k - 1, 2))
{
return true;
}
if (world.k(i, j + 1, k + 1, 3))
{
return true;
}
if (world.k(i - 1, j + 1, k, 4))
{
return true;
}
return world.k(i + 1, j + 1, k, 5);
}

public void a(fd world, int i, int j, int k, int l, int i1)
{
this.b = true;
int j1 = i1;
if (l == 0)
{
if (i(world, i, j, k, j1))
{
world.d(i, j, k, j1 | 0x8 );
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.out", 0.5F, world.r.nextFloat() * 0.25F + 0.6F);
}
}
else if (l == 1)
{
ow tileentity = world.b(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1]);
if ((tileentity != null) && ((tileentity instanceof uk)))
{
((uk)tileentity).l();
}
world.a(i, j, k, uu.ad.bn, j1);
world.a(i, j, k, ut.a(this.bn, j1, j1, false, true));
if (this.a)
{
int k1 = i + wj.b[j1] * 2;
int l1 = j + wj.c[j1] * 2;
int i2 = k + wj.d[j1] * 2;
int j2 = world.a(k1, l1, i2);
int k2 = world.e(k1, l1, i2);
boolean flag = false;
if (j2 == uu.ad.bn)
{
ow tileentity1 = world.b(k1, l1, i2);
if ((tileentity1 != null) && ((tileentity1 instanceof uk)))
{
uk tileentitypiston = (uk)tileentity1;
if ((tileentitypiston.d() == j1) && (tileentitypiston.b()))
{
tileentitypiston.l();
j2 = tileentitypiston.a();
k2 = tileentitypiston.e();
flag = true;
}
}
}
if ((!flag) && (j2 > 0) && (a(j2, world, k1, l1, i2, false)) && ((uu.m[j2].h() == 0) || (j2 == uu.aa.bn) || (j2 == uu.W.bn)))
{
this.b = false;
world.f(k1, l1, i2, 0);
this.b = true;
i += wj.b[j1];
j += wj.c[j1];
k += wj.d[j1];
world.a(i, j, k, uu.ad.bn, k2);
world.a(i, j, k, ut.a(j2, k2, j1, false, false));
}
else if (!flag)
{
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
}
else {
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.in", 0.5F, world.r.nextFloat() * 0.15F + 0.6F);
}
this.b = false;
}

public void a(xp iblockaccess, int i, int j, int k)
{
int l = iblockaccess.e(i, j, k);
if (e(l))
{
switch (d(l))
{
case 0:
a(0.0F, 0.25F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 1:
a(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F);
break;
case 2:
a(0.0F, 0.0F, 0.25F, 1.0F, 1.0F, 1.0F);
break;
case 3:
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.75F);
break;
case 4:
a(0.25F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 5:
a(0.0F, 0.0F, 0.0F, 0.75F, 1.0F, 1.0F);
}
}
else
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
}

public void g()
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}

public void a(fd world, int i, int j, int k, eq axisalignedbb, ArrayList arraylist)
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
super.a(world, i, j, k, axisalignedbb, arraylist);
}

public boolean d()
{
return false;
}

public static int d(int i)
{
return i & 0x7;
}

public static boolean e(int i)
{
return (i & 0x8 ) != 0;
}

private static int c(fd world, int i, int j, int k, gs entityplayer)
{
if ((in.e((float)entityplayer.aM - i) < 2.0F) && (in.e((float)entityplayer.aO - k) < 2.0F))
{
double d = entityplayer.aN + 1.82D - entityplayer.bf;
if (d - j > 2.0D)
{
return 1;
}
if (j - d > 0.0D)
{
return 0;
}
}
int l = in.b(entityplayer.aS * 4.0F / 360.0F + 0.5D) & 0x3;
if (l == 0)
{
return 2;
}
if (l == 1)
{
return 5;
}
if (l == 2)
{
return 3;
}
return l != 3 ? 0 : 4;
}

private static boolean a(int i, fd world, int j, int k, int l, boolean flag)
{
if (i == uu.aq.bn)
{
return false;
}
if ((i == uu.aa.bn) || (i == uu.W.bn))
{
if (e(world.e(j, k, l)))
{
return false;
}
}
else {
if (uu.m[i].m() == -1.0F)
{
return false;
}
if (uu.m[i].h() == 2)
{
return false;
}
if ((!flag) && (uu.m[i].h() == 1))
{
return false;
}
}
ow tileentity = world.b(j, k, l);
return tileentity == null;
}

private static boolean h(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int i2 = world.a(i1, j1, k1);

if (!dealingB)
{
dealingWith = mod_NWater.isPistonWater(i2, world.e(i1, j1, k1));
mod_NWater.dealWithPistonWater(world, dealingWith, l, i1, j1, k1);
dealingB = true;
}
if (i2 == 0)
{
break;
}

if (!a(i2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[i2].h() == 1)
{
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
return true;
}

private boolean i(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int j2 = world.a(i1, j1, k1);
if (j2 == 0)
{
break;
}
if (!a(j2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[j2].h() == 1)
{
uu.m[j2].g(world, i1, j1, k1, world.e(i1, j1, k1));
world.f(i1, j1, k1, 0);
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
int l2;
for (; (i1 != i) || (j1 != j) || (k1 != k); k1 = l2)
{
int i2 = i1 - wj.b[l];
int k2 = j1 - wj.c[l];
l2 = k1 - wj.d[l];
int i3 = world.a(i2, k2, l2);
int j3 = world.e(i2, k2, l2);
if ((i3 == this.bn) && (i2 == i) && (k2 == j) && (l2 == k))
{
world.a(i1, j1, k1, uu.ad.bn, l | (this.a ? 8 : 0));
world.a(i1, j1, k1, ut.a(uu.ab.bn, l | (this.a ? 8 : 0), l, true, false));
}
else {
world.a(i1, j1, k1, uu.ad.bn, j3);
world.a(i1, j1, k1, ut.a(i3, j3, l, true, false));
}
i1 = i2;
j1 = k2;
}

return true;
}
}
import java.util.ArrayList;
import java.util.Random;

public class jq extends uu
{
private static int dealingWith;
private static boolean dealingB;
private boolean a;
private boolean b;

public jq(int i, int j, boolean flag)
{
super(i, j, ln.B);
this.a = flag;
a(h);
c(0.5F);
}

public int i()
{
return !this.a ? 107 : 106;
}

public int a(int i, int j)
{
int k = d(j);
if (k > 5)
{
return this.bm;
}
if (i == k)
{
if ((e(j)) || (this.bs > 0.0D) || (this.bt > 0.0D) || (this.bu > 0.0D) || (this.bv < 1.0D) || (this.bw < 1.0D) || (this.bx < 1.0D))
{
return 110;
}

return this.bm;
}

return i != wj.a[k] ? 108 : 109;
}

public int b()
{
return 16;
}

public boolean c()
{
return false;
}

public boolean a(fd world, int i, int j, int k, gs entityplayer)
{
return false;
}

public void a(fd world, int i, int j, int k, ls entityliving)
{
int l = c(world, i, j, k, (gs)entityliving);
world.d(i, j, k, l);
if (!world.B)
{
h(world, i, j, k);
}
}

public void b(fd world, int i, int j, int k, int l)
{
if ((!world.B) && (!this.B))
{
dealingB = false;
h(world, i, j, k);
dealingB = true;
}
}

public void c(fd world, int i, int j, int k)
{
if ((!world.B) && (world.b(i, j, k) == null))
{
h(world, i, j, k);
}
}

private void h(fd world, int i, int j, int k)
{
int l = world.e(i, j, k);
int i1 = d(l);
boolean flag = f(world, i, j, k, i1);
if (l == 7)
{
return;
}
if ((flag) && (!e(l)))
{
if (h(world, i, j, k, i1))
{
world.e(i, j, k, i1 | 0x8 );
world.d(i, j, k, 0, i1);
}
}
else if ((!flag) && (e(l)))
{
world.e(i, j, k, i1);
world.d(i, j, k, 1, i1);
}
}

private boolean f(fd world, int i, int j, int k, int l)
{
if ((l != 0) && (world.k(i, j - 1, k, 0)))
{
return true;
}
if ((l != 1) && (world.k(i, j + 1, k, 1)))
{
return true;
}
if ((l != 2) && (world.k(i, j, k - 1, 2)))
{
return true;
}
if ((l != 3) && (world.k(i, j, k + 1, 3)))
{
return true;
}
if ((l != 5) && (world.k(i + 1, j, k, 5)))
{
return true;
}
if ((l != 4) && (world.k(i - 1, j, k, 4)))
{
return true;
}
if (world.k(i, j, k, 0))
{
return true;
}
if (world.k(i, j + 2, k, 1))
{
return true;
}
if (world.k(i, j + 1, k - 1, 2))
{
return true;
}
if (world.k(i, j + 1, k + 1, 3))
{
return true;
}
if (world.k(i - 1, j + 1, k, 4))
{
return true;
}
return world.k(i + 1, j + 1, k, 5);
}

public void a(fd world, int i, int j, int k, int l, int i1)
{
this.b = true;
int j1 = i1;
if (l == 0)
{
if (i(world, i, j, k, j1))
{
world.d(i, j, k, j1 | 0x8 );
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.out", 0.5F, world.r.nextFloat() * 0.25F + 0.6F);
}
}
else if (l == 1)
{
ow tileentity = world.b(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1]);
if ((tileentity != null) && ((tileentity instanceof uk)))
{
((uk)tileentity).l();
}
world.a(i, j, k, uu.ad.bn, j1);
world.a(i, j, k, ut.a(this.bn, j1, j1, false, true));
if (this.a)
{
int k1 = i + wj.b[j1] * 2;
int l1 = j + wj.c[j1] * 2;
int i2 = k + wj.d[j1] * 2;
int j2 = world.a(k1, l1, i2);
int k2 = world.e(k1, l1, i2);
boolean flag = false;
if (j2 == uu.ad.bn)
{
ow tileentity1 = world.b(k1, l1, i2);
if ((tileentity1 != null) && ((tileentity1 instanceof uk)))
{
uk tileentitypiston = (uk)tileentity1;
if ((tileentitypiston.d() == j1) && (tileentitypiston.b()))
{
tileentitypiston.l();
j2 = tileentitypiston.a();
k2 = tileentitypiston.e();
flag = true;
}
}
}
if ((!flag) && (j2 > 0) && (a(j2, world, k1, l1, i2, false)) && ((uu.m[j2].h() == 0) || (j2 == uu.aa.bn) || (j2 == uu.W.bn)))
{
this.b = false;
world.f(k1, l1, i2, 0);
this.b = true;
i += wj.b[j1];
j += wj.c[j1];
k += wj.d[j1];
world.a(i, j, k, uu.ad.bn, k2);
world.a(i, j, k, ut.a(j2, k2, j1, false, false));
}
else if (!flag)
{
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
}
else {
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.in", 0.5F, world.r.nextFloat() * 0.15F + 0.6F);
}
this.b = false;
}

public void a(xp iblockaccess, int i, int j, int k)
{
int l = iblockaccess.e(i, j, k);
if (e(l))
{
switch (d(l))
{
case 0:
a(0.0F, 0.25F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 1:
a(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F);
break;
case 2:
a(0.0F, 0.0F, 0.25F, 1.0F, 1.0F, 1.0F);
break;
case 3:
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.75F);
break;
case 4:
a(0.25F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 5:
a(0.0F, 0.0F, 0.0F, 0.75F, 1.0F, 1.0F);
}
}
else
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
}

public void g()
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}

public void a(fd world, int i, int j, int k, eq axisalignedbb, ArrayList arraylist)
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
super.a(world, i, j, k, axisalignedbb, arraylist);
}

public boolean d()
{
return false;
}

public static int d(int i)
{
return i & 0x7;
}

public static boolean e(int i)
{
return (i & 0x8 ) != 0;
}

private static int c(fd world, int i, int j, int k, gs entityplayer)
{
if ((in.e((float)entityplayer.aM - i) < 2.0F) && (in.e((float)entityplayer.aO - k) < 2.0F))
{
double d = entityplayer.aN + 1.82D - entityplayer.bf;
if (d - j > 2.0D)
{
return 1;
}
if (j - d > 0.0D)
{
return 0;
}
}
int l = in.b(entityplayer.aS * 4.0F / 360.0F + 0.5D) & 0x3;
if (l == 0)
{
return 2;
}
if (l == 1)
{
return 5;
}
if (l == 2)
{
return 3;
}
return l != 3 ? 0 : 4;
}

private static boolean a(int i, fd world, int j, int k, int l, boolean flag)
{
if (i == uu.aq.bn)
{
return false;
}
if ((i == uu.aa.bn) || (i == uu.W.bn))
{
if (e(world.e(j, k, l)))
{
return false;
}
}
else {
if (uu.m[i].m() == -1.0F)
{
return false;
}
if (uu.m[i].h() == 2)
{
return false;
}
if ((!flag) && (uu.m[i].h() == 1))
{
return false;
}
}
ow tileentity = world.b(j, k, l);
return tileentity == null;
}

private static boolean h(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int i2 = world.a(i1, j1, k1);

if (!dealingB)
{
dealingWith = mod_NWater.isPistonWater(i2, world.e(i1, j1, k1));
mod_NWater.dealWithPistonWater(world, dealingWith, l, i1, j1, k1);
dealingB = true;
}
if (i2 == 0)
{
break;
}

if (!a(i2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[i2].h() == 1)
{
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
return true;
}

private boolean i(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int j2 = world.a(i1, j1, k1);
if (j2 == 0)
{
break;
}
if (!a(j2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[j2].h() == 1)
{
uu.m[j2].g(world, i1, j1, k1, world.e(i1, j1, k1));
world.f(i1, j1, k1, 0);
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
int l2;
for (; (i1 != i) || (j1 != j) || (k1 != k); k1 = l2)
{
int i2 = i1 - wj.b[l];
int k2 = j1 - wj.c[l];
l2 = k1 - wj.d[l];
int i3 = world.a(i2, k2, l2);
int j3 = world.e(i2, k2, l2);
if ((i3 == this.bn) && (i2 == i) && (k2 == j) && (l2 == k))
{
world.a(i1, j1, k1, uu.ad.bn, l | (this.a ? 8 : 0));
world.a(i1, j1, k1, ut.a(uu.ab.bn, l | (this.a ? 8 : 0), l, true, false));
}
else {
world.a(i1, j1, k1, uu.ad.bn, j3);
world.a(i1, j1, k1, ut.a(i3, j3, l, true, false));
}
i1 = i2;
j1 = k2;
}

return true;
}
}
import java.util.ArrayList;
import java.util.Random;

public class jq extends uu
{
private static int dealingWith;
private static boolean dealingB;
private boolean a;
private boolean b;

public jq(int i, int j, boolean flag)
{
super(i, j, ln.B);
this.a = flag;
a(h);
c(0.5F);
}

public int i()
{
return !this.a ? 107 : 106;
}

public int a(int i, int j)
{
int k = d(j);
if (k > 5)
{
return this.bm;
}
if (i == k)
{
if ((e(j)) || (this.bs > 0.0D) || (this.bt > 0.0D) || (this.bu > 0.0D) || (this.bv < 1.0D) || (this.bw < 1.0D) || (this.bx < 1.0D))
{
return 110;
}

return this.bm;
}

return i != wj.a[k] ? 108 : 109;
}

public int b()
{
return 16;
}

public boolean c()
{
return false;
}

public boolean a(fd world, int i, int j, int k, gs entityplayer)
{
return false;
}

public void a(fd world, int i, int j, int k, ls entityliving)
{
int l = c(world, i, j, k, (gs)entityliving);
world.d(i, j, k, l);
if (!world.B)
{
h(world, i, j, k);
}
}

public void b(fd world, int i, int j, int k, int l)
{
if ((!world.B) && (!this.B))
{
dealingB = false;
h(world, i, j, k);
dealingB = true;
}
}

public void c(fd world, int i, int j, int k)
{
if ((!world.B) && (world.b(i, j, k) == null))
{
h(world, i, j, k);
}
}

private void h(fd world, int i, int j, int k)
{
int l = world.e(i, j, k);
int i1 = d(l);
boolean flag = f(world, i, j, k, i1);
if (l == 7)
{
return;
}
if ((flag) && (!e(l)))
{
if (h(world, i, j, k, i1))
{
world.e(i, j, k, i1 | 0x8 );
world.d(i, j, k, 0, i1);
}
}
else if ((!flag) && (e(l)))
{
world.e(i, j, k, i1);
world.d(i, j, k, 1, i1);
}
}

private boolean f(fd world, int i, int j, int k, int l)
{
if ((l != 0) && (world.k(i, j - 1, k, 0)))
{
return true;
}
if ((l != 1) && (world.k(i, j + 1, k, 1)))
{
return true;
}
if ((l != 2) && (world.k(i, j, k - 1, 2)))
{
return true;
}
if ((l != 3) && (world.k(i, j, k + 1, 3)))
{
return true;
}
if ((l != 5) && (world.k(i + 1, j, k, 5)))
{
return true;
}
if ((l != 4) && (world.k(i - 1, j, k, 4)))
{
return true;
}
if (world.k(i, j, k, 0))
{
return true;
}
if (world.k(i, j + 2, k, 1))
{
return true;
}
if (world.k(i, j + 1, k - 1, 2))
{
return true;
}
if (world.k(i, j + 1, k + 1, 3))
{
return true;
}
if (world.k(i - 1, j + 1, k, 4))
{
return true;
}
return world.k(i + 1, j + 1, k, 5);
}

public void a(fd world, int i, int j, int k, int l, int i1)
{
this.b = true;
int j1 = i1;
if (l == 0)
{
if (i(world, i, j, k, j1))
{
world.d(i, j, k, j1 | 0x8 );
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.out", 0.5F, world.r.nextFloat() * 0.25F + 0.6F);
}
}
else if (l == 1)
{
ow tileentity = world.b(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1]);
if ((tileentity != null) && ((tileentity instanceof uk)))
{
((uk)tileentity).l();
}
world.a(i, j, k, uu.ad.bn, j1);
world.a(i, j, k, ut.a(this.bn, j1, j1, false, true));
if (this.a)
{
int k1 = i + wj.b[j1] * 2;
int l1 = j + wj.c[j1] * 2;
int i2 = k + wj.d[j1] * 2;
int j2 = world.a(k1, l1, i2);
int k2 = world.e(k1, l1, i2);
boolean flag = false;
if (j2 == uu.ad.bn)
{
ow tileentity1 = world.b(k1, l1, i2);
if ((tileentity1 != null) && ((tileentity1 instanceof uk)))
{
uk tileentitypiston = (uk)tileentity1;
if ((tileentitypiston.d() == j1) && (tileentitypiston.b()))
{
tileentitypiston.l();
j2 = tileentitypiston.a();
k2 = tileentitypiston.e();
flag = true;
}
}
}
if ((!flag) && (j2 > 0) && (a(j2, world, k1, l1, i2, false)) && ((uu.m[j2].h() == 0) || (j2 == uu.aa.bn) || (j2 == uu.W.bn)))
{
this.b = false;
world.f(k1, l1, i2, 0);
this.b = true;
i += wj.b[j1];
j += wj.c[j1];
k += wj.d[j1];
world.a(i, j, k, uu.ad.bn, k2);
world.a(i, j, k, ut.a(j2, k2, j1, false, false));
}
else if (!flag)
{
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
}
else {
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.in", 0.5F, world.r.nextFloat() * 0.15F + 0.6F);
}
this.b = false;
}

public void a(xp iblockaccess, int i, int j, int k)
{
int l = iblockaccess.e(i, j, k);
if (e(l))
{
switch (d(l))
{
case 0:
a(0.0F, 0.25F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 1:
a(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F);
break;
case 2:
a(0.0F, 0.0F, 0.25F, 1.0F, 1.0F, 1.0F);
break;
case 3:
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.75F);
break;
case 4:
a(0.25F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 5:
a(0.0F, 0.0F, 0.0F, 0.75F, 1.0F, 1.0F);
}
}
else
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
}

public void g()
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}

public void a(fd world, int i, int j, int k, eq axisalignedbb, ArrayList arraylist)
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
super.a(world, i, j, k, axisalignedbb, arraylist);
}

public boolean d()
{
return false;
}

public static int d(int i)
{
return i & 0x7;
}

public static boolean e(int i)
{
return (i & 0x8 ) != 0;
}

private static int c(fd world, int i, int j, int k, gs entityplayer)
{
if ((in.e((float)entityplayer.aM - i) < 2.0F) && (in.e((float)entityplayer.aO - k) < 2.0F))
{
double d = entityplayer.aN + 1.82D - entityplayer.bf;
if (d - j > 2.0D)
{
return 1;
}
if (j - d > 0.0D)
{
return 0;
}
}
int l = in.b(entityplayer.aS * 4.0F / 360.0F + 0.5D) & 0x3;
if (l == 0)
{
return 2;
}
if (l == 1)
{
return 5;
}
if (l == 2)
{
return 3;
}
return l != 3 ? 0 : 4;
}

private static boolean a(int i, fd world, int j, int k, int l, boolean flag)
{
if (i == uu.aq.bn)
{
return false;
}
if ((i == uu.aa.bn) || (i == uu.W.bn))
{
if (e(world.e(j, k, l)))
{
return false;
}
}
else {
if (uu.m[i].m() == -1.0F)
{
return false;
}
if (uu.m[i].h() == 2)
{
return false;
}
if ((!flag) && (uu.m[i].h() == 1))
{
return false;
}
}
ow tileentity = world.b(j, k, l);
return tileentity == null;
}

private static boolean h(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int i2 = world.a(i1, j1, k1);

if (!dealingB)
{
dealingWith = mod_NWater.isPistonWater(i2, world.e(i1, j1, k1));
mod_NWater.dealWithPistonWater(world, dealingWith, l, i1, j1, k1);
dealingB = true;
}
if (i2 == 0)
{
break;
}

if (!a(i2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[i2].h() == 1)
{
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
return true;
}

private boolean i(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int j2 = world.a(i1, j1, k1);
if (j2 == 0)
{
break;
}
if (!a(j2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[j2].h() == 1)
{
uu.m[j2].g(world, i1, j1, k1, world.e(i1, j1, k1));
world.f(i1, j1, k1, 0);
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
int l2;
for (; (i1 != i) || (j1 != j) || (k1 != k); k1 = l2)
{
int i2 = i1 - wj.b[l];
int k2 = j1 - wj.c[l];
l2 = k1 - wj.d[l];
int i3 = world.a(i2, k2, l2);
int j3 = world.e(i2, k2, l2);
if ((i3 == this.bn) && (i2 == i) && (k2 == j) && (l2 == k))
{
world.a(i1, j1, k1, uu.ad.bn, l | (this.a ? 8 : 0));
world.a(i1, j1, k1, ut.a(uu.ab.bn, l | (this.a ? 8 : 0), l, true, false));
}
else {
world.a(i1, j1, k1, uu.ad.bn, j3);
world.a(i1, j1, k1, ut.a(i3, j3, l, true, false));
}
i1 = i2;
j1 = k2;
}

return true;
}
}
import java.util.ArrayList;
import java.util.Random;

public class jq extends uu
{
private static int dealingWith;
private static boolean dealingB;
private boolean a;
private boolean b;

public jq(int i, int j, boolean flag)
{
super(i, j, ln.B);
this.a = flag;
a(h);
c(0.5F);
}

public int i()
{
return !this.a ? 107 : 106;
}

public int a(int i, int j)
{
int k = d(j);
if (k > 5)
{
return this.bm;
}
if (i == k)
{
if ((e(j)) || (this.bs > 0.0D) || (this.bt > 0.0D) || (this.bu > 0.0D) || (this.bv < 1.0D) || (this.bw < 1.0D) || (this.bx < 1.0D))
{
return 110;
}

return this.bm;
}

return i != wj.a[k] ? 108 : 109;
}

public int b()
{
return 16;
}

public boolean c()
{
return false;
}

public boolean a(fd world, int i, int j, int k, gs entityplayer)
{
return false;
}

public void a(fd world, int i, int j, int k, ls entityliving)
{
int l = c(world, i, j, k, (gs)entityliving);
world.d(i, j, k, l);
if (!world.B)
{
h(world, i, j, k);
}
}

public void b(fd world, int i, int j, int k, int l)
{
if ((!world.B) && (!this.B))
{
dealingB = false;
h(world, i, j, k);
dealingB = true;
}
}

public void c(fd world, int i, int j, int k)
{
if ((!world.B) && (world.b(i, j, k) == null))
{
h(world, i, j, k);
}
}

private void h(fd world, int i, int j, int k)
{
int l = world.e(i, j, k);
int i1 = d(l);
boolean flag = f(world, i, j, k, i1);
if (l == 7)
{
return;
}
if ((flag) && (!e(l)))
{
if (h(world, i, j, k, i1))
{
world.e(i, j, k, i1 | 0x8 );
world.d(i, j, k, 0, i1);
}
}
else if ((!flag) && (e(l)))
{
world.e(i, j, k, i1);
world.d(i, j, k, 1, i1);
}
}

private boolean f(fd world, int i, int j, int k, int l)
{
if ((l != 0) && (world.k(i, j - 1, k, 0)))
{
return true;
}
if ((l != 1) && (world.k(i, j + 1, k, 1)))
{
return true;
}
if ((l != 2) && (world.k(i, j, k - 1, 2)))
{
return true;
}
if ((l != 3) && (world.k(i, j, k + 1, 3)))
{
return true;
}
if ((l != 5) && (world.k(i + 1, j, k, 5)))
{
return true;
}
if ((l != 4) && (world.k(i - 1, j, k, 4)))
{
return true;
}
if (world.k(i, j, k, 0))
{
return true;
}
if (world.k(i, j + 2, k, 1))
{
return true;
}
if (world.k(i, j + 1, k - 1, 2))
{
return true;
}
if (world.k(i, j + 1, k + 1, 3))
{
return true;
}
if (world.k(i - 1, j + 1, k, 4))
{
return true;
}
return world.k(i + 1, j + 1, k, 5);
}

public void a(fd world, int i, int j, int k, int l, int i1)
{
this.b = true;
int j1 = i1;
if (l == 0)
{
if (i(world, i, j, k, j1))
{
world.d(i, j, k, j1 | 0x8 );
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.out", 0.5F, world.r.nextFloat() * 0.25F + 0.6F);
}
}
else if (l == 1)
{
ow tileentity = world.b(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1]);
if ((tileentity != null) && ((tileentity instanceof uk)))
{
((uk)tileentity).l();
}
world.a(i, j, k, uu.ad.bn, j1);
world.a(i, j, k, ut.a(this.bn, j1, j1, false, true));
if (this.a)
{
int k1 = i + wj.b[j1] * 2;
int l1 = j + wj.c[j1] * 2;
int i2 = k + wj.d[j1] * 2;
int j2 = world.a(k1, l1, i2);
int k2 = world.e(k1, l1, i2);
boolean flag = false;
if (j2 == uu.ad.bn)
{
ow tileentity1 = world.b(k1, l1, i2);
if ((tileentity1 != null) && ((tileentity1 instanceof uk)))
{
uk tileentitypiston = (uk)tileentity1;
if ((tileentitypiston.d() == j1) && (tileentitypiston.b()))
{
tileentitypiston.l();
j2 = tileentitypiston.a();
k2 = tileentitypiston.e();
flag = true;
}
}
}
if ((!flag) && (j2 > 0) && (a(j2, world, k1, l1, i2, false)) && ((uu.m[j2].h() == 0) || (j2 == uu.aa.bn) || (j2 == uu.W.bn)))
{
this.b = false;
world.f(k1, l1, i2, 0);
this.b = true;
i += wj.b[j1];
j += wj.c[j1];
k += wj.d[j1];
world.a(i, j, k, uu.ad.bn, k2);
world.a(i, j, k, ut.a(j2, k2, j1, false, false));
}
else if (!flag)
{
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
}
else {
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.in", 0.5F, world.r.nextFloat() * 0.15F + 0.6F);
}
this.b = false;
}

public void a(xp iblockaccess, int i, int j, int k)
{
int l = iblockaccess.e(i, j, k);
if (e(l))
{
switch (d(l))
{
case 0:
a(0.0F, 0.25F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 1:
a(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F);
break;
case 2:
a(0.0F, 0.0F, 0.25F, 1.0F, 1.0F, 1.0F);
break;
case 3:
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.75F);
break;
case 4:
a(0.25F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 5:
a(0.0F, 0.0F, 0.0F, 0.75F, 1.0F, 1.0F);
}
}
else
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
}

public void g()
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}

public void a(fd world, int i, int j, int k, eq axisalignedbb, ArrayList arraylist)
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
super.a(world, i, j, k, axisalignedbb, arraylist);
}

public boolean d()
{
return false;
}

public static int d(int i)
{
return i & 0x7;
}

public static boolean e(int i)
{
return (i & 0x8 ) != 0;
}

private static int c(fd world, int i, int j, int k, gs entityplayer)
{
if ((in.e((float)entityplayer.aM - i) < 2.0F) && (in.e((float)entityplayer.aO - k) < 2.0F))
{
double d = entityplayer.aN + 1.82D - entityplayer.bf;
if (d - j > 2.0D)
{
return 1;
}
if (j - d > 0.0D)
{
return 0;
}
}
int l = in.b(entityplayer.aS * 4.0F / 360.0F + 0.5D) & 0x3;
if (l == 0)
{
return 2;
}
if (l == 1)
{
return 5;
}
if (l == 2)
{
return 3;
}
return l != 3 ? 0 : 4;
}

private static boolean a(int i, fd world, int j, int k, int l, boolean flag)
{
if (i == uu.aq.bn)
{
return false;
}
if ((i == uu.aa.bn) || (i == uu.W.bn))
{
if (e(world.e(j, k, l)))
{
return false;
}
}
else {
if (uu.m[i].m() == -1.0F)
{
return false;
}
if (uu.m[i].h() == 2)
{
return false;
}
if ((!flag) && (uu.m[i].h() == 1))
{
return false;
}
}
ow tileentity = world.b(j, k, l);
return tileentity == null;
}

private static boolean h(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int i2 = world.a(i1, j1, k1);

if (!dealingB)
{
dealingWith = mod_NWater.isPistonWater(i2, world.e(i1, j1, k1));
mod_NWater.dealWithPistonWater(world, dealingWith, l, i1, j1, k1);
dealingB = true;
}
if (i2 == 0)
{
break;
}

if (!a(i2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[i2].h() == 1)
{
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
return true;
}

private boolean i(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int j2 = world.a(i1, j1, k1);
if (j2 == 0)
{
break;
}
if (!a(j2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[j2].h() == 1)
{
uu.m[j2].g(world, i1, j1, k1, world.e(i1, j1, k1));
world.f(i1, j1, k1, 0);
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
int l2;
for (; (i1 != i) || (j1 != j) || (k1 != k); k1 = l2)
{
int i2 = i1 - wj.b[l];
int k2 = j1 - wj.c[l];
l2 = k1 - wj.d[l];
int i3 = world.a(i2, k2, l2);
int j3 = world.e(i2, k2, l2);
if ((i3 == this.bn) && (i2 == i) && (k2 == j) && (l2 == k))
{
world.a(i1, j1, k1, uu.ad.bn, l | (this.a ? 8 : 0));
world.a(i1, j1, k1, ut.a(uu.ab.bn, l | (this.a ? 8 : 0), l, true, false));
}
else {
world.a(i1, j1, k1, uu.ad.bn, j3);
world.a(i1, j1, k1, ut.a(i3, j3, l, true, false));
}
i1 = i2;
j1 = k2;
}

return true;
}
}
import java.util.ArrayList;
import java.util.Random;

public class jq extends uu
{
private static int dealingWith;
private static boolean dealingB;
private boolean a;
private boolean b;

public jq(int i, int j, boolean flag)
{
super(i, j, ln.B);
this.a = flag;
a(h);
c(0.5F);
}

public int i()
{
return !this.a ? 107 : 106;
}

public int a(int i, int j)
{
int k = d(j);
if (k > 5)
{
return this.bm;
}
if (i == k)
{
if ((e(j)) || (this.bs > 0.0D) || (this.bt > 0.0D) || (this.bu > 0.0D) || (this.bv < 1.0D) || (this.bw < 1.0D) || (this.bx < 1.0D))
{
return 110;
}

return this.bm;
}

return i != wj.a[k] ? 108 : 109;
}

public int b()
{
return 16;
}

public boolean c()
{
return false;
}

public boolean a(fd world, int i, int j, int k, gs entityplayer)
{
return false;
}

public void a(fd world, int i, int j, int k, ls entityliving)
{
int l = c(world, i, j, k, (gs)entityliving);
world.d(i, j, k, l);
if (!world.B)
{
h(world, i, j, k);
}
}

public void b(fd world, int i, int j, int k, int l)
{
if ((!world.B) && (!this.B))
{
dealingB = false;
h(world, i, j, k);
dealingB = true;
}
}

public void c(fd world, int i, int j, int k)
{
if ((!world.B) && (world.b(i, j, k) == null))
{
h(world, i, j, k);
}
}

private void h(fd world, int i, int j, int k)
{
int l = world.e(i, j, k);
int i1 = d(l);
boolean flag = f(world, i, j, k, i1);
if (l == 7)
{
return;
}
if ((flag) && (!e(l)))
{
if (h(world, i, j, k, i1))
{
world.e(i, j, k, i1 | 0x8 );
world.d(i, j, k, 0, i1);
}
}
else if ((!flag) && (e(l)))
{
world.e(i, j, k, i1);
world.d(i, j, k, 1, i1);
}
}

private boolean f(fd world, int i, int j, int k, int l)
{
if ((l != 0) && (world.k(i, j - 1, k, 0)))
{
return true;
}
if ((l != 1) && (world.k(i, j + 1, k, 1)))
{
return true;
}
if ((l != 2) && (world.k(i, j, k - 1, 2)))
{
return true;
}
if ((l != 3) && (world.k(i, j, k + 1, 3)))
{
return true;
}
if ((l != 5) && (world.k(i + 1, j, k, 5)))
{
return true;
}
if ((l != 4) && (world.k(i - 1, j, k, 4)))
{
return true;
}
if (world.k(i, j, k, 0))
{
return true;
}
if (world.k(i, j + 2, k, 1))
{
return true;
}
if (world.k(i, j + 1, k - 1, 2))
{
return true;
}
if (world.k(i, j + 1, k + 1, 3))
{
return true;
}
if (world.k(i - 1, j + 1, k, 4))
{
return true;
}
return world.k(i + 1, j + 1, k, 5);
}

public void a(fd world, int i, int j, int k, int l, int i1)
{
this.b = true;
int j1 = i1;
if (l == 0)
{
if (i(world, i, j, k, j1))
{
world.d(i, j, k, j1 | 0x8 );
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.out", 0.5F, world.r.nextFloat() * 0.25F + 0.6F);
}
}
else if (l == 1)
{
ow tileentity = world.b(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1]);
if ((tileentity != null) && ((tileentity instanceof uk)))
{
((uk)tileentity).l();
}
world.a(i, j, k, uu.ad.bn, j1);
world.a(i, j, k, ut.a(this.bn, j1, j1, false, true));
if (this.a)
{
int k1 = i + wj.b[j1] * 2;
int l1 = j + wj.c[j1] * 2;
int i2 = k + wj.d[j1] * 2;
int j2 = world.a(k1, l1, i2);
int k2 = world.e(k1, l1, i2);
boolean flag = false;
if (j2 == uu.ad.bn)
{
ow tileentity1 = world.b(k1, l1, i2);
if ((tileentity1 != null) && ((tileentity1 instanceof uk)))
{
uk tileentitypiston = (uk)tileentity1;
if ((tileentitypiston.d() == j1) && (tileentitypiston.b()))
{
tileentitypiston.l();
j2 = tileentitypiston.a();
k2 = tileentitypiston.e();
flag = true;
}
}
}
if ((!flag) && (j2 > 0) && (a(j2, world, k1, l1, i2, false)) && ((uu.m[j2].h() == 0) || (j2 == uu.aa.bn) || (j2 == uu.W.bn)))
{
this.b = false;
world.f(k1, l1, i2, 0);
this.b = true;
i += wj.b[j1];
j += wj.c[j1];
k += wj.d[j1];
world.a(i, j, k, uu.ad.bn, k2);
world.a(i, j, k, ut.a(j2, k2, j1, false, false));
}
else if (!flag)
{
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
}
else {
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.in", 0.5F, world.r.nextFloat() * 0.15F + 0.6F);
}
this.b = false;
}

public void a(xp iblockaccess, int i, int j, int k)
{
int l = iblockaccess.e(i, j, k);
if (e(l))
{
switch (d(l))
{
case 0:
a(0.0F, 0.25F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 1:
a(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F);
break;
case 2:
a(0.0F, 0.0F, 0.25F, 1.0F, 1.0F, 1.0F);
break;
case 3:
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.75F);
break;
case 4:
a(0.25F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 5:
a(0.0F, 0.0F, 0.0F, 0.75F, 1.0F, 1.0F);
}
}
else
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
}

public void g()
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}

public void a(fd world, int i, int j, int k, eq axisalignedbb, ArrayList arraylist)
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
super.a(world, i, j, k, axisalignedbb, arraylist);
}

public boolean d()
{
return false;
}

public static int d(int i)
{
return i & 0x7;
}

public static boolean e(int i)
{
return (i & 0x8 ) != 0;
}

private static int c(fd world, int i, int j, int k, gs entityplayer)
{
if ((in.e((float)entityplayer.aM - i) < 2.0F) && (in.e((float)entityplayer.aO - k) < 2.0F))
{
double d = entityplayer.aN + 1.82D - entityplayer.bf;
if (d - j > 2.0D)
{
return 1;
}
if (j - d > 0.0D)
{
return 0;
}
}
int l = in.b(entityplayer.aS * 4.0F / 360.0F + 0.5D) & 0x3;
if (l == 0)
{
return 2;
}
if (l == 1)
{
return 5;
}
if (l == 2)
{
return 3;
}
return l != 3 ? 0 : 4;
}

private static boolean a(int i, fd world, int j, int k, int l, boolean flag)
{
if (i == uu.aq.bn)
{
return false;
}
if ((i == uu.aa.bn) || (i == uu.W.bn))
{
if (e(world.e(j, k, l)))
{
return false;
}
}
else {
if (uu.m[i].m() == -1.0F)
{
return false;
}
if (uu.m[i].h() == 2)
{
return false;
}
if ((!flag) && (uu.m[i].h() == 1))
{
return false;
}
}
ow tileentity = world.b(j, k, l);
return tileentity == null;
}

private static boolean h(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int i2 = world.a(i1, j1, k1);

if (!dealingB)
{
dealingWith = mod_NWater.isPistonWater(i2, world.e(i1, j1, k1));
mod_NWater.dealWithPistonWater(world, dealingWith, l, i1, j1, k1);
dealingB = true;
}
if (i2 == 0)
{
break;
}

if (!a(i2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[i2].h() == 1)
{
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
return true;
}

private boolean i(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int j2 = world.a(i1, j1, k1);
if (j2 == 0)
{
break;
}
if (!a(j2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[j2].h() == 1)
{
uu.m[j2].g(world, i1, j1, k1, world.e(i1, j1, k1));
world.f(i1, j1, k1, 0);
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
int l2;
for (; (i1 != i) || (j1 != j) || (k1 != k); k1 = l2)
{
int i2 = i1 - wj.b[l];
int k2 = j1 - wj.c[l];
l2 = k1 - wj.d[l];
int i3 = world.a(i2, k2, l2);
int j3 = world.e(i2, k2, l2);
if ((i3 == this.bn) && (i2 == i) && (k2 == j) && (l2 == k))
{
world.a(i1, j1, k1, uu.ad.bn, l | (this.a ? 8 : 0));
world.a(i1, j1, k1, ut.a(uu.ab.bn, l | (this.a ? 8 : 0), l, true, false));
}
else {
world.a(i1, j1, k1, uu.ad.bn, j3);
world.a(i1, j1, k1, ut.a(i3, j3, l, true, false));
}
i1 = i2;
j1 = k2;
}

return true;
}
}
import java.util.ArrayList;
import java.util.Random;

public class jq extends uu
{
private static int dealingWith;
private static boolean dealingB;
private boolean a;
private boolean b;

public jq(int i, int j, boolean flag)
{
super(i, j, ln.B);
this.a = flag;
a(h);
c(0.5F);
}

public int i()
{
return !this.a ? 107 : 106;
}

public int a(int i, int j)
{
int k = d(j);
if (k > 5)
{
return this.bm;
}
if (i == k)
{
if ((e(j)) || (this.bs > 0.0D) || (this.bt > 0.0D) || (this.bu > 0.0D) || (this.bv < 1.0D) || (this.bw < 1.0D) || (this.bx < 1.0D))
{
return 110;
}

return this.bm;
}

return i != wj.a[k] ? 108 : 109;
}

public int b()
{
return 16;
}

public boolean c()
{
return false;
}

public boolean a(fd world, int i, int j, int k, gs entityplayer)
{
return false;
}

public void a(fd world, int i, int j, int k, ls entityliving)
{
int l = c(world, i, j, k, (gs)entityliving);
world.d(i, j, k, l);
if (!world.B)
{
h(world, i, j, k);
}
}

public void b(fd world, int i, int j, int k, int l)
{
if ((!world.B) && (!this.B))
{
dealingB = false;
h(world, i, j, k);
dealingB = true;
}
}

public void c(fd world, int i, int j, int k)
{
if ((!world.B) && (world.b(i, j, k) == null))
{
h(world, i, j, k);
}
}

private void h(fd world, int i, int j, int k)
{
int l = world.e(i, j, k);
int i1 = d(l);
boolean flag = f(world, i, j, k, i1);
if (l == 7)
{
return;
}
if ((flag) && (!e(l)))
{
if (h(world, i, j, k, i1))
{
world.e(i, j, k, i1 | 0x8 );
world.d(i, j, k, 0, i1);
}
}
else if ((!flag) && (e(l)))
{
world.e(i, j, k, i1);
world.d(i, j, k, 1, i1);
}
}

private boolean f(fd world, int i, int j, int k, int l)
{
if ((l != 0) && (world.k(i, j - 1, k, 0)))
{
return true;
}
if ((l != 1) && (world.k(i, j + 1, k, 1)))
{
return true;
}
if ((l != 2) && (world.k(i, j, k - 1, 2)))
{
return true;
}
if ((l != 3) && (world.k(i, j, k + 1, 3)))
{
return true;
}
if ((l != 5) && (world.k(i + 1, j, k, 5)))
{
return true;
}
if ((l != 4) && (world.k(i - 1, j, k, 4)))
{
return true;
}
if (world.k(i, j, k, 0))
{
return true;
}
if (world.k(i, j + 2, k, 1))
{
return true;
}
if (world.k(i, j + 1, k - 1, 2))
{
return true;
}
if (world.k(i, j + 1, k + 1, 3))
{
return true;
}
if (world.k(i - 1, j + 1, k, 4))
{
return true;
}
return world.k(i + 1, j + 1, k, 5);
}

public void a(fd world, int i, int j, int k, int l, int i1)
{
this.b = true;
int j1 = i1;
if (l == 0)
{
if (i(world, i, j, k, j1))
{
world.d(i, j, k, j1 | 0x8 );
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.out", 0.5F, world.r.nextFloat() * 0.25F + 0.6F);
}
}
else if (l == 1)
{
ow tileentity = world.b(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1]);
if ((tileentity != null) && ((tileentity instanceof uk)))
{
((uk)tileentity).l();
}
world.a(i, j, k, uu.ad.bn, j1);
world.a(i, j, k, ut.a(this.bn, j1, j1, false, true));
if (this.a)
{
int k1 = i + wj.b[j1] * 2;
int l1 = j + wj.c[j1] * 2;
int i2 = k + wj.d[j1] * 2;
int j2 = world.a(k1, l1, i2);
int k2 = world.e(k1, l1, i2);
boolean flag = false;
if (j2 == uu.ad.bn)
{
ow tileentity1 = world.b(k1, l1, i2);
if ((tileentity1 != null) && ((tileentity1 instanceof uk)))
{
uk tileentitypiston = (uk)tileentity1;
if ((tileentitypiston.d() == j1) && (tileentitypiston.b()))
{
tileentitypiston.l();
j2 = tileentitypiston.a();
k2 = tileentitypiston.e();
flag = true;
}
}
}
if ((!flag) && (j2 > 0) && (a(j2, world, k1, l1, i2, false)) && ((uu.m[j2].h() == 0) || (j2 == uu.aa.bn) || (j2 == uu.W.bn)))
{
this.b = false;
world.f(k1, l1, i2, 0);
this.b = true;
i += wj.b[j1];
j += wj.c[j1];
k += wj.d[j1];
world.a(i, j, k, uu.ad.bn, k2);
world.a(i, j, k, ut.a(j2, k2, j1, false, false));
}
else if (!flag)
{
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
}
else {
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.in", 0.5F, world.r.nextFloat() * 0.15F + 0.6F);
}
this.b = false;
}

public void a(xp iblockaccess, int i, int j, int k)
{
int l = iblockaccess.e(i, j, k);
if (e(l))
{
switch (d(l))
{
case 0:
a(0.0F, 0.25F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 1:
a(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F);
break;
case 2:
a(0.0F, 0.0F, 0.25F, 1.0F, 1.0F, 1.0F);
break;
case 3:
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.75F);
break;
case 4:
a(0.25F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 5:
a(0.0F, 0.0F, 0.0F, 0.75F, 1.0F, 1.0F);
}
}
else
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
}

public void g()
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}

public void a(fd world, int i, int j, int k, eq axisalignedbb, ArrayList arraylist)
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
super.a(world, i, j, k, axisalignedbb, arraylist);
}

public boolean d()
{
return false;
}

public static int d(int i)
{
return i & 0x7;
}

public static boolean e(int i)
{
return (i & 0x8 ) != 0;
}

private static int c(fd world, int i, int j, int k, gs entityplayer)
{
if ((in.e((float)entityplayer.aM - i) < 2.0F) && (in.e((float)entityplayer.aO - k) < 2.0F))
{
double d = entityplayer.aN + 1.82D - entityplayer.bf;
if (d - j > 2.0D)
{
return 1;
}
if (j - d > 0.0D)
{
return 0;
}
}
int l = in.b(entityplayer.aS * 4.0F / 360.0F + 0.5D) & 0x3;
if (l == 0)
{
return 2;
}
if (l == 1)
{
return 5;
}
if (l == 2)
{
return 3;
}
return l != 3 ? 0 : 4;
}

private static boolean a(int i, fd world, int j, int k, int l, boolean flag)
{
if (i == uu.aq.bn)
{
return false;
}
if ((i == uu.aa.bn) || (i == uu.W.bn))
{
if (e(world.e(j, k, l)))
{
return false;
}
}
else {
if (uu.m[i].m() == -1.0F)
{
return false;
}
if (uu.m[i].h() == 2)
{
return false;
}
if ((!flag) && (uu.m[i].h() == 1))
{
return false;
}
}
ow tileentity = world.b(j, k, l);
return tileentity == null;
}

private static boolean h(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int i2 = world.a(i1, j1, k1);

if (!dealingB)
{
dealingWith = mod_NWater.isPistonWater(i2, world.e(i1, j1, k1));
mod_NWater.dealWithPistonWater(world, dealingWith, l, i1, j1, k1);
dealingB = true;
}
if (i2 == 0)
{
break;
}

if (!a(i2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[i2].h() == 1)
{
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
return true;
}

private boolean i(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int j2 = world.a(i1, j1, k1);
if (j2 == 0)
{
break;
}
if (!a(j2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[j2].h() == 1)
{
uu.m[j2].g(world, i1, j1, k1, world.e(i1, j1, k1));
world.f(i1, j1, k1, 0);
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
int l2;
for (; (i1 != i) || (j1 != j) || (k1 != k); k1 = l2)
{
int i2 = i1 - wj.b[l];
int k2 = j1 - wj.c[l];
l2 = k1 - wj.d[l];
int i3 = world.a(i2, k2, l2);
int j3 = world.e(i2, k2, l2);
if ((i3 == this.bn) && (i2 == i) && (k2 == j) && (l2 == k))
{
world.a(i1, j1, k1, uu.ad.bn, l | (this.a ? 8 : 0));
world.a(i1, j1, k1, ut.a(uu.ab.bn, l | (this.a ? 8 : 0), l, true, false));
}
else {
world.a(i1, j1, k1, uu.ad.bn, j3);
world.a(i1, j1, k1, ut.a(i3, j3, l, true, false));
}
i1 = i2;
j1 = k2;
}

return true;
}
}
import java.util.ArrayList;
import java.util.Random;

public class jq extends uu
{
private static int dealingWith;
private static boolean dealingB;
private boolean a;
private boolean b;

public jq(int i, int j, boolean flag)
{
super(i, j, ln.B);
this.a = flag;
a(h);
c(0.5F);
}

public int i()
{
return !this.a ? 107 : 106;
}

public int a(int i, int j)
{
int k = d(j);
if (k > 5)
{
return this.bm;
}
if (i == k)
{
if ((e(j)) || (this.bs > 0.0D) || (this.bt > 0.0D) || (this.bu > 0.0D) || (this.bv < 1.0D) || (this.bw < 1.0D) || (this.bx < 1.0D))
{
return 110;
}

return this.bm;
}

return i != wj.a[k] ? 108 : 109;
}

public int b()
{
return 16;
}

public boolean c()
{
return false;
}

public boolean a(fd world, int i, int j, int k, gs entityplayer)
{
return false;
}

public void a(fd world, int i, int j, int k, ls entityliving)
{
int l = c(world, i, j, k, (gs)entityliving);
world.d(i, j, k, l);
if (!world.B)
{
h(world, i, j, k);
}
}

public void b(fd world, int i, int j, int k, int l)
{
if ((!world.B) && (!this.B))
{
dealingB = false;
h(world, i, j, k);
dealingB = true;
}
}

public void c(fd world, int i, int j, int k)
{
if ((!world.B) && (world.b(i, j, k) == null))
{
h(world, i, j, k);
}
}

private void h(fd world, int i, int j, int k)
{
int l = world.e(i, j, k);
int i1 = d(l);
boolean flag = f(world, i, j, k, i1);
if (l == 7)
{
return;
}
if ((flag) && (!e(l)))
{
if (h(world, i, j, k, i1))
{
world.e(i, j, k, i1 | 0x8 );
world.d(i, j, k, 0, i1);
}
}
else if ((!flag) && (e(l)))
{
world.e(i, j, k, i1);
world.d(i, j, k, 1, i1);
}
}

private boolean f(fd world, int i, int j, int k, int l)
{
if ((l != 0) && (world.k(i, j - 1, k, 0)))
{
return true;
}
if ((l != 1) && (world.k(i, j + 1, k, 1)))
{
return true;
}
if ((l != 2) && (world.k(i, j, k - 1, 2)))
{
return true;
}
if ((l != 3) && (world.k(i, j, k + 1, 3)))
{
return true;
}
if ((l != 5) && (world.k(i + 1, j, k, 5)))
{
return true;
}
if ((l != 4) && (world.k(i - 1, j, k, 4)))
{
return true;
}
if (world.k(i, j, k, 0))
{
return true;
}
if (world.k(i, j + 2, k, 1))
{
return true;
}
if (world.k(i, j + 1, k - 1, 2))
{
return true;
}
if (world.k(i, j + 1, k + 1, 3))
{
return true;
}
if (world.k(i - 1, j + 1, k, 4))
{
return true;
}
return world.k(i + 1, j + 1, k, 5);
}

public void a(fd world, int i, int j, int k, int l, int i1)
{
this.b = true;
int j1 = i1;
if (l == 0)
{
if (i(world, i, j, k, j1))
{
world.d(i, j, k, j1 | 0x8 );
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.out", 0.5F, world.r.nextFloat() * 0.25F + 0.6F);
}
}
else if (l == 1)
{
ow tileentity = world.b(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1]);
if ((tileentity != null) && ((tileentity instanceof uk)))
{
((uk)tileentity).l();
}
world.a(i, j, k, uu.ad.bn, j1);
world.a(i, j, k, ut.a(this.bn, j1, j1, false, true));
if (this.a)
{
int k1 = i + wj.b[j1] * 2;
int l1 = j + wj.c[j1] * 2;
int i2 = k + wj.d[j1] * 2;
int j2 = world.a(k1, l1, i2);
int k2 = world.e(k1, l1, i2);
boolean flag = false;
if (j2 == uu.ad.bn)
{
ow tileentity1 = world.b(k1, l1, i2);
if ((tileentity1 != null) && ((tileentity1 instanceof uk)))
{
uk tileentitypiston = (uk)tileentity1;
if ((tileentitypiston.d() == j1) && (tileentitypiston.b()))
{
tileentitypiston.l();
j2 = tileentitypiston.a();
k2 = tileentitypiston.e();
flag = true;
}
}
}
if ((!flag) && (j2 > 0) && (a(j2, world, k1, l1, i2, false)) && ((uu.m[j2].h() == 0) || (j2 == uu.aa.bn) || (j2 == uu.W.bn)))
{
this.b = false;
world.f(k1, l1, i2, 0);
this.b = true;
i += wj.b[j1];
j += wj.c[j1];
k += wj.d[j1];
world.a(i, j, k, uu.ad.bn, k2);
world.a(i, j, k, ut.a(j2, k2, j1, false, false));
}
else if (!flag)
{
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
}
else {
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.in", 0.5F, world.r.nextFloat() * 0.15F + 0.6F);
}
this.b = false;
}

public void a(xp iblockaccess, int i, int j, int k)
{
int l = iblockaccess.e(i, j, k);
if (e(l))
{
switch (d(l))
{
case 0:
a(0.0F, 0.25F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 1:
a(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F);
break;
case 2:
a(0.0F, 0.0F, 0.25F, 1.0F, 1.0F, 1.0F);
break;
case 3:
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.75F);
break;
case 4:
a(0.25F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 5:
a(0.0F, 0.0F, 0.0F, 0.75F, 1.0F, 1.0F);
}
}
else
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
}

public void g()
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}

public void a(fd world, int i, int j, int k, eq axisalignedbb, ArrayList arraylist)
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
super.a(world, i, j, k, axisalignedbb, arraylist);
}

public boolean d()
{
return false;
}

public static int d(int i)
{
return i & 0x7;
}

public static boolean e(int i)
{
return (i & 0x8 ) != 0;
}

private static int c(fd world, int i, int j, int k, gs entityplayer)
{
if ((in.e((float)entityplayer.aM - i) < 2.0F) && (in.e((float)entityplayer.aO - k) < 2.0F))
{
double d = entityplayer.aN + 1.82D - entityplayer.bf;
if (d - j > 2.0D)
{
return 1;
}
if (j - d > 0.0D)
{
return 0;
}
}
int l = in.b(entityplayer.aS * 4.0F / 360.0F + 0.5D) & 0x3;
if (l == 0)
{
return 2;
}
if (l == 1)
{
return 5;
}
if (l == 2)
{
return 3;
}
return l != 3 ? 0 : 4;
}

private static boolean a(int i, fd world, int j, int k, int l, boolean flag)
{
if (i == uu.aq.bn)
{
return false;
}
if ((i == uu.aa.bn) || (i == uu.W.bn))
{
if (e(world.e(j, k, l)))
{
return false;
}
}
else {
if (uu.m[i].m() == -1.0F)
{
return false;
}
if (uu.m[i].h() == 2)
{
return false;
}
if ((!flag) && (uu.m[i].h() == 1))
{
return false;
}
}
ow tileentity = world.b(j, k, l);
return tileentity == null;
}

private static boolean h(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int i2 = world.a(i1, j1, k1);

if (!dealingB)
{
dealingWith = mod_NWater.isPistonWater(i2, world.e(i1, j1, k1));
mod_NWater.dealWithPistonWater(world, dealingWith, l, i1, j1, k1);
dealingB = true;
}
if (i2 == 0)
{
break;
}

if (!a(i2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[i2].h() == 1)
{
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
return true;
}

private boolean i(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int j2 = world.a(i1, j1, k1);
if (j2 == 0)
{
break;
}
if (!a(j2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[j2].h() == 1)
{
uu.m[j2].g(world, i1, j1, k1, world.e(i1, j1, k1));
world.f(i1, j1, k1, 0);
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
int l2;
for (; (i1 != i) || (j1 != j) || (k1 != k); k1 = l2)
{
int i2 = i1 - wj.b[l];
int k2 = j1 - wj.c[l];
l2 = k1 - wj.d[l];
int i3 = world.a(i2, k2, l2);
int j3 = world.e(i2, k2, l2);
if ((i3 == this.bn) && (i2 == i) && (k2 == j) && (l2 == k))
{
world.a(i1, j1, k1, uu.ad.bn, l | (this.a ? 8 : 0));
world.a(i1, j1, k1, ut.a(uu.ab.bn, l | (this.a ? 8 : 0), l, true, false));
}
else {
world.a(i1, j1, k1, uu.ad.bn, j3);
world.a(i1, j1, k1, ut.a(i3, j3, l, true, false));
}
i1 = i2;
j1 = k2;
}

return true;
}
}
import java.util.ArrayList;
import java.util.Random;

public class jq extends uu
{
private static int dealingWith;
private static boolean dealingB;
private boolean a;
private boolean b;

public jq(int i, int j, boolean flag)
{
super(i, j, ln.B);
this.a = flag;
a(h);
c(0.5F);
}

public int i()
{
return !this.a ? 107 : 106;
}

public int a(int i, int j)
{
int k = d(j);
if (k > 5)
{
return this.bm;
}
if (i == k)
{
if ((e(j)) || (this.bs > 0.0D) || (this.bt > 0.0D) || (this.bu > 0.0D) || (this.bv < 1.0D) || (this.bw < 1.0D) || (this.bx < 1.0D))
{
return 110;
}

return this.bm;
}

return i != wj.a[k] ? 108 : 109;
}

public int b()
{
return 16;
}

public boolean c()
{
return false;
}

public boolean a(fd world, int i, int j, int k, gs entityplayer)
{
return false;
}

public void a(fd world, int i, int j, int k, ls entityliving)
{
int l = c(world, i, j, k, (gs)entityliving);
world.d(i, j, k, l);
if (!world.B)
{
h(world, i, j, k);
}
}

public void b(fd world, int i, int j, int k, int l)
{
if ((!world.B) && (!this.B))
{
dealingB = false;
h(world, i, j, k);
dealingB = true;
}
}

public void c(fd world, int i, int j, int k)
{
if ((!world.B) && (world.b(i, j, k) == null))
{
h(world, i, j, k);
}
}

private void h(fd world, int i, int j, int k)
{
int l = world.e(i, j, k);
int i1 = d(l);
boolean flag = f(world, i, j, k, i1);
if (l == 7)
{
return;
}
if ((flag) && (!e(l)))
{
if (h(world, i, j, k, i1))
{
world.e(i, j, k, i1 | 0x8 );
world.d(i, j, k, 0, i1);
}
}
else if ((!flag) && (e(l)))
{
world.e(i, j, k, i1);
world.d(i, j, k, 1, i1);
}
}

private boolean f(fd world, int i, int j, int k, int l)
{
if ((l != 0) && (world.k(i, j - 1, k, 0)))
{
return true;
}
if ((l != 1) && (world.k(i, j + 1, k, 1)))
{
return true;
}
if ((l != 2) && (world.k(i, j, k - 1, 2)))
{
return true;
}
if ((l != 3) && (world.k(i, j, k + 1, 3)))
{
return true;
}
if ((l != 5) && (world.k(i + 1, j, k, 5)))
{
return true;
}
if ((l != 4) && (world.k(i - 1, j, k, 4)))
{
return true;
}
if (world.k(i, j, k, 0))
{
return true;
}
if (world.k(i, j + 2, k, 1))
{
return true;
}
if (world.k(i, j + 1, k - 1, 2))
{
return true;
}
if (world.k(i, j + 1, k + 1, 3))
{
return true;
}
if (world.k(i - 1, j + 1, k, 4))
{
return true;
}
return world.k(i + 1, j + 1, k, 5);
}

public void a(fd world, int i, int j, int k, int l, int i1)
{
this.b = true;
int j1 = i1;
if (l == 0)
{
if (i(world, i, j, k, j1))
{
world.d(i, j, k, j1 | 0x8 );
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.out", 0.5F, world.r.nextFloat() * 0.25F + 0.6F);
}
}
else if (l == 1)
{
ow tileentity = world.b(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1]);
if ((tileentity != null) && ((tileentity instanceof uk)))
{
((uk)tileentity).l();
}
world.a(i, j, k, uu.ad.bn, j1);
world.a(i, j, k, ut.a(this.bn, j1, j1, false, true));
if (this.a)
{
int k1 = i + wj.b[j1] * 2;
int l1 = j + wj.c[j1] * 2;
int i2 = k + wj.d[j1] * 2;
int j2 = world.a(k1, l1, i2);
int k2 = world.e(k1, l1, i2);
boolean flag = false;
if (j2 == uu.ad.bn)
{
ow tileentity1 = world.b(k1, l1, i2);
if ((tileentity1 != null) && ((tileentity1 instanceof uk)))
{
uk tileentitypiston = (uk)tileentity1;
if ((tileentitypiston.d() == j1) && (tileentitypiston.b()))
{
tileentitypiston.l();
j2 = tileentitypiston.a();
k2 = tileentitypiston.e();
flag = true;
}
}
}
if ((!flag) && (j2 > 0) && (a(j2, world, k1, l1, i2, false)) && ((uu.m[j2].h() == 0) || (j2 == uu.aa.bn) || (j2 == uu.W.bn)))
{
this.b = false;
world.f(k1, l1, i2, 0);
this.b = true;
i += wj.b[j1];
j += wj.c[j1];
k += wj.d[j1];
world.a(i, j, k, uu.ad.bn, k2);
world.a(i, j, k, ut.a(j2, k2, j1, false, false));
}
else if (!flag)
{
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
}
else {
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.in", 0.5F, world.r.nextFloat() * 0.15F + 0.6F);
}
this.b = false;
}

public void a(xp iblockaccess, int i, int j, int k)
{
int l = iblockaccess.e(i, j, k);
if (e(l))
{
switch (d(l))
{
case 0:
a(0.0F, 0.25F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 1:
a(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F);
break;
case 2:
a(0.0F, 0.0F, 0.25F, 1.0F, 1.0F, 1.0F);
break;
case 3:
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.75F);
break;
case 4:
a(0.25F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 5:
a(0.0F, 0.0F, 0.0F, 0.75F, 1.0F, 1.0F);
}
}
else
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
}

public void g()
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}

public void a(fd world, int i, int j, int k, eq axisalignedbb, ArrayList arraylist)
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
super.a(world, i, j, k, axisalignedbb, arraylist);
}

public boolean d()
{
return false;
}

public static int d(int i)
{
return i & 0x7;
}

public static boolean e(int i)
{
return (i & 0x8 ) != 0;
}

private static int c(fd world, int i, int j, int k, gs entityplayer)
{
if ((in.e((float)entityplayer.aM - i) < 2.0F) && (in.e((float)entityplayer.aO - k) < 2.0F))
{
double d = entityplayer.aN + 1.82D - entityplayer.bf;
if (d - j > 2.0D)
{
return 1;
}
if (j - d > 0.0D)
{
return 0;
}
}
int l = in.b(entityplayer.aS * 4.0F / 360.0F + 0.5D) & 0x3;
if (l == 0)
{
return 2;
}
if (l == 1)
{
return 5;
}
if (l == 2)
{
return 3;
}
return l != 3 ? 0 : 4;
}

private static boolean a(int i, fd world, int j, int k, int l, boolean flag)
{
if (i == uu.aq.bn)
{
return false;
}
if ((i == uu.aa.bn) || (i == uu.W.bn))
{
if (e(world.e(j, k, l)))
{
return false;
}
}
else {
if (uu.m[i].m() == -1.0F)
{
return false;
}
if (uu.m[i].h() == 2)
{
return false;
}
if ((!flag) && (uu.m[i].h() == 1))
{
return false;
}
}
ow tileentity = world.b(j, k, l);
return tileentity == null;
}

private static boolean h(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int i2 = world.a(i1, j1, k1);

if (!dealingB)
{
dealingWith = mod_NWater.isPistonWater(i2, world.e(i1, j1, k1));
mod_NWater.dealWithPistonWater(world, dealingWith, l, i1, j1, k1);
dealingB = true;
}
if (i2 == 0)
{
break;
}

if (!a(i2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[i2].h() == 1)
{
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
return true;
}

private boolean i(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int j2 = world.a(i1, j1, k1);
if (j2 == 0)
{
break;
}
if (!a(j2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[j2].h() == 1)
{
uu.m[j2].g(world, i1, j1, k1, world.e(i1, j1, k1));
world.f(i1, j1, k1, 0);
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
int l2;
for (; (i1 != i) || (j1 != j) || (k1 != k); k1 = l2)
{
int i2 = i1 - wj.b[l];
int k2 = j1 - wj.c[l];
l2 = k1 - wj.d[l];
int i3 = world.a(i2, k2, l2);
int j3 = world.e(i2, k2, l2);
if ((i3 == this.bn) && (i2 == i) && (k2 == j) && (l2 == k))
{
world.a(i1, j1, k1, uu.ad.bn, l | (this.a ? 8 : 0));
world.a(i1, j1, k1, ut.a(uu.ab.bn, l | (this.a ? 8 : 0), l, true, false));
}
else {
world.a(i1, j1, k1, uu.ad.bn, j3);
world.a(i1, j1, k1, ut.a(i3, j3, l, true, false));
}
i1 = i2;
j1 = k2;
}

return true;
}
}
import java.util.ArrayList;
import java.util.Random;

public class jq extends uu
{
private static int dealingWith;
private static boolean dealingB;
private boolean a;
private boolean b;

public jq(int i, int j, boolean flag)
{
super(i, j, ln.B);
this.a = flag;
a(h);
c(0.5F);
}

public int i()
{
return !this.a ? 107 : 106;
}

public int a(int i, int j)
{
int k = d(j);
if (k > 5)
{
return this.bm;
}
if (i == k)
{
if ((e(j)) || (this.bs > 0.0D) || (this.bt > 0.0D) || (this.bu > 0.0D) || (this.bv < 1.0D) || (this.bw < 1.0D) || (this.bx < 1.0D))
{
return 110;
}

return this.bm;
}

return i != wj.a[k] ? 108 : 109;
}

public int b()
{
return 16;
}

public boolean c()
{
return false;
}

public boolean a(fd world, int i, int j, int k, gs entityplayer)
{
return false;
}

public void a(fd world, int i, int j, int k, ls entityliving)
{
int l = c(world, i, j, k, (gs)entityliving);
world.d(i, j, k, l);
if (!world.B)
{
h(world, i, j, k);
}
}

public void b(fd world, int i, int j, int k, int l)
{
if ((!world.B) && (!this.B))
{
dealingB = false;
h(world, i, j, k);
dealingB = true;
}
}

public void c(fd world, int i, int j, int k)
{
if ((!world.B) && (world.b(i, j, k) == null))
{
h(world, i, j, k);
}
}

private void h(fd world, int i, int j, int k)
{
int l = world.e(i, j, k);
int i1 = d(l);
boolean flag = f(world, i, j, k, i1);
if (l == 7)
{
return;
}
if ((flag) && (!e(l)))
{
if (h(world, i, j, k, i1))
{
world.e(i, j, k, i1 | 0x8 );
world.d(i, j, k, 0, i1);
}
}
else if ((!flag) && (e(l)))
{
world.e(i, j, k, i1);
world.d(i, j, k, 1, i1);
}
}

private boolean f(fd world, int i, int j, int k, int l)
{
if ((l != 0) && (world.k(i, j - 1, k, 0)))
{
return true;
}
if ((l != 1) && (world.k(i, j + 1, k, 1)))
{
return true;
}
if ((l != 2) && (world.k(i, j, k - 1, 2)))
{
return true;
}
if ((l != 3) && (world.k(i, j, k + 1, 3)))
{
return true;
}
if ((l != 5) && (world.k(i + 1, j, k, 5)))
{
return true;
}
if ((l != 4) && (world.k(i - 1, j, k, 4)))
{
return true;
}
if (world.k(i, j, k, 0))
{
return true;
}
if (world.k(i, j + 2, k, 1))
{
return true;
}
if (world.k(i, j + 1, k - 1, 2))
{
return true;
}
if (world.k(i, j + 1, k + 1, 3))
{
return true;
}
if (world.k(i - 1, j + 1, k, 4))
{
return true;
}
return world.k(i + 1, j + 1, k, 5);
}

public void a(fd world, int i, int j, int k, int l, int i1)
{
this.b = true;
int j1 = i1;
if (l == 0)
{
if (i(world, i, j, k, j1))
{
world.d(i, j, k, j1 | 0x8 );
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.out", 0.5F, world.r.nextFloat() * 0.25F + 0.6F);
}
}
else if (l == 1)
{
ow tileentity = world.b(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1]);
if ((tileentity != null) && ((tileentity instanceof uk)))
{
((uk)tileentity).l();
}
world.a(i, j, k, uu.ad.bn, j1);
world.a(i, j, k, ut.a(this.bn, j1, j1, false, true));
if (this.a)
{
int k1 = i + wj.b[j1] * 2;
int l1 = j + wj.c[j1] * 2;
int i2 = k + wj.d[j1] * 2;
int j2 = world.a(k1, l1, i2);
int k2 = world.e(k1, l1, i2);
boolean flag = false;
if (j2 == uu.ad.bn)
{
ow tileentity1 = world.b(k1, l1, i2);
if ((tileentity1 != null) && ((tileentity1 instanceof uk)))
{
uk tileentitypiston = (uk)tileentity1;
if ((tileentitypiston.d() == j1) && (tileentitypiston.b()))
{
tileentitypiston.l();
j2 = tileentitypiston.a();
k2 = tileentitypiston.e();
flag = true;
}
}
}
if ((!flag) && (j2 > 0) && (a(j2, world, k1, l1, i2, false)) && ((uu.m[j2].h() == 0) || (j2 == uu.aa.bn) || (j2 == uu.W.bn)))
{
this.b = false;
world.f(k1, l1, i2, 0);
this.b = true;
i += wj.b[j1];
j += wj.c[j1];
k += wj.d[j1];
world.a(i, j, k, uu.ad.bn, k2);
world.a(i, j, k, ut.a(j2, k2, j1, false, false));
}
else if (!flag)
{
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
}
else {
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.in", 0.5F, world.r.nextFloat() * 0.15F + 0.6F);
}
this.b = false;
}

public void a(xp iblockaccess, int i, int j, int k)
{
int l = iblockaccess.e(i, j, k);
if (e(l))
{
switch (d(l))
{
case 0:
a(0.0F, 0.25F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 1:
a(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F);
break;
case 2:
a(0.0F, 0.0F, 0.25F, 1.0F, 1.0F, 1.0F);
break;
case 3:
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.75F);
break;
case 4:
a(0.25F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 5:
a(0.0F, 0.0F, 0.0F, 0.75F, 1.0F, 1.0F);
}
}
else
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
}

public void g()
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}

public void a(fd world, int i, int j, int k, eq axisalignedbb, ArrayList arraylist)
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
super.a(world, i, j, k, axisalignedbb, arraylist);
}

public boolean d()
{
return false;
}

public static int d(int i)
{
return i & 0x7;
}

public static boolean e(int i)
{
return (i & 0x8 ) != 0;
}

private static int c(fd world, int i, int j, int k, gs entityplayer)
{
if ((in.e((float)entityplayer.aM - i) < 2.0F) && (in.e((float)entityplayer.aO - k) < 2.0F))
{
double d = entityplayer.aN + 1.82D - entityplayer.bf;
if (d - j > 2.0D)
{
return 1;
}
if (j - d > 0.0D)
{
return 0;
}
}
int l = in.b(entityplayer.aS * 4.0F / 360.0F + 0.5D) & 0x3;
if (l == 0)
{
return 2;
}
if (l == 1)
{
return 5;
}
if (l == 2)
{
return 3;
}
return l != 3 ? 0 : 4;
}

private static boolean a(int i, fd world, int j, int k, int l, boolean flag)
{
if (i == uu.aq.bn)
{
return false;
}
if ((i == uu.aa.bn) || (i == uu.W.bn))
{
if (e(world.e(j, k, l)))
{
return false;
}
}
else {
if (uu.m[i].m() == -1.0F)
{
return false;
}
if (uu.m[i].h() == 2)
{
return false;
}
if ((!flag) && (uu.m[i].h() == 1))
{
return false;
}
}
ow tileentity = world.b(j, k, l);
return tileentity == null;
}

private static boolean h(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int i2 = world.a(i1, j1, k1);

if (!dealingB)
{
dealingWith = mod_NWater.isPistonWater(i2, world.e(i1, j1, k1));
mod_NWater.dealWithPistonWater(world, dealingWith, l, i1, j1, k1);
dealingB = true;
}
if (i2 == 0)
{
break;
}

if (!a(i2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[i2].h() == 1)
{
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
return true;
}

private boolean i(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int j2 = world.a(i1, j1, k1);
if (j2 == 0)
{
break;
}
if (!a(j2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[j2].h() == 1)
{
uu.m[j2].g(world, i1, j1, k1, world.e(i1, j1, k1));
world.f(i1, j1, k1, 0);
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
int l2;
for (; (i1 != i) || (j1 != j) || (k1 != k); k1 = l2)
{
int i2 = i1 - wj.b[l];
int k2 = j1 - wj.c[l];
l2 = k1 - wj.d[l];
int i3 = world.a(i2, k2, l2);
int j3 = world.e(i2, k2, l2);
if ((i3 == this.bn) && (i2 == i) && (k2 == j) && (l2 == k))
{
world.a(i1, j1, k1, uu.ad.bn, l | (this.a ? 8 : 0));
world.a(i1, j1, k1, ut.a(uu.ab.bn, l | (this.a ? 8 : 0), l, true, false));
}
else {
world.a(i1, j1, k1, uu.ad.bn, j3);
world.a(i1, j1, k1, ut.a(i3, j3, l, true, false));
}
i1 = i2;
j1 = k2;
}

return true;
}
}
import java.util.ArrayList;
import java.util.Random;

public class jq extends uu
{
private static int dealingWith;
private static boolean dealingB;
private boolean a;
private boolean b;

public jq(int i, int j, boolean flag)
{
super(i, j, ln.B);
this.a = flag;
a(h);
c(0.5F);
}

public int i()
{
return !this.a ? 107 : 106;
}

public int a(int i, int j)
{
int k = d(j);
if (k > 5)
{
return this.bm;
}
if (i == k)
{
if ((e(j)) || (this.bs > 0.0D) || (this.bt > 0.0D) || (this.bu > 0.0D) || (this.bv < 1.0D) || (this.bw < 1.0D) || (this.bx < 1.0D))
{
return 110;
}

return this.bm;
}

return i != wj.a[k] ? 108 : 109;
}

public int b()
{
return 16;
}

public boolean c()
{
return false;
}

public boolean a(fd world, int i, int j, int k, gs entityplayer)
{
return false;
}

public void a(fd world, int i, int j, int k, ls entityliving)
{
int l = c(world, i, j, k, (gs)entityliving);
world.d(i, j, k, l);
if (!world.B)
{
h(world, i, j, k);
}
}

public void b(fd world, int i, int j, int k, int l)
{
if ((!world.B) && (!this.B))
{
dealingB = false;
h(world, i, j, k);
dealingB = true;
}
}

public void c(fd world, int i, int j, int k)
{
if ((!world.B) && (world.b(i, j, k) == null))
{
h(world, i, j, k);
}
}

private void h(fd world, int i, int j, int k)
{
int l = world.e(i, j, k);
int i1 = d(l);
boolean flag = f(world, i, j, k, i1);
if (l == 7)
{
return;
}
if ((flag) && (!e(l)))
{
if (h(world, i, j, k, i1))
{
world.e(i, j, k, i1 | 0x8 );
world.d(i, j, k, 0, i1);
}
}
else if ((!flag) && (e(l)))
{
world.e(i, j, k, i1);
world.d(i, j, k, 1, i1);
}
}

private boolean f(fd world, int i, int j, int k, int l)
{
if ((l != 0) && (world.k(i, j - 1, k, 0)))
{
return true;
}
if ((l != 1) && (world.k(i, j + 1, k, 1)))
{
return true;
}
if ((l != 2) && (world.k(i, j, k - 1, 2)))
{
return true;
}
if ((l != 3) && (world.k(i, j, k + 1, 3)))
{
return true;
}
if ((l != 5) && (world.k(i + 1, j, k, 5)))
{
return true;
}
if ((l != 4) && (world.k(i - 1, j, k, 4)))
{
return true;
}
if (world.k(i, j, k, 0))
{
return true;
}
if (world.k(i, j + 2, k, 1))
{
return true;
}
if (world.k(i, j + 1, k - 1, 2))
{
return true;
}
if (world.k(i, j + 1, k + 1, 3))
{
return true;
}
if (world.k(i - 1, j + 1, k, 4))
{
return true;
}
return world.k(i + 1, j + 1, k, 5);
}

public void a(fd world, int i, int j, int k, int l, int i1)
{
this.b = true;
int j1 = i1;
if (l == 0)
{
if (i(world, i, j, k, j1))
{
world.d(i, j, k, j1 | 0x8 );
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.out", 0.5F, world.r.nextFloat() * 0.25F + 0.6F);
}
}
else if (l == 1)
{
ow tileentity = world.b(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1]);
if ((tileentity != null) && ((tileentity instanceof uk)))
{
((uk)tileentity).l();
}
world.a(i, j, k, uu.ad.bn, j1);
world.a(i, j, k, ut.a(this.bn, j1, j1, false, true));
if (this.a)
{
int k1 = i + wj.b[j1] * 2;
int l1 = j + wj.c[j1] * 2;
int i2 = k + wj.d[j1] * 2;
int j2 = world.a(k1, l1, i2);
int k2 = world.e(k1, l1, i2);
boolean flag = false;
if (j2 == uu.ad.bn)
{
ow tileentity1 = world.b(k1, l1, i2);
if ((tileentity1 != null) && ((tileentity1 instanceof uk)))
{
uk tileentitypiston = (uk)tileentity1;
if ((tileentitypiston.d() == j1) && (tileentitypiston.b()))
{
tileentitypiston.l();
j2 = tileentitypiston.a();
k2 = tileentitypiston.e();
flag = true;
}
}
}
if ((!flag) && (j2 > 0) && (a(j2, world, k1, l1, i2, false)) && ((uu.m[j2].h() == 0) || (j2 == uu.aa.bn) || (j2 == uu.W.bn)))
{
this.b = false;
world.f(k1, l1, i2, 0);
this.b = true;
i += wj.b[j1];
j += wj.c[j1];
k += wj.d[j1];
world.a(i, j, k, uu.ad.bn, k2);
world.a(i, j, k, ut.a(j2, k2, j1, false, false));
}
else if (!flag)
{
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
}
else {
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.in", 0.5F, world.r.nextFloat() * 0.15F + 0.6F);
}
this.b = false;
}

public void a(xp iblockaccess, int i, int j, int k)
{
int l = iblockaccess.e(i, j, k);
if (e(l))
{
switch (d(l))
{
case 0:
a(0.0F, 0.25F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 1:
a(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F);
break;
case 2:
a(0.0F, 0.0F, 0.25F, 1.0F, 1.0F, 1.0F);
break;
case 3:
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.75F);
break;
case 4:
a(0.25F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 5:
a(0.0F, 0.0F, 0.0F, 0.75F, 1.0F, 1.0F);
}
}
else
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
}

public void g()
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}

public void a(fd world, int i, int j, int k, eq axisalignedbb, ArrayList arraylist)
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
super.a(world, i, j, k, axisalignedbb, arraylist);
}

public boolean d()
{
return false;
}

public static int d(int i)
{
return i & 0x7;
}

public static boolean e(int i)
{
return (i & 0x8 ) != 0;
}

private static int c(fd world, int i, int j, int k, gs entityplayer)
{
if ((in.e((float)entityplayer.aM - i) < 2.0F) && (in.e((float)entityplayer.aO - k) < 2.0F))
{
double d = entityplayer.aN + 1.82D - entityplayer.bf;
if (d - j > 2.0D)
{
return 1;
}
if (j - d > 0.0D)
{
return 0;
}
}
int l = in.b(entityplayer.aS * 4.0F / 360.0F + 0.5D) & 0x3;
if (l == 0)
{
return 2;
}
if (l == 1)
{
return 5;
}
if (l == 2)
{
return 3;
}
return l != 3 ? 0 : 4;
}

private static boolean a(int i, fd world, int j, int k, int l, boolean flag)
{
if (i == uu.aq.bn)
{
return false;
}
if ((i == uu.aa.bn) || (i == uu.W.bn))
{
if (e(world.e(j, k, l)))
{
return false;
}
}
else {
if (uu.m[i].m() == -1.0F)
{
return false;
}
if (uu.m[i].h() == 2)
{
return false;
}
if ((!flag) && (uu.m[i].h() == 1))
{
return false;
}
}
ow tileentity = world.b(j, k, l);
return tileentity == null;
}

private static boolean h(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int i2 = world.a(i1, j1, k1);

if (!dealingB)
{
dealingWith = mod_NWater.isPistonWater(i2, world.e(i1, j1, k1));
mod_NWater.dealWithPistonWater(world, dealingWith, l, i1, j1, k1);
dealingB = true;
}
if (i2 == 0)
{
break;
}

if (!a(i2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[i2].h() == 1)
{
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
return true;
}

private boolean i(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int j2 = world.a(i1, j1, k1);
if (j2 == 0)
{
break;
}
if (!a(j2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[j2].h() == 1)
{
uu.m[j2].g(world, i1, j1, k1, world.e(i1, j1, k1));
world.f(i1, j1, k1, 0);
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
int l2;
for (; (i1 != i) || (j1 != j) || (k1 != k); k1 = l2)
{
int i2 = i1 - wj.b[l];
int k2 = j1 - wj.c[l];
l2 = k1 - wj.d[l];
int i3 = world.a(i2, k2, l2);
int j3 = world.e(i2, k2, l2);
if ((i3 == this.bn) && (i2 == i) && (k2 == j) && (l2 == k))
{
world.a(i1, j1, k1, uu.ad.bn, l | (this.a ? 8 : 0));
world.a(i1, j1, k1, ut.a(uu.ab.bn, l | (this.a ? 8 : 0), l, true, false));
}
else {
world.a(i1, j1, k1, uu.ad.bn, j3);
world.a(i1, j1, k1, ut.a(i3, j3, l, true, false));
}
i1 = i2;
j1 = k2;
}

return true;
}
}
import java.util.ArrayList;
import java.util.Random;

public class jq extends uu
{
private static int dealingWith;
private static boolean dealingB;
private boolean a;
private boolean b;

public jq(int i, int j, boolean flag)
{
super(i, j, ln.B);
this.a = flag;
a(h);
c(0.5F);
}

public int i()
{
return !this.a ? 107 : 106;
}

public int a(int i, int j)
{
int k = d(j);
if (k > 5)
{
return this.bm;
}
if (i == k)
{
if ((e(j)) || (this.bs > 0.0D) || (this.bt > 0.0D) || (this.bu > 0.0D) || (this.bv < 1.0D) || (this.bw < 1.0D) || (this.bx < 1.0D))
{
return 110;
}

return this.bm;
}

return i != wj.a[k] ? 108 : 109;
}

public int b()
{
return 16;
}

public boolean c()
{
return false;
}

public boolean a(fd world, int i, int j, int k, gs entityplayer)
{
return false;
}

public void a(fd world, int i, int j, int k, ls entityliving)
{
int l = c(world, i, j, k, (gs)entityliving);
world.d(i, j, k, l);
if (!world.B)
{
h(world, i, j, k);
}
}

public void b(fd world, int i, int j, int k, int l)
{
if ((!world.B) && (!this.B))
{
dealingB = false;
h(world, i, j, k);
dealingB = true;
}
}

public void c(fd world, int i, int j, int k)
{
if ((!world.B) && (world.b(i, j, k) == null))
{
h(world, i, j, k);
}
}

private void h(fd world, int i, int j, int k)
{
int l = world.e(i, j, k);
int i1 = d(l);
boolean flag = f(world, i, j, k, i1);
if (l == 7)
{
return;
}
if ((flag) && (!e(l)))
{
if (h(world, i, j, k, i1))
{
world.e(i, j, k, i1 | 0x8 );
world.d(i, j, k, 0, i1);
}
}
else if ((!flag) && (e(l)))
{
world.e(i, j, k, i1);
world.d(i, j, k, 1, i1);
}
}

private boolean f(fd world, int i, int j, int k, int l)
{
if ((l != 0) && (world.k(i, j - 1, k, 0)))
{
return true;
}
if ((l != 1) && (world.k(i, j + 1, k, 1)))
{
return true;
}
if ((l != 2) && (world.k(i, j, k - 1, 2)))
{
return true;
}
if ((l != 3) && (world.k(i, j, k + 1, 3)))
{
return true;
}
if ((l != 5) && (world.k(i + 1, j, k, 5)))
{
return true;
}
if ((l != 4) && (world.k(i - 1, j, k, 4)))
{
return true;
}
if (world.k(i, j, k, 0))
{
return true;
}
if (world.k(i, j + 2, k, 1))
{
return true;
}
if (world.k(i, j + 1, k - 1, 2))
{
return true;
}
if (world.k(i, j + 1, k + 1, 3))
{
return true;
}
if (world.k(i - 1, j + 1, k, 4))
{
return true;
}
return world.k(i + 1, j + 1, k, 5);
}

public void a(fd world, int i, int j, int k, int l, int i1)
{
this.b = true;
int j1 = i1;
if (l == 0)
{
if (i(world, i, j, k, j1))
{
world.d(i, j, k, j1 | 0x8 );
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.out", 0.5F, world.r.nextFloat() * 0.25F + 0.6F);
}
}
else if (l == 1)
{
ow tileentity = world.b(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1]);
if ((tileentity != null) && ((tileentity instanceof uk)))
{
((uk)tileentity).l();
}
world.a(i, j, k, uu.ad.bn, j1);
world.a(i, j, k, ut.a(this.bn, j1, j1, false, true));
if (this.a)
{
int k1 = i + wj.b[j1] * 2;
int l1 = j + wj.c[j1] * 2;
int i2 = k + wj.d[j1] * 2;
int j2 = world.a(k1, l1, i2);
int k2 = world.e(k1, l1, i2);
boolean flag = false;
if (j2 == uu.ad.bn)
{
ow tileentity1 = world.b(k1, l1, i2);
if ((tileentity1 != null) && ((tileentity1 instanceof uk)))
{
uk tileentitypiston = (uk)tileentity1;
if ((tileentitypiston.d() == j1) && (tileentitypiston.b()))
{
tileentitypiston.l();
j2 = tileentitypiston.a();
k2 = tileentitypiston.e();
flag = true;
}
}
}
if ((!flag) && (j2 > 0) && (a(j2, world, k1, l1, i2, false)) && ((uu.m[j2].h() == 0) || (j2 == uu.aa.bn) || (j2 == uu.W.bn)))
{
this.b = false;
world.f(k1, l1, i2, 0);
this.b = true;
i += wj.b[j1];
j += wj.c[j1];
k += wj.d[j1];
world.a(i, j, k, uu.ad.bn, k2);
world.a(i, j, k, ut.a(j2, k2, j1, false, false));
}
else if (!flag)
{
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
}
else {
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.in", 0.5F, world.r.nextFloat() * 0.15F + 0.6F);
}
this.b = false;
}

public void a(xp iblockaccess, int i, int j, int k)
{
int l = iblockaccess.e(i, j, k);
if (e(l))
{
switch (d(l))
{
case 0:
a(0.0F, 0.25F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 1:
a(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F);
break;
case 2:
a(0.0F, 0.0F, 0.25F, 1.0F, 1.0F, 1.0F);
break;
case 3:
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.75F);
break;
case 4:
a(0.25F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 5:
a(0.0F, 0.0F, 0.0F, 0.75F, 1.0F, 1.0F);
}
}
else
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
}

public void g()
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}

public void a(fd world, int i, int j, int k, eq axisalignedbb, ArrayList arraylist)
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
super.a(world, i, j, k, axisalignedbb, arraylist);
}

public boolean d()
{
return false;
}

public static int d(int i)
{
return i & 0x7;
}

public static boolean e(int i)
{
return (i & 0x8 ) != 0;
}

private static int c(fd world, int i, int j, int k, gs entityplayer)
{
if ((in.e((float)entityplayer.aM - i) < 2.0F) && (in.e((float)entityplayer.aO - k) < 2.0F))
{
double d = entityplayer.aN + 1.82D - entityplayer.bf;
if (d - j > 2.0D)
{
return 1;
}
if (j - d > 0.0D)
{
return 0;
}
}
int l = in.b(entityplayer.aS * 4.0F / 360.0F + 0.5D) & 0x3;
if (l == 0)
{
return 2;
}
if (l == 1)
{
return 5;
}
if (l == 2)
{
return 3;
}
return l != 3 ? 0 : 4;
}

private static boolean a(int i, fd world, int j, int k, int l, boolean flag)
{
if (i == uu.aq.bn)
{
return false;
}
if ((i == uu.aa.bn) || (i == uu.W.bn))
{
if (e(world.e(j, k, l)))
{
return false;
}
}
else {
if (uu.m[i].m() == -1.0F)
{
return false;
}
if (uu.m[i].h() == 2)
{
return false;
}
if ((!flag) && (uu.m[i].h() == 1))
{
return false;
}
}
ow tileentity = world.b(j, k, l);
return tileentity == null;
}

private static boolean h(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int i2 = world.a(i1, j1, k1);

if (!dealingB)
{
dealingWith = mod_NWater.isPistonWater(i2, world.e(i1, j1, k1));
mod_NWater.dealWithPistonWater(world, dealingWith, l, i1, j1, k1);
dealingB = true;
}
if (i2 == 0)
{
break;
}

if (!a(i2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[i2].h() == 1)
{
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
return true;
}

private boolean i(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int j2 = world.a(i1, j1, k1);
if (j2 == 0)
{
break;
}
if (!a(j2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[j2].h() == 1)
{
uu.m[j2].g(world, i1, j1, k1, world.e(i1, j1, k1));
world.f(i1, j1, k1, 0);
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
int l2;
for (; (i1 != i) || (j1 != j) || (k1 != k); k1 = l2)
{
int i2 = i1 - wj.b[l];
int k2 = j1 - wj.c[l];
l2 = k1 - wj.d[l];
int i3 = world.a(i2, k2, l2);
int j3 = world.e(i2, k2, l2);
if ((i3 == this.bn) && (i2 == i) && (k2 == j) && (l2 == k))
{
world.a(i1, j1, k1, uu.ad.bn, l | (this.a ? 8 : 0));
world.a(i1, j1, k1, ut.a(uu.ab.bn, l | (this.a ? 8 : 0), l, true, false));
}
else {
world.a(i1, j1, k1, uu.ad.bn, j3);
world.a(i1, j1, k1, ut.a(i3, j3, l, true, false));
}
i1 = i2;
j1 = k2;
}

return true;
}
}
import java.util.ArrayList;
import java.util.Random;

public class jq extends uu
{
private static int dealingWith;
private static boolean dealingB;
private boolean a;
private boolean b;

public jq(int i, int j, boolean flag)
{
super(i, j, ln.B);
this.a = flag;
a(h);
c(0.5F);
}

public int i()
{
return !this.a ? 107 : 106;
}

public int a(int i, int j)
{
int k = d(j);
if (k > 5)
{
return this.bm;
}
if (i == k)
{
if ((e(j)) || (this.bs > 0.0D) || (this.bt > 0.0D) || (this.bu > 0.0D) || (this.bv < 1.0D) || (this.bw < 1.0D) || (this.bx < 1.0D))
{
return 110;
}

return this.bm;
}

return i != wj.a[k] ? 108 : 109;
}

public int b()
{
return 16;
}

public boolean c()
{
return false;
}

public boolean a(fd world, int i, int j, int k, gs entityplayer)
{
return false;
}

public void a(fd world, int i, int j, int k, ls entityliving)
{
int l = c(world, i, j, k, (gs)entityliving);
world.d(i, j, k, l);
if (!world.B)
{
h(world, i, j, k);
}
}

public void b(fd world, int i, int j, int k, int l)
{
if ((!world.B) && (!this.B))
{
dealingB = false;
h(world, i, j, k);
dealingB = true;
}
}

public void c(fd world, int i, int j, int k)
{
if ((!world.B) && (world.b(i, j, k) == null))
{
h(world, i, j, k);
}
}

private void h(fd world, int i, int j, int k)
{
int l = world.e(i, j, k);
int i1 = d(l);
boolean flag = f(world, i, j, k, i1);
if (l == 7)
{
return;
}
if ((flag) && (!e(l)))
{
if (h(world, i, j, k, i1))
{
world.e(i, j, k, i1 | 0x8 );
world.d(i, j, k, 0, i1);
}
}
else if ((!flag) && (e(l)))
{
world.e(i, j, k, i1);
world.d(i, j, k, 1, i1);
}
}

private boolean f(fd world, int i, int j, int k, int l)
{
if ((l != 0) && (world.k(i, j - 1, k, 0)))
{
return true;
}
if ((l != 1) && (world.k(i, j + 1, k, 1)))
{
return true;
}
if ((l != 2) && (world.k(i, j, k - 1, 2)))
{
return true;
}
if ((l != 3) && (world.k(i, j, k + 1, 3)))
{
return true;
}
if ((l != 5) && (world.k(i + 1, j, k, 5)))
{
return true;
}
if ((l != 4) && (world.k(i - 1, j, k, 4)))
{
return true;
}
if (world.k(i, j, k, 0))
{
return true;
}
if (world.k(i, j + 2, k, 1))
{
return true;
}
if (world.k(i, j + 1, k - 1, 2))
{
return true;
}
if (world.k(i, j + 1, k + 1, 3))
{
return true;
}
if (world.k(i - 1, j + 1, k, 4))
{
return true;
}
return world.k(i + 1, j + 1, k, 5);
}

public void a(fd world, int i, int j, int k, int l, int i1)
{
this.b = true;
int j1 = i1;
if (l == 0)
{
if (i(world, i, j, k, j1))
{
world.d(i, j, k, j1 | 0x8 );
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.out", 0.5F, world.r.nextFloat() * 0.25F + 0.6F);
}
}
else if (l == 1)
{
ow tileentity = world.b(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1]);
if ((tileentity != null) && ((tileentity instanceof uk)))
{
((uk)tileentity).l();
}
world.a(i, j, k, uu.ad.bn, j1);
world.a(i, j, k, ut.a(this.bn, j1, j1, false, true));
if (this.a)
{
int k1 = i + wj.b[j1] * 2;
int l1 = j + wj.c[j1] * 2;
int i2 = k + wj.d[j1] * 2;
int j2 = world.a(k1, l1, i2);
int k2 = world.e(k1, l1, i2);
boolean flag = false;
if (j2 == uu.ad.bn)
{
ow tileentity1 = world.b(k1, l1, i2);
if ((tileentity1 != null) && ((tileentity1 instanceof uk)))
{
uk tileentitypiston = (uk)tileentity1;
if ((tileentitypiston.d() == j1) && (tileentitypiston.b()))
{
tileentitypiston.l();
j2 = tileentitypiston.a();
k2 = tileentitypiston.e();
flag = true;
}
}
}
if ((!flag) && (j2 > 0) && (a(j2, world, k1, l1, i2, false)) && ((uu.m[j2].h() == 0) || (j2 == uu.aa.bn) || (j2 == uu.W.bn)))
{
this.b = false;
world.f(k1, l1, i2, 0);
this.b = true;
i += wj.b[j1];
j += wj.c[j1];
k += wj.d[j1];
world.a(i, j, k, uu.ad.bn, k2);
world.a(i, j, k, ut.a(j2, k2, j1, false, false));
}
else if (!flag)
{
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
}
else {
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.in", 0.5F, world.r.nextFloat() * 0.15F + 0.6F);
}
this.b = false;
}

public void a(xp iblockaccess, int i, int j, int k)
{
int l = iblockaccess.e(i, j, k);
if (e(l))
{
switch (d(l))
{
case 0:
a(0.0F, 0.25F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 1:
a(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F);
break;
case 2:
a(0.0F, 0.0F, 0.25F, 1.0F, 1.0F, 1.0F);
break;
case 3:
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.75F);
break;
case 4:
a(0.25F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 5:
a(0.0F, 0.0F, 0.0F, 0.75F, 1.0F, 1.0F);
}
}
else
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
}

public void g()
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}

public void a(fd world, int i, int j, int k, eq axisalignedbb, ArrayList arraylist)
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
super.a(world, i, j, k, axisalignedbb, arraylist);
}

public boolean d()
{
return false;
}

public static int d(int i)
{
return i & 0x7;
}

public static boolean e(int i)
{
return (i & 0x8 ) != 0;
}

private static int c(fd world, int i, int j, int k, gs entityplayer)
{
if ((in.e((float)entityplayer.aM - i) < 2.0F) && (in.e((float)entityplayer.aO - k) < 2.0F))
{
double d = entityplayer.aN + 1.82D - entityplayer.bf;
if (d - j > 2.0D)
{
return 1;
}
if (j - d > 0.0D)
{
return 0;
}
}
int l = in.b(entityplayer.aS * 4.0F / 360.0F + 0.5D) & 0x3;
if (l == 0)
{
return 2;
}
if (l == 1)
{
return 5;
}
if (l == 2)
{
return 3;
}
return l != 3 ? 0 : 4;
}

private static boolean a(int i, fd world, int j, int k, int l, boolean flag)
{
if (i == uu.aq.bn)
{
return false;
}
if ((i == uu.aa.bn) || (i == uu.W.bn))
{
if (e(world.e(j, k, l)))
{
return false;
}
}
else {
if (uu.m[i].m() == -1.0F)
{
return false;
}
if (uu.m[i].h() == 2)
{
return false;
}
if ((!flag) && (uu.m[i].h() == 1))
{
return false;
}
}
ow tileentity = world.b(j, k, l);
return tileentity == null;
}

private static boolean h(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int i2 = world.a(i1, j1, k1);

if (!dealingB)
{
dealingWith = mod_NWater.isPistonWater(i2, world.e(i1, j1, k1));
mod_NWater.dealWithPistonWater(world, dealingWith, l, i1, j1, k1);
dealingB = true;
}
if (i2 == 0)
{
break;
}

if (!a(i2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[i2].h() == 1)
{
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
return true;
}

private boolean i(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int j2 = world.a(i1, j1, k1);
if (j2 == 0)
{
break;
}
if (!a(j2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[j2].h() == 1)
{
uu.m[j2].g(world, i1, j1, k1, world.e(i1, j1, k1));
world.f(i1, j1, k1, 0);
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
int l2;
for (; (i1 != i) || (j1 != j) || (k1 != k); k1 = l2)
{
int i2 = i1 - wj.b[l];
int k2 = j1 - wj.c[l];
l2 = k1 - wj.d[l];
int i3 = world.a(i2, k2, l2);
int j3 = world.e(i2, k2, l2);
if ((i3 == this.bn) && (i2 == i) && (k2 == j) && (l2 == k))
{
world.a(i1, j1, k1, uu.ad.bn, l | (this.a ? 8 : 0));
world.a(i1, j1, k1, ut.a(uu.ab.bn, l | (this.a ? 8 : 0), l, true, false));
}
else {
world.a(i1, j1, k1, uu.ad.bn, j3);
world.a(i1, j1, k1, ut.a(i3, j3, l, true, false));
}
i1 = i2;
j1 = k2;
}

return true;
}
}
import java.util.ArrayList;
import java.util.Random;

public class jq extends uu
{
private static int dealingWith;
private static boolean dealingB;
private boolean a;
private boolean b;

public jq(int i, int j, boolean flag)
{
super(i, j, ln.B);
this.a = flag;
a(h);
c(0.5F);
}

public int i()
{
return !this.a ? 107 : 106;
}

public int a(int i, int j)
{
int k = d(j);
if (k > 5)
{
return this.bm;
}
if (i == k)
{
if ((e(j)) || (this.bs > 0.0D) || (this.bt > 0.0D) || (this.bu > 0.0D) || (this.bv < 1.0D) || (this.bw < 1.0D) || (this.bx < 1.0D))
{
return 110;
}

return this.bm;
}

return i != wj.a[k] ? 108 : 109;
}

public int b()
{
return 16;
}

public boolean c()
{
return false;
}

public boolean a(fd world, int i, int j, int k, gs entityplayer)
{
return false;
}

public void a(fd world, int i, int j, int k, ls entityliving)
{
int l = c(world, i, j, k, (gs)entityliving);
world.d(i, j, k, l);
if (!world.B)
{
h(world, i, j, k);
}
}

public void b(fd world, int i, int j, int k, int l)
{
if ((!world.B) && (!this.B))
{
dealingB = false;
h(world, i, j, k);
dealingB = true;
}
}

public void c(fd world, int i, int j, int k)
{
if ((!world.B) && (world.b(i, j, k) == null))
{
h(world, i, j, k);
}
}

private void h(fd world, int i, int j, int k)
{
int l = world.e(i, j, k);
int i1 = d(l);
boolean flag = f(world, i, j, k, i1);
if (l == 7)
{
return;
}
if ((flag) && (!e(l)))
{
if (h(world, i, j, k, i1))
{
world.e(i, j, k, i1 | 0x8 );
world.d(i, j, k, 0, i1);
}
}
else if ((!flag) && (e(l)))
{
world.e(i, j, k, i1);
world.d(i, j, k, 1, i1);
}
}

private boolean f(fd world, int i, int j, int k, int l)
{
if ((l != 0) && (world.k(i, j - 1, k, 0)))
{
return true;
}
if ((l != 1) && (world.k(i, j + 1, k, 1)))
{
return true;
}
if ((l != 2) && (world.k(i, j, k - 1, 2)))
{
return true;
}
if ((l != 3) && (world.k(i, j, k + 1, 3)))
{
return true;
}
if ((l != 5) && (world.k(i + 1, j, k, 5)))
{
return true;
}
if ((l != 4) && (world.k(i - 1, j, k, 4)))
{
return true;
}
if (world.k(i, j, k, 0))
{
return true;
}
if (world.k(i, j + 2, k, 1))
{
return true;
}
if (world.k(i, j + 1, k - 1, 2))
{
return true;
}
if (world.k(i, j + 1, k + 1, 3))
{
return true;
}
if (world.k(i - 1, j + 1, k, 4))
{
return true;
}
return world.k(i + 1, j + 1, k, 5);
}

public void a(fd world, int i, int j, int k, int l, int i1)
{
this.b = true;
int j1 = i1;
if (l == 0)
{
if (i(world, i, j, k, j1))
{
world.d(i, j, k, j1 | 0x8 );
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.out", 0.5F, world.r.nextFloat() * 0.25F + 0.6F);
}
}
else if (l == 1)
{
ow tileentity = world.b(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1]);
if ((tileentity != null) && ((tileentity instanceof uk)))
{
((uk)tileentity).l();
}
world.a(i, j, k, uu.ad.bn, j1);
world.a(i, j, k, ut.a(this.bn, j1, j1, false, true));
if (this.a)
{
int k1 = i + wj.b[j1] * 2;
int l1 = j + wj.c[j1] * 2;
int i2 = k + wj.d[j1] * 2;
int j2 = world.a(k1, l1, i2);
int k2 = world.e(k1, l1, i2);
boolean flag = false;
if (j2 == uu.ad.bn)
{
ow tileentity1 = world.b(k1, l1, i2);
if ((tileentity1 != null) && ((tileentity1 instanceof uk)))
{
uk tileentitypiston = (uk)tileentity1;
if ((tileentitypiston.d() == j1) && (tileentitypiston.b()))
{
tileentitypiston.l();
j2 = tileentitypiston.a();
k2 = tileentitypiston.e();
flag = true;
}
}
}
if ((!flag) && (j2 > 0) && (a(j2, world, k1, l1, i2, false)) && ((uu.m[j2].h() == 0) || (j2 == uu.aa.bn) || (j2 == uu.W.bn)))
{
this.b = false;
world.f(k1, l1, i2, 0);
this.b = true;
i += wj.b[j1];
j += wj.c[j1];
k += wj.d[j1];
world.a(i, j, k, uu.ad.bn, k2);
world.a(i, j, k, ut.a(j2, k2, j1, false, false));
}
else if (!flag)
{
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
}
else {
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.in", 0.5F, world.r.nextFloat() * 0.15F + 0.6F);
}
this.b = false;
}

public void a(xp iblockaccess, int i, int j, int k)
{
int l = iblockaccess.e(i, j, k);
if (e(l))
{
switch (d(l))
{
case 0:
a(0.0F, 0.25F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 1:
a(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F);
break;
case 2:
a(0.0F, 0.0F, 0.25F, 1.0F, 1.0F, 1.0F);
break;
case 3:
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.75F);
break;
case 4:
a(0.25F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 5:
a(0.0F, 0.0F, 0.0F, 0.75F, 1.0F, 1.0F);
}
}
else
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
}

public void g()
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}

public void a(fd world, int i, int j, int k, eq axisalignedbb, ArrayList arraylist)
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
super.a(world, i, j, k, axisalignedbb, arraylist);
}

public boolean d()
{
return false;
}

public static int d(int i)
{
return i & 0x7;
}

public static boolean e(int i)
{
return (i & 0x8 ) != 0;
}

private static int c(fd world, int i, int j, int k, gs entityplayer)
{
if ((in.e((float)entityplayer.aM - i) < 2.0F) && (in.e((float)entityplayer.aO - k) < 2.0F))
{
double d = entityplayer.aN + 1.82D - entityplayer.bf;
if (d - j > 2.0D)
{
return 1;
}
if (j - d > 0.0D)
{
return 0;
}
}
int l = in.b(entityplayer.aS * 4.0F / 360.0F + 0.5D) & 0x3;
if (l == 0)
{
return 2;
}
if (l == 1)
{
return 5;
}
if (l == 2)
{
return 3;
}
return l != 3 ? 0 : 4;
}

private static boolean a(int i, fd world, int j, int k, int l, boolean flag)
{
if (i == uu.aq.bn)
{
return false;
}
if ((i == uu.aa.bn) || (i == uu.W.bn))
{
if (e(world.e(j, k, l)))
{
return false;
}
}
else {
if (uu.m[i].m() == -1.0F)
{
return false;
}
if (uu.m[i].h() == 2)
{
return false;
}
if ((!flag) && (uu.m[i].h() == 1))
{
return false;
}
}
ow tileentity = world.b(j, k, l);
return tileentity == null;
}

private static boolean h(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int i2 = world.a(i1, j1, k1);

if (!dealingB)
{
dealingWith = mod_NWater.isPistonWater(i2, world.e(i1, j1, k1));
mod_NWater.dealWithPistonWater(world, dealingWith, l, i1, j1, k1);
dealingB = true;
}
if (i2 == 0)
{
break;
}

if (!a(i2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[i2].h() == 1)
{
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
return true;
}

private boolean i(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int j2 = world.a(i1, j1, k1);
if (j2 == 0)
{
break;
}
if (!a(j2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[j2].h() == 1)
{
uu.m[j2].g(world, i1, j1, k1, world.e(i1, j1, k1));
world.f(i1, j1, k1, 0);
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
int l2;
for (; (i1 != i) || (j1 != j) || (k1 != k); k1 = l2)
{
int i2 = i1 - wj.b[l];
int k2 = j1 - wj.c[l];
l2 = k1 - wj.d[l];
int i3 = world.a(i2, k2, l2);
int j3 = world.e(i2, k2, l2);
if ((i3 == this.bn) && (i2 == i) && (k2 == j) && (l2 == k))
{
world.a(i1, j1, k1, uu.ad.bn, l | (this.a ? 8 : 0));
world.a(i1, j1, k1, ut.a(uu.ab.bn, l | (this.a ? 8 : 0), l, true, false));
}
else {
world.a(i1, j1, k1, uu.ad.bn, j3);
world.a(i1, j1, k1, ut.a(i3, j3, l, true, false));
}
i1 = i2;
j1 = k2;
}

return true;
}
}
import java.util.ArrayList;
import java.util.Random;

public class jq extends uu
{
private static int dealingWith;
private static boolean dealingB;
private boolean a;
private boolean b;

public jq(int i, int j, boolean flag)
{
super(i, j, ln.B);
this.a = flag;
a(h);
c(0.5F);
}

public int i()
{
return !this.a ? 107 : 106;
}

public int a(int i, int j)
{
int k = d(j);
if (k > 5)
{
return this.bm;
}
if (i == k)
{
if ((e(j)) || (this.bs > 0.0D) || (this.bt > 0.0D) || (this.bu > 0.0D) || (this.bv < 1.0D) || (this.bw < 1.0D) || (this.bx < 1.0D))
{
return 110;
}

return this.bm;
}

return i != wj.a[k] ? 108 : 109;
}

public int b()
{
return 16;
}

public boolean c()
{
return false;
}

public boolean a(fd world, int i, int j, int k, gs entityplayer)
{
return false;
}

public void a(fd world, int i, int j, int k, ls entityliving)
{
int l = c(world, i, j, k, (gs)entityliving);
world.d(i, j, k, l);
if (!world.B)
{
h(world, i, j, k);
}
}

public void b(fd world, int i, int j, int k, int l)
{
if ((!world.B) && (!this.B))
{
dealingB = false;
h(world, i, j, k);
dealingB = true;
}
}

public void c(fd world, int i, int j, int k)
{
if ((!world.B) && (world.b(i, j, k) == null))
{
h(world, i, j, k);
}
}

private void h(fd world, int i, int j, int k)
{
int l = world.e(i, j, k);
int i1 = d(l);
boolean flag = f(world, i, j, k, i1);
if (l == 7)
{
return;
}
if ((flag) && (!e(l)))
{
if (h(world, i, j, k, i1))
{
world.e(i, j, k, i1 | 0x8 );
world.d(i, j, k, 0, i1);
}
}
else if ((!flag) && (e(l)))
{
world.e(i, j, k, i1);
world.d(i, j, k, 1, i1);
}
}

private boolean f(fd world, int i, int j, int k, int l)
{
if ((l != 0) && (world.k(i, j - 1, k, 0)))
{
return true;
}
if ((l != 1) && (world.k(i, j + 1, k, 1)))
{
return true;
}
if ((l != 2) && (world.k(i, j, k - 1, 2)))
{
return true;
}
if ((l != 3) && (world.k(i, j, k + 1, 3)))
{
return true;
}
if ((l != 5) && (world.k(i + 1, j, k, 5)))
{
return true;
}
if ((l != 4) && (world.k(i - 1, j, k, 4)))
{
return true;
}
if (world.k(i, j, k, 0))
{
return true;
}
if (world.k(i, j + 2, k, 1))
{
return true;
}
if (world.k(i, j + 1, k - 1, 2))
{
return true;
}
if (world.k(i, j + 1, k + 1, 3))
{
return true;
}
if (world.k(i - 1, j + 1, k, 4))
{
return true;
}
return world.k(i + 1, j + 1, k, 5);
}

public void a(fd world, int i, int j, int k, int l, int i1)
{
this.b = true;
int j1 = i1;
if (l == 0)
{
if (i(world, i, j, k, j1))
{
world.d(i, j, k, j1 | 0x8 );
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.out", 0.5F, world.r.nextFloat() * 0.25F + 0.6F);
}
}
else if (l == 1)
{
ow tileentity = world.b(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1]);
if ((tileentity != null) && ((tileentity instanceof uk)))
{
((uk)tileentity).l();
}
world.a(i, j, k, uu.ad.bn, j1);
world.a(i, j, k, ut.a(this.bn, j1, j1, false, true));
if (this.a)
{
int k1 = i + wj.b[j1] * 2;
int l1 = j + wj.c[j1] * 2;
int i2 = k + wj.d[j1] * 2;
int j2 = world.a(k1, l1, i2);
int k2 = world.e(k1, l1, i2);
boolean flag = false;
if (j2 == uu.ad.bn)
{
ow tileentity1 = world.b(k1, l1, i2);
if ((tileentity1 != null) && ((tileentity1 instanceof uk)))
{
uk tileentitypiston = (uk)tileentity1;
if ((tileentitypiston.d() == j1) && (tileentitypiston.b()))
{
tileentitypiston.l();
j2 = tileentitypiston.a();
k2 = tileentitypiston.e();
flag = true;
}
}
}
if ((!flag) && (j2 > 0) && (a(j2, world, k1, l1, i2, false)) && ((uu.m[j2].h() == 0) || (j2 == uu.aa.bn) || (j2 == uu.W.bn)))
{
this.b = false;
world.f(k1, l1, i2, 0);
this.b = true;
i += wj.b[j1];
j += wj.c[j1];
k += wj.d[j1];
world.a(i, j, k, uu.ad.bn, k2);
world.a(i, j, k, ut.a(j2, k2, j1, false, false));
}
else if (!flag)
{
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
}
else {
this.b = false;
world.f(i + wj.b[j1], j + wj.c[j1], k + wj.d[j1], 0);
this.b = true;
}
world.a(i + 0.5D, j + 0.5D, k + 0.5D, "tile.piston.in", 0.5F, world.r.nextFloat() * 0.15F + 0.6F);
}
this.b = false;
}

public void a(xp iblockaccess, int i, int j, int k)
{
int l = iblockaccess.e(i, j, k);
if (e(l))
{
switch (d(l))
{
case 0:
a(0.0F, 0.25F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 1:
a(0.0F, 0.0F, 0.0F, 1.0F, 0.75F, 1.0F);
break;
case 2:
a(0.0F, 0.0F, 0.25F, 1.0F, 1.0F, 1.0F);
break;
case 3:
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.75F);
break;
case 4:
a(0.25F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
break;
case 5:
a(0.0F, 0.0F, 0.0F, 0.75F, 1.0F, 1.0F);
}
}
else
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
}

public void g()
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}

public void a(fd world, int i, int j, int k, eq axisalignedbb, ArrayList arraylist)
{
a(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
super.a(world, i, j, k, axisalignedbb, arraylist);
}

public boolean d()
{
return false;
}

public static int d(int i)
{
return i & 0x7;
}

public static boolean e(int i)
{
return (i & 0x8 ) != 0;
}

private static int c(fd world, int i, int j, int k, gs entityplayer)
{
if ((in.e((float)entityplayer.aM - i) < 2.0F) && (in.e((float)entityplayer.aO - k) < 2.0F))
{
double d = entityplayer.aN + 1.82D - entityplayer.bf;
if (d - j > 2.0D)
{
return 1;
}
if (j - d > 0.0D)
{
return 0;
}
}
int l = in.b(entityplayer.aS * 4.0F / 360.0F + 0.5D) & 0x3;
if (l == 0)
{
return 2;
}
if (l == 1)
{
return 5;
}
if (l == 2)
{
return 3;
}
return l != 3 ? 0 : 4;
}

private static boolean a(int i, fd world, int j, int k, int l, boolean flag)
{
if (i == uu.aq.bn)
{
return false;
}
if ((i == uu.aa.bn) || (i == uu.W.bn))
{
if (e(world.e(j, k, l)))
{
return false;
}
}
else {
if (uu.m[i].m() == -1.0F)
{
return false;
}
if (uu.m[i].h() == 2)
{
return false;
}
if ((!flag) && (uu.m[i].h() == 1))
{
return false;
}
}
ow tileentity = world.b(j, k, l);
return tileentity == null;
}

private static boolean h(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int i2 = world.a(i1, j1, k1);

if (!dealingB)
{
dealingWith = mod_NWater.isPistonWater(i2, world.e(i1, j1, k1));
mod_NWater.dealWithPistonWater(world, dealingWith, l, i1, j1, k1);
dealingB = true;
}
if (i2 == 0)
{
break;
}

if (!a(i2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[i2].h() == 1)
{
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
return true;
}

private boolean i(fd world, int i, int j, int k, int l)
{
int i1 = i + wj.b[l];
int j1 = j + wj.c[l];
int k1 = k + wj.d[l];
int l1 = 0;

while (l1 < 13)
{
if ((j1 <= 0) || (j1 >= 127))
{
return false;
}
int j2 = world.a(i1, j1, k1);
if (j2 == 0)
{
break;
}
if (!a(j2, world, i1, j1, k1, true))
{
return false;
}
if (uu.m[j2].h() == 1)
{
uu.m[j2].g(world, i1, j1, k1, world.e(i1, j1, k1));
world.f(i1, j1, k1, 0);
break;
}
if (l1 == 12)
{
return false;
}
i1 += wj.b[l];
j1 += wj.c[l];
k1 += wj.d[l];
l1++;
}
int l2;
for (; (i1 != i) || (j1 != j) || (k1 != k); k1 = l2)
{
int i2 = i1 - wj.b[l];
int k2 = j1 - wj.c[l];
l2 = k1 - wj.d[l];
int i3 = world.a(i2, k2, l2);
int j3 = world.e(i2, k2, l2);
if ((i3 == this.bn) && (i2 == i) && (k2 == j) && (l2 == k))
{
world.a(i1, j1, k1, uu.ad.bn, l | (this.a ? 8 : 0));
world.a(i1, j1, k1, ut.a(uu.ab.bn, l | (this.a ? 8 : 0), l, true, false));
}
else {
world.a(i1, j1, k1, uu.ad.bn, j3);
world.a(i1, j1, k1, ut.a(i3, j3, l, true, false));
}
i1 = i2;
j1 = k2;
}

return true;
}
}
import java.util.Random;

public class jd
implements cl
{
private Random j;
private uf k;
private uf l;
private uf m;
private uf n;
private uf o;
public uf a;
public uf b;
public uf c;
private fd worldObj;
private double[] q;
private double[] r;
private double[] s;
private double[] t;
private fv u;
private kd[] v;
double[] d;
double[] e;
double[] f;
double[] g;
double[] h;
int[][] i;
private double[] w;

public jd(fd world, long l)
{
this.r = new double[256];
this.s = new double[256];
this.t = new double[256];
this.u = new sq();
this.i = new int[32][32];
this.worldObj = world;
this.j = new Random(l);
this.k = new uf(this.j, 16);
this.l = new uf(this.j, 16);
this.m = new uf(this.j, 8 );
this.n = new uf(this.j, 4);
this.o = new uf(this.j, 4);
this.a = new uf(this.j, 10);
this.b = new uf(this.j, 16);
this.c = new uf(this.j, 8 );
}

public void a(int i, int j, byte[] abyte0, kd[] abiomegenbase, double[] ad)
{
byte byte0 = 2;
int k = byte0 + 1;
byte byte1 = 33;
int l = byte0 + 1;
this.q = a(this.q, i * byte0, 0, j * byte0, k, byte1, l);
for (int i1 = 0; i1 < byte0; i1++)
{
for (int j1 = 0; j1 < byte0; j1++)
{
for (int k1 = 0; k1 < 32; k1++)
{
double d = 0.25D;
double d1 = this.q[(((i1 + 0) * l + (j1 + 0)) * byte1 + (k1 + 0))];
double d2 = this.q[(((i1 + 0) * l + (j1 + 1)) * byte1 + (k1 + 0))];
double d3 = this.q[(((i1 + 1) * l + (j1 + 0)) * byte1 + (k1 + 0))];
double d4 = this.q[(((i1 + 1) * l + (j1 + 1)) * byte1 + (k1 + 0))];
double d5 = (this.q[(((i1 + 0) * l + (j1 + 0)) * byte1 + (k1 + 1))] - d1) * d;
double d6 = (this.q[(((i1 + 0) * l + (j1 + 1)) * byte1 + (k1 + 1))] - d2) * d;
double d7 = (this.q[(((i1 + 1) * l + (j1 + 0)) * byte1 + (k1 + 1))] - d3) * d;
double d8 = (this.q[(((i1 + 1) * l + (j1 + 1)) * byte1 + (k1 + 1))] - d4) * d;
for (int l1 = 0; l1 < 4; l1++)
{
double d9 = 0.125D;
double d10 = d1;
double d11 = d2;
double d12 = (d3 - d1) * d9;
double d13 = (d4 - d2) * d9;
for (int i2 = 0; i2 < 8; i2++)
{
int j2 = i2 + i1 * 8 << 11 | 0 + j1 * 8 << 7 | k1 * 4 + l1;
char c = '€';
double d14 = 0.125D;
double d15 = d10;
double d16 = (d11 - d10) * d14;
for (int k2 = 0; k2 < 8; k2++)
{
int l2 = 0;
if (d15 > 0.0D)
{
l2 = uu.u.bn;
}
abyte0[j2] = (byte)l2;
j2 += c;
d15 += d16;
}

d10 += d12;
d11 += d13;
}

d1 += d5;
d2 += d6;
d3 += d7;
d4 += d8;
}
}
}
}
}

public void a(int i, int j, byte[] abyte0, kd[] abiomegenbase)
{
double d = 0.03125D;
this.r = this.n.a(this.r, i * 16, j * 16, 0.0D, 16, 16, 1, d, d, 1.0D);
this.s = this.n.a(this.s, i * 16, 109.0134D, j * 16, 16, 1, 16, d, 1.0D, d);
this.t = this.o.a(this.t, i * 16, j * 16, 0.0D, 16, 16, 1, d * 2.0D, d * 2.0D, d * 2.0D);
for (int k = 0; k < 16; k++)
{
for (int l = 0; l < 16; l++)
{
kd biomegenbase = abiomegenbase[(k + l * 16)];
int i1 = (int)(this.t[(k + l * 16)] / 3.0D + 3.0D + this.j.nextDouble() * 0.25D);
int j1 = -1;
byte byte0 = biomegenbase.p;
byte byte1 = biomegenbase.q;
for (int k1 = 127; k1 >= 0; k1--)
{
int l1 = (l * 16 + k) * 128 + k1;
byte byte2 = abyte0[l1];
if (byte2 == 0)
{
j1 = -1;
}
else {
if (byte2 != uu.u.bn)
{
continue;
}
if (j1 == -1)
{
if (i1 <= 0)
{
byte0 = 0;
byte1 = (byte)uu.u.bn;
}
j1 = i1;
if (k1 >= 0)
{
abyte0[l1] = byte0;
}
else
abyte0[l1] = byte1;
}
else
{
if (j1 <= 0)
{
continue;
}
j1--;
abyte0[l1] = byte1;
if ((j1 != 0) || (byte1 != uu.F.bn))
continue;
j1 = this.j.nextInt(4);
byte1 = (byte)uu.R.bn;
}
}
}
}
}
}

public lm c(int i, int j)
{
return b(i, j);
}

public ChunkCube prepareCube(int i, int y, int j) {
return provideCube(i, y, j);
}

public ChunkCube provideCube(int x, int y, int z)
{
lm chunk = this.worldObj.c(x, z);

if ((chunk == null) || (chunk.p))
{
chunk = b(x, y);
}

if ((y < 0) || (y >= 8 ))
{
byte[] data = new byte[4096];

ChunkCube cube = new ChunkCube(chunk, data, y + 128 );
cube.isAir = true;
cube.isChunkLoaded = true;
chunk.cubes[(y + 128 )] = cube;
for (int n = 0; n < cube.skylightMap.a.length; n++)
{
cube.skylightMap.a[n] = -1;
}
return cube;
}

chunk.c();
return chunk.cubes[(y + 128 )];
}

public lm b(int i, int j)
{
this.j.setSeed(i * 341873128712L + j * 132897987541L);
byte[] data = new byte[32768];
this.v = this.worldObj.a().a(this.v, i * 16, j * 16, 16, 16);
double[] ad = this.worldObj.a().a;
a(i, j, data, this.v, ad);
a(i, j, data, this.v);
this.u.a(this, this.worldObj, i, j, data);

lm chunk = new lm(this.worldObj, data, i, j);

chunk.c();
return chunk;
}

private double[] a(double[] ad, int i, int j, int k, int l, int i1, int j1)
{
if (ad == null)
{
ad = new double[l * i1 * j1];
}
double d = 684.41200000000003D;
double d1 = 684.41200000000003D;
double[] ad1 = this.worldObj.a().a;
double[] ad2 = this.worldObj.a().b;
this.g = this.a.a(this.g, i, k, l, j1, 1.121D, 1.121D, 0.5D);
this.h = this.b.a(this.h, i, k, l, j1, 200.0D, 200.0D, 0.5D);
d *= 2.0D;
this.d = this.m.a(this.d, i, j, k, l, i1, j1, d / 80.0D, d1 / 160.0D, d / 80.0D);
this.e = this.k.a(this.e, i, j, k, l, i1, j1, d, d1, d);
this.f = this.l.a(this.f, i, j, k, l, i1, j1, d, d1, d);
int k1 = 0;
int l1 = 0;
int i2 = 16 / l;
for (int j2 = 0; j2 < l; j2++)
{
int k2 = j2 * i2 + i2 / 2;
for (int l2 = 0; l2 < j1; l2++)
{
int i3 = l2 * i2 + i2 / 2;
double d2 = ad1[(k2 * 16 + i3)];
double d3 = ad2[(k2 * 16 + i3)] * d2;
double d4 = 1.0D - d3;
d4 *= d4;
d4 *= d4;
d4 = 1.0D - d4;
double d5 = (this.g[l1] + 256.0D) / 512.0D;
d5 *= d4;
if (d5 > 1.0D)
{
d5 = 1.0D;
}
double d6 = this.h[l1] / 8000.0D;
if (d6 < 0.0D)
{
d6 = -d6 * 0.3D;
}
d6 = d6 * 3.0D - 2.0D;
if (d6 > 1.0D)
{
d6 = 1.0D;
}
d6 /= 8.0D;
d6 = 0.0D;
if (d5 < 0.0D)
{
d5 = 0.0D;
}
d5 += 0.5D;
d6 = d6 * i1 / 16.0D;
l1++;
double d7 = i1 / 2.0D;
for (int j3 = 0; j3 < i1; j3++)
{
double d8 = 0.0D;
double d9 = (j3 - d7) * 8.0D / d5;
if (d9 < 0.0D)
{
d9 *= -1.0D;
}
double d10 = this.e[k1] / 512.0D;
double d11 = this.f[k1] / 512.0D;
double d12 = (this.d[k1] / 10.0D + 1.0D) / 2.0D;
if (d12 < 0.0D)
{
d8 = d10;
}
else if (d12 > 1.0D)
{
d8 = d11;
}
else {
d8 = d10 + (d11 - d10) * d12;
}
d8 -= 8.0D;
int k3 = 32;
if (j3 > i1 - k3)
{
double d13 = (j3 - (i1 - k3)) / (k3 - 1.0F);
d8 = d8 * (1.0D - d13) + -30.0D * d13;
}
k3 = 8;
if (j3 < k3)
{
double d14 = (k3 - j3) / (k3 - 1.0F);
d8 = d8 * (1.0D - d14) + -30.0D * d14;
}
ad[k1] = d8;
k1++;
}

}

}

return ad;
}

public boolean a(int i, int j)
{
return true;
}

public boolean cubeExists(int i, int y, int j)
{
return true;
}

public void populate(cl ichunkprovider, int x, int y, int z)
{
}

public void a(cl ichunkprovider, int i, int j)
{
gk.a = true;
int k = i * 16;
int l = j * 16;
kd biomegenbase = this.worldObj.a().a(k + 16, l + 16);
this.j.setSeed(this.worldObj.s());
long l1 = this.j.nextLong() / 2L * 2L + 1L;
long l2 = this.j.nextLong() / 2L * 2L + 1L;
this.j.setSeed(i * l1 + j * l2 ^ this.worldObj.s());
double d = 0.25D;
if (this.j.nextInt(4) == 0)
{
int i1 = k + this.j.nextInt(16) + 8;
int l4 = this.j.nextInt(128 );
int i8 = l + this.j.nextInt(16) + 8;
new dj(uu.C.bn).a(this.worldObj, this.j, i1, l4, i8 );
}
if (this.j.nextInt(8 ) == 0)
{
int j1 = k + this.j.nextInt(16) + 8;
int i5 = this.j.nextInt(this.j.nextInt(120) + 8 );
int j8 = l + this.j.nextInt(16) + 8;
if ((i5 < 64) || (this.j.nextInt(10) == 0))
{
new dj(uu.E.bn).a(this.worldObj, this.j, j1, i5, j8 );
}
}
for (int k1 = 0; k1 < 8; k1++)
{
int j5 = k + this.j.nextInt(16) + 8;
int k8 = this.j.nextInt(128 );
int i13 = l + this.j.nextInt(16) + 8;
new er().a(this.worldObj, this.j, j5, k8, i13);
}

for (int i2 = 0; i2 < 10; i2++)
{
int k5 = k + this.j.nextInt(16);
int l8 = this.j.nextInt(128 );
int j13 = l + this.j.nextInt(16);
new ms(32).a(this.worldObj, this.j, k5, l8, j13);
}

for (int j2 = 0; j2 < 20; j2++)
{
int l5 = k + this.j.nextInt(16);
int i9 = this.j.nextInt(128 );
int k13 = l + this.j.nextInt(16);
new fl(uu.w.bn, 32).a(this.worldObj, this.j, l5, i9, k13);
}

for (int k2 = 0; k2 < 10; k2++)
{
int i6 = k + this.j.nextInt(16);
int j9 = this.j.nextInt(128 );
int l13 = l + this.j.nextInt(16);
new fl(uu.G.bn, 32).a(this.worldObj, this.j, i6, j9, l13);
}

for (int i3 = 0; i3 < 20; i3++)
{
int j6 = k + this.j.nextInt(16);
int k9 = this.j.nextInt(128 );
int i14 = l + this.j.nextInt(16);
new fl(uu.J.bn, 16).a(this.worldObj, this.j, j6, k9, i14);
}

for (int j3 = 0; j3 < 20; j3++)
{
int k6 = k + this.j.nextInt(16);
int l9 = this.j.nextInt(64);
int j14 = l + this.j.nextInt(16);
new fl(uu.I.bn, 8 ).a(this.worldObj, this.j, k6, l9, j14);
}

for (int k3 = 0; k3 < 2; k3++)
{
int l6 = k + this.j.nextInt(16);
int i10 = this.j.nextInt(32);
int k14 = l + this.j.nextInt(16);
new fl(uu.H.bn, 8 ).a(this.worldObj, this.j, l6, i10, k14);
}

for (int l3 = 0; l3 < 8; l3++)
{
int i7 = k + this.j.nextInt(16);
int j10 = this.j.nextInt(16);
int l14 = l + this.j.nextInt(16);
new fl(uu.aO.bn, 7).a(this.worldObj, this.j, i7, j10, l14);
}

for (int i4 = 0; i4 < 1; i4++)
{
int j7 = k + this.j.nextInt(16);
int k10 = this.j.nextInt(16);
int i15 = l + this.j.nextInt(16);
new fl(uu.ax.bn, 7).a(this.worldObj, this.j, j7, k10, i15);
}

for (int j4 = 0; j4 < 1; j4++)
{
int k7 = k + this.j.nextInt(16);
int l10 = this.j.nextInt(16) + this.j.nextInt(16);
int j15 = l + this.j.nextInt(16);
new fl(uu.O.bn, 6).a(this.worldObj, this.j, k7, l10, j15);
}

d = 0.5D;
int k4 = (int)((this.c.a(k * d, l * d) / 8.0D + this.j.nextDouble() * 4.0D + 4.0D) / 3.0D);
int l7 = 0;
if (this.j.nextInt(10) == 0)
{
l7++;
}
if (biomegenbase == kd.d)
{
l7 += k4 + 5;
}
if (biomegenbase == kd.a)
{
l7 += k4 + 5;
}
if (biomegenbase == kd.c)
{
l7 += k4 + 2;
}
if (biomegenbase == kd.g)
{
l7 += k4 + 5;
}
if (biomegenbase == kd.h)
{
l7 -= 20;
}
if (biomegenbase == kd.k)
{
l7 -= 20;
}
if (biomegenbase == kd.i)
{
l7 -= 20;
}
for (int i11 = 0; i11 < l7; i11++)
{
int k15 = k + this.j.nextInt(16) + 8;
int j18 = l + this.j.nextInt(16) + 8;
pg worldgenerator = biomegenbase.a(this.j);
worldgenerator.a(1.0D, 1.0D, 1.0D);
worldgenerator.a(this.worldObj, this.j, k15, this.worldObj.d(k15, j18 ), j18 );
}

for (int j11 = 0; j11 < 2; j11++)
{
int l15 = k + this.j.nextInt(16) + 8;
int k18 = this.j.nextInt(128 );
int i21 = l + this.j.nextInt(16) + 8;
new be(uu.ae.bn).a(this.worldObj, this.j, l15, k18, i21);
}

if (this.j.nextInt(2) == 0)
{
int k11 = k + this.j.nextInt(16) + 8;
int i16 = this.j.nextInt(128 );
int l18 = l + this.j.nextInt(16) + 8;
new be(uu.af.bn).a(this.worldObj, this.j, k11, i16, l18 );
}
if (this.j.nextInt(4) == 0)
{
int l11 = k + this.j.nextInt(16) + 8;
int j16 = this.j.nextInt(128 );
int i19 = l + this.j.nextInt(16) + 8;
new be(uu.ag.bn).a(this.worldObj, this.j, l11, j16, i19);
}
if (this.j.nextInt(8 ) == 0)
{
int i12 = k + this.j.nextInt(16) + 8;
int k16 = this.j.nextInt(128 );
int j19 = l + this.j.nextInt(16) + 8;
new be(uu.ah.bn).a(this.worldObj, this.j, i12, k16, j19);
}
for (int j12 = 0; j12 < 10; j12++)
{
int l16 = k + this.j.nextInt(16) + 8;
int k19 = this.j.nextInt(128 );
int j21 = l + this.j.nextInt(16) + 8;
new ir().a(this.worldObj, this.j, l16, k19, j21);
}

if (this.j.nextInt(32) == 0)
{
int k12 = k + this.j.nextInt(16) + 8;
int i17 = this.j.nextInt(128 );
int l19 = l + this.j.nextInt(16) + 8;
new wx().a(this.worldObj, this.j, k12, i17, l19);
}
int l12 = 0;
if (biomegenbase == kd.h)
{
l12 += 10;
}
for (int j17 = 0; j17 < l12; j17++)
{
int i20 = k + this.j.nextInt(16) + 8;
int k21 = this.j.nextInt(128 );
int k22 = l + this.j.nextInt(16) + 8;
new fx().a(this.worldObj, this.j, i20, k21, k22);
}

for (int k17 = 0; k17 < 50; k17++)
{
int j20 = k + this.j.nextInt(16) + 8;
int l21 = this.j.nextInt(this.j.nextInt(120) + 8 );
int l22 = l + this.j.nextInt(16) + 8;
new xo(uu.B.bn).a(this.worldObj, this.j, j20, l21, l22);
}

for (int l17 = 0; l17 < 20; l17++)
{
int k20 = k + this.j.nextInt(16) + 8;
int i22 = this.j.nextInt(this.j.nextInt(this.j.nextInt(112) + 8 ) + 8 );
int i23 = l + this.j.nextInt(16) + 8;
new xo(uu.D.bn).a(this.worldObj, this.j, k20, i22, i23);
}

this.w = this.worldObj.a().a(this.w, k + 8, l + 8, 16, 16);
for (int i18 = k + 8; i18 < k + 8 + 16; i18++)
{
for (int l20 = l + 8; l20 < l + 8 + 16; l20++)
{
int j22 = i18 - (k + 8 );
int j23 = l20 - (l + 8 );
int k23 = this.worldObj.e(i18, l20);
double d1 = this.w[(j22 * 16 + j23)] - (k23 - 64) / 64.0D * 0.3D;
if ((d1 >= 0.5D) || (k23 <= 0) || (k23 >= 128 ) || (!this.worldObj.d(i18, k23, l20)) || (!this.worldObj.f(i18, k23 - 1, l20).c()) || (this.worldObj.f(i18, k23 - 1, l20) == ln.s))
continue;
this.worldObj.f(i18, k23, l20, uu.aT.bn);
}

}

gk.a = false;
}

public boolean a(boolean flag, yb iprogressupdate)
{
return true;
}

public boolean a()
{
return false;
}

public boolean b()
{
return true;
}

public String c()
{
return "RandomLevelSource";
}
}
import java.util.Random;

public class jd
implements cl
{
private Random j;
private uf k;
private uf l;
private uf m;
private uf n;
private uf o;
public uf a;
public uf b;
public uf c;
private fd worldObj;
private double[] q;
private double[] r;
private double[] s;
private double[] t;
private fv u;
private kd[] v;
double[] d;
double[] e;
double[] f;
double[] g;
double[] h;
int[][] i;
private double[] w;

public jd(fd world, long l)
{
this.r = new double[256];
this.s = new double[256];
this.t = new double[256];
this.u = new sq();
this.i = new int[32][32];
this.worldObj = world;
this.j = new Random(l);
this.k = new uf(this.j, 16);
this.l = new uf(this.j, 16);
this.m = new uf(this.j, 8 );
this.n = new uf(this.j, 4);
this.o = new uf(this.j, 4);
this.a = new uf(this.j, 10);
this.b = new uf(this.j, 16);
this.c = new uf(this.j, 8 );
}

public void a(int i, int j, byte[] abyte0, kd[] abiomegenbase, double[] ad)
{
byte byte0 = 2;
int k = byte0 + 1;
byte byte1 = 33;
int l = byte0 + 1;
this.q = a(this.q, i * byte0, 0, j * byte0, k, byte1, l);
for (int i1 = 0; i1 < byte0; i1++)
{
for (int j1 = 0; j1 < byte0; j1++)
{
for (int k1 = 0; k1 < 32; k1++)
{
double d = 0.25D;
double d1 = this.q[(((i1 + 0) * l + (j1 + 0)) * byte1 + (k1 + 0))];
double d2 = this.q[(((i1 + 0) * l + (j1 + 1)) * byte1 + (k1 + 0))];
double d3 = this.q[(((i1 + 1) * l + (j1 + 0)) * byte1 + (k1 + 0))];
double d4 = this.q[(((i1 + 1) * l + (j1 + 1)) * byte1 + (k1 + 0))];
double d5 = (this.q[(((i1 + 0) * l + (j1 + 0)) * byte1 + (k1 + 1))] - d1) * d;
double d6 = (this.q[(((i1 + 0) * l + (j1 + 1)) * byte1 + (k1 + 1))] - d2) * d;
double d7 = (this.q[(((i1 + 1) * l + (j1 + 0)) * byte1 + (k1 + 1))] - d3) * d;
double d8 = (this.q[(((i1 + 1) * l + (j1 + 1)) * byte1 + (k1 + 1))] - d4) * d;
for (int l1 = 0; l1 < 4; l1++)
{
double d9 = 0.125D;
double d10 = d1;
double d11 = d2;
double d12 = (d3 - d1) * d9;
double d13 = (d4 - d2) * d9;
for (int i2 = 0; i2 < 8; i2++)
{
int j2 = i2 + i1 * 8 << 11 | 0 + j1 * 8 << 7 | k1 * 4 + l1;
char c = '€';
double d14 = 0.125D;
double d15 = d10;
double d16 = (d11 - d10) * d14;
for (int k2 = 0; k2 < 8; k2++)
{
int l2 = 0;
if (d15 > 0.0D)
{
l2 = uu.u.bn;
}
abyte0[j2] = (byte)l2;
j2 += c;
d15 += d16;
}

d10 += d12;
d11 += d13;
}

d1 += d5;
d2 += d6;
d3 += d7;
d4 += d8;
}
}
}
}
}

public void a(int i, int j, byte[] abyte0, kd[] abiomegenbase)
{
double d = 0.03125D;
this.r = this.n.a(this.r, i * 16, j * 16, 0.0D, 16, 16, 1, d, d, 1.0D);
this.s = this.n.a(this.s, i * 16, 109.0134D, j * 16, 16, 1, 16, d, 1.0D, d);
this.t = this.o.a(this.t, i * 16, j * 16, 0.0D, 16, 16, 1, d * 2.0D, d * 2.0D, d * 2.0D);
for (int k = 0; k < 16; k++)
{
for (int l = 0; l < 16; l++)
{
kd biomegenbase = abiomegenbase[(k + l * 16)];
int i1 = (int)(this.t[(k + l * 16)] / 3.0D + 3.0D + this.j.nextDouble() * 0.25D);
int j1 = -1;
byte byte0 = biomegenbase.p;
byte byte1 = biomegenbase.q;
for (int k1 = 127; k1 >= 0; k1--)
{
int l1 = (l * 16 + k) * 128 + k1;
byte byte2 = abyte0[l1];
if (byte2 == 0)
{
j1 = -1;
}
else {
if (byte2 != uu.u.bn)
{
continue;
}
if (j1 == -1)
{
if (i1 <= 0)
{
byte0 = 0;
byte1 = (byte)uu.u.bn;
}
j1 = i1;
if (k1 >= 0)
{
abyte0[l1] = byte0;
}
else
abyte0[l1] = byte1;
}
else
{
if (j1 <= 0)
{
continue;
}
j1--;
abyte0[l1] = byte1;
if ((j1 != 0) || (byte1 != uu.F.bn))
continue;
j1 = this.j.nextInt(4);
byte1 = (byte)uu.R.bn;
}
}
}
}
}
}

public lm c(int i, int j)
{
return b(i, j);
}

public ChunkCube prepareCube(int i, int y, int j) {
return provideCube(i, y, j);
}

public ChunkCube provideCube(int x, int y, int z)
{
lm chunk = this.worldObj.c(x, z);

if ((chunk == null) || (chunk.p))
{
chunk = b(x, y);
}

if ((y < 0) || (y >= 8 ))
{
byte[] data = new byte[4096];

ChunkCube cube = new ChunkCube(chunk, data, y + 128 );
cube.isAir = true;
cube.isChunkLoaded = true;
chunk.cubes[(y + 128 )] = cube;
for (int n = 0; n < cube.skylightMap.a.length; n++)
{
cube.skylightMap.a[n] = -1;
}
return cube;
}

chunk.c();
return chunk.cubes[(y + 128 )];
}

public lm b(int i, int j)
{
this.j.setSeed(i * 341873128712L + j * 132897987541L);
byte[] data = new byte[32768];
this.v = this.worldObj.a().a(this.v, i * 16, j * 16, 16, 16);
double[] ad = this.worldObj.a().a;
a(i, j, data, this.v, ad);
a(i, j, data, this.v);
this.u.a(this, this.worldObj, i, j, data);

lm chunk = new lm(this.worldObj, data, i, j);

chunk.c();
return chunk;
}

private double[] a(double[] ad, int i, int j, int k, int l, int i1, int j1)
{
if (ad == null)
{
ad = new double[l * i1 * j1];
}
double d = 684.41200000000003D;
double d1 = 684.41200000000003D;
double[] ad1 = this.worldObj.a().a;
double[] ad2 = this.worldObj.a().b;
this.g = this.a.a(this.g, i, k, l, j1, 1.121D, 1.121D, 0.5D);
this.h = this.b.a(this.h, i, k, l, j1, 200.0D, 200.0D, 0.5D);
d *= 2.0D;
this.d = this.m.a(this.d, i, j, k, l, i1, j1, d / 80.0D, d1 / 160.0D, d / 80.0D);
this.e = this.k.a(this.e, i, j, k, l, i1, j1, d, d1, d);
this.f = this.l.a(this.f, i, j, k, l, i1, j1, d, d1, d);
int k1 = 0;
int l1 = 0;
int i2 = 16 / l;
for (int j2 = 0; j2 < l; j2++)
{
int k2 = j2 * i2 + i2 / 2;
for (int l2 = 0; l2 < j1; l2++)
{
int i3 = l2 * i2 + i2 / 2;
double d2 = ad1[(k2 * 16 + i3)];
double d3 = ad2[(k2 * 16 + i3)] * d2;
double d4 = 1.0D - d3;
d4 *= d4;
d4 *= d4;
d4 = 1.0D - d4;
double d5 = (this.g[l1] + 256.0D) / 512.0D;
d5 *= d4;
if (d5 > 1.0D)
{
d5 = 1.0D;
}
double d6 = this.h[l1] / 8000.0D;
if (d6 < 0.0D)
{
d6 = -d6 * 0.3D;
}
d6 = d6 * 3.0D - 2.0D;
if (d6 > 1.0D)
{
d6 = 1.0D;
}
d6 /= 8.0D;
d6 = 0.0D;
if (d5 < 0.0D)
{
d5 = 0.0D;
}
d5 += 0.5D;
d6 = d6 * i1 / 16.0D;
l1++;
double d7 = i1 / 2.0D;
for (int j3 = 0; j3 < i1; j3++)
{
double d8 = 0.0D;
double d9 = (j3 - d7) * 8.0D / d5;
if (d9 < 0.0D)
{
d9 *= -1.0D;
}
double d10 = this.e[k1] / 512.0D;
double d11 = this.f[k1] / 512.0D;
double d12 = (this.d[k1] / 10.0D + 1.0D) / 2.0D;
if (d12 < 0.0D)
{
d8 = d10;
}
else if (d12 > 1.0D)
{
d8 = d11;
}
else {
d8 = d10 + (d11 - d10) * d12;
}
d8 -= 8.0D;
int k3 = 32;
if (j3 > i1 - k3)
{
double d13 = (j3 - (i1 - k3)) / (k3 - 1.0F);
d8 = d8 * (1.0D - d13) + -30.0D * d13;
}
k3 = 8;
if (j3 < k3)
{
double d14 = (k3 - j3) / (k3 - 1.0F);
d8 = d8 * (1.0D - d14) + -30.0D * d14;
}
ad[k1] = d8;
k1++;
}

}

}

return ad;
}

public boolean a(int i, int j)
{
return true;
}

public boolean cubeExists(int i, int y, int j)
{
return true;
}

public void populate(cl ichunkprovider, int x, int y, int z)
{
}

public void a(cl ichunkprovider, int i, int j)
{
gk.a = true;
int k = i * 16;
int l = j * 16;
kd biomegenbase = this.worldObj.a().a(k + 16, l + 16);
this.j.setSeed(this.worldObj.s());
long l1 = this.j.nextLong() / 2L * 2L + 1L;
long l2 = this.j.nextLong() / 2L * 2L + 1L;
this.j.setSeed(i * l1 + j * l2 ^ this.worldObj.s());
double d = 0.25D;
if (this.j.nextInt(4) == 0)
{
int i1 = k + this.j.nextInt(16) + 8;
int l4 = this.j.nextInt(128 );
int i8 = l + this.j.nextInt(16) + 8;
new dj(uu.C.bn).a(this.worldObj, this.j, i1, l4, i8 );
}
if (this.j.nextInt(8 ) == 0)
{
int j1 = k + this.j.nextInt(16) + 8;
int i5 = this.j.nextInt(this.j.nextInt(120) + 8 );
int j8 = l + this.j.nextInt(16) + 8;
if ((i5 < 64) || (this.j.nextInt(10) == 0))
{
new dj(uu.E.bn).a(this.worldObj, this.j, j1, i5, j8 );
}
}
for (int k1 = 0; k1 < 8; k1++)
{
int j5 = k + this.j.nextInt(16) + 8;
int k8 = this.j.nextInt(128 );
int i13 = l + this.j.nextInt(16) + 8;
new er().a(this.worldObj, this.j, j5, k8, i13);
}

for (int i2 = 0; i2 < 10; i2++)
{
int k5 = k + this.j.nextInt(16);
int l8 = this.j.nextInt(128 );
int j13 = l + this.j.nextInt(16);
new ms(32).a(this.worldObj, this.j, k5, l8, j13);
}

for (int j2 = 0; j2 < 20; j2++)
{
int l5 = k + this.j.nextInt(16);
int i9 = this.j.nextInt(128 );
int k13 = l + this.j.nextInt(16);
new fl(uu.w.bn, 32).a(this.worldObj, this.j, l5, i9, k13);
}

for (int k2 = 0; k2 < 10; k2++)
{
int i6 = k + this.j.nextInt(16);
int j9 = this.j.nextInt(128 );
int l13 = l + this.j.nextInt(16);
new fl(uu.G.bn, 32).a(this.worldObj, this.j, i6, j9, l13);
}

for (int i3 = 0; i3 < 20; i3++)
{
int j6 = k + this.j.nextInt(16);
int k9 = this.j.nextInt(128 );
int i14 = l + this.j.nextInt(16);
new fl(uu.J.bn, 16).a(this.worldObj, this.j, j6, k9, i14);
}

for (int j3 = 0; j3 < 20; j3++)
{
int k6 = k + this.j.nextInt(16);
int l9 = this.j.nextInt(64);
int j14 = l + this.j.nextInt(16);
new fl(uu.I.bn, 8 ).a(this.worldObj, this.j, k6, l9, j14);
}

for (int k3 = 0; k3 < 2; k3++)
{
int l6 = k + this.j.nextInt(16);
int i10 = this.j.nextInt(32);
int k14 = l + this.j.nextInt(16);
new fl(uu.H.bn, 8 ).a(this.worldObj, this.j, l6, i10, k14);
}

for (int l3 = 0; l3 < 8; l3++)
{
int i7 = k + this.j.nextInt(16);
int j10 = this.j.nextInt(16);
int l14 = l + this.j.nextInt(16);
new fl(uu.aO.bn, 7).a(this.worldObj, this.j, i7, j10, l14);
}

for (int i4 = 0; i4 < 1; i4++)
{
int j7 = k + this.j.nextInt(16);
int k10 = this.j.nextInt(16);
int i15 = l + this.j.nextInt(16);
new fl(uu.ax.bn, 7).a(this.worldObj, this.j, j7, k10, i15);
}

for (int j4 = 0; j4 < 1; j4++)
{
int k7 = k + this.j.nextInt(16);
int l10 = this.j.nextInt(16) + this.j.nextInt(16);
int j15 = l + this.j.nextInt(16);
new fl(uu.O.bn, 6).a(this.worldObj, this.j, k7, l10, j15);
}

d = 0.5D;
int k4 = (int)((this.c.a(k * d, l * d) / 8.0D + this.j.nextDouble() * 4.0D + 4.0D) / 3.0D);
int l7 = 0;
if (this.j.nextInt(10) == 0)
{
l7++;
}
if (biomegenbase == kd.d)
{
l7 += k4 + 5;
}
if (biomegenbase == kd.a)
{
l7 += k4 + 5;
}
if (biomegenbase == kd.c)
{
l7 += k4 + 2;
}
if (biomegenbase == kd.g)
{
l7 += k4 + 5;
}
if (biomegenbase == kd.h)
{
l7 -= 20;
}
if (biomegenbase == kd.k)
{
l7 -= 20;
}
if (biomegenbase == kd.i)
{
l7 -= 20;
}
for (int i11 = 0; i11 < l7; i11++)
{
int k15 = k + this.j.nextInt(16) + 8;
int j18 = l + this.j.nextInt(16) + 8;
pg worldgenerator = biomegenbase.a(this.j);
worldgenerator.a(1.0D, 1.0D, 1.0D);
worldgenerator.a(this.worldObj, this.j, k15, this.worldObj.d(k15, j18 ), j18 );
}

for (int j11 = 0; j11 < 2; j11++)
{
int l15 = k + this.j.nextInt(16) + 8;
int k18 = this.j.nextInt(128 );
int i21 = l + this.j.nextInt(16) + 8;
new be(uu.ae.bn).a(this.worldObj, this.j, l15, k18, i21);
}

if (this.j.nextInt(2) == 0)
{
int k11 = k + this.j.nextInt(16) + 8;
int i16 = this.j.nextInt(128 );
int l18 = l + this.j.nextInt(16) + 8;
new be(uu.af.bn).a(this.worldObj, this.j, k11, i16, l18 );
}
if (this.j.nextInt(4) == 0)
{
int l11 = k + this.j.nextInt(16) + 8;
int j16 = this.j.nextInt(128 );
int i19 = l + this.j.nextInt(16) + 8;
new be(uu.ag.bn).a(this.worldObj, this.j, l11, j16, i19);
}
if (this.j.nextInt(8 ) == 0)
{
int i12 = k + this.j.nextInt(16) + 8;
int k16 = this.j.nextInt(128 );
int j19 = l + this.j.nextInt(16) + 8;
new be(uu.ah.bn).a(this.worldObj, this.j, i12, k16, j19);
}
for (int j12 = 0; j12 < 10; j12++)
{
int l16 = k + this.j.nextInt(16) + 8;
int k19 = this.j.nextInt(128 );
int j21 = l + this.j.nextInt(16) + 8;
new ir().a(this.worldObj, this.j, l16, k19, j21);
}

if (this.j.nextInt(32) == 0)
{
int k12 = k + this.j.nextInt(16) + 8;
int i17 = this.j.nextInt(128 );
int l19 = l + this.j.nextInt(16) + 8;
new wx().a(this.worldObj, this.j, k12, i17, l19);
}
int l12 = 0;
if (biomegenbase == kd.h)
{
l12 += 10;
}
for (int j17 = 0; j17 < l12; j17++)
{
int i20 = k + this.j.nextInt(16) + 8;
int k21 = this.j.nextInt(128 );
int k22 = l + this.j.nextInt(16) + 8;
new fx().a(this.worldObj, this.j, i20, k21, k22);
}

for (int k17 = 0; k17 < 50; k17++)
{
int j20 = k + this.j.nextInt(16) + 8;
int l21 = this.j.nextInt(this.j.nextInt(120) + 8 );
int l22 = l + this.j.nextInt(16) + 8;
new xo(uu.B.bn).a(this.worldObj, this.j, j20, l21, l22);
}

for (int l17 = 0; l17 < 20; l17++)
{
int k20 = k + this.j.nextInt(16) + 8;
int i22 = this.j.nextInt(this.j.nextInt(this.j.nextInt(112) + 8 ) + 8 );
int i23 = l + this.j.nextInt(16) + 8;
new xo(uu.D.bn).a(this.worldObj, this.j, k20, i22, i23);
}

this.w = this.worldObj.a().a(this.w, k + 8, l + 8, 16, 16);
for (int i18 = k + 8; i18 < k + 8 + 16; i18++)
{
for (int l20 = l + 8; l20 < l + 8 + 16; l20++)
{
int j22 = i18 - (k + 8 );
int j23 = l20 - (l + 8 );
int k23 = this.worldObj.e(i18, l20);
double d1 = this.w[(j22 * 16 + j23)] - (k23 - 64) / 64.0D * 0.3D;
if ((d1 >= 0.5D) || (k23 <= 0) || (k23 >= 128 ) || (!this.worldObj.d(i18, k23, l20)) || (!this.worldObj.f(i18, k23 - 1, l20).c()) || (this.worldObj.f(i18, k23 - 1, l20) == ln.s))
continue;
this.worldObj.f(i18, k23, l20, uu.aT.bn);
}

}

gk.a = false;
}

public boolean a(boolean flag, yb iprogressupdate)
{
return true;
}

public boolean a()
{
return false;
}

public boolean b()
{
return true;
}

public String c()
{
return "RandomLevelSource";
}
}
import java.util.Random;

public class jd
implements cl
{
private Random j;
private uf k;
private uf l;
private uf m;
private uf n;
private uf o;
public uf a;
public uf b;
public uf c;
private fd worldObj;
private double[] q;
private double[] r;
private double[] s;
private double[] t;
private fv u;
private kd[] v;
double[] d;
double[] e;
double[] f;
double[] g;
double[] h;
int[][] i;
private double[] w;

public jd(fd world, long l)
{
this.r = new double[256];
this.s = new double[256];
this.t = new double[256];
this.u = new sq();
this.i = new int[32][32];
this.worldObj = world;
this.j = new Random(l);
this.k = new uf(this.j, 16);
this.l = new uf(this.j, 16);
this.m = new uf(this.j, 8 );
this.n = new uf(this.j, 4);
this.o = new uf(this.j, 4);
this.a = new uf(this.j, 10);
this.b = new uf(this.j, 16);
this.c = new uf(this.j, 8 );
}

public void a(int i, int j, byte[] abyte0, kd[] abiomegenbase, double[] ad)
{
byte byte0 = 2;
int k = byte0 + 1;
byte byte1 = 33;
int l = byte0 + 1;
this.q = a(this.q, i * byte0, 0, j * byte0, k, byte1, l);
for (int i1 = 0; i1 < byte0; i1++)
{
for (int j1 = 0; j1 < byte0; j1++)
{
for (int k1 = 0; k1 < 32; k1++)
{
double d = 0.25D;
double d1 = this.q[(((i1 + 0) * l + (j1 + 0)) * byte1 + (k1 + 0))];
double d2 = this.q[(((i1 + 0) * l + (j1 + 1)) * byte1 + (k1 + 0))];
double d3 = this.q[(((i1 + 1) * l + (j1 + 0)) * byte1 + (k1 + 0))];
double d4 = this.q[(((i1 + 1) * l + (j1 + 1)) * byte1 + (k1 + 0))];
double d5 = (this.q[(((i1 + 0) * l + (j1 + 0)) * byte1 + (k1 + 1))] - d1) * d;
double d6 = (this.q[(((i1 + 0) * l + (j1 + 1)) * byte1 + (k1 + 1))] - d2) * d;
double d7 = (this.q[(((i1 + 1) * l + (j1 + 0)) * byte1 + (k1 + 1))] - d3) * d;
double d8 = (this.q[(((i1 + 1) * l + (j1 + 1)) * byte1 + (k1 + 1))] - d4) * d;
for (int l1 = 0; l1 < 4; l1++)
{
double d9 = 0.125D;
double d10 = d1;
double d11 = d2;
double d12 = (d3 - d1) * d9;
double d13 = (d4 - d2) * d9;
for (int i2 = 0; i2 < 8; i2++)
{
int j2 = i2 + i1 * 8 << 11 | 0 + j1 * 8 << 7 | k1 * 4 + l1;
char c = '€';
double d14 = 0.125D;
double d15 = d10;
double d16 = (d11 - d10) * d14;
for (int k2 = 0; k2 < 8; k2++)
{
int l2 = 0;
if (d15 > 0.0D)
{
l2 = uu.u.bn;
}
abyte0[j2] = (byte)l2;
j2 += c;
d15 += d16;
}

d10 += d12;
d11 += d13;
}

d1 += d5;
d2 += d6;
d3 += d7;
d4 += d8;
}
}
}
}
}

public void a(int i, int j, byte[] abyte0, kd[] abiomegenbase)
{
double d = 0.03125D;
this.r = this.n.a(this.r, i * 16, j * 16, 0.0D, 16, 16, 1, d, d, 1.0D);
this.s = this.n.a(this.s, i * 16, 109.0134D, j * 16, 16, 1, 16, d, 1.0D, d);
this.t = this.o.a(this.t, i * 16, j * 16, 0.0D, 16, 16, 1, d * 2.0D, d * 2.0D, d * 2.0D);
for (int k = 0; k < 16; k++)
{
for (int l = 0; l < 16; l++)
{
kd biomegenbase = abiomegenbase[(k + l * 16)];
int i1 = (int)(this.t[(k + l * 16)] / 3.0D + 3.0D + this.j.nextDouble() * 0.25D);
int j1 = -1;
byte byte0 = biomegenbase.p;
byte byte1 = biomegenbase.q;
for (int k1 = 127; k1 >= 0; k1--)
{
int l1 = (l * 16 + k) * 128 + k1;
byte byte2 = abyte0[l1];
if (byte2 == 0)
{
j1 = -1;
}
else {
if (byte2 != uu.u.bn)
{
continue;
}
if (j1 == -1)
{
if (i1 <= 0)
{
byte0 = 0;
byte1 = (byte)uu.u.bn;
}
j1 = i1;
if (k1 >= 0)
{
abyte0[l1] = byte0;
}
else
abyte0[l1] = byte1;
}
else
{
if (j1 <= 0)
{
continue;
}
j1--;
abyte0[l1] = byte1;
if ((j1 != 0) || (byte1 != uu.F.bn))
continue;
j1 = this.j.nextInt(4);
byte1 = (byte)uu.R.bn;
}
}
}
}
}
}

public lm c(int i, int j)
{
return b(i, j);
}

public ChunkCube prepareCube(int i, int y, int j) {
return provideCube(i, y, j);
}

public ChunkCube provideCube(int x, int y, int z)
{
lm chunk = this.worldObj.c(x, z);

if ((chunk == null) || (chunk.p))
{
chunk = b(x, y);
}

if ((y < 0) || (y >= 8 ))
{
byte[] data = new byte[4096];

ChunkCube cube = new ChunkCube(chunk, data, y + 128 );
cube.isAir = true;
cube.isChunkLoaded = true;
chunk.cubes[(y + 128 )] = cube;
for (int n = 0; n < cube.skylightMap.a.length; n++)
{
cube.skylightMap.a[n] = -1;
}
return cube;
}

chunk.c();
return chunk.cubes[(y + 128 )];
}

public lm b(int i, int j)
{
this.j.setSeed(i * 341873128712L + j * 132897987541L);
byte[] data = new byte[32768];
this.v = this.worldObj.a().a(this.v, i * 16, j * 16, 16, 16);
double[] ad = this.worldObj.a().a;
a(i, j, data, this.v, ad);
a(i, j, data, this.v);
this.u.a(this, this.worldObj, i, j, data);

lm chunk = new lm(this.worldObj, data, i, j);

chunk.c();
return chunk;
}

private double[] a(double[] ad, int i, int j, int k, int l, int i1, int j1)
{
if (ad == null)
{
ad = new double[l * i1 * j1];
}
double d = 684.41200000000003D;
double d1 = 684.41200000000003D;
double[] ad1 = this.worldObj.a().a;
double[] ad2 = this.worldObj.a().b;
this.g = this.a.a(this.g, i, k, l, j1, 1.121D, 1.121D, 0.5D);
this.h = this.b.a(this.h, i, k, l, j1, 200.0D, 200.0D, 0.5D);
d *= 2.0D;
this.d = this.m.a(this.d, i, j, k, l, i1, j1, d / 80.0D, d1 / 160.0D, d / 80.0D);
this.e = this.k.a(this.e, i, j, k, l, i1, j1, d, d1, d);
this.f = this.l.a(this.f, i, j, k, l, i1, j1, d, d1, d);
int k1 = 0;
int l1 = 0;
int i2 = 16 / l;
for (int j2 = 0; j2 < l; j2++)
{
int k2 = j2 * i2 + i2 / 2;
for (int l2 = 0; l2 < j1; l2++)
{
int i3 = l2 * i2 + i2 / 2;
double d2 = ad1[(k2 * 16 + i3)];
double d3 = ad2[(k2 * 16 + i3)] * d2;
double d4 = 1.0D - d3;
d4 *= d4;
d4 *= d4;
d4 = 1.0D - d4;
double d5 = (this.g[l1] + 256.0D) / 512.0D;
d5 *= d4;
if (d5 > 1.0D)
{
d5 = 1.0D;
}
double d6 = this.h[l1] / 8000.0D;
if (d6 < 0.0D)
{
d6 = -d6 * 0.3D;
}
d6 = d6 * 3.0D - 2.0D;
if (d6 > 1.0D)
{
d6 = 1.0D;
}
d6 /= 8.0D;
d6 = 0.0D;
if (d5 < 0.0D)
{
d5 = 0.0D;
}
d5 += 0.5D;
d6 = d6 * i1 / 16.0D;
l1++;
double d7 = i1 / 2.0D;
for (int j3 = 0; j3 < i1; j3++)
{
double d8 = 0.0D;
double d9 = (j3 - d7) * 8.0D / d5;
if (d9 < 0.0D)
{
d9 *= -1.0D;
}
double d10 = this.e[k1] / 512.0D;
double d11 = this.f[k1] / 512.0D;
double d12 = (this.d[k1] / 10.0D + 1.0D) / 2.0D;
if (d12 < 0.0D)
{
d8 = d10;
}
else if (d12 > 1.0D)
{
d8 = d11;
}
else {
d8 = d10 + (d11 - d10) * d12;
}
d8 -= 8.0D;
int k3 = 32;
if (j3 > i1 - k3)
{
double d13 = (j3 - (i1 - k3)) / (k3 - 1.0F);
d8 = d8 * (1.0D - d13) + -30.0D * d13;
}
k3 = 8;
if (j3 < k3)
{
double d14 = (k3 - j3) / (k3 - 1.0F);
d8 = d8 * (1.0D - d14) + -30.0D * d14;
}
ad[k1] = d8;
k1++;
}

}

}

return ad;
}

public boolean a(int i, int j)
{
return true;
}

public boolean cubeExists(int i, int y, int j)
{
return true;
}

public void populate(cl ichunkprovider, int x, int y, int z)
{
}

public void a(cl ichunkprovider, int i, int j)
{
gk.a = true;
int k = i * 16;
int l = j * 16;
kd biomegenbase = this.worldObj.a().a(k + 16, l + 16);
this.j.setSeed(this.worldObj.s());
long l1 = this.j.nextLong() / 2L * 2L + 1L;
long l2 = this.j.nextLong() / 2L * 2L + 1L;
this.j.setSeed(i * l1 + j * l2 ^ this.worldObj.s());
double d = 0.25D;
if (this.j.nextInt(4) == 0)
{
int i1 = k + this.j.nextInt(16) + 8;
int l4 = this.j.nextInt(128 );
int i8 = l + this.j.nextInt(16) + 8;
new dj(uu.C.bn).a(this.worldObj, this.j, i1, l4, i8 );
}
if (this.j.nextInt(8 ) == 0)
{
int j1 = k + this.j.nextInt(16) + 8;
int i5 = this.j.nextInt(this.j.nextInt(120) + 8 );
int j8 = l + this.j.nextInt(16) + 8;
if ((i5 < 64) || (this.j.nextInt(10) == 0))
{
new dj(uu.E.bn).a(this.worldObj, this.j, j1, i5, j8 );
}
}
for (int k1 = 0; k1 < 8; k1++)
{
int j5 = k + this.j.nextInt(16) + 8;
int k8 = this.j.nextInt(128 );
int i13 = l + this.j.nextInt(16) + 8;
new er().a(this.worldObj, this.j, j5, k8, i13);
}

for (int i2 = 0; i2 < 10; i2++)
{
int k5 = k + this.j.nextInt(16);
int l8 = this.j.nextInt(128 );
int j13 = l + this.j.nextInt(16);
new ms(32).a(this.worldObj, this.j, k5, l8, j13);
}

for (int j2 = 0; j2 < 20; j2++)
{
int l5 = k + this.j.nextInt(16);
int i9 = this.j.nextInt(128 );
int k13 = l + this.j.nextInt(16);
new fl(uu.w.bn, 32).a(this.worldObj, this.j, l5, i9, k13);
}

for (int k2 = 0; k2 < 10; k2++)
{
int i6 = k + this.j.nextInt(16);
int j9 = this.j.nextInt(128 );
int l13 = l + this.j.nextInt(16);
new fl(uu.G.bn, 32).a(this.worldObj, this.j, i6, j9, l13);
}

for (int i3 = 0; i3 < 20; i3++)
{
int j6 = k + this.j.nextInt(16);
int k9 = this.j.nextInt(128 );
int i14 = l + this.j.nextInt(16);
new fl(uu.J.bn, 16).a(this.worldObj, this.j, j6, k9, i14);
}

for (int j3 = 0; j3 < 20; j3++)
{
int k6 = k + this.j.nextInt(16);
int l9 = this.j.nextInt(64);
int j14 = l + this.j.nextInt(16);
new fl(uu.I.bn, 8 ).a(this.worldObj, this.j, k6, l9, j14);
}

for (int k3 = 0; k3 < 2; k3++)
{
int l6 = k + this.j.nextInt(16);
int i10 = this.j.nextInt(32);
int k14 = l + this.j.nextInt(16);
new fl(uu.H.bn, 8 ).a(this.worldObj, this.j, l6, i10, k14);
}

for (int l3 = 0; l3 < 8; l3++)
{
int i7 = k + this.j.nextInt(16);
int j10 = this.j.nextInt(16);
int l14 = l + this.j.nextInt(16);
new fl(uu.aO.bn, 7).a(this.worldObj, this.j, i7, j10, l14);
}

for (int i4 = 0; i4 < 1; i4++)
{
int j7 = k + this.j.nextInt(16);
int k10 = this.j.nextInt(16);
int i15 = l + this.j.nextInt(16);
new fl(uu.ax.bn, 7).a(this.worldObj, this.j, j7, k10, i15);
}

for (int j4 = 0; j4 < 1; j4++)
{
int k7 = k + this.j.nextInt(16);
int l10 = this.j.nextInt(16) + this.j.nextInt(16);
int j15 = l + this.j.nextInt(16);
new fl(uu.O.bn, 6).a(this.worldObj, this.j, k7, l10, j15);
}

d = 0.5D;
int k4 = (int)((this.c.a(k * d, l * d) / 8.0D + this.j.nextDouble() * 4.0D + 4.0D) / 3.0D);
int l7 = 0;
if (this.j.nextInt(10) == 0)
{
l7++;
}
if (biomegenbase == kd.d)
{
l7 += k4 + 5;
}
if (biomegenbase == kd.a)
{
l7 += k4 + 5;
}
if (biomegenbase == kd.c)
{
l7 += k4 + 2;
}
if (biomegenbase == kd.g)
{
l7 += k4 + 5;
}
if (biomegenbase == kd.h)
{
l7 -= 20;
}
if (biomegenbase == kd.k)
{
l7 -= 20;
}
if (biomegenbase == kd.i)
{
l7 -= 20;
}
for (int i11 = 0; i11 < l7; i11++)
{
int k15 = k + this.j.nextInt(16) + 8;
int j18 = l + this.j.nextInt(16) + 8;
pg worldgenerator = biomegenbase.a(this.j);
worldgenerator.a(1.0D, 1.0D, 1.0D);
worldgenerator.a(this.worldObj, this.j, k15, this.worldObj.d(k15, j18 ), j18 );
}

for (int j11 = 0; j11 < 2; j11++)
{
int l15 = k + this.j.nextInt(16) + 8;
int k18 = this.j.nextInt(128 );
int i21 = l + this.j.nextInt(16) + 8;
new be(uu.ae.bn).a(this.worldObj, this.j, l15, k18, i21);
}

if (this.j.nextInt(2) == 0)
{
int k11 = k + this.j.nextInt(16) + 8;
int i16 = this.j.nextInt(128 );
int l18 = l + this.j.nextInt(16) + 8;
new be(uu.af.bn).a(this.worldObj, this.j, k11, i16, l18 );
}
if (this.j.nextInt(4) == 0)
{
int l11 = k + this.j.nextInt(16) + 8;
int j16 = this.j.nextInt(128 );
int i19 = l + this.j.nextInt(16) + 8;
new be(uu.ag.bn).a(this.worldObj, this.j, l11, j16, i19);
}
if (this.j.nextInt(8 ) == 0)
{
int i12 = k + this.j.nextInt(16) + 8;
int k16 = this.j.nextInt(128 );
int j19 = l + this.j.nextInt(16) + 8;
new be(uu.ah.bn).a(this.worldObj, this.j, i12, k16, j19);
}
for (int j12 = 0; j12 < 10; j12++)
{
int l16 = k + this.j.nextInt(16) + 8;
int k19 = this.j.nextInt(128 );
int j21 = l + this.j.nextInt(16) + 8;
new ir().a(this.worldObj, this.j, l16, k19, j21);
}

if (this.j.nextInt(32) == 0)
{
int k12 = k + this.j.nextInt(16) + 8;
int i17 = this.j.nextInt(128 );
int l19 = l + this.j.nextInt(16) + 8;
new wx().a(this.worldObj, this.j, k12, i17, l19);
}
int l12 = 0;
if (biomegenbase == kd.h)
{
l12 += 10;
}
for (int j17 = 0; j17 < l12; j17++)
{
int i20 = k + this.j.nextInt(16) + 8;
int k21 = this.j.nextInt(128 );
int k22 = l + this.j.nextInt(16) + 8;
new fx().a(this.worldObj, this.j, i20, k21, k22);
}

for (int k17 = 0; k17 < 50; k17++)
{
int j20 = k + this.j.nextInt(16) + 8;
int l21 = this.j.nextInt(this.j.nextInt(120) + 8 );
int l22 = l + this.j.nextInt(16) + 8;
new xo(uu.B.bn).a(this.worldObj, this.j, j20, l21, l22);
}

for (int l17 = 0; l17 < 20; l17++)
{
int k20 = k + this.j.nextInt(16) + 8;
int i22 = this.j.nextInt(this.j.nextInt(this.j.nextInt(112) + 8 ) + 8 );
int i23 = l + this.j.nextInt(16) + 8;
new xo(uu.D.bn).a(this.worldObj, this.j, k20, i22, i23);
}

this.w = this.worldObj.a().a(this.w, k + 8, l + 8, 16, 16);
for (int i18 = k + 8; i18 < k + 8 + 16; i18++)
{
for (int l20 = l + 8; l20 < l + 8 + 16; l20++)
{
int j22 = i18 - (k + 8 );
int j23 = l20 - (l + 8 );
int k23 = this.worldObj.e(i18, l20);
double d1 = this.w[(j22 * 16 + j23)] - (k23 - 64) / 64.0D * 0.3D;
if ((d1 >= 0.5D) || (k23 <= 0) || (k23 >= 128 ) || (!this.worldObj.d(i18, k23, l20)) || (!this.worldObj.f(i18, k23 - 1, l20).c()) || (this.worldObj.f(i18, k23 - 1, l20) == ln.s))
continue;
this.worldObj.f(i18, k23, l20, uu.aT.bn);
}

}

gk.a = false;
}

public boolean a(boolean flag, yb iprogressupdate)
{
return true;
}

public boolean a()
{
return false;
}

public boolean b()
{
return true;
}

public String c()
{
return "RandomLevelSource";
}
}
import java.util.Random;

public class jd
implements cl
{
private Random j;
private uf k;
private uf l;
private uf m;
private uf n;
private uf o;
public uf a;
public uf b;
public uf c;
private fd worldObj;
private double[] q;
private double[] r;
private double[] s;
private double[] t;
private fv u;
private kd[] v;
double[] d;
double[] e;
double[] f;
double[] g;
double[] h;
int[][] i;
private double[] w;

public jd(fd world, long l)
{
this.r = new double[256];
this.s = new double[256];
this.t = new double[256];
this.u = new sq();
this.i = new int[32][32];
this.worldObj = world;
this.j = new Random(l);
this.k = new uf(this.j, 16);
this.l = new uf(this.j, 16);
this.m = new uf(this.j, 8 );
this.n = new uf(this.j, 4);
this.o = new uf(this.j, 4);
this.a = new uf(this.j, 10);
this.b = new uf(this.j, 16);
this.c = new uf(this.j, 8 );
}

public void a(int i, int j, byte[] abyte0, kd[] abiomegenbase, double[] ad)
{
byte byte0 = 2;
int k = byte0 + 1;
byte byte1 = 33;
int l = byte0 + 1;
this.q = a(this.q, i * byte0, 0, j * byte0, k, byte1, l);
for (int i1 = 0; i1 < byte0; i1++)
{
for (int j1 = 0; j1 < byte0; j1++)
{
for (int k1 = 0; k1 < 32; k1++)
{
double d = 0.25D;
double d1 = this.q[(((i1 + 0) * l + (j1 + 0)) * byte1 + (k1 + 0))];
double d2 = this.q[(((i1 + 0) * l + (j1 + 1)) * byte1 + (k1 + 0))];
double d3 = this.q[(((i1 + 1) * l + (j1 + 0)) * byte1 + (k1 + 0))];
double d4 = this.q[(((i1 + 1) * l + (j1 + 1)) * byte1 + (k1 + 0))];
double d5 = (this.q[(((i1 + 0) * l + (j1 + 0)) * byte1 + (k1 + 1))] - d1) * d;
double d6 = (this.q[(((i1 + 0) * l + (j1 + 1)) * byte1 + (k1 + 1))] - d2) * d;
double d7 = (this.q[(((i1 + 1) * l + (j1 + 0)) * byte1 + (k1 + 1))] - d3) * d;
double d8 = (this.q[(((i1 + 1) * l + (j1 + 1)) * byte1 + (k1 + 1))] - d4) * d;
for (int l1 = 0; l1 < 4; l1++)
{
double d9 = 0.125D;
double d10 = d1;
double d11 = d2;
double d12 = (d3 - d1) * d9;
double d13 = (d4 - d2) * d9;
for (int i2 = 0; i2 < 8; i2++)
{
int j2 = i2 + i1 * 8 << 11 | 0 + j1 * 8 << 7 | k1 * 4 + l1;
char c = '€';
double d14 = 0.125D;
double d15 = d10;
double d16 = (d11 - d10) * d14;
for (int k2 = 0; k2 < 8; k2++)
{
int l2 = 0;
if (d15 > 0.0D)
{
l2 = uu.u.bn;
}
abyte0[j2] = (byte)l2;
j2 += c;
d15 += d16;
}

d10 += d12;
d11 += d13;
}

d1 += d5;
d2 += d6;
d3 += d7;
d4 += d8;
}
}
}
}
}

public void a(int i, int j, byte[] abyte0, kd[] abiomegenbase)
{
double d = 0.03125D;
this.r = this.n.a(this.r, i * 16, j * 16, 0.0D, 16, 16, 1, d, d, 1.0D);
this.s = this.n.a(this.s, i * 16, 109.0134D, j * 16, 16, 1, 16, d, 1.0D, d);
this.t = this.o.a(this.t, i * 16, j * 16, 0.0D, 16, 16, 1, d * 2.0D, d * 2.0D, d * 2.0D);
for (int k = 0; k < 16; k++)
{
for (int l = 0; l < 16; l++)
{
kd biomegenbase = abiomegenbase[(k + l * 16)];
int i1 = (int)(this.t[(k + l * 16)] / 3.0D + 3.0D + this.j.nextDouble() * 0.25D);
int j1 = -1;
byte byte0 = biomegenbase.p;
byte byte1 = biomegenbase.q;
for (int k1 = 127; k1 >= 0; k1--)
{
int l1 = (l * 16 + k) * 128 + k1;
byte byte2 = abyte0[l1];
if (byte2 == 0)
{
j1 = -1;
}
else {
if (byte2 != uu.u.bn)
{
continue;
}
if (j1 == -1)
{
if (i1 <= 0)
{
byte0 = 0;
byte1 = (byte)uu.u.bn;
}
j1 = i1;
if (k1 >= 0)
{
abyte0[l1] = byte0;
}
else
abyte0[l1] = byte1;
}
else
{
if (j1 <= 0)
{
continue;
}
j1--;
abyte0[l1] = byte1;
if ((j1 != 0) || (byte1 != uu.F.bn))
continue;
j1 = this.j.nextInt(4);
byte1 = (byte)uu.R.bn;
}
}
}
}
}
}

public lm c(int i, int j)
{
return b(i, j);
}

public ChunkCube prepareCube(int i, int y, int j) {
return provideCube(i, y, j);
}

public ChunkCube provideCube(int x, int y, int z)
{
lm chunk = this.worldObj.c(x, z);

if ((chunk == null) || (chunk.p))
{
chunk = b(x, y);
}

if ((y < 0) || (y >= 8 ))
{
byte[] data = new byte[4096];

ChunkCube cube = new ChunkCube(chunk, data, y + 128 );
cube.isAir = true;
cube.isChunkLoaded = true;
chunk.cubes[(y + 128 )] = cube;
for (int n = 0; n < cube.skylightMap.a.length; n++)
{
cube.skylightMap.a[n] = -1;
}
return cube;
}

chunk.c();
return chunk.cubes[(y + 128 )];
}

public lm b(int i, int j)
{
this.j.setSeed(i * 341873128712L + j * 132897987541L);
byte[] data = new byte[32768];
this.v = this.worldObj.a().a(this.v, i * 16, j * 16, 16, 16);
double[] ad = this.worldObj.a().a;
a(i, j, data, this.v, ad);
a(i, j, data, this.v);
this.u.a(this, this.worldObj, i, j, data);

lm chunk = new lm(this.worldObj, data, i, j);

chunk.c();
return chunk;
}

private double[] a(double[] ad, int i, int j, int k, int l, int i1, int j1)
{
if (ad == null)
{
ad = new double[l * i1 * j1];
}
double d = 684.41200000000003D;
double d1 = 684.41200000000003D;
double[] ad1 = this.worldObj.a().a;
double[] ad2 = this.worldObj.a().b;
this.g = this.a.a(this.g, i, k, l, j1, 1.121D, 1.121D, 0.5D);
this.h = this.b.a(this.h, i, k, l, j1, 200.0D, 200.0D, 0.5D);
d *= 2.0D;
this.d = this.m.a(this.d, i, j, k, l, i1, j1, d / 80.0D, d1 / 160.0D, d / 80.0D);
this.e = this.k.a(this.e, i, j, k, l, i1, j1, d, d1, d);
this.f = this.l.a(this.f, i, j, k, l, i1, j1, d, d1, d);
int k1 = 0;
int l1 = 0;
int i2 = 16 / l;
for (int j2 = 0; j2 < l; j2++)
{
int k2 = j2 * i2 + i2 / 2;
for (int l2 = 0; l2 < j1; l2++)
{
int i3 = l2 * i2 + i2 / 2;
double d2 = ad1[(k2 * 16 + i3)];
double d3 = ad2[(k2 * 16 + i3)] * d2;
double d4 = 1.0D - d3;
d4 *= d4;
d4 *= d4;
d4 = 1.0D - d4;
double d5 = (this.g[l1] + 256.0D) / 512.0D;
d5 *= d4;
if (d5 > 1.0D)
{
d5 = 1.0D;
}
double d6 = this.h[l1] / 8000.0D;
if (d6 < 0.0D)
{
d6 = -d6 * 0.3D;
}
d6 = d6 * 3.0D - 2.0D;
if (d6 > 1.0D)
{
d6 = 1.0D;
}
d6 /= 8.0D;
d6 = 0.0D;
if (d5 < 0.0D)
{
d5 = 0.0D;
}
d5 += 0.5D;
d6 = d6 * i1 / 16.0D;
l1++;
double d7 = i1 / 2.0D;
for (int j3 = 0; j3 < i1; j3++)
{
double d8 = 0.0D;
double d9 = (j3 - d7) * 8.0D / d5;
if (d9 < 0.0D)
{
d9 *= -1.0D;
}
double d10 = this.e[k1] / 512.0D;
double d11 = this.f[k1] / 512.0D;
double d12 = (this.d[k1] / 10.0D + 1.0D) / 2.0D;
if (d12 < 0.0D)
{
d8 = d10;
}
else if (d12 > 1.0D)
{
d8 = d11;
}
else {
d8 = d10 + (d11 - d10) * d12;
}
d8 -= 8.0D;
int k3 = 32;
if (j3 > i1 - k3)
{
double d13 = (j3 - (i1 - k3)) / (k3 - 1.0F);
d8 = d8 * (1.0D - d13) + -30.0D * d13;
}
k3 = 8;
if (j3 < k3)
{
double d14 = (k3 - j3) / (k3 - 1.0F);
d8 = d8 * (1.0D - d14) + -30.0D * d14;
}
ad[k1] = d8;
k1++;
}

}

}

return ad;
}

public boolean a(int i, int j)
{
return true;
}

public boolean cubeExists(int i, int y, int j)
{
return true;
}

public void populate(cl ichunkprovider, int x, int y, int z)
{
}

public void a(cl ichunkprovider, int i, int j)
{
gk.a = true;
int k = i * 16;
int l = j * 16;
kd biomegenbase = this.worldObj.a().a(k + 16, l + 16);
this.j.setSeed(this.worldObj.s());
long l1 = this.j.nextLong() / 2L * 2L + 1L;
long l2 = this.j.nextLong() / 2L * 2L + 1L;
this.j.setSeed(i * l1 + j * l2 ^ this.worldObj.s());
double d = 0.25D;
if (this.j.nextInt(4) == 0)
{
int i1 = k + this.j.nextInt(16) + 8;
int l4 = this.j.nextInt(128 );
int i8 = l + this.j.nextInt(16) + 8;
new dj(uu.C.bn).a(this.worldObj, this.j, i1, l4, i8 );
}
if (this.j.nextInt(8 ) == 0)
{
int j1 = k + this.j.nextInt(16) + 8;
int i5 = this.j.nextInt(this.j.nextInt(120) + 8 );
int j8 = l + this.j.nextInt(16) + 8;
if ((i5 < 64) || (this.j.nextInt(10) == 0))
{
new dj(uu.E.bn).a(this.worldObj, this.j, j1, i5, j8 );
}
}
for (int k1 = 0; k1 < 8; k1++)
{
int j5 = k + this.j.nextInt(16) + 8;
int k8 = this.j.nextInt(128 );
int i13 = l + this.j.nextInt(16) + 8;
new er().a(this.worldObj, this.j, j5, k8, i13);
}

for (int i2 = 0; i2 < 10; i2++)
{
int k5 = k + this.j.nextInt(16);
int l8 = this.j.nextInt(128 );
int j13 = l + this.j.nextInt(16);
new ms(32).a(this.worldObj, this.j, k5, l8, j13);
}

for (int j2 = 0; j2 < 20; j2++)
{
int l5 = k + this.j.nextInt(16);
int i9 = this.j.nextInt(128 );
int k13 = l + this.j.nextInt(16);
new fl(uu.w.bn, 32).a(this.worldObj, this.j, l5, i9, k13);
}

for (int k2 = 0; k2 < 10; k2++)
{
int i6 = k + this.j.nextInt(16);
int j9 = this.j.nextInt(128 );
int l13 = l + this.j.nextInt(16);
new fl(uu.G.bn, 32).a(this.worldObj, this.j, i6, j9, l13);
}

for (int i3 = 0; i3 < 20; i3++)
{
int j6 = k + this.j.nextInt(16);
int k9 = this.j.nextInt(128 );
int i14 = l + this.j.nextInt(16);
new fl(uu.J.bn, 16).a(this.worldObj, this.j, j6, k9, i14);
}

for (int j3 = 0; j3 < 20; j3++)
{
int k6 = k + this.j.nextInt(16);
int l9 = this.j.nextInt(64);
int j14 = l + this.j.nextInt(16);
new fl(uu.I.bn, 8 ).a(this.worldObj, this.j, k6, l9, j14);
}

for (int k3 = 0; k3 < 2; k3++)
{
int l6 = k + this.j.nextInt(16);
int i10 = this.j.nextInt(32);
int k14 = l + this.j.nextInt(16);
new fl(uu.H.bn, 8 ).a(this.worldObj, this.j, l6, i10, k14);
}

for (int l3 = 0; l3 < 8; l3++)
{
int i7 = k + this.j.nextInt(16);
int j10 = this.j.nextInt(16);
int l14 = l + this.j.nextInt(16);
new fl(uu.aO.bn, 7).a(this.worldObj, this.j, i7, j10, l14);
}

for (int i4 = 0; i4 < 1; i4++)
{
int j7 = k + this.j.nextInt(16);
int k10 = this.j.nextInt(16);
int i15 = l + this.j.nextInt(16);
new fl(uu.ax.bn, 7).a(this.worldObj, this.j, j7, k10, i15);
}

for (int j4 = 0; j4 < 1; j4++)
{
int k7 = k + this.j.nextInt(16);
int l10 = this.j.nextInt(16) + this.j.nextInt(16);
int j15 = l + this.j.nextInt(16);
new fl(uu.O.bn, 6).a(this.worldObj, this.j, k7, l10, j15);
}

d = 0.5D;
int k4 = (int)((this.c.a(k * d, l * d) / 8.0D + this.j.nextDouble() * 4.0D + 4.0D) / 3.0D);
int l7 = 0;
if (this.j.nextInt(10) == 0)
{
l7++;
}
if (biomegenbase == kd.d)
{
l7 += k4 + 5;
}
if (biomegenbase == kd.a)
{
l7 += k4 + 5;
}
if (biomegenbase == kd.c)
{
l7 += k4 + 2;
}
if (biomegenbase == kd.g)
{
l7 += k4 + 5;
}
if (biomegenbase == kd.h)
{
l7 -= 20;
}
if (biomegenbase == kd.k)
{
l7 -= 20;
}
if (biomegenbase == kd.i)
{
l7 -= 20;
}
for (int i11 = 0; i11 < l7; i11++)
{
int k15 = k + this.j.nextInt(16) + 8;
int j18 = l + this.j.nextInt(16) + 8;
pg worldgenerator = biomegenbase.a(this.j);
worldgenerator.a(1.0D, 1.0D, 1.0D);
worldgenerator.a(this.worldObj, this.j, k15, this.worldObj.d(k15, j18 ), j18 );
}

for (int j11 = 0; j11 < 2; j11++)
{
int l15 = k + this.j.nextInt(16) + 8;
int k18 = this.j.nextInt(128 );
int i21 = l + this.j.nextInt(16) + 8;
new be(uu.ae.bn).a(this.worldObj, this.j, l15, k18, i21);
}

if (this.j.nextInt(2) == 0)
{
int k11 = k + this.j.nextInt(16) + 8;
int i16 = this.j.nextInt(128 );
int l18 = l + this.j.nextInt(16) + 8;
new be(uu.af.bn).a(this.worldObj, this.j, k11, i16, l18 );
}
if (this.j.nextInt(4) == 0)
{
int l11 = k + this.j.nextInt(16) + 8;
int j16 = this.j.nextInt(128 );
int i19 = l + this.j.nextInt(16) + 8;
new be(uu.ag.bn).a(this.worldObj, this.j, l11, j16, i19);
}
if (this.j.nextInt(8 ) == 0)
{
int i12 = k + this.j.nextInt(16) + 8;
int k16 = this.j.nextInt(128 );
int j19 = l + this.j.nextInt(16) + 8;
new be(uu.ah.bn).a(this.worldObj, this.j, i12, k16, j19);
}
for (int j12 = 0; j12 < 10; j12++)
{
int l16 = k + this.j.nextInt(16) + 8;
int k19 = this.j.nextInt(128 );
int j21 = l + this.j.nextInt(16) + 8;
new ir().a(this.worldObj, this.j, l16, k19, j21);
}

if (this.j.nextInt(32) == 0)
{
int k12 = k + this.j.nextInt(16) + 8;
int i17 = this.j.nextInt(128 );
int l19 = l + this.j.nextInt(16) + 8;
new wx().a(this.worldObj, this.j, k12, i17, l19);
}
int l12 = 0;
if (biomegenbase == kd.h)
{
l12 += 10;
}
for (int j17 = 0; j17 < l12; j17++)
{
int i20 = k + this.j.nextInt(16) + 8;
int k21 = this.j.nextInt(128 );
int k22 = l + this.j.nextInt(16) + 8;
new fx().a(this.worldObj, this.j, i20, k21, k22);
}

for (int k17 = 0; k17 < 50; k17++)
{
int j20 = k + this.j.nextInt(16) + 8;
int l21 = this.j.nextInt(this.j.nextInt(120) + 8 );
int l22 = l + this.j.nextInt(16) + 8;
new xo(uu.B.bn).a(this.worldObj, this.j, j20, l21, l22);
}

for (int l17 = 0; l17 < 20; l17++)
{
int k20 = k + this.j.nextInt(16) + 8;
int i22 = this.j.nextInt(this.j.nextInt(this.j.nextInt(112) + 8 ) + 8 );
int i23 = l + this.j.nextInt(16) + 8;
new xo(uu.D.bn).a(this.worldObj, this.j, k20, i22, i23);
}

this.w = this.worldObj.a().a(this.w, k + 8, l + 8, 16, 16);
for (int i18 = k + 8; i18 < k + 8 + 16; i18++)
{
for (int l20 = l + 8; l20 < l + 8 + 16; l20++)
{
int j22 = i18 - (k + 8 );
int j23 = l20 - (l + 8 );
int k23 = this.worldObj.e(i18, l20);
double d1 = this.w[(j22 * 16 + j23)] - (k23 - 64) / 64.0D * 0.3D;
if ((d1 >= 0.5D) || (k23 <= 0) || (k23 >= 128 ) || (!this.worldObj.d(i18, k23, l20)) || (!this.worldObj.f(i18, k23 - 1, l20).c()) || (this.worldObj.f(i18, k23 - 1, l20) == ln.s))
continue;
this.worldObj.f(i18, k23, l20, uu.aT.bn);
}

}

gk.a = false;
}

public boolean a(boolean flag, yb iprogressupdate)
{
return true;
}

public boolean a()
{
return false;
}

public boolean b()
{
return true;
}

public String c()
{
return "RandomLevelSource";
}
}import java.util.Random;

public class jd
implements cl
{
private Random j;
private uf k;
private uf l;
private uf m;
private uf n;
private uf o;
public uf a;
public uf b;
public uf c;
private fd worldObj;
private double[] q;
private double[] r;
private double[] s;
private double[] t;
private fv u;
private kd[] v;
double[] d;
double[] e;
double[] f;
double[] g;
double[] h;
int[][] i;
private double[] w;

public jd(fd world, long l)
{
this.r = new double[256];
this.s = new double[256];
this.t = new double[256];
this.u = new sq();
this.i = new int[32][32];
this.worldObj = world;
this.j = new Random(l);
this.k = new uf(this.j, 16);
this.l = new uf(this.j, 16);
this.m = new uf(this.j, 8 );
this.n = new uf(this.j, 4);
this.o = new uf(this.j, 4);
this.a = new uf(this.j, 10);
this.b = new uf(this.j, 16);
this.c = new uf(this.j, 8 );
}

public void a(int i, int j, byte[] abyte0, kd[] abiomegenbase, double[] ad)
{
byte byte0 = 2;
int k = byte0 + 1;
byte byte1 = 33;
int l = byte0 + 1;
this.q = a(this.q, i * byte0, 0, j * byte0, k, byte1, l);
for (int i1 = 0; i1 < byte0; i1++)
{
for (int j1 = 0; j1 < byte0; j1++)
{
for (int k1 = 0; k1 < 32; k1++)
{
double d = 0.25D;
double d1 = this.q[(((i1 + 0) * l + (j1 + 0)) * byte1 + (k1 + 0))];
double d2 = this.q[(((i1 + 0) * l + (j1 + 1)) * byte1 + (k1 + 0))];
double d3 = this.q[(((i1 + 1) * l + (j1 + 0)) * byte1 + (k1 + 0))];
double d4 = this.q[(((i1 + 1) * l + (j1 + 1)) * byte1 + (k1 + 0))];
double d5 = (this.q[(((i1 + 0) * l + (j1 + 0)) * byte1 + (k1 + 1))] - d1) * d;
double d6 = (this.q[(((i1 + 0) * l + (j1 + 1)) * byte1 + (k1 + 1))] - d2) * d;
double d7 = (this.q[(((i1 + 1) * l + (j1 + 0)) * byte1 + (k1 + 1))] - d3) * d;
double d8 = (this.q[(((i1 + 1) * l + (j1 + 1)) * byte1 + (k1 + 1))] - d4) * d;
for (int l1 = 0; l1 < 4; l1++)
{
double d9 = 0.125D;
double d10 = d1;
double d11 = d2;
double d12 = (d3 - d1) * d9;
double d13 = (d4 - d2) * d9;
for (int i2 = 0; i2 < 8; i2++)
{
int j2 = i2 + i1 * 8 << 11 | 0 + j1 * 8 << 7 | k1 * 4 + l1;
char c = '€';
double d14 = 0.125D;
double d15 = d10;
double d16 = (d11 - d10) * d14;
for (int k2 = 0; k2 < 8; k2++)
{
int l2 = 0;
if (d15 > 0.0D)
{
l2 = uu.u.bn;
}
abyte0[j2] = (byte)l2;
j2 += c;
d15 += d16;
}

d10 += d12;
d11 += d13;
}

d1 += d5;
d2 += d6;
d3 += d7;
d4 += d8;
}
}
}
}
}

public void a(int i, int j, byte[] abyte0, kd[] abiomegenbase)
{
double d = 0.03125D;
this.r = this.n.a(this.r, i * 16, j * 16, 0.0D, 16, 16, 1, d, d, 1.0D);
this.s = this.n.a(this.s, i * 16, 109.0134D, j * 16, 16, 1, 16, d, 1.0D, d);
this.t = this.o.a(this.t, i * 16, j * 16, 0.0D, 16, 16, 1, d * 2.0D, d * 2.0D, d * 2.0D);
for (int k = 0; k < 16; k++)
{
for (int l = 0; l < 16; l++)
{
kd biomegenbase = abiomegenbase[(k + l * 16)];
int i1 = (int)(this.t[(k + l * 16)] / 3.0D + 3.0D + this.j.nextDouble() * 0.25D);
int j1 = -1;
byte byte0 = biomegenbase.p;
byte byte1 = biomegenbase.q;
for (int k1 = 127; k1 >= 0; k1--)
{
int l1 = (l * 16 + k) * 128 + k1;
byte byte2 = abyte0[l1];
if (byte2 == 0)
{
j1 = -1;
}
else {
if (byte2 != uu.u.bn)
{
continue;
}
if (j1 == -1)
{
if (i1 <= 0)
{
byte0 = 0;
byte1 = (byte)uu.u.bn;
}
j1 = i1;
if (k1 >= 0)
{
abyte0[l1] = byte0;
}
else
abyte0[l1] = byte1;
}
else
{
if (j1 <= 0)
{
continue;
}
j1--;
abyte0[l1] = byte1;
if ((j1 != 0) || (byte1 != uu.F.bn))
continue;
j1 = this.j.nextInt(4);
byte1 = (byte)uu.R.bn;
}
}
}
}
}
}

public lm c(int i, int j)
{
return b(i, j);
}

public ChunkCube prepareCube(int i, int y, int j) {
return provideCube(i, y, j);
}

public ChunkCube provideCube(int x, int y, int z)
{
lm chunk = this.worldObj.c(x, z);

if ((chunk == null) || (chunk.p))
{
chunk = b(x, y);
}

if ((y < 0) || (y >= 8 ))
{
byte[] data = new byte[4096];

ChunkCube cube = new ChunkCube(chunk, data, y + 128 );
cube.isAir = true;
cube.isChunkLoaded = true;
chunk.cubes[(y + 128 )] = cube;
for (int n = 0; n < cube.skylightMap.a.length; n++)
{
cube.skylightMap.a[n] = -1;
}
return cube;
}

chunk.c();
return chunk.cubes[(y + 128 )];
}

public lm b(int i, int j)
{
this.j.setSeed(i * 341873128712L + j * 132897987541L);
byte[] data = new byte[32768];
this.v = this.worldObj.a().a(this.v, i * 16, j * 16, 16, 16);
double[] ad = this.worldObj.a().a;
a(i, j, data, this.v, ad);
a(i, j, data, this.v);
this.u.a(this, this.worldObj, i, j, data);

lm chunk = new lm(this.worldObj, data, i, j);

chunk.c();
return chunk;
}

private double[] a(double[] ad, int i, int j, int k, int l, int i1, int j1)
{
if (ad == null)
{
ad = new double[l * i1 * j1];
}
double d = 684.41200000000003D;
double d1 = 684.41200000000003D;
double[] ad1 = this.worldObj.a().a;
double[] ad2 = this.worldObj.a().b;
this.g = this.a.a(this.g, i, k, l, j1, 1.121D, 1.121D, 0.5D);
this.h = this.b.a(this.h, i, k, l, j1, 200.0D, 200.0D, 0.5D);
d *= 2.0D;
this.d = this.m.a(this.d, i, j, k, l, i1, j1, d / 80.0D, d1 / 160.0D, d / 80.0D);
this.e = this.k.a(this.e, i, j, k, l, i1, j1, d, d1, d);
this.f = this.l.a(this.f, i, j, k, l, i1, j1, d, d1, d);
int k1 = 0;
int l1 = 0;
int i2 = 16 / l;
for (int j2 = 0; j2 < l; j2++)
{
int k2 = j2 * i2 + i2 / 2;
for (int l2 = 0; l2 < j1; l2++)
{
int i3 = l2 * i2 + i2 / 2;
double d2 = ad1[(k2 * 16 + i3)];
double d3 = ad2[(k2 * 16 + i3)] * d2;
double d4 = 1.0D - d3;
d4 *= d4;
d4 *= d4;
d4 = 1.0D - d4;
double d5 = (this.g[l1] + 256.0D) / 512.0D;
d5 *= d4;
if (d5 > 1.0D)
{
d5 = 1.0D;
}
double d6 = this.h[l1] / 8000.0D;
if (d6 < 0.0D)
{
d6 = -d6 * 0.3D;
}
d6 = d6 * 3.0D - 2.0D;
if (d6 > 1.0D)
{
d6 = 1.0D;
}
d6 /= 8.0D;
d6 = 0.0D;
if (d5 < 0.0D)
{
d5 = 0.0D;
}
d5 += 0.5D;
d6 = d6 * i1 / 16.0D;
l1++;
double d7 = i1 / 2.0D;
for (int j3 = 0; j3 < i1; j3++)
{
double d8 = 0.0D;
double d9 = (j3 - d7) * 8.0D / d5;
if (d9 < 0.0D)
{
d9 *= -1.0D;
}
double d10 = this.e[k1] / 512.0D;
double d11 = this.f[k1] / 512.0D;
double d12 = (this.d[k1] / 10.0D + 1.0D) / 2.0D;
if (d12 < 0.0D)
{
d8 = d10;
}
else if (d12 > 1.0D)
{
d8 = d11;
}
else {
d8 = d10 + (d11 - d10) * d12;
}
d8 -= 8.0D;
int k3 = 32;
if (j3 > i1 - k3)
{
double d13 = (j3 - (i1 - k3)) / (k3 - 1.0F);
d8 = d8 * (1.0D - d13) + -30.0D * d13;
}
k3 = 8;
if (j3 < k3)
{
double d14 = (k3 - j3) / (k3 - 1.0F);
d8 = d8 * (1.0D - d14) + -30.0D * d14;
}
ad[k1] = d8;
k1++;
}

}

}

return ad;
}

public boolean a(int i, int j)
{
return true;
}

public boolean cubeExists(int i, int y, int j)
{
return true;
}

public void populate(cl ichunkprovider, int x, int y, int z)
{
}

public void a(cl ichunkprovider, int i, int j)
{
gk.a = true;
int k = i * 16;
int l = j * 16;
kd biomegenbase = this.worldObj.a().a(k + 16, l + 16);
this.j.setSeed(this.worldObj.s());
long l1 = this.j.nextLong() / 2L * 2L + 1L;
long l2 = this.j.nextLong() / 2L * 2L + 1L;
this.j.setSeed(i * l1 + j * l2 ^ this.worldObj.s());
double d = 0.25D;
if (this.j.nextInt(4) == 0)
{
int i1 = k + this.j.nextInt(16) + 8;
int l4 = this.j.nextInt(128 );
int i8 = l + this.j.nextInt(16) + 8;
new dj(uu.C.bn).a(this.worldObj, this.j, i1, l4, i8 );
}
if (this.j.nextInt(8 ) == 0)
{
int j1 = k + this.j.nextInt(16) + 8;
int i5 = this.j.nextInt(this.j.nextInt(120) + 8 );
int j8 = l + this.j.nextInt(16) + 8;
if ((i5 < 64) || (this.j.nextInt(10) == 0))
{
new dj(uu.E.bn).a(this.worldObj, this.j, j1, i5, j8 );
}
}
for (int k1 = 0; k1 < 8; k1++)
{
int j5 = k + this.j.nextInt(16) + 8;
int k8 = this.j.nextInt(128 );
int i13 = l + this.j.nextInt(16) + 8;
new er().a(this.worldObj, this.j, j5, k8, i13);
}

for (int i2 = 0; i2 < 10; i2++)
{
int k5 = k + this.j.nextInt(16);
int l8 = this.j.nextInt(128 );
int j13 = l + this.j.nextInt(16);
new ms(32).a(this.worldObj, this.j, k5, l8, j13);
}

for (int j2 = 0; j2 < 20; j2++)
{
int l5 = k + this.j.nextInt(16);
int i9 = this.j.nextInt(128 );
int k13 = l + this.j.nextInt(16);
new fl(uu.w.bn, 32).a(this.worldObj, this.j, l5, i9, k13);
}

for (int k2 = 0; k2 < 10; k2++)
{
int i6 = k + this.j.nextInt(16);
int j9 = this.j.nextInt(128 );
int l13 = l + this.j.nextInt(16);
new fl(uu.G.bn, 32).a(this.worldObj, this.j, i6, j9, l13);
}

for (int i3 = 0; i3 < 20; i3++)
{
int j6 = k + this.j.nextInt(16);
int k9 = this.j.nextInt(128 );
int i14 = l + this.j.nextInt(16);
new fl(uu.J.bn, 16).a(this.worldObj, this.j, j6, k9, i14);
}

for (int j3 = 0; j3 < 20; j3++)
{
int k6 = k + this.j.nextInt(16);
int l9 = this.j.nextInt(64);
int j14 = l + this.j.nextInt(16);
new fl(uu.I.bn, 8 ).a(this.worldObj, this.j, k6, l9, j14);
}

for (int k3 = 0; k3 < 2; k3++)
{
int l6 = k + this.j.nextInt(16);
int i10 = this.j.nextInt(32);
int k14 = l + this.j.nextInt(16);
new fl(uu.H.bn, 8 ).a(this.worldObj, this.j, l6, i10, k14);
}

for (int l3 = 0; l3 < 8; l3++)
{
int i7 = k + this.j.nextInt(16);
int j10 = this.j.nextInt(16);
int l14 = l + this.j.nextInt(16);
new fl(uu.aO.bn, 7).a(this.worldObj, this.j, i7, j10, l14);
}

for (int i4 = 0; i4 < 1; i4++)
{
int j7 = k + this.j.nextInt(16);
int k10 = this.j.nextInt(16);
int i15 = l + this.j.nextInt(16);
new fl(uu.ax.bn, 7).a(this.worldObj, this.j, j7, k10, i15);
}

for (int j4 = 0; j4 < 1; j4++)
{
int k7 = k + this.j.nextInt(16);
int l10 = this.j.nextInt(16) + this.j.nextInt(16);
int j15 = l + this.j.nextInt(16);
new fl(uu.O.bn, 6).a(this.worldObj, this.j, k7, l10, j15);
}

d = 0.5D;
int k4 = (int)((this.c.a(k * d, l * d) / 8.0D + this.j.nextDouble() * 4.0D + 4.0D) / 3.0D);
int l7 = 0;
if (this.j.nextInt(10) == 0)
{
l7++;
}
if (biomegenbase == kd.d)
{
l7 += k4 + 5;
}
if (biomegenbase == kd.a)
{
l7 += k4 + 5;
}
if (biomegenbase == kd.c)
{
l7 += k4 + 2;
}
if (biomegenbase == kd.g)
{
l7 += k4 + 5;
}
if (biomegenbase == kd.h)
{
l7 -= 20;
}
if (biomegenbase == kd.k)
{
l7 -= 20;
}
if (biomegenbase == kd.i)
{
l7 -= 20;
}
for (int i11 = 0; i11 < l7; i11++)
{
int k15 = k + this.j.nextInt(16) + 8;
int j18 = l + this.j.nextInt(16) + 8;
pg worldgenerator = biomegenbase.a(this.j);
worldgenerator.a(1.0D, 1.0D, 1.0D);
worldgenerator.a(this.worldObj, this.j, k15, this.worldObj.d(k15, j18 ), j18 );
}

for (int j11 = 0; j11 < 2; j11++)
{
int l15 = k + this.j.nextInt(16) + 8;
int k18 = this.j.nextInt(128 );
int i21 = l + this.j.nextInt(16) + 8;
new be(uu.ae.bn).a(this.worldObj, this.j, l15, k18, i21);
}

if (this.j.nextInt(2) == 0)
{
int k11 = k + this.j.nextInt(16) + 8;
int i16 = this.j.nextInt(128 );
int l18 = l + this.j.nextInt(16) + 8;
new be(uu.af.bn).a(this.worldObj, this.j, k11, i16, l18 );
}
if (this.j.nextInt(4) == 0)
{
int l11 = k + this.j.nextInt(16) + 8;
int j16 = this.j.nextInt(128 );
int i19 = l + this.j.nextInt(16) + 8;
new be(uu.ag.bn).a(this.worldObj, this.j, l11, j16, i19);
}
if (this.j.nextInt(8 ) == 0)
{
int i12 = k + this.j.nextInt(16) + 8;
int k16 = this.j.nextInt(128 );
int j19 = l + this.j.nextInt(16) + 8;
new be(uu.ah.bn).a(this.worldObj, this.j, i12, k16, j19);
}
for (int j12 = 0; j12 < 10; j12++)
{
int l16 = k + this.j.nextInt(16) + 8;
int k19 = this.j.nextInt(128 );
int j21 = l + this.j.nextInt(16) + 8;
new ir().a(this.worldObj, this.j, l16, k19, j21);
}

if (this.j.nextInt(32) == 0)
{
int k12 = k + this.j.nextInt(16) + 8;
int i17 = this.j.nextInt(128 );
int l19 = l + this.j.nextInt(16) + 8;
new wx().a(this.worldObj, this.j, k12, i17, l19);
}
int l12 = 0;
if (biomegenbase == kd.h)
{
l12 += 10;
}
for (int j17 = 0; j17 < l12; j17++)
{
int i20 = k + this.j.nextInt(16) + 8;
int k21 = this.j.nextInt(128 );
int k22 = l + this.j.nextInt(16) + 8;
new fx().a(this.worldObj, this.j, i20, k21, k22);
}

for (int k17 = 0; k17 < 50; k17++)
{
int j20 = k + this.j.nextInt(16) + 8;
int l21 = this.j.nextInt(this.j.nextInt(120) + 8 );
int l22 = l + this.j.nextInt(16) + 8;
new xo(uu.B.bn).a(this.worldObj, this.j, j20, l21, l22);
}

for (int l17 = 0; l17 < 20; l17++)
{
int k20 = k + this.j.nextInt(16) + 8;
int i22 = this.j.nextInt(this.j.nextInt(this.j.nextInt(112) + 8 ) + 8 );
int i23 = l + this.j.nextInt(16) + 8;
new xo(uu.D.bn).a(this.worldObj, this.j, k20, i22, i23);
}

this.w = this.worldObj.a().a(this.w, k + 8, l + 8, 16, 16);
for (int i18 = k + 8; i18 < k + 8 + 16; i18++)
{
for (int l20 = l + 8; l20 < l + 8 + 16; l20++)
{
int j22 = i18 - (k + 8 );
int j23 = l20 - (l + 8 );
int k23 = this.worldObj.e(i18, l20);
double d1 = this.w[(j22 * 16 + j23)] - (k23 - 64) / 64.0D * 0.3D;
if ((d1 >= 0.5D) || (k23 <= 0) || (k23 >= 128 ) || (!this.worldObj.d(i18, k23, l20)) || (!this.worldObj.f(i18, k23 - 1, l20).c()) || (this.worldObj.f(i18, k23 - 1, l20) == ln.s))
continue;
this.worldObj.f(i18, k23, l20, uu.aT.bn);
}

}

gk.a = false;
}

public boolean a(boolean flag, yb iprogressupdate)
{
return true;
}

public boolean a()
{
return false;
}

public boolean b()
{
return true;
}

public String c()
{
return "RandomLevelSource";
}
}
import java.util.Random;

public class jd
implements cl
{
private Random j;
private uf k;
private uf l;
private uf m;
private uf n;
private uf o;
public uf a;
public uf b;
public uf c;
private fd worldObj;
private double[] q;
private double[] r;
private double[] s;
private double[] t;
private fv u;
private kd[] v;
double[] d;
double[] e;
double[] f;
double[] g;
double[] h;
int[][] i;
private double[] w;

public jd(fd world, long l)
{
this.r = new double[256];
this.s = new double[256];
this.t = new double[256];
this.u = new sq();
this.i = new int[32][32];
this.worldObj = world;
this.j = new Random(l);
this.k = new uf(this.j, 16);
this.l = new uf(this.j, 16);
this.m = new uf(this.j, 8 );
this.n = new uf(this.j, 4);
this.o = new uf(this.j, 4);
this.a = new uf(this.j, 10);
this.b = new uf(this.j, 16);
this.c = new uf(this.j, 8 );
}

public void a(int i, int j, byte[] abyte0, kd[] abiomegenbase, double[] ad)
{
byte byte0 = 2;
int k = byte0 + 1;
byte byte1 = 33;
int l = byte0 + 1;
this.q = a(this.q, i * byte0, 0, j * byte0, k, byte1, l);
for (int i1 = 0; i1 < byte0; i1++)
{
for (int j1 = 0; j1 < byte0; j1++)
{
for (int k1 = 0; k1 < 32; k1++)
{
double d = 0.25D;
double d1 = this.q[(((i1 + 0) * l + (j1 + 0)) * byte1 + (k1 + 0))];
double d2 = this.q[(((i1 + 0) * l + (j1 + 1)) * byte1 + (k1 + 0))];
double d3 = this.q[(((i1 + 1) * l + (j1 + 0)) * byte1 + (k1 + 0))];
double d4 = this.q[(((i1 + 1) * l + (j1 + 1)) * byte1 + (k1 + 0))];
double d5 = (this.q[(((i1 + 0) * l + (j1 + 0)) * byte1 + (k1 + 1))] - d1) * d;
double d6 = (this.q[(((i1 + 0) * l + (j1 + 1)) * byte1 + (k1 + 1))] - d2) * d;
double d7 = (this.q[(((i1 + 1) * l + (j1 + 0)) * byte1 + (k1 + 1))] - d3) * d;
double d8 = (this.q[(((i1 + 1) * l + (j1 + 1)) * byte1 + (k1 + 1))] - d4) * d;
for (int l1 = 0; l1 < 4; l1++)
{
double d9 = 0.125D;
double d10 = d1;
double d11 = d2;
double d12 = (d3 - d1) * d9;
double d13 = (d4 - d2) * d9;
for (int i2 = 0; i2 < 8; i2++)
{
int j2 = i2 + i1 * 8 << 11 | 0 + j1 * 8 << 7 | k1 * 4 + l1;
char c = '€';
double d14 = 0.125D;
double d15 = d10;
double d16 = (d11 - d10) * d14;
for (int k2 = 0; k2 < 8; k2++)
{
int l2 = 0;
if (d15 > 0.0D)
{
l2 = uu.u.bn;
}
abyte0[j2] = (byte)l2;
j2 += c;
d15 += d16;
}

d10 += d12;
d11 += d13;
}

d1 += d5;
d2 += d6;
d3 += d7;
d4 += d8;
}
}
}
}
}

public void a(int i, int j, byte[] abyte0, kd[] abiomegenbase)
{
double d = 0.03125D;
this.r = this.n.a(this.r, i * 16, j * 16, 0.0D, 16, 16, 1, d, d, 1.0D);
this.s = this.n.a(this.s, i * 16, 109.0134D, j * 16, 16, 1, 16, d, 1.0D, d);
this.t = this.o.a(this.t, i * 16, j * 16, 0.0D, 16, 16, 1, d * 2.0D, d * 2.0D, d * 2.0D);
for (int k = 0; k < 16; k++)
{
for (int l = 0; l < 16; l++)
{
kd biomegenbase = abiomegenbase[(k + l * 16)];
int i1 = (int)(this.t[(k + l * 16)] / 3.0D + 3.0D + this.j.nextDouble() * 0.25D);
int j1 = -1;
byte byte0 = biomegenbase.p;
byte byte1 = biomegenbase.q;
for (int k1 = 127; k1 >= 0; k1--)
{
int l1 = (l * 16 + k) * 128 + k1;
byte byte2 = abyte0[l1];
if (byte2 == 0)
{
j1 = -1;
}
else {
if (byte2 != uu.u.bn)
{
continue;
}
if (j1 == -1)
{
if (i1 <= 0)
{
byte0 = 0;
byte1 = (byte)uu.u.bn;
}
j1 = i1;
if (k1 >= 0)
{
abyte0[l1] = byte0;
}
else
abyte0[l1] = byte1;
}
else
{
if (j1 <= 0)
{
continue;
}
j1--;
abyte0[l1] = byte1;
if ((j1 != 0) || (byte1 != uu.F.bn))
continue;
j1 = this.j.nextInt(4);
byte1 = (byte)uu.R.bn;
}
}
}
}
}
}

public lm c(int i, int j)
{
return b(i, j);
}

public ChunkCube prepareCube(int i, int y, int j) {
return provideCube(i, y, j);
}

public ChunkCube provideCube(int x, int y, int z)
{
lm chunk = this.worldObj.c(x, z);

if ((chunk == null) || (chunk.p))
{
chunk = b(x, y);
}

if ((y < 0) || (y >= 8 ))
{
byte[] data = new byte[4096];

ChunkCube cube = new ChunkCube(chunk, data, y + 128 );
cube.isAir = true;
cube.isChunkLoaded = true;
chunk.cubes[(y + 128 )] = cube;
for (int n = 0; n < cube.skylightMap.a.length; n++)
{
cube.skylightMap.a[n] = -1;
}
return cube;
}

chunk.c();
return chunk.cubes[(y + 128 )];
}

public lm b(int i, int j)
{
this.j.setSeed(i * 341873128712L + j * 132897987541L);
byte[] data = new byte[32768];
this.v = this.worldObj.a().a(this.v, i * 16, j * 16, 16, 16);
double[] ad = this.worldObj.a().a;
a(i, j, data, this.v, ad);
a(i, j, data, this.v);
this.u.a(this, this.worldObj, i, j, data);

lm chunk = new lm(this.worldObj, data, i, j);

chunk.c();
return chunk;
}

private double[] a(double[] ad, int i, int j, int k, int l, int i1, int j1)
{
if (ad == null)
{
ad = new double[l * i1 * j1];
}
double d = 684.41200000000003D;
double d1 = 684.41200000000003D;
double[] ad1 = this.worldObj.a().a;
double[] ad2 = this.worldObj.a().b;
this.g = this.a.a(this.g, i, k, l, j1, 1.121D, 1.121D, 0.5D);
this.h = this.b.a(this.h, i, k, l, j1, 200.0D, 200.0D, 0.5D);
d *= 2.0D;
this.d = this.m.a(this.d, i, j, k, l, i1, j1, d / 80.0D, d1 / 160.0D, d / 80.0D);
this.e = this.k.a(this.e, i, j, k, l, i1, j1, d, d1, d);
this.f = this.l.a(this.f, i, j, k, l, i1, j1, d, d1, d);
int k1 = 0;
int l1 = 0;
int i2 = 16 / l;
for (int j2 = 0; j2 < l; j2++)
{
int k2 = j2 * i2 + i2 / 2;
for (int l2 = 0; l2 < j1; l2++)
{
int i3 = l2 * i2 + i2 / 2;
double d2 = ad1[(k2 * 16 + i3)];
double d3 = ad2[(k2 * 16 + i3)] * d2;
double d4 = 1.0D - d3;
d4 *= d4;
d4 *= d4;
d4 = 1.0D - d4;
double d5 = (this.g[l1] + 256.0D) / 512.0D;
d5 *= d4;
if (d5 > 1.0D)
{
d5 = 1.0D;
}
double d6 = this.h[l1] / 8000.0D;
if (d6 < 0.0D)
{
d6 = -d6 * 0.3D;
}
d6 = d6 * 3.0D - 2.0D;
if (d6 > 1.0D)
{
d6 = 1.0D;
}
d6 /= 8.0D;
d6 = 0.0D;
if (d5 < 0.0D)
{
d5 = 0.0D;
}
d5 += 0.5D;
d6 = d6 * i1 / 16.0D;
l1++;
double d7 = i1 / 2.0D;
for (int j3 = 0; j3 < i1; j3++)
{
double d8 = 0.0D;
double d9 = (j3 - d7) * 8.0D / d5;
if (d9 < 0.0D)
{
d9 *= -1.0D;
}
double d10 = this.e[k1] / 512.0D;
double d11 = this.f[k1] / 512.0D;
double d12 = (this.d[k1] / 10.0D + 1.0D) / 2.0D;
if (d12 < 0.0D)
{
d8 = d10;
}
else if (d12 > 1.0D)
{
d8 = d11;
}
else {
d8 = d10 + (d11 - d10) * d12;
}
d8 -= 8.0D;
int k3 = 32;
if (j3 > i1 - k3)
{
double d13 = (j3 - (i1 - k3)) / (k3 - 1.0F);
d8 = d8 * (1.0D - d13) + -30.0D * d13;
}
k3 = 8;
if (j3 < k3)
{
double d14 = (k3 - j3) / (k3 - 1.0F);
d8 = d8 * (1.0D - d14) + -30.0D * d14;
}
ad[k1] = d8;
k1++;
}

}

}

return ad;
}

public boolean a(int i, int j)
{
return true;
}

public boolean cubeExists(int i, int y, int j)
{
return true;
}

public void populate(cl ichunkprovider, int x, int y, int z)
{
}

public void a(cl ichunkprovider, int i, int j)
{
gk.a = true;
int k = i * 16;
int l = j * 16;
kd biomegenbase = this.worldObj.a().a(k + 16, l + 16);
this.j.setSeed(this.worldObj.s());
long l1 = this.j.nextLong() / 2L * 2L + 1L;
long l2 = this.j.nextLong() / 2L * 2L + 1L;
this.j.setSeed(i * l1 + j * l2 ^ this.worldObj.s());
double d = 0.25D;
if (this.j.nextInt(4) == 0)
{
int i1 = k + this.j.nextInt(16) + 8;
int l4 = this.j.nextInt(128 );
int i8 = l + this.j.nextInt(16) + 8;
new dj(uu.C.bn).a(this.worldObj, this.j, i1, l4, i8 );
}
if (this.j.nextInt(8 ) == 0)
{
int j1 = k + this.j.nextInt(16) + 8;
int i5 = this.j.nextInt(this.j.nextInt(120) + 8 );
int j8 = l + this.j.nextInt(16) + 8;
if ((i5 < 64) || (this.j.nextInt(10) == 0))
{
new dj(uu.E.bn).a(this.worldObj, this.j, j1, i5, j8 );
}
}
for (int k1 = 0; k1 < 8; k1++)
{
int j5 = k + this.j.nextInt(16) + 8;
int k8 = this.j.nextInt(128 );
int i13 = l + this.j.nextInt(16) + 8;
new er().a(this.worldObj, this.j, j5, k8, i13);
}

for (int i2 = 0; i2 < 10; i2++)
{
int k5 = k + this.j.nextInt(16);
int l8 = this.j.nextInt(128 );
int j13 = l + this.j.nextInt(16);
new ms(32).a(this.worldObj, this.j, k5, l8, j13);
}

for (int j2 = 0; j2 < 20; j2++)
{
int l5 = k + this.j.nextInt(16);
int i9 = this.j.nextInt(128 );
int k13 = l + this.j.nextInt(16);
new fl(uu.w.bn, 32).a(this.worldObj, this.j, l5, i9, k13);
}

for (int k2 = 0; k2 < 10; k2++)
{
int i6 = k + this.j.nextInt(16);
int j9 = this.j.nextInt(128 );
int l13 = l + this.j.nextInt(16);
new fl(uu.G.bn, 32).a(this.worldObj, this.j, i6, j9, l13);
}

for (int i3 = 0; i3 < 20; i3++)
{
int j6 = k + this.j.nextInt(16);
int k9 = this.j.nextInt(128 );
int i14 = l + this.j.nextInt(16);
new fl(uu.J.bn, 16).a(this.worldObj, this.j, j6, k9, i14);
}

for (int j3 = 0; j3 < 20; j3++)
{
int k6 = k + this.j.nextInt(16);
int l9 = this.j.nextInt(64);
int j14 = l + this.j.nextInt(16);
new fl(uu.I.bn, 8 ).a(this.worldObj, this.j, k6, l9, j14);
}

for (int k3 = 0; k3 < 2; k3++)
{
int l6 = k + this.j.nextInt(16);
int i10 = this.j.nextInt(32);
int k14 = l + this.j.nextInt(16);
new fl(uu.H.bn, 8 ).a(this.worldObj, this.j, l6, i10, k14);
}

for (int l3 = 0; l3 < 8; l3++)
{
int i7 = k + this.j.nextInt(16);
int j10 = this.j.nextInt(16);
int l14 = l + this.j.nextInt(16);
new fl(uu.aO.bn, 7).a(this.worldObj, this.j, i7, j10, l14);
}

for (int i4 = 0; i4 < 1; i4++)
{
int j7 = k + this.j.nextInt(16);
int k10 = this.j.nextInt(16);
int i15 = l + this.j.nextInt(16);
new fl(uu.ax.bn, 7).a(this.worldObj, this.j, j7, k10, i15);
}

for (int j4 = 0; j4 < 1; j4++)
{
int k7 = k + this.j.nextInt(16);
int l10 = this.j.nextInt(16) + this.j.nextInt(16);
int j15 = l + this.j.nextInt(16);
new fl(uu.O.bn, 6).a(this.worldObj, this.j, k7, l10, j15);
}

d = 0.5D;
int k4 = (int)((this.c.a(k * d, l * d) / 8.0D + this.j.nextDouble() * 4.0D + 4.0D) / 3.0D);
int l7 = 0;
if (this.j.nextInt(10) == 0)
{
l7++;
}
if (biomegenbase == kd.d)
{
l7 += k4 + 5;
}
if (biomegenbase == kd.a)
{
l7 += k4 + 5;
}
if (biomegenbase == kd.c)
{
l7 += k4 + 2;
}
if (biomegenbase == kd.g)
{
l7 += k4 + 5;
}
if (biomegenbase == kd.h)
{
l7 -= 20;
}
if (biomegenbase == kd.k)
{
l7 -= 20;
}
if (biomegenbase == kd.i)
{
l7 -= 20;
}
for (int i11 = 0; i11 < l7; i11++)
{
int k15 = k + this.j.nextInt(16) + 8;
int j18 = l + this.j.nextInt(16) + 8;
pg worldgenerator = biomegenbase.a(this.j);
worldgenerator.a(1.0D, 1.0D, 1.0D);
worldgenerator.a(this.worldObj, this.j, k15, this.worldObj.d(k15, j18 ), j18 );
}

for (int j11 = 0; j11 < 2; j11++)
{
int l15 = k + this.j.nextInt(16) + 8;
int k18 = this.j.nextInt(128 );
int i21 = l + this.j.nextInt(16) + 8;
new be(uu.ae.bn).a(this.worldObj, this.j, l15, k18, i21);
}

if (this.j.nextInt(2) == 0)
{
int k11 = k + this.j.nextInt(16) + 8;
int i16 = this.j.nextInt(128 );
int l18 = l + this.j.nextInt(16) + 8;
new be(uu.af.bn).a(this.worldObj, this.j, k11, i16, l18 );
}
if (this.j.nextInt(4) == 0)
{
int l11 = k + this.j.nextInt(16) + 8;
int j16 = this.j.nextInt(128 );
int i19 = l + this.j.nextInt(16) + 8;
new be(uu.ag.bn).a(this.worldObj, this.j, l11, j16, i19);
}
if (this.j.nextInt(8 ) == 0)
{
int i12 = k + this.j.nextInt(16) + 8;
int k16 = this.j.nextInt(128 );
int j19 = l + this.j.nextInt(16) + 8;
new be(uu.ah.bn).a(this.worldObj, this.j, i12, k16, j19);
}
for (int j12 = 0; j12 < 10; j12++)
{
int l16 = k + this.j.nextInt(16) + 8;
int k19 = this.j.nextInt(128 );
int j21 = l + this.j.nextInt(16) + 8;
new ir().a(this.worldObj, this.j, l16, k19, j21);
}

if (this.j.nextInt(32) == 0)
{
int k12 = k + this.j.nextInt(16) + 8;
int i17 = this.j.nextInt(128 );
int l19 = l + this.j.nextInt(16) + 8;
new wx().a(this.worldObj, this.j, k12, i17, l19);
}
int l12 = 0;
if (biomegenbase == kd.h)
{
l12 += 10;
}
for (int j17 = 0; j17 < l12; j17++)
{
int i20 = k + this.j.nextInt(16) + 8;
int k21 = this.j.nextInt(128 );
int k22 = l + this.j.nextInt(16) + 8;
new fx().a(this.worldObj, this.j, i20, k21, k22);
}

for (int k17 = 0; k17 < 50; k17++)
{
int j20 = k + this.j.nextInt(16) + 8;
int l21 = this.j.nextInt(this.j.nextInt(120) + 8 );
int l22 = l + this.j.nextInt(16) + 8;
new xo(uu.B.bn).a(this.worldObj, this.j, j20, l21, l22);
}

for (int l17 = 0; l17 < 20; l17++)
{
int k20 = k + this.j.nextInt(16) + 8;
int i22 = this.j.nextInt(this.j.nextInt(this.j.nextInt(112) + 8 ) + 8 );
int i23 = l + this.j.nextInt(16) + 8;
new xo(uu.D.bn).a(this.worldObj, this.j, k20, i22, i23);
}

this.w = this.worldObj.a().a(this.w, k + 8, l + 8, 16, 16);
for (int i18 = k + 8; i18 < k + 8 + 16; i18++)
{
for (int l20 = l + 8; l20 < l + 8 + 16; l20++)
{
int j22 = i18 - (k + 8 );
int j23 = l20 - (l + 8 );
int k23 = this.worldObj.e(i18, l20);
double d1 = this.w[(j22 * 16 + j23)] - (k23 - 64) / 64.0D * 0.3D;
if ((d1 >= 0.5D) || (k23 <= 0) || (k23 >= 128 ) || (!this.worldObj.d(i18, k23, l20)) || (!this.worldObj.f(i18, k23 - 1, l20).c()) || (this.worldObj.f(i18, k23 - 1, l20) == ln.s))
continue;
this.worldObj.f(i18, k23, l20, uu.aT.bn);
}

}

gk.a = false;
}

public boolean a(boolean flag, yb iprogressupdate)
{
return true;
}

public boolean a()
{
return false;
}

public boolean b()
{
return true;
}

public String c()
{
return "RandomLevelSource";
}
}
import java.util.Random;

public class jd
implements cl
{
private Random j;
private uf k;
private uf l;
private uf m;
private uf n;
private uf o;
public uf a;
public uf b;
public uf c;
private fd worldObj;
private double[] q;
private double[] r;
private double[] s;
private double[] t;
private fv u;
private kd[] v;
double[] d;
double[] e;
double[] f;
double[] g;
double[] h;
int[][] i;
private double[] w;

public jd(fd world, long l)
{
this.r = new double[256];
this.s = new double[256];
this.t = new double[256];
this.u = new sq();
this.i = new int[32][32];
this.worldObj = world;
this.j = new Random(l);
this.k = new uf(this.j, 16);
this.l = new uf(this.j, 16);
this.m = new uf(this.j, 8 );
this.n = new uf(this.j, 4);
this.o = new uf(this.j, 4);
this.a = new uf(this.j, 10);
this.b = new uf(this.j, 16);
this.c = new uf(this.j, 8 );
}

public void a(int i, int j, byte[] abyte0, kd[] abiomegenbase, double[] ad)
{
byte byte0 = 2;
int k = byte0 + 1;
byte byte1 = 33;
int l = byte0 + 1;
this.q = a(this.q, i * byte0, 0, j * byte0, k, byte1, l);
for (int i1 = 0; i1 < byte0; i1++)
{
for (int j1 = 0; j1 < byte0; j1++)
{
for (int k1 = 0; k1 < 32; k1++)
{
double d = 0.25D;
double d1 = this.q[(((i1 + 0) * l + (j1 + 0)) * byte1 + (k1 + 0))];
double d2 = this.q[(((i1 + 0) * l + (j1 + 1)) * byte1 + (k1 + 0))];
double d3 = this.q[(((i1 + 1) * l + (j1 + 0)) * byte1 + (k1 + 0))];
double d4 = this.q[(((i1 + 1) * l + (j1 + 1)) * byte1 + (k1 + 0))];
double d5 = (this.q[(((i1 + 0) * l + (j1 + 0)) * byte1 + (k1 + 1))] - d1) * d;
double d6 = (this.q[(((i1 + 0) * l + (j1 + 1)) * byte1 + (k1 + 1))] - d2) * d;
double d7 = (this.q[(((i1 + 1) * l + (j1 + 0)) * byte1 + (k1 + 1))] - d3) * d;
double d8 = (this.q[(((i1 + 1) * l + (j1 + 1)) * byte1 + (k1 + 1))] - d4) * d;
for (int l1 = 0; l1 < 4; l1++)
{
double d9 = 0.125D;
double d10 = d1;
double d11 = d2;
double d12 = (d3 - d1) * d9;
double d13 = (d4 - d2) * d9;
for (int i2 = 0; i2 < 8; i2++)
{
int j2 = i2 + i1 * 8 << 11 | 0 + j1 * 8 << 7 | k1 * 4 + l1;
char c = '€';
double d14 = 0.125D;
double d15 = d10;
double d16 = (d11 - d10) * d14;
for (int k2 = 0; k2 < 8; k2++)
{
int l2 = 0;
if (d15 > 0.0D)
{
l2 = uu.u.bn;
}
abyte0[j2] = (byte)l2;
j2 += c;
d15 += d16;
}

d10 += d12;
d11 += d13;
}

d1 += d5;
d2 += d6;
d3 += d7;
d4 += d8;
}
}
}
}
}

public void a(int i, int j, byte[] abyte0, kd[] abiomegenbase)
{
double d = 0.03125D;
this.r = this.n.a(this.r, i * 16, j * 16, 0.0D, 16, 16, 1, d, d, 1.0D);
this.s = this.n.a(this.s, i * 16, 109.0134D, j * 16, 16, 1, 16, d, 1.0D, d);
this.t = this.o.a(this.t, i * 16, j * 16, 0.0D, 16, 16, 1, d * 2.0D, d * 2.0D, d * 2.0D);
for (int k = 0; k < 16; k++)
{
for (int l = 0; l < 16; l++)
{
kd biomegenbase = abiomegenbase[(k + l * 16)];
int i1 = (int)(this.t[(k + l * 16)] / 3.0D + 3.0D + this.j.nextDouble() * 0.25D);
int j1 = -1;
byte byte0 = biomegenbase.p;
byte byte1 = biomegenbase.q;
for (int k1 = 127; k1 >= 0; k1--)
{
int l1 = (l * 16 + k) * 128 + k1;
byte byte2 = abyte0[l1];
if (byte2 == 0)
{
j1 = -1;
}
else {
if (byte2 != uu.u.bn)
{
continue;
}
if (j1 == -1)
{
if (i1 <= 0)
{
byte0 = 0;
byte1 = (byte)uu.u.bn;
}
j1 = i1;
if (k1 >= 0)
{
abyte0[l1] = byte0;
}
else
abyte0[l1] = byte1;
}
else
{
if (j1 <= 0)
{
continue;
}
j1--;
abyte0[l1] = byte1;
if ((j1 != 0) || (byte1 != uu.F.bn))
continue;
j1 = this.j.nextInt(4);
byte1 = (byte)uu.R.bn;
}
}
}
}
}
}

public lm c(int i, int j)
{
return b(i, j);
}

public ChunkCube prepareCube(int i, int y, int j) {
return provideCube(i, y, j);
}

public ChunkCube provideCube(int x, int y, int z)
{
lm chunk = this.worldObj.c(x, z);

if ((chunk == null) || (chunk.p))
{
chunk = b(x, y);
}

if ((y < 0) || (y >= 8 ))
{
byte[] data = new byte[4096];

ChunkCube cube = new ChunkCube(chunk, data, y + 128 );
cube.isAir = true;
cube.isChunkLoaded = true;
chunk.cubes[(y + 128 )] = cube;
for (int n = 0; n < cube.skylightMap.a.length; n++)
{
cube.skylightMap.a[n] = -1;
}
return cube;
}

chunk.c();
return chunk.cubes[(y + 128 )];
}

public lm b(int i, int j)
{
this.j.setSeed(i * 341873128712L + j * 132897987541L);
byte[] data = new byte[32768];
this.v = this.worldObj.a().a(this.v, i * 16, j * 16, 16, 16);
double[] ad = this.worldObj.a().a;
a(i, j, data, this.v, ad);
a(i, j, data, this.v);
this.u.a(this, this.worldObj, i, j, data);

lm chunk = new lm(this.worldObj, data, i, j);

chunk.c();
return chunk;
}

private double[] a(double[] ad, int i, int j, int k, int l, int i1, int j1)
{
if (ad == null)
{
ad = new double[l * i1 * j1];
}
double d = 684.41200000000003D;
double d1 = 684.41200000000003D;
double[] ad1 = this.worldObj.a().a;
double[] ad2 = this.worldObj.a().b;
this.g = this.a.a(this.g, i, k, l, j1, 1.121D, 1.121D, 0.5D);
this.h = this.b.a(this.h, i, k, l, j1, 200.0D, 200.0D, 0.5D);
d *= 2.0D;
this.d = this.m.a(this.d, i, j, k, l, i1, j1, d / 80.0D, d1 / 160.0D, d / 80.0D);
this.e = this.k.a(this.e, i, j, k, l, i1, j1, d, d1, d);
this.f = this.l.a(this.f, i, j, k, l, i1, j1, d, d1, d);
int k1 = 0;
int l1 = 0;
int i2 = 16 / l;
for (int j2 = 0; j2 < l; j2++)
{
int k2 = j2 * i2 + i2 / 2;
for (int l2 = 0; l2 < j1; l2++)
{
int i3 = l2 * i2 + i2 / 2;
double d2 = ad1[(k2 * 16 + i3)];
double d3 = ad2[(k2 * 16 + i3)] * d2;
double d4 = 1.0D - d3;
d4 *= d4;
d4 *= d4;
d4 = 1.0D - d4;
double d5 = (this.g[l1] + 256.0D) / 512.0D;
d5 *= d4;
if (d5 > 1.0D)
{
d5 = 1.0D;
}
double d6 = this.h[l1] / 8000.0D;
if (d6 < 0.0D)
{
d6 = -d6 * 0.3D;
}
d6 = d6 * 3.0D - 2.0D;
if (d6 > 1.0D)
{
d6 = 1.0D;
}
d6 /= 8.0D;
d6 = 0.0D;
if (d5 < 0.0D)
{
d5 = 0.0D;
}
d5 += 0.5D;
d6 = d6 * i1 / 16.0D;
l1++;
double d7 = i1 / 2.0D;
for (int j3 = 0; j3 < i1; j3++)
{
double d8 = 0.0D;
double d9 = (j3 - d7) * 8.0D / d5;
if (d9 < 0.0D)
{
d9 *= -1.0D;
}
double d10 = this.e[k1] / 512.0D;
double d11 = this.f[k1] / 512.0D;
double d12 = (this.d[k1] / 10.0D + 1.0D) / 2.0D;
if (d12 < 0.0D)
{
d8 = d10;
}
else if (d12 > 1.0D)
{
d8 = d11;
}
else {
d8 = d10 + (d11 - d10) * d12;
}
d8 -= 8.0D;
int k3 = 32;
if (j3 > i1 - k3)
{
double d13 = (j3 - (i1 - k3)) / (k3 - 1.0F);
d8 = d8 * (1.0D - d13) + -30.0D * d13;
}
k3 = 8;
if (j3 < k3)
{
double d14 = (k3 - j3) / (k3 - 1.0F);
d8 = d8 * (1.0D - d14) + -30.0D * d14;
}
ad[k1] = d8;
k1++;
}

}

}

return ad;
}

public boolean a(int i, int j)
{
return true;
}

public boolean cubeExists(int i, int y, int j)
{
return true;
}

public void populate(cl ichunkprovider, int x, int y, int z)
{
}

public void a(cl ichunkprovider, int i, int j)
{
gk.a = true;
int k = i * 16;
int l = j * 16;
kd biomegenbase = this.worldObj.a().a(k + 16, l + 16);
this.j.setSeed(this.worldObj.s());
long l1 = this.j.nextLong() / 2L * 2L + 1L;
long l2 = this.j.nextLong() / 2L * 2L + 1L;
this.j.setSeed(i * l1 + j * l2 ^ this.worldObj.s());
double d = 0.25D;
if (this.j.nextInt(4) == 0)
{
int i1 = k + this.j.nextInt(16) + 8;
int l4 = this.j.nextInt(128 );
int i8 = l + this.j.nextInt(16) + 8;
new dj(uu.C.bn).a(this.worldObj, this.j, i1, l4, i8 );
}
if (this.j.nextInt(8 ) == 0)
{
int j1 = k + this.j.nextInt(16) + 8;
int i5 = this.j.nextInt(this.j.nextInt(120) + 8 );
int j8 = l + this.j.nextInt(16) + 8;
if ((i5 < 64) || (this.j.nextInt(10) == 0))
{
new dj(uu.E.bn).a(this.worldObj, this.j, j1, i5, j8 );
}
}
for (int k1 = 0; k1 < 8; k1++)
{
int j5 = k + this.j.nextInt(16) + 8;
int k8 = this.j.nextInt(128 );
int i13 = l + this.j.nextInt(16) + 8;
new er().a(this.worldObj, this.j, j5, k8, i13);
}

for (int i2 = 0; i2 < 10; i2++)
{
int k5 = k + this.j.nextInt(16);
int l8 = this.j.nextInt(128 );
int j13 = l + this.j.nextInt(16);
new ms(32).a(this.worldObj, this.j, k5, l8, j13);
}

for (int j2 = 0; j2 < 20; j2++)
{
int l5 = k + this.j.nextInt(16);
int i9 = this.j.nextInt(128 );
int k13 = l + this.j.nextInt(16);
new fl(uu.w.bn, 32).a(this.worldObj, this.j, l5, i9, k13);
}

for (int k2 = 0; k2 < 10; k2++)
{
int i6 = k + this.j.nextInt(16);
int j9 = this.j.nextInt(128 );
int l13 = l + this.j.nextInt(16);
new fl(uu.G.bn, 32).a(this.worldObj, this.j, i6, j9, l13);
}

for (int i3 = 0; i3 < 20; i3++)
{
int j6 = k + this.j.nextInt(16);
int k9 = this.j.nextInt(128 );
int i14 = l + this.j.nextInt(16);
new fl(uu.J.bn, 16).a(this.worldObj, this.j, j6, k9, i14);
}

for (int j3 = 0; j3 < 20; j3++)
{
int k6 = k + this.j.nextInt(16);
int l9 = this.j.nextInt(64);
int j14 = l + this.j.nextInt(16);
new fl(uu.I.bn, 8 ).a(this.worldObj, this.j, k6, l9, j14);
}

for (int k3 = 0; k3 < 2; k3++)
{
int l6 = k + this.j.nextInt(16);
int i10 = this.j.nextInt(32);
int k14 = l + this.j.nextInt(16);
new fl(uu.H.bn, 8 ).a(this.worldObj, this.j, l6, i10, k14);
}

for (int l3 = 0; l3 < 8; l3++)
{
int i7 = k + this.j.nextInt(16);
int j10 = this.j.nextInt(16);
int l14 = l + this.j.nextInt(16);
new fl(uu.aO.bn, 7).a(this.worldObj, this.j, i7, j10, l14);
}

for (int i4 = 0; i4 < 1; i4++)
{
int j7 = k + this.j.nextInt(16);
int k10 = this.j.nextInt(16);
int i15 = l + this.j.nextInt(16);
new fl(uu.ax.bn, 7).a(this.worldObj, this.j, j7, k10, i15);
}

for (int j4 = 0; j4 < 1; j4++)
{
int k7 = k + this.j.nextInt(16);
int l10 = this.j.nextInt(16) + this.j.nextInt(16);
int j15 = l + this.j.nextInt(16);
new fl(uu.O.bn, 6).a(this.worldObj, this.j, k7, l10, j15);
}

d = 0.5D;
int k4 = (int)((this.c.a(k * d, l * d) / 8.0D + this.j.nextDouble() * 4.0D + 4.0D) / 3.0D);
int l7 = 0;
if (this.j.nextInt(10) == 0)
{
l7++;
}
if (biomegenbase == kd.d)
{
l7 += k4 + 5;
}
if (biomegenbase == kd.a)
{
l7 += k4 + 5;
}
if (biomegenbase == kd.c)
{
l7 += k4 + 2;
}
if (biomegenbase == kd.g)
{
l7 += k4 + 5;
}
if (biomegenbase == kd.h)
{
l7 -= 20;
}
if (biomegenbase == kd.k)
{
l7 -= 20;
}
if (biomegenbase == kd.i)
{
l7 -= 20;
}
for (int i11 = 0; i11 < l7; i11++)
{
int k15 = k + this.j.nextInt(16) + 8;
int j18 = l + this.j.nextInt(16) + 8;
pg worldgenerator = biomegenbase.a(this.j);
worldgenerator.a(1.0D, 1.0D, 1.0D);
worldgenerator.a(this.worldObj, this.j, k15, this.worldObj.d(k15, j18 ), j18 );
}

for (int j11 = 0; j11 < 2; j11++)
{
int l15 = k + this.j.nextInt(16) + 8;
int k18 = this.j.nextInt(128 );
int i21 = l + this.j.nextInt(16) + 8;
new be(uu.ae.bn).a(this.worldObj, this.j, l15, k18, i21);
}

if (this.j.nextInt(2) == 0)
{
int k11 = k + this.j.nextInt(16) + 8;
int i16 = this.j.nextInt(128 );
int l18 = l + this.j.nextInt(16) + 8;
new be(uu.af.bn).a(this.worldObj, this.j, k11, i16, l18 );
}
if (this.j.nextInt(4) == 0)
{
int l11 = k + this.j.nextInt(16) + 8;
int j16 = this.j.nextInt(128 );
int i19 = l + this.j.nextInt(16) + 8;
new be(uu.ag.bn).a(this.worldObj, this.j, l11, j16, i19);
}
if (this.j.nextInt(8 ) == 0)
{
int i12 = k + this.j.nextInt(16) + 8;
int k16 = this.j.nextInt(128 );
int j19 = l + this.j.nextInt(16) + 8;
new be(uu.ah.bn).a(this.worldObj, this.j, i12, k16, j19);
}
for (int j12 = 0; j12 < 10; j12++)
{
int l16 = k + this.j.nextInt(16) + 8;
int k19 = this.j.nextInt(128 );
int j21 = l + this.j.nextInt(16) + 8;
new ir().a(this.worldObj, this.j, l16, k19, j21);
}

if (this.j.nextInt(32) == 0)
{
int k12 = k + this.j.nextInt(16) + 8;
int i17 = this.j.nextInt(128 );
int l19 = l + this.j.nextInt(16) + 8;
new wx().a(this.worldObj, this.j, k12, i17, l19);
}
int l12 = 0;
if (biomegenbase == kd.h)
{
l12 += 10;
}
for (int j17 = 0; j17 < l12; j17++)
{
int i20 = k + this.j.nextInt(16) + 8;
int k21 = this.j.nextInt(128 );
int k22 = l + this.j.nextInt(16) + 8;
new fx().a(this.worldObj, this.j, i20, k21, k22);
}

for (int k17 = 0; k17 < 50; k17++)
{
int j20 = k + this.j.nextInt(16) + 8;
int l21 = this.j.nextInt(this.j.nextInt(120) + 8 );
int l22 = l + this.j.nextInt(16) + 8;
new xo(uu.B.bn).a(this.worldObj, this.j, j20, l21, l22);
}

for (int l17 = 0; l17 < 20; l17++)
{
int k20 = k + this.j.nextInt(16) + 8;
int i22 = this.j.nextInt(this.j.nextInt(this.j.nextInt(112) + 8 ) + 8 );
int i23 = l + this.j.nextInt(16) + 8;
new xo(uu.D.bn).a(this.worldObj, this.j, k20, i22, i23);
}

this.w = this.worldObj.a().a(this.w, k + 8, l + 8, 16, 16);
for (int i18 = k + 8; i18 < k + 8 + 16; i18++)
{
for (int l20 = l + 8; l20 < l + 8 + 16; l20++)
{
int j22 = i18 - (k + 8 );
int j23 = l20 - (l + 8 );
int k23 = this.worldObj.e(i18, l20);
double d1 = this.w[(j22 * 16 + j23)] - (k23 - 64) / 64.0D * 0.3D;
if ((d1 >= 0.5D) || (k23 <= 0) || (k23 >= 128 ) || (!this.worldObj.d(i18, k23, l20)) || (!this.worldObj.f(i18, k23 - 1, l20).c()) || (this.worldObj.f(i18, k23 - 1, l20) == ln.s))
continue;
this.worldObj.f(i18, k23, l20, uu.aT.bn);
}

}

gk.a = false;
}

public boolean a(boolean flag, yb iprogressupdate)
{
return true;
}

public boolean a()
{
return false;
}

public boolean b()
{
return true;
}

public String c()
{
return "RandomLevelSource";
}
}
import java.util.Random;

public class jd
implements cl
{
private Random j;
private uf k;
private uf l;
private uf m;
private uf n;
private uf o;
public uf a;
public uf b;
public uf c;
private fd worldObj;
private double[] q;
private double[] r;
private double[] s;
private double[] t;
private fv u;
private kd[] v;
double[] d;
double[] e;
double[] f;
double[] g;
double[] h;
int[][] i;
private double[] w;

public jd(fd world, long l)
{
this.r = new double[256];
this.s = new double[256];
this.t = new double[256];
this.u = new sq();
this.i = new int[32][32];
this.worldObj = world;
this.j = new Random(l);
this.k = new uf(this.j, 16);
this.l = new uf(this.j, 16);
this.m = new uf(this.j, 8 );
this.n = new uf(this.j, 4);
this.o = new uf(this.j, 4);
this.a = new uf(this.j, 10);
this.b = new uf(this.j, 16);
this.c = new uf(this.j, 8 );
}

public void a(int i, int j, byte[] abyte0, kd[] abiomegenbase, double[] ad)
{
byte byte0 = 2;
int k = byte0 + 1;
byte byte1 = 33;
int l = byte0 + 1;
this.q = a(this.q, i * byte0, 0, j * byte0, k, byte1, l);
for (int i1 = 0; i1 < byte0; i1++)
{
for (int j1 = 0; j1 < byte0; j1++)
{
for (int k1 = 0; k1 < 32; k1++)
{
double d = 0.25D;
double d1 = this.q[(((i1 + 0) * l + (j1 + 0)) * byte1 + (k1 + 0))];
double d2 = this.q[(((i1 + 0) * l + (j1 + 1)) * byte1 + (k1 + 0))];
double d3 = this.q[(((i1 + 1) * l + (j1 + 0)) * byte1 + (k1 + 0))];
double d4 = this.q[(((i1 + 1) * l + (j1 + 1)) * byte1 + (k1 + 0))];
double d5 = (this.q[(((i1 + 0) * l + (j1 + 0)) * byte1 + (k1 + 1))] - d1) * d;
double d6 = (this.q[(((i1 + 0) * l + (j1 + 1)) * byte1 + (k1 + 1))] - d2) * d;
double d7 = (this.q[(((i1 + 1) * l + (j1 + 0)) * byte1 + (k1 + 1))] - d3) * d;
double d8 = (this.q[(((i1 + 1) * l + (j1 + 1)) * byte1 + (k1 + 1))] - d4) * d;
for (int l1 = 0; l1 < 4; l1++)
{
double d9 = 0.125D;
double d10 = d1;
double d11 = d2;
double d12 = (d3 - d1) * d9;
double d13 = (d4 - d2) * d9;
for (int i2 = 0; i2 < 8; i2++)
{
int j2 = i2 + i1 * 8 << 11 | 0 + j1 * 8 << 7 | k1 * 4 + l1;
char c = '€';
double d14 = 0.125D;
double d15 = d10;
double d16 = (d11 - d10) * d14;
for (int k2 = 0; k2 < 8; k2++)
{
int l2 = 0;
if (d15 > 0.0D)
{
l2 = uu.u.bn;
}
abyte0[j2] = (byte)l2;
j2 += c;
d15 += d16;
}

d10 += d12;
d11 += d13;
}

d1 += d5;
d2 += d6;
d3 += d7;
d4 += d8;
}
}
}
}
}

public void a(int i, int j, byte[] abyte0, kd[] abiomegenbase)
{
double d = 0.03125D;
this.r = this.n.a(this.r, i * 16, j * 16, 0.0D, 16, 16, 1, d, d, 1.0D);
this.s = this.n.a(this.s, i * 16, 109.0134D, j * 16, 16, 1, 16, d, 1.0D, d);
this.t = this.o.a(this.t, i * 16, j * 16, 0.0D, 16, 16, 1, d * 2.0D, d * 2.0D, d * 2.0D);
for (int k = 0; k < 16; k++)
{
for (int l = 0; l < 16; l++)
{
kd biomegenbase = abiomegenbase[(k + l * 16)];
int i1 = (int)(this.t[(k + l * 16)] / 3.0D + 3.0D + this.j.nextDouble() * 0.25D);
int j1 = -1;
byte byte0 = biomegenbase.p;
byte byte1 = biomegenbase.q;
for (int k1 = 127; k1 >= 0; k1--)
{
int l1 = (l * 16 + k) * 128 + k1;
byte byte2 = abyte0[l1];
if (byte2 == 0)
{
j1 = -1;
}
else {
if (byte2 != uu.u.bn)
{
continue;
}
if (j1 == -1)
{
if (i1 <= 0)
{
byte0 = 0;
byte1 = (byte)uu.u.bn;
}
j1 = i1;
if (k1 >= 0)
{
abyte0[l1] = byte0;
}
else
abyte0[l1] = byte1;
}
else
{
if (j1 <= 0)
{
continue;
}
j1--;
abyte0[l1] = byte1;
if ((j1 != 0) || (byte1 != uu.F.bn))
continue;
j1 = this.j.nextInt(4);
byte1 = (byte)uu.R.bn;
}
}
}
}
}
}

public lm c(int i, int j)
{
return b(i, j);
}

public ChunkCube prepareCube(int i, int y, int j) {
return provideCube(i, y, j);
}

public ChunkCube provideCube(int x, int y, int z)
{
lm chunk = this.worldObj.c(x, z);

if ((chunk == null) || (chunk.p))
{
chunk = b(x, y);
}

if ((y < 0) || (y >= 8 ))
{
byte[] data = new byte[4096];

ChunkCube cube = new ChunkCube(chunk, data, y + 128 );
cube.isAir = true;
cube.isChunkLoaded = true;
chunk.cubes[(y + 128 )] = cube;
for (int n = 0; n < cube.skylightMap.a.length; n++)
{
cube.skylightMap.a[n] = -1;
}
return cube;
}

chunk.c();
return chunk.cubes[(y + 128 )];
}

public lm b(int i, int j)
{
this.j.setSeed(i * 341873128712L + j * 132897987541L);
byte[] data = new byte[32768];
this.v = this.worldObj.a().a(this.v, i * 16, j * 16, 16, 16);
double[] ad = this.worldObj.a().a;
a(i, j, data, this.v, ad);
a(i, j, data, this.v);
this.u.a(this, this.worldObj, i, j, data);

lm chunk = new lm(this.worldObj, data, i, j);

chunk.c();
return chunk;
}

private double[] a(double[] ad, int i, int j, int k, int l, int i1, int j1)
{
if (ad == null)
{
ad = new double[l * i1 * j1];
}
double d = 684.41200000000003D;
double d1 = 684.41200000000003D;
double[] ad1 = this.worldObj.a().a;
double[] ad2 = this.worldObj.a().b;
this.g = this.a.a(this.g, i, k, l, j1, 1.121D, 1.121D, 0.5D);
this.h = this.b.a(this.h, i, k, l, j1, 200.0D, 200.0D, 0.5D);
d *= 2.0D;
this.d = this.m.a(this.d, i, j, k, l, i1, j1, d / 80.0D, d1 / 160.0D, d / 80.0D);
this.e = this.k.a(this.e, i, j, k, l, i1, j1, d, d1, d);
this.f = this.l.a(this.f, i, j, k, l, i1, j1, d, d1, d);
int k1 = 0;
int l1 = 0;
int i2 = 16 / l;
for (int j2 = 0; j2 < l; j2++)
{
int k2 = j2 * i2 + i2 / 2;
for (int l2 = 0; l2 < j1; l2++)
{
int i3 = l2 * i2 + i2 / 2;
double d2 = ad1[(k2 * 16 + i3)];
double d3 = ad2[(k2 * 16 + i3)] * d2;
double d4 = 1.0D - d3;
d4 *= d4;
d4 *= d4;
d4 = 1.0D - d4;
double d5 = (this.g[l1] + 256.0D) / 512.0D;
d5 *= d4;
if (d5 > 1.0D)
{
d5 = 1.0D;
}
double d6 = this.h[l1] / 8000.0D;
if (d6 < 0.0D)
{
d6 = -d6 * 0.3D;
}
d6 = d6 * 3.0D - 2.0D;
if (d6 > 1.0D)
{
d6 = 1.0D;
}
d6 /= 8.0D;
d6 = 0.0D;
if (d5 < 0.0D)
{
d5 = 0.0D;
}
d5 += 0.5D;
d6 = d6 * i1 / 16.0D;
l1++;
double d7 = i1 / 2.0D;
for (int j3 = 0; j3 < i1; j3++)
{
double d8 = 0.0D;
double d9 = (j3 - d7) * 8.0D / d5;
if (d9 < 0.0D)
{
d9 *= -1.0D;
}
double d10 = this.e[k1] / 512.0D;
double d11 = this.f[k1] / 512.0D;
double d12 = (this.d[k1] / 10.0D + 1.0D) / 2.0D;
if (d12 < 0.0D)
{
d8 = d10;
}
else if (d12 > 1.0D)
{
d8 = d11;
}
else {
d8 = d10 + (d11 - d10) * d12;
}
d8 -= 8.0D;
int k3 = 32;
if (j3 > i1 - k3)
{
double d13 = (j3 - (i1 - k3)) / (k3 - 1.0F);
d8 = d8 * (1.0D - d13) + -30.0D * d13;
}
k3 = 8;
if (j3 < k3)
{
double d14 = (k3 - j3) / (k3 - 1.0F);
d8 = d8 * (1.0D - d14) + -30.0D * d14;
}
ad[k1] = d8;
k1++;
}

}

}

return ad;
}

public boolean a(int i, int j)
{
return true;
}

public boolean cubeExists(int i, int y, int j)
{
return true;
}

public void populate(cl ichunkprovider, int x, int y, int z)
{
}

public void a(cl ichunkprovider, int i, int j)
{
gk.a = true;
int k = i * 16;
int l = j * 16;
kd biomegenbase = this.worldObj.a().a(k + 16, l + 16);
this.j.setSeed(this.worldObj.s());
long l1 = this.j.nextLong() / 2L * 2L + 1L;
long l2 = this.j.nextLong() / 2L * 2L + 1L;
this.j.setSeed(i * l1 + j * l2 ^ this.worldObj.s());
double d = 0.25D;
if (this.j.nextInt(4) == 0)
{
int i1 = k + this.j.nextInt(16) + 8;
int l4 = this.j.nextInt(128 );
int i8 = l + this.j.nextInt(16) + 8;
new dj(uu.C.bn).a(this.worldObj, this.j, i1, l4, i8 );
}
if (this.j.nextInt(8 ) == 0)
{
int j1 = k + this.j.nextInt(16) + 8;
int i5 = this.j.nextInt(this.j.nextInt(120) + 8 );
int j8 = l + this.j.nextInt(16) + 8;
if ((i5 < 64) || (this.j.nextInt(10) == 0))
{
new dj(uu.E.bn).a(this.worldObj, this.j, j1, i5, j8 );
}
}
for (int k1 = 0; k1 < 8; k1++)
{
int j5 = k + this.j.nextInt(16) + 8;
int k8 = this.j.nextInt(128 );
int i13 = l + this.j.nextInt(16) + 8;
new er().a(this.worldObj, this.j, j5, k8, i13);
}

for (int i2 = 0; i2 < 10; i2++)
{
int k5 = k + this.j.nextInt(16);
int l8 = this.j.nextInt(128 );
int j13 = l + this.j.nextInt(16);
new ms(32).a(this.worldObj, this.j, k5, l8, j13);
}

for (int j2 = 0; j2 < 20; j2++)
{
int l5 = k + this.j.nextInt(16);
int i9 = this.j.nextInt(128 );
int k13 = l + this.j.nextInt(16);
new fl(uu.w.bn, 32).a(this.worldObj, this.j, l5, i9, k13);
}

for (int k2 = 0; k2 < 10; k2++)
{
int i6 = k + this.j.nextInt(16);
int j9 = this.j.nextInt(128 );
int l13 = l + this.j.nextInt(16);
new fl(uu.G.bn, 32).a(this.worldObj, this.j, i6, j9, l13);
}

for (int i3 = 0; i3 < 20; i3++)
{
int j6 = k + this.j.nextInt(16);
int k9 = this.j.nextInt(128 );
int i14 = l + this.j.nextInt(16);
new fl(uu.J.bn, 16).a(this.worldObj, this.j, j6, k9, i14);
}

for (int j3 = 0; j3 < 20; j3++)
{
int k6 = k + this.j.nextInt(16);
int l9 = this.j.nextInt(64);
int j14 = l + this.j.nextInt(16);
new fl(uu.I.bn, 8 ).a(this.worldObj, this.j, k6, l9, j14);
}

for (int k3 = 0; k3 < 2; k3++)
{
int l6 = k + this.j.nextInt(16);
int i10 = this.j.nextInt(32);
int k14 = l + this.j.nextInt(16);
new fl(uu.H.bn, 8 ).a(this.worldObj, this.j, l6, i10, k14);
}

for (int l3 = 0; l3 < 8; l3++)
{
int i7 = k + this.j.nextInt(16);
int j10 = this.j.nextInt(16);
int l14 = l + this.j.nextInt(16);
new fl(uu.aO.bn, 7).a(this.worldObj, this.j, i7, j10, l14);
}

for (int i4 = 0; i4 < 1; i4++)
{
int j7 = k + this.j.nextInt(16);
int k10 = this.j.nextInt(16);
int i15 = l + this.j.nextInt(16);
new fl(uu.ax.bn, 7).a(this.worldObj, this.j, j7, k10, i15);
}

for (int j4 = 0; j4 < 1; j4++)
{
int k7 = k + this.j.nextInt(16);
int l10 = this.j.nextInt(16) + this.j.nextInt(16);
int j15 = l + this.j.nextInt(16);
new fl(uu.O.bn, 6).a(this.worldObj, this.j, k7, l10, j15);
}

d = 0.5D;
int k4 = (int)((this.c.a(k * d, l * d) / 8.0D + this.j.nextDouble() * 4.0D + 4.0D) / 3.0D);
int l7 = 0;
if (this.j.nextInt(10) == 0)
{
l7++;
}
if (biomegenbase == kd.d)
{
l7 += k4 + 5;
}
if (biomegenbase == kd.a)
{
l7 += k4 + 5;
}
if (biomegenbase == kd.c)
{
l7 += k4 + 2;
}
if (biomegenbase == kd.g)
{
l7 += k4 + 5;
}
if (biomegenbase == kd.h)
{
l7 -= 20;
}
if (biomegenbase == kd.k)
{
l7 -= 20;
}
if (biomegenbase == kd.i)
{
l7 -= 20;
}
for (int i11 = 0; i11 < l7; i11++)
{
int k15 = k + this.j.nextInt(16) + 8;
int j18 = l + this.j.nextInt(16) + 8;
pg worldgenerator = biomegenbase.a(this.j);
worldgenerator.a(1.0D, 1.0D, 1.0D);
worldgenerator.a(this.worldObj, this.j, k15, this.worldObj.d(k15, j18 ), j18 );
}

for (int j11 = 0; j11 < 2; j11++)
{
int l15 = k + this.j.nextInt(16) + 8;
int k18 = this.j.nextInt(128 );
int i21 = l + this.j.nextInt(16) + 8;
new be(uu.ae.bn).a(this.worldObj, this.j, l15, k18, i21);
}

if (this.j.nextInt(2) == 0)
{
int k11 = k + this.j.nextInt(16) + 8;
int i16 = this.j.nextInt(128 );
int l18 = l + this.j.nextInt(16) + 8;
new be(uu.af.bn).a(this.worldObj, this.j, k11, i16, l18 );
}
if (this.j.nextInt(4) == 0)
{
int l11 = k + this.j.nextInt(16) + 8;
int j16 = this.j.nextInt(128 );
int i19 = l + this.j.nextInt(16) + 8;
new be(uu.ag.bn).a(this.worldObj, this.j, l11, j16, i19);
}
if (this.j.nextInt(8 ) == 0)
{
int i12 = k + this.j.nextInt(16) + 8;
int k16 = this.j.nextInt(128 );
int j19 = l + this.j.nextInt(16) + 8;
new be(uu.ah.bn).a(this.worldObj, this.j, i12, k16, j19);
}
for (int j12 = 0; j12 < 10; j12++)
{
int l16 = k + this.j.nextInt(16) + 8;
int k19 = this.j.nextInt(128 );
int j21 = l + this.j.nextInt(16) + 8;
new ir().a(this.worldObj, this.j, l16, k19, j21);
}

if (this.j.nextInt(32) == 0)
{
int k12 = k + this.j.nextInt(16) + 8;
int i17 = this.j.nextInt(128 );
int l19 = l + this.j.nextInt(16) + 8;
new wx().a(this.worldObj, this.j, k12, i17, l19);
}
int l12 = 0;
if (biomegenbase == kd.h)
{
l12 += 10;
}
for (int j17 = 0; j17 < l12; j17++)
{
int i20 = k + this.j.nextInt(16) + 8;
int k21 = this.j.nextInt(128 );
int k22 = l + this.j.nextInt(16) + 8;
new fx().a(this.worldObj, this.j, i20, k21, k22);
}

for (int k17 = 0; k17 < 50; k17++)
{
int j20 = k + this.j.nextInt(16) + 8;
int l21 = this.j.nextInt(this.j.nextInt(120) + 8 );
int l22 = l + this.j.nextInt(16) + 8;
new xo(uu.B.bn).a(this.worldObj, this.j, j20, l21, l22);
}

for (int l17 = 0; l17 < 20; l17++)
{
int k20 = k + this.j.nextInt(16) + 8;
int i22 = this.j.nextInt(this.j.nextInt(this.j.nextInt(112) + 8 ) + 8 );
int i23 = l + this.j.nextInt(16) + 8;
new xo(uu.D.bn).a(this.worldObj, this.j, k20, i22, i23);
}

this.w = this.worldObj.a().a(this.w, k + 8, l + 8, 16, 16);
for (int i18 = k + 8; i18 < k + 8 + 16; i18++)
{
for (int l20 = l + 8; l20 < l + 8 + 16; l20++)
{
int j22 = i18 - (k + 8 );
int j23 = l20 - (l + 8 );
int k23 = this.worldObj.e(i18, l20);
double d1 = this.w[(j22 * 16 + j23)] - (k23 - 64) / 64.0D * 0.3D;
if ((d1 >= 0.5D) || (k23 <= 0) || (k23 >= 128 ) || (!this.worldObj.d(i18, k23, l20)) || (!this.worldObj.f(i18, k23 - 1, l20).c()) || (this.worldObj.f(i18, k23 - 1, l20) == ln.s))
continue;
this.worldObj.f(i18, k23, l20, uu.aT.bn);
}

}

gk.a = false;
}

public boolean a(boolean flag, yb iprogressupdate)
{
return true;
}

public boolean a()
{
return false;
}

public boolean b()
{
return true;
}

public String c()
{
return "RandomLevelSource";
}
}import java.util.Random;

public class jd
implements cl
{
private Random j;
private uf k;
private uf l;
private uf m;
private uf n;
private uf o;
public uf a;
public uf b;
public uf c;
private fd worldObj;
private double[] q;
private double[] r;
private double[] s;
private double[] t;
private fv u;
private kd[] v;
double[] d;
double[] e;
double[] f;
double[] g;
double[] h;
int[][] i;
private double[] w;

public jd(fd world, long l)
{
this.r = new double[256];
this.s = new double[256];
this.t = new double[256];
this.u = new sq();
this.i = new int[32][32];
this.worldObj = world;
this.j = new Random(l);
this.k = new uf(this.j, 16);
this.l = new uf(this.j, 16);
this.m = new uf(this.j, 8 );
this.n = new uf(this.j, 4);
this.o = new uf(this.j, 4);
this.a = new uf(this.j, 10);
this.b = new uf(this.j, 16);
this.c = new uf(this.j, 8 );
}

public void a(int i, int j, byte[] abyte0, kd[] abiomegenbase, double[] ad)
{
byte byte0 = 2;
int k = byte0 + 1;
byte byte1 = 33;
int l = byte0 + 1;
this.q = a(this.q, i * byte0, 0, j * byte0, k, byte1, l);
for (int i1 = 0; i1 < byte0; i1++)
{
for (int j1 = 0; j1 < byte0; j1++)
{
for (int k1 = 0; k1 < 32; k1++)
{
double d = 0.25D;
double d1 = this.q[(((i1 + 0) * l + (j1 + 0)) * byte1 + (k1 + 0))];
double d2 = this.q[(((i1 + 0) * l + (j1 + 1)) * byte1 + (k1 + 0))];
double d3 = this.q[(((i1 + 1) * l + (j1 + 0)) * byte1 + (k1 + 0))];
double d4 = this.q[(((i1 + 1) * l + (j1 + 1)) * byte1 + (k1 + 0))];
double d5 = (this.q[(((i1 + 0) * l + (j1 + 0)) * byte1 + (k1 + 1))] - d1) * d;
double d6 = (this.q[(((i1 + 0) * l + (j1 + 1)) * byte1 + (k1 + 1))] - d2) * d;
double d7 = (this.q[(((i1 + 1) * l + (j1 + 0)) * byte1 + (k1 + 1))] - d3) * d;
double d8 = (this.q[(((i1 + 1) * l + (j1 + 1)) * byte1 + (k1 + 1))] - d4) * d;
for (int l1 = 0; l1 < 4; l1++)
{
double d9 = 0.125D;
double d10 = d1;
double d11 = d2;
double d12 = (d3 - d1) * d9;
double d13 = (d4 - d2) * d9;
for (int i2 = 0; i2 < 8; i2++)
{
int j2 = i2 + i1 * 8 << 11 | 0 + j1 * 8 << 7 | k1 * 4 + l1;
char c = '€';
double d14 = 0.125D;
double d15 = d10;
double d16 = (d11 - d10) * d14;
for (int k2 = 0; k2 < 8; k2++)
{
int l2 = 0;
if (d15 > 0.0D)
{
l2 = uu.u.bn;
}
abyte0[j2] = (byte)l2;
j2 += c;
d15 += d16;
}

d10 += d12;
d11 += d13;
}

d1 += d5;
d2 += d6;
d3 += d7;
d4 += d8;
}
}
}
}
}

public void a(int i, int j, byte[] abyte0, kd[] abiomegenbase)
{
double d = 0.03125D;
this.r = this.n.a(this.r, i * 16, j * 16, 0.0D, 16, 16, 1, d, d, 1.0D);
this.s = this.n.a(this.s, i * 16, 109.0134D, j * 16, 16, 1, 16, d, 1.0D, d);
this.t = this.o.a(this.t, i * 16, j * 16, 0.0D, 16, 16, 1, d * 2.0D, d * 2.0D, d * 2.0D);
for (int k = 0; k < 16; k++)
{
for (int l = 0; l < 16; l++)
{
kd biomegenbase = abiomegenbase[(k + l * 16)];
int i1 = (int)(this.t[(k + l * 16)] / 3.0D + 3.0D + this.j.nextDouble() * 0.25D);
int j1 = -1;
byte byte0 = biomegenbase.p;
byte byte1 = biomegenbase.q;
for (int k1 = 127; k1 >= 0; k1--)
{
int l1 = (l * 16 + k) * 128 + k1;
byte byte2 = abyte0[l1];
if (byte2 == 0)
{
j1 = -1;
}
else {
if (byte2 != uu.u.bn)
{
continue;
}
if (j1 == -1)
{
if (i1 <= 0)
{
byte0 = 0;
byte1 = (byte)uu.u.bn;
}
j1 = i1;
if (k1 >= 0)
{
abyte0[l1] = byte0;
}
else
abyte0[l1] = byte1;
}
else
{
if (j1 <= 0)
{
continue;
}
j1--;
abyte0[l1] = byte1;
if ((j1 != 0) || (byte1 != uu.F.bn))
continue;
j1 = this.j.nextInt(4);
byte1 = (byte)uu.R.bn;
}
}
}
}
}
}

public lm c(int i, int j)
{
return b(i, j);
}

public ChunkCube prepareCube(int i, int y, int j) {
return provideCube(i, y, j);
}

public ChunkCube provideCube(int x, int y, int z)
{
lm chunk = this.worldObj.c(x, z);

if ((chunk == null) || (chunk.p))
{
chunk = b(x, y);
}

if ((y < 0) || (y >= 8 ))
{
byte[] data = new byte[4096];

ChunkCube cube = new ChunkCube(chunk, data, y + 128 );
cube.isAir = true;
cube.isChunkLoaded = true;
chunk.cubes[(y + 128 )] = cube;
for (int n = 0; n < cube.skylightMap.a.length; n++)
{
cube.skylightMap.a[n] = -1;
}
return cube;
}

chunk.c();
return chunk.cubes[(y + 128 )];
}

public lm b(int i, int j)
{
this.j.setSeed(i * 341873128712L + j * 132897987541L);
byte[] data = new byte[32768];
this.v = this.worldObj.a().a(this.v, i * 16, j * 16, 16, 16);
double[] ad = this.worldObj.a().a;
a(i, j, data, this.v, ad);
a(i, j, data, this.v);
this.u.a(this, this.worldObj, i, j, data);

lm chunk = new lm(this.worldObj, data, i, j);

chunk.c();
return chunk;
}

private double[] a(double[] ad, int i, int j, int k, int l, int i1, int j1)
{
if (ad == null)
{
ad = new double[l * i1 * j1];
}
double d = 684.41200000000003D;
double d1 = 684.41200000000003D;
double[] ad1 = this.worldObj.a().a;
double[] ad2 = this.worldObj.a().b;
this.g = this.a.a(this.g, i, k, l, j1, 1.121D, 1.121D, 0.5D);
this.h = this.b.a(this.h, i, k, l, j1, 200.0D, 200.0D, 0.5D);
d *= 2.0D;
this.d = this.m.a(this.d, i, j, k, l, i1, j1, d / 80.0D, d1 / 160.0D, d / 80.0D);
this.e = this.k.a(this.e, i, j, k, l, i1, j1, d, d1, d);
this.f = this.l.a(this.f, i, j, k, l, i1, j1, d, d1, d);
int k1 = 0;
int l1 = 0;
int i2 = 16 / l;
for (int j2 = 0; j2 < l; j2++)
{
int k2 = j2 * i2 + i2 / 2;
for (int l2 = 0; l2 < j1; l2++)
{
int i3 = l2 * i2 + i2 / 2;
double d2 = ad1[(k2 * 16 + i3)];
double d3 = ad2[(k2 * 16 + i3)] * d2;
double d4 = 1.0D - d3;
d4 *= d4;
d4 *= d4;
d4 = 1.0D - d4;
double d5 = (this.g[l1] + 256.0D) / 512.0D;
d5 *= d4;
if (d5 > 1.0D)
{
d5 = 1.0D;
}
double d6 = this.h[l1] / 8000.0D;
if (d6 < 0.0D)
{
d6 = -d6 * 0.3D;
}
d6 = d6 * 3.0D - 2.0D;
if (d6 > 1.0D)
{
d6 = 1.0D;
}
d6 /= 8.0D;
d6 = 0.0D;
if (d5 < 0.0D)
{
d5 = 0.0D;
}
d5 += 0.5D;
d6 = d6 * i1 / 16.0D;
l1++;
double d7 = i1 / 2.0D;
for (int j3 = 0; j3 < i1; j3++)
{
double d8 = 0.0D;
double d9 = (j3 - d7) * 8.0D / d5;
if (d9 < 0.0D)
{
d9 *= -1.0D;
}
double d10 = this.e[k1] / 512.0D;
double d11 = this.f[k1] / 512.0D;
double d12 = (this.d[k1] / 10.0D + 1.0D) / 2.0D;
if (d12 < 0.0D)
{
d8 = d10;
}
else if (d12 > 1.0D)
{
d8 = d11;
}
else {
d8 = d10 + (d11 - d10) * d12;
}
d8 -= 8.0D;
int k3 = 32;
if (j3 > i1 - k3)
{
double d13 = (j3 - (i1 - k3)) / (k3 - 1.0F);
d8 = d8 * (1.0D - d13) + -30.0D * d13;
}
k3 = 8;
if (j3 < k3)
{
double d14 = (k3 - j3) / (k3 - 1.0F);
d8 = d8 * (1.0D - d14) + -30.0D * d14;
}
ad[k1] = d8;
k1++;
}

}

}

return ad;
}

public boolean a(int i, int j)
{
return true;
}

public boolean cubeExists(int i, int y, int j)
{
return true;
}

public void populate(cl ichunkprovider, int x, int y, int z)
{
}

public void a(cl ichunkprovider, int i, int j)
{
gk.a = true;
int k = i * 16;
int l = j * 16;
kd biomegenbase = this.worldObj.a().a(k + 16, l + 16);
this.j.setSeed(this.worldObj.s());
long l1 = this.j.nextLong() / 2L * 2L + 1L;
long l2 = this.j.nextLong() / 2L * 2L + 1L;
this.j.setSeed(i * l1 + j * l2 ^ this.worldObj.s());
double d = 0.25D;
if (this.j.nextInt(4) == 0)
{
int i1 = k + this.j.nextInt(16) + 8;
int l4 = this.j.nextInt(128 );
int i8 = l + this.j.nextInt(16) + 8;
new dj(uu.C.bn).a(this.worldObj, this.j, i1, l4, i8 );
}
if (this.j.nextInt(8 ) == 0)
{
int j1 = k + this.j.nextInt(16) + 8;
int i5 = this.j.nextInt(this.j.nextInt(120) + 8 );
int j8 = l + this.j.nextInt(16) + 8;
if ((i5 < 64) || (this.j.nextInt(10) == 0))
{
new dj(uu.E.bn).a(this.worldObj, this.j, j1, i5, j8 );
}
}
for (int k1 = 0; k1 < 8; k1++)
{
int j5 = k + this.j.nextInt(16) + 8;
int k8 = this.j.nextInt(128 );
int i13 = l + this.j.nextInt(16) + 8;
new er().a(this.worldObj, this.j, j5, k8, i13);
}

for (int i2 = 0; i2 < 10; i2++)
{
int k5 = k + this.j.nextInt(16);
int l8 = this.j.nextInt(128 );
int j13 = l + this.j.nextInt(16);
new ms(32).a(this.worldObj, this.j, k5, l8, j13);
}

for (int j2 = 0; j2 < 20; j2++)
{
int l5 = k + this.j.nextInt(16);
int i9 = this.j.nextInt(128 );
int k13 = l + this.j.nextInt(16);
new fl(uu.w.bn, 32).a(this.worldObj, this.j, l5, i9, k13);
}

for (int k2 = 0; k2 < 10; k2++)
{
int i6 = k + this.j.nextInt(16);
int j9 = this.j.nextInt(128 );
int l13 = l + this.j.nextInt(16);
new fl(uu.G.bn, 32).a(this.worldObj, this.j, i6, j9, l13);
}

for (int i3 = 0; i3 < 20; i3++)
{
int j6 = k + this.j.nextInt(16);
int k9 = this.j.nextInt(128 );
int i14 = l + this.j.nextInt(16);
new fl(uu.J.bn, 16).a(this.worldObj, this.j, j6, k9, i14);
}

for (int j3 = 0; j3 < 20; j3++)
{
int k6 = k + this.j.nextInt(16);
int l9 = this.j.nextInt(64);
int j14 = l + this.j.nextInt(16);
new fl(uu.I.bn, 8 ).a(this.worldObj, this.j, k6, l9, j14);
}

for (int k3 = 0; k3 < 2; k3++)
{
int l6 = k + this.j.nextInt(16);
int i10 = this.j.nextInt(32);
int k14 = l + this.j.nextInt(16);
new fl(uu.H.bn, 8 ).a(this.worldObj, this.j, l6, i10, k14);
}

for (int l3 = 0; l3 < 8; l3++)
{
int i7 = k + this.j.nextInt(16);
int j10 = this.j.nextInt(16);
int l14 = l + this.j.nextInt(16);
new fl(uu.aO.bn, 7).a(this.worldObj, this.j, i7, j10, l14);
}

for (int i4 = 0; i4 < 1; i4++)
{
int j7 = k + this.j.nextInt(16);
int k10 = this.j.nextInt(16);
int i15 = l + this.j.nextInt(16);
new fl(uu.ax.bn, 7).a(this.worldObj, this.j, j7, k10, i15);
}

for (int j4 = 0; j4 < 1; j4++)
{
int k7 = k + this.j.nextInt(16);
int l10 = this.j.nextInt(16) + this.j.nextInt(16);
int j15 = l + this.j.nextInt(16);
new fl(uu.O.bn, 6).a(this.worldObj, this.j, k7, l10, j15);
}

d = 0.5D;
int k4 = (int)((this.c.a(k * d, l * d) / 8.0D + this.j.nextDouble() * 4.0D + 4.0D) / 3.0D);
int l7 = 0;
if (this.j.nextInt(10) == 0)
{
l7++;
}
if (biomegenbase == kd.d)
{
l7 += k4 + 5;
}
if (biomegenbase == kd.a)
{
l7 += k4 + 5;
}
if (biomegenbase == kd.c)
{
l7 += k4 + 2;
}
if (biomegenbase == kd.g)
{
l7 += k4 + 5;
}
if (biomegenbase == kd.h)
{
l7 -= 20;
}
if (biomegenbase == kd.k)
{
l7 -= 20;
}
if (biomegenbase == kd.i)
{
l7 -= 20;
}
for (int i11 = 0; i11 < l7; i11++)
{
int k15 = k + this.j.nextInt(16) + 8;
int j18 = l + this.j.nextInt(16) + 8;
pg worldgenerator = biomegenbase.a(this.j);
worldgenerator.a(1.0D, 1.0D, 1.0D);
worldgenerator.a(this.worldObj, this.j, k15, this.worldObj.d(k15, j18 ), j18 );
}

for (int j11 = 0; j11 < 2; j11++)
{
int l15 = k + this.j.nextInt(16) + 8;
int k18 = this.j.nextInt(128 );
int i21 = l + this.j.nextInt(16) + 8;
new be(uu.ae.bn).a(this.worldObj, this.j, l15, k18, i21);
}

if (this.j.nextInt(2) == 0)
{
int k11 = k + this.j.nextInt(16) + 8;
int i16 = this.j.nextInt(128 );
int l18 = l + this.j.nextInt(16) + 8;
new be(uu.af.bn).a(this.worldObj, this.j, k11, i16, l18 );
}
if (this.j.nextInt(4) == 0)
{
int l11 = k + this.j.nextInt(16) + 8;
int j16 = this.j.nextInt(128 );
int i19 = l + this.j.nextInt(16) + 8;
new be(uu.ag.bn).a(this.worldObj, this.j, l11, j16, i19);
}
if (this.j.nextInt(8 ) == 0)
{
int i12 = k + this.j.nextInt(16) + 8;
int k16 = this.j.nextInt(128 );
int j19 = l + this.j.nextInt(16) + 8;
new be(uu.ah.bn).a(this.worldObj, this.j, i12, k16, j19);
}
for (int j12 = 0; j12 < 10; j12++)
{
int l16 = k + this.j.nextInt(16) + 8;
int k19 = this.j.nextInt(128 );
int j21 = l + this.j.nextInt(16) + 8;
new ir().a(this.worldObj, this.j, l16, k19, j21);
}

if (this.j.nextInt(32) == 0)
{
int k12 = k + this.j.nextInt(16) + 8;
int i17 = this.j.nextInt(128 );
int l19 = l + this.j.nextInt(16) + 8;
new wx().a(this.worldObj, this.j, k12, i17, l19);
}
int l12 = 0;
if (biomegenbase == kd.h)
{
l12 += 10;
}
for (int j17 = 0; j17 < l12; j17++)
{
int i20 = k + this.j.nextInt(16) + 8;
int k21 = this.j.nextInt(128 );
int k22 = l + this.j.nextInt(16) + 8;
new fx().a(this.worldObj, this.j, i20, k21, k22);
}

for (int k17 = 0; k17 < 50; k17++)
{
int j20 = k + this.j.nextInt(16) + 8;
int l21 = this.j.nextInt(this.j.nextInt(120) + 8 );
int l22 = l + this.j.nextInt(16) + 8;
new xo(uu.B.bn).a(this.worldObj, this.j, j20, l21, l22);
}

for (int l17 = 0; l17 < 20; l17++)
{
int k20 = k + this.j.nextInt(16) + 8;
int i22 = this.j.nextInt(this.j.nextInt(this.j.nextInt(112) + 8 ) + 8 );
int i23 = l + this.j.nextInt(16) + 8;
new xo(uu.D.bn).a(this.worldObj, this.j, k20, i22, i23);
}

this.w = this.worldObj.a().a(this.w, k + 8, l + 8, 16, 16);
for (int i18 = k + 8; i18 < k + 8 + 16; i18++)
{
for (int l20 = l + 8; l20 < l + 8 + 16; l20++)
{
int j22 = i18 - (k + 8 );
int j23 = l20 - (l + 8 );
int k23 = this.worldObj.e(i18, l20);
double d1 = this.w[(j22 * 16 + j23)] - (k23 - 64) / 64.0D * 0.3D;
if ((d1 >= 0.5D) || (k23 <= 0) || (k23 >= 128 ) || (!this.worldObj.d(i18, k23, l20)) || (!this.worldObj.f(i18, k23 - 1, l20).c()) || (this.worldObj.f(i18, k23 - 1, l20) == ln.s))
continue;
this.worldObj.f(i18, k23, l20, uu.aT.bn);
}

}

gk.a = false;
}

public boolean a(boolean flag, yb iprogressupdate)
{
return true;
}

public boolean a()
{
return false;
}

public boolean b()
{
return true;
}

public String c()
{
return "RandomLevelSource";
}
}

Jeśli chcesz dodać odpowiedź, zaloguj się lub zarejestruj nowe konto

Jedynie zarejestrowani użytkownicy mogą komentować zawartość tej strony.

Zarejestruj nowe konto

Załóż nowe konto. To bardzo proste!

Zarejestruj się

Zaloguj się

Zaloguj się poniżej.

Zaloguj się
×
×
  • Dodaj nową pozycję...