Skip to content

Commit

Permalink
Future MC 0.2.8
Browse files Browse the repository at this point in the history
  • Loading branch information
thedarkcolour committed Mar 28, 2022
1 parent d3eb4da commit 1cc86d4
Show file tree
Hide file tree
Showing 37 changed files with 309 additions and 326 deletions.
20 changes: 20 additions & 0 deletions src/main/java/thedarkcolour/futuremc/FutureMC.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
package thedarkcolour.futuremc

import net.minecraft.block.BlockDispenser
import net.minecraft.block.material.Material
import net.minecraft.creativetab.CreativeTabs
import net.minecraft.dispenser.IBehaviorDispenseItem
import net.minecraft.init.Biomes
import net.minecraft.init.Blocks
import net.minecraft.init.Items
import net.minecraft.item.Item
Expand All @@ -18,6 +20,7 @@ import net.minecraftforge.fml.common.FMLCommonHandler
import net.minecraftforge.fml.common.Mod
import net.minecraftforge.fml.common.Mod.EventHandler
import net.minecraftforge.fml.common.event.FMLInitializationEvent
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent
import net.minecraftforge.fml.common.registry.ForgeRegistries
import net.minecraftforge.fml.common.registry.GameRegistry
Expand All @@ -36,6 +39,7 @@ import thedarkcolour.futuremc.client.tesr.WoodenSignRenderer
import thedarkcolour.futuremc.compat.QUARK
import thedarkcolour.futuremc.compat.isModLoaded
import thedarkcolour.futuremc.config.FConfig
import thedarkcolour.futuremc.entity.bee.EntityBee
import thedarkcolour.futuremc.event.Events
import thedarkcolour.futuremc.item.BannerPatternItem
import thedarkcolour.futuremc.network.NetworkHandler
Expand Down Expand Up @@ -134,6 +138,9 @@ object FutureMC {
BottleDispenserBehavior.dispense(source.world, source, stack, existing)
})
}
if (FConfig.villageAndPillage.campfire.enabled) {
// todo campfire lighting with flint steel and burnout with shovel
}

if (FConfig.villageAndPillage.loom.enabled) {
val params = arrayOf(String::class.java, String::class.java)
Expand All @@ -155,6 +162,19 @@ object FutureMC {
}
}

@EventHandler
fun postInit(event: FMLPostInitializationEvent) {
EntityBee.FLOWERS.removeIf { state ->
state.material == Material.AIR // try to fix #281
}

Biomes.PLAINS.addFlower(FBlocks.CORNFLOWER.defaultState, 5)
for (biome in listOf(Biomes.FOREST, Biomes.BIRCH_FOREST_HILLS, Biomes.BIRCH_FOREST, Biomes.FOREST_HILLS, Biomes.MUTATED_BIRCH_FOREST, Biomes.MUTATED_BIRCH_FOREST_HILLS, Biomes.MUTATED_FOREST)) {
Biomes.PLAINS.addFlower(FBlocks.CORNFLOWER.defaultState, 5)
Biomes.PLAINS.addFlower(FBlocks.LILY_OF_THE_VALLEY.defaultState, 5)
}
}

