Skip to content
This repository was archived by the owner on Oct 26, 2024. It is now read-only.

Commit 8c93605

Browse files
committed
1
1 parent e952f2c commit 8c93605

File tree

3 files changed

+63
-58
lines changed

3 files changed

+63
-58
lines changed

.github/workflows/build-template.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ env:
99
BUILD_CONFIGURATION: Release
1010
Platform: X64
1111
SDK_DIR: ./SDK
12-
BDS_VERSION: 1.19.1.02
12+
BDS_VERSION: 1.19.1.01
1313

1414
jobs:
1515
build:

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
- You can get help with `/map help`
1212

13-
13+
<img src=".github/cropharvesting.gif" alt="show" />
1414

1515
### ⚠️ Warning
1616

Template/Plugin.cpp

+61-56
Original file line numberDiff line numberDiff line change
@@ -272,69 +272,74 @@ void RegCommand()
272272
auto action = results["MapsEnum"].get<std::string>();
273273
string str = "";
274274
ServerPlayer* sp = origin.getPlayer();
275-
switch (do_hash(action.c_str()))
276-
{
277-
case do_hash("add"): {
278-
auto picfile = results["MapSoftEnum"].get<std::string>();
279-
if (!picfile.empty()) {
280-
auto [data, w, h] = Helper::Png2Pix(".\\plugins\\CustomMapX\\picture\\" + picfile);
281-
if (data.size() == 0) return;
282-
vector<mce::Color> Colorlist;
283-
for (int y = 0; y < h; y++)
284-
{
285-
for (int x = 0; x < w; x++)
275+
if (sp) {
276+
switch (do_hash(action.c_str()))
277+
{
278+
case do_hash("add"): {
279+
auto picfile = results["MapSoftEnum"].get<std::string>();
280+
if (!picfile.empty()) {
281+
auto [data, w, h] = Helper::Png2Pix(".\\plugins\\CustomMapX\\picture\\" + picfile);
282+
if (data.size() == 0) return;
283+
vector<mce::Color> Colorlist;
284+
for (int y = 0; y < h; y++)
286285
{
287-
mce::Color img((float)data[(y * w + x) * 4 + 0] / 255, (float)data[(y * w + x) * 4 + 1] / 255, (float)data[(y * w + x) * 4 + 2] / 255, (float)data[(y * w + x) * 4 + 3] / 255);
288-
Colorlist.push_back(img);
286+
for (int x = 0; x < w; x++)
287+
{
288+
mce::Color img((float)data[(y * w + x) * 4 + 0] / 255, (float)data[(y * w + x) * 4 + 1] / 255, (float)data[(y * w + x) * 4 + 2] / 255, (float)data[(y * w + x) * 4 + 3] / 255);
289+
Colorlist.push_back(img);
290+
}
289291
}
290-
}
291-
auto datalist = Helper::CuttingImages(Colorlist,w, h);
292-
int xtemp = 0;
293-
int ytemp = 0;
294-
for (auto data : datalist) {
295-
auto mapitem = ItemStack::create("minecraft:filled_map");
296-
auto MapIndex = sp->getMapIndex();
297-
sp->setMapIndex(MapIndex + 1);
298-
MapItem::setMapNameIndex(*mapitem, MapIndex);
299-
auto& mapdate = Global<Level>->_createMapSavedData(MapIndex);
300-
mapdate.setLocked();
301-
for (int x = 0; x < 128; x++)
302-
for (int y= 0; y < 128; y++) {
303-
mapdate.setPixel(data.rawColor[y + x * 128].toABGR(), y, x);
292+
auto datalist = Helper::CuttingImages(Colorlist, w, h);
293+
int xtemp = 0;
294+
int ytemp = 0;
295+
for (auto data : datalist) {
296+
auto mapitem = ItemStack::create("minecraft:filled_map");
297+
auto MapIndex = sp->getMapIndex();
298+
sp->setMapIndex(MapIndex + 1);
299+
MapItem::setMapNameIndex(*mapitem, MapIndex);
300+
auto& mapdate = Global<Level>->_createMapSavedData(MapIndex);
301+
mapdate.setLocked();
302+
for (int x = 0; x < 128; x++)
303+
for (int y = 0; y < 128; y++) {
304+
mapdate.setPixel(data.rawColor[y + x * 128].toABGR(), y, x);
305+
}
306+
mapdate.save(*Global<LevelStorage>);
307+
MapItem::setItemInstanceInfo(*mapitem, mapdate);
308+
auto sizetest = sqrt(datalist.size());
309+
mapitem->setCustomName(picfile + "-" + std::to_string(xtemp) + "_" + std::to_string(ytemp));
310+
Level::spawnItem(sp->getPos(), sp->getDimensionId(), mapitem);
311+
delete mapitem;
312+
ytemp++;
313+
if (ytemp == sizetest) {
314+
xtemp++;
315+
ytemp = 0;
304316
}
305-
mapdate.save(*Global<LevelStorage>);
306-
MapItem::setItemInstanceInfo(*mapitem,mapdate);
307-
auto sizetest = sqrt(datalist.size());
308-
mapitem->setCustomName(picfile +"-"+ std::to_string(xtemp) + "_" + std::to_string(ytemp));
309-
Level::spawnItem(sp->getPos(), sp->getDimensionId(), mapitem);
310-
delete mapitem;
311-
ytemp++;
312-
if (ytemp == sizetest) {
313-
xtemp++;
314-
ytemp = 0;
315317
}
318+
output.success("§l§6[CustomMapX] §aAdd Map Success!(" + std::to_string(datalist.size()) + ")");
316319
}
317-
output.success("§l§6[CustomMapX] §aAdd Map Success!(" + std::to_string(datalist.size()) + ")");
320+
break;
321+
}
322+
case do_hash("reload"): {
323+
vector<string> out;
324+
getAllFiles(".\\plugins\\CustomMapX\\picture", out);
325+
command.getInstance()->setSoftEnum("MapENameList", out);
326+
break;
327+
}
328+
case do_hash("help"): {
329+
output.success(
330+
"§l§e>§6CustomMapX§e<\n"
331+
"§b/map add §l§a<mapfile> §l§gAdd maps\n"
332+
"§b/map reload §l§gRefresh picture path\n"
333+
"§b/map help\n"
334+
"§l§e>§6CustomMapX§e<");
335+
break;
336+
}
337+
default:
338+
break;
318339
}
319-
break;
320-
}
321-
case do_hash("reload"): {
322-
vector<string> out;
323-
getAllFiles(".\\plugins\\CustomMapX\\picture", out);
324-
command.getInstance()->setSoftEnum("MapENameList", out);
325-
break;
326-
}
327-
case do_hash("help"): {
328-
output.success(
329-
"§l§e>§6CustomMapX§e<\n"
330-
"§b/map add §l§a<mapfile> §l§gAdd maps\n"
331-
"§b/map reload §l§gRefresh picture path\n"
332-
"§b/map help\n"
333-
"§l§e>§6CustomMapX§e<");
334-
break;
335340
}
336-
default:
337-
break;
341+
else {
342+
output.error("§l§6[CustomMapX] §cYou are not in the game!");
338343
}
339344
});
340345
DynamicCommand::setup(std::move(command));

0 commit comments

Comments
 (0)