Skip to content

Commit

Permalink
Fix Aether ores not dropping XP
Browse files Browse the repository at this point in the history
Fix #93
  • Loading branch information
kalucky0 committed Mar 3, 2021
1 parent 62a2ff1 commit b294f70
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/aether/blocks/AetherBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,12 @@ public class AetherBlocks {
AETHER_FERN = register("aether_fern", new AetherBrushBlock(GRASS), buildingBlock());
POTTED_AETHER_FERN = register("potted_aether_fern", createPottedBlock(AETHER_FERN));
AETHER_BUSH = register("aether_bush", new AetherBrushBlock(GRASS), buildingBlock());
AMBROSIUM_ORE = register("ambrosium_ore", new Block(AbstractBlock.Settings.of(Material.STONE).requiresTool().strength(3.0F, 3.0F)), buildingBlock());
AMBROSIUM_ORE = register("ambrosium_ore", new OreBlock(AbstractBlock.Settings.of(Material.STONE).requiresTool().strength(3.0F, 3.0F)), buildingBlock());
BLUE_PORTAL = register("blue_portal", new AetherPortalBlock(AbstractBlock.Settings.of(Material.PORTAL, MaterialColor.BLUE).nonOpaque().noCollision().ticksRandomly().dropsNothing().blockVision(AetherBlocks::never).strength(-1.0f).sounds(BlockSoundGroup.GLASS).luminance((state) -> 11)));
HOLYSTONE = register("holystone", new Block(FabricBlockSettings.of(Material.STONE, MaterialColor.GRAY).strength(0.5f, 10.0f).sounds(BlockSoundGroup.STONE)), buildingBlock());
HOLYSTONE_BRICK = register("holystone_brick", new Block(FabricBlockSettings.of(Material.STONE).requiresTool().strength(1.5F, 6.0F).materialColor(MaterialColor.WHITE)), buildingBlock());
MOSSY_HOLYSTONE = register("mossy_holystone", new Block(FabricBlockSettings.of(Material.STONE).requiresTool().strength(2.0F, 6.0F).materialColor(MaterialColor.WHITE)), buildingBlock());
ZANITE_ORE = register("zanite_ore", new Block(FabricBlockSettings.of(Material.STONE).requiresTool().strength(3.0F, 3.0F)), buildingBlock());
ZANITE_ORE = register("zanite_ore", new OreBlock(FabricBlockSettings.of(Material.STONE).requiresTool().strength(3.0F, 3.0F)), buildingBlock());
AEROGEL = register("aerogel", new Block(FabricBlockSettings.of(Material.SOIL).strength(1.0f, 2000.0f).sounds(BlockSoundGroup.GLASS).solidBlock(AetherBlocks::never).nonOpaque()), buildingBlock());
AEROGEL_SLAB = register("aerogel_slab", new AetherSlabBlock(AEROGEL.getDefaultState()), buildingBlock());
AEROGEL_STAIRS = register("aerogel_stairs", new AetherStairsBlock(AEROGEL.getDefaultState()), buildingBlock());
Expand Down
24 changes: 17 additions & 7 deletions src/main/java/com/aether/blocks/FloatingBlock.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
package com.aether.blocks;

import com.aether.entities.block.FloatingBlockEntity;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.BlockState;
import net.minecraft.block.FallingBlock;
import net.minecraft.block.Material;
import net.minecraft.block.OreBlock;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.tag.BlockTags;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;

import java.util.Random;

public class FloatingBlock extends FallingBlock {
@SuppressWarnings("deprecation")
public class FloatingBlock extends OreBlock {
private final boolean powered;

public FloatingBlock(boolean powered, FabricBlockSettings properties) {
super(properties);
this.powered = powered;
}

@Override
public void onBlockAdded(BlockState state, World worldIn, BlockPos posIn, BlockState oldState, boolean notify) {
worldIn.getBlockTickScheduler().schedule(posIn, this, this.getFallDelay());
}

@Override
public BlockState getStateForNeighborUpdate(BlockState stateIn, Direction facingIn, BlockState facingState, WorldAccess worldIn, BlockPos posIn, BlockPos facingPosIn) {
worldIn.getBlockTickScheduler().schedule(posIn, this, this.getFallDelay());
return super.getStateForNeighborUpdate(stateIn, facingIn, facingState, worldIn, posIn, facingPosIn);
}

@Override
public void scheduledTick(BlockState stateIn, ServerWorld worldIn, BlockPos posIn, Random randIn) {
this.checkFloatable(worldIn, posIn);
}
Expand All @@ -55,13 +58,20 @@ public void onEndFloating(World worldIn, BlockPos posIn, BlockState floatingStat
public void onBroken(World worldIn, BlockPos pos) {
}

@Override
protected int getFallDelay() {
return 2;
}

@Override
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
}

public static boolean canFallThrough(BlockState state) {
Material material = state.getMaterial();
return state.isAir() || state.isIn(BlockTags.FIRE) || material.isLiquid() || material.isReplaceable();
}

@Environment(EnvType.CLIENT)
public int getColor(BlockState state, BlockView world, BlockPos pos) {
return -16777216;
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/aether/mixin/block/OreBlockMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.aether.mixin.block;

import com.aether.blocks.AetherBlocks;
import net.minecraft.block.OreBlock;
import net.minecraft.util.math.MathHelper;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Random;

@SuppressWarnings("ConstantConditions")
@Mixin(OreBlock.class)
public abstract class OreBlockMixin {
//TODO: Tweak the xp values
@Inject(method = "getExperienceWhenMined", at = @At("HEAD"), cancellable = true)
protected void getExperience(Random random, CallbackInfoReturnable<Integer> cir) {
if ((Object) this == AetherBlocks.ZANITE_ORE) {
cir.setReturnValue(MathHelper.nextInt(random, 0, 2));
} else if ((Object) this == AetherBlocks.AMBROSIUM_ORE) {
cir.setReturnValue(MathHelper.nextInt(random, 0, 2));
} else if ((Object) this == AetherBlocks.GRAVITITE_ORE) {
cir.setReturnValue(MathHelper.nextInt(random, 0, 2));
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/the_aether.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"block.AbstractBlockAccessor",
"block.CropBlockMixin",
"block.FarmlandBlockMixin",
"block.OreBlockMixin",
"block.PlantBlockMixin",
"entity.EntityMixin",
"entity.MixinLivingEntity",
Expand Down

0 comments on commit b294f70

Please sign in to comment.