initial commit

main
maia arson crimew 2021-12-09 00:51:46 +01:00
commit 4cabb69d3a
15 changed files with 463 additions and 0 deletions

118
.gitignore vendored Normal file
View File

@ -0,0 +1,118 @@
# User-specific stuff
.idea/
*.iml
*.ipr
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
*~
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
.gradle
build/
# Ignore Gradle GUI config
gradle-app.setting
# Cache of project
.gradletasknamecache
**/build/
# Common working directory
run/
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2021 nyancrimew
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

16
README.md Normal file
View File

@ -0,0 +1,16 @@
# pathetic - a shitty path block enhancement mod
does fun things with path blocks!! most likely not the first person to do these things, but it seems like a fun way to
get into modding.
## current goals
* automatically convert often walked over grass/dirt blocks into path blocks
* current plan is at least 5 times walked across in recent x amount of ticks, debounced by x ticks
* automatically converted paths fade back out over time as they become "overgrown"
## current status
* very basic MVP implementation as a mixin, with cursed in memory state handling
* blocks that have been walked over 5 times, within any overall timeframe are converted, and tagged as created by
the mod

90
build.gradle Normal file
View File

@ -0,0 +1,90 @@
plugins {
id 'fabric-loom' version '0.10-SNAPSHOT'
id 'maven-publish'
}
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}"
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them.
}
processResources {
inputs.property "version", project.version
filteringCharset "UTF-8"
filesMatching("fabric.mod.json") {
expand "version": project.version
}
}
def targetJavaVersion = 16
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"
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
it.options.release = targetJavaVersion
}
}
java {
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
if (JavaVersion.current() < javaVersion) {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
archivesBaseName = project.archives_base_name
// 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.
}
}

14
gradle.properties Normal file
View File

@ -0,0 +1,14 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.18
yarn_mappings=1.18+build.1
loader_version=0.12.8
# Mod Properties
mod_version=0.1
maven_group=ch.deletescape
archives_base_name=pathetic
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.44.0+1.18

View File

@ -0,0 +1 @@
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip

9
settings.gradle Normal file
View File

@ -0,0 +1,9 @@
pluginManagement {
repositories {
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
gradlePluginPortal()
}
}

View File

@ -0,0 +1,40 @@
package ch.deletescape.pathetic;
import net.minecraft.util.math.BlockPos;
import java.util.HashMap;
import java.util.Map;
public class LastSteppedOnStore {
private static final Map<BlockPos, Long> LAST_STEPPED_ON = new HashMap<>();
// TODO: adjust depending on our needs
private static final long GC_TIME = 100;
public static long get(BlockPos pos) {
Long val = LAST_STEPPED_ON.get(pos);
if (val == null) {
return 0;
}
return val;
}
public static long putIfAbsent(BlockPos pos, long currentTime) {
Long val = LAST_STEPPED_ON.putIfAbsent(pos, currentTime);
if (val == null) {
gc(currentTime);
return 0;
}
return val;
}
// TODO: this is honestly an incredibly horrible idea lmao
private static void gc(long currentTime) {
if (LAST_STEPPED_ON.size() > 100) {
for (BlockPos key : LAST_STEPPED_ON.keySet()) {
if (currentTime - LAST_STEPPED_ON.get(key) >= GC_TIME) {
LAST_STEPPED_ON.remove(key);
}
}
}
}
}

View File

@ -0,0 +1,9 @@
package ch.deletescape.pathetic;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.IntProperty;
public class PatheticProperties {
public static final IntProperty STEP_COUNT = IntProperty.of("step_count", 0, 10);
public static final BooleanProperty IS_AUTOPATH = BooleanProperty.of("is_autopath");
}

View File

