Skip to content

Commit

Permalink
Latest changes from questing branch also included
Browse files Browse the repository at this point in the history
Merge remote-tracking branch 'origin/questing'

Conflicts:
	src/main/resources/assets/mhfc/textures/gui/GuiList.png
  • Loading branch information
HeroicKatora committed Apr 15, 2015
2 parents 552ccc2 + 5649b01 commit 73ea1d9
Show file tree
Hide file tree
Showing 12 changed files with 280 additions and 5 deletions.
28 changes: 28 additions & 0 deletions src/main/java/mhfc/net/common/quests/party/IParty.java
@@ -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 src/main/java/mhfc/net/common/world/area/ActiveAreaAdapter.java
@@ -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();
}

}
30 changes: 30 additions & 0 deletions src/main/java/mhfc/net/common/world/area/IActiveArea.java
@@ -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();
}
20 changes: 20 additions & 0 deletions src/main/java/mhfc/net/common/world/area/IArea.java
@@ -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();
}
12 changes: 12 additions & 0 deletions src/main/java/mhfc/net/common/world/area/IAreaType.java
@@ -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 src/main/java/mhfc/net/common/world/controller/DefaultAreaManager.java
@@ -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();
}

}
@@ -0,0 +1,5 @@
package mhfc.net.common.world.controller;

public class DefaultProxy {

}
22 changes: 22 additions & 0 deletions src/main/java/mhfc/net/common/world/controller/IAreaManager.java
@@ -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 src/main/java/mhfc/net/common/world/controller/IWorldProxy.java
@@ -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);
}
10 changes: 5 additions & 5 deletions src/main/resources/assets/mhfc/lang/en_US.lang
Expand Up @@ -195,11 +195,11 @@ item.longsword_14.name=Mirage Finsword+
item.longsword_15.name=Phantom Mirage


entity.mhfc.tigrex.name=Tigrex
entity.mhfc.kirin.name=Kirin
entity.mhfc.rathalos.name=Rathalos
entity.mhfc.popo.name=Popo
entity.mhfc.aptonoth.name=Aptonoth
entity.tigrex.name=Tigrex
entity.kirin.name=Kirin
entity.rathalos.name=Rathalos
entity.popo.name=Popo
entity.aptonoth.name=Aptonoth

potion.kirinbless=Spark of Kirin
potion.paralyze=Paralyze
Expand Down
Binary file modified src/main/resources/assets/mhfc/textures/gui/GuiList.png
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.

0 comments on commit 73ea1d9

Please sign in to comment.