upgrade userdev and neoforge, display message from env detector above hotbar, damage item if not in creative, only add data to server side chunks and add 10 durability to env detector

This commit is contained in:
Robin Bärtschi 2024-06-02 16:15:30 +02:00
parent 5c05e112d7
commit eda52283d6
5 changed files with 16 additions and 10 deletions

View File

@ -3,7 +3,7 @@ plugins {
id 'eclipse'
id 'idea'
id 'maven-publish'
id 'net.neoforged.gradle.userdev' version '7.0.136'
id 'net.neoforged.gradle.userdev' version '7.0.138'
}
version = mod_version

View File

@ -12,7 +12,7 @@ minecraft_version=1.20.6
# as they do not follow standard versioning conventions.
minecraft_version_range=[1.20.6,1.21)
# The Neo version must agree with the Minecraft version to get a valid artifact
neo_version=20.6.99-beta
neo_version=20.6.100-beta
# The Neo version range can use any version of Neo as bounds
neo_version_range=[20,)
# The loader version range can only use the major version of FML as bounds

View File

@ -13,16 +13,17 @@ import robaertschi.environmenttech.data.attachments.ETAttachments;
public class ETChunkEvents {
@SubscribeEvent()
public static void onChunkLoad(ChunkEvent.Load event) {
if (event.getLevel().isClientSide()) return;
if (event.isNewChunk() && event.getChunk() instanceof LevelChunk levelChunk && !event.getChunk().hasData(ETAttachments.ENV)) {
if (levelChunk.getStatus() != ChunkStatus.FULL) {
return;
}
int random = event.getLevel().getRandom().nextIntBetweenInclusive(Config.minEnvForNewChunk, Config.maxEnvForNewChunk);
EnvironmentTech.LOGGER.info("New Chunk, set random to {}", random);
EnvironmentTech.LOGGER.debug("New Chunk, set random to {}", random);
event.getChunk().setData(ETAttachments.ENV, random);
} else if (!event.getChunk().hasData(ETAttachments.ENV)) {
int random = event.getLevel().getRandom().nextIntBetweenInclusive(Config.minEnvForNewChunk, Config.maxEnvForNewChunk);
EnvironmentTech.LOGGER.info("Chunk without data, set random to {}", random);
EnvironmentTech.LOGGER.debug("Chunk without data, set random to {}", random);
event.getChunk().setData(ETAttachments.ENV, random);
}
}

View File

@ -33,7 +33,7 @@ public class ETItems {
public static final DeferredItem<Item> EXAMPLE_ITEM = ITEMS.registerSimpleItem("example_item", new Item.Properties().food(new FoodProperties.Builder()
.alwaysEdible().nutrition(1).saturationModifier(2f).build()));
public static final DeferredItem<EnvDetectorItem> ENV_DETECTOR_ITEM = ITEMS.registerItem("env_detector", EnvDetectorItem::new, new Item.Properties().stacksTo(1));
public static final DeferredItem<EnvDetectorItem> ENV_DETECTOR_ITEM = ITEMS.registerItem("env_detector", EnvDetectorItem::new, new Item.Properties().stacksTo(1).durability(10));
public static final DeferredHolder<CreativeModeTab, CreativeModeTab> EXAMPLE_TAB = CREATIVE_MODE_TABS.register("example_tab", () -> CreativeModeTab.builder()

View File

@ -1,5 +1,6 @@
package robaertschi.environmenttech.level.item;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResultHolder;
@ -18,19 +19,23 @@ public class EnvDetectorItem extends Item {
super(properties);
}
@Override
public void onUseTick(Level pLevel, LivingEntity pLivingEntity, ItemStack pStack, int pRemainingUseDuration) {
}
@Override
public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) {
if (pLevel.isClientSide()) return InteractionResultHolder.pass(pPlayer.getItemInHand(pUsedHand));
var chunk = pLevel.getChunk(pPlayer.blockPosition());
if (chunk.hasData(ETAttachments.ENV)) {
pPlayer.sendSystemMessage(Component.literal("Chunk has " + chunk.getData(ETAttachments.ENV) + " ENV"));
pPlayer.displayClientMessage(Component.literal("Chunk has " + chunk.getData(ETAttachments.ENV) + " ENV").withStyle(ChatFormatting.GREEN), true);
} else {
pPlayer.sendSystemMessage(Component.literal("Warning: This chunk does not have the ENV attachment"));
pPlayer.displayClientMessage(Component.literal("Warning: This chunk does not have the ENV attachment, please report this to the Author of the Mod.").withStyle(ChatFormatting.YELLOW), true);
}
if (!pPlayer.isCreative()) {
pPlayer.getItemInHand(pUsedHand).hurtAndBreak(1, pLevel.getRandom(), pPlayer, () -> {
pPlayer.getItemInHand(pUsedHand).setCount(0);
});
}
return InteractionResultHolder.consume(pPlayer.getItemInHand(pUsedHand));