Skip to content

Commit

Permalink
Update to 1.19.4
Browse files Browse the repository at this point in the history
- Reintroduced old shadowSuppression
- Added Custom Recipe to craft shadow stacks
  • Loading branch information
mattymatty97 committed Jun 24, 2023
1 parent d52a2df commit 5a80baf
Show file tree
Hide file tree
Showing 15 changed files with 267 additions and 83 deletions.
74 changes: 53 additions & 21 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
plugins {
id 'fabric-loom' version '0.12-SNAPSHOT'
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'io.github.juuxel.loom-quiltflower' version '1.10.0'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

archivesBaseName = project.archives_base_name
version = project.mod_version + project.mod_suffix
group = project.maven_group
def buildnumber = 1

repositories {
// Add repositories to retrieve artifacts from in here.
Expand All @@ -21,6 +19,12 @@ repositories {
}
}

configurations {
provided
// Make compile extend from our provided configuration so that things added to bundled end up on the compile classpath
implementation.extendsFrom(provided)
}

dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
Expand All @@ -36,30 +40,56 @@ dependencies {
implementation 'de.cronn:reflection-util:2.13.2'
}


def placeholders = [
'version': project.version,
'mc_version': project.minecraft_version,
'build': buildnumber
]

processResources {
inputs.property "version", project.version
inputs.properties placeholders
filteringCharset "UTF-8"

filesMatching("fabric.mod.json") {
expand "version": project.version
expand placeholders
}
filesMatching("placeholders.properties") {
expand placeholders
}
}


def targetJavaVersion = 17
tasks.withType(JavaCompile).configureEach {
// Minecraft 1.18 (1.18-pre2) upwards uses Java 17.
it.options.release = 17
// 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 {
duplicatesStrategy(DuplicatesStrategy.EXCLUDE)
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}"}
rename { "${it}_${project.archivesBaseName}" }
}
from configurations.provided.asFileTree.files.collect { zipTree(it) }
}

// configure the maven publication
Expand All @@ -79,22 +109,24 @@ publishing {
}
}

def buildnumber = 1

