mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-20 04:09:51 +00:00
Add a hook for farmland watering (#4891)
This commit is contained in:
1 parent
72bc39d831
commit
a67cce2f91
11 files changed
+635
No files matched your search
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2018.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.ticket;
|
||||
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class AABBTicket extends SimpleTicket<Vec3d>
|
||||
{
|
||||
@Nonnull
|
||||
public final AxisAlignedBB axisAlignedBB;
|
||||
|
||||
public AABBTicket(@Nonnull AxisAlignedBB axisAlignedBB)
|
||||
{
|
||||
this.axisAlignedBB = axisAlignedBB;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Vec3d toMatch)
|
||||
{
|
||||
return this.axisAlignedBB.contains(toMatch);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2018.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.ticket;
|
||||
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
public class ChunkTicketManager<T> implements ITicketGetter<T>
|
||||
{
|
||||
private final Set<SimpleTicket<T>> tickets = Collections.newSetFromMap(new WeakHashMap<>());
|
||||
public final ChunkPos pos;
|
||||
|
||||
public ChunkTicketManager(ChunkPos pos)
|
||||
{
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(SimpleTicket<T> ticket)
|
||||
{
|
||||
this.tickets.add(ticket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(SimpleTicket<T> ticket)
|
||||
{
|
||||
this.tickets.remove(ticket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<SimpleTicket<T>> getTickets()
|
||||
{
|
||||
return tickets;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2018.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.ticket;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface ITicketGetter<T> extends ITicketManager<T>
|
||||
{
|
||||
Collection<SimpleTicket<T>> getTickets();
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2018.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.ticket;
|
||||
|
||||
public interface ITicketManager<T>
|
||||
{
|
||||
void add(SimpleTicket<T> ticket);
|
||||
|
||||
void remove(SimpleTicket<T> ticket);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2018.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.ticket;
|
||||
|
||||
public class MultiTicketManager<T> implements ITicketManager<T>
|
||||
{
|
||||
private final ITicketGetter<T>[] ticketManagers;
|
||||
|
||||
@SafeVarargs
|
||||
public MultiTicketManager(ITicketGetter<T>... ticketManagers)
|
||||
{
|
||||
this.ticketManagers = ticketManagers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(SimpleTicket<T> ticket)
|
||||
{
|
||||
for (ITicketGetter<T> manager : ticketManagers)
|
||||
manager.add(ticket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(SimpleTicket<T> ticket)
|
||||
{
|
||||
for (ITicketGetter<T> manager : ticketManagers)
|
||||
manager.remove(ticket);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2018.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.ticket;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Common class for a simple ticket based system.
|
||||
* @param <T> The type that will be used to check if your ticket matches
|
||||
*/
|
||||
public abstract class SimpleTicket<T>
|
||||
{
|
||||
@Nullable
|
||||
private ITicketManager<T> manager;
|
||||
protected boolean isValid = false;
|
||||
|
||||
/**
|
||||
* Internal method that sets the collection from the managing system.
|
||||
* <br>
|
||||
* Should <b>not</b> be called if you just want to register a ticket to a system like the {@link net.minecraftforge.common.FarmlandWaterManager}
|
||||
*/
|
||||
public final void setBackend(@Nonnull ITicketManager<T> ticketManager)
|
||||
{
|
||||
Preconditions.checkState(this.manager == null, "Ticket is already registered to a managing system");
|
||||
this.manager = ticketManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if your ticket is still registered in the system.
|
||||
*/
|
||||
public boolean isValid()
|
||||
{
|
||||
return isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the ticket from the managing system.
|
||||
* After this call, any calls to {@link #isValid()} should return false unless it is registered again using {@link #validate()}
|
||||
*/
|
||||
public void invalidate()
|
||||
{
|
||||
Preconditions.checkState(this.manager != null, "Ticket is not registered to a managing system");
|
||||
if (this.isValid())
|
||||
{
|
||||
this.manager.remove(this);
|
||||
}
|
||||
this.isValid = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-adds your ticket to the system.
|
||||
*/
|
||||
public void validate()
|
||||
{
|
||||
Preconditions.checkState(this.manager != null, "Ticket is not registered to a managing system");
|
||||
if (!this.isValid())
|
||||
{
|
||||
this.manager.add(this);
|
||||
}
|
||||
this.isValid = true;
|
||||
}
|
||||
|
||||
public abstract boolean matches(T toMatch);
|
||||
}
|
||||
Reference in new issue
Block a user