use of net.minecraftforge.eventbus.api.SubscribeEvent in project Tropicraft by Tropicraft.
the class BongoDrumBlock method onBlockLeftClick.
@SubscribeEvent
public static void onBlockLeftClick(PlayerInteractEvent.LeftClickBlock event) {
final Level world = event.getWorld();
final BlockState state = world.getBlockState(event.getPos());
final Block block = state.getBlock();
if (state.getBlock() instanceof BongoDrumBlock && event.getFace() == Direction.UP) {
((BongoDrumBlock) block).playBongoSound(world, event.getPos(), state);
}
}
use of net.minecraftforge.eventbus.api.SubscribeEvent in project Tropicraft by Tropicraft.
the class JigarbovTorchPlacement method onPlaceBlock.
@SubscribeEvent
public static void onPlaceBlock(BlockEvent.EntityPlaceEvent event) {
BlockState placedState = event.getPlacedBlock();
Block placedBlock = placedState.getBlock();
if (placedBlock == Blocks.REDSTONE_WALL_TORCH) {
RegistryObject<RedstoneWallTorchBlock> jigarbovTorchBlock = getJigarbovTorchFor(event.getPlacedAgainst().getBlock());
if (jigarbovTorchBlock != null) {
BlockState jigarbovTorch = jigarbovTorchBlock.get().defaultBlockState();
jigarbovTorch = copyPropertiesTo(jigarbovTorch, placedState);
event.getWorld().setBlock(event.getPos(), jigarbovTorch, Block.UPDATE_ALL);
}
}
}
use of net.minecraftforge.eventbus.api.SubscribeEvent in project Tropicraft by Tropicraft.
the class ScubaData method onPlayerTick.
@SubscribeEvent
public static void onPlayerTick(PlayerTickEvent event) {
Level world = event.player.level;
if (event.phase == Phase.END) {
// TODO support more than chest slot?
ItemStack chestStack = event.player.getItemBySlot(EquipmentSlot.CHEST);
Item chestItem = chestStack.getItem();
if (chestItem instanceof ScubaArmorItem) {
LazyOptional<ScubaData> data = event.player.getCapability(CAPABILITY);
if (!world.isClientSide) {
underwaterPlayers.add((ServerPlayer) event.player);
}
if (isUnderWater(event.player)) {
data.ifPresent(d -> {
d.tick(event.player);
if (!world.isClientSide) {
d.updateClient((ServerPlayer) event.player, false);
}
});
((ScubaArmorItem) chestItem).tickAir(event.player, EquipmentSlot.CHEST, chestStack);
if (!world.isClientSide && world.getGameTime() % 60 == 0) {
// TODO this effect could be better, custom packet?
Vec3 eyePos = event.player.getEyePosition(0);
Vec3 motion = event.player.getDeltaMovement();
Vec3 particlePos = eyePos.add(motion.reverse());
((ServerLevel) world).sendParticles(ParticleTypes.BUBBLE, particlePos.x(), particlePos.y(), particlePos.z(), 4 + world.random.nextInt(3), 0.25, 0.25, 0.25, motion.length());
}
} else if (!world.isClientSide && underwaterPlayers.remove(event.player)) {
// Update client state as they leave the water
data.ifPresent(d -> d.updateClient((ServerPlayer) event.player, false));
}
}
}
}
use of net.minecraftforge.eventbus.api.SubscribeEvent in project MC-Prefab by Brian-Wuest.
the class StructureEventHandler method onServerTick.
/**
* This event is primarily used to build 100 blocks for any queued structures for all players.
*
* @param event The event object.
*/
@SubscribeEvent
public static void onServerTick(ServerTickEvent event) {
if (event.phase == TickEvent.Phase.START) {
ArrayList<Player> playersToRemove = new ArrayList<>();
if (StructureEventHandler.entitiesToGenerate.size() > 0) {
StructureEventHandler.ticksSinceLastEntitiesGenerated++;
if (StructureEventHandler.ticksSinceLastEntitiesGenerated > 40) {
// Process any entities.
StructureEventHandler.processStructureEntities();
StructureEventHandler.ticksSinceLastEntitiesGenerated = 0;
}
}
if (StructureEventHandler.structuresToBuild.size() > 0) {
for (Entry<Player, ArrayList<Structure>> entry : StructureEventHandler.structuresToBuild.entrySet()) {
ArrayList<Structure> structuresToRemove = new ArrayList<>();
// Build the first 100 blocks of each structure for this player.
for (Structure structure : entry.getValue()) {
if (!structure.entitiesRemoved) {
// If there is a player there...they will probably die anyways.....
for (BlockPos clearedPos : structure.clearedBlockPos) {
AABB axisPos = Shapes.block().bounds().move(clearedPos);
List<Entity> list = structure.world.getEntities(null, axisPos);
if (!list.isEmpty()) {
for (Entity entity : list) {
// Don't kill living entities.
if (!(entity instanceof LivingEntity)) {
if (entity instanceof HangingEntity) {
structure.BeforeHangingEntityRemoved((HangingEntity) entity);
}
structure.world.removeEntity(entity, false);
}
}
}
}
structure.entitiesRemoved = true;
}
if (structure.airBlocks.size() > 0) {
structure.hasAirBlocks = true;
}
for (int i = 0; i < 10; i++) {
i = StructureEventHandler.setBlock(i, structure, structuresToRemove);
}
// After building the blocks for this tick, find waterlogged blocks and remove them.
StructureEventHandler.removeWaterLogging(structure);
}
// Update the list of structures to remove this structure since it's done building.
StructureEventHandler.removeStructuresFromList(structuresToRemove, entry);
if (entry.getValue().size() == 0) {
playersToRemove.add(entry.getKey());
}
}
}
// Remove each player that has their structure's built.
for (Player player : playersToRemove) {
StructureEventHandler.structuresToBuild.remove(player);
}
}
}
use of net.minecraftforge.eventbus.api.SubscribeEvent in project MC-Prefab by Brian-Wuest.
the class StructureEventHandler method onClone.
/**
* This occurs when a player dies and is used to make sure that a player does not get a duplicate starting house.
*
* @param event The player clone event.
*/
@SubscribeEvent
public static void onClone(PlayerEvent.Clone event) {
if (event.getPlayer() instanceof ServerPlayer) {
// Don't add the tag unless the house item was added. This way it can be added if the feature is turned on.
// When the player is cloned, make sure to copy the tag. If this is not done the item can be given to the
// player again if they die before the log out and log back in.
CompoundTag originalTag = event.getOriginal().getPersistentData();
// Use the server configuration to determine if the house should be added for this player.
String startingItem = CommonProxy.proxyConfiguration.serverConfiguration.startingItem;
if (startingItem != null && !startingItem.equalsIgnoreCase("Nothing")) {
if (originalTag.contains(EntityPlayerConfiguration.PLAYER_ENTITY_TAG)) {
CompoundTag newPlayerTag = event.getPlayer().getPersistentData();
newPlayerTag.put(EntityPlayerConfiguration.PLAYER_ENTITY_TAG, originalTag.get(EntityPlayerConfiguration.PLAYER_ENTITY_TAG));
// Send the persist tag to the client.
Prefab.network.sendTo(new PlayerEntityTagMessage(originalTag.getCompound(EntityPlayerConfiguration.PLAYER_ENTITY_TAG)), ((ServerPlayer) event.getPlayer()).connection.connection, NetworkDirection.PLAY_TO_CLIENT);
}
}
}
}
Aggregations