Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Latest changes from questing branch also included
Merge remote-tracking branch 'origin/questing' Conflicts: src/main/resources/assets/mhfc/textures/gui/GuiList.png
- Loading branch information
Showing
12 changed files
with
280 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package mhfc.net.common.quests.party; | ||
|
||
import java.util.Collection; | ||
|
||
import net.minecraft.entity.player.EntityPlayer; | ||
|
||
/** | ||
* An descriptive implementation for parties. This interface is used to | ||
* represent the party in an immutable way. It is exposed to provide information | ||
* about the party. | ||
* | ||
* @author WorldSEnder | ||
* | ||
*/ | ||
public interface IParty { | ||
/** | ||
* Gets the party leader | ||
* | ||
* @return the player that leads the party | ||
*/ | ||
EntityPlayer getLeader(); | ||
/** | ||
* Gets all players that are in the party, including the leader | ||
* | ||
* @return a collection of all party members | ||
*/ | ||
Collection<EntityPlayer> getPartyMembers(); | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/mhfc/net/common/world/area/ActiveAreaAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package mhfc.net.common.world.area; | ||
|
||
public abstract class ActiveAreaAdapter implements IActiveArea { | ||
private boolean dismissed = false; | ||
|
||
@Override | ||
public abstract IArea getArea(); | ||
|
||
protected abstract void onDismiss(); | ||
|
||
@Override | ||
public final boolean dismiss() { | ||
if (!dismissed) { | ||
onDismiss(); | ||
return dismissed = true; | ||
} | ||
return false; | ||
} | ||
/** | ||
* Alias to {@link #dismiss()} to implement {@link AutoCloseable}. | ||
*/ | ||
@Override | ||
public void close() throws Exception { | ||
dismiss(); | ||
} | ||
|
||
@Override | ||
protected void finalize() throws Throwable { | ||
super.finalize(); | ||
dismiss(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package mhfc.net.common.world.area; | ||
/** | ||
* Represents an {@link IArea} in use. It can be dismissed via | ||
* {@link #dismiss()}. | ||
* | ||
* @author WorldSEnder | ||
* | ||
*/ | ||
public interface IActiveArea extends AutoCloseable { | ||
/** | ||
* Gets the area of the active area | ||
* | ||
* @return the underlying area | ||
*/ | ||
IArea getArea(); | ||
/** | ||
* Gets the {@link IAreaType} of the underlying area | ||
* | ||
* @return | ||
*/ | ||
IAreaType getType(); | ||
/** | ||
* Dismisses the area. All following calls to this area should fail - and | ||
* may throw an {@link IllegalStateException}. | ||
* | ||
* @return <code>true</code> if the area was active before, aka there was no | ||
* call to {@link #dismiss()} before | ||
*/ | ||
boolean dismiss(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package mhfc.net.common.world.area; | ||
|
||
import mhfc.net.common.quests.world.IQuestArea; | ||
import mhfc.net.common.world.controller.IAreaManager; | ||
|
||
public interface IArea extends IQuestArea { | ||
/** | ||
* Returns whether this area can (temporarily) not be used.<br> | ||
* Checked by the {@link IAreaManager} when it searches for an area to put a | ||
* questing party in. When an area without a party is found and this returns | ||
* <code>false</code> the area is used as the area where the raid takes | ||
* place.<br> | ||
* This is optional and should probably always return <code>false</code>. | ||
* | ||
* @return <code>false</code> to disable questing in this area. | ||
*/ | ||
boolean isBlocked(); | ||
|
||
IAreaType getOwnType(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package mhfc.net.common.world.area; | ||
|
||
import mhfc.net.common.world.controller.IWorldProxy; | ||
|
||
public interface IAreaType { | ||
|
||
void populate(IWorldProxy world); | ||
|
||
@Override | ||
int hashCode(); | ||
|
||
} |
104 changes: 104 additions & 0 deletions
104
src/main/java/mhfc/net/common/world/controller/DefaultAreaManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package mhfc.net.common.world.controller; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import mhfc.net.common.world.area.ActiveAreaAdapter; | ||
import mhfc.net.common.world.area.IActiveArea; | ||
import mhfc.net.common.world.area.IArea; | ||
import mhfc.net.common.world.area.IAreaType; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.tileentity.TileEntity; | ||
import net.minecraft.world.World; | ||
|
||
public class DefaultAreaManager implements IAreaManager { | ||
private static class Active extends ActiveAreaAdapter { | ||
private IArea area; | ||
private IAreaType type; | ||
private DefaultAreaManager ref; | ||
|
||
public Active(IArea area, IAreaType type, DefaultAreaManager ref) { | ||
this.area = Objects.requireNonNull(area); | ||
this.type = Objects.requireNonNull(type); | ||
this.ref = Objects.requireNonNull(ref); | ||
} | ||
|
||
@Override | ||
public IArea getArea() { | ||
return area; | ||
} | ||
|
||
@Override | ||
public IAreaType getType() { | ||
return type; | ||
} | ||
|
||
@Override | ||
protected void onDismiss() { | ||
ref.dismiss(this); | ||
} | ||
|
||
} | ||
|
||
private static class Proxy implements IWorldProxy { | ||
|
||
@Override | ||
public void setBlockAt(int x, int y, int z, Block block) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
@Override | ||
public void setTileEntityAt(int x, int y, int z, TileEntity tile) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
public void applyTo(World world, int chunkOffX, int chunkOffZ) { | ||
// TODO Auto-generated method stub | ||
} | ||
} | ||
private Map<IAreaType, List<IArea>> spawnedAreas = new HashMap<>(); | ||
private World world; | ||
|
||
public DefaultAreaManager(World world) { | ||
this.world = Objects.requireNonNull(world); | ||
} | ||
|
||
private void dismiss(IActiveArea active) { | ||
this.spawnedAreas.get(active.getType()).add(active.getArea()); | ||
} | ||
|
||
@Override | ||
public IActiveArea getEmptyInstance(IAreaType type) { | ||
List<IArea> list = spawnedAreas.get(type); | ||
if (list == null) { | ||
IArea newArea = newArea(type); | ||
spawnedAreas.put(type, Arrays.asList(newArea)); | ||
return new Active(newArea, type, this); | ||
} | ||
for (IArea area : list) { | ||
if (area.isBlocked()) | ||
continue; | ||
return new Active(area, type, this); | ||
} | ||
IArea newArea = newArea(type); | ||
return new Active(newArea, type, this); | ||
} | ||
|
||
private IArea newArea(IAreaType type) { | ||
Proxy proxy = newProxy(); | ||
type.populate(proxy); | ||
// TODO | ||
proxy.applyTo(world, 0, 0); | ||
return null; | ||
} | ||
|
||
private static Proxy newProxy() { | ||
return new Proxy(); | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/mhfc/net/common/world/controller/DefaultProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package mhfc.net.common.world.controller; | ||
|
||
public class DefaultProxy { | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/mhfc/net/common/world/controller/IAreaManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package mhfc.net.common.world.controller; | ||
|
||
import mhfc.net.common.world.area.IActiveArea; | ||
import mhfc.net.common.world.area.IArea; | ||
import mhfc.net.common.world.area.IAreaType; | ||
|
||
public interface IAreaManager { | ||
/** | ||
* Gets an empty {@link IArea} of the {@link IAreaType} given. This tries to | ||
* reuse existing instances if possible. If no existing IArea of the type | ||
* can be found, a new one is created.<br> | ||
* The area is embedded in the {@link IActiveArea}. When the caller is | ||
* finished using the area he should call {@link IActiveArea#dismiss()} and | ||
* dispose his instance. | ||
* | ||
* @param type | ||
* the type of the requested area | ||
* @return an {@link IActiveArea} with an empty area that can be used for | ||
* e.g. questing | ||
*/ | ||
IActiveArea getEmptyInstance(IAreaType type); | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/mhfc/net/common/world/controller/IWorldProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package mhfc.net.common.world.controller; | ||
|
||
import mhfc.net.common.world.area.IAreaType; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.tileentity.TileEntity; | ||
|
||
/** | ||
* A proxy that may lead to a fake or a real world. Used to control the world | ||
* population by a {@link IAreaType}. A world proxy could have its (0, 0) offset | ||
* compared to the underlying world, or have no world at all.<br> | ||
* The proxy offers write-only access to the world so you shouldn't rely on | ||
* already spawned areas. | ||
* | ||
* @author WorldSEnder | ||
* | ||
*/ | ||
public interface IWorldProxy { | ||
void setBlockAt(int x, int y, int z, Block block); | ||
|
||
void setTileEntityAt(int x, int y, int z, TileEntity tile); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.