Skip to content

Commit

Permalink
1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Insane96 committed Jun 15, 2022
1 parent 6c60900 commit bb58da6
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 86 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 1.2.1
* Now requires InsaneLib 1.5.1

## 1.2.0
* Added Block Transformation. Liquids flowing near blocks can now be changed. The example data pack contains lava flowing near/onto Sand that's near Magma Blocks to transform into Glass.

Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# This is required to provide enough memory for the Minecraft decompilation process.
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
mod_version=1.2.0
mod_version=1.2.1
mc_version=1.18.2
mixin_version=0.8.4
lib_version=1.4.6
forge_version=40.1.19
mixin_version=0.8.5
lib_version=1.5.1
forge_version=40.1.51
jei_version=9.7.0.195
Binary file removed libs/InsaneLib-1.4.6-mc1.18.2.jar
Binary file not shown.
Binary file added libs/InsaneLib-1.5.1-mc1.18.2.jar
Binary file not shown.
80 changes: 22 additions & 58 deletions src/main/java/insane96mcp/customfluidmixin/data/CFM.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
package insane96mcp.customfluidmixin.data;

import com.google.gson.JsonParseException;
import com.google.gson.annotations.SerializedName;
import insane96mcp.customfluidmixin.exception.JsonValidationException;
import insane96mcp.insanelib.util.IdTagMatcher;
import net.minecraft.commands.CommandFunction;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.EmptyFluid;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.tags.ITag;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -47,40 +41,40 @@ public class CFM {
public transient IdTagMatcher blockToTransform;
public transient List<IdTagMatcher> blocksNearby;

public void validate() throws JsonValidationException {
public void validate() throws JsonParseException {
if (type == null)
throw new JsonValidationException("Missing type");
throw new JsonParseException("Missing type");

if (_flowing == null)
throw new JsonValidationException("Missing flowing block");
throw new JsonParseException("Missing flowing block");
flowing = IdTagMatcher.parseLine(_flowing);
if (flowing == null)
throw new JsonValidationException("Failed to parse flowing");
throw new JsonParseException("Failed to parse flowing");

if (type == Type.BLOCK_TRANSFORM) {
if (_blockToTransform == null)
throw new JsonValidationException("Missing block_to_transform block");
throw new JsonParseException("Missing block_to_transform block");
blockToTransform = IdTagMatcher.parseLine(_blockToTransform);
if (blockToTransform == null)
throw new JsonValidationException("Failed to parse block_to_transform");
throw new JsonParseException("Failed to parse block_to_transform");
}

if (_blocksNearby == null)
throw new JsonValidationException("Missing blocks_nearby");
throw new JsonParseException("Missing blocks_nearby");
int minBlocksNearby = this.type == Type.FLOWING_MIXIN ? 1 : 0;
if (_blocksNearby.size() < minBlocksNearby || _blocksNearby.size() > 5)
throw new JsonValidationException("Invalid blocks_nearby. There must be at least one block nearby (0 works too if type = 'block_transform') and less than 5 blocks");
throw new JsonParseException("Invalid blocks_nearby. There must be at least one block nearby (0 works too if type = 'block_transform') and less than 5 blocks");

blocksNearby = new ArrayList<>();
for (String s : _blocksNearby) {
IdTagMatcher idTagMatcher = IdTagMatcher.parseLine(s);
if (idTagMatcher == null)
throw new JsonValidationException("Failed to parse a block nearby " + s);
throw new JsonParseException("Failed to parse a block nearby " + s);
blocksNearby.add(idTagMatcher);
}

if (result == null)
throw new JsonValidationException("Missing result");
throw new JsonParseException("Missing result");
result.validate();

if (this.fizz == null)
Expand All @@ -90,7 +84,7 @@ public void validate() throws JsonValidationException {
public static CFM createFlowingMixin(String flowing, List<IdTagMatcher> blocksNearby, String blockResult) {
CFM cfm = new CFM();
cfm.type = Type.FLOWING_MIXIN;
cfm.flowing = new IdTagMatcher(null, new ResourceLocation(flowing));
cfm.flowing = new IdTagMatcher(IdTagMatcher.Type.ID, new ResourceLocation(flowing));
cfm.blocksNearby = blocksNearby;
cfm.result = MixinResult.newBlockResult(blockResult);
return cfm;
Expand All @@ -99,7 +93,7 @@ public static CFM createFlowingMixin(String flowing, List<IdTagMatcher> blocksNe
public static CFM createBlockTransformation(String flowing, IdTagMatcher blockToTransform, List<IdTagMatcher> blocksNearby, String blockResult) {
CFM cfm = new CFM();
cfm.type = Type.BLOCK_TRANSFORM;
cfm.flowing = new IdTagMatcher(null, new ResourceLocation(flowing));
cfm.flowing = new IdTagMatcher(IdTagMatcher.Type.ID, new ResourceLocation(flowing));
cfm.blockToTransform = blockToTransform;
cfm.blocksNearby = blocksNearby;
cfm.result = MixinResult.newBlockResult(blockResult);
Expand All @@ -110,53 +104,23 @@ public static CFM createBlockTransformation(String flowing, IdTagMatcher blockTo
* Returns a list with all the fluid stacks in the "flowing" key
*/
public List<FluidStack> getFlowingStacks() {
return getFluidStacks(this.flowing);
return this.flowing.getAllFluidStacks();
}

/**
* Returns a list with all the fluids stacks in the "block_to_transform" key
*/
public List<FluidStack> getFluidToTransformStacks() {
return getFluidStacks(this.blockToTransform);
return this.blockToTransform.getAllFluidStacks();
}

/**
* Returns a list with all the block stacks in the "block_to_transform" key
*/
public List<ItemStack> getBlockToTransformStacks() {
return getItemStacks(this.blockToTransform);
return this.blockToTransform.getAllItemStacks();
}

public static List<FluidStack> getFluidStacks(IdTagMatcher idTagMatcher) {
List<FluidStack> fluidStacks = new ArrayList<>();
if (idTagMatcher.id != null) {
Fluid fluid = ForgeRegistries.FLUIDS.getValue(idTagMatcher.id);
if (!(fluid instanceof EmptyFluid))
fluidStacks.add(new FluidStack(fluid, 1000));
}
else {
TagKey<Fluid> fluidTagKey = TagKey.create(Registry.FLUID_REGISTRY, idTagMatcher.tag);
ITag<Fluid> fluidITag = ForgeRegistries.FLUIDS.tags().getTag(fluidTagKey);
fluidITag.stream().forEach(fluid -> fluidStacks.add(new FluidStack(fluid, 1000)));
}
return fluidStacks;
}

public static List<ItemStack> getItemStacks(IdTagMatcher idTagMatcher) {
List<ItemStack> itemStacks = new ArrayList<>();
if (idTagMatcher.id != null) {
Block block = ForgeRegistries.BLOCKS.getValue(idTagMatcher.id);
itemStacks.add(new ItemStack(block));
}
else {
TagKey<Block> blockTagKey = TagKey.create(Registry.BLOCK_REGISTRY, idTagMatcher.tag);
ITag<Block> blockITag = ForgeRegistries.BLOCKS.tags().getTag(blockTagKey);
blockITag.stream().forEach(block -> itemStacks.add(new ItemStack(block)));
}
return itemStacks;
}


@Override
public String toString() {
return String.format("CFM[flowing: %s, blocks_nearby: %s, result: %s]", this.flowing, this.blocksNearby,
Expand Down Expand Up @@ -187,28 +151,28 @@ public static MixinResult newBlockResult(String block) {
return m;
}

public void validate() throws JsonValidationException {
public void validate() throws JsonParseException {
if (this.type == null)
throw new JsonValidationException("Missing type for result");
throw new JsonParseException("Missing type for result");

switch (this.type) {
case BLOCK -> {
if (this._block == null)
throw new JsonValidationException("Missing block for block result");
throw new JsonParseException("Missing block for block result");
ResourceLocation blockRL = ResourceLocation.tryParse(_block);
if (blockRL == null)
throw new JsonValidationException("Invalid block for block result");
throw new JsonParseException("Invalid block for block result");
this.block = ForgeRegistries.BLOCKS.getValue(blockRL).defaultBlockState();
}
case EXPLOSION -> {
if (this.explosionPower == null)
throw new JsonValidationException("Missing power for explosion result");
throw new JsonParseException("Missing power for explosion result");
if (this.shouldGenerateFire == null)
this.shouldGenerateFire = false;
}
case FUNCTION -> {
if (this._function == null)
throw new JsonValidationException("Missing function for function result");
throw new JsonParseException("Missing function for function result");
this.function = new CommandFunction.CacheableFunction(new ResourceLocation(this._function));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonSyntaxException;
import com.google.gson.JsonParseException;
import insane96mcp.customfluidmixin.CustomFluidMixin;
import insane96mcp.customfluidmixin.exception.JsonValidationException;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener;
Expand Down Expand Up @@ -48,10 +47,7 @@ protected void apply(Map<ResourceLocation, JsonElement> map, ResourceManager res

this.customFluidMixin.put(name, cfm);
}
catch (JsonValidationException e) {
CustomFluidMixin.LOGGER.error("Validation error loading Custom Fluid Mixin {}: {}", entry.getKey(), e.getMessage());
}
catch (JsonSyntaxException e) {
catch (JsonParseException e) {
CustomFluidMixin.LOGGER.error("Parsing error loading Custom Fluid Mixin {}: {}", entry.getKey(), e.getMessage());
}
catch (Exception e) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public void setRecipe(IRecipeLayoutBuilder builder, CFM recipe, IFocusGroup focu
if (blocksNearby.size() <= 3)
y += 8;
builder.addSlot(RecipeIngredientRole.CATALYST, x, y)
.addIngredients(ForgeTypes.FLUID_STACK, CFM.getFluidStacks(blockNearby))
.addItemStacks(CFM.getItemStacks(blockNearby));
.addIngredients(ForgeTypes.FLUID_STACK, blockNearby.getAllFluidStacks())
.addItemStacks(blockNearby.getAllItemStacks());
catalysts++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public void setRecipe(IRecipeLayoutBuilder builder, CFM recipe, IFocusGroup focu
if (blocksNearby.size() <= 3)
y += 8;
builder.addSlot(RecipeIngredientRole.CATALYST, x, y)
.addIngredients(ForgeTypes.FLUID_STACK, CFM.getFluidStacks(blockNearby))
.addItemStacks(CFM.getItemStacks(blockNearby));
.addIngredients(ForgeTypes.FLUID_STACK, blockNearby.getAllFluidStacks())
.addItemStacks(blockNearby.getAllItemStacks());
catalysts++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ public void registerCategories(IRecipeCategoryRegistration registration) {

private final CFM CFM_COBBLESTONE = CFM.createFlowingMixin("minecraft:lava",
List.of(
new IdTagMatcher(null, new ResourceLocation("minecraft:water"))),
new IdTagMatcher(IdTagMatcher.Type.ID, new ResourceLocation("minecraft:water"))),
"minecraft:cobblestone");
private final CFM CFM_BASALT = CFM.createFlowingMixin("minecraft:lava",
List.of(
new IdTagMatcher(new ResourceLocation("minecraft:soul_soil"), null),
new IdTagMatcher(new ResourceLocation("minecraft:blue_ice"), null)),
new IdTagMatcher(IdTagMatcher.Type.ID, new ResourceLocation("minecraft:soul_soil")),
new IdTagMatcher(IdTagMatcher.Type.ID, new ResourceLocation("minecraft:blue_ice"))),
"minecraft:basalt");
private final CFM CFM_OBSIDIAN = CFM.createBlockTransformation("minecraft:water",
new IdTagMatcher(null, new ResourceLocation("minecraft:lava")),
new IdTagMatcher(IdTagMatcher.Type.ID, new ResourceLocation("minecraft:lava")),
List.of(),
"minecraft:obsidian");
private final CFM CFM_STONE = CFM.createBlockTransformation("minecraft:lava",
new IdTagMatcher(null, new ResourceLocation("minecraft:water")),
new IdTagMatcher(IdTagMatcher.Type.ID, new ResourceLocation("minecraft:water")),
List.of(),
"minecraft:stone");

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ Modpack maker tool to make custom output when fluids flow (much like vanilla doe
[[dependencies.customfluidmixin]]
modId="insanelib"
mandatory=true
versionRange="[1.4.3,)"
versionRange="[1.5.1,)"
ordering="NONE"
side="BOTH"

0 comments on commit bb58da6

Please sign in to comment.