Skip to content

Commit

Permalink
FAP
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberpwnn committed Dec 5, 2016
1 parent f7d1327 commit e07bbea
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 78 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.cyberpwn</groupId>
<artifactId>fap</artifactId>
<version>2.5</version>
<version>2.6</version>
<name>FAP</name>
<description>Fast Async Physics</description>
<properties>
Expand Down
168 changes: 91 additions & 77 deletions src/main/java/org/cyberpwn/fap/handler/PistonHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,61 +64,68 @@ public void on(BlockPistonExtendEvent e)

e.setCancelled(true);

new GSound(Sound.PISTON_EXTEND, 1f, 1.5f).play(e.getBlock().getLocation());
BlockFace face = e.getDirection();
GList<Block> blocks = new GList<Block>(e.getBlocks());
Block piston = e.getBlock();

for(Block i : blocks.copy())
{
if(!i.getType().isSolid() || i.getType().equals(Material.MELON_BLOCK))
{
i.breakNaturally();
blocks.remove(i);
}
}

for(Block i : blocks)
{
FAPController.wq.set(i.getLocation(), Material.AIR);
}

if(pushEntities)
{
push(piston, face);
}

for(Block i : blocks)
{
if(pushEntities)
{
push(i, face);
push(i.getRelative(BlockFace.DOWN), face);
push(i.getRelative(BlockFace.UP), face);
}

FAPController.wq.set(i.getLocation().clone().add(face.getModX(), face.getModY(), face.getModZ()), i.getType(), i.getData());
}

PistonExtensionMaterial pem = new PistonExtensionMaterial(Material.PISTON_EXTENSION);
PistonBaseMaterial pbm = (PistonBaseMaterial) piston.getState().getData();
pbm.setPowered(true);
pem.setSticky(pbm.isSticky());
pem.setFacingDirection(pbm.getFacing());

FAPController.wq.set(piston.getLocation(), pbm.getItemType(), pbm.getData());
FAPController.wq.set(piston.getLocation().clone().add(face.getModX(), face.getModY(), face.getModZ()), Material.PISTON_EXTENSION, pem.getData());
FAPController.wq.flush();

new TaskLater(2)
{
@Override
public void run()
{
new GSound(Sound.PISTON_EXTEND, 1f, 1.5f).play(e.getBlock().getLocation());
BlockFace face = e.getDirection();
GList<Block> blocks = new GList<Block>(e.getBlocks());
Block piston = e.getBlock();

for(Block i : blocks.copy())
{
if(!i.getType().isSolid() || i.getType().equals(Material.MELON_BLOCK))
{
i.breakNaturally();
blocks.remove(i);
}
}

for(Block i : blocks)
{
FAPController.wq.set(i.getLocation(), Material.AIR);
}

if(pushEntities)
{
push(piston, face);
}

for(Block i : blocks)
{
update(i.getLocation().clone().add(face.getModX(), face.getModY(), face.getModZ()).getBlock());
if(pushEntities)
{
push(i, face);
push(i.getRelative(BlockFace.DOWN), face);
push(i.getRelative(BlockFace.UP), face);
}

FAPController.wq.set(i.getLocation().clone().add(face.getModX(), face.getModY(), face.getModZ()), i.getType(), i.getData());
}

PistonExtensionMaterial pem = new PistonExtensionMaterial(Material.PISTON_EXTENSION);
PistonBaseMaterial pbm = (PistonBaseMaterial) piston.getState().getData();
pbm.setPowered(true);
pem.setSticky(pbm.isSticky());
pem.setFacingDirection(pbm.getFacing());

FAPController.wq.set(piston.getLocation(), pbm.getItemType(), pbm.getData());
FAPController.wq.set(piston.getLocation().clone().add(face.getModX(), face.getModY(), face.getModZ()), Material.PISTON_EXTENSION, pem.getData());
FAPController.wq.flush();

new TaskLater(2)
{
@Override
public void run()
{
for(Block i : blocks)
{
update(i.getLocation().clone().add(face.getModX(), face.getModY(), face.getModZ()).getBlock());
}
}
};
}
};
}
Expand All @@ -134,43 +141,50 @@ public void on(BlockPistonRetractEvent e)

e.setCancelled(true);

new GSound(Sound.PISTON_RETRACT, 1f, 1.5f).play(e.getBlock().getLocation());
BlockFace face = e.isSticky() ? e.getDirection().getOppositeFace() : e.getDirection();
GList<Block> blocks = new GList<Block>(e.getBlocks());
Block piston = e.getBlock();
PistonBaseMaterial pbm = new PistonBaseMaterial(e.isSticky() ? Material.PISTON_STICKY_BASE : Material.PISTON_BASE);
pbm.setPowered(false);
pbm.setFacingDirection(face);
FAPController.wq.set(piston.getLocation(), pbm.getItemType(), pbm.getData());
FAPController.wq.set(piston.getLocation().clone().add(face.getModX(), face.getModY(), face.getModZ()), Material.AIR);
face = face.getOppositeFace();

for(Block i : blocks)
{
FAPController.wq.set(i.getLocation(), Material.AIR);
}

for(Block i : blocks)
{
FAPController.wq.set(i.getLocation().clone().add(face.getModX(), face.getModY(), face.getModZ()), i.getType(), i.getData());
}

FAPController.wq.flush();

if(usePhoton)
{
Photon.relight(e.getBlock());
}

new TaskLater(2)
new TaskLater(4)
{
@Override
public void run()
{
new GSound(Sound.PISTON_RETRACT, 1f, 1.5f).play(e.getBlock().getLocation());
BlockFace face = e.isSticky() ? e.getDirection().getOppositeFace() : e.getDirection();
GList<Block> blocks = new GList<Block>(e.getBlocks());
Block piston = e.getBlock();
PistonBaseMaterial pbm = new PistonBaseMaterial(e.isSticky() ? Material.PISTON_STICKY_BASE : Material.PISTON_BASE);
pbm.setPowered(false);
pbm.setFacingDirection(face);
FAPController.wq.set(piston.getLocation(), pbm.getItemType(), pbm.getData());
FAPController.wq.set(piston.getLocation().clone().add(face.getModX(), face.getModY(), face.getModZ()), Material.AIR);
face = face.getOppositeFace();

for(Block i : blocks)
{
update(i);
FAPController.wq.set(i.getLocation(), Material.AIR);
}

for(Block i : blocks)
{
FAPController.wq.set(i.getLocation().clone().add(face.getModX(), face.getModY(), face.getModZ()), i.getType(), i.getData());
}

FAPController.wq.flush();

if(usePhoton)
{
Photon.relight(e.getBlock());
}

new TaskLater(2)
{
@Override
public void run()
{
for(Block i : blocks)
{
update(i);
}
}
};
}
};
}
Expand Down

0 comments on commit e07bbea

Please sign in to comment.