mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-02 11:21:15 +01:00
Remove #copy
This commit is contained in:
parent
f39f6444d7
commit
f7c05a445e
@ -86,7 +86,7 @@ public class CollisionUtils {
|
||||
BlockPosition[] cornerPositions = new BlockPosition[corners.length];
|
||||
Vector[] cornersCopy = new Vector[corners.length];
|
||||
for (int i = 0; i < corners.length; i++) {
|
||||
cornersCopy[i] = corners[i].copy();
|
||||
cornersCopy[i] = corners[i].clone();
|
||||
cornerPositions[i] = new BlockPosition(corners[i]);
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,7 @@ public abstract class Data implements PublicCloneable<Data> {
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Data clone() {
|
||||
return this;
|
||||
@ -119,6 +120,7 @@ public abstract class Data implements PublicCloneable<Data> {
|
||||
*/
|
||||
public abstract boolean isEmpty();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Data clone() {
|
||||
try {
|
||||
|
@ -58,6 +58,7 @@ public class DataImpl extends Data {
|
||||
return data.isEmpty();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DataImpl clone() {
|
||||
return (DataImpl) super.clone();
|
||||
|
@ -66,6 +66,7 @@ public abstract class SerializableData extends Data {
|
||||
readSerializedData(reader, typeToIndexMap);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public SerializableData clone() {
|
||||
return (SerializableData) super.clone();
|
||||
|
@ -89,6 +89,7 @@ public class SerializableDataImpl extends SerializableData {
|
||||
return data.isEmpty();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public SerializableDataImpl clone() {
|
||||
return (SerializableDataImpl) super.clone();
|
||||
|
@ -142,7 +142,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P
|
||||
this.id = generateId();
|
||||
this.entityType = entityType;
|
||||
this.uuid = UUID.randomUUID();
|
||||
this.position = spawnPosition.copy();
|
||||
this.position = spawnPosition.clone();
|
||||
|
||||
setBoundingBox(0, 0, 0);
|
||||
|
||||
@ -436,7 +436,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P
|
||||
|
||||
sendPacketToViewersAndSelf(positionAndRotationPacket);
|
||||
|
||||
refreshPosition(position.copy());
|
||||
refreshPosition(position.clone());
|
||||
|
||||
// Fix head rotation
|
||||
EntityHeadLookPacket entityHeadLookPacket = new EntityHeadLookPacket();
|
||||
@ -451,7 +451,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P
|
||||
|
||||
sendPacketToViewersAndSelf(entityPositionPacket);
|
||||
|
||||
refreshPosition(position.copy());
|
||||
refreshPosition(position.clone());
|
||||
|
||||
} else if (viewChange) {
|
||||
// Yaw/Pitch
|
||||
|
@ -111,7 +111,7 @@ public class ItemEntity extends ObjectEntity {
|
||||
if (!canApply)
|
||||
continue;
|
||||
|
||||
final ItemStack result = stackingRule.apply(itemStack.copy(), totalAmount);
|
||||
final ItemStack result = stackingRule.apply(itemStack.clone(), totalAmount);
|
||||
|
||||
EntityItemMergeEvent entityItemMergeEvent = new EntityItemMergeEvent(this, itemEntity, result);
|
||||
callCancellableEvent(EntityItemMergeEvent.class, entityItemMergeEvent, () -> {
|
||||
|
@ -1402,7 +1402,7 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
*/
|
||||
@NotNull
|
||||
public Position getRespawnPoint() {
|
||||
return respawnPoint.copy();
|
||||
return respawnPoint.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1981,7 +1981,7 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
*/
|
||||
protected void updatePlayerPosition() {
|
||||
PlayerPositionAndLookPacket positionAndLookPacket = new PlayerPositionAndLookPacket();
|
||||
positionAndLookPacket.position = position.copy(); // clone needed to prevent synchronization issue
|
||||
positionAndLookPacket.position = position.clone(); // clone needed to prevent synchronization issue
|
||||
positionAndLookPacket.flags = 0x00;
|
||||
positionAndLookPacket.teleportId = teleportId.incrementAndGet();
|
||||
playerConnection.sendPacket(positionAndLookPacket);
|
||||
|
@ -41,8 +41,8 @@ public class EatBlockGoal extends GoalSelector {
|
||||
}
|
||||
final Instance instance = entityCreature.getInstance();
|
||||
final BlockPosition blockPosition = entityCreature.getPosition().toBlockPosition();
|
||||
final short blockStateIdIn = instance.getBlockStateId(blockPosition.copy().subtract(0, 1, 0));
|
||||
final short blockStateIdBelow = instance.getBlockStateId(blockPosition.copy().subtract(0, 2, 0));
|
||||
final short blockStateIdIn = instance.getBlockStateId(blockPosition.clone().subtract(0, 1, 0));
|
||||
final short blockStateIdBelow = instance.getBlockStateId(blockPosition.clone().subtract(0, 2, 0));
|
||||
|
||||
return eatInMap.containsKey(blockStateIdIn) || eatBelowMap.containsKey(blockStateIdBelow);
|
||||
}
|
||||
@ -62,8 +62,8 @@ public class EatBlockGoal extends GoalSelector {
|
||||
return;
|
||||
}
|
||||
Instance instance = entityCreature.getInstance();
|
||||
final BlockPosition currentPosition = entityCreature.getPosition().toBlockPosition().copy().subtract(0, 1, 0);
|
||||
final BlockPosition belowPosition = currentPosition.copy().subtract(0, 1, 0);
|
||||
final BlockPosition currentPosition = entityCreature.getPosition().toBlockPosition().clone().subtract(0, 1, 0);
|
||||
final BlockPosition belowPosition = currentPosition.clone().subtract(0, 1, 0);
|
||||
|
||||
final short blockStateIdIn = instance.getBlockStateId(currentPosition);
|
||||
final short blockStateIdBelow = instance.getBlockStateId(belowPosition);
|
||||
|
@ -40,7 +40,7 @@ public class FollowTargetGoal extends GoalSelector {
|
||||
final Entity target = entityCreature.getTarget();
|
||||
|
||||
if (target != null) {
|
||||
lastTargetPos = target.getPosition().copy();
|
||||
lastTargetPos = target.getPosition().clone();
|
||||
if (getDistance(lastTargetPos, entityCreature.getPosition()) < 2) {
|
||||
forceEnd = true;
|
||||
entityCreature.setPathTo(null);
|
||||
|
@ -69,7 +69,7 @@ public class RandomLookAroundGoal extends GoalSelector {
|
||||
@Override
|
||||
public void tick(long time) {
|
||||
--lookTime;
|
||||
entityCreature.setView(entityCreature.getPosition().copy().setDirection(lookDirection));
|
||||
entityCreature.setView(entityCreature.getPosition().clone().setDirection(lookDirection));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -35,7 +35,7 @@ public class RandomStrollGoal extends GoalSelector {
|
||||
Collections.shuffle(closePositions);
|
||||
|
||||
for (Position position : closePositions) {
|
||||
final Position target = position.copy().add(entityCreature.getPosition());
|
||||
final Position target = position.clone().add(entityCreature.getPosition());
|
||||
final boolean result = entityCreature.setPathTo(target);
|
||||
if (result) {
|
||||
break;
|
||||
|
@ -26,7 +26,7 @@ public class Hologram implements Viewable {
|
||||
private boolean removed;
|
||||
|
||||
public Hologram(Instance instance, Position spawnPosition, ColoredText text, boolean autoViewable) {
|
||||
this.entity = new HologramEntity(spawnPosition.copy().add(0, OFFSET_Y, 0));
|
||||
this.entity = new HologramEntity(spawnPosition.clone().add(0, OFFSET_Y, 0));
|
||||
this.entity.setInstance(instance);
|
||||
this.entity.setAutoViewable(autoViewable);
|
||||
|
||||
|
@ -120,7 +120,7 @@ public interface NavigableEntity {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Position targetPosition = position.copy();
|
||||
final Position targetPosition = position.clone();
|
||||
|
||||
final IPath path = pathFinder.initiatePathTo(targetPosition.getX(), targetPosition.getY(), targetPosition.getZ());
|
||||
setPath(path);
|
||||
|
@ -387,8 +387,8 @@ public class DynamicChunk extends Chunk {
|
||||
fullDataPacket.biomes = biomes;
|
||||
fullDataPacket.chunkX = chunkX;
|
||||
fullDataPacket.chunkZ = chunkZ;
|
||||
fullDataPacket.paletteStorage = blockPalette.copy();
|
||||
fullDataPacket.customBlockPaletteStorage = customBlockPalette.copy();
|
||||
fullDataPacket.paletteStorage = blockPalette.clone();
|
||||
fullDataPacket.customBlockPaletteStorage = customBlockPalette.clone();
|
||||
fullDataPacket.blockEntities = new IntOpenHashSet(blockEntities);
|
||||
fullDataPacket.blocksData = new Int2ObjectOpenHashMap<>(blocksData);
|
||||
return fullDataPacket;
|
||||
@ -398,8 +398,8 @@ public class DynamicChunk extends Chunk {
|
||||
@Override
|
||||
public Chunk copy(int chunkX, int chunkZ) {
|
||||
DynamicChunk dynamicChunk = new DynamicChunk(biomes.clone(), chunkX, chunkZ);
|
||||
dynamicChunk.blockPalette = blockPalette.copy();
|
||||
dynamicChunk.customBlockPalette = customBlockPalette.copy();
|
||||
dynamicChunk.blockPalette = blockPalette.clone();
|
||||
dynamicChunk.customBlockPalette = customBlockPalette.clone();
|
||||
dynamicChunk.blocksData.putAll(blocksData);
|
||||
dynamicChunk.updatableBlocks.addAll(updatableBlocks);
|
||||
dynamicChunk.updatableBlocksLastUpdate.putAll(updatableBlocksLastUpdate);
|
||||
|
@ -5,6 +5,7 @@ import it.unimi.dsi.fastutil.shorts.Short2ShortOpenHashMap;
|
||||
import net.minestom.server.instance.Chunk;
|
||||
import net.minestom.server.utils.MathUtils;
|
||||
import net.minestom.server.utils.chunk.ChunkUtils;
|
||||
import net.minestom.server.utils.clone.PublicCloneable;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -17,7 +18,7 @@ import static net.minestom.server.instance.Chunk.CHUNK_SECTION_SIZE;
|
||||
* The format used is the one described in the {@link net.minestom.server.network.packet.server.play.ChunkDataPacket},
|
||||
* the reason is that it allows us to write the packet much faster.
|
||||
*/
|
||||
public class PaletteStorage {
|
||||
public class PaletteStorage implements PublicCloneable<PaletteStorage> {
|
||||
|
||||
/**
|
||||
* The maximum bits per entry value.
|
||||
@ -155,15 +156,29 @@ public class PaletteStorage {
|
||||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #clone()}
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public PaletteStorage copy() {
|
||||
PaletteStorage paletteStorage = new PaletteStorage(bitsPerEntry, bitsIncrement);
|
||||
paletteStorage.sectionBlocks = sectionBlocks.clone();
|
||||
return clone();
|
||||
}
|
||||
|
||||
paletteStorage.paletteBlockMaps = paletteBlockMaps.clone();
|
||||
paletteStorage.blockPaletteMaps = blockPaletteMaps.clone();
|
||||
@NotNull
|
||||
@Override
|
||||
public PaletteStorage clone() {
|
||||
try {
|
||||
PaletteStorage paletteStorage = (PaletteStorage) super.clone();
|
||||
paletteStorage.sectionBlocks = sectionBlocks.clone();
|
||||
|
||||
return paletteStorage;
|
||||
paletteStorage.paletteBlockMaps = paletteBlockMaps.clone();
|
||||
paletteStorage.blockPaletteMaps = blockPaletteMaps.clone();
|
||||
return paletteStorage;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
e.printStackTrace();
|
||||
throw new IllegalStateException("Weird thing happened");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -96,18 +96,18 @@ public class InventoryClickProcessor {
|
||||
} else {
|
||||
if (cursor.isAir()) {
|
||||
final int amount = (int) Math.ceil((double) clicked.getAmount() / 2d);
|
||||
resultCursor = clicked.copy();
|
||||
resultCursor = clicked.clone();
|
||||
resultCursor = cursorRule.apply(resultCursor, amount);
|
||||
|
||||
resultClicked = clicked.copy();
|
||||
resultClicked = clicked.clone();
|
||||
resultClicked = clickedRule.apply(resultClicked, clicked.getAmount() / 2);
|
||||
} else {
|
||||
if (clicked.isAir()) {
|
||||
final int amount = cursor.getAmount();
|
||||
resultCursor = cursor.copy();
|
||||
resultCursor = cursor.clone();
|
||||
resultCursor = cursorRule.apply(resultCursor, amount - 1);
|
||||
|
||||
resultClicked = cursor.copy();
|
||||
resultClicked = cursor.clone();
|
||||
resultClicked = clickedRule.apply(resultClicked, 1);
|
||||
} else {
|
||||
resultCursor = clicked;
|
||||
@ -181,7 +181,7 @@ public class InventoryClickProcessor {
|
||||
final StackingRule clickedRule = clicked.getStackingRule();
|
||||
|
||||
boolean filled = false;
|
||||
ItemStack resultClicked = clicked.copy();
|
||||
ItemStack resultClicked = clicked.clone();
|
||||
|
||||
for (InventoryClickLoopHandler loopHandler : loopHandlers) {
|
||||
final Int2IntFunction indexModifier = loopHandler.getIndexModifier();
|
||||
@ -278,7 +278,7 @@ public class InventoryClickProcessor {
|
||||
int finalCursorAmount = cursorAmount;
|
||||
|
||||
for (Integer s : slots) {
|
||||
final ItemStack draggedItem = cursor.copy();
|
||||
final ItemStack draggedItem = cursor.clone();
|
||||
ItemStack slotItem = itemGetter.apply(s);
|
||||
|
||||
clickResult = startCondition(clickResult, inventory, player, s, ClickType.DRAGGING, slotItem, cursor);
|
||||
@ -318,7 +318,7 @@ public class InventoryClickProcessor {
|
||||
if (size > cursorAmount)
|
||||
return null;
|
||||
for (Integer s : slots) {
|
||||
ItemStack draggedItem = cursor.copy();
|
||||
ItemStack draggedItem = cursor.clone();
|
||||
ItemStack slotItem = itemGetter.apply(s);
|
||||
|
||||
clickResult = startCondition(clickResult, inventory, player, s, ClickType.DRAGGING, slotItem, cursor);
|
||||
@ -435,8 +435,8 @@ public class InventoryClickProcessor {
|
||||
final StackingRule clickedRule = clicked == null ? null : clicked.getStackingRule();
|
||||
final StackingRule cursorRule = cursor.getStackingRule();
|
||||
|
||||
ItemStack resultClicked = clicked == null ? null : clicked.copy();
|
||||
ItemStack resultCursor = cursor.copy();
|
||||
ItemStack resultClicked = clicked == null ? null : clicked.clone();
|
||||
ItemStack resultCursor = cursor.clone();
|
||||
|
||||
|
||||
if (slot == -999) {
|
||||
@ -444,7 +444,7 @@ public class InventoryClickProcessor {
|
||||
if (button == 0) {
|
||||
// Left (drop all)
|
||||
final int amount = cursorRule.getAmount(resultCursor);
|
||||
final ItemStack dropItem = cursorRule.apply(resultCursor.copy(), amount);
|
||||
final ItemStack dropItem = cursorRule.apply(resultCursor.clone(), amount);
|
||||
final boolean dropResult = player.dropItem(dropItem);
|
||||
clickResult.setCancel(!dropResult);
|
||||
if (dropResult) {
|
||||
@ -452,7 +452,7 @@ public class InventoryClickProcessor {
|
||||
}
|
||||
} else if (button == 1) {
|
||||
// Right (drop 1)
|
||||
final ItemStack dropItem = cursorRule.apply(resultCursor.copy(), 1);
|
||||
final ItemStack dropItem = cursorRule.apply(resultCursor.clone(), 1);
|
||||
final boolean dropResult = player.dropItem(dropItem);
|
||||
clickResult.setCancel(!dropResult);
|
||||
if (dropResult) {
|
||||
@ -465,7 +465,7 @@ public class InventoryClickProcessor {
|
||||
} else if (mode == 4) {
|
||||
if (button == 0) {
|
||||
// Drop key Q (drop 1)
|
||||
final ItemStack dropItem = cursorRule.apply(resultClicked.copy(), 1);
|
||||
final ItemStack dropItem = cursorRule.apply(resultClicked.clone(), 1);
|
||||
final boolean dropResult = player.dropItem(dropItem);
|
||||
clickResult.setCancel(!dropResult);
|
||||
if (dropResult) {
|
||||
@ -476,7 +476,7 @@ public class InventoryClickProcessor {
|
||||
} else if (button == 1) {
|
||||
// Ctrl + Drop key Q (drop all)
|
||||
final int amount = cursorRule.getAmount(resultClicked);
|
||||
final ItemStack dropItem = clickedRule.apply(resultClicked.copy(), amount);
|
||||
final ItemStack dropItem = clickedRule.apply(resultClicked.clone(), amount);
|
||||
final boolean dropResult = player.dropItem(dropItem);
|
||||
clickResult.setCancel(!dropResult);
|
||||
if (dropResult) {
|
||||
|
@ -567,6 +567,7 @@ public class ItemStack implements DataContainer, PublicCloneable<ItemStack> {
|
||||
*
|
||||
* @return a cloned item stack with a different identifier
|
||||
*/
|
||||
@NotNull
|
||||
@Override
|
||||
public ItemStack clone() {
|
||||
try {
|
||||
|
@ -107,11 +107,11 @@ public class PlayerDiggingListener {
|
||||
dropItem(player, handItem, ItemStack.getAirItem());
|
||||
} else {
|
||||
// Drop a single item, need a copy
|
||||
ItemStack droppedItemStack2 = handItem.copy();
|
||||
ItemStack droppedItemStack2 = handItem.clone();
|
||||
|
||||
droppedItemStack2 = stackingRule.apply(droppedItemStack2, dropAmount);
|
||||
|
||||
handItem = handItem.copy(); // Force the copy
|
||||
handItem = handItem.clone(); // Force the copy
|
||||
handItem = stackingRule.apply(handItem, handAmount - dropAmount);
|
||||
|
||||
dropItem(player, droppedItemStack2, handItem);
|
||||
|
@ -67,7 +67,7 @@ public class PlayerPositionListener {
|
||||
|
||||
final Position currentPosition = player.getPosition().copy();
|
||||
Position newPosition = new Position(x, y, z, yaw, pitch);
|
||||
final Position cachedPosition = newPosition.copy();
|
||||
final Position cachedPosition = newPosition.clone();
|
||||
|
||||
PlayerMoveEvent playerMoveEvent = new PlayerMoveEvent(player, newPosition);
|
||||
player.callEvent(PlayerMoveEvent.class, playerMoveEvent);
|
||||
|
@ -222,6 +222,7 @@ public class BlockPosition implements PublicCloneable<BlockPosition> {
|
||||
return clone();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public BlockPosition clone() {
|
||||
try {
|
||||
|
@ -197,6 +197,7 @@ public class Position implements PublicCloneable<Position> {
|
||||
this.z = position.getZ();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Position clone() {
|
||||
try {
|
||||
|
@ -1,8 +1,9 @@
|
||||
package net.minestom.server.utils;
|
||||
|
||||
import net.minestom.server.utils.clone.PublicCloneable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Vector {
|
||||
public class Vector implements PublicCloneable<Vector> {
|
||||
|
||||
private static final double epsilon = 0.000001;
|
||||
|
||||
@ -103,7 +104,7 @@ public class Vector {
|
||||
this.y = vector.getY();
|
||||
this.z = vector.getZ();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the magnitude of the vector, defined as sqrt(x^2+y^2+z^2). The
|
||||
* value of this method is not cached and uses a costly square-root
|
||||
@ -246,12 +247,23 @@ public class Vector {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a new vector with the same values.
|
||||
*
|
||||
* @return vector
|
||||
* @deprecated use {@link #clone()}
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public Vector copy() {
|
||||
return new Vector(x, y, z);
|
||||
return clone();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Vector clone() {
|
||||
try {
|
||||
return (Vector) super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
e.printStackTrace();
|
||||
throw new IllegalStateException("Weird thing happened");
|
||||
}
|
||||
}
|
||||
|
||||
public float getX() {
|
||||
|
@ -1,10 +1,14 @@
|
||||
package net.minestom.server.utils.clone;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Convenient interface to expose {@link Object#clone()} publicly with a generic.
|
||||
*
|
||||
* @param <T> the type to clone
|
||||
*/
|
||||
public interface PublicCloneable<T> extends Cloneable {
|
||||
|
||||
@NotNull
|
||||
T clone();
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ public class RelativeBlockPosition extends RelativeLocation<BlockPosition> {
|
||||
@Override
|
||||
public BlockPosition fromRelativePosition(Entity entity) {
|
||||
if (!relativeX && !relativeY && !relativeZ) {
|
||||
return location.copy();
|
||||
return location.clone();
|
||||
}
|
||||
final Position entityPosition = entity.getPosition();
|
||||
|
||||
|
@ -19,7 +19,7 @@ public class RelativeVec extends RelativeLocation<Vector> {
|
||||
@Override
|
||||
public Vector fromRelativePosition(@Nullable Entity entity) {
|
||||
if (!relativeX && !relativeY && !relativeZ) {
|
||||
return location.copy();
|
||||
return location.clone();
|
||||
}
|
||||
final Position entityPosition = entity.getPosition();
|
||||
|
||||
|
@ -60,7 +60,6 @@ public class Main {
|
||||
//MojangAuth.init();
|
||||
|
||||
minecraftServer.start("0.0.0.0", 25565, PlayerInit.getResponseDataConsumer());
|
||||
|
||||
//Runtime.getRuntime().addShutdownHook(new Thread(MinecraftServer::stopCleanly));
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@ import demo.generator.ChunkGeneratorDemo;
|
||||
import demo.generator.NoiseTestGenerator;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.benchmark.BenchmarkManager;
|
||||
import net.minestom.server.chat.ColoredText;
|
||||
import net.minestom.server.data.Data;
|
||||
import net.minestom.server.data.DataImpl;
|
||||
import net.minestom.server.entity.*;
|
||||
@ -25,9 +24,7 @@ import net.minestom.server.inventory.InventoryType;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.Material;
|
||||
import net.minestom.server.network.ConnectionManager;
|
||||
import net.minestom.server.network.packet.server.play.PlayerListHeaderAndFooterPacket;
|
||||
import net.minestom.server.ping.ResponseDataConsumer;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import net.minestom.server.utils.Position;
|
||||
import net.minestom.server.utils.Vector;
|
||||
import net.minestom.server.utils.time.TimeUnit;
|
||||
@ -49,7 +46,7 @@ public class PlayerInit {
|
||||
NoiseTestGenerator noiseTestGenerator = new NoiseTestGenerator();
|
||||
instanceContainer = instanceManager.createInstanceContainer(DimensionType.OVERWORLD);
|
||||
instanceContainer.enableAutoChunkLoad(true);
|
||||
instanceContainer.setChunkGenerator(chunkGeneratorDemo);
|
||||
instanceContainer.setChunkGenerator(noiseTestGenerator);
|
||||
|
||||
// Load some chunks beforehand
|
||||
final int loopStart = -10;
|
||||
@ -65,14 +62,14 @@ public class PlayerInit {
|
||||
System.out.println("slot inv: " + slot)0;
|
||||
inventoryConditionResult.setCancel(slot == 3);
|
||||
});*/
|
||||
inventory.setItemStack(3, new ItemStack(Material.DIAMOND, (byte) 34));
|
||||
//inventory.setItemStack(3, new ItemStack(Material.DIAMOND, (byte) 34));
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
ConnectionManager connectionManager = MinecraftServer.getConnectionManager();
|
||||
BenchmarkManager benchmarkManager = MinecraftServer.getBenchmarkManager();
|
||||
|
||||
MinecraftServer.getSchedulerManager().buildTask(() -> {
|
||||
/*MinecraftServer.getSchedulerManager().buildTask(() -> {
|
||||
long ramUsage = benchmarkManager.getUsedMemory();
|
||||
ramUsage /= 1e6; // bytes to MB
|
||||
|
||||
@ -87,7 +84,7 @@ public class PlayerInit {
|
||||
PacketUtils.sendGroupedPacket(connectionManager.getOnlinePlayers(), playerListHeaderAndFooterPacket);
|
||||
}
|
||||
|
||||
}).repeat(10, TimeUnit.TICK).schedule();
|
||||
}).repeat(10, TimeUnit.TICK).schedule();*/
|
||||
|
||||
connectionManager.onPacketReceive((player, packetController, packet) -> {
|
||||
// Listen to all received packet
|
||||
@ -108,13 +105,13 @@ public class PlayerInit {
|
||||
if (entity instanceof EntityCreature) {
|
||||
EntityCreature creature = (EntityCreature) entity;
|
||||
creature.damage(DamageType.fromPlayer(player), 0);
|
||||
Vector velocity = player.getPosition().copy().getDirection().multiply(3);
|
||||
Vector velocity = player.getPosition().clone().getDirection().multiply(3);
|
||||
velocity.setY(3f);
|
||||
entity.setVelocity(velocity);
|
||||
player.sendMessage("You attacked an entity!");
|
||||
} else if (entity instanceof Player) {
|
||||
Player target = (Player) entity;
|
||||
Vector velocity = player.getPosition().copy().getDirection().multiply(4);
|
||||
Vector velocity = player.getPosition().clone().getDirection().multiply(4);
|
||||
velocity.setY(3.5f);
|
||||
target.setVelocity(velocity);
|
||||
target.damage(DamageType.fromPlayer(player), 5);
|
||||
@ -157,11 +154,11 @@ public class PlayerInit {
|
||||
player.addEventCallback(ItemDropEvent.class, event -> {
|
||||
ItemStack droppedItem = event.getItemStack();
|
||||
|
||||
Position position = player.getPosition().copy().add(0, 1.5f, 0);
|
||||
Position position = player.getPosition().clone().add(0, 1.5f, 0);
|
||||
ItemEntity itemEntity = new ItemEntity(droppedItem, position);
|
||||
itemEntity.setPickupDelay(500, TimeUnit.MILLISECOND);
|
||||
itemEntity.setInstance(player.getInstance());
|
||||
Vector velocity = player.getPosition().copy().getDirection().multiply(6);
|
||||
Vector velocity = player.getPosition().clone().getDirection().multiply(6);
|
||||
itemEntity.setVelocity(velocity);
|
||||
|
||||
EntityZombie entityZombie = new EntityZombie(new Position(0, 41, 0));
|
||||
@ -178,15 +175,13 @@ public class PlayerInit {
|
||||
event.setSpawningInstance(instanceContainer);
|
||||
int x = Math.abs(ThreadLocalRandom.current().nextInt()) % 1000 - 250;
|
||||
int z = Math.abs(ThreadLocalRandom.current().nextInt()) % 1000 - 250;
|
||||
player.setRespawnPoint(new Position(x, 45f, z));
|
||||
player.setRespawnPoint(new Position(0, 70f, 0));
|
||||
|
||||
player.getInventory().addInventoryCondition((p, slot, clickType, inventoryConditionResult) -> {
|
||||
if (slot == -999)
|
||||
return;
|
||||
inventoryConditionResult.setCancel(false);
|
||||
ItemStack itemStack = p.getInventory().getItemStack(slot);
|
||||
final int value = itemStack.getData() != null ? itemStack.getData().get("testc") : 0;
|
||||
System.out.println("slot player: " + slot + " : " + itemStack.getMaterial() + " : " + value);
|
||||
System.out.println("test "+itemStack.getIdentifier()+" "+itemStack.getData());
|
||||
});
|
||||
});
|
||||
|
||||
@ -199,7 +194,7 @@ public class PlayerInit {
|
||||
itemStack.setData(data);
|
||||
player.getInventory().addItemStack(itemStack);
|
||||
|
||||
//player.getInventory().addItemStack(new ItemStack(Material.STONE, (byte)64));
|
||||
//player.getInventory().addItemStack(new ItemStack(Material.STONE, (byte) 32));
|
||||
});
|
||||
|
||||
player.addEventCallback(PlayerUseItemEvent.class, useEvent -> {
|
||||
|
@ -42,7 +42,7 @@ public class ChickenCreature extends EntityChicken {
|
||||
addEventCallback(EntityAttackEvent.class, event -> {
|
||||
//System.out.println("CALL ATTACK");
|
||||
LivingEntity entity = (LivingEntity) event.getTarget();
|
||||
Vector velocity = getPosition().copy().getDirection().multiply(6);
|
||||
Vector velocity = getPosition().clone().getDirection().multiply(6);
|
||||
velocity.setY(4f);
|
||||
entity.damage(DamageType.fromEntity(this), -1);
|
||||
entity.setVelocity(velocity);
|
||||
|
@ -18,7 +18,7 @@ public class Structure {
|
||||
return;
|
||||
if (bPos.getZ() + pos.getZ() >= Chunk.CHUNK_SIZE_Z || bPos.getZ() + pos.getZ() < 0)
|
||||
return;
|
||||
batch.setBlock(bPos.copy().add(pos), block);
|
||||
batch.setBlock(bPos.clone().add(pos), block);
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user