This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds GlowBat, GlowChicken, GlowHorse, GlowPig, GlowRabbit, GlowSheep, GlowTameable, GlowAgeable, GlowAmbient, GlowAnimal, BoundingBox, and EntityBoundingBox. This is part of a larger feature addition to Glowstone to implementing all entities from the Bukkit API. This depends on GlowstoneMC/Glowkit#31
- Loading branch information
Showing
17 changed files
with
824 additions
and
6 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,121 @@ | ||
package net.glowstone.entity; | ||
|
||
import com.flowpowered.networking.Message; | ||
import net.glowstone.entity.meta.MetadataIndex; | ||
import net.glowstone.entity.meta.MetadataMap; | ||
import net.glowstone.net.message.play.entity.EntityMetadataMessage; | ||
import org.bukkit.Location; | ||
import org.bukkit.entity.Ageable; | ||
import org.bukkit.entity.EntityType; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Represents a creature that ages, such as a sheep. | ||
*/ | ||
public class GlowAgeable extends GlowCreature implements Ageable { | ||
|
||
private static final int AGE_BABY = -24000; | ||
private static final int AGE_ADULT = 0; | ||
private static final int BREEDING_AGE = 6000; | ||
protected float width, height; | ||
private int age = 0; | ||
private boolean ageLocked = false; | ||
|
||
/** | ||
* Creates a new ageable monster. | ||
* @param location The location of the monster. | ||
* @param type The type of monster. | ||
*/ | ||
public GlowAgeable(Location location, EntityType type) { | ||
super(location, type); | ||
} | ||
|
||
@Override | ||
public void pulse() { | ||
super.pulse(); | ||
if (this.ageLocked) { | ||
setScaleForAge(!isAdult()); | ||
} else { | ||
int currentAge = this.age; | ||
if (currentAge < AGE_ADULT) { | ||
currentAge++; | ||
setAge(currentAge); | ||
} else if (currentAge > AGE_ADULT) { | ||
currentAge--; | ||
setAge(currentAge); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public final int getAge() { | ||
return this.age; | ||
} | ||
|
||
@Override | ||
public final void setAge(int age) { | ||
this.age = age; | ||
this.setScaleForAge(isAdult()); | ||
} | ||
|
||
@Override | ||
public final boolean getAgeLock() { | ||
return this.ageLocked; | ||
} | ||
|
||
@Override | ||
public final void setAgeLock(boolean ageLocked) { | ||
this.ageLocked = ageLocked; | ||
} | ||
|
||
@Override | ||
public final void setBaby() { | ||
if (isAdult()) { | ||
setAge(AGE_BABY); | ||
} | ||
} | ||
|
||
@Override | ||
public final void setAdult() { | ||
if (!isAdult()) { | ||
setAge(AGE_ADULT); | ||
} | ||
} | ||
|
||
@Override | ||
public final boolean isAdult() { | ||
return this.age >= AGE_ADULT; | ||
} | ||
|
||
@Override | ||
public final boolean canBreed() { | ||
return this.age == AGE_ADULT; | ||
} | ||
|
||
@Override | ||
public void setBreed(boolean breed) { | ||
if (breed) { | ||
setAge(AGE_ADULT); | ||
} else if (isAdult()) { | ||
setAge(BREEDING_AGE); | ||
} | ||
} | ||
|
||
public void setScaleForAge(boolean isAdult) { | ||
setScale(isAdult ? 1.0F : 0.5F); | ||
} | ||
|
||
@Override | ||
public List<Message> createSpawnMessage() { | ||
List<Message> messages = super.createSpawnMessage(); | ||
MetadataMap map = new MetadataMap(GlowAgeable.class); | ||
map.set(MetadataIndex.AGE, this.getAge()); | ||
messages.add(new EntityMetadataMessage(id, map.getEntryList())); | ||
return messages; | ||
} | ||
|
||
protected final void setScale(float scale) { | ||
setSize(this.height * scale, this.width * scale); | ||
} | ||
} |
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,11 @@ | ||
package net.glowstone.entity; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.entity.Ambient; | ||
|
||
public abstract class GlowAmbient extends GlowLivingEntity implements Ambient { | ||
|
||
public GlowAmbient(Location location) { | ||
super(location); | ||
} | ||
} |
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 net.glowstone.entity; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.entity.Animals; | ||
import org.bukkit.entity.EntityType; | ||
|
||
/** | ||
* Represents an Animal, such as a Cow | ||
*/ | ||
public class GlowAnimal extends GlowAgeable implements Animals { | ||
|
||
/** | ||
* Creates a new ageable animal. | ||
* @param location The location of the animal. | ||
* @param type The type of animal. | ||
*/ | ||
public GlowAnimal(Location location, EntityType type) { | ||
super(location, type); | ||
} | ||
} |
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
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
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
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,60 @@ | ||
package net.glowstone.entity.passive; | ||
|
||
import com.flowpowered.networking.Message; | ||
import net.glowstone.entity.GlowAmbient; | ||
import net.glowstone.entity.meta.MetadataIndex; | ||
import net.glowstone.entity.meta.MetadataMap; | ||
import net.glowstone.net.message.play.entity.EntityHeadRotationMessage; | ||
import net.glowstone.net.message.play.entity.EntityMetadataMessage; | ||
import net.glowstone.net.message.play.entity.SpawnMobMessage; | ||
import net.glowstone.util.Position; | ||
import org.bukkit.Location; | ||
import org.bukkit.entity.Bat; | ||
import org.bukkit.entity.EntityType; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
public class GlowBat extends GlowAmbient implements Bat { | ||
|
||
private boolean isAwake; | ||
|
||
public GlowBat(Location location) { | ||
super(location); | ||
} | ||
|
||
@Override | ||
public List<Message> createSpawnMessage() { | ||
List<Message> result = new LinkedList<>(); | ||
|
||
// spawn mob | ||
int x = Position.getIntX(location); | ||
int y = Position.getIntY(location); | ||
int z = Position.getIntZ(location); | ||
int yaw = Position.getIntYaw(location); | ||
int pitch = Position.getIntPitch(location); | ||
result.add(new SpawnMobMessage(id, getType().getTypeId(), x, y, z, yaw, pitch, pitch, 0, 0, 0, metadata.getEntryList())); | ||
|
||
// head facing | ||
result.add(new EntityHeadRotationMessage(id, yaw)); | ||
MetadataMap map = new MetadataMap(GlowBat.class); | ||
map.set(MetadataIndex.BAT_HANGING, (byte) (this.isAwake ? 1 : 0)); | ||
result.add(new EntityMetadataMessage(id, map.getEntryList())); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean isAwake() { | ||
return isAwake; | ||
} | ||
|
||
@Override | ||
public void setAwake(boolean isAwake) { | ||
this.isAwake = isAwake; | ||
} | ||
|
||
@Override | ||
public EntityType getType() { | ||
return EntityType.BAT; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/net/glowstone/entity/passive/GlowChicken.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,14 @@ | ||
package net.glowstone.entity.passive; | ||
|
||
import net.glowstone.entity.GlowAnimal; | ||
import org.bukkit.Location; | ||
import org.bukkit.entity.Chicken; | ||
import org.bukkit.entity.EntityType; | ||
|
||
public class GlowChicken extends GlowAnimal implements Chicken { | ||
|
||
public GlowChicken(Location location) { | ||
super(location, EntityType.CHICKEN); | ||
setSize(0.3F, 0.7F); | ||
} | ||
} |
Oops, something went wrong.