Skip to content

Commit

Permalink
Removed the velocity from being passed through dispenser recipes.
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Mar 4, 2018
1 parent 63c6dbe commit f679b3f
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Cannon() {
}

@Override
public boolean doAction(Dispenser dispenser, ItemStack[] recipe, Vector3d velocity) {
public boolean doAction(Dispenser dispenser, ItemStack[] recipe) {
Direction face = dispenser.getLocation().get(Keys.DIRECTION).orElse(Direction.NONE);
if (face != Direction.NONE) {
Location<World> location = dispenser.getLocation().getRelative(face).add(0.5, 0.5, 0.5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
*/
package com.sk89q.craftbook.sponge.mechanics.dispenser;

import com.flowpowered.math.vector.Vector3d;
import org.spongepowered.api.block.tileentity.carrier.Dispenser;
import org.spongepowered.api.item.inventory.ItemStack;

public interface DispenserRecipe {

boolean doesPass(ItemStack[] recipe);

boolean doAction(Dispenser dispenser, ItemStack[] recipe, Vector3d velocity);
boolean doAction(Dispenser dispenser, ItemStack[] recipe);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package com.sk89q.craftbook.sponge.mechanics.dispenser;

import com.flowpowered.math.vector.Vector3d;
import com.google.inject.Inject;
import com.me4502.modularframework.module.Module;
import com.me4502.modularframework.module.guice.ModuleConfiguration;
Expand Down Expand Up @@ -44,8 +43,6 @@
import java.util.List;
import java.util.stream.StreamSupport;

import javax.annotation.Nullable;

@Module(id = "dispenserrecipes", name = "DispenserRecipes", onEnable = "onInitialize", onDisable = "onDisable")
public class DispenserRecipes extends SpongeBlockMechanic implements DocumentationProvider {

Expand Down Expand Up @@ -110,7 +107,7 @@ public void onDispense(DropItemEvent.Dispense event, @First LocatableBlock dispe
}

Dispenser dispenserTile = (Dispenser) dispenser.getLocation().getTileEntity().get();
if (handleDispenserAction(dispenserTile, event.getEntities().get(0).getVelocity())) {
if (handleDispenserAction(dispenserTile)) {
event.setCancelled(true);
}
}
Expand All @@ -123,7 +120,7 @@ public void onCreateEntity(SpawnEntityEvent event, @First LocatableBlock dispens
}

Dispenser dispenserTile = (Dispenser) dispenser.getLocation().getTileEntity().get();
if (handleDispenserAction(dispenserTile, event.getEntities().get(0).getVelocity())) {
if (handleDispenserAction(dispenserTile)) {
event.setCancelled(true);
}
});
Expand All @@ -136,19 +133,19 @@ public void onChangeBlock(ChangeBlockEvent event, @First LocatableBlock dispense
}

Dispenser dispenserTile = (Dispenser) dispenser.getLocation().getTileEntity().get();
if (handleDispenserAction(dispenserTile, null)) {
if (handleDispenserAction(dispenserTile)) {
event.setCancelled(true);
}
}

public boolean handleDispenserAction(Dispenser dispenser, @Nullable Vector3d velocity) {
public boolean handleDispenserAction(Dispenser dispenser) {
for (DispenserRecipe recipe : recipes) {
ItemStack[] items = StreamSupport.stream(dispenser.getInventory().slots().spliterator(), false)
.map(Inventory::peek)
.map(opt -> opt.orElse(ItemStack.empty()))
.toArray(ItemStack[]::new);
if (recipe.doesPass(items)) {
if (recipe.doAction(dispenser, items, velocity)) {
if (recipe.doAction(dispenser, items)) {
dispenser.getInventory().slots().forEach(inv -> inv.poll(1)); // Take one of every stack.
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package com.sk89q.craftbook.sponge.mechanics.dispenser;

import com.flowpowered.math.vector.Vector3d;
import com.sk89q.craftbook.sponge.util.LocationUtil;
import org.spongepowered.api.block.BlockTypes;
import org.spongepowered.api.block.tileentity.carrier.Dispenser;
Expand All @@ -39,7 +38,7 @@ public Fan() {
}

@Override
public boolean doAction(Dispenser dispenser, ItemStack[] recipe, Vector3d velocity) {
public boolean doAction(Dispenser dispenser, ItemStack[] recipe) {
Direction face = dispenser.getLocation().get(Keys.DIRECTION).orElse(Direction.NONE);
if (face != Direction.NONE) {
Location<World> offset = dispenser.getLocation().getRelative(face);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public FireArrows() {
}

@Override
public boolean doAction(Dispenser dispenser, ItemStack[] recipe, Vector3d velocity) {
public boolean doAction(Dispenser dispenser, ItemStack[] recipe) {
Direction face = dispenser.getLocation().get(Keys.DIRECTION).orElse(Direction.NONE);
if (face != Direction.NONE) {
Location<World> location = dispenser.getLocation().getRelative(face).add(0.5, 0.5, 0.5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public SnowShooter() {
}

@Override
public boolean doAction(Dispenser dispenser, ItemStack[] recipe, Vector3d velocity) {
public boolean doAction(Dispenser dispenser, ItemStack[] recipe) {
Direction face = dispenser.getLocation().get(Keys.DIRECTION).orElse(Direction.NONE);
if (face != Direction.NONE) {
Location<World> location = dispenser.getLocation().getRelative(face).add(0.5, 0.5, 0.5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package com.sk89q.craftbook.sponge.mechanics.dispenser;

import com.flowpowered.math.vector.Vector3d;
import com.sk89q.craftbook.sponge.util.LocationUtil;
import org.spongepowered.api.block.BlockTypes;
import org.spongepowered.api.block.tileentity.carrier.Dispenser;
Expand All @@ -39,7 +38,7 @@ public Vacuum() {
}

@Override
public boolean doAction(Dispenser dispenser, ItemStack[] recipe, Vector3d velocity) {
public boolean doAction(Dispenser dispenser, ItemStack[] recipe) {
Direction face = dispenser.getLocation().get(Keys.DIRECTION).orElse(Direction.NONE);
if (face != Direction.NONE) {
Location<World> offset = dispenser.getLocation().getRelative(face);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ public XPShooter() {
}

@Override
public boolean doAction(Dispenser dispenser, ItemStack[] recipe, Vector3d velocity) {
public boolean doAction(Dispenser dispenser, ItemStack[] recipe) {
Direction face = dispenser.getLocation().get(Keys.DIRECTION).orElse(Direction.NONE);
if (face != Direction.NONE) {
Location<World> location = dispenser.getLocation().getRelative(face).add(0.5, 0.5, 0.5);
ThrownExpBottle bottle = (ThrownExpBottle) dispenser.getWorld().createEntity(EntityTypes.THROWN_EXP_BOTTLE, location.getPosition());
bottle.setVelocity(velocity);
Vector3d bottleVelocity = face.asOffset().add(0, 0.1f, 0).normalize().mul(1.5f);
bottle.setVelocity(bottleVelocity);
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.CUSTOM);
dispenser.getWorld().spawnEntity(bottle);
Expand Down

0 comments on commit f679b3f

Please sign in to comment.