From 1d368e3adcdeab24ee417ff7f56275007f585785 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Tue, 14 Apr 2026 19:43:37 -0500 Subject: [PATCH] Add DhApiBlockStateWrapperCreatedEvent --- .../DhApiBlockStateWrapperCreatedEvent.java | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 api/src/main/java/com/seibel/distanthorizons/api/methods/events/abstractEvents/DhApiBlockStateWrapperCreatedEvent.java diff --git a/api/src/main/java/com/seibel/distanthorizons/api/methods/events/abstractEvents/DhApiBlockStateWrapperCreatedEvent.java b/api/src/main/java/com/seibel/distanthorizons/api/methods/events/abstractEvents/DhApiBlockStateWrapperCreatedEvent.java new file mode 100644 index 000000000..8b0953019 --- /dev/null +++ b/api/src/main/java/com/seibel/distanthorizons/api/methods/events/abstractEvents/DhApiBlockStateWrapperCreatedEvent.java @@ -0,0 +1,123 @@ +/* + * This file is part of the Distant Horizons mod + * licensed under the GNU LGPL v3 License. + * + * Copyright (C) 2020 James Seibel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.seibel.distanthorizons.api.methods.events.abstractEvents; + +import com.seibel.distanthorizons.api.enums.rendering.EDhApiBlockMaterial; +import com.seibel.distanthorizons.api.interfaces.block.IDhApiBlockStateWrapper; +import com.seibel.distanthorizons.api.methods.events.interfaces.IDhApiEvent; +import com.seibel.distanthorizons.api.methods.events.interfaces.IDhApiEventParam; +import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiEventParam; + +/** + * Can be used to modify {@link IDhApiBlockStateWrapper}'s as they're created. + * This can be helpful for modded blocks that are mis-categorized by DH's base logic.

+ * + * Note: this is only fired once per {@link IDhApiBlockStateWrapper} that is created + * and those {@link IDhApiBlockStateWrapper} will only be created once per JVM session. + * + * @author James Seibel + * @version 2026-04-14 + * @since API 6.0.0 + * @see IDhApiBlockStateWrapper + */ +public abstract class DhApiBlockStateWrapperCreatedEvent implements IDhApiEvent +{ + public abstract void blockStateWrapperCreated(DhApiEventParam event); + + + //=========================// + // internal DH API methods // + //=========================// + + @Override + public final void fireEvent(DhApiEventParam event) { this.blockStateWrapperCreated(event); } + + + //==================// + // parameter object // + //==================// + + public static class EventParam implements IDhApiEventParam + { + /** + * A copy of the wrapper that will be created.
+ * Note: modifying this object won't change anything + * a new wrapper will be created after this event finishes. + */ + public final IDhApiBlockStateWrapper blockStateWrapper; + + private boolean overridesSet = false; + private EDhApiBlockMaterial blockMaterial = null; + private Integer opacity = null; + + + + //=============// + // constructor // + //=============// + + public EventParam(IDhApiBlockStateWrapper blockStateWrapper) + { + this.blockStateWrapper = blockStateWrapper; + } + + + + //=================// + // getters/setters // + //=================// + + /** if set this will override the value currently set in the given {@link IDhApiBlockStateWrapper} */ + public void setBlockMaterial(EDhApiBlockMaterial blockMaterial) + { + this.blockMaterial = blockMaterial; + this.overridesSet = true; + } + public EDhApiBlockMaterial getBlockMaterial() { return this.blockMaterial; } + + /** if set this will override the value currently set in the given {@link IDhApiBlockStateWrapper} */ + public void setOpacity(int opacity) + { + this.opacity = opacity; + this.overridesSet = true; + } + public Integer getOpacity() { return this.opacity; } + + /** If true then one or more options for this block were set to be changed */ + public boolean getOverridesSet() { return this.overridesSet; } + + + + /** + * Returns the same instance of this event. + * Copying this event isn't supported + * since the internal parameters must be mutated + * by API users in order to be tracked by DH's internal + * logic. + */ + @Override + public EventParam copy() { return this; } + + @Override + public boolean getCopyBeforeFire() { return false; } + + } + +} \ No newline at end of file