Skip to content

Commit

Permalink
Update upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
IzzelAliz committed Nov 19, 2023
1 parent fd650cc commit 14c59f6
Show file tree
Hide file tree
Showing 18 changed files with 465 additions and 27 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ A Bukkit server implementation utilizing Mixin.
|:--------------------:|:------:|:------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
| Net (1.20.2) | 48.0.4 | ACTIVE | [![1.20.2 Status](https://img.shields.io/github/actions/workflow/status/IzzelAliz/Arclight/gradle.yml?branch=Net&style=flat-square)](https://github.com/IzzelAliz/Arclight/actions?query=branch%3ANet) |
| Trials (1.20-1.20.1) | 47.2.0 | LTS | [![1.20.1 Status](https://img.shields.io/github/actions/workflow/status/IzzelAliz/Arclight/gradle.yml?branch=Trials&style=flat-square)](https://github.com/IzzelAliz/Arclight/actions?query=branch%3ATrials) |
| Horn (1.19-1.19.2) | 43.3.2 | LTS | [![Horn Status](https://img.shields.io/appveyor/build/IzzelAliz/arclight-19?style=flat-square)](https://ci.appveyor.com/project/IzzelAliz/arclight-19) |

**Legacy versions**:

Expand All @@ -17,10 +18,9 @@ A Bukkit server implementation utilizing Mixin.
|:-------------------:|:-------:|:----------------------------------------------------------------------------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|
| Executions (1.19.4) | 45.1.0 | LEGACY | [![1.19.4 Status](https://img.shields.io/github/actions/workflow/status/IzzelAliz/Arclight/gradle.yml?branch=Executions&style=flat-square)](https://github.com/IzzelAliz/Arclight/actions?query=branch%3AExecutions) |
| Great Horn (1.19.3) | 44.1.22 | [LEGACY](https://github.com/IzzelAliz/Arclight/releases/tag/GreatHorn/1.0.3) | [![1.19 Status](https://img.shields.io/github/actions/workflow/status/IzzelAliz/Arclight/gradle.yml?branch=GreatHorn&style=flat-square)](https://ci.appveyor.com/project/IzzelAliz/arclight-19) |
| Horn (1.19-1.19.2) | 43.2.11 | [LEGACY](https://github.com/IzzelAliz/Arclight/releases/tag/horn/1.0.2) | [![Horn Status](https://img.shields.io/appveyor/build/IzzelAliz/arclight-19?style=flat-square)](https://ci.appveyor.com/project/IzzelAliz/arclight-19) |
| 1.18.x | 40.1.80 | LEGACY | [![1.18 Status](https://img.shields.io/github/actions/workflow/status/IzzelAliz/Arclight/gradle.yml?branch=1.18&style=flat-square)](https://ci.appveyor.com/project/IzzelAliz/arclight-18) |
| 1.18.x | 40.2.10 | [LEGACY](https://github.com/IzzelAliz/Arclight/releases/tag/1.18%2F1.0.9) | [![1.18 Status](https://img.shields.io/github/actions/workflow/status/IzzelAliz/Arclight/gradle.yml?branch=1.18&style=flat-square)](https://ci.appveyor.com/project/IzzelAliz/arclight-18) |
| 1.17.x | 37.1.0 | [LEGACY](https://github.com/IzzelAliz/Arclight/releases/tag/1.17/1.0.2) | [![1.17 Status](https://img.shields.io/appveyor/build/IzzelAliz/arclight-17?style=flat-square)](https://ci.appveyor.com/project/IzzelAliz/arclight-17) |
| 1.16.x | 36.2.39 | LEGACY | [![1.16 Status](https://img.shields.io/github/actions/workflow/status/IzzelAliz/Arclight/gradle.yml?branch=1.16&style=flat-square)](https://ci.appveyor.com/project/IzzelAliz/arclight-16) |
| 1.16.x | 36.2.39 | [LEGACY](https://github.com/IzzelAliz/Arclight/releases/tag/1.16%2F1.0.25) | [![1.16 Status](https://img.shields.io/github/actions/workflow/status/IzzelAliz/Arclight/gradle.yml?branch=1.16&style=flat-square)](https://ci.appveyor.com/project/IzzelAliz/arclight-16) |
| 1.15.x | 31.2.48 | [LEGACY](https://github.com/IzzelAliz/Arclight/releases/tag/1.15/1.0.19) | [![1.15 Status](https://img.shields.io/appveyor/build/IzzelAliz/arclight-15?style=flat-square)](https://ci.appveyor.com/project/IzzelAliz/arclight-15) |
| 1.14.x | 28.2.0 | [LEGACY](https://github.com/IzzelAliz/Arclight/releases/tag/1.0.6) | [![1.14 Status](https://img.shields.io/appveyor/build/IzzelAliz/arclight?style=flat-square)](https://ci.appveyor.com/project/IzzelAliz/arclight) |

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.izzel.arclight.common.bridge.core.world.level.levelgen;

import org.bukkit.event.world.AsyncStructureGenerateEvent;

public interface StructureStartBridge {

void bridge$setGenerateCause(AsyncStructureGenerateEvent.Cause cause);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.izzel.arclight.common.bridge.core.world.storage.loot;

import org.bukkit.craftbukkit.v.CraftLootTable;

public interface LootTableBridge {

void bridge$setCraftLootTable(CraftLootTable lootTable);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.izzel.arclight.common.mixin.bukkit;

import org.bukkit.NamespacedKey;
import org.bukkit.potion.PotionType;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(PotionType.class)
public class PotionTypeMixin {

@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lorg/bukkit/NamespacedKey;minecraft(Ljava/lang/String;)Lorg/bukkit/NamespacedKey;"))
private NamespacedKey arclight$nsFromString(String key) {
return NamespacedKey.fromString(key);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import net.minecraft.network.protocol.game.ServerboundPlayerAbilitiesPacket;
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
import net.minecraft.network.protocol.game.ServerboundPlayerCommandPacket;
import net.minecraft.network.protocol.game.ServerboundRecipeBookChangeSettingsPacket;
import net.minecraft.network.protocol.game.ServerboundSelectTradePacket;
import net.minecraft.network.protocol.game.ServerboundSetCarriedItemPacket;
import net.minecraft.network.protocol.game.ServerboundSetCreativeModeSlotPacket;
Expand Down Expand Up @@ -1601,6 +1602,11 @@ public void handleContainerClick(ServerboundContainerClickPacket packet) {
}
}

@Inject(method = "handleRecipeBookChangeSettingsPacket", at = @At(value = "INVOKE", target = "Lnet/minecraft/stats/ServerRecipeBook;setBookSetting(Lnet/minecraft/world/inventory/RecipeBookType;ZZ)V"))
private void arclight$recipeBookSettings(ServerboundRecipeBookChangeSettingsPacket packet, CallbackInfo ci) {
CraftEventFactory.callRecipeBookSettingsEvent(this.player, packet.getBookType(), packet.isOpen(), packet.isFiltering());
}

@Redirect(method = "handlePlaceRecipe", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/game/ServerboundPlaceRecipePacket;getRecipe()Lnet/minecraft/resources/ResourceLocation;"))
private ResourceLocation arclight$recipeBookClick(ServerboundPlaceRecipePacket instance) {
var location = instance.getRecipe();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.izzel.arclight.common.mixin.core.server.commands;

import io.izzel.arclight.common.bridge.core.world.level.levelgen.StructureStartBridge;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.server.commands.PlaceCommand;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.levelgen.structure.Structure;
import net.minecraft.world.level.levelgen.structure.StructureStart;
import org.bukkit.event.world.AsyncStructureGenerateEvent;
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 org.spongepowered.asm.mixin.injection.callback.LocalCapture;

@Mixin(PlaceCommand.class)
public class PlaceCommandMixin {

@Inject(method = "placeStructure", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/levelgen/structure/StructureStart;getBoundingBox()Lnet/minecraft/world/level/levelgen/structure/BoundingBox;"))
private static void arclight$cause(CommandSourceStack p_214588_, Holder.Reference<Structure> p_251799_, BlockPos p_214590_, CallbackInfoReturnable<Integer> cir,
ServerLevel level, Structure structure, ChunkGenerator chunkGenerator, StructureStart structureStart) {
((StructureStartBridge) (Object) structureStart).bridge$setGenerateCause(AsyncStructureGenerateEvent.Cause.COMMAND);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void playerTouch(Player playerEntity) {
ItemStack itemstack = this.getPickupItem();
if (this.pickup == net.minecraft.world.entity.projectile.AbstractArrow.Pickup.ALLOWED && !itemstack.isEmpty() && ((PlayerInventoryBridge) playerEntity.getInventory()).bridge$canHold(itemstack) > 0) {
ItemEntity item = new ItemEntity(this.level(), this.getX(), this.getY(), this.getZ(), itemstack);
PlayerPickupArrowEvent event = new PlayerPickupArrowEvent(((ServerPlayerEntityBridge) playerEntity).bridge$getBukkitEntity(), new CraftItem(((CraftServer) Bukkit.getServer()), (net.minecraft.world.entity.projectile.AbstractArrow) (Object) this, item), (AbstractArrow) this.getBukkitEntity());
PlayerPickupArrowEvent event = new PlayerPickupArrowEvent(((ServerPlayerEntityBridge) playerEntity).bridge$getBukkitEntity(), new CraftItem(((CraftServer) Bukkit.getServer()), item), (AbstractArrow) this.getBukkitEntity());
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected void onHit(HitResult result) {
super.onHit(result);
if (!this.level().isClientSide) {
int i = 3 + this.level().random.nextInt(5) + this.level().random.nextInt(5);
ExpBottleEvent event = CraftEventFactory.callExpBottleEvent((ThrownExperienceBottle) (Object) this, i);
ExpBottleEvent event = CraftEventFactory.callExpBottleEvent((ThrownExperienceBottle) (Object) this, result, i);
i = event.getExperience();
if (event.getShowEffect()) {
this.level().levelEvent(2002, this.blockPosition(), PotionUtils.getColor(Potions.WATER));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
import net.minecraft.world.level.block.CampfireBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.HitResult;
import org.bukkit.craftbukkit.v.entity.CraftLivingEntity;
import org.bukkit.craftbukkit.v.event.CraftEventFactory;
import org.bukkit.event.entity.EntityPotionEffectEvent;
import org.bukkit.event.entity.LingeringPotionSplashEvent;
import org.bukkit.event.entity.PotionSplashEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
Expand All @@ -39,11 +41,19 @@
@Mixin(ThrownPotion.class)
public abstract class ThrownPotionMixin extends ThrowableItemProjectileMixin {

@Unique private transient HitResult arclight$hitResult;

@Redirect(method = "onHit", at = @At(value = "INVOKE", remap = false, ordinal = 1, target = "Ljava/util/List;isEmpty()Z"))
private boolean arclight$callEvent(List list) {
private boolean arclight$callEvent(List list, HitResult hitResult) {
arclight$hitResult = hitResult;
return false;
}

@Inject(method = "onHit", at = @At("RETURN"))
private void arclight$resetResult(HitResult p_37543_, CallbackInfo ci) {
arclight$hitResult = null;
}

/**
* @author IzzelAliz
* @reason
Expand All @@ -68,7 +78,7 @@ private void applySplash(List<MobEffectInstance> list, @Nullable Entity entity)
}
}
}
PotionSplashEvent event = CraftEventFactory.callPotionSplashEvent((ThrownPotion) (Object) this, affected);
PotionSplashEvent event = CraftEventFactory.callPotionSplashEvent((ThrownPotion) (Object) this, arclight$hitResult, affected);
if (!event.isCancelled() && list != null && !list.isEmpty()) {
for (org.bukkit.entity.LivingEntity victim : event.getAffectedEntities()) {
if (!(victim instanceof CraftLivingEntity)) {
Expand Down Expand Up @@ -101,7 +111,7 @@ private void applySplash(List<MobEffectInstance> list, @Nullable Entity entity)

@Inject(method = "makeAreaOfEffectCloud", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z"))
private void arclight$makeCloud(ItemStack p_190542_1_, Potion p_190542_2_, CallbackInfo ci, AreaEffectCloud entity) {
LingeringPotionSplashEvent event = CraftEventFactory.callLingeringPotionSplashEvent((ThrownPotion) (Object) this, entity);
LingeringPotionSplashEvent event = CraftEventFactory.callLingeringPotionSplashEvent((ThrownPotion) (Object) this, arclight$hitResult, entity);
if (event.isCancelled() || entity.isRemoved()) {
ci.cancel();
entity.discard();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package io.izzel.arclight.common.mixin.core.world.level.levelgen.structure;

import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.StructurePiece;
import org.bukkit.craftbukkit.v.block.CraftBlockEntityState;
import org.bukkit.craftbukkit.v.block.CraftBlockState;
import org.bukkit.craftbukkit.v.block.CraftBlockStates;
import org.bukkit.craftbukkit.v.block.CraftCreatureSpawner;
import org.bukkit.craftbukkit.v.util.TransformerGeneratorAccess;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

@Mixin(StructurePiece.class)
public class StructurePieceMixin {

@Inject(method = "placeBlock", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/WorldGenLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z"))
private void arclight$useTransformer(WorldGenLevel level, BlockState p_73436_, int p_73437_, int p_73438_, int p_73439_, BoundingBox p_73440_, CallbackInfo ci, BlockPos pos) {
if (level instanceof TransformerGeneratorAccess transformerGeneratorAccess) {
transformerGeneratorAccess.setCraftBlock(pos, (CraftBlockState) CraftBlockStates.getBlockState(pos, p_73436_, null), 2);
ci.cancel();
}
}

@Unique
protected boolean placeCraftBlockEntity(ServerLevelAccessor worldAccess, BlockPos position, CraftBlockEntityState<?> craftBlockEntityState, int i) {
if (worldAccess instanceof TransformerGeneratorAccess transformerAccess) {
return transformerAccess.setCraftBlock(position, craftBlockEntityState, i);
}
boolean result = worldAccess.setBlock(position, craftBlockEntityState.getHandle(), i);
var tileEntity = worldAccess.getBlockEntity(position);
if (tileEntity != null) {
tileEntity.load(craftBlockEntityState.getSnapshotNBT());
}
return result;
}

@Unique
protected void placeCraftSpawner(ServerLevelAccessor worldAccess, BlockPos position, org.bukkit.entity.EntityType entityType, int i) {
// This method is used in structures that are generated by code and place spawners as they set the entity after the block was placed making it impossible for plugins to access that information
var spawner = (CraftCreatureSpawner) CraftBlockStates.getBlockState(position, Blocks.SPAWNER.defaultBlockState(), null);
spawner.setSpawnedType(entityType);
placeCraftBlockEntity(worldAccess, position, spawner, i);
}

@Unique
protected void setCraftLootTable(ServerLevelAccessor worldAccess, BlockPos position, RandomSource randomSource, ResourceLocation loottableKey) {
// This method is used in structures that use data markers to a loot table to loot containers as otherwise plugins won't have access to that information.
var tileEntity = worldAccess.getBlockEntity(position);
if (tileEntity instanceof RandomizableContainerBlockEntity tileEntityLootable) {
tileEntityLootable.setLootTable(loottableKey, randomSource.nextLong());
if (worldAccess instanceof TransformerGeneratorAccess transformerAccess) {
transformerAccess.setCraftBlock(position, (CraftBlockState) CraftBlockStates.getBlockState(position, tileEntity.getBlockState(), tileEntityLootable.saveWithFullMetadata()), 3);
}
}
}
}
Loading

0 comments on commit 14c59f6

Please sign in to comment.