Skip to content

Commit

Permalink
fixed a lot of shit
Browse files Browse the repository at this point in the history
  • Loading branch information
Leclowndu93150 committed Nov 7, 2024
1 parent 6bb14cd commit b54003e
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 44 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
# org.gradle.java.home=C:/Program Files/Java/jdk-17
# TODO: Remove before pushing ^

# Idiot
mod_version=3.8.4

parchment_version=2023.09.03

# Minecraft Version Information
minecraft_base_version=1.20
minecraft_version=1.20.1
Expand All @@ -20,8 +22,6 @@ loader_range=[47,)
loader_version_range=[47,)
mapping_version=1.20.1

parchment_version=2023.09.03

# Build Dependencies
mantle_version=1.11-UnofficialBuild
mantle_range=[1.11,)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package slimeknights.tconstruct.common.config;

import com.google.common.collect.ImmutableList;
import net.minecraft.tags.DamageTypeTags;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraftforge.common.ForgeConfigSpec;
Expand Down Expand Up @@ -79,6 +81,8 @@ public enum LogInvalidToolStack { STACKTRACE, WARNING, IGNORED };
"If true, extends the applicable slots for the fire protection enchantment to work better with shields. Will not impact gameplay with the vanilla enchantment.\nIf false, fire protection on a shield will not reduce fire tick time.",
() -> Enchantments.FIRE_PROTECTION.slots = EquipmentSlot.values()));

/*
TODO: Fix this by adding the DamageTypeTags to the DamageSource
builder.comment("Tweaks to vanilla damage sources to better work with armor").push("damageTweaks");
actions.add(new ConfigurableAction(builder, "wither", true, "Makes withering damage count as magic", DamageSource.WITHER::setMagic));
actions.add(new ConfigurableAction(builder, "dragon_breath", true, "Makes dragons breath count as magic", DamageSource.DRAGON_BREATH::setMagic));
Expand All @@ -88,8 +92,10 @@ public enum LogInvalidToolStack { STACKTRACE, WARNING, IGNORED };
DamageSource.FALLING_STALACTITE.setProjectile();
}));
actions.add(new ConfigurableAction(builder, "lightning", true, "Makes lightning count as fire damage", DamageSource.LIGHTNING_BOLT::setIsFire));
*/
toolTweaks = actions.build();