private fun registerWorldGen() {
if (FConfig.villageAndPillage.lilyOfTheValley.enabled) {
GameRegistry.registerWorldGenerator(FlowerWorldGen(FBlocks.LILY_OF_THE_VALLEY), 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ import net.minecraft.init.Blocks
import net.minecraft.init.Items
import net.minecraft.item.Item
import net.minecraft.item.ItemStack
import net.minecraft.item.crafting.Ingredient
import net.minecraft.tileentity.TileEntity
import net.minecraft.util.*
import net.minecraft.util.EnumFacing
import net.minecraft.util.EnumHand
import net.minecraft.util.EnumParticleTypes
import net.minecraft.util.SoundCategory
import net.minecraft.util.math.AxisAlignedBB
import net.minecraft.util.math.BlockPos
import net.minecraft.world.World
Expand Down Expand Up @@ -141,36 +145,37 @@ class ComposterBlock(properties: Properties) : InteractionBlock(properties) {
}

object ItemsForComposter {
private val VALID_ITEMS = Object2ByteOpenHashMap<ItemStack>()
val entries: Object2ByteMap.FastEntrySet<ItemStack>
private val VALID_ITEMS = Object2ByteOpenHashMap<Ingredient>()
val entries: Object2ByteMap.FastEntrySet<Ingredient>
get() = VALID_ITEMS.object2ByteEntrySet()

private fun add(registryObject: IForgeRegistryEntry<*>, rarity: ComposterRarity) {
private fun add(registryObject: IForgeRegistryEntry<*>, rarity: Byte) {
if (registryObject is Block) {
add(ItemStack(registryObject), rarity)
add(Ingredient.fromItem(Item.getItemFromBlock(registryObject)), rarity)
} else {
add(ItemStack(registryObject as Item), rarity)
add(Ingredient.fromItem(registryObject as Item), rarity)
}
}

fun add(stack: ItemStack, rarity: ComposterRarity) {
add(stack, rarity.chance)
@Suppress("ReplacePutWithAssignment")
fun add(ingredient: Ingredient, rarity: Byte) {
VALID_ITEMS.put(ingredient, rarity)
}

@JvmStatic
fun add(stack: ItemStack, rarity: Int) {
VALID_ITEMS[stack] = rarity.toByte().coerceAtMost(100)
add(stack, rarity.toByte().coerceAtMost(100))
}

@Suppress("ReplacePutWithAssignment")
fun add(stack: ItemStack, rarity: Byte) {
VALID_ITEMS.put(stack, rarity)
VALID_ITEMS.put(Ingredient.fromStacks(stack), rarity)
}

@JvmStatic
fun getChance(stack: ItemStack): Byte {
if (stack.isEmpty) return -1
val item = VALID_ITEMS.keys.firstOrNull(stack::isItemEqual)
val item = VALID_ITEMS.keys.firstOrNull { it.test(stack) }
return VALID_ITEMS[item] ?: -1
}

Expand All @@ -188,22 +193,12 @@ class ComposterBlock(properties: Properties) : InteractionBlock(properties) {
if (FConfig.villageAndPillage.composter) {
// COMMON
add(ItemStack(Blocks.TALLGRASS, 1, 1), ComposterRarity.COMMON)
add(ItemStack(Blocks.LEAVES, 1, 0), ComposterRarity.COMMON)
add(ItemStack(Blocks.LEAVES, 1, 1), ComposterRarity.COMMON)
add(ItemStack(Blocks.LEAVES, 1, 2), ComposterRarity.COMMON)
add(ItemStack(Blocks.LEAVES, 1, 3), ComposterRarity.COMMON)
add(ItemStack(Blocks.LEAVES2, 1, 0), ComposterRarity.COMMON)
add(ItemStack(Blocks.LEAVES2, 1, 1), ComposterRarity.COMMON)
add(Blocks.LEAVES, ComposterRarity.COMMON)
add(Items.MELON_SEEDS, ComposterRarity.COMMON)
add(Items.PUMPKIN_SEEDS, ComposterRarity.COMMON)
add(Items.WHEAT_SEEDS, ComposterRarity.COMMON)
add(Items.BEETROOT_SEEDS, ComposterRarity.COMMON)
add(ItemStack(Blocks.SAPLING, 1, 0), ComposterRarity.COMMON)
add(ItemStack(Blocks.SAPLING, 1, 1), ComposterRarity.COMMON)
add(ItemStack(Blocks.SAPLING, 1, 2), ComposterRarity.COMMON)
add(ItemStack(Blocks.SAPLING, 1, 3), ComposterRarity.COMMON)
add(ItemStack(Blocks.SAPLING, 1, 4), ComposterRarity.COMMON)
add(ItemStack(Blocks.SAPLING, 1, 5), ComposterRarity.COMMON)
add(Blocks.SAPLING, ComposterRarity.COMMON)
add(SWEET_BERRIES, ComposterRarity.COMMON)
// UNCOMMON
add(Items.MELON, ComposterRarity.UNCOMMON)
Expand All @@ -218,9 +213,7 @@ class ComposterBlock(properties: Properties) : InteractionBlock(properties) {
add(ItemStack(Items.DYE, 1, 3), ComposterRarity.RARE)
add(ItemStack(Blocks.TALLGRASS, 1, 2), ComposterRarity.RARE)
add(ItemStack(Blocks.DOUBLE_PLANT, 1, 3), ComposterRarity.RARE)
val subFlowers = NonNullList.create<ItemStack>()
Blocks.RED_FLOWER.getSubBlocks(null, subFlowers)
for (f in subFlowers) add(f, ComposterRarity.RARE)
add(Blocks.RED_FLOWER, ComposterRarity.RARE)
add(Blocks.YELLOW_FLOWER, ComposterRarity.RARE)
add(LILY_OF_THE_VALLEY, ComposterRarity.RARE)
add(CORNFLOWER, ComposterRarity.RARE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package thedarkcolour.futuremc.block.villagepillage

// inlined because there's no reason for an actual enum aha
inline class ComposterRarity(val chance: Byte) {
companion object {
val COMMON = ComposterRarity(30)
val UNCOMMON = ComposterRarity(50)
val RARE = ComposterRarity(65)
val EPIC = ComposterRarity(85)
val LEGENDARY = ComposterRarity(100)
}
object ComposterRarity {
val COMMON = 30.toByte()
val UNCOMMON = 50.toByte()
val RARE = 65.toByte()
val EPIC = 85.toByte()
val LEGENDARY = 100.toByte()
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class FSignItem extends ModeledItem {
private final FSignBlock.Wall wall;

public FSignItem(FSignBlock.Standing standing, FSignBlock.Wall wall) {
super();
super(""); // todo

this.standing = standing;
this.wall = wall;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ private static final class AddRecipe implements IAction {
private final IIngredient input;
private final IItemStack output;
private final int duration;
//private final int experience; Seems to not be given to the player

private AddRecipe(IIngredient input, IItemStack output, int duration) {
this.input = input;
Expand All @@ -35,13 +34,7 @@ private AddRecipe(IIngredient input, IItemStack output, int duration) {
public void apply() {
ItemStack output = CraftTweakerMC.getItemStack(this.output);

for (IItemStack item : input.getItems()) {
if (CampfireRecipes.INSTANCE.getRecipe(CraftTweakerMC.getItemStack(input)) != null) {
CraftTweakerAPI.logWarning("Cannot add duplicate recipe for " + input.toCommandString());
} else {
CampfireRecipes.INSTANCE.addRecipe(CraftTweakerMC.getItemStack(item), output, duration);
}
}
CampfireRecipes.INSTANCE.addRecipe(CraftTweakerMC.getIngredient(input), output, duration);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,73 +5,57 @@
import crafttweaker.annotations.ZenRegister;
import crafttweaker.api.item.IIngredient;
import crafttweaker.api.item.IItemStack;
import crafttweaker.api.minecraft.CraftTweakerMC;
import net.minecraft.item.ItemStack;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import thedarkcolour.futuremc.block.villagepillage.ComposterBlock;
import thedarkcolour.futuremc.tile.TileComposter;

import static thedarkcolour.futuremc.compat.crafttweaker.RecipeUtil.applyAction;
import static thedarkcolour.futuremc.compat.crafttweaker.RecipeUtil.toItemStack;

@ZenRegister
@ZenClass("mods.futuremc.Composter")
public final class Composter {
@ZenMethod
public static void addValidItem(IIngredient stack, int rarity) {
applyAction(new Add(stack, rarity, false));
CraftTweakerAPI.apply(new Add(stack, rarity));
}

@ZenMethod
public static void removeValidItem(IIngredient stack) {
applyAction(new Remove(stack));
CraftTweakerAPI.apply(new Remove(stack));
}

@ZenMethod
public static void replaceValidItemChance(IIngredient stack, int newRarity) {
applyAction(new Add(stack, newRarity, true));
CraftTweakerAPI.apply(new Add(stack, newRarity));
}

@ZenMethod
public static void clearValidItems() {
applyAction(new RecipeUtil.NamedAction("Cleared composter recipes", ComposterBlock.ItemsForComposter::clear));
CraftTweakerAPI.apply(new RecipeUtil.NamedAction("Cleared composter recipes", ComposterBlock.ItemsForComposter::clear));
}

private static final class Add implements IAction {
private final IIngredient ingredient;
private final int rarity;
private final boolean replace;
private final byte rarity;

private Add(IIngredient ingredient, int rarity, boolean replace) {
private Add(IIngredient ingredient, int rarity) {
this.ingredient = ingredient;
this.rarity = rarity;
this.replace = replace;
this.rarity = (byte) rarity;
}

@Override
public void apply() {
for (IItemStack item : ingredient.getItems()) {
ItemStack stack = toItemStack(item);
ItemStack stack = CraftTweakerMC.getItemStack(item);

if (TileComposter.isBoneMeal(stack)) {
CraftTweakerAPI.logWarning("Cannot add bone meal as compostable item!");
} else {
if (ComposterBlock.ItemsForComposter.getChance(stack) == -1) {
if (!replace) {
CraftTweakerAPI.logWarning("Failed to add duplicate recipe for item " + item.toCommandString());
continue;
}
} else {
if (replace) {
CraftTweakerAPI.logWarning("Tried change chance for invalid item " + item.toCommandString() +
" If you wish to add a chance to the item, use mods.futuremc.Composter.addValidItem");
continue;
}
}

ComposterBlock.ItemsForComposter.add(stack, rarity);
return;
}
}

ComposterBlock.ItemsForComposter.INSTANCE.add(CraftTweakerMC.getIngredient(ingredient), rarity);
}

@Override
Expand All @@ -90,13 +74,9 @@ private Remove(IIngredient ingredient) {
@Override
public void apply() {
for (IItemStack item : ingredient.getItems()) {
ItemStack stack = toItemStack(item);
ItemStack stack = CraftTweakerMC.getItemStack(item);

if (ComposterBlock.ItemsForComposter.getChance(stack) != -1) {
ComposterBlock.ItemsForComposter.remove(stack);
} else {
CraftTweakerAPI.logWarning("Tried to remove non-existent item from valid composter items: " + item.toCommandString());
}
ComposterBlock.ItemsForComposter.remove(stack);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package thedarkcolour.futuremc.compat.crafttweaker;

import crafttweaker.CraftTweakerAPI;
import crafttweaker.IAction;
import crafttweaker.annotations.ZenRegister;
import crafttweaker.api.item.IIngredient;
import crafttweaker.api.item.IItemStack;
import crafttweaker.api.minecraft.CraftTweakerMC;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import thedarkcolour.futuremc.recipe.smithing.SmithingRecipe;
import thedarkcolour.futuremc.recipe.smithing.SmithingRecipes;

import static thedarkcolour.futuremc.compat.crafttweaker.RecipeUtil.*;

@ZenRegister
@ZenClass("mods.futuremc.SmithingTable")
public final class SmithingTable {
Expand All @@ -25,7 +25,7 @@ public final class SmithingTable {
*/
@ZenMethod
public static void addRecipe(IIngredient input, IIngredient material, IItemStack result) {
applyAction(new AddAction(input, material, result));
CraftTweakerAPI.apply(new AddAction(input, material, result));
}

private static final class AddAction implements IAction {
Expand All @@ -34,9 +34,9 @@ private static final class AddAction implements IAction {
private final ItemStack result;

private AddAction(IIngredient input, IIngredient material, IItemStack result) {
this.input = toIngredient(input);
this.material = toIngredient(material);
this.result = toItemStack(result);
this.input = CraftTweakerMC.getIngredient(input);
this.material = CraftTweakerMC.getIngredient(material);
this.result = CraftTweakerMC.getItemStack(result);
}

@Override
Expand All @@ -58,22 +58,21 @@ public String describe() {
*/
@ZenMethod
public static void removeRecipe(IItemStack input, IItemStack material) {
applyAction(new RemoveAction(input, material));
CraftTweakerAPI.apply(new RemoveAction(input, material));
}

private static final class RemoveAction implements IAction {
private Runnable remove;
private final IItemStack input;
private final IItemStack material;

private RemoveAction(IItemStack input, IItemStack material) {
this.remove = () -> {
SmithingRecipes.INSTANCE.removeRecipe(toItemStack(input), toItemStack(material));
};
this.input = input;
this.material = material;
}

@Override
public void apply() {
remove.run();
remove = null;
SmithingRecipes.INSTANCE.removeRecipe(CraftTweakerMC.getItemStack(input), CraftTweakerMC.getItemStack(material));
}

@Override
Expand Down
Loading

2 comments on commit 1cc86d4

@democat3457
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rip the multiple close didn't work

@thedarkcolour
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah lol

Please sign in to comment.