@ -0,0 +1,49 @@
package ch.deletescape.pathetic.mixin;
import ch.deletescape.pathetic.LastSteppedOnStore;
import ch.deletescape.pathetic.PatheticProperties;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.Entity;
import net.minecraft.state.StateManager;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
// TODO: set default step count value to 0 in constructor
@Mixin(Block.class)
public abstract class BlockMixin {
@Inject(at = @At("RETURN"), method = "appendProperties")
private void pathetic_appendProperties(StateManager.Builder<Block, BlockState> builder, CallbackInfo ci) {
builder.add(PatheticProperties.STEP_COUNT);
}
// TODO: half of this should probably be done with block entity tick shit
@Inject(at = @At("RETURN"), method = "onSteppedOn")
private void pathetic_onSteppedOn(World world, BlockPos pos, BlockState state, Entity entity, CallbackInfo ci) {
if (entity.isPlayer()) {
Block block = state.getBlock();
long currentTime = world.getTime();
if (block == Blocks.DIRT || block == Blocks.GRASS_BLOCK) {
if (currentTime - LastSteppedOnStore.putIfAbsent(pos, currentTime) >= 50) {
int currentStepCount = state.get(PatheticProperties.STEP_COUNT);
if (currentStepCount < 5) {
world.setBlockState(pos, state.with(PatheticProperties.STEP_COUNT, currentStepCount + 1));
}
if (currentStepCount >= 5) {
Block.replace(state, Blocks.DIRT_PATH.getDefaultState().with(PatheticProperties.IS_AUTOPATH, true), world, pos, Block.NOTIFY_ALL);
}
}
} else if (block == Blocks.DIRT_PATH && state.get(PatheticProperties.IS_AUTOPATH)) {
// TODO: turn blocks back into grass blocks if no one steps on them for a specified amount of time, we mostly need to do
// block entity hackery for that, and idk if we can do that with mixins tbh
}
}
}
}

View File

@ -0,0 +1,30 @@
package ch.deletescape.pathetic.mixin;
import ch.deletescape.pathetic.PatheticProperties;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.DirtPathBlock;
import net.minecraft.state.StateManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(DirtPathBlock.class)
public abstract class DirtPathBlockMixin extends Block {
DirtPathBlockMixin(Settings settings) {
super(settings);
}
@Inject(at = @At("RETURN"), method = "<init>")
private void onConstruct(AbstractBlock.Settings settings, CallbackInfo ci) {
setDefaultState(getDefaultState().with(PatheticProperties.IS_AUTOPATH, false).with(PatheticProperties.STEP_COUNT, 0));
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(PatheticProperties.IS_AUTOPATH);
super.appendProperties(builder);
}
}

View File

@ -0,0 +1,22 @@
package ch.deletescape.pathetic.mixin;
import ch.deletescape.pathetic.PatheticProperties;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.GrassBlock;
import net.minecraft.state.StateManager;
import org.spongepowered.asm.mixin.Mixin;
// SnowyBlock is in the class hierarchy of GrassBlock and overrides appendProperties without calling super()
@Mixin(GrassBlock.class)
public abstract class GrassBlockMixin extends Block {
GrassBlockMixin(Settings settings) {
super(settings);
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(PatheticProperties.STEP_COUNT);
super.appendProperties(builder);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@ -0,0 +1,28 @@
{
"schemaVersion": 1,
"id": "pathetic",
"version": "${version}",
"name": "pathetic",
"description": "does fun things with path blocks!!",
"authors": [
"nyancrimew"
],
"contact": {},
"license": "MIT",
"icon": "assets/pathetic/icon.png",
"environment": "*",
"entrypoints": {
"client": [
],
"main": [
]
},
"mixins": [
"pathetic.mixins.json"
],
"depends": {
"fabricloader": ">=0.12.8",
"fabric": "*",
"minecraft": "1.18"
}
}

View File

@ -0,0 +1,16 @@
{
"required": true,
"minVersion": "0.8",
"package": "ch.deletescape.pathetic.mixin",
"compatibilityLevel": "JAVA_16",
"mixins": [
"BlockMixin",
"GrassBlockMixin",
"DirtPathBlockMixin"
],
"client": [
],
"injectors": {
"defaultRequire": 1
}
}