Skip to content

Commit

Permalink
Completing seal animation.
Browse files Browse the repository at this point in the history
  • Loading branch information
aegistudio committed Mar 2, 2016
1 parent d95ee9a commit 48c4555
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 10 deletions.
9 changes: 7 additions & 2 deletions src/net/aegistudio/magick/book/MagickBookListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.InventoryType.SlotType;
import org.bukkit.event.player.PlayerInteractEvent;
Expand All @@ -20,8 +21,12 @@ public MagickBookListener(MagickElement element, String tryToClone) {
@EventHandler
public void onItemUse(PlayerInteractEvent event) {
if(!this.element.book.isMagickBook(event.getItem())) return;
this.element.handler.handleSpell(event.getPlayer(), event.getItem());
event.setCancelled(true);
if(event.getAction() == Action.RIGHT_CLICK_AIR
|| event.getAction() == Action.RIGHT_CLICK_BLOCK
|| event.getAction() == Action.PHYSICAL) {
this.element.handler.handleSpell(event.getPlayer(), event.getItem());
event.setCancelled(true);
}
}

/** Prevent magick book from cloning. **/
Expand Down
7 changes: 5 additions & 2 deletions src/net/aegistudio/magick/entity/Flamepillar.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.bukkit.Sound;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.FallingBlock;
import org.bukkit.util.Vector;

import net.aegistudio.magick.MagickElement;
import net.aegistudio.magick.Spawnable;
Expand All @@ -31,10 +30,14 @@ public void after(MagickElement element) {
@Override
public void spawn(Location location) {
location.getWorld().playSound(location, Sound.FIZZ, 1.0f, 1.0f);
FallingBlock previous = null;
for(int i = 0; i < 3; i ++) {
FallingBlock block = location.getWorld()
.spawnFallingBlock(location, Material.FIRE, (byte) 0);
block.setVelocity(new Vector(0, i * PILLAR_FACTOR, 0));
//block.setFireTicks(100);
//block.setVelocity(new Vector(0, i * PILLAR_FACTOR, 0));
if(previous != null) previous.setPassenger(block);
previous = block;
}
}
}
65 changes: 65 additions & 0 deletions src/net/aegistudio/magick/seal/AnimationFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package net.aegistudio.magick.seal;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;

import net.aegistudio.magick.MagickElement;

public class AnimationFactory implements PainterFactory {
public List<String> order;
public static final String ORDER = "order";

public Map<String, PainterFactory> factory;
public Map<String, Integer> ticks;
public static final String CLASS = "Class";
public static final String CONFIG = "Config";
public static final String TICKS = "Ticks";

@Override
public void load(MagickElement magick, ConfigurationSection config) throws Exception {
this.order = config.getStringList(ORDER);
this.factory = new TreeMap<String, PainterFactory>();
this.ticks = new TreeMap<String, Integer>();

for(String current : order) {
factory.put(current, magick.loadInstance(PainterFactory.class, config, current.concat(CLASS),
null, current.concat(CONFIG), null));
ticks.put(current, config.getInt(current.concat(TICKS)));
}
}

@Override
public void save(MagickElement element, ConfigurationSection config) throws Exception {
config.set(ORDER, order);
for(String current : order) {
PainterFactory pFactory = factory.get(current);
config.set(current.concat(CLASS), pFactory.getClass().getName());
if(!config.contains(current.concat(CONFIG))) config.createSection(current.concat(CONFIG));
pFactory.save(element, config.getConfigurationSection(current.concat(CONFIG)));

config.set(current.concat(TICKS), ticks.get(current));
}
}

@Override
public void after(MagickElement element) {
for(PainterFactory pf : this.factory.values())
pf.after(element);
}

@Override
public Painter newPainter(Entity entity) {
ArrayList<Painter> factory = new ArrayList<Painter>();
ArrayList<Integer> ticks = new ArrayList<Integer>();
for(String current : order) {
factory.add(this.factory.get(current).newPainter(entity));
ticks.add(this.ticks.get(current));
}
return new AnimationPainter(factory.toArray(new Painter[0]), ticks.toArray(new Integer[0]));
}
}
36 changes: 36 additions & 0 deletions src/net/aegistudio/magick/seal/AnimationPainter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package net.aegistudio.magick.seal;

public class AnimationPainter implements Painter {
protected final Painter[] painter;
protected final Integer[] tick;

protected int index;
protected int frame;

public AnimationPainter(Painter[] painter, Integer[] tick) {
this.painter = painter;
this.tick = tick;

this.index = 0;
this.frame = 0;
}

@Override
public void paint(double x, double y, double z) {
if(index < painter.length)
painter[index].paint(x, y, z);
}

@Override
public void end() {
if(index < tick.length) {
painter[index].end();
frame ++;

if(tick[index] >= 0 && frame > tick[index]) {
index ++;
frame = 0;
}
}
}
}
4 changes: 1 addition & 3 deletions src/net/aegistudio/magick/seal/PitchOrientPainter.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ public void end() {
public static final double FACTOR = Math.PI / 180;

public void calculateTranslation(Location orient) {
for(int i = 0; i < 4; i ++)
for(int j = 0; j < 4; j ++)
actual[i][j] = 0;
super.setZero();

double cosRotActual = Math.cos((-orient.getPitch() + initPhase) * FACTOR);
double sinRotActual = Math.sin((-orient.getPitch() + initPhase) * FACTOR);
Expand Down
12 changes: 12 additions & 0 deletions src/net/aegistudio/magick/seal/TransformPainter.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ public void paint(double x, double y, double z) {
next.paint(this.vec[0], this.vec[1], this.vec[2]);
}

protected void setZero() {
for(int i = 0; i < 4; i ++)
for(int j = 0; j < 4; j ++)
actual[i][j] = 0;
}

protected void addTrans() {
for(int i = 0; i < 4; i ++)
for(int j = 0; j < 4; j ++)
actual[i][j] += this.trans[i][j];
}

protected void multTrans() {
double[][] nextActual = new double[4][4];
for(int i = 0; i < 4; i ++)
Expand Down
4 changes: 1 addition & 3 deletions src/net/aegistudio/magick/seal/YawOrientPainter.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public void end() {
public static final double FACTOR = Math.PI / 180;

public void calculateTranslation(Location orient) {
for(int i = 0; i < 4; i ++)
for(int j = 0; j < 4; j ++)
actual[i][j] = 0;
super.setZero();

double cosRotActual = Math.cos(orient.getYaw() * FACTOR);
double sinRotActual = Math.sin(orient.getYaw() * FACTOR);
Expand Down
48 changes: 48 additions & 0 deletions src/net/aegistudio/magick/seal/ZoomFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package net.aegistudio.magick.seal;

import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;

import net.aegistudio.magick.MagickElement;

public class ZoomFactory extends WrappedPainterFactory {
private double init = 0.0;
public static final String INIT = "init";
private double zoom = 0.1;
public static final String ZOOM = "zoom";

@Override
public void load(MagickElement magick, ConfigurationSection config) throws Exception {
super.load(magick, config);
this.init = config.getDouble(INIT);
this.zoom = config.getDouble(ZOOM);
}

@Override
public void save(MagickElement element, ConfigurationSection config) throws Exception {
super.save(element, config);
config.set(INIT, init);
config.set(ZOOM, zoom);
}

@Override
public Painter newPainter(Entity entity) {
return new TransformPainter(this.wrapped.newPainter(entity), new double[][] {
{zoom, 0, 0, 0},
{0, zoom, 0, 0},
{0, 0, zoom, 0},
{0, 0, 0, 0}
}, new double[][] {
{init, 0, 0, 0},
{0, init, 0, 0},
{0, 0, init, 0},
{0, 0, 0, 1}
}){
@Override
public void end() {
this.addTrans();
this.next.end();
}
};
}
}

0 comments on commit 48c4555

Please sign in to comment.