-
Notifications
You must be signed in to change notification settings - Fork 99
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
Fix drops #563
Fix drops #563
Changes from 32 commits
70d5ca6
5bbe32d
87df5b8
58a1173
f7cb915
8ec8599
30d2fb2
d071eb1
14c9317
45ffb0b
387bcd4
fde046f
9fca6b9
129d571
64c5c2b
be9574a
49f0072
fdb4d1e
0a814d1
ba0cf2b
40b8e86
24c3c7a
313acc2
2571bd6
54bbdef
9592959
277f46a
e70af9e
cd288b7
8d1e55c
266d232
a61e3a9
e413525
9c3faff
e32cffc
200b50b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,8 +205,8 @@ module.exports.server = function (serv, { version }) { | |
|
||
const notudf = i => typeof i !== 'undefined' | ||
|
||
serv.selector = (type, opt) => { | ||
if (['all', 'random', 'near', 'entity'].indexOf(type) === -1) { throw new UserError('serv.selector(): type must be either [all, random, near, or entity]') } | ||
serv.selector = (type, opt, selfEntityId) => { | ||
if (['all', 'random', 'self', 'near', 'entity'].indexOf(type) === -1) { throw new UserError('serv.selector(): type must be either [all, random, self, near, or entity]') } | ||
|
||
const count = opt.count !== undefined | ||
? opt.count | ||
|
@@ -215,6 +215,7 @@ module.exports.server = function (serv, { version }) { | |
const pos = opt.pos | ||
let sample | ||
if (type === 'all') sample = serv.players | ||
else if (type === 'self') sample = serv.players.filter(p => p.id === selfEntityId) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this needs to be added in doc |
||
else if (type === 'random' || type === 'near') sample = serv.players.filter(p => p.health !== 0) | ||
else if (type === 'entity') sample = Object.keys(serv.entities).map(k => serv.entities[k]) | ||
|
||
|
@@ -287,17 +288,18 @@ module.exports.server = function (serv, { version }) { | |
else return sample.slice(count) // Negative, returns from end | ||
} | ||
|
||
serv.selectorString = (str, pos, world, allowUser = true) => { | ||
serv.selectorString = (str, pos, world, allowUser = true, ctxEntityId) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add in doc |
||
if (pos) pos = pos.clone() | ||
const player = serv.getPlayer(str) | ||
if (!player && str[0] !== '@') return [] | ||
else if (player) return allowUser ? [player] : [] | ||
const match = str.match(/^@([arpe])(?:\[([^\]]+)\])?$/) | ||
const match = str.match(/^@([arspe])(?:\[([^\]]+)\])?$/) | ||
if (match[1] === 'r' && !pos) throw new UserError('Can\'t found nearest players') | ||
if (match === null) throw new UserError('Invalid selector format') | ||
const typeConversion = { | ||
a: 'all', | ||
r: 'random', | ||
s: 'self', | ||
p: 'near', | ||
e: 'entity' | ||
} | ||
|
@@ -346,7 +348,7 @@ module.exports.server = function (serv, { version }) { | |
} | ||
}) | ||
|
||
return serv.selector(type, data) | ||
return serv.selector(type, data, ctxEntityId) | ||
} | ||
|
||
serv.posFromString = (str, pos) => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ module.exports.server = (serv, { version }) => { | |
const itemPlaceHandlers = new Map() | ||
serv.placeItem = (data) => { | ||
const handler = itemPlaceHandlers.get(data.item.type) | ||
return handler ? handler(data) : { id: data.item.type, data: data.item.metadata } | ||
return handler ? handler(data) : (serv.supportFeature('theFlattening') ? {} : { id: data.item.type, data: data.item.metadata }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is wrong There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think I understand what you mean. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why would we return nothing after the flattening ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. placeItem is currently only used in the same file, handling the block_place packet from clients. It's destructured into id and data after being called, then the id is used to find the corresponding blocks. Blocks with the same ID as an item is not the corresponding block for the item when the item does not have a corresponding block post-flattening, so I return an empty object with ID undefined such that the wrong block won't be placed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In pre-flattening times however this can be used as a fallback for items that somehow don't have an item place handler as the old assumption is indeed true. |
||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nbtItem.tag.name would be undefined otherwise and would cause an error on join.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it's defined and not empty you're losing the value
but it sounds like the problem should be fixed wherever the error was happening instead of here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nbtItem.tag.name is intended to be empty. It's just somehow lost during the saving process, and I don't know prismarine-nbt enough to figure out what caused it to omit this empty string value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you do if (nbtItem.tag && nbtItem.tag == undefined)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did it