Skip to content

Commit

Permalink
Update 1.20.6.
Browse files Browse the repository at this point in the history
Remove compatibility as StrageBox and TorchBinder.
  • Loading branch information
noriokun4649 committed May 11, 2024
1 parent aeb997e commit 30c83c4
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 154 deletions.
28 changes: 13 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
id 'eclipse'
id 'idea'
id 'maven-publish'
id 'net.minecraftforge.gradle' version '[6.0.16,6.2)'
id 'net.minecraftforge.gradle' version '[6.0.24,6.2)'
id 'net.darkhax.curseforgegradle' version '1.+'
id "com.modrinth.minotaur" version "2.+"
}
Expand All @@ -16,8 +16,8 @@ base {
archivesName = "$mod_name-$modloader_name-$minecraft_version"
}

// Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17.
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
// Mojang ships Java 21 to end users in 1.20.5+, so your mod should target Java 21.
java.toolchain.languageVersion = JavaLanguageVersion.of(21)

println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}"
minecraft {
Expand All @@ -36,6 +36,9 @@ minecraft {
// Simply re-run your setup task after changing the mappings to update your workspace.
mappings channel: mapping_channel, version: mapping_version

// Tell FG to not automtically create the reobf tasks, as we now use Official mappings at runtime, If you don't use them at dev time then you'll have to fix your reobf yourself.
reobf = false

// When true, this property will have all Eclipse/IntelliJ IDEA run configurations run the "prepareX" task for the given run configuration before launching the game.
// In most cases, it is not necessary to enable.
// enableEclipsePrepareRuns = true
Expand Down Expand Up @@ -128,11 +131,11 @@ dependencies {
// then special handling is done to allow a setup of a vanilla dependency without the use of an external repository.
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"

// Example mod dependency with JEI - using fg.deobf() ensures the dependency is remapped to your development mappings
// Example mod dependency with JEI
// The JEI API is declared for compile time use, while the full JEI artifact is used at runtime
// compileOnly fg.deobf("mezz.jei:jei-${mc_version}-common-api:${jei_version}")
// compileOnly fg.deobf("mezz.jei:jei-${mc_version}-forge-api:${jei_version}")
// runtimeOnly fg.deobf("mezz.jei:jei-${mc_version}-forge:${jei_version}")
// compileOnly "mezz.jei:jei-${mc_version}-common-api:${jei_version}"
// compileOnly "mezz.jei:jei-${mc_version}-forge-api:${jei_version}"
// runtimeOnly "mezz.jei:jei-${mc_version}-forge:${jei_version}"

// Example mod dependency using a mod jar from ./libs with a flat dir repository
// This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar
Expand All @@ -142,6 +145,9 @@ dependencies {
// For more info:
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html

// Hack fix for now, force jopt-simple to be exactly 5.0.4 because Mojang ships that version, but some transtive dependencies request 6.0+
implementation('net.sf.jopt-simple:jopt-simple:5.0.4') { version { strictly '5.0.4' } }
}

// This block of code expands all declared replace properties in the specified resource targets.
Expand Down Expand Up @@ -175,16 +181,8 @@ tasks.named('jar', Jar).configure {
'Implementation-Vendor' : mod_authors
])
}

// This is the preferred method to reobfuscate your jar file
finalizedBy 'reobfJar'
}

// However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing:
// tasks.named('publish').configure {
// dependsOn 'reobfJar'
// }

