-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
960 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/main/generated/data/minecraft/tags/block/beacon_base_blocks.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"values": [ | ||
"vanilla-addition:steel_block" | ||
"vanilla-addition:steel_block", | ||
"vanilla-addition:light_beacon_base" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/generated/data/vanilla-addition/loot_table/blocks/light_beacon_base.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"type": "minecraft:block", | ||
"pools": [ | ||
{ | ||
"bonus_rolls": 0.0, | ||
"conditions": [ | ||
{ | ||
"condition": "minecraft:survives_explosion" | ||
} | ||
], | ||
"entries": [ | ||
{ | ||
"type": "minecraft:item", | ||
"name": "vanilla-addition:light_beacon_base" | ||
} | ||
], | ||
"rolls": 1.0 | ||
} | ||
] | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/generated/data/vanilla-addition/loot_table/blocks/portable_beacon_base.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"type": "minecraft:block", | ||
"pools": [ | ||
{ | ||
"bonus_rolls": 0.0, | ||
"conditions": [ | ||
{ | ||
"condition": "minecraft:match_tool", | ||
"predicate": { | ||
"predicates": { | ||
"minecraft:enchantments": [ | ||
{ | ||
"enchantments": "minecraft:silk_touch", | ||
"levels": { | ||
"min": 1 | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
], | ||
"entries": [ | ||
{ | ||
"type": "minecraft:item", | ||
"name": "minecraft:beacon" | ||
} | ||
], | ||
"rolls": 1.0 | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
src/main/java/com/yipkei/vanilladdition/block/EnderTntBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package com.yipkei.vanilladdition.block; | ||
|
||
import com.mojang.serialization.MapCodec; | ||
import com.yipkei.vanilladdition.entity.EnderTntEntity; | ||
import net.minecraft.block.*; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.entity.projectile.ProjectileEntity; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemPlacementContext; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.registry.tag.ItemTags; | ||
import net.minecraft.sound.SoundCategory; | ||
import net.minecraft.sound.SoundEvents; | ||
import net.minecraft.stat.Stats; | ||
import net.minecraft.state.StateManager; | ||
import net.minecraft.state.property.BooleanProperty; | ||
import net.minecraft.state.property.Properties; | ||
import net.minecraft.util.BlockMirror; | ||
import net.minecraft.util.BlockRotation; | ||
import net.minecraft.util.Hand; | ||
import net.minecraft.util.ItemActionResult; | ||
import net.minecraft.util.hit.BlockHitResult; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.world.World; | ||
import net.minecraft.world.event.GameEvent; | ||
import net.minecraft.world.explosion.Explosion; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class EnderTntBlock extends FacingBlock { | ||
public static final MapCodec<EnderTntBlock> CODEC = EnderTntBlock.createCodec(EnderTntBlock::new); | ||
public static final BooleanProperty UNSTABLE = Properties.UNSTABLE; | ||
|
||
@Override | ||
protected MapCodec<EnderTntBlock> getCodec() { return CODEC; } | ||
|
||
public EnderTntBlock(Settings settings) { | ||
super(settings); | ||
this.setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.SOUTH).with(UNSTABLE,false)); | ||
} | ||
|
||
@Override | ||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder){ | ||
builder.add(FACING, UNSTABLE); | ||
} | ||
|
||
@Override | ||
protected BlockState rotate(BlockState state, BlockRotation rotation) { | ||
return state.with(FACING, rotation.rotate(state.get(FACING))); | ||
} | ||
|
||
@Override | ||
protected BlockState mirror(BlockState state, BlockMirror mirror) { | ||
return state.rotate(mirror.getRotation(state.get(FACING))); | ||
} | ||
|
||
@Override | ||
public BlockState getPlacementState(ItemPlacementContext ctx) { | ||
return this.getDefaultState().with(FACING, ctx.getPlayerLookDirection().getOpposite().getOpposite()); | ||
} | ||
|
||
@Override | ||
protected void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify) { | ||
if (oldState.isOf(state.getBlock())) { | ||
return; | ||
} | ||
if (world.isReceivingRedstonePower(pos)) { | ||
primeEnderTNT(world, pos, state.get(FACING)); | ||
world.removeBlock(pos, false); | ||
} | ||
} | ||
|
||
|
||
@Override | ||
protected void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify){ | ||
if (world.isReceivingRedstonePower(pos)) { | ||
primeEnderTNT(world, pos, state.get(FACING)); | ||
world.removeBlock(pos, false); | ||
} | ||
} | ||
|
||
@Override | ||
public BlockState onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) { | ||
if (!world.isClient() && !player.isCreative() && state.get(UNSTABLE)) { | ||
primeEnderTNT(world, pos, state.get(FACING)); | ||
} | ||
return super.onBreak(world, pos, state, player); | ||
} | ||
|
||
public static void primeEnderTNT(World world, BlockPos pos, Direction facing){ | ||
primeEnderTNT(world, pos, facing, null); | ||
} | ||
|
||
private static void primeEnderTNT(World world, BlockPos pos, Direction facing, @Nullable LivingEntity igniter){ | ||
if (world.isClient) { | ||
return; | ||
} | ||
EnderTntEntity enderTntEntity = new EnderTntEntity(world, pos.getX()+0.5, pos.getY(), pos.getZ()+0.5, igniter, facing); | ||
world.spawnEntity(enderTntEntity); | ||
world.playSound(null, enderTntEntity.getX(), enderTntEntity.getY(), enderTntEntity.getZ(), SoundEvents.ENTITY_TNT_PRIMED, SoundCategory.BLOCKS, 1.0f, 1.0f); | ||
world.emitGameEvent(igniter, GameEvent.PRIME_FUSE, pos); | ||
} | ||
|
||
@Override | ||
protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit){ | ||
if (!stack.isIn(ItemTags.CREEPER_IGNITERS)){ | ||
return super.onUseWithItem(stack, state, world, pos, player, hand, hit); | ||
} | ||
primeEnderTNT(world, pos, state.get(FACING), player); | ||
world.setBlockState(pos, Blocks.AIR.getDefaultState(), Block.NOTIFY_ALL_AND_REDRAW); | ||
Item item = stack.getItem(); | ||
if (stack.isIn(ItemTags.CREEPER_IGNITERS) && !stack.isOf(Items.FIRE_CHARGE)){ | ||
stack.damage(1, player, LivingEntity.getSlotForHand(hand)); | ||
}else { | ||
stack.decrementUnlessCreative(1, player); | ||
} | ||
player.incrementStat(Stats.USED.getOrCreateStat(item)); | ||
return ItemActionResult.success(world.isClient); | ||
} | ||
|
||
@Override | ||
protected void onProjectileHit(World world, BlockState state, BlockHitResult hit, ProjectileEntity projectile){ | ||
if (!world.isClient) { | ||
BlockPos blockPos = hit.getBlockPos(); | ||
Entity entity = projectile.getOwner(); | ||
if (projectile.isOnFire() && projectile.canModifyAt(world, blockPos)) { | ||
primeEnderTNT(world, blockPos, state.get(FACING), entity instanceof LivingEntity ? (LivingEntity)entity : null); | ||
world.removeBlock(blockPos, false); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public boolean shouldDropItemsOnExplosion(Explosion explosion) { | ||
return false; | ||
} | ||
|
||
} |
112 changes: 112 additions & 0 deletions
112
src/main/java/com/yipkei/vanilladdition/block/SmitherBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package com.yipkei.vanilladdition.block; | ||
|
||
import com.mojang.serialization.MapCodec; | ||
import com.yipkei.vanilladdition.block.entity.SmitherBlockEntity; | ||
import net.minecraft.block.AbstractBlock; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.BlockWithEntity; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.block.enums.Orientation; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.item.ItemPlacementContext; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.recipe.RecipeEntry; | ||
import net.minecraft.recipe.SmithingRecipe; | ||
import net.minecraft.recipe.input.SmithingRecipeInput; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.state.property.BooleanProperty; | ||
import net.minecraft.state.property.EnumProperty; | ||
import net.minecraft.state.property.Properties; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.util.math.random.Random; | ||
import net.minecraft.world.World; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Optional; | ||
|
||
public class SmitherBlock extends BlockWithEntity { | ||
|
||
public static final MapCodec<SmitherBlock> CODEC = SmitherBlock.createCodec(SmitherBlock::new); | ||
public static final BooleanProperty SMITHING = Properties.CRAFTING; | ||
public static final BooleanProperty TRIGGERED = Properties.TRIGGERED; | ||
private static final EnumProperty<Orientation> ORIENTATION = Properties.ORIENTATION; | ||
|
||
private static final int TRIGGER_DELAY = 4; | ||
|
||
public SmitherBlock(AbstractBlock.Settings settings) { | ||
super(settings); | ||
this.setDefaultState(this.stateManager.getDefaultState().with(ORIENTATION, Orientation.NORTH_UP).with(TRIGGERED, false).with(SMITHING, false)); | ||
} | ||
|
||
protected MapCodec<SmitherBlock> getCodec(){ return CODEC; } | ||
|
||
@Override | ||
protected boolean hasComparatorOutput(BlockState state) { return true; } | ||
|
||
private void setTriggered(@Nullable BlockEntity blockEntity, boolean triggered) { | ||
if (blockEntity instanceof SmitherBlockEntity smitherBlockEntity) { | ||
smitherBlockEntity.setTriggered(triggered); | ||
} | ||
} | ||
|
||
@Override | ||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { | ||
SmitherBlockEntity smitherBlockEntity = new SmitherBlockEntity(pos, state); | ||
smitherBlockEntity.setTriggered(state.contains(TRIGGERED) && state.get(TRIGGERED)); | ||
return smitherBlockEntity; | ||
} | ||
|
||
@Override | ||
public BlockState getPlacementState(ItemPlacementContext ctx) { | ||
Direction direction = ctx.getPlayerLookDirection().getOpposite(); | ||
Direction direction2 = switch (direction) { | ||
default -> throw new MatchException(null, null); | ||
case UP -> ctx.getHorizontalPlayerFacing(); | ||
case DOWN -> ctx.getHorizontalPlayerFacing().getOpposite(); | ||
case EAST, SOUTH, WEST, NORTH -> Direction.UP; | ||
}; | ||
return this.getDefaultState().with(ORIENTATION, Orientation.byDirections(direction, direction2)).with(TRIGGERED, ctx.getWorld().isReceivingRedstonePower(ctx.getBlockPos())); | ||
} | ||
|
||
@Override | ||
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) { | ||
if (state.get(TRIGGERED)) { | ||
world.scheduleBlockTick(pos, this, TRIGGER_DELAY); | ||
} | ||
} | ||
|
||
@Override | ||
protected void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) { | ||
boolean bl = world.isReceivingRedstonePower(pos); | ||
boolean bl2 = state.get(TRIGGERED); | ||
BlockEntity blockEntity = world.getBlockEntity(pos); | ||
if (bl && !bl2) { | ||
world.scheduleBlockTick(pos, this, TRIGGER_DELAY); | ||
world.setBlockState(pos, state.with(TRIGGERED, true), Block.NOTIFY_LISTENERS); | ||
this.setTriggered(blockEntity, true); | ||
} else if (!bl && bl2) { | ||
while (world.setBlockState(pos, state.with(TRIGGERED, false).with(SMITHING, false), Block.NOTIFY_LISTENERS)); | ||
this.setTriggered(blockEntity, false); | ||
} | ||
} | ||
|
||
@Override | ||
protected void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random){ | ||
this.smith(state, world, pos); | ||
} | ||
|
||
protected void smith(BlockState state, ServerWorld world, BlockPos pos) { | ||
BlockEntity blockEntity = world.getBlockEntity(pos); | ||
if (!(blockEntity instanceof SmitherBlockEntity smitherBlockEntity)) return; | ||
SmithingRecipeInput smithingRecipeInput = new SmithingRecipeInput(((SmitherBlockEntity) blockEntity).getStack(0), ((SmitherBlockEntity) blockEntity).getStack(1), ((SmitherBlockEntity) blockEntity).getStack(2)); | ||
Optional<RecipeEntry<SmithingRecipe>> optional = SmitherBlock.getSmithingRecipe(world, smithingRecipeInput); | ||
} | ||
|
||
public static Optional<RecipeEntry<SmithingRecipe>> getSmithingRecipe(World world, SmithingRecipeInput input) { | ||
if (input.isEmpty()) return Optional.empty(); | ||
|
||
return null; | ||
} | ||
} |
Oops, something went wrong.