-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
196 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...m/sekwah/sekclib/core/util/ColorUtil.java → ...va/com/sekwah/sekclib/util/ColorUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../sekwah/sekclib/core/util/ModelUtils.java → ...a/com/sekwah/sekclib/util/ModelUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 20 additions & 1 deletion
21
forge-testmod/src/main/java/com/sekwah/sekclibtest/SekCLibTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,32 @@ | ||
package com.sekwah.sekclibtest; | ||
|
||
import com.sekwah.sekclib.capabilitysync.capabilitysync.RegisterCapabilitySyncEvent; | ||
import com.sekwah.sekclibtest.capabilities.CapabilityHandler; | ||
import com.sekwah.sekclibtest.capabilities.IDiamondData; | ||
import com.sekwah.sekclibtest.capabilities.DiamondData; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraftforge.common.capabilities.RegisterCapabilitiesEvent; | ||
import net.minecraftforge.eventbus.api.IEventBus; | ||
import net.minecraftforge.fml.common.Mod; | ||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; | ||
|
||
@Mod(SekCLibTest.MOD_ID) | ||
@Mod.EventBusSubscriber(modid = SekCLibTest.MOD_ID) | ||
public class SekCLibTest { | ||
public static final String MOD_ID = "sekclibtest"; | ||
|
||
public SekCLibTest() { | ||
System.out.println("HELLO"); | ||
// You can do it this way or use a EventBusSubscriber that points to the MOD bus. | ||
IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus(); | ||
eventBus.addListener(this::registerCapabilities); | ||
eventBus.addListener(this::registerCapabilitySync); | ||
} | ||
|
||
private void registerCapabilities(RegisterCapabilitiesEvent event) { | ||
event.register(IDiamondData.class); | ||
} | ||
|
||
public void registerCapabilitySync(RegisterCapabilitySyncEvent event) { | ||
event.registerPlayerCap(new ResourceLocation(SekCLibTest.MOD_ID, "test_data"), CapabilityHandler.DIAMOND_DATA, DiamondData.class); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
forge-testmod/src/main/java/com/sekwah/sekclibtest/capabilities/CapabilityHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.sekwah.sekclibtest.capabilities; | ||
|
||
import com.sekwah.sekclibtest.SekCLibTest; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraftforge.common.capabilities.Capability; | ||
import net.minecraftforge.common.capabilities.CapabilityManager; | ||
import net.minecraftforge.common.capabilities.CapabilityToken; | ||
import net.minecraftforge.event.AttachCapabilitiesEvent; | ||
import net.minecraftforge.event.entity.living.LivingHurtEvent; | ||
import net.minecraftforge.eventbus.api.SubscribeEvent; | ||
import net.minecraftforge.fml.common.Mod; | ||
|
||
@Mod.EventBusSubscriber(modid = SekCLibTest.MOD_ID) | ||
public class CapabilityHandler { | ||
public static final Capability<IDiamondData> DIAMOND_DATA = CapabilityManager.get(new CapabilityToken<>() {}); | ||
|
||
@SubscribeEvent | ||
public static void attachCapability(AttachCapabilitiesEvent<Entity> event) { | ||
event.addCapability(new ResourceLocation(SekCLibTest.MOD_ID, "diamond_infected_data"), new DiamondData()); | ||
} | ||
|
||
@SubscribeEvent | ||
public static void livingHurt(LivingHurtEvent event) { | ||
var entity = event.getEntity(); | ||
entity.getCapability(DIAMOND_DATA).ifPresent(testData -> { | ||
testData.setDiamond(true); | ||
}); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
forge-testmod/src/main/java/com/sekwah/sekclibtest/capabilities/DiamondData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.sekwah.sekclibtest.capabilities; | ||
|
||
import com.sekwah.sekclib.capabilitysync.capabilitysync.annotation.Sync; | ||
import net.minecraft.core.Direction; | ||
import net.minecraftforge.common.capabilities.Capability; | ||
import net.minecraftforge.common.capabilities.ICapabilityProvider; | ||
import net.minecraftforge.common.util.LazyOptional; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class DiamondData implements IDiamondData, ICapabilityProvider { | ||
|
||
|
||
private final LazyOptional<IDiamondData> holder = LazyOptional.of(() -> this); | ||
|
||
@Sync(syncGlobally = true) | ||
private boolean diamondMode = false; | ||
|
||
@NotNull | ||
@Override | ||
public <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) { | ||
return CapabilityHandler.DIAMOND_DATA.orEmpty(cap, holder); | ||
} | ||
|
||
@Override | ||
public boolean isDiamond() { | ||
return this.diamondMode; | ||
} | ||
|
||
@Override | ||
public void setDiamond(boolean isDiamond) { | ||
this.diamondMode = isDiamond; | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
forge-testmod/src/main/java/com/sekwah/sekclibtest/capabilities/IDiamondData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.sekwah.sekclibtest.capabilities; | ||
|
||
public interface IDiamondData { | ||
boolean isDiamond(); | ||
void setDiamond(boolean isDiamond); | ||
} |
39 changes: 39 additions & 0 deletions
39
...testmod/src/main/java/com/sekwah/sekclibtest/mixins/client/LivingEntityRendererMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.sekwah.sekclibtest.mixins.client; | ||
|
||
import com.sekwah.sekclibtest.SekCLibTest; | ||
import com.sekwah.sekclibtest.capabilities.CapabilityHandler; | ||
import net.minecraft.client.model.EntityModel; | ||
import net.minecraft.client.renderer.RenderType; | ||
import net.minecraft.client.renderer.entity.LivingEntityRenderer; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.entity.animal.Wolf; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(LivingEntityRenderer.class) | ||
public class LivingEntityRendererMixin<T extends LivingEntity, M extends EntityModel<T>> { | ||
|
||
@Shadow protected M model; | ||
private ResourceLocation diamond = new ResourceLocation(SekCLibTest.MOD_ID, "textures/entity/diamond_block.png"); | ||
|
||
@Inject(method = "getRenderType", at = @At("HEAD"), cancellable = true) | ||
protected void getEntityTexture(T target, boolean p_115323_, boolean p_115324_, boolean p_115325_, CallbackInfoReturnable<RenderType> cir) { | ||
target.getCapability(CapabilityHandler.DIAMOND_DATA).ifPresent(diamondInfectedData -> { | ||
if(diamondInfectedData.isDiamond()) { | ||
ResourceLocation resourcelocation = diamond; | ||
if (p_115324_) { | ||
cir.setReturnValue(RenderType.itemEntityTranslucentCull(resourcelocation)); | ||
} else if (p_115323_) { | ||
cir.setReturnValue(this.model.renderType(resourcelocation)); | ||
} else { | ||
cir.setReturnValue(p_115325_ ? RenderType.outline(resourcelocation) : null); | ||
} | ||
cir.cancel(); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
COMMENT: This file exists purely for dev time, | ||
anything added here should be mirrored in the build.gradle. | ||
MixinConfigs: mixins.sekclibtest.json |
Binary file added
BIN
+9.82 KB
...testmod/src/main/resources/assets/sekclibtest/textures/entity/diamond_block.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.