Skip to content

Commit 44b4734

Browse files
committed
scripts
1 parent ec2ab54 commit 44b4734

23 files changed

+936
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.idea/

Carpet Commands/draw_command.sc

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
//Draw command in scarpet
2+
//By: Ghoulboy & gnembon
3+
//The reason I used c_for loops is cos I copied directly from java and am too lazy to replace it all myself.
4+
//Also may serve as an example to newcomers to how c_for loops work
5+
6+
__command()->print('Draw command.');
7+
8+
//Command functions
9+
10+
ball(radius, block)-> __drawSphere(radius,block,true);
11+
12+
sphere(radius, block)-> __drawSphere(radius, block,false);
13+
14+
cone(x, y, z, radius, height, pointup, orientation, block)->__drawPyramid(x, y, z, radius, height, pointup, orientation, block, false);
15+
16+
pyramid(x, y, z, radius, height, pointup, orientation, block)->__drawPyramid(x, y, z, radius, height, pointup, orientation, block, true);
17+
18+
diamond_shape(cx,cy,cz,radius,block)->(//If I do diamond, it conflicts with diamond iterator
19+
affected=0;
20+
for(range(radius),
21+
y=_-radius+1;
22+
r=_;
23+
for(range(-r,r+1),
24+
x=_;
25+
z=r-abs(x);
26+
affected+=__set_block(x+cx,cy+y,cz-z,block);
27+
affected+=__set_block(x+cx,y+cy,z+cz,block);
28+
affected+=__set_block(x+cx,cy-y,cz-z,block);
29+
affected+=__set_block(x+cx,cy-y,cz+z,block)
30+
);
31+
);
32+
print('Successfully filled '+affected+' blocks')
33+
);
34+
35+
//Other functions
36+
37+
__set_block(pos,block)->(
38+
if(block(pos)!=block,
39+
set(pos,block);
40+
return(1)
41+
);
42+
return(0)
43+
);
44+
45+
__lengthSq(x,y,z)->return((x * x) + (y * y) + (z * z));
46+
47+
__fillFlat(x,y,z, offset,radius,orientation,block,square)->(
48+
success=0;
49+
if(orientation=='x',
50+
scan(x + offset,y,z, 0, radius, radius,
51+
if((square||sqrt(__lengthSq(x + offset -_x,y -_y,z -_z))<1),
52+
success+=__set_block(pos(_),block)
53+
)
54+
)
55+
);
56+
if(orientation=='y',
57+
scan(x,y+ offset,z, radius, 0, radius,
58+
if((square||sqrt(__lengthSq(x -_x,y + offset -_y,z -_z))<1),
59+
success+=__set_block(pos(_),block)
60+
)
61+
)
62+
);
63+
if(orientation=='z',
64+
scan(x,y,z+ offset, radius, radius, 0,
65+
if((square||sqrt(__lengthSq(x -_x,y -_y,z + offset -_z))<1),
66+
success+=__set_block(pos(_),block)
67+
)
68+
)
69+
);
70+
return(success)
71+
);
72+
73+
__drawPyramid(x, y, z, radius, height, pointup, orientation, block, isSquare)->(
74+
affected=0;
75+
c_for(i =0, i<height, i+=1,
76+
r = if(pointup, radius - radius * i / height - 1 , radius * i / height);
77+
affected+=__fillFlat(x,y,z,i,r,orientation,block,isSquare);
78+
);
79+
80+
print('Successfully filled '+affected+' blocks');
81+
);
82+
83+
__drawSphere(radius,block,solid)->(
84+
85+
pos=pos(player());
86+
affected = 0;
87+
88+
radiusX = radius+0.5;
89+
radiusY = radius+0.5;
90+
radiusZ = radius+0.5;
91+
92+
invRadiusX = 1 / radiusX;
93+
invRadiusY = 1 / radiusY;
94+
invRadiusZ = 1 / radiusZ;
95+
96+
ceilRadiusX = ceil(radiusX);
97+
ceilRadiusY = ceil(radiusY);
98+
ceilRadiusZ = ceil(radiusZ);
99+
100+
101+
nextXn = 0;
102+
103+
c_for (x = 0, x <= ceilRadiusX, x+=1,
104+
xn = nextXn;
105+
nextXn = (x + 1) * invRadiusX;
106+
nextYn = 0;
107+
c_for (y = 0, y <= ceilRadiusY, y+=1,
108+
109+
yn = nextYn;
110+
nextYn = (y + 1) * invRadiusY;
111+
nextZn = 0;
112+
c_for (z = 0, z <= ceilRadiusZ, z+=1,
113+
114+
zn = nextZn;
115+
nextZn = (z + 1) * invRadiusZ;
116+
117+
distanceSq = __lengthSq(xn, yn, zn);
118+
if (distanceSq > 1,break());
119+
120+
if (!solid && __lengthSq(nextXn, yn, zn) <= 1 && __lengthSq(xn, nextYn, zn) <= 1 && __lengthSq(xn, yn, nextZn) <= 1,
121+
continue();
122+
);
123+
124+
c_for (xmod = -1, xmod < 2, xmod += 2,
125+
126+
c_for (ymod = -1, ymod < 2, ymod += 2,
127+
128+
c_for (zmod = -1, zmod < 2, zmod += 2,
129+
130+
affected+=__set_block(pos+l(xmod * x,ymod * y,zmod * z),block);
131+
)
132+
)
133+
)
134+
)
135+
)
136+
);
137+
return('Successfully sent '+affected+' blocks')
138+
);
139+