// Example configuration to allow publishing using the maven-publish plugin
publishing {
publications {
Expand Down
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ org.gradle.daemon=false
## Environment Properties

# The Minecraft version must agree with the Forge version to get a valid artifact
minecraft_version=1.20.4
minecraft_version=1.20.6
# The Minecraft version range can use any release version of Minecraft as bounds.
# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly
# as they do not follow standard versioning conventions.
minecraft_version_range=[1.20.4,1.21)
minecraft_version_range=[1.20.6,1.21)
# The Forge version must agree with the Minecraft version to get a valid artifact
forge_version=49.0.14
forge_version=50.0.9
# The Forge version range can use any version of Forge as bounds or match the loader version range
forge_version_range=[49,)
forge_version_range=[50,)
# The loader version range can only use the major version of Forge/FML as bounds
loader_version_range=[49,)
loader_version_range=[50,)
# The mapping channel to use for mappings.
# The default set of supported mapping channels are ["official", "snapshot", "snapshot_nodoc", "stable", "stable_nodoc"].
# Additional mapping channels can be registered through the "channelProviders" extension in a Gradle plugin.
Expand All @@ -35,7 +35,7 @@ loader_version_range=[49,)
mapping_channel=official
# The mapping version to query from the mapping channel.
# This must match the format required by the mapping channel.
mapping_version=1.20.4
mapping_version=1.20.6


## Mod Properties
Expand All @@ -49,7 +49,7 @@ mod_name=TorchBowMod
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=MIT License
# The mod version. See https://semver.org/
mod_version=1.1.0
mod_version=1.0.0
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
5 changes: 5 additions & 0 deletions src/main/java/mod/torchbowmod/EntityTorch.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ protected void onHitBlock(BlockHitResult raytraceResultIn) {
}
}

@Override
protected ItemStack getDefaultPickupItem() {
return new ItemStack(Blocks.TORCH);
}

private void creeperIgnite(Creeper creeper){
if (Math.random() < 0.05) {
creeper.ignite();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/mod/torchbowmod/TorchArrow.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.world.item.ArrowItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.entity.projectile.AbstractArrow.Pickup;

public class TorchArrow extends ArrowItem {

Expand All @@ -20,7 +21,7 @@ public AbstractArrow createArrow(Level level, ItemStack itemStack, LivingEntity
}

@Override
public boolean isInfinite(ItemStack stack, ItemStack bow, Player player) {
public boolean isInfinite(ItemStack stack, ItemStack bow, LivingEntity owner) {
return false;
}
}
138 changes: 17 additions & 121 deletions src/main/java/mod/torchbowmod/TorchBow.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package mod.torchbowmod;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.stats.Stats;
Expand All @@ -10,51 +9,29 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.item.*;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.event.ForgeEventFactory;
import org.jetbrains.annotations.Nullable;

import java.util.function.Predicate;

import static mod.torchbowmod.TorchBowMod.multiTorch;
import static mod.torchbowmod.TorchBowMod.torchArrow;
import static net.minecraft.world.item.BowItem.getPowerForTime;

public class TorchBow extends ProjectileWeaponItem implements Vanishable {
private ItemStack torchbinder;
private ItemStack sitemstack;
private boolean sitem;
private boolean storageid;

private boolean binder;
public class TorchBow extends ProjectileWeaponItem {
public static final Predicate<ItemStack> TORCH = itemStack -> itemStack.is(Blocks.TORCH.asItem());
public static final Predicate<ItemStack> MULTI_TORCH = itemStack -> itemStack.is(multiTorch.get());
public static final Predicate<ItemStack> TORCH_ARROW = itemStack -> itemStack.is(torchArrow.get());
public static final Predicate<ItemStack> TORCH_BINDER;
public static final Predicate<ItemStack> STORAGE_BOX;
public static final Predicate<ItemStack> TORCH_BOW_ONLY;


static {
STORAGE_BOX = itemStack -> {
if (itemStack.getTag() == null) return false;
var isStorageBox = itemStack.is(TorchBowMod.StorageBox);
var storageItem = ItemStack.of(itemStack.getTag().getCompound("StorageItemData"));
var containsTorch = storageItem.is(Blocks.TORCH.asItem());
var containsMultiTorch = storageItem.is(multiTorch.get());

return isStorageBox && (containsTorch || containsMultiTorch);
};

TORCH_BINDER = itemStack -> {
var isTorchBinder = itemStack.is(TorchBowMod.torchbinder);
var notEmpty = itemStack.getOrCreateTagElement("TorchBandolier").getInt("Count") > 0;
return isTorchBinder && notEmpty;
};
TORCH_BOW_ONLY = TORCH.or(MULTI_TORCH).or(TORCH_ARROW).or(TORCH_BINDER).or(STORAGE_BOX);
TORCH_BOW_ONLY = TORCH.or(MULTI_TORCH).or(TORCH_ARROW);
}

public TorchBow(Item.Properties properties) {
Expand All @@ -71,6 +48,11 @@ public int getDefaultProjectileRange() {
return 0;
}

@Override
protected void shootProjectile(LivingEntity p_330864_, Projectile p_328720_, int p_328740_, float p_335337_, float p_332934_, float p_329948_, @Nullable LivingEntity p_329516_) {

}

@Override
public boolean isValidRepairItem(ItemStack itemStack, ItemStack itemStack2) {
return itemStack2.is(Items.FLINT_AND_STEEL) || super.isValidRepairItem(itemStack, itemStack2);
Expand All @@ -84,7 +66,7 @@ public int getEnchantmentValue() {
@Override
public void releaseUsing(ItemStack stack, Level worldIn, LivingEntity entityLiving, int timeLeft) {
if (entityLiving instanceof Player playerentity) {
boolean flag = playerentity.getAbilities().invulnerable || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.INFINITY_ARROWS, stack) > 0;
boolean flag = playerentity.getAbilities().invulnerable || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
ItemStack itemstack = playerentity.getProjectile(stack);

int i = this.getUseDuration(stack) - timeLeft;
Expand All @@ -100,7 +82,7 @@ public void releaseUsing(ItemStack stack, Level worldIn, LivingEntity entityLivi
if ((double) f >= 0.1D) {
boolean flag1 = playerentity.getAbilities().invulnerable || (itemstack.getItem() instanceof ArrowItem && ((ArrowItem) itemstack.getItem()).isInfinite(itemstack, stack, playerentity));
if (!worldIn.isClientSide) {
boolean isMultitorch = itemstack.getItem() == multiTorch.get() || (itemstack.getItem() == TorchBowMod.StorageBox && ItemStack.of(itemstack.getTag().getCompound("StorageItemData")).getItem() == multiTorch.get());
boolean isMultitorch = itemstack.getItem() == multiTorch.get();
shootTorch(playerentity, entityLiving, worldIn, itemstack, stack, flag1, f);
if (isMultitorch){
float size = 10f;
Expand All @@ -123,24 +105,6 @@ public void releaseUsing(ItemStack stack, Level worldIn, LivingEntity entityLivi
if (itemstack.isEmpty()) {
playerentity.getInventory().removeItem(itemstack);
}
} else if (sitem) {//StorageBoxだった場合の処理
if (!worldIn.isClientSide) {
if (storageid) {
int Size = sitemstack.getTag().getInt("StorageSize");//今のアイテムの数取得
int retrun_size = --Size;
if (retrun_size != 0) {
sitemstack.getTag().putInt("StorageSize", retrun_size);//ストレージBoxの中のアイテムの数減少させる。
} else {
sitemstack.getTag().remove("StorageItemData");
}
}
}
} else if (binder) {//TorchBandolierだった場合の処理
if (!worldIn.isClientSide) {
int Size = torchbinder.getOrCreateTagElement("TorchBandolier").getInt("Count");//今のアイテムの数取得
int retrun_size = --Size;
torchbinder.getOrCreateTagElement("TorchBandolier").putInt("Count", retrun_size);//TorchBandolierのアイテムの数減少させる。
}
}
}

Expand All @@ -162,23 +126,21 @@ private void shootTorch(Player entitle, LivingEntity livingEntity, Level worldIn
abstractedly.setCritArrow(true);
}

int j = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.POWER_ARROWS, stack);
int j = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.POWER, stack);
if (j > 0) {
abstractedly.setBaseDamage(abstractedly.getBaseDamage() + (double) j * 0.5D + 0.5D);
}

int k = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.PUNCH_ARROWS, stack);
int k = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.PUNCH, stack);
if (k > 0) {
abstractedly.setKnockback(k);
}

if (EnchantmentHelper.getItemEnchantmentLevel(Enchantments.FLAMING_ARROWS, stack) > 0) {
abstractedly.setSecondsOnFire(100);
if (EnchantmentHelper.getItemEnchantmentLevel(Enchantments.FLAME, stack) > 0) {
abstractedly.igniteForSeconds(100);
}

stack.hurtAndBreak(1, entitle, (player) -> {
player.broadcastBreakEvent(entitle.getUsedItemHand());
});
stack.hurtAndBreak(1, entitle, LivingEntity.getSlotForHand(entitle.getUsedItemHand()));
if (flag1 || entitle.getAbilities().instabuild && (itemstack.getItem() == Blocks.TORCH.asItem())) {
abstractedly.pickup = AbstractArrow.Pickup.CREATIVE_ONLY;
}
Expand All @@ -196,83 +158,17 @@ public UseAnim getUseAnimation(ItemStack itemStack) {

public InteractionResultHolder<ItemStack> use(Level worldIn, Player playerIn, InteractionHand handIn) {
ItemStack itemstack = playerIn.getItemInHand(handIn);
binder = getSilentsMod(playerIn);
storageid = getStorageMod(playerIn);
boolean flag = !playerIn.getProjectile(itemstack).isEmpty();

InteractionResultHolder<ItemStack> ret = net.minecraftforge.event.ForgeEventFactory.onArrowNock(itemstack, worldIn, playerIn, handIn, flag);
if (ret != null) return ret;

if (!playerIn.getAbilities().instabuild && !flag && !binder && !storageid) {
if (!playerIn.getAbilities().instabuild && !flag) {
return new InteractionResultHolder<>(InteractionResult.FAIL, itemstack);
} else {
playerIn.startUsingItem(handIn);
return new InteractionResultHolder<>(InteractionResult.SUCCESS, itemstack);
}
}

/***
* アイテムからアイテムスタック取得。
* @param player
* @param item
* @return ItemStack
*/
private ItemStack getStack(Player player, Item item) {
for (int i = 0; i < player.getInventory().items.size(); ++i) {
player.getInventory();
if (player.getInventory().items.get(i).getItem() == item/*TorchBowMod.StorageBox*/) {
ItemStack itemstack = player.getInventory().items.get(i);
//アイテムスタックがからじゃなかったら
if (itemstack.getTag() == null) {//NBTがNullだったら
itemstack.setTag(new CompoundTag());//新しい空のNBTを書き込む
}
return itemstack;
}
}
return new ItemStack(Items.BONE);
}

/***
* Modのアイテムが有効かどうか、松明が切れてないかどうか
* StorageBoxMod用処理
* @param player
* @return Modお問い合わせ
*/
private boolean getStorageMod(Player player) {
sitemstack = getStack(player, TorchBowMod.StorageBox);//ItemStack取得
boolean as = sitemstack.getItem() == TorchBowMod.StorageBox;//正しいかどうかチェック
boolean storageid = false;//ストレージBoxに入ってるItemのIDチェック用の変数初期化 初期値:無効
int ssize = 0;
if (as) {//ただしかったら
CompoundTag a = sitemstack.getTag().getCompound("StorageItemData");//StrageBoxに入ってるItemStackを取得
Item itemname = ItemStack.of(a).getItem();//スロトレージBoxのなかのID取得
Item itemid = new ItemStack(Blocks.TORCH).getItem();//対象のID取得
Item itemid2 = new ItemStack(multiTorch.get()).getItem();
sitem = itemname == itemid || itemname == itemid2;
if (sitem) {//同じ場合
ssize = sitemstack.getTag().getInt("StorageSize");//有効に
storageid = ssize != 0;//無効に
}
}
return storageid;
}

/**
* Modのアイテムが有効かどうか、松明が切れてないかどうか
* TorchBandolier用処理
*
* @param player  プレイヤー
* @return Modお問い合わせ
*/
private boolean getSilentsMod(Player player) {
torchbinder = getStack(player, TorchBowMod.torchbinder);//ItemStack取得
boolean mitem = torchbinder.getItem() == TorchBowMod.torchbinder;//正しいかどうかチェック
boolean myes = false;//ストレージBoxに入ってるItemのIDチェック用の変数初期化 初期値:無効
if (mitem) {
int ssize = 0;
ssize = torchbinder.getOrCreateTagElement("TorchBandolier").getInt("Count");//有効に
myes = ssize != 0;//無効に
}
return myes;
}
}
6 changes: 1 addition & 5 deletions src/main/java/mod/torchbowmod/TorchBowMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,10 @@ public class TorchBowMod {
private static final DeferredRegister<EntityType<?>> ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.ENTITY_TYPES, MODID);
private static final DeferredRegister<CreativeModeTab> TAB = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MODID);

@ObjectHolder(registryName = "torchbandolier:torch_bandolier", value = "torch_bandolier")
public static Item torchbinder = null;
@ObjectHolder(registryName = "storagebox:storagebox", value = "storagebox")
public static Item StorageBox = null;
@ObjectHolder(registryName = "ceilingtorch:torch", value = "ceilingtorch")
public static Block CeilingTorch = null;

public static RegistryObject<Item> torchbow = ITEMS.register("torchbow", () -> new TorchBow(new Item.Properties().defaultDurability(384)));
public static RegistryObject<Item> torchbow = ITEMS.register("torchbow", () -> new TorchBow(new Item.Properties().durability(384)));
public static RegistryObject<Item> multiTorch = ITEMS.register("multitorch", () -> new Item(new Item.Properties().stacksTo(64)));
public static RegistryObject<Item> torchArrow = ITEMS.register("torcharrow", () -> new TorchArrow(new Item.Properties().stacksTo(64)));
public static RegistryObject<EntityType<EntityTorch>> entityTorch = ENTITY_TYPES.register("entitytorch", () ->
Expand Down
Loading

0 comments on commit 30c83c4

Please sign in to comment.