Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement vibration support #4707

Merged
merged 10 commits into from
Jul 27, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
Expand Down Expand Up @@ -66,6 +67,7 @@ public InteractionResult use(BlockState state, Level world, BlockPos pos, Player

if (plateStack.isEmpty() && plate.acceptsItem(stack)) {
plate.getItemHandler().setItem(0, stack.copy());
world.gameEvent(null, GameEvent.BLOCK_CHANGE, pos);
stack.shrink(1);
did = true;
} else if (!plateStack.isEmpty() && !plate.burning) {
Expand All @@ -75,6 +77,7 @@ public InteractionResult use(BlockState state, Level world, BlockPos pos, Player
} else {
player.getInventory().placeItemBackInInventory(plateStack);
plate.getItemHandler().setItem(0, ItemStack.EMPTY);
world.gameEvent(null, GameEvent.BLOCK_CHANGE, pos);
}
did = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
Expand Down Expand Up @@ -73,6 +74,7 @@ public InteractionResult use(BlockState state, Level world, BlockPos pos, Player
if (!world.isClientSide) {
stack.shrink(1);
relay.setNoParticle();
world.gameEvent(null, GameEvent.BLOCK_CHANGE, pos);
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(relay);
}
return InteractionResult.sidedSuccess(world.isClientSide());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.phys.BlockHitResult;
Expand Down Expand Up @@ -139,6 +140,7 @@ public void handlePrecipitation(BlockState state, Level world, BlockPos pos, Bio
if (world.random.nextInt(20) == 1) {
if (state.getValue(FLUID) == State.EMPTY) {
world.setBlockAndUpdate(pos, state.setValue(FLUID, State.WATER));
world.gameEvent(null, GameEvent.BLOCK_CHANGE, pos);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.gameevent.GameEvent;

import vazkii.botania.common.item.CacophoniumItem;

Expand All @@ -32,6 +33,7 @@ public void annoyDirewolf() {
if (!level.isClientSide) {
float noteColor = level.random.nextInt(25) / 24.0F;
((ServerLevel) level).sendParticles(ParticleTypes.NOTE, worldPosition.getX() + 0.5, worldPosition.getY() + 1.2, worldPosition.getZ() + 0.5, 0, noteColor, 0, 0, 1);
level.gameEvent(null, GameEvent.NOTE_BLOCK_PLAY, getBlockPos());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.AABB;

import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -95,6 +96,7 @@ public static void commonTick(Level level, BlockPos worldPosition, BlockState st
} else {
self.getItemHandler().setItem(0, ItemStack.EMPTY);
self.burning = false;
level.gameEvent(null, GameEvent.BLOCK_DEACTIVATE, worldPosition);
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(self);
}
} else {
Expand Down Expand Up @@ -144,6 +146,7 @@ public void ignite() {
Brew brew = ((IncenseStickItem) BotaniaItems.incenseStick).getBrew(stack);
timeLeft = brew.getPotionEffects(stack).get(0).getDuration() * IncenseStickItem.TIME_MULTIPLIER;
level.playSound(null, getBlockPos(), BotaniaSounds.incensePlateIgnite, SoundSource.BLOCKS, 1F, 1F);
level.gameEvent(null, GameEvent.BLOCK_ACTIVATE, getBlockPos());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;

Expand Down Expand Up @@ -307,10 +308,13 @@ public void tick() {
return;
}

boolean isItem = getVehicle() instanceof ItemEntity;
boolean isItem = getPassengers().stream().allMatch(ItemEntity.class::isInstance);
if (!isItem && tickCount % 30 == 0) {
playSound(BotaniaSounds.lightRelay, 0.25F, (float) Math.random() * 0.3F + 0.7F);
}
if (!isItem && tickCount % 10 == 0) {
gameEvent(GameEvent.ELYTRA_GLIDE);
}

BlockPos pos = blockPosition();
BlockPos exitPos = getExitPos();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.phys.AABB;

Expand Down Expand Up @@ -114,8 +115,9 @@ public boolean collideEntityItem(ItemEntity item) {
XplatAbstractions.INSTANCE.itemFlagsComponent(outputItem).apothecarySpawned = true;
level.addFreshEntity(outputItem);

setFluid(State.EMPTY);
setFluid(State.EMPTY, false);

level.gameEvent(null, GameEvent.BLOCK_ACTIVATE, getBlockPos());
level.blockEvent(getBlockPos(), getBlockState().getBlock(), CRAFT_EFFECT_EVENT, 0);
return true;
}
Expand All @@ -136,6 +138,7 @@ public boolean collideEntityItem(ItemEntity item) {
getItemHandler().setItem(i, stack.split(1));
EntityHelper.syncItem(item);
level.playSound(null, worldPosition, SoundEvents.GENERIC_SPLASH, SoundSource.BLOCKS, 0.1F, 10F);
level.gameEvent(null, GameEvent.BLOCK_CHANGE, getBlockPos());
clearLastRecipe();
return true;
}
Expand Down Expand Up @@ -177,13 +180,16 @@ public InteractionResult trySetLastRecipe(Player player) {
// lastRecipe is not synced. If we're calling this method we already checked that
// the apothecary has water and no items, so just optimistically assume
// success on the client.
boolean success = player.level().isClientSide
|| InventoryHelper.tryToSetLastRecipe(player, getItemHandler(), lastRecipe, SoundEvents.GENERIC_SPLASH);
if (player.level().isClientSide()) {
return InteractionResult.sidedSuccess(true);
}
boolean success = InventoryHelper.tryToSetLastRecipe(player, getItemHandler(), lastRecipe, SoundEvents.GENERIC_SPLASH);
if (success) {
level.gameEvent(null, GameEvent.BLOCK_CHANGE, getBlockPos());
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(this);
}
return success
? InteractionResult.sidedSuccess(player.level().isClientSide())
? InteractionResult.sidedSuccess(false)
: InteractionResult.PASS;
}

Expand Down Expand Up @@ -290,6 +296,13 @@ public int getMaxStackSize() {

@Override
public void setFluid(State fluid) {
setFluid(fluid, true);
}

public void setFluid(State fluid, boolean withVibration) {
if (withVibration) {
level.gameEvent(null, fluid == State.EMPTY ? GameEvent.FLUID_PICKUP : GameEvent.FLUID_PLACE, getBlockPos());
}
level.setBlockAndUpdate(getBlockPos(), getBlockState().setValue(PetalApothecaryBlock.FLUID, fluid));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;

Expand Down Expand Up @@ -115,6 +116,7 @@ public boolean addItem(@Nullable Player player, ItemStack stack, @Nullable Inter
}

if (did) {
level.gameEvent(null, GameEvent.BLOCK_CHANGE, getBlockPos());
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(this);
}

Expand Down Expand Up @@ -238,13 +240,16 @@ private void saveLastRecipe() {
public InteractionResult trySetLastRecipe(Player player) {
// lastRecipe is not synced. If we're calling this method we already checked that
// the altar has no items, so just optimistically assume success on the client.
boolean success = player.level().isClientSide
|| InventoryHelper.tryToSetLastRecipe(player, getItemHandler(), lastRecipe, null);
if (player.level().isClientSide()) {
return InteractionResult.sidedSuccess(true);
}
boolean success = InventoryHelper.tryToSetLastRecipe(player, getItemHandler(), lastRecipe, null);
if (success) {
level.gameEvent(null, GameEvent.BLOCK_CHANGE, getBlockPos());
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(this);
}
return success
? InteractionResult.sidedSuccess(player.level().isClientSide())
? InteractionResult.sidedSuccess(false)
: InteractionResult.PASS;
}

Expand Down Expand Up @@ -283,6 +288,7 @@ public boolean onUsedByWand(@Nullable Player player, ItemStack wand, Direction s
XplatAbstractions.INSTANCE.itemFlagsComponent(outputItem).runicAltarSpawned = true;
level.addFreshEntity(outputItem);
currentRecipe = null;
level.gameEvent(null, GameEvent.BLOCK_ACTIVATE, getBlockPos());
level.blockEvent(getBlockPos(), BotaniaBlocks.runeAltar, SET_COOLDOWN_EVENT, 60);
level.blockEvent(getBlockPos(), BotaniaBlocks.runeAltar, CRAFT_EFFECT_EVENT, 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.minecraft.world.level.block.entity.FurnaceBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.gameevent.GameEvent;

import vazkii.botania.api.internal.VanillaPacketDispatcher;
import vazkii.botania.common.block.block_entity.BotaniaBlockEntities;
Expand Down Expand Up @@ -65,6 +66,9 @@ public static void commonTick(Level level, BlockPos worldPosition, BlockState st

if (self.movePos < max && self.active && self.moving >= 0F) {
if (self.moving == 0F) {
if (!level.isClientSide()) {
level.gameEvent(null, GameEvent.BLOCK_ACTIVATE, worldPosition);
}
level.playSound(null, worldPosition, BotaniaSounds.bellows, SoundSource.BLOCKS, 1F, 1F);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;

Expand Down Expand Up @@ -197,6 +198,7 @@ public void craftingEffect(boolean playSound) {
soundTicks = 6;
}

level.gameEvent(null, GameEvent.BLOCK_ACTIVATE, getBlockPos());
level.blockEvent(getBlockPos(), getBlockState().getBlock(), CRAFT_EFFECT_EVENT, 0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.LevelEvent;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.gameevent.GameEvent;

import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -98,6 +99,7 @@ public void tickFlower() {
if (BotaniaConfig.common().blockBreakParticles()) {
getLevel().levelEvent(LevelEvent.PARTICLES_DESTROY_BLOCK, coords, Block.getId(recipe.getOutputState()));
}
getLevel().gameEvent(null, GameEvent.BLOCK_CHANGE, coords);
getLevel().blockEvent(getBlockPos(), getBlockState().getBlock(), RECIPE_COMPLETE_EVENT, positionAt);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.minecraft.world.level.block.LevelEvent;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.gameevent.GameEvent;

import vazkii.botania.api.block_entity.FunctionalFlowerBlockEntity;
import vazkii.botania.api.block_entity.RadiusDescriptor;
Expand Down Expand Up @@ -55,6 +56,7 @@ public void tickFlower() {
if (BotaniaConfig.common().blockBreakParticles()) {
getLevel().levelEvent(LevelEvent.PARTICLES_DESTROY_BLOCK, coords, stateId);
}
getLevel().gameEvent(null, GameEvent.BLOCK_DESTROY, coords);
ItemEntity item = new ItemEntity(getLevel(), coords.getX() + 0.5, coords.getY() + 0.5, coords.getZ() + 0.5, new ItemStack(Items.CLAY_BALL));
getLevel().addFreshEntity(item);
addMana(-COST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.LevelEvent;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.gameevent.GameEvent;

import vazkii.botania.api.block_entity.FunctionalFlowerBlockEntity;
import vazkii.botania.api.block_entity.RadiusDescriptor;
Expand Down Expand Up @@ -54,6 +55,7 @@ public void tickFlower() {
getLevel().levelEvent(LevelEvent.PARTICLES_DESTROY_BLOCK, up, Block.getId(flower));
}
getLevel().setBlockAndUpdate(up, flower);
getLevel().gameEvent(null, GameEvent.BLOCK_PLACE, up);
addMana(-COST);
sync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.minecraft.world.level.block.LevelEvent;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.Vec3;

import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -96,6 +97,7 @@ private void trySetRecipe(BlockPos coords, @Nullable OrechidRecipe recipe) {
}
playSound(coords);
addMana(-getCost());
getLevel().gameEvent(null, GameEvent.BLOCK_CHANGE, coords);

var serverLevel = (ServerLevel) this.level;
var server = serverLevel.getServer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.AABB;

import vazkii.botania.api.block_entity.GeneratingFlowerBlockEntity;
Expand Down Expand Up @@ -44,7 +45,8 @@ public EndoflameBlockEntity(BlockPos pos, BlockState state) {
public void tickFlower() {
super.tickFlower();

if (burnTime > 0) {
boolean wasBurning = burnTime > 0;
if (wasBurning) {
burnTime--;
}

Expand Down Expand Up @@ -76,13 +78,17 @@ public void tickFlower() {
EntityHelper.shrinkItem(item);
getLevel().playSound(null, getEffectivePos(), BotaniaSounds.endoflame, SoundSource.BLOCKS, 1F, 1F);
getLevel().blockEvent(getBlockPos(), getBlockState().getBlock(), START_BURN_EVENT, item.getId());
getLevel().gameEvent(null, GameEvent.BLOCK_ACTIVATE, getBlockPos());
sync();

return;
}
}
}
}
if (wasBurning) {
getLevel().gameEvent(null, GameEvent.BLOCK_DEACTIVATE, getBlockPos());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.minecraft.world.level.block.BucketPickup;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.FluidState;

Expand Down Expand Up @@ -92,11 +93,13 @@ public void tickFlower() {
} else {
getLevel().setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
}
getLevel().gameEvent(null, GameEvent.FLUID_PICKUP, pos);
}
}

if (cooldown == 0) {
burnTime += startBurnTime;
getLevel().gameEvent(null, GameEvent.BLOCK_ACTIVATE, getBlockPos());
} else {
cooldown = getCooldownTime(false);
}
Expand All @@ -115,6 +118,7 @@ public void tickFlower() {
burnTime--;
if (burnTime == 0) {
cooldown = getCooldownTime(true);
getLevel().gameEvent(null, GameEvent.BLOCK_DEACTIVATE, getBlockPos());
setChanged();
sync();
}
Expand Down
Loading