Skip to content

Commit

Permalink
Version 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mt1006 committed Oct 28, 2024
1 parent 1b9a479 commit 7960b71
Show file tree
Hide file tree
Showing 28 changed files with 462 additions and 128 deletions.
39 changes: 18 additions & 21 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
# gradle

.gradle/
build/
out/
classes/

# eclipse

*.launch

# idea

.idea/
*.iml
out/
*.ipr
*.iws
*.iml
.idea/*
!.idea/scopes

# vscode
# eclipse
eclipse
*.launch
.settings
.metadata
.classpath
.project

# vscode
.settings/
.vscode/
bin/
.classpath
.project

# macos

*.DS_Store

# fabric

run/

# java

hs_err_*.log
replay_*.log
*.hprof
*.jfr

# other
run/
runs/
bin/
classes/
5 changes: 5 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
===Version 1.2===
-Fixed opening non-openable fence gates with Iron Door Key not emitting sound and rotating fence gate in any direction depending on player rotation.
-Obtaining Redstone Dust now gives player Iron Door Key recipe.
-Iron door key recipe is now properly placed in equipment category, instead of building.

===Version 1.1.1===
-Version information is no longer sent to logs during startup.
-Warning message for unopenable block being declared as openable now properly includes "FenceGateBlock" as class of blocks possible to open.
Expand Down
84 changes: 47 additions & 37 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,46 +1,56 @@
plugins
subprojects
{
id "fabric-loom" version "1.7-SNAPSHOT"
}
apply plugin: "java"
java.toolchain.languageVersion = JavaLanguageVersion.of(java_version)

version = project.mod_version
group = project.maven_group

base
{
archivesName = "${project.archives_base_name}-FABRIC-${project.minecraft_version}"
}

repositories
{
maven { url = "https://maven.parchmentmc.org/" }
}

dependencies
{
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings loom.layered()
base
{
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-${project.mappings_version}@zip")
archivesName = "${mod_jar_name}-${project.name.toUpperCase()}-${minecraft_version}"
}

modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
}

processResources
{
inputs.property "version", project.version
filesMatching("fabric.mod.json") { expand "version": project.version }
}
processResources
{
var replaceProperties =
[
"mod_name" : mod_name,
"mod_jar_name" : mod_jar_name,
"mod_id" : mod_id,
"mod_group" : mod_group,
"mod_author" : mod_author,
"version" : version,
"license" : license,
"homepage" : homepage,
"source_url" : source_url,
"issue_tracker" : issue_tracker,
"mod_description" : mod_description,
"minecraft_version" : minecraft_version,
"java_version" : java_version,
"version_range_fabric" : version_range_fabric,
"version_range_forge" : version_range_forge,
"version_range_neoforge" : version_range_neoforge,
"fabric_loader_version" : fabric_loader_version,
"fabric_api_version" : fabric_api_version,
"forge_version" : forge_version,
"neoforge_version" : neoforge_version,
]

filesMatching(["pack.mcmeta", "fabric.mod.json", "META-INF/mods.toml", "META-INF/neoforge.mods.toml", "*.mixins.json"])
{
expand replaceProperties
}
inputs.properties replaceProperties
}

tasks.withType(JavaCompile).configureEach { it.options.release = 21 }
tasks.withType(JavaCompile).configureEach { it.options.encoding = "UTF-8" }

java
{
withSourcesJar()
if (project.name != "common")
{
dependencies
{
compileOnly project(":common")
}

sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
processResources { from project(":common").sourceSets.main.resources }
tasks.named("compileJava", JavaCompile) { source project(":common").sourceSets.main.allSource }
}
}
18 changes: 18 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
plugins
{
id "fabric-loom" version "${fabric_loom_version}"
}

repositories
{
maven { url = "https://maven.parchmentmc.org/" }
}

dependencies
{
minecraft "com.mojang:minecraft:${minecraft_version}"
mappings loom.layered {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-${parchment_minecraft}:${parchment_version}@zip")
}
}
16 changes: 16 additions & 0 deletions common/src/main/java/com/mt1006/irondoorkey/IronDoorKeyCommon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.mt1006.irondoorkey;

import com.mojang.logging.LogUtils;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.level.block.Block;
import org.slf4j.Logger;

public class IronDoorKeyCommon
{
public static final String MOD_ID = "irondoorkey";
public static final Logger LOGGER = LogUtils.getLogger();

public static final TagKey<Block> OPENABLE = TagKey.create(Registries.BLOCK, ResourceLocation.fromNamespaceAndPath(MOD_ID, "openable"));
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.mt1006.irondoorkey;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
Expand All @@ -14,13 +13,20 @@
import net.minecraft.world.level.block.TrapDoorBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockSetType;
import net.minecraft.world.level.block.state.properties.WoodType;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.level.material.Fluids;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

public class IronDoorKeyItem extends Item
{
private static boolean fenceGateSoundUsed = false;
private static @Nullable Field fenceGateTypeField = null;

public IronDoorKeyItem()
{
super(new Item.Properties());
Expand All @@ -32,7 +38,7 @@ public IronDoorKeyItem()
BlockPos blockPos = ctx.getClickedPos();
BlockState blockState = level.getBlockState(blockPos);

if (!blockState.is(IronDoorKeyMod.OPENABLE)) { return InteractionResult.PASS; }
if (!blockState.is(IronDoorKeyCommon.OPENABLE)) { return InteractionResult.PASS; }
Block blockType = blockState.getBlock();

if (blockType instanceof DoorBlock)
Expand All @@ -49,11 +55,11 @@ else if (blockType instanceof TrapDoorBlock)
else if (blockType instanceof FenceGateBlock)
{
// redundant in vanilla, added for better mod support, e.g. with SecurityCraft
openFenceGate(ctx.getPlayer(), level, blockPos, blockState);
openFenceGate(ctx.getPlayer(), level, blockPos, blockState, (FenceGateBlock)blockType);
return InteractionResult.sidedSuccess(level.isClientSide);
}

IronDoorKeyMod.LOGGER.warn("Failed to open the block - " +
IronDoorKeyCommon.LOGGER.warn("Failed to open the block - " +
"it has \"openable\" tag, but isn't instance of DoorBlock, TrapDoorBlock or FenceGateBlock");
return InteractionResult.PASS;
}
Expand All @@ -74,7 +80,7 @@ private static void openTrapDoor(@Nullable Player player, Level level, BlockPos
level.gameEvent(player, isOpen ? GameEvent.BLOCK_OPEN : GameEvent.BLOCK_CLOSE, blockPos);
}

private static void openFenceGate(@Nullable Player player, Level level, BlockPos blockPos, BlockState blockState)
private static void openFenceGate(@Nullable Player player, Level level, BlockPos blockPos, BlockState blockState, FenceGateBlock blockType)
{
boolean wasOpen = blockState.getValue(FenceGateBlock.OPEN);
if (wasOpen)
Expand All @@ -84,13 +90,43 @@ private static void openFenceGate(@Nullable Player player, Level level, BlockPos
}
else
{
Direction direction = player != null ? player.getDirection() : blockState.getValue(FenceGateBlock.FACING);
BlockState newBlockState = blockState.setValue(FenceGateBlock.OPEN, true).setValue(FenceGateBlock.FACING, direction);
BlockState newBlockState = blockState.setValue(FenceGateBlock.OPEN, true);
if (player != null && player.getDirection().getOpposite() == blockState.getValue(FenceGateBlock.FACING))
{
newBlockState = newBlockState.setValue(FenceGateBlock.FACING, player.getDirection());
}
level.setBlock(blockPos, newBlockState, 10);
}

boolean isOpen = !wasOpen;
level.levelEvent(player, isOpen ? 1008 : 1014, blockPos, 0);
playFenceGateSound(player, level, blockPos, blockType, isOpen);
level.gameEvent(player, isOpen ? GameEvent.BLOCK_OPEN : GameEvent.BLOCK_CLOSE, blockPos);
}

private static void playFenceGateSound(@Nullable Player player, Level level, BlockPos blockPos, FenceGateBlock blockType, boolean isOpen)
{
if (fenceGateTypeField == null)
{
if (fenceGateSoundUsed) { return; }
fenceGateSoundUsed = true;

for (Field field : FenceGateBlock.class.getDeclaredFields())
{
if (field.getType() == WoodType.class && !Modifier.isStatic(field.getModifiers()))
{
fenceGateTypeField = field;
field.setAccessible(true);
break;
}
}
if (fenceGateTypeField == null) { return; }
}

WoodType woodType;
try { woodType = (WoodType)fenceGateTypeField.get(blockType); }
catch (Exception exception) { return; }

level.playSound(player, blockPos, isOpen ? woodType.fenceGateOpen() : woodType.fenceGateClose(),
SoundSource.BLOCKS, 1.0f, level.getRandom().nextFloat() * 0.1f + 0.9f);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"parent": "minecraft:recipes/root",
"criteria":
{
"has_redstone": {
"conditions":
{
"items": [{ "items": "minecraft:redstone" }]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe":
{
"conditions": { "recipe": "irondoorkey:iron_door_key" },
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_the_recipe",
"has_redstone"
]
],
"rewards":
{
"recipes": [ "irondoorkey:iron_door_key" ]
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "minecraft:crafting_shaped",
"category": "building",
"category": "equipment",
"key":
{
"#": { "item": "minecraft:iron_nugget" },
Expand Down
File renamed without changes
16 changes: 16 additions & 0 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
plugins
{
id "fabric-loom" version "${fabric_loom_version}"
}

dependencies
{
minecraft "com.mojang:minecraft:${minecraft_version}"
mappings loom.layered {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-${parchment_minecraft}:${parchment_version}@zip")
}

modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_api_version}"
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
package com.mt1006.irondoorkey;

import com.mojang.logging.LogUtils;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import org.slf4j.Logger;

public class IronDoorKeyMod implements ModInitializer
{
public static final String MOD_ID = "irondoorkey";
public static final Logger LOGGER = LogUtils.getLogger();

private static final Item ITEM_IRON_DOOR_KEY = new IronDoorKeyItem();
public static final TagKey<Block> OPENABLE = TagKey.create(Registries.BLOCK, ResourceLocation.fromNamespaceAndPath(MOD_ID, "openable"));

@Override public void onInitialize()
{
Registry.register(BuiltInRegistries.ITEM, ResourceLocation.fromNamespaceAndPath(MOD_ID, "iron_door_key"), ITEM_IRON_DOOR_KEY);
Registry.register(BuiltInRegistries.ITEM, ResourceLocation.fromNamespaceAndPath(IronDoorKeyCommon.MOD_ID, "iron_door_key"), ITEM_IRON_DOOR_KEY);
ItemGroupEvents.modifyEntriesEvent(CreativeModeTabs.TOOLS_AND_UTILITIES).register((content) -> content.accept(ITEM_IRON_DOOR_KEY));
}
}
Loading

0 comments on commit 7960b71

Please sign in to comment.