Skip to content

Commit

Permalink
make use of tags
Browse files Browse the repository at this point in the history
  • Loading branch information
MelanX committed Sep 19, 2020
1 parent 6a726c0 commit bc6c3da
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 15 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Expand Up @@ -2,8 +2,8 @@ org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false

minecraft_version=1.16.2
forge_version=33.0.20
mod_version=1.3
forge_version=33.0.61
mappings_version=20200723-1.16.1

jei_version=7.1.3.20
2 changes: 1 addition & 1 deletion src/main/java/de/melanx/ultimatools/data/DataHandler.java
Expand Up @@ -2,7 +2,7 @@

import de.melanx.ultimatools.SkyblockUltimaTools;
import net.minecraft.data.DataGenerator;
import net.minecraftforge.client.model.generators.ExistingFileHelper;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.GatherDataEvent;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/melanx/ultimatools/data/ItemModels.java
Expand Up @@ -4,8 +4,8 @@
import de.melanx.ultimatools.item.Registration;
import net.minecraft.data.DataGenerator;
import net.minecraft.item.Item;
import net.minecraftforge.client.model.generators.ExistingFileHelper;
import net.minecraftforge.client.model.generators.ItemModelProvider;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.fml.RegistryObject;

import javax.annotation.Nonnull;
Expand Down
28 changes: 24 additions & 4 deletions src/main/java/de/melanx/ultimatools/item/Registration.java
Expand Up @@ -8,17 +8,37 @@
import net.minecraft.block.Blocks;
import net.minecraft.item.Item;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraftforge.common.Tags;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

import java.util.ArrayList;
import java.util.List;

public class Registration {

public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, SkyblockUltimaTools.MODID);
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, SkyblockUltimaTools.MODID);

private static final ImmutableSet<Block> ALL_STONES = ImmutableSet.copyOf(getAllStoneTags());
private static final ImmutableSet<Block> ALL_DIRTS = ImmutableSet.copyOf(getAllDirts());

private static List<Block> getAllDirts() {
List<Block> list = new ArrayList<>(Tags.Blocks.DIRT.getAllElements());
list.add(Blocks.GRASS_BLOCK);
return list;
}

private static List<Block> getAllStoneTags() {
List<Block> list = new ArrayList<>();
list.addAll(Tags.Blocks.COBBLESTONE.getAllElements());
list.addAll(Tags.Blocks.STONE.getAllElements());
return list;
}

