mirror of
https://github.com/Ste3et/furniture.git
synced 2024-11-22 10:36:12 +01:00
Fix Campfire#2 Cooking finally
This commit is contained in:
parent
efb2131ccc
commit
2887aa1c0b
@ -26,24 +26,15 @@ import de.Ste3et_C0st.FurnitureLib.main.Type.SQLAction;
|
||||
import de.Ste3et_C0st.FurnitureLib.main.entity.fArmorStand;
|
||||
import de.Ste3et_C0st.FurnitureLib.main.entity.fEntity;
|
||||
|
||||
public class campfire_2 extends Furniture{
|
||||
private List<Material> items = new ArrayList<Material>(
|
||||
Arrays.asList(
|
||||
public class campfire_2 extends Furniture {
|
||||
private List<Material> items = new ArrayList<Material>(Arrays.asList(
|
||||
Material.valueOf(FurnitureHook.isNewVersion() ? "BEEF" : "RAW_BEEF"),
|
||||
Material.valueOf(FurnitureHook.isNewVersion() ? "CHICKEN" : "RAW_CHICKEN"),
|
||||
Material.valueOf(FurnitureHook.isNewVersion() ? "COD" : "RAW_FISH"),
|
||||
Material.POTATO,
|
||||
Material.valueOf(FurnitureHook.isNewVersion() ? "PORKCHOP" : "PORK"),
|
||||
Material.RABBIT,
|
||||
Material.MUTTON
|
||||
)
|
||||
);
|
||||
Material.valueOf(FurnitureHook.isNewVersion() ? "COD" : "RAW_FISH"), Material.POTATO,
|
||||
Material.valueOf(FurnitureHook.isNewVersion() ? "PORKCHOP" : "PORK"), Material.RABBIT, Material.MUTTON));
|
||||
|
||||
private EulerAngle[] angle = {
|
||||
new EulerAngle(-1.5, -.5, 0),
|
||||
new EulerAngle(-1.9, -.3, .7),
|
||||
new EulerAngle(-1.5, .3, 1.9),
|
||||
new EulerAngle(-0.7, -.5, -1.2)
|
||||
private EulerAngle[] angle = { new EulerAngle(-1.5, -.5, 0), new EulerAngle(-1.9, -.3, .7),
|
||||
new EulerAngle(-1.5, .3, 1.9), new EulerAngle(-0.7, -.5, -1.2)
|
||||
|
||||
};
|
||||
|
||||
@ -53,77 +44,84 @@ public class campfire_2 extends Furniture{
|
||||
private fArmorStand armorS;
|
||||
private ItemStack is;
|
||||
|
||||
public campfire_2(ObjectID id){
|
||||
public campfire_2(ObjectID id) {
|
||||
super(id);
|
||||
this.middle = getLutil().getCenter(getLocation());
|
||||
this.middle = getLutil().getRelativ(middle, getBlockFace(), .5D, -.5D);
|
||||
this.middle.add(0,-1.2,0);
|
||||
this.middle.add(0, -1.2, 0);
|
||||
|
||||
this.grill = getLutil().getRelativ(middle,getBlockFace(), .0D, .5D);
|
||||
this.grill.setYaw(getLutil().FaceToYaw(getBlockFace())+90);
|
||||
if(id.isFinish()){
|
||||
this.grill = getLutil().getRelativ(middle, getBlockFace(), .0D, .5D);
|
||||
this.grill.setYaw(getLutil().FaceToYaw(getBlockFace()) + 90);
|
||||
if (id.isFinish()) {
|
||||
return;
|
||||
}
|
||||
spawn(id.getStartLocation());
|
||||
}
|
||||
|
||||
public void spawn(Location loc){}
|
||||
public void spawn(Location loc) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(Player player){
|
||||
if(getObjID() == null) return;
|
||||
if(getObjID().getSQLAction().equals(SQLAction.REMOVE)) return;
|
||||
if(player == null) return;
|
||||
if(canBuild(player)) {
|
||||
public void onClick(Player player) {
|
||||
if (getObjID() == null)
|
||||
return;
|
||||
if (getObjID().getSQLAction().equals(SQLAction.REMOVE))
|
||||
return;
|
||||
if (player == null)
|
||||
return;
|
||||
if (canBuild(player)) {
|
||||
List<fEntity> aspList = getManager().getfArmorStandByObjectID(getObjID());
|
||||
final ItemStack itemStack = player.getInventory().getItemInMainHand();
|
||||
fArmorStand packet = null;
|
||||
for(fEntity pack : aspList){
|
||||
if(pack instanceof fArmorStand){
|
||||
for (fEntity pack : aspList) {
|
||||
if (pack instanceof fArmorStand) {
|
||||
fArmorStand stand = (fArmorStand) pack;
|
||||
if(stand.isSmall() && pack.isInvisible()){
|
||||
if (stand.isSmall() && pack.isInvisible()) {
|
||||
packet = stand;
|
||||
if(packet.isFire()) {
|
||||
if (packet.isFire()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(itemStack.getType().equals(Material.WATER_BUCKET) && packet.isFire()){
|
||||
if (itemStack.getType().equals(Material.WATER_BUCKET) && packet.isFire()) {
|
||||
setfire(false);
|
||||
}else if(itemStack.getType().equals(Material.FLINT_AND_STEEL) && !packet.isFire()){
|
||||
} else if (itemStack.getType().equals(Material.FLINT_AND_STEEL) && !packet.isFire()) {
|
||||
setfire(true);
|
||||
}else if(items.contains(itemStack.getType()) && packet.isFire() && armorS==null){
|
||||
} else if (items.contains(itemStack.getType()) && packet.isFire() && armorS == null) {
|
||||
is = itemStack.clone();
|
||||
is.setAmount(1);
|
||||
|
||||
setGrill();
|
||||
|
||||
if(player.getGameMode().equals(GameMode.CREATIVE) && getLib().useGamemode()) return;
|
||||
if (player.getGameMode().equals(GameMode.CREATIVE) && getLib().useGamemode())
|
||||
return;
|
||||
Integer i = player.getInventory().getHeldItemSlot();
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
item.setAmount(item.getAmount()-1);
|
||||
item.setAmount(item.getAmount() - 1);
|
||||
player.getInventory().setItem(i, item);
|
||||
player.updateInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setfire(boolean b){
|
||||
private void setfire(boolean b) {
|
||||
Location loc = getCenter().clone();
|
||||
loc.add(0, 1.3, 0);
|
||||
if(b){
|
||||
if (b) {
|
||||
getLib().getLightManager().addLight(loc, 15);
|
||||
}else{
|
||||
} else {
|
||||
getLib().getLightManager().removeLight(loc);
|
||||
}
|
||||
|
||||
for(fEntity entity : getfAsList()){
|
||||
if(entity instanceof fArmorStand){
|
||||
for (fEntity entity : getfAsList()) {
|
||||
if (entity instanceof fArmorStand) {
|
||||
fArmorStand stand = (fArmorStand) entity;
|
||||
if((stand.getInventory().getHelmet() == null || stand.getInventory().getHelmet().getType().equals(Material.AIR)) &&
|
||||
(stand.getInventory().getItemInMainHand() == null || stand.getInventory().getItemInMainHand().getType().equals(Material.AIR))){
|
||||
if(stand.isSmall() && entity.isInvisible()){
|
||||
if ((stand.getInventory().getHelmet() == null
|
||||
|| stand.getInventory().getHelmet().getType().equals(Material.AIR))
|
||||
&& (stand.getInventory().getItemInMainHand() == null
|
||||
|| stand.getInventory().getItemInMainHand().getType().equals(Material.AIR))) {
|
||||
if (stand.isSmall() && entity.isInvisible()) {
|
||||
stand.setFire(b);
|
||||
}
|
||||
}
|
||||
@ -134,13 +132,16 @@ public class campfire_2 extends Furniture{
|
||||
|
||||
@Override
|
||||
public void onBreak(Player player) {
|
||||
if(getObjID() == null) return;
|
||||
if(getObjID().getSQLAction().equals(SQLAction.REMOVE)) return;
|
||||
if(player == null) return;
|
||||
if(canBuild(player)) {
|
||||
if(isRunning()){
|
||||
if (getObjID() == null)
|
||||
return;
|
||||
if (getObjID().getSQLAction().equals(SQLAction.REMOVE))
|
||||
return;
|
||||
if (player == null)
|
||||
return;
|
||||
if (canBuild(player)) {
|
||||
if (isRunning()) {
|
||||
Bukkit.getScheduler().cancelTask(timer);
|
||||
timer=null;
|
||||
timer = null;
|
||||
getWorld().dropItemNaturally(middle.clone().add(0, 1, 0), is).setVelocity(new Vector().zero());
|
||||
}
|
||||
setfire(false);
|
||||
@ -148,52 +149,67 @@ public class campfire_2 extends Furniture{
|
||||
}
|
||||
}
|
||||
|
||||
public void removeGrill(){
|
||||
if(isRunning()){
|
||||
public void removeGrill() {
|
||||
if (isRunning()) {
|
||||
Bukkit.getScheduler().cancelTask(timer);
|
||||
timer=null;
|
||||
if(armorS!=null&&armorS.getInventory().getItemInMainHand()!=null&&getItem(armorS.getInventory().getItemInMainHand())!=null){
|
||||
getWorld().dropItemNaturally(middle.clone().add(0, 1, 0), getCooked(is)).setVelocity(new Vector().zero());
|
||||
timer = null;
|
||||
if (armorS != null && armorS.getInventory().getItemInMainHand() != null
|
||||
&& getItem(armorS.getInventory().getItemInMainHand()) != null) {
|
||||
getWorld().dropItemNaturally(middle.clone().add(0, 1, 0), getCooked(is))
|
||||
.setVelocity(new Vector().zero());
|
||||
getObjID().getPacketList().remove(this.armorS);
|
||||
armorS.kill();
|
||||
armorS.delete();
|
||||
armorS=null;
|
||||
armorS = null;
|
||||
}
|
||||
}
|
||||
if(armorS!=null){
|
||||
if(armorS.getInventory().getItemInMainHand()!=null){getWorld().dropItemNaturally(middle.clone().add(0, 1, 0), getCooked(is)).setVelocity(new Vector().zero());}
|
||||
if (armorS != null) {
|
||||
if (armorS.getInventory().getItemInMainHand() != null) {
|
||||
getWorld().dropItemNaturally(middle.clone().add(0, 1, 0), getCooked(is))
|
||||
.setVelocity(new Vector().zero());
|
||||
}
|
||||
getObjID().getPacketList().remove(this.armorS);
|
||||
armorS.kill();
|
||||
armorS.delete();
|
||||
armorS=null;
|
||||
armorS = null;
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
public ItemStack getItem(ItemStack is){
|
||||
if(is==null){return null;}
|
||||
if(is.getType()==null){return null;}
|
||||
if(items.contains(is.getType())){
|
||||
public ItemStack getItem(ItemStack is) {
|
||||
if (is == null) {
|
||||
return null;
|
||||
}
|
||||
if (is.getType() == null) {
|
||||
return null;
|
||||
}
|
||||
if (items.contains(is.getType())) {
|
||||
return is;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ItemStack getCooked(ItemStack is){
|
||||
if(is==null){return null;}
|
||||
if(is.getType()==null){return null;}
|
||||
if(items.contains(is.getType())){
|
||||
public ItemStack getCooked(ItemStack is) {
|
||||
if (is == null) {
|
||||
return null;
|
||||
}
|
||||
if (is.getType() == null) {
|
||||
return null;
|
||||
}
|
||||
if (items.contains(is.getType())) {
|
||||
Material mat = null;
|
||||
int rnd = (int)(Math.random()*100);
|
||||
if(rnd < 5) {
|
||||
int rnd = (int) (Math.random() * 100);
|
||||
if (rnd < 5) {
|
||||
mat = Material.COAL;
|
||||
}else {
|
||||
} else {
|
||||
Iterator<Recipe> recipes = Bukkit.recipeIterator();
|
||||
while (recipes.hasNext()) {
|
||||
if (recipes.next() instanceof FurnaceRecipe == false) continue;
|
||||
FurnaceRecipe frecipe = (FurnaceRecipe) recipes.next();
|
||||
if(frecipe.getInput().getType().equals(is.getType())) {
|
||||
frecipe.getResult();
|
||||
Recipe recipe = recipes.next();
|
||||
if(Objects.isNull(recipe)) continue;
|
||||
if (recipe instanceof FurnaceRecipe == false) continue;
|
||||
FurnaceRecipe frecipe = (FurnaceRecipe) recipe;
|
||||
if (frecipe.getInput().getType().equals(is.getType())) {
|
||||
return frecipe.getResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -202,26 +218,35 @@ public class campfire_2 extends Furniture{
|
||||
return is;
|
||||
}
|
||||
|
||||
public boolean isRunning(){
|
||||
if(timer==null){return false;}
|
||||
public boolean isRunning() {
|
||||
if (timer == null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setGrill(){
|
||||
public void setGrill() {
|
||||
this.armorS = getManager().createArmorStand(getObjID(), grill);
|
||||
this.armorS.setInvisible(true);
|
||||
this.armorS.getInventory().setItemInMainHand(is);
|
||||
getObjID().getPlayerList().clear();
|
||||
send();
|
||||
this.timer = main.getInstance().getServer().getScheduler().scheduleSyncRepeatingTask(main.getInstance(), new Runnable() {
|
||||
this.timer = main.getInstance().getServer().getScheduler().scheduleSyncRepeatingTask(main.getInstance(),
|
||||
new Runnable() {
|
||||
Integer rounds = getLutil().randInt(15, 30);
|
||||
Integer labs = 0;
|
||||
Integer position = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if(labs>=rounds){removeGrill();return;}
|
||||
if(position>3){position=0;}
|
||||
if(armorS!=null){
|
||||
if (labs >= rounds) {
|
||||
removeGrill();
|
||||
return;
|
||||
}
|
||||
if (position > 3) {
|
||||
position = 0;
|
||||
}
|
||||
if (armorS != null) {
|
||||
armorS.setPose(angle[position], BodyPart.RIGHT_ARM);
|
||||
update();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user