Skip to content

Commit

Permalink
more works
Browse files Browse the repository at this point in the history
  • Loading branch information
wdog5 committed Sep 29, 2023
1 parent 003b865 commit fdb6ca4
Show file tree
Hide file tree
Showing 42 changed files with 574 additions and 528 deletions.
5 changes: 3 additions & 2 deletions src/main/java/com/mohistmc/banner/bukkit/BukkitContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeHolder;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftInventory;
Expand Down Expand Up @@ -158,12 +159,12 @@ public Location getLocation() {
}

@Override
public Recipe<?> getCurrentRecipe() {
public RecipeHolder<?> getCurrentRecipe() {
return null;
}

@Override
public void setCurrentRecipe(Recipe<?> recipe) {
public void setCurrentRecipe(RecipeHolder<?> recipe) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.PositionImpl;
import net.minecraft.server.WorldLoader;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
Expand All @@ -11,6 +10,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.phys.Vec3;
import org.bukkit.TreeType;
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.v1_20_R2.event.CraftPortalEvent;
Expand All @@ -35,13 +35,13 @@ public class BukkitSnapshotCaptures {
return banner$stopGlide;
}

private static PositionImpl positionImpl;
private static Vec3 positionImpl;

public static void capturePositionImpl(PositionImpl position) {
public static void capturePositionImpl(Vec3 position) {
positionImpl = position;
}

public static PositionImpl getPositionImpl() {
public static Vec3 getPositionImpl() {
try {
return positionImpl;
} finally {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.mohistmc.banner.mixin.interaction.dispenser;

import com.mohistmc.banner.bukkit.BukkitExtraConstants;
import net.minecraft.core.BlockSource;
import net.minecraft.core.Direction;
import net.minecraft.core.Position;
import net.minecraft.core.dispenser.AbstractProjectileDispenseBehavior;
import net.minecraft.core.dispenser.BlockSource;
import net.minecraft.core.dispenser.DispenseItemBehavior;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
Expand All @@ -32,42 +34,45 @@ public abstract class MixinAbstractProjectileDispenseBehavior {
* @reason
*/
@Overwrite
public ItemStack execute(BlockSource isourceblock, ItemStack stack) {
Level level = isourceblock.getLevel();
Position position = DispenserBlock.getDispensePosition(isourceblock);
Direction direction = (Direction)isourceblock.getBlockState().getValue(DispenserBlock.FACING);
Projectile projectile = this.getProjectile(level, position, stack);
public ItemStack execute(BlockSource isourceblock, ItemStack itemstack) {
ServerLevel worldserver = isourceblock.level();
Position iposition = DispenserBlock.getDispensePosition(isourceblock);
Direction enumdirection = (Direction) isourceblock.state().getValue(DispenserBlock.FACING);
Projectile iprojectile = this.getProjectile(worldserver, iposition, itemstack);

// CraftBukkit start
//projectile.shoot((double)direction.getStepX(), (double)((float)direction.getStepY() + 0.1F), (double)direction.getStepZ(), this.getPower(), this.getUncertainty());
ItemStack itemstack1 = stack.split(1);
org.bukkit.block.Block block = level.getWorld().getBlockAt(isourceblock.getPos().getX(), isourceblock.getPos().getY(), isourceblock.getPos().getZ());
// iprojectile.shoot((double) enumdirection.getStepX(), (double) ((float) enumdirection.getStepY() + 0.1F), (double) enumdirection.getStepZ(), this.getPower(), this.getUncertainty());
ItemStack itemstack1 = itemstack.split(1);
org.bukkit.block.Block block = worldserver.getWorld().getBlockAt(isourceblock.pos().getX(), isourceblock.pos().getY(), isourceblock.pos().getZ());
CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);

BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector((double) direction.getStepX(), (double) ((float) direction.getStepY() + 0.1F), (double) direction.getStepZ()));
BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector((double) enumdirection.getStepX(), (double) ((float) enumdirection.getStepY() + 0.1F), (double) enumdirection.getStepZ()));
if (!BukkitExtraConstants.dispenser_eventFired) {
level.getCraftServer().getPluginManager().callEvent(event);
worldserver.getCraftServer().getPluginManager().callEvent(event);
}

if (event.isCancelled()) {
stack.grow(1);
return stack;
itemstack.grow(1);
return itemstack;
}

if (!event.getItem().equals(craftItem)) {
stack.grow(1);
itemstack.grow(1);
// Chain to handler for new item
ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
DispenseItemBehavior idispensebehavior = (DispenseItemBehavior) DispenserBlock.DISPENSER_REGISTRY.get(eventStack.getItem());
if (idispensebehavior != DispenseItemBehavior.NOOP && idispensebehavior != this) {
idispensebehavior.dispense(isourceblock, eventStack);
return stack;
return itemstack;
}
}
projectile.shoot(event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ(), this.getPower(), this.getUncertainty());
projectile.banner$setProjectileSource(new CraftBlockProjectileSource((DispenserBlockEntity) isourceblock.getEntity()));

level.addFreshEntity(projectile);
//stack.shrink(1);// CraftBukkit - Handled during event processing
return stack;
iprojectile.shoot(event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ(), this.getPower(), this.getUncertainty());
((Entity) iprojectile).banner$setProjectileSource(new CraftBlockProjectileSource((DispenserBlockEntity) isourceblock.blockEntity()));
// CraftBukkit end
worldserver.addFreshEntity(iprojectile);
// itemstack.shrink(1); // CraftBukkit - Handled during event processing
return itemstack;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@

import com.mohistmc.banner.bukkit.BukkitExtraConstants;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockSource;
import net.minecraft.core.Direction;
import net.minecraft.core.dispenser.BlockSource;
import net.minecraft.core.dispenser.BoatDispenseItemBehavior;
import net.minecraft.core.dispenser.DefaultDispenseItemBehavior;
import net.minecraft.core.dispenser.DispenseItemBehavior;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.FluidTags;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.vehicle.Boat;
import net.minecraft.world.entity.vehicle.ChestBoat;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.DispenserBlock;
import net.minecraft.world.phys.Vec3;
import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack;
import org.bukkit.event.block.BlockDispenseEvent;
import org.spongepowered.asm.mixin.Final;
Expand All @@ -35,54 +38,62 @@ public abstract class MixinBoatDispenseItemBehavior {
* @reason bukkit event
*/
@Overwrite
public ItemStack execute(BlockSource source, ItemStack stack) {
Direction direction = (Direction)source.getBlockState().getValue(DispenserBlock.FACING);
Level level = source.getLevel();
double d = source.x() + (double)((float)direction.getStepX() * 1.125F);
double e = source.y() + (double)((float)direction.getStepY() * 1.125F);
double f = source.z() + (double)((float)direction.getStepZ() * 1.125F);
BlockPos blockPos = source.getPos().relative(direction);
double g;
if (level.getFluidState(blockPos).is(FluidTags.WATER)) {
g = 1.0;
public ItemStack execute(BlockSource isourceblock, ItemStack itemstack) {
Direction enumdirection = (Direction) isourceblock.state().getValue(DispenserBlock.FACING);
ServerLevel worldserver = isourceblock.level();
Vec3 vec3 = isourceblock.center();
double d0 = 0.5625 + (double)EntityType.BOAT.getWidth() / 2.0;
double d1 = vec3.x() + (double)enumdirection.getStepX() * d0;
double d2 = vec3.y() + (double)((float)enumdirection.getStepY() * 1.125F);
double d3 = vec3.z() + (double)enumdirection.getStepZ() * d0;
BlockPos blockposition = isourceblock.pos().relative(enumdirection);
double d4;

if (worldserver.getFluidState(blockposition).is(FluidTags.WATER)) {
d4 = 1.0D;
} else {
if (!level.getBlockState(blockPos).isAir() || !level.getFluidState(blockPos.below()).is(FluidTags.WATER)) {
return this.defaultDispenseItemBehavior.dispense(source, stack);
if (!worldserver.getBlockState(blockposition).isAir() || !worldserver.getFluidState(blockposition.below()).is(FluidTags.WATER)) {
return this.defaultDispenseItemBehavior.dispense(isourceblock, itemstack);
}

g = 0.0;
d4 = 0.0D;
}

//Boat boat = this.isChestBoat ? new ChestBoat(level, d, e + g, f) : new Boat(level, d, e + g, f);

// Object object = this.isChestBoat ? new ChestBoat(worldserver, d1, d2 + d4, d3) : new EntityBoat(worldserver, d1, d2 + d4, d3);
// CraftBukkit start
ItemStack itemstack1 = stack.split(1);
org.bukkit.block.Block block = level.getWorld().getBlockAt(source.getPos().getX(), source.getPos().getY(), source.getPos().getZ());
ItemStack itemstack1 = itemstack.split(1);
org.bukkit.block.Block block = worldserver.getWorld().getBlockAt(isourceblock.pos().getX(), isourceblock.pos().getY(), isourceblock.pos().getZ());
CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);

BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(d, e + g, f));
BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector(d1, d2 + d4, d3));
if (!BukkitExtraConstants.dispenser_eventFired) {
level.getCraftServer().getPluginManager().callEvent(event);
worldserver.getCraftServer().getPluginManager().callEvent(event);
}

if (event.isCancelled()) {
stack.grow(1);
return stack;
itemstack.grow(1);
return itemstack;
}

if (!event.getItem().equals(craftItem)) {
stack.grow(1);
itemstack.grow(1);
// Chain to handler for new item
ItemStack eventStack = CraftItemStack.asNMSCopy(event.getItem());
DispenseItemBehavior idispensebehavior = (DispenseItemBehavior) DispenserBlock.DISPENSER_REGISTRY.get(eventStack.getItem());
if (idispensebehavior != DispenseItemBehavior.NOOP && idispensebehavior != this) {
idispensebehavior.dispense(source, eventStack);
return stack;
idispensebehavior.dispense(isourceblock, eventStack);
return itemstack;
}
}
Boat boat = this.isChestBoat ? new ChestBoat(level, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ()) : new Boat(level, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ());
((Boat)boat).setVariant(this.type);
((Boat)boat).setYRot(direction.toYRot());
if (!level.addFreshEntity((Entity) boat)) stack.grow(1); // CraftBukkit
return stack;

Object object = this.isChestBoat ? new ChestBoat(worldserver, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ()) : new Boat(worldserver, event.getVelocity().getX(), event.getVelocity().getY(), event.getVelocity().getZ());
// CraftBukkit end

((Boat) object).setVariant(this.type);
((Boat) object).setYRot(enumdirection.toYRot());
if (!worldserver.addFreshEntity((Entity) object)) itemstack.grow(1); // CraftBukkit
// itemstack.shrink(1); // CraftBukkit - handled during event processing
return itemstack;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.mohistmc.banner.bukkit.BukkitExtraConstants;
import net.minecraft.core.BlockPos;
import net.minecraft.core.BlockSource;
import net.minecraft.core.Direction;
import net.minecraft.core.dispenser.DispenseItemBehavior;
import net.minecraft.core.dispenser.OptionalDispenseItemBehavior;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.mohistmc.banner.mixin.server;

import com.google.common.collect.Maps;
import com.google.common.collect.ImmutableMap;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.minecraft.advancements.Advancement;
import net.minecraft.advancements.AdvancementList;
import net.minecraft.advancements.AdvancementHolder;
import net.minecraft.advancements.AdvancementNode;
import net.minecraft.advancements.AdvancementTree;
import net.minecraft.advancements.TreeNodePosition;
import net.minecraft.advancements.critereon.DeserializationContext;
import net.minecraft.resources.ResourceLocation;
Expand All @@ -19,24 +21,27 @@
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

import java.util.Iterator;
import java.util.Map;

@Mixin(ServerAdvancementManager.class)
public class MixinServerAdvancementManager {

@Shadow @Final private static Logger LOGGER;

@Shadow public AdvancementList advancements;

@Shadow @Final private LootDataManager lootData;

@Shadow private AdvancementTree tree;

@Shadow public Map<ResourceLocation, AdvancementHolder> advancements;

/**
* @author wdog5
* @reason
* @reason spigot config
*/
@Overwrite
protected void apply(Map<ResourceLocation, JsonElement> object, ResourceManager resourceManager, ProfilerFiller profiler) {
Map<ResourceLocation, Advancement.Builder> map = Maps.newHashMap();
ImmutableMap.Builder<ResourceLocation, AdvancementHolder> builder = ImmutableMap.builder();
object.forEach((resourceLocation, jsonElement) -> {
// Spigot start
if (org.spigotmc.SpigotConfig.disabledAdvancements != null
Expand All @@ -48,23 +53,26 @@ protected void apply(Map<ResourceLocation, JsonElement> object, ResourceManager
// Spigot end
try {
JsonObject jsonObject = GsonHelper.convertToJsonObject(jsonElement, "advancement");
Advancement.Builder builder = Advancement.Builder.fromJson(jsonObject, new DeserializationContext(resourceLocation, this.lootData));
map.put(resourceLocation, builder);
Advancement advancement = Advancement.fromJson(jsonObject, new DeserializationContext(resourceLocation, this.lootData));
builder.put(resourceLocation, new AdvancementHolder(resourceLocation, advancement));
} catch (Exception var6) {
LOGGER.error("Parsing error loading custom advancement {}: {}", resourceLocation, var6.getMessage());
}

});
AdvancementList advancementList = new AdvancementList();
advancementList.add(map);
this.advancements = builder.buildOrThrow();
AdvancementTree advancementTree = new AdvancementTree();
advancementTree.addAll(this.advancements.values());
Iterator var6 = advancementTree.roots().iterator();

for (Advancement advancement : advancementList.getRoots()) {
if (advancement.getDisplay() != null) {
TreeNodePosition.run(advancement);
while(var6.hasNext()) {
AdvancementNode advancementNode = (AdvancementNode)var6.next();
if (advancementNode.holder().value().display().isPresent()) {
TreeNodePosition.run(advancementNode);
}
}

this.advancements = advancementList;
this.tree = advancementTree;
}

}
Loading

0 comments on commit fdb6ca4

Please sign in to comment.