public static final RegistryObject<Item> beginner = ITEMS.register("beginner", () -> new UltimaTool(ServerConfig.BEGINNER.get(), ToolEffects::placeWater));
public static final RegistryObject<Item> bloodMagician = ITEMS.register("blood_magician", () -> new UltimaTool(ServerConfig.BLOOD_MAGICIAN.get(), ToolEffects::spawnAnimal));
public static final RegistryObject<Item> cursedKnight = ITEMS.register("cursed_knight", () -> new UltimaTool(ServerConfig.CURSED_KNIGHT.get(), ToolEffects::applyMagicDamage));
Expand All @@ -27,17 +47,17 @@ public class Registration {
public static final RegistryObject<Item> knight = ITEMS.register("knight", UltimaCrafting::new);
public static final RegistryObject<Item> lighter = ITEMS.register("lighter", UltimaCrafting::new);
public static final RegistryObject<Item> oreBetter = ITEMS.register("ore_better", () -> new UltimaTool(ServerConfig.ORE_BETTER.get(), ToolEffects::upgradeOre));
public static final RegistryObject<Item> scholar = ITEMS.register("scholar", () -> new UltimaTool(ServerConfig.SCHOLAR.get(), ToolEffects.changeBlock(ImmutableSet.of(Blocks.DIRT, Blocks.COARSE_DIRT, Blocks.FARMLAND), Blocks.GRASS_BLOCK)));
public static final RegistryObject<Item> scholar = ITEMS.register("scholar", () -> new UltimaTool(ServerConfig.SCHOLAR.get(), ToolEffects.changeBlock(ImmutableSet.copyOf(Tags.Blocks.DIRT.getAllElements()), Blocks.GRASS_BLOCK)));
public static final RegistryObject<Item> soothsayer = ITEMS.register("soothsayer", () -> new UltimaTool(ServerConfig.SOOTHSAYER.get(), ToolEffects::applyPotion));
public static final RegistryObject<Item> ultimaFighter = ITEMS.register("ultima_fighter", () -> new UltimaTool(ServerConfig.ULTIMA_FIGHTER.get(), ToolEffects::generateOre));
public static final RegistryObject<Item> ultimaGod = ITEMS.register("ultima_god", () -> new UltimaTool(ServerConfig.ULTIMA_GOD.get(), ToolEffects::ultimate));

public static final RegistryObject<Item> kryptoBeginner = ITEMS.register("krypto_beginner", () -> new UltimaTool(ServerConfig.KRYPTO_BEGINNER.get(), ToolEffects::removeFluid));
public static final RegistryObject<Item> kryptoBloodMagician = ITEMS.register("krypto_blood_magician", () -> new UltimaTool(ServerConfig.KRYPTO_BLOOD_MAGICIAN.get(), ToolEffects::applyRegeneration));
public static final RegistryObject<Item> kryptoCursedKnight = ITEMS.register("krypto_cursed_knight", () -> new UltimaTool(ServerConfig.KRYPTO_CURSED_KNIGHT.get(), ToolEffects::applyLevitation));
public static final RegistryObject<Item> kryptoFarmer = ITEMS.register("krypto_farmer", () -> new UltimaTool(ServerConfig.KRYPTO_FARMER.get(), ToolEffects.changeBlock(ImmutableSet.of(Blocks.DIRT, Blocks.COARSE_DIRT, Blocks.GRASS_BLOCK), Blocks.FARMLAND.getDefaultState().with(BlockStateProperties.MOISTURE_0_7, 7))));
public static final RegistryObject<Item> kryptoScholar = ITEMS.register("krypto_scholar", () -> new UltimaTool(ServerConfig.KRYPTO_SCHOLAR.get(), ToolEffects.changeBlock(ImmutableSet.of(Blocks.DIRT, Blocks.COARSE_DIRT, Blocks.GRASS_BLOCK), Blocks.STONE)));
public static final RegistryObject<Item> kryptoSoothsayer = ITEMS.register("krypto_soothsayer", () -> new UltimaTool(ServerConfig.KRYPTO_SOOTHSAYER.get(), ToolEffects.changeBlock(ImmutableSet.of(Blocks.STONE, Blocks.COBBLESTONE), Blocks.COAL_ORE)));
public static final RegistryObject<Item> kryptoFarmer = ITEMS.register("krypto_farmer", () -> new UltimaTool(ServerConfig.KRYPTO_FARMER.get(), ToolEffects.changeBlock(ALL_DIRTS, Blocks.FARMLAND.getDefaultState().with(BlockStateProperties.MOISTURE_0_7, 7))));
public static final RegistryObject<Item> kryptoScholar = ITEMS.register("krypto_scholar", () -> new UltimaTool(ServerConfig.KRYPTO_SCHOLAR.get(), ToolEffects.changeBlock(ALL_STONES, Blocks.STONE)));
public static final RegistryObject<Item> kryptoSoothsayer = ITEMS.register("krypto_soothsayer", () -> new UltimaTool(ServerConfig.KRYPTO_SOOTHSAYER.get(), ToolEffects.changeBlock(ALL_STONES, Blocks.COAL_ORE)));
public static final RegistryObject<Item> kryptoForestRunner = ITEMS.register("krypto_forest_runner", UltimaCrafting::new);
public static final RegistryObject<Item> kryptoKnight = ITEMS.register("krypto_knight", UltimaCrafting::new);
public static final RegistryObject<Item> kryptoLighter = ITEMS.register("krypto_lighter", UltimaCrafting::new);
Expand Down
1 change: 0 additions & 1 deletion src/main/java/de/melanx/ultimatools/item/UltimaTool.java
Expand Up @@ -3,7 +3,6 @@
import de.melanx.ultimatools.SkyblockUltimaTools;
import de.melanx.ultimatools.lib.Function3;
import de.melanx.ultimatools.lib.Function5;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/de/melanx/ultimatools/util/ToolEffects.java
Expand Up @@ -22,7 +22,6 @@
import net.minecraft.tags.FluidTags;
import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IServerWorld;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.Tags;
Expand Down Expand Up @@ -184,8 +183,8 @@ public static boolean generateOre(World world, PlayerEntity player, Hand hand, B
if (!player.canPlayerEdit(pos, face, player.getHeldItem(hand)))
return false;

if (world.getBlockState(pos).getBlock() == Blocks.COBBLESTONE
|| world.getBlockState(pos).getBlock() == Blocks.STONE) {
if (Tags.Blocks.COBBLESTONE.contains(world.getBlockState(pos).getBlock())
|| Tags.Blocks.STONE.contains(world.getBlockState(pos).getBlock())) {

Block block = Tags.Blocks.ORES.getRandomElement(world.rand);
BlockState state = block.getDefaultState();
Expand All @@ -201,22 +200,22 @@ public static boolean generateOre(World world, PlayerEntity player, Hand hand, B

public static boolean ultimate(World world, PlayerEntity player, Hand hand, BlockPos pos, Direction face) {
Block block = world.getBlockState(pos).getBlock();
if (block != Blocks.DIRT && block != Blocks.COARSE_DIRT && block != Blocks.FARMLAND && block != Blocks.GRASS_BLOCK) {
if (!Tags.Blocks.DIRT.contains(block) && block != Blocks.GRASS_BLOCK) {
if (player.isSneaking()) {
return placeWater(world, player, hand, pos, face);
}
} else if (!player.isSneaking()) {
if (block == Blocks.DIRT || block == Blocks.COARSE_DIRT || block == Blocks.FARMLAND) {
if (Tags.Blocks.DIRT.contains(block)) {
BlockState newState = Blocks.GRASS_BLOCK.getDefaultState();
SoundType sound = newState.getSoundType();
world.playSound(null, pos, sound.getPlaceSound(), SoundCategory.BLOCKS, (sound.getVolume() + 1.0F) / 2.0F, sound.getPitch() * 0.8F);
world.setBlockState(pos, newState);
return true;
} else if (block == Blocks.COBBLESTONE || block == Blocks.STONE) {
} else if (Tags.Blocks.COBBLESTONE.contains(block) || Tags.Blocks.STONE.contains(block)) {
return generateOre(world, player, hand, pos, face);
}
} else {
if (block == Blocks.DIRT || block == Blocks.COARSE_DIRT || block == Blocks.GRASS_BLOCK || world.getBlockState(pos.offset(face)).getBlock() == Blocks.WATER) {
if (Tags.Blocks.DIRT.contains(block) || block == Blocks.GRASS_BLOCK || world.getBlockState(pos.offset(face)).getBlock() == Blocks.WATER) {
return spawnAnimal(world, player, hand, pos, face);
} else {
return useBonemeal(world, player, hand, pos, face);
Expand Down

0 comments on commit bc6c3da

Please sign in to comment.