-
Notifications
You must be signed in to change notification settings - Fork 2
/
calclavia-ICBM.js
145 lines (114 loc) · 6.29 KB
/
calclavia-ICBM.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
"use strict";
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Explosion = (function () {
function Explosion(world, position, strength) {
_classCallCheck(this, Explosion);
this.world = world;
this.position = position;
this.strength = strength;
}
_createClass(Explosion, [{
key: "doExplosion",
value: function doExplosion() {
var _this = this;
for (var x = -this.strength; x < this.strength; x++) {
for (var y = -this.strength; y < this.strength; y++) {
for (var z = -this.strength; z < this.strength; z++) {
var checkPos = this.position.add(new Vector3D(x, y, z));
if (checkPos.distance(this.position) <= this.strength) {
this.world.removeBlock(Vector3DUtil.floor(checkPos));
this.world.addClientEntity(entityManager.get("minecraft:smoke").get()).setPosition(checkPos);
this.world.addClientEntity(entityManager.get("minecraft:explode").get()).setPosition(checkPos);
}
}
}
}
if (networkManager.isServer()) {
//Damage entities
this.world.getEntities(nova.util.shape.Cuboid.ONE.expand(this.strength).add(this.position)).forEach(function (entity) {
print("Found entity: " + entity);
if (entity.components.has(nova.component.misc.Damageable["class"])) {
entity.components.get(nova.component.misc.Damageable["class"]).damage(_this.strength);
}
});
}
//Play sound effect
this.world.playSoundAtPosition(this.position, new nova.sound.Sound("icbm", "explode-small").withVolume(2));
//Spawn particles
this.world.addClientEntity(entityManager.get("minecraft:largeexplode").get()).setPosition(this.position);
}
}]);
return Explosion;
})();
"use strict";
var dependencies = ["https://raw.githubusercontent.com/calclavia/ICBM-Classic/ltm/icbm.zip"];
function main() {
var textureExplosiveBottom = new nova.render.texture.BlockTexture("icbm", "explosive_bottom_1");
var textureExplosiveSide = new nova.render.texture.BlockTexture("icbm", "explosive_condensed_side");
var textureExplosiveTop = new nova.render.texture.BlockTexture("icbm", "explosive_condensed_top");
var textureGrenadeCondensed = new nova.render.texture.ItemTexture("icbm", "grenade_condensed");
events.on(RenderManager.Init["class"]).bind(function (evt) {
renderManager.registerTexture(textureExplosiveBottom);
renderManager.registerTexture(textureExplosiveSide);
renderManager.registerTexture(textureExplosiveTop);
renderManager.registerTexture(textureGrenadeCondensed);
});
events.on(BlockManager.Init["class"]).bind(function (evt) {
return blockManager.register("Condensed Explosive", function () {
var block = new nova.block.Block();
block.components.add(new nova.component.Category("ICBM"));
block.components.add(new nova.component.renderer.StaticRenderer()).onRender(new nova.render.pipeline.BlockRenderPipeline(block).withTexture(function (side) {
if (side == nova.util.Direction.UP) return Optional.of(textureExplosiveTop);
if (side == nova.util.Direction.DOWN) return Optional.of(textureExplosiveBottom);
return Optional.of(textureExplosiveSide);
}).build());
block.components.add(new nova.component.renderer.ItemRenderer(block));
block.events.on(nova.block.Block.RightClickEvent["class"]).bind(function (evt) {
if (networkManager.isServer()) {
evt.entity.world().addEntity(entityManager.get("Condensed Explosive").get()).setPosition(block.position().add(new Vector3D(0.5, 0.5, 0.5)));
evt.entity.world().removeBlock(block.position());
}
});
return block;
});
});
events.on(EntityManager.Init["class"]).bind(function (evt) {
return entityManager.register("Condensed Explosive", function () {
var EntityExplosive = Java.extend(nova.entity.Entity, {
time: 0,
update: function update(deltaTime) {
this.time += deltaTime;
if (this.time >= 5) {
if (networkManager.isServer()) {
new Explosion(entity.world(), entity.position(), 3).doExplosion();
}
entity.world().removeEntity(entity);
}
}
});
var entity = new EntityExplosive();
entity.components.add(new nova.component.renderer.DynamicRenderer()).onRender(function (model) {
blockManager.get("Condensed Explosive").get().build().components.get(nova.component.renderer.StaticRenderer["class"]).onRender.accept(model);
});
entity.components.add(new nova.component.misc.Collider(entity)).setBoundingBox(new nova.util.shape.Cuboid(-0.5, -0.5, -0.5, 0.5, 0.5, 0.5));
entity.components.add(nova.entity.component.RigidBody["class"]);
return entity;
});
});
events.on(ItemManager.Init["class"]).bind(function (evt) {
itemManager.register("Condensed Grenade", function () {
var item = new Item();
item.components.add(new nova.component.Category("ICBM"));
item.components.add(new ItemRenderer()).setTexture(textureGrenadeCondensed);
item.events.on(Item.RightClickEvent["class"]).bind(function (evt) {
return new Explosion(evt.entity.world(), evt.entity.position(), 3).doExplosion();
});
return item;
});
});
events.on(RecipeManager.Init["class"]).bind(function (evt) {
var codensedExplosive = itemManager.get("Condensed Explosive").get().build();
recipeManager.addRecipe(new nova.recipes.crafting.ShapelessCraftingRecipe(codensedExplosive, [nova.recipes.crafting.ItemIngredient.forItem("minecraft:redstone"), nova.recipes.crafting.ItemIngredient.forItem("minecraft:tnt")]));
});
}