import { world, MinecraftEntityTypes, DynamicPropertiesDefinition } from "@minecraft/server";
const overworld = world.getDimension(`overworld`);
const formatTime = milliseconds => {
const seconds = Math.floor((milliseconds / 1000) % 60);
const minutes = Math.floor((milliseconds / 1000 / 60) % 60);
const hours = Math.floor((milliseconds / 1000 / 60 / 60) % 24);
return [
hours.toString().padStart(2, "0"),
minutes.toString().padStart(2, "0"),
seconds.toString().padStart(2, "0")
];
};
world.afterEvents.worldInitialize.subscribe((world) => {
let playerEntityProperties = new DynamicPropertiesDefinition();
playerEntityProperties.defineString("lastClaimedDaily", 13);
world.propertyRegistry.registerEntityTypeDynamicProperties(playerEntityProperties, MinecraftEntityTypes.player);
});
world.afterEvents.entityHitEntity.subscribe(data => {
if (data.hitBlock) return;
const npc = data.hitEntity;
let player = data.damagingEntity;
if (npc.hasTag('Dailyclaim')) {
if (!Number.parseInt(player.getDynamicProperty("lastClaimedDaily"))) player.setDynamicProperty("lastClaimedDaily", "0");
let timeSinceLastClaim = Date.now() - Number.parseInt(player.getDynamicProperty("lastClaimedDaily"));
if (timeSinceLastClaim > 86400000) {
player.playSound('random.levelup');
player.sendMessage('§7[§c!§7]:§a Daily Reward Claimed!'); //Change Claim Message Here
overworld.runCommandAsync(`give @a[name="${player.nameTag}"] netherite_scrap 2`);
player.setDynamicProperty("lastClaimedDaily", Date.now().toString());
} else {
player.playSound('random.glass');
let [hours, minutes, seconds] = formatTime(86400000 - timeSinceLastClaim);
player.sendMessage(`§7[§c!§7]: You've already claimed you Daily Reward! You can claim again in §3${hours} hours ${minutes} minutes ${seconds} seconds`); //Change Claimed Message Here
}
}
})```
#Daily Reward function isnt working?
1 messages · Page 1 of 1 (latest)
MinecraftEntityTypes has been moved from @minecraft/server to @minecraft/vanilla-data. You will need to learn how to bundle vanilla-data into your project so it ships with the pack and of course target it instead of @minecraft/server or change all instances to use strings such as minecraft:player.
Debug Result
There are 10 errors in this [code](#1173102811635007629 message).
Please read the attached file for the result.
Debug (Stable)
its saying this now
import { MinecraftEntityTypes } from "@minecraft/vanilla-data";
import { world, DynamicPropertiesDefinition } from "@minecraft/server";```
Because Dynamic Property registration is not a thing anymore, so DynamicPropertiesDefinition does not exist either.
it says this also
Because vanilla data is not actually a Minecraft native module.
It is a folder that you download and put it in your scripts. You would have to import it like a normal file
npm install @minecraft/vanilla-data
ohh
It will download a folder inside node_modules
Get that folder out of node_modules and put it on your scripts folder
Then use it like
import { .... } from "./vanilla-data/main.js"
Something like that, it's just an example
import { MinecraftEntityTypes } from "./vanilla-data";```
What is wrong
Click the vanilla data folder and send a ss
Click lib and send ss
Ok you would have to import it like this:
import { MinecraftEntityTypes } from './vanilla-data/lib/index.js'
And you don't need to use MinecraftEntityTypes from Minecraft vanilla data, you can use EntityTypes.getAll() from minecraft/server which is better.
oh ok thank you
Vanilla data could be useful for things like get all enchantments cuz there's not EnchantmentTypes.getAll()
...
^
nvm
i got it
Bro I told you it's not needed anymore xD, you can just use setDynamicProperty or get DynamicProperty without registering