Skip to content
Permalink
Browse files

チュートリアル初級編⑤ JSONの利用

  • Loading branch information...
TomKate committed Mar 20, 2018
1 parent 1e24fff commit 88fe0db28bc6a1a927552f369015ad13f434d922
@@ -21,7 +21,7 @@ compileJava {
}

minecraft {
version = "1.12.2-14.23.1.2555"
version = "1.12.2-14.23.2.2611"
runDir = "run"

// the mappings can be changed at any time, and must be in the following format.
78 gradlew
@@ -1,25 +1,43 @@
#!/usr/bin/env bash
#!/usr/bin/env sh

##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
warn () {
echo "$*"
}

die ( ) {
die () {
echo
echo "$*"
echo
@@ -30,6 +48,7 @@ die ( ) {
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
@@ -40,31 +59,11 @@ case "`uname`" in
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac

# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
APP_HOME="`pwd -P`"
cd "$SAVED" >&-

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
@@ -90,7 +89,7 @@ location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
@@ -114,6 +113,7 @@ fi
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
@@ -154,11 +154,19 @@ if $cygwin ; then
esac
fi

# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
APP_ARGS=$(save "$@")

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
exec "$JAVACMD" "$@"
@@ -8,14 +8,13 @@
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
set JAVA_HOME=C:\PROGRA~1\Java\jdk1.8.0_91

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
@@ -47,10 +46,9 @@ echo location of your Java installation.
goto fail

:init
@rem Get command-line arguments, handling Windowz variants
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args

:win9xME_args
@rem Slurp the command line arguments.
@@ -61,11 +59,6 @@ set _SKIP=2
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*
goto execute

:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$

:execute
@rem Setup the command line
@@ -7,6 +7,7 @@
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.storage.loot.LootTableList;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.common.MinecraftForge;
@@ -23,57 +24,62 @@

import java.util.List;

@Mod(modid = "aluminiummod", version = "1.0", name = "AluminiumMod",
updateJSON = "https://raw.githubusercontent.com/TNTModders/aluminiummod/master/version/aluminiumVersionCheck" +
".json")
@Mod(modid = "aluminiummod", version = "1.0", name = "AluminiumMod", updateJSON =
"https://raw.githubusercontent.com/TNTModders/aluminiummod/master/version/aluminiumVersionCheck" + ".json")
public class AluminiumMod {
public static final Item ALUMINIUM = new ItemAluminium();
public static final Block ALUMINIUM_BLOCK = new BlockAluminium();
public static final Item ALUMINIUM_ROD = new ItemAluminiumRod();
private static final AluminiumRecipeHolder HOLDER = new AluminiumRecipeHolder();

@Mod.Instance("aluminiummod")
public static AluminiumMod aluminiumInstance;

@Mod.EventHandler
//この関数でMODファイル自体をイベントの発火先にする。
public void construct(FMLConstructionEvent event) {
MinecraftForge.EVENT_BUS.register(this);
LootTableList.register(new ResourceLocation("aluminiummod:chests/aluminium_chest"));
LootTableList.register(new ResourceLocation("aluminiummod:entities/aluminium_get"));
}

//アイテムを登録するイベント。 旧preinitのタイミングで発火する。
@SubscribeEvent
public void registerItems(RegistryEvent.Register<Item> event) {
event.getRegistry().register(ALUMINIUM);
event.getRegistry().register(ALUMINIUM_ROD);
event.getRegistry().register(new ItemBlock(ALUMINIUM_BLOCK).setRegistryName("aluminiummod", "aluminium_block"));
}

//ブロックを登録するイベント。 旧preinitのタイミングで発火する。
@SubscribeEvent
public void registerBlocks(RegistryEvent.Register<Block> event) {
event.getRegistry().register(ALUMINIUM_BLOCK);
}

//モデルを登録するイベント。SideOnlyによってクライアント側のみ呼ばれる。旧preinitのタイミングで発火する。
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void registerModels(ModelRegistryEvent event) {
ModelLoader.setCustomModelResourceLocation(ALUMINIUM, 0, new ModelResourceLocation(new ResourceLocation
("aluminiummod", "aluminium"), "inventory"));
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(ALUMINIUM_BLOCK), 0, new
ModelResourceLocation(new ResourceLocation("aluminiummod", "aluminium_block"), "inventory"));
ModelLoader.setCustomModelResourceLocation(ALUMINIUM, 0,
new ModelResourceLocation(new ResourceLocation("aluminiummod", "aluminium"), "inventory"));
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(ALUMINIUM_BLOCK), 0,
new ModelResourceLocation(new ResourceLocation("aluminiummod", "aluminium_block"), "inventory"));
ModelLoader.setCustomModelResourceLocation(ALUMINIUM_ROD, 0,
new ModelResourceLocation(new ResourceLocation("aluminiummod", "aluminium_rod"), "inventory"));
}

@Mod.EventHandler
public void init(FMLInitializationEvent event) {
HOLDER.register();
}

//アイテムを拾ったときのイベント。
@SubscribeEvent
public void onPickupItem(EntityItemPickupEvent event) {
this.aluminiumUnlockRecipes(event.getItem().getItem(), event.getEntityPlayer());
}

private void aluminiumUnlockRecipes(ItemStack stack, EntityPlayer player) {
if (FMLCommonHandler.instance().getSide().isClient()) {
Item item = stack.getItem();
@@ -87,7 +93,7 @@ private void aluminiumUnlockRecipes(ItemStack stack, EntityPlayer player) {
}
}
}

//コンテナを閉じたとき(チェストやプレイヤーインベントリなど)のイベント。
@SubscribeEvent
public void onCloseContainer(PlayerContainerEvent.Close event) {
@@ -0,0 +1,37 @@
package com.tntmodders.tutorial;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class ItemAluminiumRod extends Item {

public ItemAluminiumRod() {
super();
//レジストリに保存する名称を登録する。大文字禁止。
this.setRegistryName("aluminiummod", "aluminium_rod");
//クリエイティブタブを設定する。
this.setCreativeTab(CreativeTabs.MATERIALS);
//翻訳名を登録する。大文字非推奨。
this.setUnlocalizedName("aluminium_rod");
}

@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand,
EnumFacing facing, float hitX, float hitY, float hitZ) {
worldIn.setBlockState(pos.offset(facing), Blocks.CHEST.getDefaultState());
if (worldIn.getTileEntity(pos.offset(facing)) instanceof TileEntityChest) {
((TileEntityChest) worldIn.getTileEntity(pos.offset(facing))).setLootTable(
new ResourceLocation("aluminiummod:chests/aluminium_chest"), player.getRNG().nextLong());
}
return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
}
}
@@ -0,0 +1,48 @@
{
"display": {
"icon": {
"item": "aluminiummod:aluminium"
},
"title": {
"translate": "advancements.aluminiummod.get.title"
},
"description": {
"translate": "advancements.aluminiummod.get.desc"
}
},
"parent": "aluminiummod:root",
"rewards": {
"loot": [
"aluminiummod:entities/aluminium_get"
],
"experience": 500
},
"criteria": {
"get_aluminium": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"item": "aluminiummod:aluminium"
}
]
}
},
"get_aluminium_block": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"item": "aluminiummod:aluminium_block"
}
]
}
}
},
"requirements": [
[
"get_aluminium",
"get_aluminium_block"
]
]
}
@@ -0,0 +1,21 @@
{
"display": {
"icon": {
"item": "aluminiummod:aluminium_block"
},
"title": {
"translate": "advancements.aluminiummod.root.title"
},
"description": {
"translate": "advancements.aluminiummod.root.desc"
},
"background": "aluminiummod:textures/blocks/aluminium_block.png",
"show_toast": false,
"announce_to_chat": false
},
"criteria": {
"tick": {
"trigger": "minecraft:tick"
}
}
}
Oops, something went wrong.

0 comments on commit 88fe0db

Please sign in to comment.
You can’t perform that action at this time.