|
@@ -2,11 +2,13 @@ package me.km.snuviscript;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
|
+import java.util.List;
|
|
import java.util.function.Consumer;
|
|
import java.util.function.Consumer;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
import me.hammerle.snuviscript.code.Script;
|
|
import me.hammerle.snuviscript.code.Script;
|
|
import me.hammerle.snuviscript.code.SnuviUtils;
|
|
import me.hammerle.snuviscript.code.SnuviUtils;
|
|
import me.hammerle.snuviscript.inputprovider.Variable;
|
|
import me.hammerle.snuviscript.inputprovider.Variable;
|
|
|
|
+import me.kcm.BlockHarvest;
|
|
import me.km.utils.Utils;
|
|
import me.km.utils.Utils;
|
|
import me.km.entities.EntityHuman;
|
|
import me.km.entities.EntityHuman;
|
|
import me.km.entities.EntityItemProjectile;
|
|
import me.km.entities.EntityItemProjectile;
|
|
@@ -14,6 +16,8 @@ import me.km.events.CommandEvent;
|
|
import me.km.inventory.ModInventory;
|
|
import me.km.inventory.ModInventory;
|
|
import me.km.utils.ExplosionUtils;
|
|
import me.km.utils.ExplosionUtils;
|
|
import me.km.utils.Location;
|
|
import me.km.utils.Location;
|
|
|
|
+import net.minecraft.block.Block;
|
|
|
|
+import net.minecraft.block.BlockState;
|
|
import net.minecraft.command.ICommandSource;
|
|
import net.minecraft.command.ICommandSource;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.LivingEntity;
|
|
import net.minecraft.entity.LivingEntity;
|
|
@@ -23,10 +27,14 @@ import net.minecraft.inventory.container.ClickType;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.server.MinecraftServer;
|
|
import net.minecraft.server.MinecraftServer;
|
|
import net.minecraft.server.management.PlayerList;
|
|
import net.minecraft.server.management.PlayerList;
|
|
|
|
+import net.minecraft.tileentity.TileEntity;
|
|
import net.minecraft.util.math.*;
|
|
import net.minecraft.util.math.*;
|
|
import net.minecraft.util.text.ITextComponent;
|
|
import net.minecraft.util.text.ITextComponent;
|
|
import net.minecraft.util.text.StringTextComponent;
|
|
import net.minecraft.util.text.StringTextComponent;
|
|
import net.minecraft.world.GameRules;
|
|
import net.minecraft.world.GameRules;
|
|
|
|
+import net.minecraft.world.server.ServerWorld;
|
|
|
|
+import net.minecraft.world.storage.loot.LootContext;
|
|
|
|
+import net.minecraft.world.storage.loot.LootParameters;
|
|
import net.minecraftforge.event.ServerChatEvent;
|
|
import net.minecraftforge.event.ServerChatEvent;
|
|
import net.minecraftforge.event.TickEvent;
|
|
import net.minecraftforge.event.TickEvent;
|
|
import net.minecraftforge.event.entity.*;
|
|
import net.minecraftforge.event.entity.*;
|
|
@@ -40,7 +48,7 @@ import net.minecraftforge.eventbus.api.*;
|
|
import net.minecraftforge.event.entity.player.PlayerEvent;
|
|
import net.minecraftforge.event.entity.player.PlayerEvent;
|
|
import net.minecraftforge.eventbus.api.Event.Result;
|
|
import net.minecraftforge.eventbus.api.Event.Result;
|
|
|
|
|
|
-public class ScriptEvents {
|
|
+public class ScriptEvents implements BlockHarvest {
|
|
private static void setLivingEntity(Script sc, LivingEntity ent) {
|
|
private static void setLivingEntity(Script sc, LivingEntity ent) {
|
|
sc.setVar("living_entity", ent);
|
|
sc.setVar("living_entity", ent);
|
|
}
|
|
}
|
|
@@ -307,13 +315,12 @@ public class ScriptEvents {
|
|
sc.setVar("looting", (double) e.getLootingLevel());
|
|
sc.setVar("looting", (double) e.getLootingLevel());
|
|
}, null);
|
|
}, null);
|
|
}
|
|
}
|
|
-
|
|
+
|
|
@SubscribeEvent(receiveCanceled = true)
|
|
@SubscribeEvent(receiveCanceled = true)
|
|
public void onLivingExperienceDrop(LivingExperienceDropEvent e) {
|
|
public void onLivingExperienceDrop(LivingExperienceDropEvent e) {
|
|
handleEvent(e, "living_experience_drop", (sc) -> {
|
|
handleEvent(e, "living_experience_drop", (sc) -> {
|
|
setLivingEntity(sc, e.getEntityLiving());
|
|
setLivingEntity(sc, e.getEntityLiving());
|
|
sc.setVar("experience", (double) e.getDroppedExperience());
|
|
sc.setVar("experience", (double) e.getDroppedExperience());
|
|
- sc.setVar("original_experience", (double) e.getOriginalExperience());
|
|
|
|
}, (sc) -> {
|
|
}, (sc) -> {
|
|
handleVar(sc, "living_experience_drop", "experience", v -> e.setDroppedExperience(v.getInt(sc)));
|
|
handleVar(sc, "living_experience_drop", "experience", v -> e.setDroppedExperience(v.getInt(sc)));
|
|
});
|
|
});
|
|
@@ -367,6 +374,33 @@ public class ScriptEvents {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public List<ItemStack> onBlockHarvest(BlockState state, ServerWorld w, BlockPos pos, TileEntity tileEnt, Entity ent, ItemStack stack) {
|
|
|
|
+ LootContext.Builder loot = new LootContext.Builder(w)
|
|
|
|
+ .withRandom(w.getRandom())
|
|
|
|
+ .withParameter(LootParameters.POSITION, pos)
|
|
|
|
+ .withParameter(LootParameters.TOOL, stack == null ? ItemStack.EMPTY : stack)
|
|
|
|
+ .withNullableParameter(LootParameters.THIS_ENTITY, ent)
|
|
|
|
+ .withNullableParameter(LootParameters.BLOCK_ENTITY, tileEnt);
|
|
|
|
+ List<ItemStack> list = state.getDrops(loot);
|
|
|
|
+ try {
|
|
|
|
+ final Block b = state.getBlock();
|
|
|
|
+ final String name = b.getRegistryName().toString();
|
|
|
|
+ scripts.getScriptManager().callEvent("block_drop", sc -> {
|
|
|
|
+ sc.setVar("drops", list);
|
|
|
|
+ sc.setVar("block_type", name);
|
|
|
|
+ sc.setVar("block", b);
|
|
|
|
+ sc.setVar("location", new Location(w, pos));
|
|
|
|
+ ScriptVars.setEntityVars(sc, ent);
|
|
|
|
+ setItem(sc, stack);
|
|
|
|
+ }, sc -> {
|
|
|
|
+ });
|
|
|
|
+ } catch(Exception ex) {
|
|
|
|
+ ex.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
@SubscribeEvent(receiveCanceled = true)
|
|
@SubscribeEvent(receiveCanceled = true)
|
|
public void onBlockHarvest(BlockEvent.HarvestDropsEvent e) {
|
|
public void onBlockHarvest(BlockEvent.HarvestDropsEvent e) {
|
|
handleEvent(e, "block_harvest", (sc) -> {
|
|
handleEvent(e, "block_harvest", (sc) -> {
|
|
@@ -681,6 +715,7 @@ public class ScriptEvents {
|
|
}
|
|
}
|
|
rider.remove();
|
|
rider.remove();
|
|
});
|
|
});
|
|
|
|
+ e.getEntity().removePassengers();
|
|
e.setCanceled(true);
|
|
e.setCanceled(true);
|
|
return;
|
|
return;
|
|
}
|
|
}
|