fix: hotbar jank

This commit is contained in:
cha0s 2021-01-20 10:15:58 -06:00
parent 58baea68f2
commit 902adc9de2
2 changed files with 17 additions and 2 deletions

View File

@ -43,7 +43,22 @@ const Play = () => {
if (selfEntity) {
selfEntity.inputStream = inputStream;
}
socket.send(['Input', inputStream]);
const sending = inputStream.filter(({action}) => {
if (action.match(/^HotbarSlot(\d)/)) {
return false;
}
switch (action) {
case 'HotbarSlotNext':
case 'HotbarSlotPrevious':
return false;
default:
break;
}
return true;
});
if (sending.length > 0) {
socket.send(['Input', sending]);
}
}
}, 1000 / 60);
ref.current.focus();

View File

@ -17,7 +17,7 @@ export default () => class Controllable extends Trait {
const {action, value} = inputStream[i];
const normalized = 0 === value ? -1 : 1;
const hotbarMatch = action.match(/^HotbarSlot(\d)/);
if (hotbarMatch) {
if (hotbarMatch && value) {
this.entity.activeSlotIndex = (parseInt(hotbarMatch[1], 10) + 10) % 10;
}
switch (action) {