-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cca6cec
Showing
8 changed files
with
289 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# | ||
# https://help.github.com/articles/dealing-with-line-endings/ | ||
# | ||
# These are explicitly windows files and should use crlf | ||
*.bat text eol=crlf | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Ignore Gradle project-specific cache directory | ||
.gradle | ||
|
||
gradle | ||
gradlew | ||
gradlew.bat | ||
|
||
.classpath | ||
.project | ||
.settings | ||
*.launch | ||
|
||
# Ignore Gradle build output directory | ||
build | ||
bin | ||
run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
plugins { | ||
id 'fabric-loom' version '0.7-SNAPSHOT' | ||
id 'maven-publish' | ||
} | ||
|
||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
|
||
archivesBaseName = project.archives_base_name | ||
version = project.mod_version | ||
group = project.maven_group | ||
|
||
repositories { | ||
// Add repositories to retrieve artifacts from in here. | ||
// You should only use this when depending on other mods because | ||
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically. | ||
// See https://docs.gradle.org/current/userguide/declaring_repositories.html | ||
// for more information about repositories. | ||
} | ||
|
||
dependencies { | ||
// To change the versions see the gradle.properties file | ||
minecraft "com.mojang:minecraft:${project.minecraft_version}" | ||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" | ||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" | ||
|
||
// Fabric API. This is technically optional, but you probably want it anyway. | ||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" | ||
|
||
modImplementation "com.google.zxing:javase:${project.zxing_version}" | ||
include "com.google.zxing:javase:${project.zxing_version}" | ||
include "com.google.zxing:core:${project.zxing_version}" | ||
} | ||
|
||
processResources { | ||
inputs.property "version", project.version | ||
|
||
filesMatching("fabric.mod.json") { | ||
expand "version": project.version | ||
} | ||
} | ||
|
||
tasks.withType(JavaCompile).configureEach { | ||
// ensure that the encoding is set to UTF-8, no matter what the system default is | ||
// this fixes some edge cases with special characters not displaying correctly | ||
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html | ||
// If Javadoc is generated, this must be specified in that task too. | ||
it.options.encoding = "UTF-8" | ||
|
||
// The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too | ||
// JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used. | ||
// We'll use that if it's available, but otherwise we'll use the older option. | ||
def targetVersion = 8 | ||
if (JavaVersion.current().isJava9Compatible()) { | ||
it.options.release = targetVersion | ||
} | ||
} | ||
|
||
java { | ||
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task | ||
// if it is present. | ||
// If you remove this line, sources will not be generated. | ||
withSourcesJar() | ||
} | ||
|
||
jar { | ||
from("LICENSE") { | ||
rename { "${it}_${project.archivesBaseName}"} | ||
} | ||
} | ||
|
||
// configure the maven publication | ||
publishing { | ||
publications { | ||
mavenJava(MavenPublication) { | ||
// add all the jars that should be included when publishing to maven | ||
artifact(remapJar) { | ||
builtBy remapJar | ||
} | ||
artifact(sourcesJar) { | ||
builtBy remapSourcesJar | ||
} | ||
} | ||
} | ||
|
||
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. | ||
repositories { | ||
// Add repositories to publish to here. | ||
// Notice: This block does NOT have the same function as the block in the top level. | ||
// The repositories here will be used for publishing your artifact, not for | ||
// retrieving dependencies. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Done to increase the memory available to gradle. | ||
org.gradle.jvmargs=-Xmx1G | ||
|
||
# Fabric Properties | ||
# check these on https://fabricmc.net/versions.html | ||
minecraft_version=1.16.5 | ||
yarn_mappings=1.16.5+build.9 | ||
loader_version=0.11.3 | ||
|
||
# Mod Properties | ||
mod_version = 0.1 | ||
maven_group = de.rangun | ||
archives_base_name = pandacrossing | ||
|
||
# Dependencies | ||
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api (or https://fabricmc.net/versions.html) | ||
fabric_version=0.34.2+1.16 | ||
zxing_version=3.4.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
pluginManagement { | ||
repositories { | ||
maven { | ||
name = 'Fabric' | ||
url = 'https://maven.fabricmc.net/' | ||
} | ||
gradlePluginPortal() | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
src/main/java/de/rangun/pandacrossing/PandaCrossingMod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright 2021 by Heiko Schäfer <[email protected]> | ||
* | ||
* This file is part of PandaCrossing. | ||
* | ||
* PandaCrossing is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation, either version 3 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* PandaCrossing is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with PandaCrossing. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package de.rangun.pandacrossing; | ||
|
||
import static com.mojang.brigadier.arguments.StringArgumentType.getString; | ||
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString; | ||
import static net.minecraft.server.command.CommandManager.argument; | ||
import static net.minecraft.server.command.CommandManager.literal; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.google.zxing.BarcodeFormat; | ||
import com.google.zxing.EncodeHintType; | ||
import com.google.zxing.WriterException; | ||
import com.google.zxing.common.BitMatrix; | ||
import com.google.zxing.qrcode.QRCodeWriter; | ||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; | ||
|
||
import net.fabricmc.api.ModInitializer; | ||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback; | ||
import net.minecraft.block.Blocks; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import net.minecraft.text.LiteralText; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Vec3d; | ||
import net.minecraft.world.World; | ||
|
||
public class PandaCrossingMod implements ModInitializer { | ||
|
||
private interface IBlockPlacer { | ||
void placeBlock(int x, int y, boolean b); | ||
}; | ||
|
||
private static void createQRCode(IBlockPlacer bp, String qrCodeData, int qrCodeheight, int qrCodewidth) | ||
throws WriterException, UnsupportedEncodingException { | ||
|
||
@SuppressWarnings("rawtypes") | ||
final Map<EncodeHintType, Comparable> hintMap = new HashMap<EncodeHintType, Comparable>(); | ||
|
||
hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.Q); | ||
hintMap.put(EncodeHintType.MARGIN, 1); | ||
|
||
final BitMatrix matrix = new QRCodeWriter().encode( | ||
new String(qrCodeData.getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8), BarcodeFormat.QR_CODE, | ||
qrCodewidth, qrCodeheight, hintMap); | ||
|
||
for (int y = 0; y < matrix.getHeight(); ++y) { | ||
for (int x = 0; x < matrix.getWidth(); ++x) { | ||
bp.placeBlock(x, y, matrix.get(x, y)); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void onInitialize() { | ||
|
||
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> { | ||
dispatcher.register(literal("qr").then(argument("text", greedyString()).executes(ctx -> { | ||
|
||
final String txt = getString(ctx, "text"); | ||
final ServerPlayerEntity player = ctx.getSource().getPlayer(); | ||
final World world = player.getServerWorld(); | ||
final Vec3d playerPos = player.getPos(); | ||
final BlockPos curPos = new BlockPos(playerPos.getX(), playerPos.getY() - 1.0d, playerPos.getZ()); | ||
|
||
try { | ||
|
||
createQRCode(new IBlockPlacer() { | ||
|
||
@Override | ||
public void placeBlock(int x, int y, boolean b) { | ||
|
||
world.setBlockState(curPos.add(x, 0, y), b ? Blocks.BLACK_CONCRETE.getDefaultState() | ||
: Blocks.WHITE_CONCRETE.getDefaultState()); | ||
} | ||
|
||
}, txt, 21, 21); | ||
|
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
return 1; | ||
})).executes(ctx -> { | ||
ctx.getSource().sendFeedback(new LiteralText("Some usage"), false); | ||
|
||
return 1; | ||
})); | ||
}); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"schemaVersion": 1, | ||
"id": "panda_crossing", | ||
"version": "${version}", | ||
|
||
"name": "Panda Crossing QR Generator", | ||
"description": "Creates QR codes", | ||
"authors": [ | ||
"Velnias75" | ||
], | ||
"contact": { | ||
"discord": "https://discord.me/agoramc", | ||
"sources": "https://github.com/FabricMC/fabric-example-mod" | ||
}, | ||
|
||
"license": "GPL-3.0-or-later", | ||
"icon": "assets/panda_crossing/icon.png", | ||
|
||
"environment": "*", | ||
"entrypoints": { | ||
"main": [ | ||
"de.rangun.pandacrossing.PandaCrossingMod" | ||
] | ||
}, | ||
"mixins": [ | ||
], | ||
|
||
"depends": { | ||
"fabricloader": ">=0.7.4", | ||
"fabric": "*", | ||
"minecraft": "1.16.x" | ||
}, | ||
"suggests": { | ||
"another-mod": "*" | ||
} | ||
} |