Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into feature/TagAPITypeS…
Browse files Browse the repository at this point in the history
…afety
  • Loading branch information
quiqueck committed Jan 17, 2022
2 parents b0f6dd6 + 611fb4d commit 7533858
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 9 deletions.
14 changes: 10 additions & 4 deletions src/main/java/ru/bclib/api/biomes/BiomeAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,10 @@ public static void registerBiomeSource(BiomeSource source){
public static void registerWorldData(WorldData w){
worldData = w;
if (worldData!=null){

worldData.worldGenSettings().dimensions().forEach(dim->{
StructureSettingsAccessor a = (StructureSettingsAccessor)dim.generator().getSettings();
STRUCTURE_STARTS.entrySet().forEach(entry -> applyStructureStarts(a, entry.getValue()));
});

}
}

Expand Down Expand Up @@ -542,6 +540,7 @@ else if (level.dimension() == Level.END) {
List<BiConsumer<ResourceLocation, Biome>> modifications = MODIFICATIONS.get(level.dimension());
if (modifications == null) {
biomes.forEach(biome -> sortBiomeFeatures(biome));
((BiomeSourceAccessor) source).bclRebuildFeatures();
return;
}

Expand Down Expand Up @@ -898,8 +897,15 @@ private static void registerNoiseGeneratorAndChangeSurfaceRules(NoiseGeneratorSe
public static void registerStructureEvents(){
DynamicRegistrySetupCallback.EVENT.register(registryManager -> {
Optional<? extends Registry<NoiseGeneratorSettings>> oGeneratorRegistry = registryManager.registry(Registry.NOISE_GENERATOR_SETTINGS_REGISTRY);
Optional<? extends Registry<Codec<? extends BiomeSource>>> oBiomeSourceRegistry = registryManager.registry(Registry.BIOME_SOURCE_REGISTRY);

// Optional<? extends Registry<Codec<? extends BiomeSource>>> oBiomeSourceRegistry = registryManager.registry(Registry.BIOME_SOURCE_REGISTRY);
//
// if (oBiomeSourceRegistry.isPresent()) {
// RegistryEntryAddedCallback
// .event(oBiomeSourceRegistry.get())
// .register((rawId, id, source) -> {
// BCLib.LOGGER.info(" #### " + rawId + ", " + source + ", " + id);
// });
// }

if (oGeneratorRegistry.isPresent()) {
oGeneratorRegistry.get().forEach(BiomeAPI::registerNoiseGeneratorAndChangeSurfaceRules);
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/ru/bclib/blocks/BaseLeavesBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import ru.bclib.interfaces.BlockModelProvider;
import ru.bclib.interfaces.RenderLayerProvider;
import ru.bclib.interfaces.TagProvider;
import ru.bclib.items.tool.BaseShearsItem;
import ru.bclib.util.MHelper;

import java.util.Collections;
Expand All @@ -31,12 +32,12 @@

public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider, RenderLayerProvider, TagProvider {
protected final Block sapling;

private static FabricBlockSettings makeLeaves(MaterialColor color) {
return FabricBlockSettings
.copyOf(Blocks.OAK_LEAVES)
.mapColor(color)
.requiresTool()
//.requiresTool()
.allowsSpawning((state, world, pos, type) -> false)
.suffocates((state, world, pos) -> false)
.blockVision((state, world, pos) -> false);
Expand Down Expand Up @@ -72,7 +73,7 @@ public BCLRenderLayer getRenderLayer() {
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null) {
if (tool.isCorrectToolForDrops(state) || EnchantmentHelper.getItemEnchantmentLevel(
if (BaseShearsItem.isShear(tool) || EnchantmentHelper.getItemEnchantmentLevel(
Enchantments.SILK_TOUCH,
tool
) > 0) {
Expand All @@ -95,7 +96,7 @@ public BlockModel getItemModel(ResourceLocation resourceLocation) {
@Override
public void addTags(List<Named<Block>> blockTags, List<Named<Item>> itemTags) {
blockTags.add(FabricMineableTags.SHEARS_MINEABLE);
blockTags.add(TagAPI.MINEABLE_HOE);
//blockTags.add(TagAPI.MINEABLE_HOE);
blockTags.add(BlockTags.LEAVES);
}
}
6 changes: 5 additions & 1 deletion src/main/java/ru/bclib/items/tool/BaseShearsItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ public class BaseShearsItem extends ShearsItem {
public BaseShearsItem(Properties properties) {
super(properties);
}


public static boolean isShear(ItemStack tool){
return tool.is(Items.SHEARS) | tool.is(TagAPI.ITEM_COMMON_SHEARS) || tool.is(TagAPI.ITEM_SHEARS);
}

public static boolean isShear(ItemStack itemStack, Item item){
if (item == Items.SHEARS){
return itemStack.is(item) | itemStack.is(TagAPI.ITEM_COMMON_SHEARS) || itemStack.is(TagAPI.ITEM_SHEARS);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package ru.bclib.mixin.common.shears;

import net.minecraft.advancements.critereon.ItemPredicate;
import net.minecraft.advancements.critereon.ItemPredicate.Builder;
import net.minecraft.tags.Tag;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.ItemLike;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import ru.bclib.api.TagAPI;

import java.util.Set;

@Mixin(ItemPredicate.class)
public abstract class ItemPredicateBuilderMixin {

@Shadow @Final private @Nullable Set<Item> items;

@Inject(method = "matches", at = @At("HEAD"), cancellable = true)
void bclib_of(ItemStack itemStack, CallbackInfoReturnable<Boolean> cir) {
if (this.items != null && this.items.size() == 1 && this.items.contains(Items.SHEARS)) {
if (itemStack.is(TagAPI.ITEM_COMMON_SHEARS) || itemStack.is(TagAPI.ITEM_SHEARS)){
cir.setReturnValue(true);
}
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/bclib.mixins.common.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"SimpleReloadableResourceManagerMixin",
"BiomeGenerationSettingsAccessor",
"shears.DiggingEnchantmentMixin",
"shears.ItemPredicateBuilderMixin",
"LayerLightSectionStorageMixin",
"NoiseBasedChunkGeneratorMixin",
"NoiseGeneratorSettingsMixin",
Expand Down

0 comments on commit 7533858

Please sign in to comment.