Carpet Commands/tick_command.sc

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//Tick command in scarpet
2+
//By: Ghoulboy & gnembon
3+
//I could only implement so many functions in scarpet. Soz.
4+
5+
__command()->print('Tick command.');
6+
7+
//Global Variables
8+
9+
global_tick_rate=20;
10+
11+
global_tick_warping_player=null;
12+
13+
//Command functions
14+
15+
rate(tick_rate)->(//Set to 0 to stop this working. Setting to low tps screws stuff up. DON'T USE
16+
if(!__check_type(tick_rate,'number'),return('Invalid argument type'));
17+
print('Current tps is: '+tick_rate);
18+
global_tick_rate=tick_rate;
19+
while(global_tick_rate==tick_rate,10e10,//159 irl years at 20 tps
20+
game_tick(1000/tick_rate)
21+
)
22+
);
23+
24+
warp(ticks)->(//Seems complex at first, then seems easy, but is really hard if you wanna do it quick
25+
if(!__check_type(ticks,'number'),return('Invalid argument type'));//Little extra something
26+
if(global_tick_warping_player,
27+
if(ticks,
28+
print('Player '+global_tick_warping_player+' is already advancing time at the moment. Try later or ask them.')
29+
),
30+
print('Warp speed...');
31+
global_tick_warping_player=player();
32+
global_tick_rate=0//Stops the previous rate command from interfering and messing this up
33+
);
34+
total_ms=0;
35+
loop(ticks,
36+
if(global_tick_warping_player,total_ms+=profile_expr(game_tick()),break())
37+
);
38+
avg_ms=total_ms/ticks;
39+
global_tick_warping_player=null;
40+
print('Time warp successfully completed with '+(if(1000/avg_ms==NaN,0,1000/avg_ms))+' tps, or '+avg_ms+' mspt')
41+
);
42+
43+
//Other functions
44+
45+
__check_type(arg,type)->return(type(arg)==type);

Carpet features/chickenshearing.sc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//Inspired by /carpet chickenShearing from carpet-extra
2+
//By: Ghoulboy
3+
4+
__on_player_interacts_with_entity(player, entity, hand)->(
5+
if(entity!='Chicken'||entity~'health'<=0||player~'holds':0!='shears'||hand!='mainhand',return());
6+
if(player~'gamemode'=='survival',inventory_set(player,player~'selected_slot',1,'shears','{Damage:'+(get(player~'holds':2,'Damage')+1)+'}'));
7+
spawn('item',pos(entity),'{Motion:[0.0,0.5,0.0],Item:{id:"minecraft:feather",Count:1b}}');
8+
modify(entity,'health',entity~'health'-(rand(4)/2+0.5))//can remove between 0.5 and 2 health
9+
)

