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

More core plugin updates #2514

Merged
merged 1 commit into from
Mar 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,6 @@ public static boolean canEntityJoinWorld(final Entity entity, final ServerWorld
}

public static TileEntity createTileEntity(final BlockState newState, final World world) {
return ((ITileEntityProvider) newState).createNewTileEntity(world);
return ((ITileEntityProvider) newState.getBlock()).createNewTileEntity(world);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
package org.spongepowered.common.entity.projectile;

import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.INBT;
import net.minecraft.nbt.LongNBT;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.StringNBT;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
Expand All @@ -44,7 +44,7 @@ public class ProjectileSourceSerializer {
// TODO Revisit when persistent containers are implemented.
// Note: ProjectileSource itself does not extend DataContainer

public static NBTBase toNbt(ProjectileSource projectileSource) {
public static INBT toNbt(ProjectileSource projectileSource) {
if (projectileSource instanceof Entity) {
return new StringNBT(((Entity) projectileSource).getUniqueId().toString());
}
Expand All @@ -54,7 +54,7 @@ public static NBTBase toNbt(ProjectileSource projectileSource) {
return null;
}

public static ProjectileSource fromNbt(World worldObj, NBTBase tag) {
public static ProjectileSource fromNbt(World worldObj, INBT tag) {
if (tag instanceof StringNBT) {
Entity entity =
((org.spongepowered.api.world.World) worldObj).getEntity(UUID.fromString(((StringNBT) tag).getString())).orElse(null);
Expand All @@ -78,7 +78,7 @@ public static void writeSourceToNbt(CompoundNBT compound, ProjectileSource proje
if (projectileSource == null && potentialEntity instanceof ProjectileSource) {
projectileSource = (ProjectileSource) potentialEntity;
}
NBTBase projectileNbt = toNbt(projectileSource);
INBT projectileNbt = toNbt(projectileSource);
if (projectileNbt != null) {
compound.put("projectileSource", projectileNbt);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.server.SOpenWindowPacket;
import net.minecraft.tileentity.JukeboxTileEntity;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EntityDamageSource;
import net.minecraft.util.Hand;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.EntityRayTraceResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.GameRules;
Expand Down Expand Up @@ -889,7 +892,7 @@ public static boolean handleCollideBlockEvent(final Block block, final net.minec

public static boolean handleCollideImpactEvent(final net.minecraft.entity.Entity projectile, @Nullable final ProjectileSource projectileSource,
final RayTraceResult movingObjectPosition) {
final RayTraceResult.Type movingObjectType = movingObjectPosition.typeOfHit;
final RayTraceResult.Type movingObjectType = movingObjectPosition.getType();
try (final CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
frame.pushCause(projectile);
frame.addContext(EventContextKeys.PROJECTILE_SOURCE, projectileSource == null
Expand All @@ -898,19 +901,20 @@ public static boolean handleCollideImpactEvent(final net.minecraft.entity.Entity
final Optional<User> owner = PhaseTracker.getInstance().getCurrentContext().getOwner();
owner.ifPresent(user -> frame.addContext(EventContextKeys.OWNER, user));

final Location<World> impactPoint = new Location<>((World) projectile.world, VecHelper.toVector3d(movingObjectPosition.hitResult));
final Location impactPoint = Location.of((World) projectile.world, VecHelper.toVector3d(movingObjectPosition.getHitVec()));
boolean cancelled = false;

if (movingObjectType == RayTraceResult.Type.BLOCK) {
final BlockPos blockPos = movingObjectPosition.getBlockPos();
final BlockRayTraceResult blockMovingObjectPosition = (BlockRayTraceResult) movingObjectPosition;
final BlockPos blockPos = blockMovingObjectPosition.getPos();
if (blockPos.getY() <= 0) {
return false;
}

final BlockSnapshot targetBlock = ((World) projectile.world).createSnapshot(VecHelper.toVector3i(movingObjectPosition.getBlockPos()));
final BlockSnapshot targetBlock = ((World) projectile.world).createSnapshot(VecHelper.toVector3i(blockMovingObjectPosition.getPos()));
Direction side = Direction.NONE;
if (movingObjectPosition.sideHit != null) {
side = DirectionFacingProvider.getInstance().getKey(movingObjectPosition.sideHit).get();
if (blockMovingObjectPosition.getFace() != null) {
side = DirectionFacingProvider.getInstance().getKey(blockMovingObjectPosition.getFace()).get();
}

final CollideBlockEvent.Impact event = SpongeEventFactory.createCollideBlockEventImpact(frame.getCurrentCause(),
Expand All @@ -923,9 +927,10 @@ public static boolean handleCollideImpactEvent(final net.minecraft.entity.Entity
final ChunkBridge spongeChunk = (ChunkBridge) projectile.world.getChunkAt(targetPos);
spongeChunk.bridge$addTrackedBlockPosition((Block) targetBlock.getState().getType(), targetPos, owner.get(), PlayerTracker.Type.NOTIFIER);
}
} else if (movingObjectPosition.entityHit != null) { // entity
} else if (movingObjectType == RayTraceResult.Type.ENTITY) { // entity
final EntityRayTraceResult entityMovingObjectPosition = (EntityRayTraceResult) movingObjectPosition;
final ArrayList<Entity> entityList = new ArrayList<>();
entityList.add((Entity) movingObjectPosition.entityHit);
entityList.add((Entity) entityMovingObjectPosition.getEntity());
final CollideEntityEvent.Impact event = SpongeEventFactory.createCollideEntityEventImpact(frame.getCurrentCause(), entityList, impactPoint);
cancelled = SpongeImpl.postEvent(event);
}
Expand Down Expand Up @@ -1097,13 +1102,13 @@ public static ItemStack throwDropItemAndConstructEvent(final net.minecraft.entit
@Nullable
public static PlaySoundEvent.Broadcast callPlaySoundBroadcastEvent(final CauseStackManager.StackFrame frame, final WorldBridge bridge,
final BlockPos pos, final int effectID) {
final SoundType soundType;
final Supplier<SoundType> soundType;
final float volume;
if (effectID == Constants.WorldEvents.PLAY_WITHER_SPAWN_EVENT) {
soundType = SoundTypes.ENTITY_WITHER_SPAWN;
volume = 1.0F;
} else if (effectID == Constants.WorldEvents.PLAY_ENDERDRAGON_DEATH_EVENT) {
soundType = SoundTypes.ENTITY_ENDERDRAGON_DEATH;
soundType = SoundTypes.ENTITY_ENDER_DRAGON_DEATH;
volume = 5.0F;
} else if (effectID == Constants.WorldEvents.PLAY_BLOCK_END_PORTAL_SPAWN_EVENT) {
soundType = SoundTypes.BLOCK_END_PORTAL_SPAWN;
Expand All @@ -1113,21 +1118,21 @@ public static PlaySoundEvent.Broadcast callPlaySoundBroadcastEvent(final CauseSt
}
final Location<World> location = new Location<>((World) bridge, pos.getX(), pos.getY(), pos.getZ());
final PlaySoundEvent.Broadcast event = SpongeEventFactory.createPlaySoundEventBroadcast(frame.getCurrentCause(), location,
SoundCategories.HOSTILE, soundType, 1.0F, volume);
SoundCategories.HOSTILE.get(), soundType.get(), 1.0F, volume);
SpongeImpl.postEvent(event);
return event;
}

public static PlaySoundEvent.Record callPlaySoundRecordEvent(final Cause cause, final JukeboxBlock.TileEntityJukebox jukebox,
public static PlaySoundEvent.Record callPlaySoundRecordEvent(final Cause cause, final JukeboxTileEntity jukebox,
final MusicDisc recordType, final int data) {
final Jukebox apiJuke = (Jukebox) jukebox;
final Location<World> location = apiJuke.getLocation();
final PlaySoundEvent.Record
event =
data == 0 ? SpongeEventFactory
.createPlaySoundEventRecordStart(cause, apiJuke, location, recordType, SoundCategories.RECORD, recordType.getSound(), 1.0F, 4.0F)
.createPlaySoundEventRecordStart(cause, apiJuke, location, recordType, SoundCategories.RECORD.get(), recordType.getSound(), 1.0F, 4.0F)
: SpongeEventFactory
.createPlaySoundEventRecordStop(cause, apiJuke, location, recordType, SoundCategories.RECORD, recordType.getSound(), 1.0F, 4.0F);
.createPlaySoundEventRecordStop(cause, apiJuke, location, recordType, SoundCategories.RECORD.get(), recordType.getSound(), 1.0F, 4.0F);
SpongeImpl.postEvent(event);
return event;
}
Expand All @@ -1143,9 +1148,9 @@ public static PlaySoundEvent.AtEntity callPlaySoundAtEntityEvent(final Cause cau
return event;
}

public static PlaySoundEvent.NoteBlock callPlaySoundNoteBLockEvent(final Cause cause, final World world, Note note, final BlockPos pos, final SoundEvent soundEvent, final InstrumentType instrument, final NotePitch notePitch, final Float pitch) {
public static PlaySoundEvent.NoteBlock callPlaySoundNoteBlockEvent(final Cause cause, final World world, final BlockPos pos, final SoundEvent soundEvent, final InstrumentType instrument, final NotePitch notePitch, final Float pitch) {
final Location<World> location = new Location<>(world, pos.getX(), pos.getY(), pos.getZ());
final PlaySoundEvent.NoteBlock event = SpongeEventFactory.createPlaySoundEventNoteBlock(cause, instrument, location, note, notePitch, SoundCategories.RECORD, (SoundType)soundEvent, pitch, 3.0F);
final PlaySoundEvent.NoteBlock event = SpongeEventFactory.createPlaySoundEventNoteBlock(cause, instrument, location, notePitch, SoundCategories.RECORD.get(), (SoundType)soundEvent, pitch, 3.0F);
SpongeImpl.postEvent(event);
return event;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ public interface CHandshakePacketAccessor {
@Accessor("ip") String accessor$getIp();

@Accessor("ip") void accessor$setIp(String ip);

@Accessor("port") int accessor$getPort();
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public abstract class ServerLoginNetHandlerMixin_Bungee {
@Inject(method = "processLoginStart",
at = @At(
value = "FIELD",
target = "Lnet/minecraft/server/network/NetHandlerLoginServer;loginGameProfile:Lcom/mojang/authlib/GameProfile;",
target = "Lnet/minecraft/network/login/ServerLoginNetHandler;loginGameProfile:Lcom/mojang/authlib/GameProfile;",
opcode = Opcodes.PUTFIELD,
ordinal = 0,
shift = At.Shift.AFTER))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,15 @@
import net.minecraft.block.BlockState;
import net.minecraft.block.NoteBlock;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.SoundEvent;
import net.minecraft.state.properties.NoteBlockInstrument;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.block.tileentity.Note;
import org.spongepowered.api.data.property.block.InstrumentProperty;
import org.spongepowered.api.data.Keys;
import org.spongepowered.api.data.type.InstrumentType;
import org.spongepowered.api.event.CauseStackManager;
import org.spongepowered.api.event.sound.PlaySoundEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
Expand All @@ -47,11 +45,9 @@
@Mixin(NoteBlock.class)
public abstract class NoteBlockMixin extends BlockMixin {

@Shadow protected abstract SoundEvent getInstrument(int eventId);

@SuppressWarnings("ConstantConditions")
@Inject(method = "eventReceived(Lnet/minecraft/block/state/IBlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;II)Z",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;playSound(Lnet/minecraft/entity/player/EntityPlayer;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/SoundEvent;Lnet/minecraft/util/SoundCategory;FF)V"),
@Inject(method = "eventReceived(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;II)Z",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;playSound(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/SoundEvent;Lnet/minecraft/util/SoundCategory;FF)V"),
cancellable = true)
private void impl$throwNoteBlockSoundEvent(BlockState state, World worldIn, BlockPos pos, int id, int param, CallbackInfoReturnable<Boolean> callbackInfo) {
if (!ShouldFire.PLAY_SOUND_EVENT_NOTE_BLOCK) {
Expand All @@ -64,20 +60,15 @@ public abstract class NoteBlockMixin extends BlockMixin {
}

//InstrumentProperty doesn't return what we wan't for the noteblock directly, so we have to check the block under it.
InstrumentProperty instrumentProperty = ((org.spongepowered.api.world.World) worldIn).getBlock(pos.getX(), pos.getY() - 1, pos.getZ()).getProperty(InstrumentProperty.class).orElse(null);
if (instrumentProperty == null) {
return;
}

TileEntity tileEntity = worldIn.getTileEntity(pos);
if (!(tileEntity instanceof Note)) {
InstrumentType instrumentType = ((org.spongepowered.api.world.World) worldIn).getBlock(pos.getX(), pos.getY() - 1, pos.getZ()).get(Keys.REPRESENTED_INSTRUMENT).orElse(null);
if (instrumentType == null) {
return;
}

float pitch = (float) Math.pow(2.0D, (double) (param - 12) / 12.0D);

try (final CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
final PlaySoundEvent.NoteBlock event = SpongeCommonEventFactory.callPlaySoundNoteBLockEvent(frame.getCurrentCause(), (org.spongepowered.api.world.World) worldIn, (Note) tileEntity, pos, this.getInstrument(id), instrumentProperty.getValue(), NotePitchRegistryModule.getPitch((byte) param), pitch);
final PlaySoundEvent.NoteBlock event = SpongeCommonEventFactory.callPlaySoundNoteBlockEvent(frame.getCurrentCause(), (org.spongepowered.api.world.World) worldIn, pos, NoteBlockInstrument.byState(state).getSound(), instrumentType, NotePitchRegistryModule.getPitch((byte) param), pitch);
if (event.isCancelled()) {
callbackInfo.setReturnValue(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ public abstract class EnderDragonEntityMixin extends MobEntityMixin {
method = "destroyBlocksInAABB",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/block/state/IBlockState;getBlock()Lnet/minecraft/block/Block;"
target = "Lnet/minecraft/block/BlockState;getBlock()Lnet/minecraft/block/Block;"
),
slice = @Slice(
from = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/World;getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/state/IBlockState;"
target = "Lnet/minecraft/world/World;getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;"
),
to = @At(
value = "FIELD",
Expand All @@ -69,7 +69,7 @@ public abstract class EnderDragonEntityMixin extends MobEntityMixin {
),
require = 0 // Forge rewrites the material request to block.isAir
)
private Block spongeImpl$onCanGrief(BlockState state) {
private Block impl$onCanGrief(BlockState state) {
return ((GrieferBridge) this).bridge$canGrief() ? state.getBlock() : Blocks.AIR;
}

Expand All @@ -81,7 +81,7 @@ public abstract class EnderDragonEntityMixin extends MobEntityMixin {
*/
@Redirect(method = "livingTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/boss/dragon/phase/IPhase;getTargetLocation()Lnet/minecraft/util/math/Vec3d;"))
@Nullable
private Vec3d spongeImpl$getTargetLocationOrNull(IPhase iPhase) {
private Vec3d impl$getTargetLocationOrNull(IPhase iPhase) {
Vec3d target = iPhase.getTargetLocation();
if (target != null && target.x == this.posX && target.z == this.posZ) {
return null; // Skips the movement code
Expand Down
Loading