tasks.register("updateBuildNumber") {
tasks.register("updateBuildNumber"){
doLast {
Properties props = new Properties()

File propsFile = new File('build.properties')
File propsFile = new File("build-${project.minecraft_version}.properties")

props.load(propsFile.newDataInputStream())
try {
props.load(propsFile.newDataInputStream())

String prevVersion = (props.getProperty('mod_version'))
String prevVersion = (props.getProperty('mod_version'))

if (prevVersion.equals(project.mod_version)) {
if (prevVersion.equals(project.mod_version)) {

buildnumber = (((props.getProperty('mod_buildnumber')) as Integer) + 1)
buildnumber = (((props.getProperty('mod_buildnumber')) as Integer) + 1)
placeholders.build = buildnumber

}
}catch (IOException ignored){
}

props.setProperty('mod_buildnumber', buildnumber.toString())
Expand Down Expand Up @@ -123,6 +155,6 @@ tasks.register("FinalizeBuild", Copy) {
outputs.upToDateWhen { false }
}

tasks.build.finalizedBy updateBuildNumber
tasks.updateBuildNumber.shouldRunAfter build
tasks.updateBuildNumber.finalizedBy FinalizeBuild
tasks.compileJava.finalizedBy updateBuildNumber
tasks.updateBuildNumber.shouldRunAfter compileJava
tasks.build.finalizedBy FinalizeBuild
3 changes: 0 additions & 3 deletions build.properties

This file was deleted.

14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
org.gradle.jvmargs=-Xmx4G
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.19.3
yarn_mappings=1.19.3+build.5
loader_version=0.14.14
carpet_core_version=1.4.96+v230201
minecraft_version=1.19.4
yarn_mappings=1.19.4+build.2
loader_version=0.14.21
carpet_core_version=1.4.101+v230319
# Mod Properties
mod_version=1.9.7
mod_suffix=-MC1.19.3+
mod_version=1.10.0
mod_suffix=-MC1.19.4
maven_group=carpet-shadow-item
archives_base_name=carpet-shadow
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.75.1+1.19.3
fabric_version=0.84.0+1.19.4
30 changes: 25 additions & 5 deletions src/main/java/com/carpet_shadow/CarpetShadow.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@
import carpet.CarpetExtension;
import carpet.CarpetServer;
import com.carpet_shadow.utility.RandomString;
import net.fabricmc.api.EnvType;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.item.ItemStack;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class CarpetShadow implements CarpetExtension, ModInitializer {
public static final HashMap<String, WeakReference<ItemStack>> shadowMap = new HashMap<>();
Expand All @@ -22,9 +29,6 @@ public class CarpetShadow implements CarpetExtension, ModInitializer {
@Override
public void onGameStarted() {
CarpetShadow.LOGGER.info("Carpet Shadow Loaded!");
if(FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER){
CarpetServer.settingsManager.parseSettingsClass(CarpetShadowServerSettings.class);
}
CarpetServer.settingsManager.parseSettingsClass(CarpetShadowSettings.class);
shadow_id_generator = new RandomString(CarpetShadowSettings.shadowItemIdSize);
}
Expand All @@ -37,4 +41,20 @@ public void onInitialize() {
shadowMap.clear();
}));
}

@Override
public Map<String, String> canHasTranslations(String lang) {
InputStream langFile = getClass().getClassLoader().getResourceAsStream("assets/carpet-shadow/lang/%s.json".formatted(lang));
if (langFile == null) {
return Collections.emptyMap();
}
String jsonData;
try {
jsonData = IOUtils.toString(langFile, StandardCharsets.UTF_8);
} catch (IOException e) {
return Collections.emptyMap();
}
Gson gson = new GsonBuilder().setLenient().create();
return gson.fromJson(jsonData, new TypeToken<Map<String, String>>() {}.getType());
}
}
13 changes: 0 additions & 13 deletions src/main/java/com/carpet_shadow/CarpetShadowServerSettings.java

This file was deleted.

34 changes: 20 additions & 14 deletions src/main/java/com/carpet_shadow/CarpetShadowSettings.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,45 @@
package com.carpet_shadow;

import carpet.settings.ParsedRule;
import carpet.settings.Rule;
import carpet.settings.Validator;
import carpet.api.settings.CarpetRule;
import carpet.api.settings.Rule;
import carpet.api.settings.Validator;
import com.carpet_shadow.utility.RandomString;
import net.minecraft.server.command.ServerCommandSource;
import org.jetbrains.annotations.Nullable;

import static carpet.settings.RuleCategory.*;
import static carpet.api.settings.RuleCategory.*;

@SuppressWarnings({"removal"})
public class CarpetShadowSettings {
public static final String SHADOW = "shadow_items";
@Rule(desc = "Shadow Items Action over Unloading ( Unlink is default vanilla )", category = {SHADOW, BUGFIX})
@Rule( categories = {SHADOW, BUGFIX})
public static Mode shadowItemMode = Mode.UNLINK;
@Rule(desc = "Shadow Items Id Length", category = {SHADOW}, validate = {IdSizeValidator.class})
@Rule( categories = {SHADOW}, validators = {IdSizeValidator.class})
public static int shadowItemIdSize = 5;
@Rule(desc = "Show Shadow Items Id in Item Names", category = {SHADOW, FEATURE})
@Rule( categories = {SHADOW, FEATURE})
public static boolean shadowSuppressionGeneration = false;
@Rule( categories = {SHADOW, FEATURE})
public static boolean shadowCraftingGeneration = false;
@Rule( categories = {SHADOW, FEATURE})
public static boolean shadowItemTooltip = false;
@Rule(desc = "Prevent Unlinking Shadow Items on base inventory movements", category = {SHADOW, BUGFIX})
@Rule( categories = {SHADOW, BUGFIX})
public static boolean shadowItemInventoryFragilityFix = false;
@Rule(desc = "Prevent Unlinking Shadow Items on hopper-dropper item transfers", category = {SHADOW, BUGFIX})
@Rule( categories = {SHADOW, BUGFIX})
public static boolean shadowItemTransferFragilityFix = false;
@Rule(desc = "Shadow Items will produce inventory updates", category = {SHADOW, BUGFIX, EXPERIMENTAL})
@Rule( categories = {SHADOW, BUGFIX, EXPERIMENTAL})
public static boolean shadowItemUpdateFix = false;
@Rule(desc = "Prevent Merging any Shadow Item on base inventory movements", category = {SHADOW, OPTIMIZATION, FEATURE})
@Rule( categories = {SHADOW, OPTIMIZATION, FEATURE})
public static boolean shadowItemPreventCombine = false;
@Rule( categories = {SHADOW, OPTIMIZATION, FEATURE})
public static boolean shadowItemUseFix = false;

private static class IdSizeValidator extends Validator<Integer> {
@Override
public Integer validate(ServerCommandSource source, ParsedRule<Integer> currentRule, Integer newValue, String string) {
public Integer validate(@Nullable ServerCommandSource source, CarpetRule<Integer> changingRule, Integer newValue, String userInput) {
try {
CarpetShadow.shadow_id_generator = new RandomString(newValue);
return newValue;
} catch (IllegalArgumentException ex) {
return currentRule.get();
return changingRule.value();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.carpet_shadow.mixins.crafting;

import com.carpet_shadow.CarpetShadow;
import com.carpet_shadow.CarpetShadowSettings;
import com.carpet_shadow.Globals;
import com.carpet_shadow.interfaces.ShadowItem;
import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonElement;
import net.minecraft.inventory.CraftingInventory;
import net.minecraft.item.*;
import net.minecraft.recipe.*;
import net.minecraft.recipe.book.CraftingRecipeCategory;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.profiler.Profiler;
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;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import java.util.Map;

@SuppressWarnings({"unchecked","rawtypes"})
@Mixin(RecipeManager.class)
public class RecipeManagerMixin {
@Inject(method = "apply(Ljava/util/Map;Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/util/profiler/Profiler;)V", at = @At(value = "INVOKE", target = "Ljava/util/Map;entrySet()Ljava/util/Set;", ordinal = 0, shift = At.Shift.BEFORE), locals = LocalCapture.CAPTURE_FAILHARD)
private void addShadowRecipe(Map<Identifier, JsonElement> map, ResourceManager resourceManager, Profiler profiler, CallbackInfo ci, Map map2, ImmutableMap.Builder<Identifier, Recipe<?>> builder){
Identifier identifier = new Identifier("carpet_shadow","shadow_recipe");
Recipe<?> recipe = new ShapelessRecipe(identifier, "shadow", CraftingRecipeCategory.MISC, ItemStack.EMPTY, DefaultedList.of()) {
@Override
public boolean matches(CraftingInventory inventory, World world) {
if (CarpetShadowSettings.shadowItemMode== CarpetShadowSettings.Mode.UNLINK || !CarpetShadowSettings.shadowCraftingGeneration)
return false;

boolean enderchest = false;
int count = 0;
for(int i = 0; i < inventory.size(); ++i) {
ItemStack itemStack2 = inventory.getStack(i);
if (!itemStack2.isEmpty()) {
if (itemStack2.getItem().equals(Items.ENDER_CHEST) && itemStack2.getCount() == 1)
enderchest = true;
count++;
}
}
return enderchest && count == 2;
}

@Override
public ItemStack craft(CraftingInventory inventory, DynamicRegistryManager registryManager) {
if (CarpetShadowSettings.shadowItemMode== CarpetShadowSettings.Mode.UNLINK || !CarpetShadowSettings.shadowCraftingGeneration)
return ItemStack.EMPTY;

ItemStack item = null;
ItemStack enderchest = null;
for(int i = 0; i < inventory.size(); ++i) {
ItemStack itemStack2 = inventory.getStack(i);
if (!itemStack2.isEmpty()) {
if (itemStack2.getItem().equals(Items.ENDER_CHEST) && itemStack2.getCount() == 1 && enderchest == null)
enderchest = itemStack2;
else
item = itemStack2;
}
}
if (item==null || enderchest==null)
return ItemStack.EMPTY;

if (item.getItem().equals(Items.ENDER_CHEST) && item.getCount()==1){
item = enderchest;
}
String id = ((ShadowItem)(Object)item).getShadowId();
if (id == null){
id = CarpetShadow.shadow_id_generator.nextString();
}
return Globals.getByIdOrAdd(id, item);
}

@Override
public boolean fits(int width, int height) {
if (CarpetShadowSettings.shadowItemMode== CarpetShadowSettings.Mode.UNLINK || !CarpetShadowSettings.shadowCraftingGeneration)
return false;
return width * height >= 2;
}

};
((ImmutableMap.Builder)map2.computeIfAbsent(recipe.getType(), recipeType -> ImmutableMap.builder())).put(identifier, recipe);
builder.put(identifier, recipe);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.carpet_shadow.mixins.fragility;

import com.carpet_shadow.CarpetShadowSettings;
import com.carpet_shadow.Globals;
import com.carpet_shadow.interfaces.ItemEntitySlot;
import com.carpet_shadow.interfaces.ShadowItem;
import net.minecraft.entity.ItemEntity;
Expand Down
Loading

0 comments on commit 5a80baf

Please sign in to comment.