this.repairKitAmount = builder
.comment("Amount of durability restored by a repair kit in terms of ingots. Does not affect the cost to create the kit, that is controlled by JSON.")
.defineInRange("repairKitAmount", 2f, 0f, Short.MAX_VALUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
import net.minecraft.advancements.critereon.MinMaxBounds;
import net.minecraft.advancements.critereon.StatePropertiesPredicate;
import net.minecraft.core.Registry;
import net.minecraft.data.loot.BlockLoot;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.data.loot.BlockLootSubProvider;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.flag.FeatureFlags;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.Block;
Expand Down Expand Up @@ -53,20 +57,27 @@
import slimeknights.tconstruct.world.block.FoliageType;

import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

public class BlockLootTableProvider extends BlockLoot {
public class BlockLootTableProvider extends BlockLootSubProvider {

protected BlockLootTableProvider(Set<Item> p_249153_, FeatureFlagSet p_251215_) {
super(Collections.emptySet(), FeatureFlags.VANILLA_SET);
}

@Nonnull
@Override
protected Iterable<Block> getKnownBlocks() {
return ForgeRegistries.BLOCKS.getValues().stream()
.filter((block) -> TConstruct.MOD_ID.equals(Registry.BLOCK.getKey(block).getNamespace()))
.filter((block) -> TConstruct.MOD_ID.equals(BuiltInRegistries.BLOCK.getKey(block).getNamespace()))
.collect(Collectors.toList());
}

@Override
protected void addTables() {
protected void generate() {
this.addCommon();
this.addDecorative();
this.addGadgets();
Expand Down Expand Up @@ -314,11 +325,11 @@ private static LootTable.Builder droppingSilkOrShears(Block block, LootPoolEntry
return createSelfDropDispatchTable(block, SILK_TOUCH_OR_SHEARS, alternativeLootEntry);
}

private static LootTable.Builder dropSapling(Block blockIn, Block saplingIn, float... fortuneIn) {
private LootTable.Builder dropSapling(Block blockIn, Block saplingIn, float... fortuneIn) {
return droppingSilkOrShears(blockIn, applyExplosionCondition(blockIn, LootItem.lootTableItem(saplingIn)).when(BonusLevelTableCondition.bonusLevelFlatChance(Enchantments.BLOCK_FORTUNE, fortuneIn)));
}

private static LootTable.Builder randomDropSlimeBallOrSapling(FoliageType foliageType, Block blockIn, Block sapling, float... fortuneIn) {
private LootTable.Builder randomDropSlimeBallOrSapling(FoliageType foliageType, Block blockIn, Block sapling, float... fortuneIn) {
LootTable.Builder builder = dropSapling(blockIn, sapling, fortuneIn);
SlimeType slime = foliageType.asSlime();
if (slime != null) {
Expand All @@ -331,7 +342,7 @@ private static LootTable.Builder randomDropSlimeBallOrSapling(FoliageType foliag
return builder;
}

private static LootTable.Builder droppingWithFunctions(Block block, Function<LootItem.Builder<?>,LootItem.Builder<?>> mapping) {
private LootTable.Builder droppingWithFunctions(Block block, Function<LootItem.Builder<?>, LootItem.Builder<?>> mapping) {
return LootTable.lootTable().withPool(applyExplosionCondition(block, LootPool.lootPool().setRolls(ConstantValue.exactly(1)).add(mapping.apply(LootItem.lootTableItem(block)))));
}

Expand All @@ -341,7 +352,8 @@ private static LootTable.Builder droppingWithFunctions(Block block, Function<Loo
*/
private void registerBuildingLootTables(BuildingBlockObject object) {
this.dropSelf(object.get());
this.add(object.getSlab(), BlockLoot::createSlabItemTable);
// TODO: Find a fix for this
// this.add(object.getSlab(), BlockLootSubProvider::createSlabItemTable);
this.dropSelf(object.getStairs());
}

Expand Down Expand Up @@ -371,18 +383,16 @@ private void registerWoodLootTables(WoodBlockObject object) {
this.dropSelf(object.getStrippedLog());
this.dropSelf(object.getWood());
this.dropSelf(object.getStrippedWood());
// door
this.dropSelf(object.getFenceGate());
this.add(object.getDoor(), BlockLoot::createDoorTable);
// TODO: Find a fix for this
//this.add(object.getDoor(), BlockLootTableProvider::createDoorTable);
this.dropSelf(object.getTrapdoor());
// redstone
this.dropSelf(object.getPressurePlate());
this.dropSelf(object.getButton());
// sign
this.dropSelf(object.getSign());
}

private static Function<Block, LootTable.Builder> ADD_TABLE = block -> droppingWithFunctions(block, (builder) ->
private final Function<Block, LootTable.Builder> ADD_TABLE = block -> droppingWithFunctions(block, (builder) ->
builder.apply(CopyNameFunction.copyName(CopyNameFunction.NameSource.BLOCK_ENTITY)).apply(RetexturedLootFunction::new));

/** Registers a block that drops with its own texture stored in NBT */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import net.minecraft.advancements.critereon.EntityPredicate;
import net.minecraft.advancements.critereon.MinMaxBounds;
import net.minecraft.advancements.critereon.SlimePredicate;
import net.minecraft.data.loot.EntityLoot;
import net.minecraft.data.loot.EntityLootSubProvider;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.storage.loot.LootContext;
Expand All @@ -28,20 +29,24 @@
import slimeknights.tconstruct.world.TinkerWorld;

import java.util.Map.Entry;
import java.util.stream.Stream;

public class EntityLootTableProvider extends EntityLoot {
public class EntityLootTableProvider extends EntityLootSubProvider {

protected EntityLootTableProvider(FeatureFlagSet pEnabledFeatures) {
super(pEnabledFeatures);
}

@Override
protected Iterable<EntityType<?>> getKnownEntities() {
protected Stream<EntityType<?>> getKnownEntityTypes() {
return ForgeRegistries.ENTITY_TYPES.getEntries().stream()
// remove earth slime entity, we redirect to the vanilla loot table
.filter(entry -> TConstruct.MOD_ID.equals(entry.getKey().location().getNamespace()))
.<EntityType<?>>map(Entry::getValue)
.toList();
// remove earth slime entity, we redirect to the vanilla loot table
.filter(entry -> TConstruct.MOD_ID.equals(entry.getKey().location().getNamespace()))
.<EntityType<?>>map(Entry::getValue);
}

@Override
protected void addTables() {
public void generate() {
this.add(TinkerWorld.skySlimeEntity.get(), dropSlimeballs(SlimeType.SKY));
this.add(TinkerWorld.enderSlimeEntity.get(), dropSlimeballs(SlimeType.ENDER));
this.add(TinkerWorld.terracubeEntity.get(),
Expand Down Expand Up @@ -71,11 +76,11 @@ protected void addTables() {

}

private static LootItemCondition.Builder killedByFrog() {
public LootItemCondition.Builder killedByFrog() {
return DamageSourceCondition.hasDamageSource(DamageSourcePredicate.Builder.damageType().source(EntityPredicate.Builder.entity().of(EntityType.FROG)));
}

private static LootTable.Builder dropSlimeballs(SlimeType type) {
private LootTable.Builder dropSlimeballs(SlimeType type) {
LootItemCondition.Builder killedByFrog = killedByFrog();
Item slimeball = TinkerCommons.slimeball.get(type);
return LootTable.lootTable().withPool(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.advancements.critereon.EntityPredicate;
import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.data.DataGenerator;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
Expand Down Expand Up @@ -41,7 +42,7 @@

public class GlobalLootModifiersProvider extends GlobalLootModifierProvider {
public GlobalLootModifiersProvider(DataGenerator gen) {
super(gen, TConstruct.MOD_ID);
super(gen.getPackOutput(), TConstruct.MOD_ID);
}

@Override
Expand Down Expand Up @@ -78,19 +79,19 @@ protected void start() {
addLustrous("cobalt", false);
addLustrous("netherite_scrap", false);
for (SmelteryCompat compat : SmelteryCompat.values()) {
if (compat.isOre()) {
addLustrous(compat.getName(), true);
if (compat.isOre) {
addLustrous(compat.name, true);
}
}
}

/** Adds lustrous for an ore */
private void addLustrous(String name, boolean optional) {
TagKey<Item> nuggets = TagKey.create(Registry.ITEM_REGISTRY, new ResourceLocation("forge", "nuggets/" + name));
TagKey<Item> nuggets = TagKey.create(BuiltInRegistries.ITEM.key(), new ResourceLocation("forge", "nuggets/" + name));
ResourceLocation ores = new ResourceLocation("forge", "ores/" + name);
AddEntryLootModifier.Builder builder = AddEntryLootModifier.builder(TagPreferenceLootEntry.tagPreference(nuggets));
builder.addCondition(new BlockTagLootCondition(TagKey.create(Registry.BLOCK_REGISTRY, ores)))
.addCondition(new ContainsItemModifierLootCondition(Ingredient.of(TagKey.create(Registry.ITEM_REGISTRY, ores))).inverted());
builder.addCondition(new BlockTagLootCondition(TagKey.create(BuiltInRegistries.BLOCK.key(), ores)))
.addCondition(new ContainsItemModifierLootCondition(Ingredient.of(TagKey.create(BuiltInRegistries.ITEM.key(), ores))).inverted());
if (optional) {
builder.addCondition(new TagNotEmptyCondition<>(nuggets));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,51 @@

import com.google.common.collect.ImmutableList;
import com.mojang.datafixers.util.Pair;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.PackOutput;
import net.minecraft.data.loot.LootTableProvider;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.flag.FeatureFlags;
import net.minecraft.world.level.storage.loot.LootTable;
import net.minecraft.world.level.storage.loot.LootTables;
import net.minecraft.world.level.storage.loot.ValidationContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSet;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
import slimeknights.tconstruct.TConstruct;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Supplier;

public class TConstructLootTableProvider extends LootTableProvider {

private LootTableProvider x;
private final List<Pair<Supplier<Consumer<BiConsumer<ResourceLocation, LootTable.Builder>>>, LootContextParamSet>> lootTables = ImmutableList.of(Pair.of(BlockLootTableProvider::new, LootContextParamSets.BLOCK), Pair.of(AdvancementLootTableProvider::new, LootContextParamSets.ADVANCEMENT_REWARD), Pair.of(EntityLootTableProvider::new, LootContextParamSets.ENTITY));

public TConstructLootTableProvider(DataGenerator gen) {
super(gen);
private final List<Pair<Supplier<Consumer<BiConsumer<ResourceLocation, LootTable.Builder>>>, LootContextParamSet>> lootTables = ImmutableList.of(
Pair.of((Supplier<Consumer<BiConsumer<ResourceLocation, LootTable.Builder>>>) new BlockLootTableProvider(Collections.emptySet(), FeatureFlags.VANILLA_SET), LootContextParamSets.BLOCK),
Pair.of((Supplier<Consumer<BiConsumer<ResourceLocation, LootTable.Builder>>>) new AdvancementLootTableProvider(), LootContextParamSets.ADVANCEMENT_REWARD),
Pair.of((Supplier<Consumer<BiConsumer<ResourceLocation, LootTable.Builder>>>) new EntityLootTableProvider(FeatureFlagSet.of()), LootContextParamSets.ENTITY)
);

public TConstructLootTableProvider(PackOutput pOutput, Set<ResourceLocation> pRequiredTables, List<SubProviderEntry> pSubProviders) {
super(pOutput, pRequiredTables, pSubProviders);
}


@Override
protected List<Pair<Supplier<Consumer<BiConsumer<ResourceLocation, LootTable.Builder>>>, LootContextParamSet>> getTables() {
return lootTables;
}

@Override
protected void validate(Map<ResourceLocation,LootTable> map, ValidationContext validationtracker) {
map.forEach((loc, table) -> LootTables.validate(validationtracker, loc, table));
protected void validate(Map<ResourceLocation, LootTable> map, ValidationContext validationtracker) {
map.forEach((loc, table) -> {
LootTable lootTable = map.get(loc);
lootTable.validate(validationtracker);
});
// Remove vanilla's tables, which we also loaded so we can redirect stuff to them.
// This ensures the remaining generator logic doesn't write those to files.
map.keySet().removeIf((loc) -> !loc.getNamespace().equals(TConstruct.MOD_ID));
Expand All @@ -43,8 +55,11 @@ protected void validate(Map<ResourceLocation,LootTable> map, ValidationContext v
/**
* Gets a name for this provider, to use in logging.
*/
// TODO: Fix this
/*
@Override
public String getName() {
return "TConstruct LootTables";
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public class TagNotEmptyCondition<T> implements LootItemCondition, ICondition {
private static final ResourceLocation NAME = TConstruct.getResource("tag_not_empty");
private final TagKey<T> tag;

public TagNotEmptyCondition(TagKey<T> tag) {this.tag = tag;}


@Override
public LootItemConditionType getType() {
return TinkerCommons.lootTagNotEmptyCondition.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ public enum SmelteryCompat {
REFINED_OBSIDIAN (TinkerFluids.moltenRefinedObsidian, false);

@Getter
private final String name = this.name().toLowerCase(Locale.US);
private final FluidObject<? extends ForgeFlowingFluid> fluid;
public final String name = this.name().toLowerCase(Locale.US);
public final FluidObject<? extends ForgeFlowingFluid> fluid;
@Getter
private final boolean isOre;
public final boolean isOre;
@Accessors(fluent = true)
@Getter
private final boolean hasDust;
public final boolean hasDust;
@Getter
private final Byproduct[] byproducts;
public final Byproduct[] byproducts;

SmelteryCompat(FluidObject<? extends ForgeFlowingFluid> fluid, boolean hasDust) {
this.fluid = fluid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
public class HasModifierLootCondition implements LootItemCondition {
private final ModifierId modifier;

public HasModifierLootCondition(ModifierId modifier) {this.modifier = modifier;}

@Override
public LootItemConditionType getType() {
return TinkerModifiers.hasModifierLootCondition.get();
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,8 @@ public-f net.minecraft.world.item.enchantment.Enchantment f_44671_ # slots
# Enderbark
public net.minecraft.world.level.block.MangrovePropaguleBlock f_221444_ # SHAPE_PER_AGE
protected net.minecraft.world.level.levelgen.feature.rootplacers.MangroveRootPlacer f_225814_ # mangroveRootPlacement

# Sticks drop from leaves chances omg mojang
public net.minecraft.data.loot.BlockLootSubProvider f_244531_ # NORMAL_LEAVES_STICK_CHANCES
public net.minecraft.data.loot.BlockLootSubProvider f_244248_ # HAS_NO_SHEARS_OR_SILK_TOUCH
public net.minecraft.data.loot.BlockLootSubProvider m_247233_(Lnet/minecraft/world/level/block/Block;)Lnet/minecraft/world/level/storage/loot/LootTable$Builder; # createSlabItemTable

0 comments on commit b54003e

Please sign in to comment.