Carpet features/combineXPOrbs.sc

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//Inspired by carpet rule
2+
//By: Ghoulboy
3+
4+
__on_tick()->(
5+
for(entity_selector('@e[type=experience_orb]'),
6+
if(_~'age'<50,continue(),orb1=_);
7+
l(x1,y1,z1)=pos(orb1);
8+
orb2=first(filter(entity_area('*',x1,y1,z1,0.5,0.5,0.5),_~'type'=='experience_orb'&&_!=orb1),_~'age'>=50);
9+
if(!orb2,continue());
10+
l(x2,y2,z2)=pos(orb2);
11+
s=spawn('experience_orb',(x1+x2)/2,(y1+y2)/2,(z1+z2)/2,str('{Age:0,Value:%s}',orb1~'nbt':'Value'+orb2~'nbt':'Value'));
12+
modify(orb1,'remove');
13+
modify(orb2,'remove');
14+
)
15+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//Carpet rule
2+
//By: Ghoulboy
3+
4+
__on_tick()->(
5+
for(filter(entity_selector('@e'),_~'category'=='monster'),
6+
print('1');
7+
if(_~'age'==0,continue());//Age dont work, use tags
8+
print('2');
9+
l(x,y,z)=pos(_);
10+
if(structure_references(x,y,z,'jungle_temple'),continue());//For players with spawn eggs:||entity_area('players',x,y,z,24,24,24)
11+
spawn('creeper',pos(_));
12+
modify(_,'remove')
13+
)
14+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//carpet-extra rule
2+
//By: Ghoulboy
3+
__on_tick()->(
4+
for(entity_selector('@e[type=item,nbt={Item:{id:"minecraft:dragon_breath",Count:1b}}]'),
5+
if(block(pos(_))=='cobblestone'&&for(neighbours(pos(_)),block(pos(_))=='dispenser'),
6+
set(pos(_),'end_stone');
7+
modify(_,'remove')
8+
)
9+
)
10+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//Inspired by carpet-extra rule of the same name
2+
//By: Ghoulboy
3+
4+
//Events
5+
6+
__on_tick()->(
7+
for(entity_selector('@e'),
8+
if(!query(_,'has_tag','SandtoSoulsand'),
9+
modify(_,'tag','SandtoSoulsand');
10+
entity_event(_,'on_death','__sand_to_soul_sand')
11+
)
12+
)
13+
);
14+
15+
//Other functions
16+
17+
__sand_to_soul_sand(entity,cause)->if(entity~'category'!='misc'&&(cause=='inFire'||'onFire')&&block(pos(entity)-l(0,1,0))=='sand',set(pos(entity)-l(0,1,0),'soul_sand'));//All the checks in one

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# Scarpet-apps
1+
# Scarpet apps
22
A collection of my crazy and wacky apps, replicating some modded features, and other stuff like that.

branchminer.sc

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//See https://www.youtube.com/watch?v=mXLvl4dWLyg a branch mining bot by Earthcomputer
2+
//By: Ghoulboy
3+
4+
5+
//Breaks a stright line of blocks
6+
//Max length of tunnel is : (number of torches prestacked in offhand) * 6 + (initial light level at the opening of the tunnel-7)
7+
//cos calculations are easier that way, and torhces are placed in such a way that lightlevel only ever goes down to 8
8+
__command()->(print('Welcome to the BranchMiner program inspired by Earthcomputer\'s branchminer!'));
9+
10+
global_niceblocks=l('coal_ore','iron_ore','emerald_ore','gold_ore','redstone_ore','diamond_ore','diorite');//I'll ignore all the rest, and throw out of inventory
11+
12+
branch_mine()->(
13+
player=player();
14+
print(pos(block(pos(player))));//Remind me to remove this line and the one below
15+
print(query(player,'facing',0));
16+
if(!player~'holds':0~'diamond_pickaxe',return());//If you want you can make it for any pick, by removing the 'diamond_' in front of 'pickaxe'
17+
18+
if(inventory_get(player,40):0!='torch'&&inventory_get(player,40):0!='soul_torch',
19+
print(inventory_get(player,40):0+' is an invalid offhand item; it must be a torch or (in 1.16+) a soul torch');
20+
return()
21+
);//soul torch for 1.16 and above
22+
23+
torchtype=if(inventory_get(player,40):0=='torch','torch','soul_torch')
24+
25+
if(block(pos_offset(pos(block(pos(player))),query(player,'facing',0))+l(0,1,0))=='air'||block(pos_offset(pos(block(pos(player))),query(player,'facing',0)))=='air',return());//checks that youre looking at non-air blocks to start mining
26+
while(true,inventory_get(player,40):1*6+light(pos(player))-7,
27+
if(inventory_get(player,40):0!='torch'&&inventory_get(player,40):0!='soul_torch'&&light(pos(player))==8,return());
28+
if(light(pos(player)==2,
29+
inventory_remove(player,torchtype,1,40));
30+
31+
);
32+
);
33+
);

easier_renewable_sponge.sc

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//killing one of each type of fish gives a random chance to get sponge
2+
//By: Ghoulboy
3+
4+
global_debug=false;//for debugging purposes only
5+
6+
__on_player_attacks_entity(player,entity)->(
7+
if(global_fishez ~ entity,
8+
schedule(0,'__add_dead_fish',entity);//if not the fish's health may not yet be calculated, and I cant check if its dead or not
9+
);
10+
);
11+
12+
global_fishez = l('','Pufferfish', 'Tropical Fish', 'Salmon','Cod');
13+
global_vars=l('',global_puff,global_trop,global_salmon,global_cod);
14+
15+
16+
__add_dead_fish(entity)->(
17+
if(entity ~ 'health'!=0,return());
18+
poslist=global_fishez ~ entity;
19+
global_vars:poslist+=1;
20+
if(global_vars:1>=1 && global_vars:2>=1 && global_vars:3>=1 && global_vars:4>=1,
21+
if(!rand(50)||global_debug==true,
22+
run('summon minecraft:item '+(str(map(pos(entity), str('%.2f',_)))-'['-']'-','-',')+' {Item:{id:"minecraft:wet_sponge",Count:1b}}');//Why isn't there an easier way to do this?
23+
);
24+
global_vars:1 +=-1;
25+
global_vars:2 +=-1;
26+
global_vars:3 +=-1;
27+
global_vars:4 +=-1;
28+
);
29+
);

0 commit comments

Comments
 (0)