├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── etc ├── OpenModsFormatter.xml ├── model_to_hitboxes.py ├── notes.txt ├── open_mods_lib_dummy_jar.jar └── orientations │ ├── all.txt │ ├── four_directions.txt │ ├── none.txt │ ├── six_directions.txt │ ├── three_directions.txt │ ├── three_four_directions.txt │ ├── twelve_directions.txt │ └── two_directions.txt ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src ├── main ├── java │ └── openmods │ │ ├── GuiFactory.java │ │ ├── LibConfig.java │ │ ├── Log.java │ │ ├── Mods.java │ │ ├── OpenMods.java │ │ ├── Sounds.java │ │ ├── access │ │ ├── ApiFactory.java │ │ ├── ApiImplementation.java │ │ ├── ApiInstanceProvider.java │ │ ├── ApiProviderBase.java │ │ ├── ApiProviderRegistry.java │ │ └── ApiSingleton.java │ │ ├── api │ │ ├── IActivateAwareTile.java │ │ ├── IAddAwareTile.java │ │ ├── IBreakAwareTile.java │ │ ├── ICustomBreakDrops.java │ │ ├── ICustomHarvestDrops.java │ │ ├── ICustomPickItem.java │ │ ├── IHasGui.java │ │ ├── IInventoryCallback.java │ │ ├── IInventoryContainer.java │ │ ├── INeighbourAwareTile.java │ │ ├── INeighbourTeAwareTile.java │ │ ├── IPlaceAwareTile.java │ │ ├── IProxy.java │ │ ├── IResultListener.java │ │ ├── ISelectionAware.java │ │ ├── ISurfaceAttachment.java │ │ ├── IValueProvider.java │ │ ├── IValueReceiver.java │ │ └── VisibleForDocumentation.java │ │ ├── asm │ │ ├── FieldMatcher.java │ │ ├── MappedType.java │ │ ├── MethodMatcher.java │ │ ├── StopTransforming.java │ │ ├── TransformerState.java │ │ └── VisitorHelper.java │ │ ├── block │ │ ├── BlockRotationMode.java │ │ ├── BlockSelectionHandler.java │ │ ├── IBlockRotationMode.java │ │ ├── OpenBlock.java │ │ └── RotationAxis.java │ │ ├── calc │ │ ├── CalcState.java │ │ ├── CommandCalc.java │ │ ├── CommandCalcFactory.java │ │ ├── CommandExecutionException.java │ │ ├── CommandSyntaxException.java │ │ ├── EntityPlayerWrapper.java │ │ ├── HelpPrinter.java │ │ ├── ICommandComponent.java │ │ ├── IWhitespaceSplitter.java │ │ ├── MapCommandComponent.java │ │ ├── NestedCommandException.java │ │ ├── TerminalCommandComponent.java │ │ └── WhitespaceSplitters.java │ │ ├── colors │ │ ├── CYMK.java │ │ ├── ColorMeta.java │ │ ├── ColorUtils.java │ │ ├── ColoredModelProvider.java │ │ └── RGB.java │ │ ├── conditions │ │ ├── Conditions.java │ │ └── ICondition.java │ │ ├── config │ │ ├── BlockInstances.java │ │ ├── ConfigChangeListener.java │ │ ├── ConfigStorage.java │ │ ├── FieldProcessor.java │ │ ├── InstanceContainer.java │ │ ├── ItemInstances.java │ │ ├── game │ │ │ ├── AbstractFeatureManager.java │ │ │ ├── ConfigurableFeatureManager.java │ │ │ ├── FactoryRegistry.java │ │ │ ├── FeatureRegistry.java │ │ │ ├── GameRegistryObjectsProvider.java │ │ │ ├── ICustomItemModelProvider.java │ │ │ ├── IRegisterableBlock.java │ │ │ ├── IgnoreFeature.java │ │ │ ├── ModStartupHelper.java │ │ │ ├── RegisterBlock.java │ │ │ └── RegisterItem.java │ │ ├── gui │ │ │ └── OpenModsConfigScreen.java │ │ ├── properties │ │ │ ├── CommandConfig.java │ │ │ ├── ConfigProcessing.java │ │ │ ├── ConfigProperty.java │ │ │ ├── ConfigPropertyMeta.java │ │ │ ├── ConfigurationChange.java │ │ │ └── OnLineModifiable.java │ │ ├── simple │ │ │ ├── ClassFrontend.java │ │ │ ├── ConfigProcessor.java │ │ │ └── Entry.java │ │ └── simpler │ │ │ ├── Configurable.java │ │ │ └── ConfigurableClassAdapter.java │ │ ├── container │ │ ├── ContainerBase.java │ │ ├── ContainerInventory.java │ │ ├── ContainerInventoryProvider.java │ │ ├── FakeSlot.java │ │ └── ICustomSlot.java │ │ ├── core │ │ ├── Bootstrap.java │ │ ├── BundledJarUnpacker.java │ │ ├── OpenModsClassTransformer.java │ │ ├── OpenModsCore.java │ │ ├── OpenModsCorePlugin.java │ │ ├── OpenModsHook.java │ │ └── fixes │ │ │ └── HorseNullFix.java │ │ ├── entity │ │ ├── DelayedEntityLoadManager.java │ │ ├── EntityBlock.java │ │ ├── IEntityLoadListener.java │ │ └── renderer │ │ │ └── EntityBlockRenderer.java │ │ ├── events │ │ └── network │ │ │ └── BlockEventPacket.java │ │ ├── fakeplayer │ │ ├── BreakBlockAction.java │ │ ├── DropItemAction.java │ │ ├── FakePlayerPool.java │ │ ├── OpenModsFakePlayer.java │ │ └── UseItemAction.java │ │ ├── fixers │ │ ├── GenericInventoryTeFixerWalker.java │ │ ├── IFixerFactory.java │ │ ├── ItemInventoryWalker.java │ │ ├── ItemTagWalker.java │ │ ├── NestedItemInventoryWalker.java │ │ ├── NestedItemStackWalker.java │ │ ├── RegisterFixer.java │ │ └── ResourceDataWalker.java │ │ ├── gamelogic │ │ └── WorkerLogic.java │ │ ├── geometry │ │ ├── AabbBuilder.java │ │ ├── BlockSpaceTransform.java │ │ ├── BlockTextureTransform.java │ │ ├── BoundingBoxBuilder.java │ │ ├── BoundingBoxMap.java │ │ ├── Box2d.java │ │ ├── FaceClassifier.java │ │ ├── HalfAxis.java │ │ ├── Hitbox.java │ │ ├── HitboxManager.java │ │ ├── IHitboxSupplier.java │ │ ├── LocalDirections.java │ │ ├── Matrix2d.java │ │ ├── Orientation.java │ │ ├── OrientationInfoGenerator.java │ │ └── Permutation2d.java │ │ ├── gui │ │ ├── BaseGuiContainer.java │ │ ├── ClientGuiHandler.java │ │ ├── CommonGuiHandler.java │ │ ├── ComponentGui.java │ │ ├── DummyContainer.java │ │ ├── GuiConfigurableSlots.java │ │ ├── IComponentParent.java │ │ ├── Icon.java │ │ ├── SyncedGuiContainer.java │ │ ├── component │ │ │ ├── BaseComponent.java │ │ │ ├── BaseComposite.java │ │ │ ├── EmptyComposite.java │ │ │ ├── GuiComponentBook.java │ │ │ ├── GuiComponentButton.java │ │ │ ├── GuiComponentCheckbox.java │ │ │ ├── GuiComponentColorPicker.java │ │ │ ├── GuiComponentCraftingGrid.java │ │ │ ├── GuiComponentHBox.java │ │ │ ├── GuiComponentHCenter.java │ │ │ ├── GuiComponentIconButton.java │ │ │ ├── GuiComponentItemStack.java │ │ │ ├── GuiComponentItemStackSpinner.java │ │ │ ├── GuiComponentLabel.java │ │ │ ├── GuiComponentLevel.java │ │ │ ├── GuiComponentPalettePicker.java │ │ │ ├── GuiComponentPanel.java │ │ │ ├── GuiComponentProgress.java │ │ │ ├── GuiComponentRect.java │ │ │ ├── GuiComponentResizable.java │ │ │ ├── GuiComponentResizableComposite.java │ │ │ ├── GuiComponentSideSelector.java │ │ │ ├── GuiComponentSlider.java │ │ │ ├── GuiComponentSprite.java │ │ │ ├── GuiComponentSpriteButton.java │ │ │ ├── GuiComponentTab.java │ │ │ ├── GuiComponentTabWrapper.java │ │ │ ├── GuiComponentTankLevel.java │ │ │ ├── GuiComponentTextButton.java │ │ │ ├── GuiComponentTextbox.java │ │ │ ├── GuiComponentToggleButton.java │ │ │ ├── GuiComponentVCenter.java │ │ │ └── page │ │ │ │ ├── BookScaleConfig.java │ │ │ │ ├── ItemStackTocPage.java │ │ │ │ ├── PageBase.java │ │ │ │ ├── SectionPage.java │ │ │ │ ├── StandardRecipePage.java │ │ │ │ └── TitledPage.java │ │ ├── listener │ │ │ ├── IKeyTypedListener.java │ │ │ ├── IListenerBase.java │ │ │ ├── IMouseDownListener.java │ │ │ ├── IMouseDragListener.java │ │ │ ├── IMouseUpListener.java │ │ │ └── IValueChangedListener.java │ │ ├── logic │ │ │ ├── IValueUpdateAction.java │ │ │ ├── SyncObjectUpdateDispatcher.java │ │ │ ├── ValueCopyAction.java │ │ │ └── ValueUpdateDispatcher.java │ │ └── misc │ │ │ ├── BoxRenderer.java │ │ │ ├── IConfigurableGuiSlots.java │ │ │ ├── ISlotBackgroundRenderer.java │ │ │ ├── SidePicker.java │ │ │ └── Trackball.java │ │ ├── include │ │ ├── IExtendable.java │ │ ├── IncludeInterface.java │ │ ├── IncludeOverride.java │ │ └── IncludingClassVisitor.java │ │ ├── infobook │ │ ├── BookDocumentation.java │ │ ├── ICustomBookEntryProvider.java │ │ └── PageBuilder.java │ │ ├── integration │ │ ├── IIntegrationModule.java │ │ ├── Integration.java │ │ ├── IntegrationConditions.java │ │ ├── IntegrationModule.java │ │ └── modules │ │ │ └── ComputerCraftUtils.java │ │ ├── inventory │ │ ├── GenericInventory.java │ │ ├── IInventoryProvider.java │ │ ├── ItemInventory.java │ │ ├── ItemMover.java │ │ ├── ItemStackComparators.java │ │ ├── PlayerItemInventory.java │ │ ├── StackComparatorBuilder.java │ │ ├── StackEqualityTesterBuilder.java │ │ ├── TileEntityInventory.java │ │ └── comparator │ │ │ ├── ComparatorComponents.java │ │ │ └── EqualComponents.java │ │ ├── item │ │ ├── IMetaItem.java │ │ ├── IMetaItemFactory.java │ │ ├── ItemGeneric.java │ │ ├── ItemOpenBlock.java │ │ └── MetaGeneric.java │ │ ├── liquids │ │ ├── ContainerBucketFillHandler.java │ │ ├── GenericFluidCapabilityWrapper.java │ │ ├── GenericTank.java │ │ ├── SidedFluidCapabilityWrapper.java │ │ ├── SingleFluidBucketFillHandler.java │ │ └── SingleFluidBucketHandler.java │ │ ├── math │ │ └── Complex.java │ │ ├── model │ │ ├── BakedModelAdapter.java │ │ ├── MappedModelLoader.java │ │ ├── ModelTextureMap.java │ │ ├── ModelUpdater.java │ │ ├── ModelUtils.java │ │ ├── ModelWithDependencies.java │ │ ├── MultiLayerModel.java │ │ ├── PerspectiveAwareModel.java │ │ ├── eval │ │ │ ├── BakedEvalModel.java │ │ │ ├── EvalExpandModel.java │ │ │ ├── EvalModel.java │ │ │ ├── EvalModelBase.java │ │ │ ├── EvalModelState.java │ │ │ ├── EvaluatorFactory.java │ │ │ ├── ITransformEvaluator.java │ │ │ └── IVarExpander.java │ │ ├── itemstate │ │ │ ├── ISimpleStateItem.java │ │ │ ├── IStateItem.java │ │ │ ├── ItemStateModel.java │ │ │ ├── ItemStateOverrideList.java │ │ │ └── SimpleStateItemSetup.java │ │ ├── textureditem │ │ │ ├── IItemTexture.java │ │ │ ├── ItemTextureCapability.java │ │ │ ├── TexturedItemModel.java │ │ │ └── TexturedItemOverrides.java │ │ └── variant │ │ │ ├── Evaluator.java │ │ │ ├── VariantModel.java │ │ │ ├── VariantModelData.java │ │ │ ├── VariantModelState.java │ │ │ └── VariantSelectorData.java │ │ ├── movement │ │ ├── PlayerMovementEvent.java │ │ └── PlayerMovementManager.java │ │ ├── network │ │ ├── Dispatcher.java │ │ ├── ExtendedOutboundHandler.java │ │ ├── IPacketTargetSelector.java │ │ ├── event │ │ │ ├── EventDirection.java │ │ │ ├── NetworkEvent.java │ │ │ ├── NetworkEventCodec.java │ │ │ ├── NetworkEventDispatcher.java │ │ │ ├── NetworkEventEntry.java │ │ │ ├── NetworkEventInboundHandler.java │ │ │ ├── NetworkEventManager.java │ │ │ ├── NetworkEventMeta.java │ │ │ └── SerializableNetworkEvent.java │ │ ├── rpc │ │ │ ├── IRpcTarget.java │ │ │ ├── IRpcTargetProvider.java │ │ │ ├── MethodEntry.java │ │ │ ├── MethodParamsCodec.java │ │ │ ├── NullableArg.java │ │ │ ├── RpcCall.java │ │ │ ├── RpcCallCodec.java │ │ │ ├── RpcCallDispatcher.java │ │ │ ├── RpcCallInboundHandler.java │ │ │ ├── RpcIgnore.java │ │ │ ├── RpcProxyFactory.java │ │ │ ├── TargetTypeProvider.java │ │ │ └── targets │ │ │ │ ├── EntityRpcTarget.java │ │ │ │ ├── SyncRpcTarget.java │ │ │ │ └── TileEntityRpcTarget.java │ │ ├── senders │ │ │ ├── ExtPacketSenderFactory.java │ │ │ ├── FmlPacketSenderFactory.java │ │ │ ├── IPacketSender.java │ │ │ ├── ITargetedPacketSender.java │ │ │ ├── PacketSenderBase.java │ │ │ └── TargetedPacketSenderBase.java │ │ └── targets │ │ │ └── SelectMultiplePlayers.java │ │ ├── physics │ │ ├── Cloth.java │ │ ├── Constraint.java │ │ ├── FastVector.java │ │ └── Point.java │ │ ├── proxy │ │ ├── IOpenModsProxy.java │ │ ├── OpenClientProxy.java │ │ └── OpenServerProxy.java │ │ ├── recipe │ │ └── EnchantingRecipe.java │ │ ├── reflection │ │ ├── ClonerFactory.java │ │ ├── ConstructorAccess.java │ │ ├── FieldAccess.java │ │ ├── FieldAccessHelpers.java │ │ ├── InstanceFieldAccess.java │ │ ├── MethodAccess.java │ │ ├── ReflectionHelper.java │ │ ├── ReflectionLog.java │ │ ├── SafeClassLoad.java │ │ ├── TypeUtils.java │ │ ├── TypeVariableHolder.java │ │ ├── TypeVariableHolderHandler.java │ │ └── TypeVisitor.java │ │ ├── renderer │ │ ├── CachedRendererFactory.java │ │ ├── CommandGlDebug.java │ │ ├── DisplayListWrapper.java │ │ ├── DisposableDynamicTexture.java │ │ ├── DynamicTextureAtlas.java │ │ ├── ITileEntityModel.java │ │ ├── ManualDisplayList.java │ │ ├── PlayerBodyRenderEvent.java │ │ ├── PlayerRendererHookVisitor.java │ │ ├── PreWorldRenderHookVisitor.java │ │ ├── SimpleModelTileEntityRenderer.java │ │ ├── StencilRendererHandler.java │ │ ├── StenciledTextureRenderer.java │ │ ├── TessellatorPool.java │ │ ├── rotations │ │ │ └── TransformProvider.java │ │ └── shaders │ │ │ ├── ArraysHelper.java │ │ │ ├── BufferHelper.java │ │ │ ├── ShaderHelper.java │ │ │ ├── ShaderProgram.java │ │ │ └── ShaderProgramBuilder.java │ │ ├── serializable │ │ ├── IGenericSerializerProvider.java │ │ ├── IInstanceFactory.java │ │ ├── INbtSerializable.java │ │ ├── IObjectSerializer.java │ │ ├── ISerializable.java │ │ ├── ISerializerProvider.java │ │ ├── IStreamReadable.java │ │ ├── IStreamSerializable.java │ │ ├── IStreamWriteable.java │ │ ├── NbtSerializable.java │ │ ├── SerializerAdapters.java │ │ ├── SerializerRegistry.java │ │ ├── StreamSerializable.java │ │ ├── cls │ │ │ ├── ClassSerializerBuilder.java │ │ │ ├── ClassSerializersProvider.java │ │ │ ├── SerializableClass.java │ │ │ └── Serialize.java │ │ └── providers │ │ │ ├── ArraySerializerProvider.java │ │ │ ├── ClassSerializerProvider.java │ │ │ ├── EnumSerializerProvider.java │ │ │ ├── ListSerializerProvider.java │ │ │ ├── MapSerializerProvider.java │ │ │ ├── NullableCollectionSerializer.java │ │ │ └── SetSerializerProvider.java │ │ ├── shapes │ │ ├── DefaultShapeGenerator.java │ │ ├── IShapeGenerator.java │ │ ├── IShapeable.java │ │ ├── ShapeAxesGenerator.java │ │ ├── ShapeCuboidGenerator.java │ │ ├── ShapeCylinderGenerator.java │ │ ├── ShapeEquilateral2dGenerator.java │ │ ├── ShapePlanesGenerator.java │ │ └── ShapeSphereGenerator.java │ │ ├── source │ │ ├── ClassSourceCollector.java │ │ └── CommandSource.java │ │ ├── state │ │ ├── State.java │ │ └── StateContainer.java │ │ ├── structured │ │ ├── Command.java │ │ ├── ElementField.java │ │ ├── FieldContainer.java │ │ ├── ICustomCreateData.java │ │ ├── IStructureContainer.java │ │ ├── IStructureContainerFactory.java │ │ ├── IStructureElement.java │ │ ├── IStructureObserver.java │ │ ├── StructureField.java │ │ ├── StructureObserver.java │ │ ├── StructuredData.java │ │ ├── StructuredDataMaster.java │ │ └── StructuredDataSlave.java │ │ ├── sync │ │ ├── ISyncListener.java │ │ ├── ISyncMapProvider.java │ │ ├── ISyncableObject.java │ │ ├── ISyncableValueProvider.java │ │ ├── InboundSyncHandler.java │ │ ├── SyncChannelHolder.java │ │ ├── SyncMap.java │ │ ├── SyncMapClient.java │ │ ├── SyncMapEntity.java │ │ ├── SyncMapServer.java │ │ ├── SyncMapTile.java │ │ ├── SyncObjectScanner.java │ │ ├── SyncableBlock.java │ │ ├── SyncableBlockState.java │ │ ├── SyncableBoolean.java │ │ ├── SyncableByte.java │ │ ├── SyncableByteArray.java │ │ ├── SyncableDouble.java │ │ ├── SyncableEnum.java │ │ ├── SyncableFlags.java │ │ ├── SyncableFloat.java │ │ ├── SyncableInt.java │ │ ├── SyncableIntArray.java │ │ ├── SyncableItemStack.java │ │ ├── SyncableNBT.java │ │ ├── SyncableObjectBase.java │ │ ├── SyncableObjectType.java │ │ ├── SyncableObjectTypeRegistry.java │ │ ├── SyncableShort.java │ │ ├── SyncableSides.java │ │ ├── SyncableString.java │ │ ├── SyncableTank.java │ │ ├── SyncableUUID.java │ │ ├── SyncableUnsignedByte.java │ │ ├── SyncableVarInt.java │ │ └── drops │ │ │ ├── DropTagSerializer.java │ │ │ ├── DroppableTileEntity.java │ │ │ └── StoreOnDrop.java │ │ ├── tileentity │ │ ├── OpenTileEntity.java │ │ ├── SimpleNetTileEntity.java │ │ └── SyncedTileEntity.java │ │ ├── utils │ │ ├── AnnotationMap.java │ │ ├── BitSet.java │ │ ├── BlockManipulator.java │ │ ├── BlockNotifyFlags.java │ │ ├── BlockUtils.java │ │ ├── ByteUtils.java │ │ ├── CachedFactory.java │ │ ├── CachedInstanceFactory.java │ │ ├── CollectionUtils.java │ │ ├── CommandUtils.java │ │ ├── CommonRegistryCallbacks.java │ │ ├── CompatibilityUtils.java │ │ ├── Coord.java │ │ ├── CustomRecipeBase.java │ │ ├── Diagonal.java │ │ ├── DirUtils.java │ │ ├── EnchantmentUtils.java │ │ ├── EntityUtils.java │ │ ├── EnumUtils.java │ │ ├── FakeBlockAccess.java │ │ ├── FieldsSelector.java │ │ ├── ITester.java │ │ ├── InventoryUtils.java │ │ ├── ItemUtils.java │ │ ├── LazyValue.java │ │ ├── MCUtils.java │ │ ├── MathUtils.java │ │ ├── MiscUtils.java │ │ ├── ModIdentifier.java │ │ ├── ModVersionChecker.java │ │ ├── NbtUtils.java │ │ ├── NetUtils.java │ │ ├── ObjectTester.java │ │ ├── OptionalInt.java │ │ ├── PlayerUtils.java │ │ ├── RecipeUtils.java │ │ ├── RegistrationContextBase.java │ │ ├── SidedCommand.java │ │ ├── SidedInventoryAdapter.java │ │ ├── SidedItemHandlerAdapter.java │ │ ├── SimpleUnlistedProperty.java │ │ ├── SneakyThrower.java │ │ ├── Stack.java │ │ ├── StackUnderflowException.java │ │ ├── StackValidationException.java │ │ ├── StateTracker.java │ │ ├── StringUtils.java │ │ ├── TextureUtils.java │ │ ├── TranslationUtils.java │ │ ├── Units.java │ │ ├── VanillaAnvilLogic.java │ │ ├── VanillaEnchantLogic.java │ │ ├── Variant.java │ │ ├── WorldUtils.java │ │ ├── bitmap │ │ │ ├── BitMapUtils.java │ │ │ ├── IBitMap.java │ │ │ ├── IReadableBitMap.java │ │ │ ├── IRpcDirectionBitMap.java │ │ │ ├── IRpcIntBitMap.java │ │ │ └── IWriteableBitMap.java │ │ ├── bitstream │ │ │ ├── InputBitStream.java │ │ │ ├── InputBitStreamBase.java │ │ │ ├── InputVarBitStream.java │ │ │ ├── OutputBitStream.java │ │ │ └── OutputVarBitStream.java │ │ ├── io │ │ │ ├── BufferedResourceWrapper.java │ │ │ ├── FileLineReader.java │ │ │ ├── GameProfileSerializer.java │ │ │ ├── IByteSink.java │ │ │ ├── IByteSource.java │ │ │ ├── ILineReadMethod.java │ │ │ ├── INBTSerializer.java │ │ │ ├── INbtChecker.java │ │ │ ├── INbtReader.java │ │ │ ├── INbtWriter.java │ │ │ ├── ISerializer.java │ │ │ ├── IStreamReader.java │ │ │ ├── IStreamSerializer.java │ │ │ ├── IStreamWriter.java │ │ │ ├── IStringSerializer.java │ │ │ ├── InputBitStream.java │ │ │ ├── Locks.java │ │ │ ├── PacketChunker.java │ │ │ ├── StreamAdapters.java │ │ │ ├── StreamUtils.java │ │ │ ├── StringConversionException.java │ │ │ └── TypeRW.java │ │ └── render │ │ │ ├── FramebufferBlitter.java │ │ │ ├── GeometryUtils.java │ │ │ ├── MarkerClassGenerator.java │ │ │ ├── OpenGLUtils.java │ │ │ ├── ProjectionHelper.java │ │ │ └── RenderUtils.java │ │ ├── words │ │ ├── Alternative.java │ │ ├── IGenerator.java │ │ ├── Optional.java │ │ ├── Range.java │ │ ├── Sequence.java │ │ ├── Substitution.java │ │ ├── Terminal.java │ │ ├── Transformer.java │ │ └── Words.java │ │ └── world │ │ ├── DelayedActionTickHandler.java │ │ ├── DropCapture.java │ │ ├── IStructureGenProvider.java │ │ └── StructureRegistry.java └── resources │ ├── assets │ └── openmods │ │ ├── lang │ │ ├── en_us.lang │ │ ├── es_es.lang │ │ ├── pt_br.lang │ │ ├── ru_ru.lang │ │ └── zh_cn.lang │ │ ├── models │ │ └── block │ │ │ ├── cube_all_tinted.json │ │ │ ├── cube_tinted.json │ │ │ └── cube_top_tinted.json │ │ ├── recipes │ │ └── _factories.json │ │ ├── sounds.json │ │ ├── sounds │ │ └── pageturn.ogg │ │ └── textures │ │ └── gui │ │ ├── book.png │ │ └── components.png │ ├── mcmod.info │ └── pack.mcmeta └── test └── java └── openmods ├── calc └── WhitespaceSplitterTest.java ├── geometry ├── BlockRotationModeTest.java ├── BlockSpaceTransformTest.java ├── BlockTextureTransformTest.java ├── FaceClassifierTest.java ├── HalfAxisTest.java ├── LocalDirectionsTest.java ├── OrientationTest.java └── Permutation2dTestSuite.java ├── inventory ├── EqualTest.java ├── ItemMoverTest.java └── Utils.java ├── model ├── EvalModelTest.java └── VariantEvaluatorTest.java ├── reflection ├── ClonerFactoryTest.java ├── FunctionTypesTest.java └── TypeVariableHolderTest.java ├── serializable ├── ClassSerializerTest.java └── SerializableTest.java ├── shapes └── ShapesTest.java ├── structured └── StructuredTest.java └── utils ├── EnchantmentTest.java ├── StackTest.java └── io ├── BitStreamsTest.java └── VarBitStreamsTest.java /.gitattributes: -------------------------------------------------------------------------------- 1 | *.java text 2 | *.xml text 3 | *.info text 4 | *.lang text 5 | *.mcmeta text 6 | *.md text 7 | *.txt text 8 | *.properties text 9 | 10 | *.png -text 11 | *.ogg -text 12 | *.zip -text 13 | *.jar -text -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OpenMods Java Project .gitignore file 2 | # Last Authored: 20150816 3 | 4 | # Runtime output 5 | *.class 6 | *.log 7 | *.pid 8 | 9 | # Package Files 10 | *.jar 11 | *.war 12 | *.ear 13 | 14 | # Gradle 15 | .gradle/ 16 | build/ 17 | run/ 18 | repo/ 19 | 20 | # Eclipse 21 | .classpath 22 | .project 23 | .settings/ 24 | *.launch 25 | bin/ 26 | 27 | # IntelliJ IDEA 28 | *.iml 29 | *.iws 30 | *.ipr 31 | .idea/ 32 | 33 | # OS Garbage 34 | .DS_Store 35 | Thumbs.db 36 | desktop.ini 37 | 38 | # Misc 39 | download/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Open Mods 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | OpenModsLib 2 | =========== 3 | 4 | OpenModsLib is a work-in-progress library of all our common code from OpenBlocks and OpenPeripheral. It's purpose is to provide a common API for both the OpenMods Team to use for future mods, speeding up development and reducing redundent code, and also for others to use for their mods. Cutting out some of the hard work and leaving more time to write the important content. 5 | 6 | License 7 | - 8 | 9 | OpenModsLib is open source, have a look at the LICENCE file. 10 | -------------------------------------------------------------------------------- /etc/open_mods_lib_dummy_jar.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenMods/OpenModsLib/239bb8ad9421837cecebe77479b5acfd1583ceda/etc/open_mods_lib_dummy_jar.jar -------------------------------------------------------------------------------- /etc/orientations/four_directions.txt: -------------------------------------------------------------------------------- 1 | "xn_yp": {"y": 180}, // front: south, top: up 2 | "xp_yp": {}, // front: north, top: up 3 | "zn_yp": {"y": 270}, // front: west, top: up 4 | "zp_yp": {"y": 90}, // front: east, top: up 5 | -------------------------------------------------------------------------------- /etc/orientations/none.txt: -------------------------------------------------------------------------------- 1 | "xp_yp": {}, // front: north, top: up 2 | -------------------------------------------------------------------------------- /etc/orientations/six_directions.txt: -------------------------------------------------------------------------------- 1 | "xn_zp": {"x": 90, "y": 180}, // front: south, top: up 2 | "xp_yn": {"x": 180}, // front: down, top: north 3 | "xp_yp": {}, // front: up, top: south 4 | "xp_zn": {"x": 90}, // front: north, top: up 5 | "zn_xn": {"x": 90, "y": 270}, // front: west, top: up 6 | "zp_xp": {"x": 90, "y": 90}, // front: east, top: up 7 | -------------------------------------------------------------------------------- /etc/orientations/three_directions.txt: -------------------------------------------------------------------------------- 1 | "xp_yp": {}, // front: up, top: south 2 | "xp_zn": {"x": 90}, // front: north, top: up 3 | "zn_xn": {"x": 90, "y": 270}, // front: west, top: up 4 | -------------------------------------------------------------------------------- /etc/orientations/three_four_directions.txt: -------------------------------------------------------------------------------- 1 | "xn_yp": {"y": 180}, // front: up, top: north 2 | "xn_zn": {"x": 270, "y": 180}, // front: north, top: down 3 | "xp_yp": {}, // front: up, top: south 4 | "xp_zn": {"x": 90}, // front: north, top: up 5 | "yn_xn": {{ "transform": { "rotation": [{"z": 90}, {"y": 180}]}}}, // front: west, top: north 6 | "yn_zn": {{ "transform": { "rotation": [{"z": 270}, {"x": 270}]}}}, // front: north, top: east 7 | "yp_xn": {{ "transform": { "rotation": [{"z": 90}]}}}, // front: west, top: south 8 | "yp_zn": {{ "transform": { "rotation": [{"z": 90}, {"x": 270}]}}}, // front: north, top: west 9 | "zn_xn": {"x": 90, "y": 270}, // front: west, top: up 10 | "zn_yp": {"y": 270}, // front: up, top: east 11 | "zp_xn": {"x": 270, "y": 90}, // front: west, top: down 12 | "zp_yp": {"y": 90}, // front: up, top: west 13 | -------------------------------------------------------------------------------- /etc/orientations/twelve_directions.txt: -------------------------------------------------------------------------------- 1 | "xn_yn": {"x": 180, "y": 180}, // front: down, top: south 2 | "xn_yp": {"y": 180}, // front: up, top: north 3 | "xn_zp": {"x": 90, "y": 180}, // front: south, top: up 4 | "xp_yn": {"x": 180}, // front: down, top: north 5 | "xp_yp": {}, // front: up, top: south 6 | "xp_zn": {"x": 90}, // front: north, top: up 7 | "zn_xn": {"x": 90, "y": 270}, // front: west, top: up 8 | "zn_yp": {"y": 270}, // front: up, top: east 9 | "zn_yn": {"x": 180, "y": 270}, // front: down, top: west 10 | "zp_xp": {"x": 90, "y": 90}, // front: east, top: up 11 | "zp_yn": {"x": 180, "y": 90}, // front: down, top: east 12 | "zp_yp": {"y": 90}, // front: up, top: west 13 | -------------------------------------------------------------------------------- /etc/orientations/two_directions.txt: -------------------------------------------------------------------------------- 1 | "xp_yp": {}, // front: north, top: up 2 | "zn_yp": {"y": 270}, // front: west, top: up 3 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | mod_version=0.12.2 2 | next_mod_version=0.13 3 | mc_ver=1.12.2 4 | forge_ver=14.23.4.2705 5 | mcp_mappings=snapshot_20171003 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenMods/OpenModsLib/239bb8ad9421837cecebe77479b5acfd1583ceda/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jan 03 19:36:05 CET 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip 7 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'OpenModsLib' -------------------------------------------------------------------------------- /src/main/java/openmods/GuiFactory.java: -------------------------------------------------------------------------------- 1 | package openmods; 2 | 3 | import com.google.common.collect.ImmutableSet; 4 | import java.util.Set; 5 | import net.minecraft.client.Minecraft; 6 | import net.minecraft.client.gui.GuiScreen; 7 | import net.minecraftforge.fml.client.IModGuiFactory; 8 | import openmods.config.gui.OpenModsConfigScreen; 9 | 10 | public class GuiFactory implements IModGuiFactory { 11 | 12 | public static class ConfigScreen extends OpenModsConfigScreen { 13 | public ConfigScreen(GuiScreen parent) { 14 | super(parent, OpenMods.MODID, "OpenModsLib"); 15 | } 16 | } 17 | 18 | @Override 19 | public void initialize(Minecraft minecraftInstance) {} 20 | 21 | @Override 22 | public Set runtimeGuiCategories() { 23 | return ImmutableSet.of(); 24 | } 25 | 26 | @Override 27 | public boolean hasConfigGui() { 28 | return true; 29 | } 30 | 31 | @Override 32 | public GuiScreen createConfigGui(GuiScreen parentScreen) { 33 | return new ConfigScreen(parentScreen); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/openmods/LibConfig.java: -------------------------------------------------------------------------------- 1 | package openmods; 2 | 3 | import openmods.config.properties.ConfigProperty; 4 | import openmods.config.properties.OnLineModifiable; 5 | 6 | public class LibConfig { 7 | @OnLineModifiable 8 | @ConfigProperty(category = "debug", name = "fakePlayerCountThreshold", comment = "Maximum fake player pool that doesn't produce warning") 9 | public static int fakePlayerThreshold = 10; 10 | 11 | @OnLineModifiable 12 | @ConfigProperty(category = "feature", name = "fakePlayerBlockBreakTools", comment = "List of tools used for checking effective during block breaking") 13 | public static String[] toolProbes = new String[] { "minecraft:diamond_pickaxe", "minecraft:diamond_shovel", "minecraft:diamond_axe", "minecraft:diamond_sword", "minecraft:shears" }; 14 | 15 | @OnLineModifiable 16 | @ConfigProperty(category = "debug", name = "dropsDebug", comment = "Control printing of stacktraces in case of unharvested drops") 17 | public static boolean dropsDebug; 18 | 19 | @ConfigProperty(category = "feature", name = "calculatorCommands", comment = "Enables command line calculator") 20 | public static boolean enableCalculatorCommands = true; 21 | 22 | @ConfigProperty(category = "debug", name = "tessellatorPoolLimit", comment = "Maximum allowed size of tessellator pool") 23 | public static int tessellatorPoolLimit = 20; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/openmods/Sounds.java: -------------------------------------------------------------------------------- 1 | package openmods; 2 | 3 | import net.minecraft.util.ResourceLocation; 4 | import net.minecraft.util.SoundEvent; 5 | import net.minecraftforge.event.RegistryEvent; 6 | import net.minecraftforge.fml.common.Mod.EventBusSubscriber; 7 | import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; 8 | import net.minecraftforge.fml.common.registry.GameRegistry.ObjectHolder; 9 | import net.minecraftforge.registries.IForgeRegistry; 10 | 11 | @ObjectHolder(OpenMods.MODID) 12 | @EventBusSubscriber 13 | public class Sounds { 14 | @ObjectHolder("pageturn") 15 | public static final SoundEvent PAGE_TURN = null; 16 | 17 | @SubscribeEvent 18 | public static void registerSounds(RegistryEvent.Register evt) { 19 | final IForgeRegistry registry = evt.getRegistry(); 20 | registerSound(registry, "pageturn"); 21 | } 22 | 23 | private static void registerSound(IForgeRegistry registry, String id) { 24 | final ResourceLocation resourceLocation = OpenMods.location(id); 25 | registry.register(new SoundEvent(resourceLocation).setRegistryName(resourceLocation)); 26 | } 27 | } -------------------------------------------------------------------------------- /src/main/java/openmods/access/ApiImplementation.java: -------------------------------------------------------------------------------- 1 | package openmods.access; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.TYPE) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface ApiImplementation { 11 | public boolean includeSuper() default true; 12 | 13 | public boolean cacheable() default true; 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/openmods/access/ApiProviderBase.java: -------------------------------------------------------------------------------- 1 | package openmods.access; 2 | 3 | import com.google.common.reflect.TypeToken; 4 | 5 | public abstract class ApiProviderBase { 6 | 7 | @SuppressWarnings("serial") 8 | private final Class markerType = (new TypeToken(getClass()) {}).getRawType(); 9 | 10 | private final ApiProviderRegistry apiRegistry; 11 | 12 | public ApiProviderBase(ApiProviderRegistry apiRegistry) { 13 | this.apiRegistry = apiRegistry; 14 | } 15 | 16 | public ApiProviderBase() { 17 | this.apiRegistry = new ApiProviderRegistry<>(markerType); 18 | } 19 | 20 | public void registerClass(Class cls) { 21 | apiRegistry.registerClass(cls); 22 | } 23 | 24 | public void registerInstance(T obj) { 25 | apiRegistry.registerInstance(obj); 26 | } 27 | 28 | public T getApi(Class cls) { 29 | return apiRegistry.getApi(cls); 30 | } 31 | 32 | public boolean isApiPresent(Class cls) { 33 | return apiRegistry.isApiPresent(cls); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/openmods/access/ApiSingleton.java: -------------------------------------------------------------------------------- 1 | package openmods.access; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.TYPE) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface ApiSingleton { 11 | public boolean includeSuper() default true; 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/openmods/api/IActivateAwareTile.java: -------------------------------------------------------------------------------- 1 | package openmods.api; 2 | 3 | import net.minecraft.entity.player.EntityPlayer; 4 | import net.minecraft.util.EnumFacing; 5 | import net.minecraft.util.EnumHand; 6 | 7 | public interface IActivateAwareTile { 8 | public boolean onBlockActivated(EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ); 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/openmods/api/IAddAwareTile.java: -------------------------------------------------------------------------------- 1 | package openmods.api; 2 | 3 | public interface IAddAwareTile { 4 | public void onAdded(); 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/openmods/api/IBreakAwareTile.java: -------------------------------------------------------------------------------- 1 | package openmods.api; 2 | 3 | public interface IBreakAwareTile { 4 | public void onBlockBroken(); 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/openmods/api/ICustomBreakDrops.java: -------------------------------------------------------------------------------- 1 | package openmods.api; 2 | 3 | import java.util.List; 4 | import net.minecraft.item.ItemStack; 5 | 6 | public interface ICustomBreakDrops { 7 | public List getDrops(List originalDrops); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/openmods/api/ICustomHarvestDrops.java: -------------------------------------------------------------------------------- 1 | package openmods.api; 2 | 3 | import java.util.List; 4 | import net.minecraft.block.state.IBlockState; 5 | import net.minecraft.entity.player.EntityPlayer; 6 | import net.minecraft.item.ItemStack; 7 | 8 | public interface ICustomHarvestDrops { 9 | 10 | boolean suppressBlockHarvestDrops(); 11 | 12 | void addHarvestDrops(EntityPlayer player, List drops, IBlockState blockState, int fortune, boolean isSilkTouch); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/openmods/api/ICustomPickItem.java: -------------------------------------------------------------------------------- 1 | package openmods.api; 2 | 3 | import javax.annotation.Nonnull; 4 | import net.minecraft.entity.player.EntityPlayer; 5 | import net.minecraft.item.ItemStack; 6 | 7 | public interface ICustomPickItem { 8 | @Nonnull 9 | public ItemStack getPickBlock(EntityPlayer player); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/openmods/api/IHasGui.java: -------------------------------------------------------------------------------- 1 | package openmods.api; 2 | 3 | import net.minecraft.entity.player.EntityPlayer; 4 | 5 | public interface IHasGui { 6 | public Object getServerGui(EntityPlayer player); 7 | 8 | public Object getClientGui(EntityPlayer player); 9 | 10 | public boolean canOpenGui(EntityPlayer player); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/openmods/api/IInventoryCallback.java: -------------------------------------------------------------------------------- 1 | package openmods.api; 2 | 3 | import net.minecraft.inventory.IInventory; 4 | import openmods.utils.OptionalInt; 5 | 6 | public interface IInventoryCallback { 7 | public void onInventoryChanged(IInventory inventory, OptionalInt slotNumber); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/openmods/api/IInventoryContainer.java: -------------------------------------------------------------------------------- 1 | package openmods.api; 2 | 3 | import net.minecraft.inventory.IInventory; 4 | 5 | public interface IInventoryContainer { 6 | public IInventory[] getInternalInventories(); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/openmods/api/INeighbourAwareTile.java: -------------------------------------------------------------------------------- 1 | package openmods.api; 2 | 3 | import net.minecraft.block.Block; 4 | import net.minecraft.util.math.BlockPos; 5 | 6 | public interface INeighbourAwareTile { 7 | 8 | public void onNeighbourChanged(BlockPos neighbourPos, Block neigbourBlock); 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/openmods/api/INeighbourTeAwareTile.java: -------------------------------------------------------------------------------- 1 | package openmods.api; 2 | 3 | import net.minecraft.util.math.BlockPos; 4 | 5 | public interface INeighbourTeAwareTile { 6 | public void onNeighbourTeChanged(BlockPos pos); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/openmods/api/IPlaceAwareTile.java: -------------------------------------------------------------------------------- 1 | package openmods.api; 2 | 3 | import javax.annotation.Nonnull; 4 | import net.minecraft.block.state.IBlockState; 5 | import net.minecraft.entity.EntityLivingBase; 6 | import net.minecraft.item.ItemStack; 7 | 8 | public interface IPlaceAwareTile { 9 | public void onBlockPlacedBy(IBlockState state, EntityLivingBase placer, @Nonnull ItemStack stack); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/openmods/api/IProxy.java: -------------------------------------------------------------------------------- 1 | package openmods.api; 2 | 3 | public interface IProxy { 4 | public void preInit(); 5 | 6 | public void init(); 7 | 8 | public void postInit(); 9 | 10 | public void registerRenderInformation(); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/openmods/api/IResultListener.java: -------------------------------------------------------------------------------- 1 | package openmods.api; 2 | 3 | public interface IResultListener { 4 | public void onSuccess(); 5 | 6 | public void onFailure(); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/openmods/api/ISelectionAware.java: -------------------------------------------------------------------------------- 1 | package openmods.api; 2 | 3 | import net.minecraft.util.math.BlockPos; 4 | import net.minecraft.world.World; 5 | import net.minecraftforge.client.event.DrawBlockHighlightEvent; 6 | 7 | public interface ISelectionAware { 8 | boolean onSelected(World world, BlockPos blockPos, DrawBlockHighlightEvent evt); 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/openmods/api/ISurfaceAttachment.java: -------------------------------------------------------------------------------- 1 | package openmods.api; 2 | 3 | import net.minecraft.util.EnumFacing; 4 | 5 | public interface ISurfaceAttachment { 6 | public EnumFacing getSurfaceDirection(); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/openmods/api/IValueProvider.java: -------------------------------------------------------------------------------- 1 | package openmods.api; 2 | 3 | @FunctionalInterface 4 | public interface IValueProvider { 5 | public T getValue(); 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/openmods/api/IValueReceiver.java: -------------------------------------------------------------------------------- 1 | package openmods.api; 2 | 3 | @FunctionalInterface 4 | public interface IValueReceiver { 5 | public void setValue(T value); 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/openmods/api/VisibleForDocumentation.java: -------------------------------------------------------------------------------- 1 | package openmods.api; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Marker for any documenting mod. 10 | * Note: this does not have any effect in OpenModsLib 11 | */ 12 | @Target(ElementType.TYPE) 13 | @Retention(RetentionPolicy.RUNTIME) 14 | public @interface VisibleForDocumentation { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/openmods/asm/FieldMatcher.java: -------------------------------------------------------------------------------- 1 | package openmods.asm; 2 | 3 | import net.minecraftforge.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper; 4 | 5 | public class FieldMatcher { 6 | private final String clsName; 7 | private final String description; 8 | private final String srgName; 9 | private final String mcpName; 10 | 11 | public FieldMatcher(String clsName, String description, String mcpName, String srgName) { 12 | this.clsName = clsName; 13 | this.description = description; 14 | this.srgName = srgName; 15 | this.mcpName = mcpName; 16 | } 17 | 18 | public boolean match(String fieldName, String fieldDesc) { 19 | if (!fieldDesc.equals(description)) return false; 20 | if (fieldName.equals(mcpName)) return true; 21 | if (!VisitorHelper.useSrgNames()) return false; 22 | String mapped = FMLDeobfuscatingRemapper.INSTANCE.mapFieldName(clsName, fieldName, fieldDesc); 23 | return mapped.equals(srgName); 24 | } 25 | } -------------------------------------------------------------------------------- /src/main/java/openmods/asm/MappedType.java: -------------------------------------------------------------------------------- 1 | package openmods.asm; 2 | 3 | import org.objectweb.asm.Type; 4 | 5 | public class MappedType { 6 | 7 | private final String clsName; 8 | 9 | public static MappedType of(Class cls) { 10 | return new MappedType(cls.getName()); 11 | } 12 | 13 | public static MappedType of(String clsName) { 14 | return new MappedType(clsName); 15 | } 16 | 17 | private MappedType(String clsName) { 18 | this.clsName = VisitorHelper.getMappedName(clsName.replace('.', '/')); 19 | } 20 | 21 | public String name() { 22 | return clsName; 23 | } 24 | 25 | public Type type() { 26 | return Type.getObjectType(clsName); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/openmods/asm/MethodMatcher.java: -------------------------------------------------------------------------------- 1 | package openmods.asm; 2 | 3 | import net.minecraftforge.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper; 4 | 5 | public class MethodMatcher { 6 | private final String clsName; 7 | private final String description; 8 | private final String srgName; 9 | private final String mcpName; 10 | 11 | public MethodMatcher(String clsName, String description, String mcpName, String srgName) { 12 | this.clsName = clsName; 13 | this.description = description; 14 | this.srgName = srgName; 15 | this.mcpName = mcpName; 16 | } 17 | 18 | public MethodMatcher(MappedType cls, String description, String mcpName, String srgName) { 19 | this(cls.name(), description, mcpName, srgName); 20 | } 21 | 22 | public boolean match(String methodName, String methodDesc) { 23 | if (!methodDesc.equals(description)) return false; 24 | if (methodName.equals(mcpName)) return true; 25 | if (!VisitorHelper.useSrgNames()) return false; 26 | String mapped = FMLDeobfuscatingRemapper.INSTANCE.mapMethodName(clsName, methodName, methodDesc); 27 | return mapped.equals(srgName); 28 | } 29 | 30 | @Override 31 | public String toString() { 32 | return String.format("Matcher: %s.[%s,%s] %s", clsName, srgName, mcpName, description); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /src/main/java/openmods/asm/StopTransforming.java: -------------------------------------------------------------------------------- 1 | package openmods.asm; 2 | 3 | public class StopTransforming extends RuntimeException { 4 | private static final long serialVersionUID = -8222603827170240869L; 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/openmods/asm/TransformerState.java: -------------------------------------------------------------------------------- 1 | package openmods.asm; 2 | 3 | public enum TransformerState { 4 | DISABLED, 5 | ENABLED, 6 | ACTIVATED, 7 | FINISHED, 8 | FAILED; 9 | } -------------------------------------------------------------------------------- /src/main/java/openmods/block/BlockSelectionHandler.java: -------------------------------------------------------------------------------- 1 | package openmods.block; 2 | 3 | import net.minecraft.block.Block; 4 | import net.minecraft.util.math.BlockPos; 5 | import net.minecraft.util.math.RayTraceResult; 6 | import net.minecraft.world.World; 7 | import net.minecraftforge.client.event.DrawBlockHighlightEvent; 8 | import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; 9 | import openmods.api.ISelectionAware; 10 | 11 | public class BlockSelectionHandler { 12 | 13 | @SubscribeEvent 14 | public void onHighlightDraw(DrawBlockHighlightEvent evt) { 15 | final RayTraceResult mop = evt.getTarget(); 16 | 17 | if (mop != null && mop.typeOfHit == RayTraceResult.Type.BLOCK) { 18 | 19 | final World world = evt.getPlayer().world; 20 | final BlockPos blockPos = mop.getBlockPos(); 21 | final Block block = world.getBlockState(blockPos).getBlock(); 22 | 23 | if (block instanceof ISelectionAware) { 24 | final boolean result = ((ISelectionAware)block).onSelected(world, blockPos, evt); 25 | evt.setCanceled(result); 26 | } 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/openmods/block/RotationAxis.java: -------------------------------------------------------------------------------- 1 | package openmods.block; 2 | 3 | import net.minecraft.util.EnumFacing; 4 | 5 | class RotationAxis { 6 | public static final EnumFacing[] NO_AXIS = {}; 7 | public static final EnumFacing[] SINGLE_AXIS = { EnumFacing.UP, EnumFacing.DOWN }; 8 | public static final EnumFacing[] THREE_AXIS = EnumFacing.VALUES; 9 | } -------------------------------------------------------------------------------- /src/main/java/openmods/calc/CommandExecutionException.java: -------------------------------------------------------------------------------- 1 | package openmods.calc; 2 | 3 | import com.google.common.base.Joiner; 4 | import com.google.common.base.Strings; 5 | import com.google.common.collect.Lists; 6 | import java.util.List; 7 | 8 | public class CommandExecutionException extends NestedCommandException { 9 | private static final long serialVersionUID = -781052257944634757L; 10 | 11 | public CommandExecutionException(String message, Object... args) { 12 | super(message, args); 13 | } 14 | 15 | public CommandExecutionException(Throwable t) { 16 | super("openmodslib.command.calc_error", getThrowableCause(t)); 17 | } 18 | 19 | private static String getThrowableCause(Throwable t) { 20 | final List causes = Lists.newArrayList(); 21 | Throwable current = t; 22 | while (current != null) { 23 | causes.add(Strings.nullToEmpty(current.getMessage())); 24 | current = current.getCause(); 25 | } 26 | 27 | return Joiner.on("', caused by '").join(causes); 28 | } 29 | 30 | @Override 31 | protected String contents() { 32 | return "openmodslib.command.calc_runtime_error_path"; 33 | } 34 | } -------------------------------------------------------------------------------- /src/main/java/openmods/calc/CommandSyntaxException.java: -------------------------------------------------------------------------------- 1 | package openmods.calc; 2 | 3 | public class CommandSyntaxException extends NestedCommandException { 4 | private static final long serialVersionUID = -781052257944634757L; 5 | 6 | public CommandSyntaxException(String message, Object... args) { 7 | super(message, args); 8 | } 9 | 10 | @Override 11 | protected String contents() { 12 | return "openmodslib.command.calc_syntax_error_path"; 13 | } 14 | } -------------------------------------------------------------------------------- /src/main/java/openmods/calc/HelpPrinter.java: -------------------------------------------------------------------------------- 1 | package openmods.calc; 2 | 3 | import com.google.common.base.Preconditions; 4 | import com.google.common.collect.Lists; 5 | import java.util.List; 6 | 7 | public class HelpPrinter { 8 | 9 | private final List path = Lists.newArrayList(); 10 | 11 | private boolean first = true; 12 | 13 | private final StringBuilder result = new StringBuilder(); 14 | 15 | public void push(String name) { 16 | path.add(name); 17 | } 18 | 19 | public void pop() { 20 | Preconditions.checkState(!path.isEmpty()); 21 | path.remove(path.size() - 1); 22 | } 23 | 24 | public void print(String contents) { 25 | if (!first) 26 | result.append(" OR\n"); 27 | 28 | first = false; 29 | 30 | for (String p : path) { 31 | result.append(p); 32 | result.append(' '); 33 | } 34 | result.append(contents); 35 | } 36 | 37 | public String generate() { 38 | return result.toString(); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/openmods/calc/ICommandComponent.java: -------------------------------------------------------------------------------- 1 | package openmods.calc; 2 | 3 | import java.util.List; 4 | import net.minecraft.command.ICommandSender; 5 | 6 | public interface ICommandComponent { 7 | public void execute(ICommandSender sender, IWhitespaceSplitter args); 8 | 9 | public ICommandComponent partialyExecute(IWhitespaceSplitter args); 10 | 11 | public List getTabCompletions(IWhitespaceSplitter args); 12 | 13 | public void help(HelpPrinter printer); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/openmods/calc/IWhitespaceSplitter.java: -------------------------------------------------------------------------------- 1 | package openmods.calc; 2 | 3 | public interface IWhitespaceSplitter { 4 | public String getNextPart(); 5 | 6 | public String getTail(); 7 | 8 | public boolean isFinished(); 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/openmods/calc/NestedCommandException.java: -------------------------------------------------------------------------------- 1 | package openmods.calc; 2 | 3 | import com.google.common.base.Joiner; 4 | import com.google.common.collect.Lists; 5 | import java.util.List; 6 | import net.minecraft.util.text.ITextComponent; 7 | import net.minecraft.util.text.TextComponentTranslation; 8 | 9 | public abstract class NestedCommandException extends RuntimeException { 10 | private static final long serialVersionUID = 601967437864511783L; 11 | 12 | private final Object[] args; 13 | private final List path = Lists.newArrayList(); 14 | 15 | public NestedCommandException(String message, Object... args) { 16 | super(message); 17 | this.args = args; 18 | } 19 | 20 | public NestedCommandException(Throwable cause, String message, Object... args) { 21 | super(message, cause); 22 | this.args = args; 23 | } 24 | 25 | public NestedCommandException pushCommandName(String name) { 26 | path.add(name); 27 | return this; 28 | } 29 | 30 | protected String getPath() { 31 | return Joiner.on("::").join(Lists.reverse(path)); 32 | } 33 | 34 | protected abstract String contents(); 35 | 36 | public ITextComponent getChatComponent() { 37 | return new TextComponentTranslation(contents(), getPath()) 38 | .appendSibling(new TextComponentTranslation(getMessage(), args)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/openmods/calc/TerminalCommandComponent.java: -------------------------------------------------------------------------------- 1 | package openmods.calc; 2 | 3 | import java.util.List; 4 | 5 | public abstract class TerminalCommandComponent implements ICommandComponent { 6 | 7 | private final String help; 8 | 9 | public TerminalCommandComponent(String help) { 10 | this.help = help; 11 | } 12 | 13 | @Override 14 | public ICommandComponent partialyExecute(IWhitespaceSplitter args) { 15 | throw new CommandSyntaxException("openmodslib.command.no_subcommands"); 16 | } 17 | 18 | @Override 19 | public List getTabCompletions(IWhitespaceSplitter args) { 20 | return null; 21 | } 22 | 23 | @Override 24 | public void help(HelpPrinter printer) { 25 | printer.print(help); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/openmods/colors/CYMK.java: -------------------------------------------------------------------------------- 1 | package openmods.colors; 2 | 3 | public class CYMK { 4 | private float cyan, yellow, magenta, key; 5 | 6 | public CYMK(float c, float y, float m, float k) { 7 | this.cyan = c; 8 | this.yellow = y; 9 | this.magenta = m; 10 | this.key = k; 11 | } 12 | 13 | public float getCyan() { 14 | return cyan; 15 | } 16 | 17 | public void setCyan(float cyan) { 18 | this.cyan = cyan; 19 | } 20 | 21 | public float getYellow() { 22 | return yellow; 23 | } 24 | 25 | public void setYellow(float yellow) { 26 | this.yellow = yellow; 27 | } 28 | 29 | public float getMagenta() { 30 | return magenta; 31 | } 32 | 33 | public void setMagenta(float magenta) { 34 | this.magenta = magenta; 35 | } 36 | 37 | public float getKey() { 38 | return key; 39 | } 40 | 41 | public void setKey(float key) { 42 | this.key = key; 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /src/main/java/openmods/colors/ColorUtils.java: -------------------------------------------------------------------------------- 1 | package openmods.colors; 2 | 3 | import com.google.common.base.Preconditions; 4 | 5 | public class ColorUtils { 6 | public static int bitmaskToVanilla(int color) { 7 | int high = Integer.numberOfLeadingZeros(color); 8 | int low = Integer.numberOfTrailingZeros(color); 9 | Preconditions.checkArgument(high == 31 - low && low <= 16, "Invalid color value: %sb", Integer.toBinaryString(color)); 10 | return low; 11 | } 12 | 13 | public static ColorMeta findNearestColor(RGB target, int tolernace) { 14 | ColorMeta result = null; 15 | int distSq = Integer.MAX_VALUE; 16 | 17 | for (ColorMeta meta : ColorMeta.VALUES) { 18 | final int currentDistSq = meta.rgbWrap.distance(target); 19 | if (currentDistSq < distSq) { 20 | result = meta; 21 | distSq = currentDistSq; 22 | } 23 | } 24 | 25 | return (distSq < 3 * tolernace * tolernace)? result : null; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/openmods/colors/ColoredModelProvider.java: -------------------------------------------------------------------------------- 1 | package openmods.colors; 2 | 3 | import net.minecraft.client.renderer.block.model.ModelResourceLocation; 4 | import net.minecraft.item.Item; 5 | import net.minecraft.util.ResourceLocation; 6 | import openmods.config.game.ICustomItemModelProvider; 7 | 8 | public class ColoredModelProvider implements ICustomItemModelProvider { 9 | @Override 10 | public void addCustomItemModels(Item item, ResourceLocation itemId, IModelRegistrationSink modelsOut) { 11 | for (ColorMeta meta : ColorMeta.VALUES) { 12 | modelsOut.register(meta.vanillaBlockId, new ModelResourceLocation(itemId, "inventory_" + meta.name)); 13 | } 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/openmods/conditions/Conditions.java: -------------------------------------------------------------------------------- 1 | package openmods.conditions; 2 | 3 | public class Conditions { 4 | public static ICondition any(final ICondition... conditions) { 5 | return () -> { 6 | for (ICondition c : conditions) 7 | if (c.check()) return true; 8 | 9 | return false; 10 | }; 11 | } 12 | 13 | public static ICondition all(final ICondition... conditions) { 14 | return () -> { 15 | for (ICondition c : conditions) 16 | if (!c.check()) return false; 17 | 18 | return true; 19 | }; 20 | } 21 | 22 | public static ICondition not(final ICondition condition) { 23 | return () -> !condition.check(); 24 | } 25 | 26 | public static ICondition alwaysTrue() { 27 | return () -> true; 28 | } 29 | 30 | public static ICondition alwaysFalse() { 31 | return () -> false; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/openmods/conditions/ICondition.java: -------------------------------------------------------------------------------- 1 | package openmods.conditions; 2 | 3 | @FunctionalInterface 4 | public interface ICondition { 5 | public boolean check(); 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/openmods/config/BlockInstances.java: -------------------------------------------------------------------------------- 1 | package openmods.config; 2 | 3 | import net.minecraft.block.Block; 4 | 5 | public interface BlockInstances extends InstanceContainer { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/openmods/config/ConfigChangeListener.java: -------------------------------------------------------------------------------- 1 | package openmods.config; 2 | 3 | import net.minecraftforge.common.config.Configuration; 4 | import net.minecraftforge.fml.client.event.ConfigChangedEvent.OnConfigChangedEvent; 5 | import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; 6 | 7 | public class ConfigChangeListener { 8 | 9 | private final String modId; 10 | private final Configuration config; 11 | 12 | public ConfigChangeListener(String modId, Configuration config) { 13 | this.modId = modId; 14 | this.config = config; 15 | } 16 | 17 | @SubscribeEvent 18 | public void onConfigChange(OnConfigChangedEvent evt) { 19 | if (modId.equals(evt.getModID())) config.save(); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/openmods/config/InstanceContainer.java: -------------------------------------------------------------------------------- 1 | package openmods.config; 2 | 3 | public interface InstanceContainer { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/openmods/config/ItemInstances.java: -------------------------------------------------------------------------------- 1 | package openmods.config; 2 | 3 | import net.minecraft.item.Item; 4 | 5 | public interface ItemInstances extends InstanceContainer { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/openmods/config/game/AbstractFeatureManager.java: -------------------------------------------------------------------------------- 1 | package openmods.config.game; 2 | 3 | import java.util.Set; 4 | 5 | public abstract class AbstractFeatureManager { 6 | 7 | public static final String CATEGORY_ITEMS = "items"; 8 | 9 | public static final String CATEGORY_BLOCKS = "blocks"; 10 | 11 | public abstract Set getCategories(); 12 | 13 | public abstract Set getFeaturesInCategory(String category); 14 | 15 | public abstract boolean isEnabled(String category, String name); 16 | 17 | public boolean isBlockEnabled(String name) { 18 | return isEnabled(CATEGORY_BLOCKS, name); 19 | } 20 | 21 | public boolean isItemEnabled(String name) { 22 | return isEnabled(CATEGORY_ITEMS, name); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/openmods/config/game/FactoryRegistry.java: -------------------------------------------------------------------------------- 1 | package openmods.config.game; 2 | 3 | import com.google.common.base.Preconditions; 4 | import com.google.common.collect.Maps; 5 | import java.util.Map; 6 | 7 | public class FactoryRegistry { 8 | 9 | @FunctionalInterface 10 | public interface Factory { 11 | public T construct(); 12 | } 13 | 14 | private final Map> customFactories = Maps.newHashMap(); 15 | 16 | public void registerFactory(String feature, Factory factory) { 17 | customFactories.put(feature, factory); 18 | } 19 | 20 | public C construct(String feature, Class cls) { 21 | Factory customFactory = customFactories.get(feature); 22 | if (customFactory != null) { 23 | @SuppressWarnings("unchecked") 24 | C result = (C)customFactory.construct(); 25 | Preconditions.checkArgument(cls.isInstance(result), 26 | "Invalid class for feature entry '%s', got '%s', expected '%s'", 27 | feature, result != null? result.getClass().toString() : "null", cls); 28 | return result; 29 | } 30 | 31 | try { 32 | return cls.newInstance(); 33 | } catch (ReflectiveOperationException e) { 34 | throw new RuntimeException(e); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/openmods/config/game/ICustomItemModelProvider.java: -------------------------------------------------------------------------------- 1 | package openmods.config.game; 2 | 3 | import net.minecraft.item.Item; 4 | import net.minecraft.util.ResourceLocation; 5 | 6 | public interface ICustomItemModelProvider { 7 | 8 | public interface IModelRegistrationSink { 9 | public void register(int meta, ResourceLocation modelLocation); 10 | } 11 | 12 | public void addCustomItemModels(Item item, ResourceLocation itemId, IModelRegistrationSink modelsOut); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/openmods/config/game/IRegisterableBlock.java: -------------------------------------------------------------------------------- 1 | package openmods.config.game; 2 | 3 | import javax.annotation.Nullable; 4 | import net.minecraft.item.ItemBlock; 5 | import net.minecraft.tileentity.TileEntity; 6 | import net.minecraftforge.fml.common.ModContainer; 7 | 8 | public interface IRegisterableBlock { 9 | public void setupBlock(ModContainer container, String id, Class tileEntity, @Nullable ItemBlock itemBlock); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/openmods/config/game/IgnoreFeature.java: -------------------------------------------------------------------------------- 1 | package openmods.config.game; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.FIELD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface IgnoreFeature { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/openmods/config/game/RegisterItem.java: -------------------------------------------------------------------------------- 1 | package openmods.config.game; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | import net.minecraft.item.Item; 8 | 9 | @Retention(RetentionPolicy.RUNTIME) 10 | @Target(ElementType.FIELD) 11 | public @interface RegisterItem { 12 | public static final String DEFAULT = "[default]"; 13 | public static final String NONE = "[none]"; 14 | 15 | // if left default, will use field type 16 | public Class type() default Item.class; 17 | 18 | public String id(); 19 | 20 | public String unlocalizedName() default DEFAULT; 21 | 22 | public boolean isEnabled() default true; 23 | 24 | public boolean isConfigurable() default true; 25 | 26 | public boolean registerDefaultModel() default true; 27 | 28 | public boolean addToModCreativeTab() default true; 29 | 30 | public Class customItemModels() default ICustomItemModelProvider.class; 31 | 32 | public String[] legacyIds() default {}; 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/openmods/config/properties/ConfigProperty.java: -------------------------------------------------------------------------------- 1 | package openmods.config.properties; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target(ElementType.FIELD) 10 | public @interface ConfigProperty { 11 | public String name() default ""; 12 | 13 | public String category(); 14 | 15 | public String comment() default ""; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/openmods/config/properties/ConfigurationChange.java: -------------------------------------------------------------------------------- 1 | package openmods.config.properties; 2 | 3 | import com.google.common.base.Preconditions; 4 | import net.minecraftforge.fml.common.eventhandler.Cancelable; 5 | import net.minecraftforge.fml.common.eventhandler.Event; 6 | 7 | public class ConfigurationChange extends Event { 8 | 9 | public final String name; 10 | public final String category; 11 | 12 | public ConfigurationChange(String name, String category) { 13 | Preconditions.checkNotNull(name); 14 | this.name = name; 15 | 16 | Preconditions.checkNotNull(category); 17 | this.category = category; 18 | } 19 | 20 | public boolean check(String category, String name) { 21 | return this.category.equals(category) && this.name.equals(name); 22 | } 23 | 24 | @Cancelable 25 | public static class Pre extends ConfigurationChange { 26 | public String[] proposedValues; 27 | 28 | public Pre(String name, String category, String[] proposedValues) { 29 | super(name, category); 30 | this.proposedValues = proposedValues; 31 | } 32 | } 33 | 34 | public static class Post extends ConfigurationChange { 35 | public Post(String name, String category) { 36 | super(name, category); 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/openmods/config/properties/OnLineModifiable.java: -------------------------------------------------------------------------------- 1 | package openmods.config.properties; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.FIELD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface OnLineModifiable { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/openmods/config/simple/Entry.java: -------------------------------------------------------------------------------- 1 | package openmods.config.simple; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.FIELD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Entry { 11 | public static final String SAME_AS_FIELD = ""; 12 | 13 | public String name() default SAME_AS_FIELD; 14 | 15 | public String[] comment() default {}; 16 | 17 | public int version() default 0; 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/openmods/config/simpler/Configurable.java: -------------------------------------------------------------------------------- 1 | package openmods.config.simpler; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.FIELD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Configurable { 11 | public String name() default ""; 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/openmods/container/ContainerInventory.java: -------------------------------------------------------------------------------- 1 | package openmods.container; 2 | 3 | import net.minecraft.inventory.IInventory; 4 | 5 | public abstract class ContainerInventory extends ContainerBase { 6 | 7 | public ContainerInventory(IInventory playerInventory, T owner) { 8 | super(playerInventory, owner, owner); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/openmods/container/ContainerInventoryProvider.java: -------------------------------------------------------------------------------- 1 | package openmods.container; 2 | 3 | import net.minecraft.inventory.IInventory; 4 | import openmods.inventory.IInventoryProvider; 5 | 6 | public abstract class ContainerInventoryProvider extends ContainerBase { 7 | 8 | public ContainerInventoryProvider(IInventory playerInventory, T owner) { 9 | super(playerInventory, owner.getInventory(), owner); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/openmods/container/ICustomSlot.java: -------------------------------------------------------------------------------- 1 | package openmods.container; 2 | 3 | import net.minecraft.entity.player.EntityPlayer; 4 | import net.minecraft.inventory.ClickType; 5 | import net.minecraft.item.ItemStack; 6 | 7 | public interface ICustomSlot { 8 | 9 | public ItemStack onClick(EntityPlayer player, int dragType, ClickType clickType); 10 | 11 | public boolean canDrag(); 12 | 13 | public boolean canTransferItemsOut(); 14 | 15 | public boolean canTransferItemsIn(); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/openmods/core/Bootstrap.java: -------------------------------------------------------------------------------- 1 | package openmods.core; 2 | 3 | import java.io.File; 4 | import java.util.Map; 5 | import openmods.config.simple.ConfigProcessor; 6 | 7 | /** 8 | * Methods from core plugin, extracted to prevent accidental early load 9 | */ 10 | public class Bootstrap { 11 | 12 | public static void injectData(Map data) { 13 | File mcLocation = (File)data.get("mcLocation"); 14 | File configDir = new File(mcLocation, "config"); 15 | 16 | if (!configDir.exists()) configDir.mkdir(); 17 | 18 | File configFile = new File(configDir, "OpenModsLibCore.json"); 19 | 20 | try { 21 | ConfigProcessor processor = new ConfigProcessor(); 22 | OpenModsClassTransformer.instance().addConfigValues(processor); 23 | processor.process(configFile); 24 | } catch (Throwable t) { 25 | throw new RuntimeException(String.format("Failed to read config from file %s", configFile), t); 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/openmods/core/OpenModsHook.java: -------------------------------------------------------------------------------- 1 | package openmods.core; 2 | 3 | import java.util.Map; 4 | import net.minecraftforge.fml.relauncher.IFMLCallHook; 5 | 6 | public class OpenModsHook implements IFMLCallHook { 7 | 8 | @Override 9 | public Void call() throws Exception { 10 | return null; 11 | } 12 | 13 | @Override 14 | public void injectData(Map data) { 15 | BundledJarUnpacker.setup(data); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/openmods/entity/IEntityLoadListener.java: -------------------------------------------------------------------------------- 1 | package openmods.entity; 2 | 3 | import net.minecraft.entity.Entity; 4 | 5 | public interface IEntityLoadListener { 6 | public void onEntityLoaded(Entity entity); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/openmods/fixers/GenericInventoryTeFixerWalker.java: -------------------------------------------------------------------------------- 1 | package openmods.fixers; 2 | 3 | import net.minecraft.util.datafix.DataFixer; 4 | import net.minecraft.util.datafix.FixTypes; 5 | import net.minecraft.util.datafix.walkers.ItemStackDataLists; 6 | import openmods.inventory.GenericInventory; 7 | 8 | public class GenericInventoryTeFixerWalker implements IFixerFactory { 9 | 10 | @Override 11 | public void register(DataFixer registry, Class registeringClass) { 12 | registry.registerWalker(FixTypes.BLOCK_ENTITY, new ItemStackDataLists(registeringClass, GenericInventory.TAG_ITEMS)); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/openmods/fixers/IFixerFactory.java: -------------------------------------------------------------------------------- 1 | package openmods.fixers; 2 | 3 | import net.minecraft.util.datafix.DataFixer; 4 | 5 | public interface IFixerFactory { 6 | public void register(DataFixer registry, Class registeringClass); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/openmods/fixers/ItemInventoryWalker.java: -------------------------------------------------------------------------------- 1 | package openmods.fixers; 2 | 3 | import net.minecraft.nbt.NBTTagCompound; 4 | import net.minecraft.util.datafix.DataFixesManager; 5 | import net.minecraft.util.datafix.IDataFixer; 6 | import net.minecraftforge.common.util.Constants; 7 | import net.minecraftforge.registries.IForgeRegistryEntry; 8 | import openmods.inventory.GenericInventory; 9 | import openmods.inventory.ItemInventory; 10 | 11 | public class ItemInventoryWalker extends ItemTagWalker { 12 | 13 | public ItemInventoryWalker(IForgeRegistryEntry entry) { 14 | super(entry); 15 | } 16 | 17 | @Override 18 | protected NBTTagCompound processTag(IDataFixer fixer, NBTTagCompound compound, int version) { 19 | if (compound.hasKey(ItemInventory.TAG_INVENTORY, Constants.NBT.TAG_COMPOUND)) { 20 | final NBTTagCompound inventoryTag = compound.getCompoundTag(ItemInventory.TAG_INVENTORY); 21 | final NBTTagCompound newInventoryTag = DataFixesManager.processInventory(fixer, inventoryTag, version, GenericInventory.TAG_ITEMS); 22 | compound.setTag(ItemInventory.TAG_INVENTORY, newInventoryTag); 23 | } 24 | 25 | return compound; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/openmods/fixers/ItemTagWalker.java: -------------------------------------------------------------------------------- 1 | package openmods.fixers; 2 | 3 | import net.minecraft.nbt.NBTTagCompound; 4 | import net.minecraft.util.datafix.IDataFixer; 5 | import net.minecraftforge.common.util.Constants; 6 | import net.minecraftforge.registries.IForgeRegistryEntry; 7 | 8 | public abstract class ItemTagWalker extends ResourceDataWalker { 9 | 10 | public ItemTagWalker(IForgeRegistryEntry entry) { 11 | super(entry); 12 | } 13 | 14 | @Override 15 | protected final NBTTagCompound processImpl(IDataFixer fixer, NBTTagCompound compound, int version) { 16 | if (compound.hasKey("tag", Constants.NBT.TAG_COMPOUND)) { 17 | final NBTTagCompound tag = compound.getCompoundTag("tag"); 18 | final NBTTagCompound newTag = processTag(fixer, tag, version); 19 | compound.setTag("tag", newTag); 20 | } 21 | 22 | return compound; 23 | } 24 | 25 | protected abstract NBTTagCompound processTag(IDataFixer fixer, NBTTagCompound tag, int version); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/openmods/fixers/NestedItemInventoryWalker.java: -------------------------------------------------------------------------------- 1 | package openmods.fixers; 2 | 3 | import net.minecraft.item.Item; 4 | import net.minecraft.nbt.NBTTagCompound; 5 | import net.minecraft.util.datafix.DataFixesManager; 6 | import net.minecraft.util.datafix.IDataFixer; 7 | import net.minecraftforge.registries.IForgeRegistryEntry; 8 | 9 | public class NestedItemInventoryWalker extends ItemTagWalker { 10 | 11 | private final String[] tags; 12 | 13 | public NestedItemInventoryWalker(IForgeRegistryEntry entry, String... tags) { 14 | super(entry); 15 | this.tags = tags; 16 | } 17 | 18 | @Override 19 | protected NBTTagCompound processTag(IDataFixer fixer, NBTTagCompound compound, int version) { 20 | for (String tag : tags) 21 | compound = DataFixesManager.processInventory(fixer, compound, version, tag); 22 | 23 | return compound; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/openmods/fixers/NestedItemStackWalker.java: -------------------------------------------------------------------------------- 1 | package openmods.fixers; 2 | 3 | import net.minecraft.item.Item; 4 | import net.minecraft.nbt.NBTTagCompound; 5 | import net.minecraft.util.datafix.DataFixesManager; 6 | import net.minecraft.util.datafix.IDataFixer; 7 | import net.minecraftforge.registries.IForgeRegistryEntry; 8 | 9 | public class NestedItemStackWalker extends ItemTagWalker { 10 | 11 | private final String[] tags; 12 | 13 | public NestedItemStackWalker(IForgeRegistryEntry entry, String... tags) { 14 | super(entry); 15 | this.tags = tags; 16 | } 17 | 18 | @Override 19 | protected NBTTagCompound processTag(IDataFixer fixer, NBTTagCompound compound, int version) { 20 | for (String tag : tags) 21 | compound = DataFixesManager.processItemStack(fixer, compound, version, tag); 22 | 23 | return compound; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/openmods/fixers/RegisterFixer.java: -------------------------------------------------------------------------------- 1 | package openmods.fixers; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.TYPE) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface RegisterFixer { 11 | public Class value(); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/openmods/fixers/ResourceDataWalker.java: -------------------------------------------------------------------------------- 1 | package openmods.fixers; 2 | 3 | import net.minecraft.nbt.NBTTagCompound; 4 | import net.minecraft.util.ResourceLocation; 5 | import net.minecraft.util.datafix.IDataFixer; 6 | import net.minecraft.util.datafix.IDataWalker; 7 | import net.minecraftforge.registries.IForgeRegistryEntry; 8 | 9 | public abstract class ResourceDataWalker implements IDataWalker { 10 | 11 | private final IForgeRegistryEntry entry; 12 | 13 | private final String idTag; 14 | 15 | public ResourceDataWalker(IForgeRegistryEntry entry, String idTag) { 16 | this.entry = entry; 17 | this.idTag = idTag; 18 | } 19 | 20 | public ResourceDataWalker(IForgeRegistryEntry entry) { 21 | this(entry, "id"); 22 | } 23 | 24 | @Override 25 | public NBTTagCompound process(IDataFixer fixer, NBTTagCompound compound, int version) { 26 | final ResourceLocation id = new ResourceLocation(compound.getString(idTag)); 27 | final ResourceLocation expected = entry.getRegistryName(); 28 | if (id.equals(expected)) return processImpl(fixer, compound, version); 29 | 30 | return compound; 31 | } 32 | 33 | protected abstract NBTTagCompound processImpl(IDataFixer fixer, NBTTagCompound compound, int version); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/openmods/gamelogic/WorkerLogic.java: -------------------------------------------------------------------------------- 1 | package openmods.gamelogic; 2 | 3 | import openmods.sync.SyncableInt; 4 | 5 | public class WorkerLogic { 6 | private final SyncableInt progress; 7 | private final int maxProgress; 8 | private boolean isWorking; 9 | 10 | public WorkerLogic(SyncableInt progress, int maxProgress) { 11 | this.progress = progress; 12 | this.maxProgress = maxProgress; 13 | } 14 | 15 | public void start() { 16 | isWorking = true; 17 | } 18 | 19 | public void pause() { 20 | isWorking = false; 21 | } 22 | 23 | public void reset() { 24 | isWorking = false; 25 | progress.set(0); 26 | } 27 | 28 | public void checkWorkCondition(boolean canWork) { 29 | if (isWorking && !canWork) { 30 | reset(); 31 | } else if (!isWorking && canWork) { 32 | start(); 33 | } 34 | } 35 | 36 | public boolean update() { 37 | if (isWorking) { 38 | if (progress.get() >= maxProgress) { 39 | reset(); 40 | return true; 41 | } 42 | 43 | progress.modify(+1); 44 | } 45 | 46 | return false; 47 | } 48 | 49 | public boolean isWorking() { 50 | return isWorking; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/openmods/geometry/AabbBuilder.java: -------------------------------------------------------------------------------- 1 | package openmods.geometry; 2 | 3 | import net.minecraft.util.math.AxisAlignedBB; 4 | 5 | public class AabbBuilder { 6 | 7 | private float minX; 8 | 9 | private float minY; 10 | 11 | private float minZ; 12 | 13 | private float maxX; 14 | 15 | private float maxY; 16 | 17 | private float maxZ; 18 | 19 | public AabbBuilder(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) { 20 | this.minX = minX; 21 | this.minY = minY; 22 | this.minZ = minZ; 23 | this.maxX = maxX; 24 | this.maxY = maxY; 25 | this.maxZ = maxZ; 26 | } 27 | 28 | public static AabbBuilder create() { 29 | return new AabbBuilder( 30 | Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, 31 | Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY); 32 | } 33 | 34 | public AabbBuilder addPoint(float x, float y, float z) { 35 | if (x < minX) minX = x; 36 | if (x > maxX) maxX = x; 37 | 38 | if (y < minY) minY = y; 39 | if (y > maxY) maxY = y; 40 | 41 | if (z < minZ) minZ = z; 42 | if (z > maxZ) maxZ = z; 43 | return this; 44 | } 45 | 46 | public AxisAlignedBB build() { 47 | return new AxisAlignedBB(minX, minY, minZ, maxX, maxY, maxZ); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/openmods/geometry/BoundingBoxBuilder.java: -------------------------------------------------------------------------------- 1 | package openmods.geometry; 2 | 3 | public class BoundingBoxBuilder { 4 | 5 | private float top; 6 | 7 | private float bottom; 8 | 9 | private float left; 10 | 11 | private float right; 12 | 13 | private BoundingBoxBuilder(float left, float right, float top, float bottom) { 14 | this.top = top; 15 | this.bottom = bottom; 16 | this.left = left; 17 | this.right = right; 18 | } 19 | 20 | public static BoundingBoxBuilder create() { 21 | return new BoundingBoxBuilder(Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY); 22 | } 23 | 24 | public static BoundingBoxBuilder create(int x, int y) { 25 | return new BoundingBoxBuilder(x, x, y, y); 26 | } 27 | 28 | public BoundingBoxBuilder addPoint(float x, float y) { 29 | if (x < left) left = x; 30 | if (x > right) right = x; 31 | if (y < top) top = y; 32 | if (y > bottom) bottom = y; 33 | return this; 34 | } 35 | 36 | public Box2d build() { 37 | return Box2d.fromCoords(top, bottom, left, right); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/openmods/geometry/BoundingBoxMap.java: -------------------------------------------------------------------------------- 1 | package openmods.geometry; 2 | 3 | import com.google.common.base.Preconditions; 4 | import com.google.common.collect.Lists; 5 | import com.google.common.collect.Maps; 6 | import java.util.Collection; 7 | import java.util.List; 8 | import java.util.Map; 9 | import net.minecraft.util.math.AxisAlignedBB; 10 | import net.minecraft.util.math.Vec3d; 11 | 12 | public class BoundingBoxMap { 13 | 14 | private final List> entries = Lists.newArrayList(); 15 | 16 | public void addBox(AxisAlignedBB aabb, T value) { 17 | Preconditions.checkNotNull(aabb); 18 | entries.add(Maps.immutableEntry(aabb, value)); 19 | } 20 | 21 | public Map.Entry findEntryContainingPoint(Vec3d point) { 22 | for (Map.Entry e : entries) 23 | if (e.getKey().contains(point)) return e; 24 | 25 | return null; 26 | } 27 | 28 | public void findAllEntriesContainingPoint(Vec3d point, Collection> output) { 29 | for (Map.Entry e : entries) 30 | if (e.getKey().contains(point)) output.add(e); 31 | } 32 | 33 | public static BoundingBoxMap create() { 34 | return new BoundingBoxMap<>(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/openmods/geometry/Hitbox.java: -------------------------------------------------------------------------------- 1 | package openmods.geometry; 2 | 3 | import net.minecraft.util.math.AxisAlignedBB; 4 | import net.minecraft.util.math.Vec3d; 5 | 6 | public class Hitbox { 7 | 8 | public String name; 9 | 10 | public Vec3d from; 11 | 12 | public Vec3d to; 13 | 14 | private transient AxisAlignedBB aabb; 15 | 16 | public AxisAlignedBB aabb() { 17 | if (aabb == null) 18 | aabb = new AxisAlignedBB(from, to); 19 | 20 | return aabb; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/openmods/geometry/IHitboxSupplier.java: -------------------------------------------------------------------------------- 1 | package openmods.geometry; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | public interface IHitboxSupplier { 7 | 8 | public List asList(); 9 | 10 | public Map asMap(); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/openmods/gui/ClientGuiHandler.java: -------------------------------------------------------------------------------- 1 | package openmods.gui; 2 | 3 | import net.minecraft.client.multiplayer.WorldClient; 4 | import net.minecraft.entity.player.EntityPlayer; 5 | import net.minecraft.tileentity.TileEntity; 6 | import net.minecraft.util.math.BlockPos; 7 | import net.minecraft.world.World; 8 | import net.minecraftforge.fml.common.network.IGuiHandler; 9 | import openmods.api.IHasGui; 10 | import openmods.block.OpenBlock; 11 | 12 | public class ClientGuiHandler extends CommonGuiHandler { 13 | 14 | public ClientGuiHandler() {} 15 | 16 | public ClientGuiHandler(IGuiHandler wrappedHandler) { 17 | super(wrappedHandler); 18 | } 19 | 20 | @Override 21 | public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { 22 | if (world instanceof WorldClient) { 23 | if (id != OpenBlock.OPEN_MODS_TE_GUI) return wrappedHandler != null? wrappedHandler.getClientGuiElement(id, player, world, x, y, z) : null; 24 | else { 25 | TileEntity tile = world.getTileEntity(new BlockPos(x, y, z)); 26 | if (tile instanceof IHasGui) return ((IHasGui)tile).getClientGui(player); 27 | } 28 | } 29 | return null; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/openmods/gui/CommonGuiHandler.java: -------------------------------------------------------------------------------- 1 | package openmods.gui; 2 | 3 | import net.minecraft.entity.player.EntityPlayer; 4 | import net.minecraft.tileentity.TileEntity; 5 | import net.minecraft.util.math.BlockPos; 6 | import net.minecraft.world.World; 7 | import net.minecraftforge.fml.common.network.IGuiHandler; 8 | import openmods.api.IHasGui; 9 | import openmods.block.OpenBlock; 10 | 11 | public class CommonGuiHandler implements IGuiHandler { 12 | protected final IGuiHandler wrappedHandler; 13 | 14 | public CommonGuiHandler(IGuiHandler wrappedHandler) { 15 | this.wrappedHandler = wrappedHandler; 16 | } 17 | 18 | public CommonGuiHandler() { 19 | this.wrappedHandler = null; 20 | } 21 | 22 | @Override 23 | public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { 24 | if (id != OpenBlock.OPEN_MODS_TE_GUI) return wrappedHandler != null? wrappedHandler.getServerGuiElement(id, player, world, x, y, z) : null; 25 | else { 26 | TileEntity tile = world.getTileEntity(new BlockPos(x, y, z)); 27 | if (tile instanceof IHasGui) return ((IHasGui)tile).getServerGui(player); 28 | } 29 | return null; 30 | } 31 | 32 | @Override 33 | public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { 34 | return null; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/openmods/gui/DummyContainer.java: -------------------------------------------------------------------------------- 1 | package openmods.gui; 2 | 3 | import net.minecraft.entity.player.EntityPlayer; 4 | import net.minecraft.inventory.Container; 5 | 6 | public class DummyContainer extends Container { 7 | @Override 8 | public boolean canInteractWith(EntityPlayer p_75145_1_) { 9 | return true; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/openmods/gui/IComponentParent.java: -------------------------------------------------------------------------------- 1 | package openmods.gui; 2 | 3 | import java.util.List; 4 | import javax.annotation.Nonnull; 5 | import net.minecraft.client.Minecraft; 6 | import net.minecraft.client.audio.SoundHandler; 7 | import net.minecraft.client.gui.FontRenderer; 8 | import net.minecraft.client.renderer.RenderItem; 9 | import net.minecraft.client.renderer.texture.TextureAtlasSprite; 10 | import net.minecraft.client.renderer.texture.TextureMap; 11 | import net.minecraft.item.ItemStack; 12 | import net.minecraft.util.ResourceLocation; 13 | 14 | public interface IComponentParent { 15 | 16 | public Minecraft getMinecraft(); 17 | 18 | public TextureMap getBlocksTextureMap(); 19 | 20 | public TextureAtlasSprite getIcon(ResourceLocation location); 21 | 22 | public FontRenderer getFontRenderer(); 23 | 24 | public RenderItem getItemRenderer(); 25 | 26 | public SoundHandler getSoundHandler(); 27 | 28 | public void bindTexture(ResourceLocation texture); 29 | 30 | public void drawHoveringText(List textLines, int x, int y); 31 | 32 | public void drawItemStackTooltip(@Nonnull ItemStack stack, int x, int y); 33 | 34 | public void drawGradientRect(int left, int top, int right, int bottom, int startColor, int endColor); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/openmods/gui/SyncedGuiContainer.java: -------------------------------------------------------------------------------- 1 | package openmods.gui; 2 | 3 | import openmods.container.ContainerBase; 4 | import openmods.gui.logic.IValueUpdateAction; 5 | import openmods.gui.logic.SyncObjectUpdateDispatcher; 6 | import openmods.sync.ISyncMapProvider; 7 | 8 | public class SyncedGuiContainer> extends BaseGuiContainer { 9 | 10 | private SyncObjectUpdateDispatcher dispatcher; 11 | 12 | public SyncedGuiContainer(T container, int width, int height, String name) { 13 | super(container, width, height, name); 14 | 15 | if (dispatcher != null) dispatcher.triggerAll(); 16 | } 17 | 18 | protected SyncObjectUpdateDispatcher dispatcher() { 19 | if (dispatcher == null) { 20 | dispatcher = new SyncObjectUpdateDispatcher(); 21 | getContainer().getOwner().getSyncMap().addUpdateListener(dispatcher); 22 | } 23 | 24 | return dispatcher; 25 | } 26 | 27 | public void addSyncUpdateListener(IValueUpdateAction action) { 28 | dispatcher().addAction(action); 29 | } 30 | 31 | @Override 32 | public void initGui() { 33 | super.initGui(); 34 | if (dispatcher != null) dispatcher.triggerAll(); 35 | } 36 | 37 | @Override 38 | public void onGuiClosed() { 39 | super.onGuiClosed(); 40 | 41 | if (dispatcher != null) getContainer().getOwner().getSyncMap().removeUpdateListener(dispatcher); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/openmods/gui/component/EmptyComposite.java: -------------------------------------------------------------------------------- 1 | package openmods.gui.component; 2 | 3 | public class EmptyComposite extends BaseComposite { 4 | private final int width; 5 | 6 | private final int height; 7 | 8 | public EmptyComposite(int x, int y, int width, int height) { 9 | super(x, y); 10 | this.width = width; 11 | this.height = height; 12 | } 13 | 14 | @Override 15 | public int getWidth() { 16 | return width; 17 | } 18 | 19 | @Override 20 | public int getHeight() { 21 | return height; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/openmods/gui/component/GuiComponentHBox.java: -------------------------------------------------------------------------------- 1 | package openmods.gui.component; 2 | 3 | import openmods.gui.IComponentParent; 4 | 5 | public class GuiComponentHBox extends BaseComposite { 6 | 7 | private int height; 8 | 9 | private int width; 10 | 11 | public GuiComponentHBox(int x, int y) { 12 | super(x, y); 13 | } 14 | 15 | @Override 16 | public void init(IComponentParent parent) { 17 | super.init(parent); 18 | 19 | int currentX = 0; 20 | for (BaseComponent c : components) { 21 | c.setX(currentX); 22 | currentX += c.getWidth(); 23 | height = Math.max(height, c.getY() + c.getHeight()); 24 | } 25 | 26 | width = currentX; 27 | } 28 | 29 | @Override 30 | public int getWidth() { 31 | return width; 32 | } 33 | 34 | @Override 35 | public int getHeight() { 36 | return height; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/openmods/gui/component/GuiComponentHCenter.java: -------------------------------------------------------------------------------- 1 | package openmods.gui.component; 2 | 3 | import openmods.gui.IComponentParent; 4 | 5 | public class GuiComponentHCenter extends BaseComposite { 6 | 7 | private int width; 8 | 9 | private int height; 10 | 11 | public GuiComponentHCenter(int x, int y, int width) { 12 | super(x, y); 13 | this.width = width; 14 | } 15 | 16 | @Override 17 | public void init(IComponentParent parent) { 18 | super.init(parent); 19 | 20 | for (BaseComponent c : components) { 21 | if (width >= 0) { 22 | int x = (width - c.getWidth()) / 2; 23 | c.setX(x); 24 | } 25 | 26 | height = Math.max(height, c.getY() + c.getHeight()); 27 | } 28 | } 29 | 30 | @Override 31 | public int getWidth() { 32 | return width; 33 | } 34 | 35 | @Override 36 | public int getHeight() { 37 | return height; 38 | } 39 | 40 | public static BaseComposite wrap(int x, int y, int width, BaseComponent component) { 41 | return new GuiComponentHCenter(x, y, width).addComponent(component); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/openmods/gui/component/GuiComponentIconButton.java: -------------------------------------------------------------------------------- 1 | package openmods.gui.component; 2 | 3 | import openmods.gui.Icon; 4 | 5 | public class GuiComponentIconButton extends GuiComponentButton { 6 | 7 | public static final int BORDER_SIZE = 4; 8 | 9 | private final Icon icon; 10 | 11 | public GuiComponentIconButton(int x, int y, int color, Icon icon) { 12 | super(x, y, icon.width + BORDER_SIZE, icon.height + BORDER_SIZE, color); 13 | this.icon = icon; 14 | } 15 | 16 | @Override 17 | public void renderContents(int offsetX, int offsetY, int mouseX, int mouseY, boolean pressed) { 18 | int offset = (buttonEnabled && pressed)? 3 : 2; 19 | 20 | drawSprite(icon, offsetX + x + offset, offsetY + y + offset); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/openmods/gui/component/GuiComponentRect.java: -------------------------------------------------------------------------------- 1 | package openmods.gui.component; 2 | 3 | import openmods.api.IValueReceiver; 4 | 5 | public class GuiComponentRect extends GuiComponentResizable implements IValueReceiver { 6 | 7 | private int color; 8 | private final int mask; 9 | 10 | public GuiComponentRect(int x, int y, int width, int height, int color) { 11 | this(x, y, width, height, color, 0xFF000000); 12 | } 13 | 14 | public GuiComponentRect(int x, int y, int width, int height, int color, int mask) { 15 | super(x, y, width, height); 16 | this.mask = mask; 17 | this.color = color | mask; 18 | } 19 | 20 | public int getColorForRender() { 21 | return color; 22 | } 23 | 24 | @Override 25 | public void render(int offsetX, int offsetY, int mouseX, int mouseY) { 26 | int oX = x + offsetX; 27 | int oY = y + offsetY; 28 | drawRect(oX, oY, oX + width, oY + height, getColorForRender()); 29 | } 30 | 31 | @Override 32 | public void setValue(Integer color) { 33 | this.color = color | mask; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/openmods/gui/component/GuiComponentResizable.java: -------------------------------------------------------------------------------- 1 | package openmods.gui.component; 2 | 3 | public abstract class GuiComponentResizable extends BaseComponent { 4 | protected int width; 5 | protected int height; 6 | 7 | public GuiComponentResizable(int x, int y, int width, int height) { 8 | super(x, y); 9 | this.width = width; 10 | this.height = height; 11 | } 12 | 13 | @Override 14 | public int getWidth() { 15 | return width; 16 | } 17 | 18 | @Override 19 | public int getHeight() { 20 | return height; 21 | } 22 | 23 | public void setWidth(int width) { 24 | this.width = width; 25 | } 26 | 27 | public void setHeight(int height) { 28 | this.height = height; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/openmods/gui/component/GuiComponentResizableComposite.java: -------------------------------------------------------------------------------- 1 | package openmods.gui.component; 2 | 3 | public abstract class GuiComponentResizableComposite extends BaseComposite { 4 | protected int width; 5 | protected int height; 6 | 7 | public GuiComponentResizableComposite(int x, int y, int width, int height) { 8 | super(x, y); 9 | this.width = width; 10 | this.height = height; 11 | } 12 | 13 | @Override 14 | public int getWidth() { 15 | return width; 16 | } 17 | 18 | @Override 19 | public int getHeight() { 20 | return height; 21 | } 22 | 23 | public void setWidth(int width) { 24 | this.width = width; 25 | } 26 | 27 | public void setHeight(int height) { 28 | this.height = height; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/openmods/gui/component/GuiComponentSpriteButton.java: -------------------------------------------------------------------------------- 1 | package openmods.gui.component; 2 | 3 | import net.minecraft.client.renderer.GlStateManager; 4 | import openmods.gui.Icon; 5 | import org.lwjgl.input.Mouse; 6 | 7 | public class GuiComponentSpriteButton extends GuiComponentSprite { 8 | 9 | private final Icon hoverIcon; 10 | 11 | public GuiComponentSpriteButton(int x, int y, Icon icon, Icon hoverIcon) { 12 | super(x, y, icon); 13 | this.hoverIcon = hoverIcon; 14 | } 15 | 16 | @Override 17 | protected void doRender(int offsetX, int offsetY, int mouseX, int mouseY) { 18 | if (icon == null) { return; } 19 | 20 | GlStateManager.color(r, g, b); 21 | boolean mouseOver = isMouseOver(mouseX, mouseY); 22 | boolean pressed = mouseOver && Mouse.isButtonDown(0); 23 | int offset = pressed? 1 : 0; 24 | Icon useIcon = hoverIcon != null && mouseOver? hoverIcon : icon; 25 | drawSprite(useIcon, offsetX + x + offset, offsetY + y + offset); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/openmods/gui/component/GuiComponentTextButton.java: -------------------------------------------------------------------------------- 1 | package openmods.gui.component; 2 | 3 | import net.minecraft.client.gui.FontRenderer; 4 | 5 | public class GuiComponentTextButton extends GuiComponentButton { 6 | 7 | private String text; 8 | 9 | public GuiComponentTextButton(int x, int y, int width, int height, int color, String text) { 10 | super(x, y, width, height, color); 11 | this.text = text; 12 | } 13 | 14 | public GuiComponentTextButton(int x, int y, int width, int height, int color) { 15 | this(x, y, width, height, color, ""); 16 | } 17 | 18 | public GuiComponentTextButton setText(String buttonText) { 19 | this.text = buttonText; 20 | return this; 21 | } 22 | 23 | @Override 24 | public void renderContents(int offsetX, int offsetY, int mouseX, int mouseY, boolean pressed) { 25 | final FontRenderer fontRenderer = parent.getFontRenderer(); 26 | int textWidth = fontRenderer.getStringWidth(text); 27 | int offX = ((width - textWidth) / 2) + 1; 28 | int offY = 3; 29 | if (buttonEnabled && pressed) { 30 | offY++; 31 | offX++; 32 | } 33 | fontRenderer.drawString(text, offsetX + x + offX, offsetY + y + offY, 4210752); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/openmods/gui/component/GuiComponentVCenter.java: -------------------------------------------------------------------------------- 1 | package openmods.gui.component; 2 | 3 | import openmods.gui.IComponentParent; 4 | 5 | public class GuiComponentVCenter extends BaseComposite { 6 | 7 | private int width; 8 | 9 | private int height; 10 | 11 | public GuiComponentVCenter(int x, int y, int height) { 12 | super(x, y); 13 | this.height = height; 14 | } 15 | 16 | @Override 17 | public void init(IComponentParent parent) { 18 | super.init(parent); 19 | 20 | for (BaseComponent c : components) { 21 | if (height >= 0) { 22 | int y = (height - c.getHeight()) / 2; 23 | c.setY(y); 24 | } 25 | 26 | width = Math.max(width, c.getX() + c.getWidth()); 27 | } 28 | } 29 | 30 | @Override 31 | public int getWidth() { 32 | return width; 33 | } 34 | 35 | @Override 36 | public int getHeight() { 37 | return height; 38 | } 39 | 40 | public static BaseComposite wrap(int x, int y, int width, BaseComponent component) { 41 | return new GuiComponentVCenter(x, y, width).addComponent(component); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/openmods/gui/component/page/SectionPage.java: -------------------------------------------------------------------------------- 1 | package openmods.gui.component.page; 2 | 3 | import openmods.gui.component.GuiComponentHCenter; 4 | import openmods.gui.component.GuiComponentLabel; 5 | import openmods.gui.component.GuiComponentVCenter; 6 | import openmods.utils.TranslationUtils; 7 | 8 | public class SectionPage extends PageBase { 9 | 10 | public SectionPage(String name) { 11 | String txt = TranslationUtils.translateToLocal(name); 12 | GuiComponentLabel title = new GuiComponentLabel(0, 0, getWidth(), 40, txt); 13 | title.setScale(BookScaleConfig.getSectionTitleScale()); 14 | 15 | addComponent(GuiComponentHCenter.wrap(0, 0, getWidth(), 16 | GuiComponentVCenter.wrap(0, 0, getHeight(), 17 | title))); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/openmods/gui/component/page/TitledPage.java: -------------------------------------------------------------------------------- 1 | package openmods.gui.component.page; 2 | 3 | import openmods.gui.component.GuiComponentHCenter; 4 | import openmods.gui.component.GuiComponentLabel; 5 | import openmods.utils.TranslationUtils; 6 | import org.apache.commons.lang3.StringEscapeUtils; 7 | 8 | public class TitledPage extends PageBase { 9 | 10 | public TitledPage(String title, String content) { 11 | { 12 | final String translatedTitle = TranslationUtils.translateToLocal(title); 13 | final GuiComponentLabel titleLabel = new GuiComponentLabel(0, 0, translatedTitle).setScale(BookScaleConfig.getPageTitleScale()); 14 | addComponent(new GuiComponentHCenter(0, 12, getWidth()).addComponent(titleLabel)); 15 | } 16 | 17 | { 18 | final String translatedContent = StringEscapeUtils.unescapeJava(TranslationUtils.translateToLocal(content)); 19 | final GuiComponentLabel lblContent = new GuiComponentLabel(0, 0, getWidth() - 20, 300, translatedContent); 20 | 21 | lblContent.setScale(BookScaleConfig.getPageContentScale()); 22 | lblContent.setAdditionalLineHeight(BookScaleConfig.getTitlePageSeparator()); 23 | 24 | addComponent(new GuiComponentHCenter(0, 35, getWidth()).addComponent(lblContent)); 25 | } 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/openmods/gui/listener/IKeyTypedListener.java: -------------------------------------------------------------------------------- 1 | package openmods.gui.listener; 2 | 3 | import openmods.gui.component.BaseComponent; 4 | 5 | @FunctionalInterface 6 | public interface IKeyTypedListener extends IListenerBase { 7 | public void componentKeyTyped(BaseComponent component, char character, int keyCode); 8 | } -------------------------------------------------------------------------------- /src/main/java/openmods/gui/listener/IListenerBase.java: -------------------------------------------------------------------------------- 1 | package openmods.gui.listener; 2 | 3 | public interface IListenerBase { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/openmods/gui/listener/IMouseDownListener.java: -------------------------------------------------------------------------------- 1 | package openmods.gui.listener; 2 | 3 | import openmods.gui.component.BaseComponent; 4 | 5 | @FunctionalInterface 6 | public interface IMouseDownListener extends IListenerBase { 7 | public void componentMouseDown(BaseComponent component, int x, int y, int button); 8 | } -------------------------------------------------------------------------------- /src/main/java/openmods/gui/listener/IMouseDragListener.java: -------------------------------------------------------------------------------- 1 | package openmods.gui.listener; 2 | 3 | import openmods.gui.component.BaseComponent; 4 | 5 | @FunctionalInterface 6 | public interface IMouseDragListener extends IListenerBase { 7 | public void componentMouseDrag(BaseComponent component, int x, int y, int button, long time); 8 | } -------------------------------------------------------------------------------- /src/main/java/openmods/gui/listener/IMouseUpListener.java: -------------------------------------------------------------------------------- 1 | package openmods.gui.listener; 2 | 3 | import openmods.gui.component.BaseComponent; 4 | 5 | @FunctionalInterface 6 | public interface IMouseUpListener extends IListenerBase { 7 | public void componentMouseUp(BaseComponent component, int x, int y, int button); 8 | } -------------------------------------------------------------------------------- /src/main/java/openmods/gui/listener/IValueChangedListener.java: -------------------------------------------------------------------------------- 1 | package openmods.gui.listener; 2 | 3 | @FunctionalInterface 4 | public interface IValueChangedListener extends IListenerBase { 5 | public void valueChanged(T value); 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/openmods/gui/logic/IValueUpdateAction.java: -------------------------------------------------------------------------------- 1 | package openmods.gui.logic; 2 | 3 | public interface IValueUpdateAction { 4 | 5 | public Iterable getTriggers(); 6 | 7 | public void execute(); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/openmods/gui/logic/SyncObjectUpdateDispatcher.java: -------------------------------------------------------------------------------- 1 | package openmods.gui.logic; 2 | 3 | import java.util.Set; 4 | import openmods.sync.ISyncListener; 5 | import openmods.sync.ISyncableObject; 6 | 7 | public class SyncObjectUpdateDispatcher extends ValueUpdateDispatcher implements ISyncListener { 8 | @Override 9 | public void onSync(Set changes) { 10 | trigger(changes); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/openmods/gui/logic/ValueUpdateDispatcher.java: -------------------------------------------------------------------------------- 1 | package openmods.gui.logic; 2 | 3 | import com.google.common.collect.HashMultimap; 4 | import com.google.common.collect.Multimap; 5 | import com.google.common.collect.Sets; 6 | import java.util.Set; 7 | 8 | public class ValueUpdateDispatcher { 9 | 10 | private Multimap actions = HashMultimap.create(); 11 | 12 | public void addAction(IValueUpdateAction listener) { 13 | for (Object trigger : listener.getTriggers()) 14 | actions.put(trigger, listener); 15 | } 16 | 17 | public void trigger(Iterable triggers) { 18 | Set actionsToTrigger = Sets.newIdentityHashSet(); 19 | 20 | for (Object trigger : triggers) 21 | actionsToTrigger.addAll(actions.get(trigger)); 22 | 23 | for (IValueUpdateAction action : actionsToTrigger) 24 | action.execute(); 25 | } 26 | 27 | public void triggerAll() { 28 | Set uniques = Sets.newIdentityHashSet(); 29 | uniques.addAll(actions.values()); 30 | for (IValueUpdateAction action : uniques) 31 | action.execute(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/openmods/gui/misc/IConfigurableGuiSlots.java: -------------------------------------------------------------------------------- 1 | package openmods.gui.misc; 2 | 3 | import java.util.Set; 4 | import net.minecraft.util.EnumFacing; 5 | import openmods.api.IValueProvider; 6 | import openmods.api.IValueReceiver; 7 | import openmods.utils.bitmap.IWriteableBitMap; 8 | 9 | public interface IConfigurableGuiSlots> { 10 | public IValueProvider> createAllowedDirectionsProvider(T slot); 11 | 12 | public IWriteableBitMap createAllowedDirectionsReceiver(T slot); 13 | 14 | public IValueProvider createAutoFlagProvider(T slot); 15 | 16 | public IValueReceiver createAutoSlotReceiver(T slot); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/openmods/gui/misc/ISlotBackgroundRenderer.java: -------------------------------------------------------------------------------- 1 | package openmods.gui.misc; 2 | 3 | import net.minecraft.inventory.Slot; 4 | import openmods.gui.component.BaseComponent; 5 | 6 | public interface ISlotBackgroundRenderer { 7 | public void render(BaseComponent gui, Slot slot); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/openmods/include/IExtendable.java: -------------------------------------------------------------------------------- 1 | package openmods.include; 2 | 3 | /** 4 | * @deprecated No longer needed, annotations are sufficient 5 | */ 6 | @Deprecated 7 | public interface IExtendable { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/openmods/include/IncludeInterface.java: -------------------------------------------------------------------------------- 1 | package openmods.include; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Target; 5 | 6 | @Target({ ElementType.FIELD, ElementType.METHOD }) 7 | public @interface IncludeInterface { 8 | public Class value() default Object.class; 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/openmods/include/IncludeOverride.java: -------------------------------------------------------------------------------- 1 | package openmods.include; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Target; 5 | 6 | @Target(ElementType.METHOD) 7 | public @interface IncludeOverride { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/openmods/infobook/BookDocumentation.java: -------------------------------------------------------------------------------- 1 | package openmods.infobook; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target(ElementType.TYPE) 10 | public @interface BookDocumentation { 11 | public static abstract class EMPTY implements ICustomBookEntryProvider {} 12 | 13 | public String customName() default ""; 14 | 15 | public Class customProvider() default EMPTY.class; 16 | 17 | public boolean hasVideo() default false; 18 | } -------------------------------------------------------------------------------- /src/main/java/openmods/infobook/ICustomBookEntryProvider.java: -------------------------------------------------------------------------------- 1 | package openmods.infobook; 2 | 3 | import javax.annotation.Nonnull; 4 | import net.minecraft.item.ItemStack; 5 | 6 | public interface ICustomBookEntryProvider { 7 | 8 | public class Entry { 9 | public final String name; 10 | @Nonnull 11 | public final ItemStack stack; 12 | 13 | public Entry(String name, @Nonnull ItemStack stack) { 14 | this.name = name; 15 | this.stack = stack; 16 | } 17 | } 18 | 19 | public Iterable getBookEntries(); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/openmods/integration/IIntegrationModule.java: -------------------------------------------------------------------------------- 1 | package openmods.integration; 2 | 3 | public interface IIntegrationModule { 4 | 5 | public String name(); 6 | 7 | public boolean canLoad(); 8 | 9 | public void load(); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/openmods/integration/Integration.java: -------------------------------------------------------------------------------- 1 | package openmods.integration; 2 | 3 | import com.google.common.collect.Lists; 4 | import java.util.List; 5 | import openmods.Log; 6 | 7 | public class Integration { 8 | 9 | private static final List modules = Lists.newArrayList(); 10 | 11 | private static boolean alreadyLoaded; 12 | 13 | public static void addModule(IIntegrationModule module) { 14 | if (alreadyLoaded) Log.warn("Trying to add integration module %s after loading. This will not work"); 15 | modules.add(module); 16 | } 17 | 18 | public static void loadModules() { 19 | if (alreadyLoaded) { 20 | Log.warn("Trying to load integration modules twice, ignoring"); 21 | return; 22 | } 23 | 24 | for (IIntegrationModule module : modules) { 25 | try { 26 | if (module.canLoad()) { 27 | module.load(); 28 | Log.debug("Loaded integration module '%s'", module.name()); 29 | } else { 30 | Log.debug("Condition no met for integration module '%s', not loading", module.name()); 31 | } 32 | } catch (Throwable t) { 33 | Log.warn(t, "Can't load integration module '%s'", module.name()); 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/openmods/integration/IntegrationConditions.java: -------------------------------------------------------------------------------- 1 | package openmods.integration; 2 | 3 | import net.minecraftforge.fml.common.Loader; 4 | import openmods.conditions.ICondition; 5 | import openmods.reflection.SafeClassLoad; 6 | 7 | public class IntegrationConditions extends openmods.conditions.Conditions { 8 | 9 | public static ICondition classExists(String clsName) { 10 | final SafeClassLoad cls = new SafeClassLoad(clsName); 11 | return cls::tryLoad; 12 | } 13 | 14 | public static ICondition modLoaded(final String modName) { 15 | return () -> Loader.isModLoaded(modName); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/openmods/integration/IntegrationModule.java: -------------------------------------------------------------------------------- 1 | package openmods.integration; 2 | 3 | import com.google.common.base.Preconditions; 4 | import openmods.conditions.ICondition; 5 | 6 | public abstract class IntegrationModule implements IIntegrationModule { 7 | private final ICondition condition; 8 | 9 | public IntegrationModule(ICondition condition) { 10 | Preconditions.checkNotNull(condition, "Invalid use"); 11 | this.condition = condition; 12 | } 13 | 14 | @Override 15 | public boolean canLoad() { 16 | return condition.check(); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/openmods/inventory/IInventoryProvider.java: -------------------------------------------------------------------------------- 1 | package openmods.inventory; 2 | 3 | import net.minecraft.inventory.IInventory; 4 | 5 | public interface IInventoryProvider { 6 | public IInventory getInventory(); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/openmods/inventory/ItemInventory.java: -------------------------------------------------------------------------------- 1 | package openmods.inventory; 2 | 3 | import com.google.common.base.Preconditions; 4 | import javax.annotation.Nonnull; 5 | import net.minecraft.item.ItemStack; 6 | import net.minecraft.nbt.NBTTagCompound; 7 | import openmods.utils.ItemUtils; 8 | 9 | public class ItemInventory extends GenericInventory { 10 | 11 | public static final String TAG_INVENTORY = "inventory"; 12 | 13 | @Nonnull 14 | protected final ItemStack containerStack; 15 | 16 | public ItemInventory(@Nonnull ItemStack containerStack, int size) { 17 | super("", false, size); 18 | Preconditions.checkNotNull(containerStack); 19 | this.containerStack = containerStack; 20 | final NBTTagCompound tag = ItemUtils.getItemTag(containerStack); 21 | readFromNBT(getInventoryTag(tag)); 22 | 23 | } 24 | 25 | @Override 26 | public void onInventoryChanged(int slotNumber) { 27 | super.onInventoryChanged(slotNumber); 28 | 29 | NBTTagCompound tag = ItemUtils.getItemTag(containerStack); 30 | NBTTagCompound inventoryTag = getInventoryTag(tag); 31 | writeToNBT(inventoryTag); 32 | tag.setTag(TAG_INVENTORY, inventoryTag); 33 | containerStack.setTagCompound(tag); 34 | } 35 | 36 | public static NBTTagCompound getInventoryTag(NBTTagCompound tag) { 37 | return tag.getCompoundTag(TAG_INVENTORY); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/openmods/inventory/ItemStackComparators.java: -------------------------------------------------------------------------------- 1 | package openmods.inventory; 2 | 3 | import openmods.inventory.StackEqualityTesterBuilder.IEqualityTester; 4 | 5 | public class ItemStackComparators { 6 | 7 | public static final IEqualityTester ITEM = new StackEqualityTesterBuilder().useItem().build(); 8 | 9 | public static final IEqualityTester ITEM_DMG = new StackEqualityTesterBuilder().useItem().useDamage().build(); 10 | 11 | public static final IEqualityTester ITEM_DMG_NBT = new StackEqualityTesterBuilder().useItem().useDamage().useNBT().build(); 12 | 13 | public static final IEqualityTester FULL = new StackEqualityTesterBuilder().useItem().useSize().useDamage().useNBT().build(); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/openmods/inventory/TileEntityInventory.java: -------------------------------------------------------------------------------- 1 | package openmods.inventory; 2 | 3 | import net.minecraft.entity.player.EntityPlayer; 4 | import net.minecraft.tileentity.TileEntity; 5 | import net.minecraft.util.math.BlockPos; 6 | 7 | public class TileEntityInventory extends GenericInventory { 8 | 9 | private final TileEntity owner; 10 | 11 | public TileEntityInventory(TileEntity owner, String name, boolean isInvNameLocalized, int size) { 12 | super(name, isInvNameLocalized, size); 13 | this.owner = owner; 14 | } 15 | 16 | @Override 17 | public boolean isUsableByPlayer(EntityPlayer player) { 18 | final BlockPos pos = owner.getPos(); 19 | return (owner.getWorld().getTileEntity(pos) == owner) 20 | && (player.getDistanceSq(pos) <= 64.0D); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/openmods/inventory/comparator/ComparatorComponents.java: -------------------------------------------------------------------------------- 1 | package openmods.inventory.comparator; 2 | 3 | import com.google.common.collect.Ordering; 4 | import net.minecraft.item.Item; 5 | import net.minecraft.item.ItemStack; 6 | 7 | public class ComparatorComponents { 8 | 9 | @SuppressWarnings("unchecked") 10 | private static Ordering arbitrary() { 11 | return (Ordering)Ordering.arbitrary(); 12 | } 13 | 14 | public static final Ordering ITEM_COMPARATOR = arbitrary().onResultOf(ItemStack::getItem).nullsLast(); 15 | 16 | public static final Ordering ITEM_ID_COMPARATOR = Ordering.natural().onResultOf((ItemStack input) -> Item.getIdFromItem(input.getItem())).nullsLast(); 17 | 18 | public static final Ordering DAMAGE_COMPARATOR = Ordering.natural().onResultOf(ItemStack::getItemDamage).nullsLast(); 19 | 20 | public static final Ordering SIZE_COMPARATOR = Ordering.natural().onResultOf(ItemStack::getCount).nullsLast(); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/openmods/inventory/comparator/EqualComponents.java: -------------------------------------------------------------------------------- 1 | package openmods.inventory.comparator; 2 | 3 | import com.google.common.base.Objects; 4 | import net.minecraft.item.Item; 5 | import net.minecraft.item.ItemStack; 6 | 7 | public class EqualComponents { 8 | 9 | @FunctionalInterface 10 | public interface IItemStackTester { 11 | public boolean isEqual(ItemStack left, ItemStack right); 12 | } 13 | 14 | public static final IItemStackTester ITEM_TESTER = (left, right) -> left.getItem() == right.getItem(); 15 | 16 | public static final IItemStackTester ITEM_ID_TESTER = (left, right) -> Item.getIdFromItem(left.getItem()) == Item.getIdFromItem(right.getItem()); 17 | 18 | public static final IItemStackTester DAMAGE_TESTER = (left, right) -> left.getItemDamage() == right.getItemDamage(); 19 | 20 | public static final IItemStackTester SIZE_TESTER = (left, right) -> left.getCount() == right.getCount(); 21 | 22 | public static final IItemStackTester NBT_TESTER = (left, right) -> Objects.equal(left.getTagCompound(), right.getTagCompound()); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/openmods/item/IMetaItem.java: -------------------------------------------------------------------------------- 1 | package openmods.item; 2 | 3 | import javax.annotation.Nonnull; 4 | import net.minecraft.entity.EntityLivingBase; 5 | import net.minecraft.entity.player.EntityPlayer; 6 | import net.minecraft.item.Item; 7 | import net.minecraft.item.ItemStack; 8 | import net.minecraft.util.ActionResult; 9 | import net.minecraft.util.EnumActionResult; 10 | import net.minecraft.util.EnumFacing; 11 | import net.minecraft.util.EnumHand; 12 | import net.minecraft.util.NonNullList; 13 | import net.minecraft.util.ResourceLocation; 14 | import net.minecraft.util.math.BlockPos; 15 | import net.minecraft.world.World; 16 | 17 | public interface IMetaItem { 18 | 19 | public String getUnlocalizedName(@Nonnull ItemStack stack); 20 | 21 | public boolean hitEntity(@Nonnull ItemStack itemStack, EntityLivingBase target, EntityLivingBase player); 22 | 23 | public EnumActionResult onItemUse(@Nonnull ItemStack itemStack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ); 24 | 25 | public ActionResult onItemRightClick(@Nonnull ItemStack itemStack, World world, EntityPlayer player, EnumHand hand); 26 | 27 | public void addToCreativeList(Item item, int meta, NonNullList result); 28 | 29 | public boolean hasEffect(); 30 | 31 | public ResourceLocation getLocation(); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/openmods/item/IMetaItemFactory.java: -------------------------------------------------------------------------------- 1 | package openmods.item; 2 | 3 | public interface IMetaItemFactory { 4 | 5 | public int getMeta(); 6 | 7 | public boolean isEnabled(); 8 | 9 | public IMetaItem createMetaItem(); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/openmods/model/ModelUtils.java: -------------------------------------------------------------------------------- 1 | package openmods.model; 2 | 3 | import net.minecraft.block.Block; 4 | import net.minecraft.client.renderer.block.model.ModelBakery; 5 | import net.minecraft.client.renderer.block.model.ModelResourceLocation; 6 | import net.minecraft.item.Item; 7 | import net.minecraftforge.client.model.ModelLoader; 8 | 9 | public class ModelUtils { 10 | 11 | public static void registerMetaInsensitiveModel(Block block) { 12 | registerMetaInsensitiveModel(Item.getItemFromBlock(block)); 13 | } 14 | 15 | public static void registerMetaInsensitiveModel(Item item) { 16 | registerMetaInsensitiveModel(item, "inventory"); 17 | } 18 | 19 | public static void registerMetaInsensitiveModel(Block item, String variant) { 20 | registerMetaInsensitiveModel(Item.getItemFromBlock(item), variant); 21 | } 22 | 23 | public static void registerMetaInsensitiveModel(Item item, String variant) { 24 | final ModelResourceLocation location = new ModelResourceLocation(item.getRegistryName(), variant); 25 | 26 | ModelBakery.registerItemVariants(item, location); 27 | 28 | ModelLoader.setCustomMeshDefinition(item, stack -> location); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/openmods/model/eval/ITransformEvaluator.java: -------------------------------------------------------------------------------- 1 | package openmods.model.eval; 2 | 3 | import java.util.Map; 4 | import net.minecraftforge.common.model.TRSRTransformation; 5 | import net.minecraftforge.common.model.animation.IJoint; 6 | 7 | @FunctionalInterface 8 | public interface ITransformEvaluator { 9 | 10 | public TRSRTransformation evaluate(IJoint joint, Map args); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/openmods/model/eval/IVarExpander.java: -------------------------------------------------------------------------------- 1 | package openmods.model.eval; 2 | 3 | import java.util.Map; 4 | 5 | @FunctionalInterface 6 | public interface IVarExpander { 7 | public Map expand(Map args); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/openmods/model/itemstate/ISimpleStateItem.java: -------------------------------------------------------------------------------- 1 | package openmods.model.itemstate; 2 | 3 | import javax.annotation.Nonnull; 4 | import net.minecraft.item.ItemStack; 5 | import openmods.state.State; 6 | import openmods.state.StateContainer; 7 | 8 | public interface ISimpleStateItem { 9 | 10 | public StateContainer getStateContainer(); 11 | 12 | public State getState(@Nonnull ItemStack stack); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/openmods/model/itemstate/IStateItem.java: -------------------------------------------------------------------------------- 1 | package openmods.model.itemstate; 2 | 3 | import javax.annotation.Nonnull; 4 | import net.minecraft.entity.EntityLivingBase; 5 | import net.minecraft.item.ItemStack; 6 | import net.minecraft.world.World; 7 | import openmods.state.State; 8 | import openmods.state.StateContainer; 9 | 10 | public interface IStateItem { 11 | 12 | public StateContainer getStateContainer(); 13 | 14 | public State getState(@Nonnull ItemStack stack, World world, EntityLivingBase entity); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/openmods/model/itemstate/SimpleStateItemSetup.java: -------------------------------------------------------------------------------- 1 | package openmods.model.itemstate; 2 | 3 | import net.minecraft.client.renderer.block.model.ModelBakery; 4 | import net.minecraft.client.renderer.block.model.ModelResourceLocation; 5 | import net.minecraft.item.Item; 6 | import net.minecraft.util.ResourceLocation; 7 | import net.minecraftforge.client.model.ModelLoader; 8 | import openmods.state.State; 9 | import openmods.state.StateContainer; 10 | 11 | public class SimpleStateItemSetup { 12 | 13 | public static void setupItemRendering(T item) { 14 | setupItemRendering(item.getRegistryName(), item); 15 | } 16 | 17 | public static void setupItemRendering(ResourceLocation base, final T item) { 18 | final ResourceLocation id = item.getRegistryName(); 19 | 20 | final StateContainer stateContainer = item.getStateContainer(); 21 | 22 | for (State state : stateContainer.getAllStates()) { 23 | ModelResourceLocation modelLoc = new ModelResourceLocation(id, state.getVariant()); 24 | ModelBakery.registerItemVariants(item, modelLoc); 25 | } 26 | 27 | ModelLoader.setCustomMeshDefinition(item, stack -> { 28 | final State state = item.getState(stack); 29 | return new ModelResourceLocation(id, state.getVariant()); 30 | }); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/openmods/model/textureditem/IItemTexture.java: -------------------------------------------------------------------------------- 1 | package openmods.model.textureditem; 2 | 3 | import java.util.Optional; 4 | import net.minecraft.util.ResourceLocation; 5 | 6 | @FunctionalInterface 7 | public interface IItemTexture { 8 | public Optional getTexture(); 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/openmods/model/textureditem/ItemTextureCapability.java: -------------------------------------------------------------------------------- 1 | package openmods.model.textureditem; 2 | 3 | import java.util.Optional; 4 | import net.minecraft.nbt.NBTBase; 5 | import net.minecraft.util.EnumFacing; 6 | import net.minecraftforge.common.capabilities.Capability; 7 | import net.minecraftforge.common.capabilities.CapabilityInject; 8 | import net.minecraftforge.common.capabilities.CapabilityManager; 9 | 10 | public class ItemTextureCapability { 11 | 12 | @CapabilityInject(IItemTexture.class) 13 | public static Capability CAPABILITY = null; 14 | 15 | public static void register() { 16 | CapabilityManager.INSTANCE.register(IItemTexture.class, new Capability.IStorage() { 17 | @Override 18 | public NBTBase writeNBT(Capability capability, IItemTexture instance, EnumFacing side) { 19 | return null; 20 | } 21 | 22 | @Override 23 | public void readNBT(Capability capability, IItemTexture instance, EnumFacing side, NBTBase nbt) {} 24 | }, () -> Optional::empty); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/openmods/movement/PlayerMovementEvent.java: -------------------------------------------------------------------------------- 1 | package openmods.movement; 2 | 3 | import net.minecraft.entity.player.EntityPlayer; 4 | import net.minecraftforge.event.entity.player.PlayerEvent; 5 | import net.minecraftforge.fml.common.eventhandler.Cancelable; 6 | 7 | @Cancelable 8 | public class PlayerMovementEvent extends PlayerEvent { 9 | 10 | public enum Type { 11 | JUMP, 12 | SNEAK; 13 | } 14 | 15 | public Type type; 16 | 17 | public PlayerMovementEvent(EntityPlayer player, Type type) { 18 | super(player); 19 | this.type = type; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/openmods/network/IPacketTargetSelector.java: -------------------------------------------------------------------------------- 1 | package openmods.network; 2 | 3 | import java.util.Collection; 4 | import net.minecraftforge.fml.common.network.handshake.NetworkDispatcher; 5 | import net.minecraftforge.fml.relauncher.Side; 6 | 7 | public interface IPacketTargetSelector { 8 | public boolean isAllowedOnSide(Side side); 9 | 10 | public T castArg(Object arg); 11 | 12 | public void listDispatchers(T arg, Collection result); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/openmods/network/event/EventDirection.java: -------------------------------------------------------------------------------- 1 | package openmods.network.event; 2 | 3 | import net.minecraftforge.fml.relauncher.Side; 4 | 5 | public enum EventDirection { 6 | C2S { 7 | @Override 8 | public boolean validateSend(Side side) { 9 | return side == Side.CLIENT; 10 | } 11 | 12 | @Override 13 | public boolean validateReceive(Side side) { 14 | return side == Side.SERVER; 15 | } 16 | }, 17 | S2C { 18 | @Override 19 | public boolean validateSend(Side side) { 20 | return side == Side.SERVER; 21 | } 22 | 23 | @Override 24 | public boolean validateReceive(Side side) { 25 | return side == Side.CLIENT; 26 | } 27 | }, 28 | ANY { 29 | @Override 30 | public boolean validateSend(Side side) { 31 | return true; 32 | } 33 | 34 | @Override 35 | public boolean validateReceive(Side side) { 36 | return true; 37 | } 38 | }; 39 | 40 | public abstract boolean validateSend(Side side); 41 | 42 | public abstract boolean validateReceive(Side side); 43 | } -------------------------------------------------------------------------------- /src/main/java/openmods/network/event/NetworkEventDispatcher.java: -------------------------------------------------------------------------------- 1 | package openmods.network.event; 2 | 3 | import java.util.Map; 4 | import net.minecraftforge.fml.common.network.FMLEmbeddedChannel; 5 | import net.minecraftforge.fml.common.network.NetworkRegistry; 6 | import net.minecraftforge.fml.relauncher.Side; 7 | import net.minecraftforge.registries.IForgeRegistry; 8 | import openmods.network.Dispatcher; 9 | import openmods.network.ExtendedOutboundHandler; 10 | 11 | public class NetworkEventDispatcher extends Dispatcher { 12 | 13 | public static final String CHANNEL_NAME = "OpenMods|E"; 14 | 15 | private final Map channels; 16 | 17 | public final Senders senders; 18 | 19 | public NetworkEventDispatcher(IForgeRegistry registry) { 20 | this.channels = NetworkRegistry.INSTANCE.newChannel(CHANNEL_NAME, new NetworkEventCodec(registry), new NetworkEventInboundHandler()); 21 | ExtendedOutboundHandler.install(this.channels); 22 | 23 | this.senders = new Senders(); 24 | } 25 | 26 | @Override 27 | protected FMLEmbeddedChannel getChannel(Side side) { 28 | return channels.get(side); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/openmods/network/event/NetworkEventEntry.java: -------------------------------------------------------------------------------- 1 | package openmods.network.event; 2 | 3 | import com.google.common.base.Preconditions; 4 | import net.minecraft.util.ResourceLocation; 5 | import net.minecraftforge.registries.IForgeRegistryEntry; 6 | 7 | public abstract class NetworkEventEntry implements IForgeRegistryEntry { 8 | 9 | private ResourceLocation name; 10 | 11 | public abstract Class getPacketType(); 12 | 13 | public abstract NetworkEvent createPacket(); 14 | 15 | public abstract EventDirection getDirection(); 16 | 17 | @Override 18 | public NetworkEventEntry setRegistryName(ResourceLocation name) { 19 | Preconditions.checkState(this.name == null, "Name already set, %s->%s", this.name, name); 20 | this.name = name; 21 | return this; 22 | } 23 | 24 | @Override 25 | public ResourceLocation getRegistryName() { 26 | return name; 27 | } 28 | 29 | @Override 30 | public Class getRegistryType() { 31 | return NetworkEventEntry.class; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/openmods/network/event/NetworkEventInboundHandler.java: -------------------------------------------------------------------------------- 1 | package openmods.network.event; 2 | 3 | import io.netty.channel.ChannelHandler.Sharable; 4 | import io.netty.channel.ChannelHandlerContext; 5 | import io.netty.channel.SimpleChannelInboundHandler; 6 | import net.minecraftforge.common.MinecraftForge; 7 | import net.minecraftforge.fml.common.network.FMLOutboundHandler; 8 | import net.minecraftforge.fml.common.network.FMLOutboundHandler.OutboundTarget; 9 | import openmods.utils.NetUtils; 10 | 11 | @Sharable 12 | public class NetworkEventInboundHandler extends SimpleChannelInboundHandler { 13 | 14 | @Override 15 | protected void channelRead0(final ChannelHandlerContext ctx, final NetworkEvent msg) throws Exception { 16 | NetUtils.executeSynchronized(ctx, () -> { 17 | // TODO asynchronous events, once needed 18 | MinecraftForge.EVENT_BUS.post(msg); 19 | msg.dispatcher = null; 20 | 21 | for (NetworkEvent reply : msg.replies) { 22 | ctx.channel().attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.REPLY); 23 | ctx.writeAndFlush(reply); 24 | } 25 | }); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/openmods/network/event/NetworkEventMeta.java: -------------------------------------------------------------------------------- 1 | package openmods.network.event; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.TYPE) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface NetworkEventMeta { 11 | public EventDirection direction() default EventDirection.ANY; 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/openmods/network/event/SerializableNetworkEvent.java: -------------------------------------------------------------------------------- 1 | package openmods.network.event; 2 | 3 | import java.io.IOException; 4 | import net.minecraft.network.PacketBuffer; 5 | import openmods.serializable.cls.ClassSerializersProvider; 6 | 7 | public class SerializableNetworkEvent extends NetworkEvent { 8 | 9 | @Override 10 | protected void readFromStream(PacketBuffer input) throws IOException { 11 | ClassSerializersProvider.instance.readFromStream(this, input); 12 | } 13 | 14 | @Override 15 | protected void writeToStream(PacketBuffer output) throws IOException { 16 | ClassSerializersProvider.instance.writeToStream(this, output); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/openmods/network/rpc/IRpcTarget.java: -------------------------------------------------------------------------------- 1 | package openmods.network.rpc; 2 | 3 | import java.io.IOException; 4 | import net.minecraft.entity.player.EntityPlayer; 5 | import net.minecraft.network.PacketBuffer; 6 | import net.minecraftforge.fml.relauncher.Side; 7 | 8 | public interface IRpcTarget { 9 | 10 | public Object getTarget(); 11 | 12 | public void writeToStream(PacketBuffer output) throws IOException; 13 | 14 | public void readFromStreamStream(Side side, EntityPlayer player, PacketBuffer input) throws IOException; 15 | 16 | public void afterCall(); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/openmods/network/rpc/IRpcTargetProvider.java: -------------------------------------------------------------------------------- 1 | package openmods.network.rpc; 2 | 3 | @FunctionalInterface 4 | public interface IRpcTargetProvider { 5 | public IRpcTarget createRpcTarget(); 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/openmods/network/rpc/MethodEntry.java: -------------------------------------------------------------------------------- 1 | package openmods.network.rpc; 2 | 3 | import com.google.common.base.Preconditions; 4 | import java.lang.reflect.Method; 5 | import net.minecraft.util.ResourceLocation; 6 | import net.minecraftforge.registries.IForgeRegistryEntry; 7 | 8 | public class MethodEntry implements IForgeRegistryEntry { 9 | 10 | private ResourceLocation name; 11 | 12 | public final Method method; 13 | 14 | public final MethodParamsCodec paramsCodec; 15 | 16 | public MethodEntry(Method method) { 17 | this.method = method; 18 | this.paramsCodec = new MethodParamsCodec(method); 19 | } 20 | 21 | @Override 22 | public MethodEntry setRegistryName(ResourceLocation name) { 23 | Preconditions.checkState(this.name == null, "Name already set, %s->%s", this.name, name); 24 | this.name = name; 25 | return this; 26 | } 27 | 28 | @Override 29 | public ResourceLocation getRegistryName() { 30 | return name; 31 | } 32 | 33 | @Override 34 | public Class getRegistryType() { 35 | return MethodEntry.class; 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return "Method{" + method + "}"; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/openmods/network/rpc/NullableArg.java: -------------------------------------------------------------------------------- 1 | package openmods.network.rpc; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.PARAMETER) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface NullableArg { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/openmods/network/rpc/RpcCall.java: -------------------------------------------------------------------------------- 1 | package openmods.network.rpc; 2 | 3 | public class RpcCall { 4 | public final IRpcTarget target; 5 | 6 | public final MethodEntry method; 7 | 8 | public final Object[] args; 9 | 10 | public RpcCall(IRpcTarget target, MethodEntry method, Object[] args) { 11 | this.target = target; 12 | this.method = method; 13 | this.args = args; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/openmods/network/rpc/RpcCallInboundHandler.java: -------------------------------------------------------------------------------- 1 | package openmods.network.rpc; 2 | 3 | import com.google.common.base.Preconditions; 4 | import io.netty.channel.ChannelHandler.Sharable; 5 | import io.netty.channel.ChannelHandlerContext; 6 | import io.netty.channel.SimpleChannelInboundHandler; 7 | import openmods.utils.NetUtils; 8 | import openmods.utils.SneakyThrower; 9 | 10 | @Sharable 11 | public class RpcCallInboundHandler extends SimpleChannelInboundHandler { 12 | 13 | @Override 14 | protected void channelRead0(ChannelHandlerContext ctx, final RpcCall msg) throws Exception { 15 | NetUtils.executeSynchronized(ctx, () -> { 16 | try { 17 | Object target = msg.target.getTarget(); 18 | Preconditions.checkNotNull(target, "Target wrapper %s returned null object"); 19 | msg.method.method.invoke(target, msg.args); 20 | msg.target.afterCall(); 21 | } catch (Throwable t) { 22 | throw SneakyThrower.sneakyThrow(t); 23 | } 24 | }); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/openmods/network/rpc/RpcIgnore.java: -------------------------------------------------------------------------------- 1 | package openmods.network.rpc; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.METHOD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface RpcIgnore {} 11 | -------------------------------------------------------------------------------- /src/main/java/openmods/network/rpc/RpcProxyFactory.java: -------------------------------------------------------------------------------- 1 | package openmods.network.rpc; 2 | 3 | import java.lang.reflect.Method; 4 | import java.lang.reflect.Proxy; 5 | import java.util.Map; 6 | import net.minecraftforge.registries.IForgeRegistry; 7 | import openmods.network.senders.IPacketSender; 8 | import openmods.utils.CommonRegistryCallbacks; 9 | import org.apache.commons.lang3.ArrayUtils; 10 | 11 | public class RpcProxyFactory { 12 | 13 | private final IForgeRegistry registry; 14 | 15 | RpcProxyFactory(IForgeRegistry registry) { 16 | this.registry = registry; 17 | } 18 | 19 | @SuppressWarnings("unchecked") 20 | public T createProxy(ClassLoader loader, final IPacketSender sender, final IRpcTarget wrapper, Class mainIntf, Class... extraIntf) { 21 | Class allInterfaces[] = ArrayUtils.add(extraIntf, mainIntf); 22 | 23 | final Map methodMap = CommonRegistryCallbacks.getObjectToEntryMap(registry); 24 | 25 | Object proxy = Proxy.newProxyInstance(loader, allInterfaces, (self, method, args) -> { 26 | final MethodEntry entry = methodMap.get(method); 27 | if (entry != null) { 28 | RpcCall call = new RpcCall(wrapper, entry, args); 29 | sender.sendMessage(call); 30 | } 31 | return null; 32 | }); 33 | 34 | return (T)proxy; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/openmods/network/rpc/TargetTypeProvider.java: -------------------------------------------------------------------------------- 1 | package openmods.network.rpc; 2 | 3 | import com.google.common.base.Preconditions; 4 | import net.minecraft.util.ResourceLocation; 5 | import net.minecraftforge.registries.IForgeRegistryEntry; 6 | 7 | public abstract class TargetTypeProvider implements IForgeRegistryEntry { 8 | 9 | private ResourceLocation name; 10 | 11 | public abstract IRpcTarget createRpcTarget(); 12 | 13 | public abstract Class getTargetClass(); 14 | 15 | @Override 16 | public TargetTypeProvider setRegistryName(ResourceLocation name) { 17 | Preconditions.checkState(this.name == null, "Name already set, %s->%s", this.name, name); 18 | this.name = name; 19 | return this; 20 | } 21 | 22 | @Override 23 | public ResourceLocation getRegistryName() { 24 | return name; 25 | } 26 | 27 | @Override 28 | public Class getRegistryType() { 29 | return TargetTypeProvider.class; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/openmods/network/rpc/targets/EntityRpcTarget.java: -------------------------------------------------------------------------------- 1 | package openmods.network.rpc.targets; 2 | 3 | import net.minecraft.entity.Entity; 4 | import net.minecraft.entity.player.EntityPlayer; 5 | import net.minecraft.network.PacketBuffer; 6 | import net.minecraft.world.World; 7 | import net.minecraftforge.fml.relauncher.Side; 8 | import openmods.network.rpc.IRpcTarget; 9 | import openmods.utils.WorldUtils; 10 | 11 | public class EntityRpcTarget implements IRpcTarget { 12 | 13 | private Entity entity; 14 | 15 | public EntityRpcTarget() {} 16 | 17 | public EntityRpcTarget(Entity entity) { 18 | this.entity = entity; 19 | } 20 | 21 | @Override 22 | public Object getTarget() { 23 | return entity; 24 | } 25 | 26 | @Override 27 | public void writeToStream(PacketBuffer output) { 28 | output.writeInt(entity.world.provider.getDimension()); 29 | output.writeInt(entity.getEntityId()); 30 | } 31 | 32 | @Override 33 | public void readFromStreamStream(Side side, EntityPlayer player, PacketBuffer input) { 34 | int worldId = input.readInt(); 35 | int entityId = input.readInt(); 36 | 37 | World world = WorldUtils.getWorld(side, worldId); 38 | entity = world.getEntityByID(entityId); 39 | } 40 | 41 | @Override 42 | public void afterCall() {} 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/openmods/network/rpc/targets/TileEntityRpcTarget.java: -------------------------------------------------------------------------------- 1 | package openmods.network.rpc.targets; 2 | 3 | import net.minecraft.entity.player.EntityPlayer; 4 | import net.minecraft.network.PacketBuffer; 5 | import net.minecraft.tileentity.TileEntity; 6 | import net.minecraft.util.math.BlockPos; 7 | import net.minecraft.world.World; 8 | import net.minecraftforge.fml.relauncher.Side; 9 | import openmods.network.rpc.IRpcTarget; 10 | import openmods.utils.WorldUtils; 11 | 12 | public class TileEntityRpcTarget implements IRpcTarget { 13 | 14 | private TileEntity te; 15 | 16 | public TileEntityRpcTarget() {} 17 | 18 | public TileEntityRpcTarget(TileEntity te) { 19 | this.te = te; 20 | } 21 | 22 | @Override 23 | public Object getTarget() { 24 | return te; 25 | } 26 | 27 | @Override 28 | public void writeToStream(PacketBuffer output) { 29 | output.writeInt(te.getWorld().provider.getDimension()); 30 | output.writeBlockPos(te.getPos()); 31 | } 32 | 33 | @Override 34 | public void readFromStreamStream(Side side, EntityPlayer player, PacketBuffer input) { 35 | int worldId = input.readInt(); 36 | BlockPos pos = input.readBlockPos(); 37 | 38 | World world = WorldUtils.getWorld(side, worldId); 39 | te = world.getTileEntity(pos); 40 | } 41 | 42 | @Override 43 | public void afterCall() {} 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/openmods/network/senders/IPacketSender.java: -------------------------------------------------------------------------------- 1 | package openmods.network.senders; 2 | 3 | import java.util.Collection; 4 | 5 | public interface IPacketSender { 6 | public void sendMessage(Object msg); 7 | 8 | public void sendMessages(Collection msg); 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/openmods/network/senders/ITargetedPacketSender.java: -------------------------------------------------------------------------------- 1 | package openmods.network.senders; 2 | 3 | import java.util.Collection; 4 | 5 | public interface ITargetedPacketSender { 6 | public void sendMessage(Object msg, T target); 7 | 8 | public void sendMessages(Collection msg, T target); 9 | 10 | public IPacketSender bind(T target); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/openmods/network/senders/PacketSenderBase.java: -------------------------------------------------------------------------------- 1 | package openmods.network.senders; 2 | 3 | import io.netty.channel.Channel; 4 | import java.util.Collection; 5 | import openmods.utils.NetUtils; 6 | 7 | public class PacketSenderBase implements IPacketSender { 8 | 9 | private final Channel channel; 10 | 11 | public PacketSenderBase(Channel channel) { 12 | this.channel = channel; 13 | } 14 | 15 | protected void configureChannel(Channel channel) {} 16 | 17 | protected void cleanupChannel(Channel channel) {} 18 | 19 | @Override 20 | public void sendMessage(Object msg) { 21 | configureChannel(channel); 22 | channel.writeAndFlush(msg).addListener(NetUtils.LOGGING_LISTENER); 23 | } 24 | 25 | @Override 26 | public void sendMessages(Collection msgs) { 27 | configureChannel(channel); 28 | 29 | for (Object msg : msgs) 30 | channel.write(msg).addListener(NetUtils.LOGGING_LISTENER); 31 | 32 | channel.flush(); 33 | 34 | cleanupChannel(channel); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/openmods/network/targets/SelectMultiplePlayers.java: -------------------------------------------------------------------------------- 1 | package openmods.network.targets; 2 | 3 | import java.util.Collection; 4 | import net.minecraft.entity.player.EntityPlayerMP; 5 | import net.minecraftforge.fml.common.network.handshake.NetworkDispatcher; 6 | import net.minecraftforge.fml.relauncher.Side; 7 | import openmods.Log; 8 | import openmods.network.IPacketTargetSelector; 9 | import openmods.utils.NetUtils; 10 | 11 | public class SelectMultiplePlayers implements IPacketTargetSelector> { 12 | 13 | public static final IPacketTargetSelector> INSTANCE = new SelectMultiplePlayers(); 14 | 15 | @Override 16 | public boolean isAllowedOnSide(Side side) { 17 | return side == Side.SERVER; 18 | } 19 | 20 | @Override 21 | public void listDispatchers(Collection players, Collection result) { 22 | for (EntityPlayerMP player : players) { 23 | NetworkDispatcher dispatcher = NetUtils.getPlayerDispatcher(player); 24 | if (dispatcher != null) result.add(dispatcher); 25 | else Log.info("Trying to send message to disconnected player %s", player); 26 | } 27 | } 28 | 29 | @Override 30 | @SuppressWarnings("unchecked") 31 | public Collection castArg(Object arg) { 32 | return (Collection)arg; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/openmods/physics/Constraint.java: -------------------------------------------------------------------------------- 1 | package openmods.physics; 2 | 3 | public class Constraint { 4 | private Point p1, p2; 5 | private double rest_length, squared_rest_length; 6 | 7 | public Constraint(Point p1, Point p2, double r1) { 8 | this.p1 = p1; 9 | this.p2 = p2; 10 | this.rest_length = Double.isNaN(r1)? p1.getCurrent().subtract(p2.getCurrent()).length() : r1; 11 | this.squared_rest_length = this.rest_length * this.rest_length; 12 | } 13 | 14 | public Point getPoint1() { 15 | return this.p1; 16 | } 17 | 18 | public Point getPoint2() { 19 | return this.p2; 20 | } 21 | 22 | public double getRestLength() { 23 | return this.rest_length; 24 | } 25 | 26 | public double getSquaredRestLength() { 27 | return this.squared_rest_length; 28 | } 29 | 30 | public void update() { 31 | FastVector p1 = this.p1.getCurrent(); 32 | FastVector p2 = this.p2.getCurrent(); 33 | FastVector delta = p2.subtract(p1); 34 | 35 | double p1_im = this.p1.inv_mass, p2_im = this.p2.inv_mass; 36 | 37 | double d = delta.squaredLength(); 38 | 39 | double diff = (d - this.squared_rest_length) / ((this.squared_rest_length + d) * (p1_im + p2_im)); 40 | 41 | if (p1_im != 0) { 42 | this.p1.setCurrent(p1.add(delta.multiply(p1_im * diff))); 43 | } 44 | if (p2_im != 0) { 45 | this.p2.setCurrent(p2.subtract(delta.multiply(p2_im * diff))); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/openmods/physics/Point.java: -------------------------------------------------------------------------------- 1 | package openmods.physics; 2 | 3 | public class Point { 4 | 5 | private FastVector current, previous, force; 6 | double mass, inv_mass; 7 | 8 | public Point(double x, double y, double z) { 9 | this.current = this.previous = new FastVector(x, y, z); 10 | this.mass = this.inv_mass = 1; 11 | this.force = new FastVector(0.0, -0.5, 0).multiply(0.05 * 0.05); 12 | } 13 | 14 | public void setCurrent(FastVector v) { 15 | this.current = v; 16 | } 17 | 18 | public void setPrevious(FastVector v) { 19 | this.previous = v; 20 | } 21 | 22 | public FastVector getCurrent() { 23 | return this.current; 24 | } 25 | 26 | public FastVector getPrevious() { 27 | return this.previous; 28 | } 29 | 30 | public void update() { 31 | if (this.inv_mass != 0) { 32 | FastVector new_pos = this.current.multiply(1.99).subtract(this.previous.multiply(0.99)).add(this.force); 33 | new_pos.x = (new_pos.x < 0)? 0 : ((new_pos.x > 1)? 1 : new_pos.x); 34 | new_pos.y = (new_pos.y < 0)? 0 : ((new_pos.y > 1)? 1 : new_pos.y); 35 | new_pos.z = (new_pos.z < 0)? 0 : ((new_pos.z > 1)? 1 : new_pos.z); 36 | this.previous = this.current; 37 | this.current = new_pos; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/openmods/reflection/FieldAccessHelpers.java: -------------------------------------------------------------------------------- 1 | package openmods.reflection; 2 | 3 | import java.lang.reflect.Field; 4 | 5 | public class FieldAccessHelpers { 6 | 7 | public static int getIntField(final Class klazz, Object target, String field) { 8 | return FieldAccessHelpers.getField(klazz, target, field, -1); 9 | } 10 | 11 | public static boolean getBooleanField(final Class klazz, Object target, String field) { 12 | return FieldAccessHelpers.getField(klazz, target, field, false); 13 | } 14 | 15 | public static byte getByteField(final Class klazz, Object target, String field) { 16 | return FieldAccessHelpers.getField(klazz, target, field, (byte)-1); 17 | } 18 | 19 | @SuppressWarnings("unchecked") 20 | public static T getField(final Class klazz, Object target, String field, T defaultValue) { 21 | try { 22 | Field f = ReflectionHelper.getField(klazz, field); 23 | Object o = f.get(target); 24 | if (o != null) return (T)o; 25 | } catch (IllegalAccessException e) { 26 | throw new RuntimeException(e); 27 | } 28 | return defaultValue; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/openmods/reflection/SafeClassLoad.java: -------------------------------------------------------------------------------- 1 | package openmods.reflection; 2 | 3 | import openmods.Log; 4 | 5 | public class SafeClassLoad { 6 | public final String clsName; 7 | private Class loaded; 8 | 9 | public SafeClassLoad(String clsName) { 10 | this.clsName = clsName; 11 | } 12 | 13 | public static SafeClassLoad create(String clsName) { 14 | return new SafeClassLoad(clsName); 15 | } 16 | 17 | public void load() { 18 | if (loaded == null) loaded = ReflectionHelper.getClass(clsName); 19 | } 20 | 21 | public Class get() { 22 | load(); 23 | return loaded; 24 | } 25 | 26 | public boolean tryLoad() { 27 | return tryLoad(true); 28 | } 29 | 30 | public boolean tryLoad(boolean silent) { 31 | try { 32 | load(); 33 | return true; 34 | } catch (Throwable t) { 35 | if (!silent) Log.warn(t, "Loading class %s failed", clsName); 36 | return false; 37 | } 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return "delayed " + clsName; 43 | } 44 | } -------------------------------------------------------------------------------- /src/main/java/openmods/reflection/TypeVariableHolder.java: -------------------------------------------------------------------------------- 1 | package openmods.reflection; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target({ ElementType.TYPE, ElementType.FIELD }) 10 | public @interface TypeVariableHolder { 11 | 12 | public static class UseDeclaringType {} 13 | 14 | public Class value() default UseDeclaringType.class; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/openmods/reflection/TypeVisitor.java: -------------------------------------------------------------------------------- 1 | package openmods.reflection; 2 | 3 | import static com.google.common.base.Preconditions.checkArgument; 4 | 5 | import com.google.common.reflect.TypeToken; 6 | import java.lang.reflect.ParameterizedType; 7 | import java.lang.reflect.Type; 8 | 9 | public abstract class TypeVisitor { 10 | private final Class selectedClass; 11 | 12 | protected TypeVisitor(Class selectedClass) { 13 | this.selectedClass = selectedClass; 14 | } 15 | 16 | protected TypeVisitor() { 17 | Type superclass = getClass().getGenericSuperclass(); 18 | checkArgument(superclass instanceof ParameterizedType, "%s isn't parameterized", superclass); 19 | Type firstArg = ((ParameterizedType)superclass).getActualTypeArguments()[0]; 20 | this.selectedClass = TypeToken.of(firstArg).getRawType(); 21 | } 22 | 23 | protected abstract void visit(T value); 24 | 25 | @SuppressWarnings("unchecked") 26 | public void visit(Iterable values) { 27 | for (Object listener : values) 28 | if (selectedClass.isInstance(listener)) visit((T)listener); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/openmods/renderer/DisplayListWrapper.java: -------------------------------------------------------------------------------- 1 | package openmods.renderer; 2 | 3 | import org.lwjgl.opengl.GL11; 4 | 5 | public abstract class DisplayListWrapper { 6 | 7 | private int displayList; 8 | 9 | private boolean isValid; 10 | 11 | private boolean pendingInvalidate; 12 | 13 | public boolean isCompiled() { 14 | return isValid; 15 | } 16 | 17 | public void render() { 18 | if (pendingInvalidate) reset(); 19 | 20 | if (!isValid) { 21 | displayList = GL11.glGenLists(1); 22 | GL11.glNewList(displayList, GL11.GL_COMPILE); 23 | compile(); 24 | GL11.glEndList(); 25 | isValid = true; 26 | } 27 | 28 | GL11.glCallList(displayList); 29 | } 30 | 31 | public abstract void compile(); 32 | 33 | /** 34 | * WARNING: this method can be only used in client (rendering) thread. If not possible, use {@link #invalidate()}. 35 | */ 36 | public void reset() { 37 | if (isValid) GL11.glDeleteLists(displayList, 1); 38 | pendingInvalidate = isValid = false; 39 | } 40 | 41 | public void invalidate() { 42 | pendingInvalidate = true; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/openmods/renderer/ITileEntityModel.java: -------------------------------------------------------------------------------- 1 | package openmods.renderer; 2 | 3 | import net.minecraft.tileentity.TileEntity; 4 | 5 | public interface ITileEntityModel { 6 | 7 | public void render(T te, float partialTicks); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/openmods/renderer/ManualDisplayList.java: -------------------------------------------------------------------------------- 1 | package openmods.renderer; 2 | 3 | import com.google.common.base.Preconditions; 4 | import org.lwjgl.opengl.GL11; 5 | 6 | public class ManualDisplayList { 7 | 8 | public interface Renderer { 9 | public void render(); 10 | } 11 | 12 | private int displayList; 13 | 14 | private boolean isAllocated; 15 | 16 | private boolean isValid; 17 | 18 | public boolean isCompiled() { 19 | return isValid; 20 | } 21 | 22 | public void render() { 23 | Preconditions.checkState(isValid, "Display list not initialized"); 24 | GL11.glCallList(displayList); 25 | } 26 | 27 | public void compile(Renderer renderer) { 28 | if (isAllocated) GL11.glDeleteLists(displayList, 1); 29 | 30 | displayList = GL11.glGenLists(1); 31 | GL11.glNewList(displayList, GL11.GL_COMPILE); 32 | renderer.render(); 33 | GL11.glEndList(); 34 | 35 | isAllocated = isValid = true; 36 | } 37 | 38 | public void invalidate() { 39 | isValid = false; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/openmods/renderer/PlayerBodyRenderEvent.java: -------------------------------------------------------------------------------- 1 | package openmods.renderer; 2 | 3 | import net.minecraft.client.entity.AbstractClientPlayer; 4 | import net.minecraftforge.fml.common.eventhandler.Event; 5 | 6 | public class PlayerBodyRenderEvent extends Event { 7 | 8 | public final AbstractClientPlayer player; 9 | 10 | public final float partialTickTime; 11 | 12 | public PlayerBodyRenderEvent(AbstractClientPlayer player, float partialTickTime) { 13 | this.player = player; 14 | this.partialTickTime = partialTickTime; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/openmods/renderer/StencilRendererHandler.java: -------------------------------------------------------------------------------- 1 | package openmods.renderer; 2 | 3 | import net.minecraft.client.renderer.RenderGlobal; 4 | import net.minecraftforge.client.event.RenderWorldLastEvent; 5 | import net.minecraftforge.common.MinecraftForge; 6 | import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; 7 | 8 | public abstract class StencilRendererHandler { 9 | 10 | public static final StencilRendererHandler DUMMY = new StencilRendererHandler() { 11 | @Override 12 | public void render(RenderGlobal context, float partialTickTime) {} 13 | }; 14 | 15 | public abstract void render(RenderGlobal context, float partialTickTime); 16 | 17 | private boolean renderThisTick; 18 | 19 | public StencilRendererHandler() { 20 | MinecraftForge.EVENT_BUS.register(this); 21 | } 22 | 23 | public void markForRender() { 24 | renderThisTick = true; 25 | } 26 | 27 | @SubscribeEvent 28 | public void drawStenciledBackground(RenderWorldLastEvent evt) { 29 | if (!renderThisTick) return; 30 | renderThisTick = false; 31 | 32 | render(evt.getContext(), evt.getPartialTicks()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/openmods/serializable/IGenericSerializerProvider.java: -------------------------------------------------------------------------------- 1 | package openmods.serializable; 2 | 3 | import java.lang.reflect.Type; 4 | import openmods.utils.io.IStreamSerializer; 5 | 6 | @FunctionalInterface 7 | public interface IGenericSerializerProvider { 8 | public IStreamSerializer getSerializer(Type type); 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/openmods/serializable/IInstanceFactory.java: -------------------------------------------------------------------------------- 1 | package openmods.serializable; 2 | 3 | public interface IInstanceFactory { 4 | public T create(); 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/openmods/serializable/INbtSerializable.java: -------------------------------------------------------------------------------- 1 | package openmods.serializable; 2 | 3 | import net.minecraft.nbt.NBTTagCompound; 4 | 5 | public interface INbtSerializable { 6 | 7 | public void writeToNBT(NBTTagCompound nbt); 8 | 9 | public void readFromNBT(NBTTagCompound nbt); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/openmods/serializable/IObjectSerializer.java: -------------------------------------------------------------------------------- 1 | package openmods.serializable; 2 | 3 | import java.io.IOException; 4 | import net.minecraft.network.PacketBuffer; 5 | 6 | public interface IObjectSerializer { 7 | public void readFromStream(T object, PacketBuffer input) throws IOException; 8 | 9 | public void writeToStream(T object, PacketBuffer output) throws IOException; 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/openmods/serializable/ISerializable.java: -------------------------------------------------------------------------------- 1 | package openmods.serializable; 2 | 3 | public interface ISerializable extends IStreamSerializable, INbtSerializable {} 4 | -------------------------------------------------------------------------------- /src/main/java/openmods/serializable/ISerializerProvider.java: -------------------------------------------------------------------------------- 1 | package openmods.serializable; 2 | 3 | import openmods.utils.io.IStreamSerializer; 4 | 5 | public interface ISerializerProvider { 6 | public IStreamSerializer getSerializer(Class cls); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/openmods/serializable/IStreamReadable.java: -------------------------------------------------------------------------------- 1 | package openmods.serializable; 2 | 3 | import java.io.IOException; 4 | import net.minecraft.network.PacketBuffer; 5 | 6 | public interface IStreamReadable { 7 | 8 | public void readFromStream(PacketBuffer input) throws IOException; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/openmods/serializable/IStreamSerializable.java: -------------------------------------------------------------------------------- 1 | package openmods.serializable; 2 | 3 | public interface IStreamSerializable extends IStreamReadable, IStreamWriteable {} 4 | -------------------------------------------------------------------------------- /src/main/java/openmods/serializable/IStreamWriteable.java: -------------------------------------------------------------------------------- 1 | package openmods.serializable; 2 | 3 | import java.io.IOException; 4 | import net.minecraft.network.PacketBuffer; 5 | 6 | public interface IStreamWriteable { 7 | 8 | public void writeToStream(PacketBuffer output) throws IOException; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/openmods/serializable/NbtSerializable.java: -------------------------------------------------------------------------------- 1 | package openmods.serializable; 2 | 3 | import net.minecraft.nbt.NBTTagCompound; 4 | import openmods.utils.io.INBTSerializer; 5 | import openmods.utils.io.INbtReader; 6 | import openmods.utils.io.INbtWriter; 7 | 8 | public class NbtSerializable implements INbtSerializable { 9 | 10 | public T value; 11 | 12 | private final String name; 13 | 14 | private final INbtWriter nbtWriter; 15 | 16 | private final INbtReader nbtReader; 17 | 18 | public NbtSerializable(T value, String name, INbtWriter nbtWriter, INbtReader nbtReader) { 19 | this.value = value; 20 | this.name = name; 21 | this.nbtWriter = nbtWriter; 22 | this.nbtReader = nbtReader; 23 | } 24 | 25 | public NbtSerializable(T value, String name, INBTSerializer nbtSerializer) { 26 | this.value = value; 27 | this.name = name; 28 | this.nbtWriter = nbtSerializer; 29 | this.nbtReader = nbtSerializer; 30 | } 31 | 32 | @Override 33 | public void writeToNBT(NBTTagCompound nbt) { 34 | nbtWriter.writeToNBT(value, nbt, name); 35 | } 36 | 37 | @Override 38 | public void readFromNBT(NBTTagCompound nbt) { 39 | value = nbtReader.readFromNBT(nbt, name); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/openmods/serializable/StreamSerializable.java: -------------------------------------------------------------------------------- 1 | package openmods.serializable; 2 | 3 | import java.io.IOException; 4 | import net.minecraft.network.PacketBuffer; 5 | import openmods.utils.io.IStreamReader; 6 | import openmods.utils.io.IStreamSerializer; 7 | import openmods.utils.io.IStreamWriter; 8 | 9 | public class StreamSerializable implements IStreamSerializable { 10 | 11 | public T value; 12 | 13 | private final IStreamWriter streamWriter; 14 | 15 | private final IStreamReader streamReader; 16 | 17 | public StreamSerializable(T value, IStreamWriter streamWriter, IStreamReader streamReader) { 18 | this.value = value; 19 | this.streamWriter = streamWriter; 20 | this.streamReader = streamReader; 21 | } 22 | 23 | public StreamSerializable(T value, IStreamSerializer streamSerializer) { 24 | this.value = value; 25 | this.streamWriter = streamSerializer; 26 | this.streamReader = streamSerializer; 27 | } 28 | 29 | @Override 30 | public void readFromStream(PacketBuffer input) throws IOException { 31 | value = streamReader.readFromStream(input); 32 | } 33 | 34 | @Override 35 | public void writeToStream(PacketBuffer output) throws IOException { 36 | streamWriter.writeToStream(value, output); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/openmods/serializable/cls/SerializableClass.java: -------------------------------------------------------------------------------- 1 | package openmods.serializable.cls; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.TYPE) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface SerializableClass { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/openmods/serializable/cls/Serialize.java: -------------------------------------------------------------------------------- 1 | package openmods.serializable.cls; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.FIELD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Serialize { 11 | 12 | public int rank() default 0; 13 | 14 | public boolean nullable() default true; 15 | } -------------------------------------------------------------------------------- /src/main/java/openmods/serializable/providers/ClassSerializerProvider.java: -------------------------------------------------------------------------------- 1 | package openmods.serializable.providers; 2 | 3 | import openmods.serializable.IObjectSerializer; 4 | import openmods.serializable.ISerializerProvider; 5 | import openmods.serializable.SerializerAdapters; 6 | import openmods.serializable.cls.ClassSerializersProvider; 7 | import openmods.serializable.cls.SerializableClass; 8 | import openmods.utils.io.IStreamSerializer; 9 | 10 | public class ClassSerializerProvider implements ISerializerProvider { 11 | 12 | @Override 13 | public IStreamSerializer getSerializer(Class cls) { 14 | if (cls.isAnnotationPresent(SerializableClass.class)) { 15 | IObjectSerializer objectSerializer = ClassSerializersProvider.instance.getSerializer(cls); 16 | return SerializerAdapters.createFromObjectSerializer(cls, objectSerializer); 17 | } 18 | return null; 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /src/main/java/openmods/shapes/DefaultShapeGenerator.java: -------------------------------------------------------------------------------- 1 | package openmods.shapes; 2 | 3 | public abstract class DefaultShapeGenerator implements IShapeGenerator { 4 | 5 | @Override 6 | public void generateShape(int xSize, int ySize, int zSize, IShapeable shapeable) { 7 | generateShape(-xSize, -ySize, -zSize, +xSize, +ySize, +zSize, shapeable); 8 | 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/openmods/shapes/IShapeGenerator.java: -------------------------------------------------------------------------------- 1 | package openmods.shapes; 2 | 3 | public interface IShapeGenerator { 4 | public void generateShape(int xSize, int ySize, int zSize, IShapeable shapeable); 5 | 6 | public void generateShape(int minX, int minY, int minZ, int maxX, int maxY, int maxZ, IShapeable shapeable); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/openmods/shapes/IShapeable.java: -------------------------------------------------------------------------------- 1 | package openmods.shapes; 2 | 3 | @FunctionalInterface 4 | public interface IShapeable { 5 | public void setBlock(int x, int y, int z); 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/openmods/shapes/ShapeAxesGenerator.java: -------------------------------------------------------------------------------- 1 | package openmods.shapes; 2 | 3 | public class ShapeAxesGenerator extends DefaultShapeGenerator { 4 | 5 | @Override 6 | public void generateShape(int minX, int minY, int minZ, int maxX, int maxY, int maxZ, IShapeable shapeable) { 7 | for (int x = minX; x <= maxX; x++) 8 | shapeable.setBlock(x, 0, 0); 9 | 10 | for (int y = minY; y <= maxY; y++) 11 | shapeable.setBlock(0, y, 0); 12 | 13 | for (int z = minZ; z <= maxZ; z++) 14 | shapeable.setBlock(0, 0, z); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/openmods/shapes/ShapeCylinderGenerator.java: -------------------------------------------------------------------------------- 1 | package openmods.shapes; 2 | 3 | import java.util.Set; 4 | import openmods.utils.render.GeometryUtils; 5 | import openmods.utils.render.GeometryUtils.Quadrant; 6 | 7 | public class ShapeCylinderGenerator extends DefaultShapeGenerator { 8 | 9 | private final Set quadrants; 10 | 11 | public ShapeCylinderGenerator() { 12 | this(Quadrant.ALL); 13 | } 14 | 15 | public ShapeCylinderGenerator(Set quadrants) { 16 | this.quadrants = quadrants; 17 | } 18 | 19 | @Override 20 | public void generateShape(int minX, final int minY, int minZ, int maxX, final int maxY, int maxZ, final IShapeable shapeable) { 21 | GeometryUtils.makeEllipse(minX, minZ, maxX, maxZ, 0, (x, ignore, z) -> { 22 | for (int y = minY; y <= maxY; y++) 23 | shapeable.setBlock(x, y, z); 24 | }, quadrants); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/openmods/shapes/ShapePlanesGenerator.java: -------------------------------------------------------------------------------- 1 | package openmods.shapes; 2 | 3 | public class ShapePlanesGenerator extends DefaultShapeGenerator { 4 | 5 | @Override 6 | public void generateShape(int minX, int minY, int minZ, int maxX, int maxY, int maxZ, IShapeable shapeable) { 7 | for (int y = minY; y <= maxY; y++) { 8 | for (int z = minZ; z <= maxZ; z++) 9 | shapeable.setBlock(0, y, z); 10 | 11 | for (int x = minX; x <= maxX; x++) 12 | shapeable.setBlock(x, y, 0); 13 | } 14 | 15 | for (int x = minX; x <= maxX; x++) 16 | for (int z = minZ; z <= maxZ; z++) 17 | shapeable.setBlock(x, 0, z); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/openmods/shapes/ShapeSphereGenerator.java: -------------------------------------------------------------------------------- 1 | package openmods.shapes; 2 | 3 | import java.util.Set; 4 | import openmods.utils.render.GeometryUtils; 5 | import openmods.utils.render.GeometryUtils.Octant; 6 | 7 | public class ShapeSphereGenerator extends DefaultShapeGenerator { 8 | 9 | private final Set octants; 10 | 11 | public ShapeSphereGenerator() { 12 | this(Octant.ALL); 13 | } 14 | 15 | public ShapeSphereGenerator(Set octants) { 16 | this.octants = octants; 17 | } 18 | 19 | @Override 20 | public void generateShape(int minX, int minY, int minZ, int maxX, int maxY, int maxZ, IShapeable shapeable) { 21 | GeometryUtils.makeEllipsoid(minX, minY, minZ, maxX, maxY, maxZ, shapeable, octants); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/openmods/structured/ElementField.java: -------------------------------------------------------------------------------- 1 | package openmods.structured; 2 | 3 | import com.google.common.base.Preconditions; 4 | import com.google.common.reflect.TypeToken; 5 | import java.io.IOException; 6 | import java.lang.reflect.Field; 7 | import net.minecraft.network.PacketBuffer; 8 | import openmods.reflection.InstanceFieldAccess; 9 | import openmods.reflection.TypeUtils; 10 | import openmods.serializable.SerializerRegistry; 11 | import openmods.utils.io.IStreamSerializer; 12 | 13 | public class ElementField extends InstanceFieldAccess implements IStructureElement { 14 | 15 | public final IStreamSerializer serializer; 16 | 17 | public ElementField(Object parent, Field field) { 18 | super(parent, field); 19 | 20 | final TypeToken fieldType = TypeUtils.resolveFieldType(parent.getClass(), field); 21 | this.serializer = SerializerRegistry.instance.findSerializer(fieldType.getType()); 22 | Preconditions.checkNotNull(serializer, "Invalid field type"); 23 | } 24 | 25 | @Override 26 | public void writeToStream(PacketBuffer output) throws IOException { 27 | Object value = get(); 28 | serializer.writeToStream(value, output); 29 | } 30 | 31 | @Override 32 | public void readFromStream(PacketBuffer input) throws IOException { 33 | Object value = serializer.readFromStream(input); 34 | set(value); 35 | } 36 | } -------------------------------------------------------------------------------- /src/main/java/openmods/structured/FieldContainer.java: -------------------------------------------------------------------------------- 1 | package openmods.structured; 2 | 3 | import gnu.trove.impl.Constants; 4 | import gnu.trove.map.TObjectIntMap; 5 | import gnu.trove.map.hash.TObjectIntHashMap; 6 | import java.lang.reflect.Field; 7 | 8 | public abstract class FieldContainer implements IStructureContainer { 9 | 10 | private static final int NULL = -1; 11 | 12 | private final TObjectIntMap fields = new TObjectIntHashMap<>(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, NULL); 13 | 14 | @Override 15 | public void createElements(IElementAddCallback callback) { 16 | for (Field field : getClass().getFields()) { 17 | field.setAccessible(true); 18 | if (!field.isAnnotationPresent(StructureField.class)) continue; 19 | 20 | final ElementField fieldWrapper = new ElementField(this, field); 21 | final int fieldId = callback.addElement(fieldWrapper); 22 | fields.put(field, fieldId); 23 | } 24 | } 25 | 26 | public Integer getElementIdForField(Field field) { 27 | final int id = fields.get(field); 28 | return id != NULL? id : null; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/openmods/structured/ICustomCreateData.java: -------------------------------------------------------------------------------- 1 | package openmods.structured; 2 | 3 | import java.io.IOException; 4 | import net.minecraft.network.PacketBuffer; 5 | 6 | public interface ICustomCreateData { 7 | 8 | public void readCustomDataFromStream(PacketBuffer input) throws IOException; 9 | 10 | public void writeCustomDataFromStream(PacketBuffer output) throws IOException; 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/openmods/structured/IStructureContainer.java: -------------------------------------------------------------------------------- 1 | package openmods.structured; 2 | 3 | public interface IStructureContainer { 4 | 5 | public interface IElementAddCallback { 6 | public int addElement(E element); 7 | } 8 | 9 | public int getType(); 10 | 11 | public void createElements(IElementAddCallback callback); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/openmods/structured/IStructureContainerFactory.java: -------------------------------------------------------------------------------- 1 | package openmods.structured; 2 | 3 | public interface IStructureContainerFactory> { 4 | public C createContainer(int type); 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/openmods/structured/IStructureElement.java: -------------------------------------------------------------------------------- 1 | package openmods.structured; 2 | 3 | import openmods.serializable.IStreamSerializable; 4 | 5 | public interface IStructureElement extends IStreamSerializable {} 6 | -------------------------------------------------------------------------------- /src/main/java/openmods/structured/IStructureObserver.java: -------------------------------------------------------------------------------- 1 | package openmods.structured; 2 | 3 | public interface IStructureObserver, E extends IStructureElement> { 4 | 5 | public void onContainerAdded(int containerId, C container); 6 | 7 | public void onElementAdded(int containerId, C container, int elementId, E element); 8 | 9 | public void onUpdateStarted(); 10 | 11 | public void onDataUpdate(); 12 | 13 | public void onStructureUpdate(); 14 | 15 | public void onContainerUpdated(int containerId, C container); 16 | 17 | public void onElementUpdated(int containerId, C container, int elementId, E element); 18 | 19 | public void onUpdateFinished(); 20 | 21 | public void onElementRemoved(int containerId, C container, int elementId, E element); 22 | 23 | public void onContainerRemoved(int containerId, C container); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/openmods/structured/StructureField.java: -------------------------------------------------------------------------------- 1 | package openmods.structured; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * This annotation is used to mark members of {@link FieldContainer} that should be wrapped as structure elements 10 | */ 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target(ElementType.FIELD) 13 | public @interface StructureField {} 14 | -------------------------------------------------------------------------------- /src/main/java/openmods/structured/StructureObserver.java: -------------------------------------------------------------------------------- 1 | package openmods.structured; 2 | 3 | public class StructureObserver, E extends IStructureElement> implements IStructureObserver { 4 | 5 | @Override 6 | public void onContainerAdded(int containerId, C container) {} 7 | 8 | @Override 9 | public void onElementAdded(int containerId, C container, int elementId, E element) {} 10 | 11 | @Override 12 | public void onUpdateStarted() {} 13 | 14 | @Override 15 | public void onDataUpdate() {} 16 | 17 | @Override 18 | public void onStructureUpdate() {} 19 | 20 | @Override 21 | public void onContainerUpdated(int containerId, C container) {} 22 | 23 | @Override 24 | public void onElementUpdated(int containerId, C container, int elementId, E element) {} 25 | 26 | @Override 27 | public void onUpdateFinished() {} 28 | 29 | @Override 30 | public void onElementRemoved(int containerId, C container, int elementId, E element) {} 31 | 32 | @Override 33 | public void onContainerRemoved(int containerId, C container) {} 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/openmods/sync/ISyncListener.java: -------------------------------------------------------------------------------- 1 | package openmods.sync; 2 | 3 | import java.util.Set; 4 | 5 | public interface ISyncListener { 6 | public void onSync(Set changes); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/openmods/sync/ISyncMapProvider.java: -------------------------------------------------------------------------------- 1 | package openmods.sync; 2 | 3 | public interface ISyncMapProvider { 4 | public SyncMap getSyncMap(); 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/openmods/sync/ISyncableObject.java: -------------------------------------------------------------------------------- 1 | package openmods.sync; 2 | 3 | import java.io.IOException; 4 | import net.minecraft.nbt.NBTTagCompound; 5 | import net.minecraft.network.PacketBuffer; 6 | 7 | public interface ISyncableObject { 8 | public boolean isDirty(); 9 | 10 | public void markClean(); 11 | 12 | public void markDirty(); 13 | 14 | public void readFromStream(PacketBuffer buf) throws IOException; 15 | 16 | public void writeToStream(PacketBuffer buf) throws IOException; 17 | 18 | public void writeToNBT(NBTTagCompound nbt, String name); 19 | 20 | public void readFromNBT(NBTTagCompound nbt, String name); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/openmods/sync/ISyncableValueProvider.java: -------------------------------------------------------------------------------- 1 | package openmods.sync; 2 | 3 | import openmods.api.IValueProvider; 4 | 5 | public interface ISyncableValueProvider extends ISyncableObject, IValueProvider {} 6 | -------------------------------------------------------------------------------- /src/main/java/openmods/sync/SyncableBoolean.java: -------------------------------------------------------------------------------- 1 | package openmods.sync; 2 | 3 | import net.minecraft.nbt.NBTTagCompound; 4 | import net.minecraft.network.PacketBuffer; 5 | 6 | public class SyncableBoolean extends SyncableObjectBase implements ISyncableValueProvider { 7 | 8 | private boolean value; 9 | 10 | public SyncableBoolean(boolean value) { 11 | this.value = value; 12 | } 13 | 14 | public SyncableBoolean() {} 15 | 16 | public void set(boolean newValue) { 17 | if (newValue != value) { 18 | value = newValue; 19 | markDirty(); 20 | } 21 | } 22 | 23 | public boolean get() { 24 | return value; 25 | } 26 | 27 | @Override 28 | public Boolean getValue() { 29 | return value; 30 | } 31 | 32 | @Override 33 | public void readFromStream(PacketBuffer stream) { 34 | value = stream.readBoolean(); 35 | } 36 | 37 | @Override 38 | public void writeToStream(PacketBuffer stream) { 39 | stream.writeBoolean(value); 40 | } 41 | 42 | @Override 43 | public void writeToNBT(NBTTagCompound tag, String name) { 44 | tag.setBoolean(name, value); 45 | } 46 | 47 | @Override 48 | public void readFromNBT(NBTTagCompound tag, String name) { 49 | value = tag.getBoolean(name); 50 | } 51 | 52 | public void toggle() { 53 | value = !value; 54 | markDirty(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/openmods/sync/SyncableByte.java: -------------------------------------------------------------------------------- 1 | package openmods.sync; 2 | 3 | import com.google.common.primitives.SignedBytes; 4 | import net.minecraft.nbt.NBTTagCompound; 5 | import net.minecraft.network.PacketBuffer; 6 | 7 | public class SyncableByte extends SyncableObjectBase implements ISyncableValueProvider { 8 | 9 | private byte value; 10 | 11 | public SyncableByte(byte value) { 12 | this.value = value; 13 | } 14 | 15 | public SyncableByte() {} 16 | 17 | public void set(byte newValue) { 18 | if (newValue != value) { 19 | value = newValue; 20 | markDirty(); 21 | } 22 | } 23 | 24 | public byte get() { 25 | return value; 26 | } 27 | 28 | @Override 29 | public Byte getValue() { 30 | return value; 31 | } 32 | 33 | @Override 34 | public void readFromStream(PacketBuffer stream) { 35 | value = stream.readByte(); 36 | } 37 | 38 | @Override 39 | public void writeToStream(PacketBuffer stream) { 40 | stream.writeByte(value); 41 | } 42 | 43 | @Override 44 | public void writeToNBT(NBTTagCompound tag, String name) { 45 | tag.setByte(name, value); 46 | } 47 | 48 | @Override 49 | public void readFromNBT(NBTTagCompound tag, String name) { 50 | value = tag.getByte(name); 51 | } 52 | 53 | public void modify(int by) { 54 | set(SignedBytes.checkedCast(value + by)); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/openmods/sync/SyncableByteArray.java: -------------------------------------------------------------------------------- 1 | package openmods.sync; 2 | 3 | import net.minecraft.nbt.NBTTagCompound; 4 | import net.minecraft.network.PacketBuffer; 5 | 6 | public class SyncableByteArray extends SyncableObjectBase implements ISyncableValueProvider { 7 | 8 | private byte[] value = new byte[0]; 9 | 10 | public SyncableByteArray() {} 11 | 12 | public SyncableByteArray(byte[] val) { 13 | this.value = val; 14 | } 15 | 16 | public void setValue(byte[] newValue) { 17 | if (newValue != value) { 18 | value = newValue; 19 | markDirty(); 20 | } 21 | } 22 | 23 | @Override 24 | public byte[] getValue() { 25 | return value; 26 | } 27 | 28 | @Override 29 | public void readFromStream(PacketBuffer stream) { 30 | value = stream.readByteArray(); 31 | } 32 | 33 | @Override 34 | public void writeToStream(PacketBuffer stream) { 35 | if (value == null) { 36 | stream.writeInt(0); 37 | } else { 38 | stream.writeByteArray(value); 39 | } 40 | } 41 | 42 | @Override 43 | public void writeToNBT(NBTTagCompound nbt, String name) { 44 | nbt.setByteArray(name, value); 45 | } 46 | 47 | @Override 48 | public void readFromNBT(NBTTagCompound nbt, String name) { 49 | nbt.getByteArray(name); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/openmods/sync/SyncableDouble.java: -------------------------------------------------------------------------------- 1 | package openmods.sync; 2 | 3 | import net.minecraft.nbt.NBTTagCompound; 4 | import net.minecraft.network.PacketBuffer; 5 | 6 | public class SyncableDouble extends SyncableObjectBase implements ISyncableValueProvider { 7 | 8 | private double value; 9 | 10 | public SyncableDouble(double value) { 11 | this.value = value; 12 | } 13 | 14 | public SyncableDouble() {} 15 | 16 | public void set(double newValue) { 17 | if (newValue != value) { 18 | value = newValue; 19 | markDirty(); 20 | } 21 | } 22 | 23 | public double get() { 24 | return value; 25 | } 26 | 27 | @Override 28 | public Double getValue() { 29 | return value; 30 | } 31 | 32 | @Override 33 | public void readFromStream(PacketBuffer stream) { 34 | value = stream.readDouble(); 35 | } 36 | 37 | @Override 38 | public void writeToStream(PacketBuffer stream) { 39 | stream.writeDouble(value); 40 | } 41 | 42 | @Override 43 | public void writeToNBT(NBTTagCompound tag, String name) { 44 | tag.setDouble(name, value); 45 | } 46 | 47 | @Override 48 | public void readFromNBT(NBTTagCompound tag, String name) { 49 | value = tag.getDouble(name); 50 | } 51 | 52 | public void modify(float by) { 53 | set(value + by); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/openmods/sync/SyncableInt.java: -------------------------------------------------------------------------------- 1 | package openmods.sync; 2 | 3 | import net.minecraft.nbt.NBTTagCompound; 4 | import net.minecraft.network.PacketBuffer; 5 | 6 | public class SyncableInt extends SyncableObjectBase implements ISyncableValueProvider { 7 | 8 | protected int value = 0; 9 | 10 | public SyncableInt(int value) { 11 | this.value = value; 12 | } 13 | 14 | public SyncableInt() {} 15 | 16 | @Override 17 | public void readFromStream(PacketBuffer stream) { 18 | value = stream.readInt(); 19 | } 20 | 21 | public void modify(int by) { 22 | set(value + by); 23 | } 24 | 25 | public void set(int val) { 26 | if (val != value) { 27 | value = val; 28 | markDirty(); 29 | } 30 | } 31 | 32 | public int get() { 33 | return value; 34 | } 35 | 36 | @Override 37 | public Integer getValue() { 38 | return value; 39 | } 40 | 41 | @Override 42 | public void writeToStream(PacketBuffer stream) { 43 | stream.writeInt(value); 44 | } 45 | 46 | @Override 47 | public void writeToNBT(NBTTagCompound tag, String name) { 48 | tag.setInteger(name, value); 49 | } 50 | 51 | @Override 52 | public void readFromNBT(NBTTagCompound tag, String name) { 53 | if (tag.hasKey(name)) { 54 | value = tag.getInteger(name); 55 | } 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/openmods/sync/SyncableNBT.java: -------------------------------------------------------------------------------- 1 | package openmods.sync; 2 | 3 | import java.io.IOException; 4 | import net.minecraft.nbt.NBTTagCompound; 5 | import net.minecraft.network.PacketBuffer; 6 | 7 | /*** 8 | * Note: you must manually .markDirty() right now 9 | */ 10 | public class SyncableNBT extends SyncableObjectBase implements ISyncableValueProvider { 11 | 12 | private NBTTagCompound tag; 13 | 14 | public SyncableNBT() { 15 | tag = new NBTTagCompound(); 16 | } 17 | 18 | public SyncableNBT(NBTTagCompound nbt) { 19 | tag = nbt.copy(); 20 | } 21 | 22 | @Override 23 | public NBTTagCompound getValue() { 24 | return tag.copy(); 25 | } 26 | 27 | public void setValue(NBTTagCompound tag) { 28 | this.tag = tag.copy(); 29 | } 30 | 31 | @Override 32 | public void readFromStream(PacketBuffer stream) throws IOException { 33 | this.tag = stream.readCompoundTag(); 34 | 35 | } 36 | 37 | @Override 38 | public void writeToStream(PacketBuffer stream) { 39 | stream.writeCompoundTag(this.tag); 40 | } 41 | 42 | @Override 43 | public void writeToNBT(NBTTagCompound nbt, String name) { 44 | nbt.setTag(name, nbt); 45 | } 46 | 47 | @Override 48 | public void readFromNBT(NBTTagCompound nbt, String name) { 49 | nbt.getCompoundTag(name); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/openmods/sync/SyncableObjectBase.java: -------------------------------------------------------------------------------- 1 | package openmods.sync; 2 | 3 | public abstract class SyncableObjectBase implements ISyncableObject { 4 | 5 | protected boolean dirty = false; 6 | 7 | @Override 8 | public boolean isDirty() { 9 | return dirty; 10 | } 11 | 12 | @Override 13 | public void markClean() { 14 | dirty = false; 15 | } 16 | 17 | @Override 18 | public void markDirty() { 19 | dirty = true; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/openmods/sync/SyncableObjectType.java: -------------------------------------------------------------------------------- 1 | package openmods.sync; 2 | 3 | import com.google.common.base.Preconditions; 4 | import net.minecraft.util.ResourceLocation; 5 | import net.minecraftforge.registries.IForgeRegistryEntry; 6 | 7 | public abstract class SyncableObjectType implements IForgeRegistryEntry { 8 | 9 | private ResourceLocation name; 10 | 11 | public abstract ISyncableObject createDummyObject(); 12 | 13 | public abstract Class getObjectClass(); 14 | 15 | public boolean isValidType(ISyncableObject object) { 16 | return getObjectClass().isInstance(object); 17 | } 18 | 19 | @Override 20 | public SyncableObjectType setRegistryName(ResourceLocation name) { 21 | Preconditions.checkState(this.name == null, "Name already set, %s->%s", this.name, name); 22 | this.name = name; 23 | return this; 24 | } 25 | 26 | @Override 27 | public ResourceLocation getRegistryName() { 28 | return name; 29 | } 30 | 31 | @Override 32 | public Class getRegistryType() { 33 | return SyncableObjectType.class; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/openmods/sync/SyncableShort.java: -------------------------------------------------------------------------------- 1 | package openmods.sync; 2 | 3 | import net.minecraft.nbt.NBTTagCompound; 4 | import net.minecraft.network.PacketBuffer; 5 | 6 | public class SyncableShort extends SyncableObjectBase implements ISyncableValueProvider { 7 | 8 | private short value = 0; 9 | 10 | public SyncableShort(short value) { 11 | this.value = value; 12 | } 13 | 14 | public SyncableShort() {} 15 | 16 | @Override 17 | public void readFromStream(PacketBuffer stream) { 18 | value = stream.readShort(); 19 | } 20 | 21 | public void modify(short by) { 22 | set((short)(value + by)); 23 | } 24 | 25 | public void set(short val) { 26 | if (val != value) { 27 | value = val; 28 | markDirty(); 29 | } 30 | } 31 | 32 | public short get() { 33 | return value; 34 | } 35 | 36 | @Override 37 | public Short getValue() { 38 | return value; 39 | } 40 | 41 | @Override 42 | public void writeToStream(PacketBuffer stream) { 43 | stream.writeShort(value); 44 | } 45 | 46 | @Override 47 | public void writeToNBT(NBTTagCompound tag, String name) { 48 | tag.setShort(name, value); 49 | } 50 | 51 | @Override 52 | public void readFromNBT(NBTTagCompound tag, String name) { 53 | value = tag.getShort(name); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/openmods/sync/SyncableString.java: -------------------------------------------------------------------------------- 1 | package openmods.sync; 2 | 3 | import com.google.common.base.Objects; 4 | import net.minecraft.nbt.NBTTagCompound; 5 | import net.minecraft.network.PacketBuffer; 6 | 7 | public class SyncableString extends SyncableObjectBase implements ISyncableValueProvider { 8 | 9 | private String value; 10 | 11 | public SyncableString() { 12 | this(""); 13 | } 14 | 15 | public SyncableString(String val) { 16 | this.value = val; 17 | } 18 | 19 | public void setValue(String val) { 20 | if (!Objects.equal(val, value)) { 21 | value = val; 22 | markDirty(); 23 | } 24 | } 25 | 26 | @Override 27 | public String getValue() { 28 | return value; 29 | } 30 | 31 | @Override 32 | public void readFromStream(PacketBuffer stream) { 33 | value = stream.readString(Short.MAX_VALUE); 34 | } 35 | 36 | @Override 37 | public void writeToStream(PacketBuffer stream) { 38 | stream.writeString(value); 39 | } 40 | 41 | @Override 42 | public void writeToNBT(NBTTagCompound nbt, String name) { 43 | nbt.setString(name, value); 44 | } 45 | 46 | @Override 47 | public void readFromNBT(NBTTagCompound nbt, String name) { 48 | value = nbt.getString(name); 49 | } 50 | 51 | public void clear() { 52 | setValue(""); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/openmods/sync/drops/StoreOnDrop.java: -------------------------------------------------------------------------------- 1 | package openmods.sync.drops; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.FIELD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface StoreOnDrop { 11 | public String name() default ""; 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/openmods/tileentity/SimpleNetTileEntity.java: -------------------------------------------------------------------------------- 1 | package openmods.tileentity; 2 | 3 | import net.minecraft.nbt.NBTTagCompound; 4 | import net.minecraft.network.NetworkManager; 5 | import net.minecraft.network.play.server.SPacketUpdateTileEntity; 6 | import net.minecraft.tileentity.TileEntity; 7 | 8 | public abstract class SimpleNetTileEntity extends OpenTileEntity { 9 | 10 | @Override 11 | public SPacketUpdateTileEntity getUpdatePacket() { 12 | return writeToPacket(this); 13 | } 14 | 15 | public static SPacketUpdateTileEntity writeToPacket(TileEntity te) { 16 | NBTTagCompound data = new NBTTagCompound(); 17 | te.writeToNBT(data); 18 | return new SPacketUpdateTileEntity(te.getPos(), 42, data); 19 | } 20 | 21 | @Override 22 | public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) { 23 | readFromNBT(pkt.getNbtCompound()); 24 | } 25 | } -------------------------------------------------------------------------------- /src/main/java/openmods/utils/AnnotationMap.java: -------------------------------------------------------------------------------- 1 | package openmods.utils; 2 | 3 | import com.google.common.collect.Maps; 4 | import java.lang.annotation.Annotation; 5 | import java.util.Map; 6 | 7 | public class AnnotationMap { 8 | private final Map, Annotation> annotations = Maps.newHashMap(); 9 | 10 | public AnnotationMap() {} 11 | 12 | public AnnotationMap(Annotation[] annotations) { 13 | for (Annotation a : annotations) 14 | this.annotations.put(a.annotationType(), a); 15 | } 16 | 17 | public boolean hasAnnotation(Class cls) { 18 | return annotations.get(cls) != null; 19 | } 20 | 21 | public T get(Class cls) { 22 | Annotation a = annotations.get(cls); 23 | return cls.cast(a); 24 | } 25 | 26 | public void put(Annotation a) { 27 | annotations.put(a.annotationType(), a); 28 | } 29 | } -------------------------------------------------------------------------------- /src/main/java/openmods/utils/BlockNotifyFlags.java: -------------------------------------------------------------------------------- 1 | package openmods.utils; 2 | 3 | /** 4 | * Provides constants for the types of block notifications possible in 5 | * World.setBlock() 6 | * 7 | * @author: bspkrs 8 | */ 9 | 10 | public class BlockNotifyFlags { 11 | public static final int NONE = 0; 12 | 13 | /** 14 | * Cause a block update 15 | */ 16 | public static final int BLOCK_UPDATE = 1; 17 | 18 | /** 19 | * Send the change to clients 20 | */ 21 | public static final int SEND_TO_CLIENTS = 2; 22 | 23 | public static final int ALL = BLOCK_UPDATE | SEND_TO_CLIENTS; 24 | 25 | /** 26 | * prevents the block from being re-rendered, if this is a client world 27 | */ 28 | public static final int NO_RENDER = 4; 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/CachedFactory.java: -------------------------------------------------------------------------------- 1 | package openmods.utils; 2 | 3 | import com.google.common.collect.Maps; 4 | import java.util.Map; 5 | 6 | public abstract class CachedFactory { 7 | 8 | private final Map cache = Maps.newHashMap(); 9 | 10 | public V getOrCreate(K key) { 11 | V value = cache.get(key); 12 | 13 | if (value == null) { 14 | value = create(key); 15 | cache.put(key, value); 16 | } 17 | 18 | return value; 19 | } 20 | 21 | public V remove(K key) { 22 | return cache.remove(key); 23 | } 24 | 25 | protected abstract V create(K key); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/CachedInstanceFactory.java: -------------------------------------------------------------------------------- 1 | package openmods.utils; 2 | 3 | public class CachedInstanceFactory extends CachedFactory, V> { 4 | 5 | @Override 6 | protected V create(Class key) { 7 | try { 8 | return key.newInstance(); 9 | } catch (ReflectiveOperationException e) { 10 | throw new RuntimeException(e); 11 | } 12 | } 13 | 14 | public static CachedInstanceFactory create() { 15 | return new CachedInstanceFactory<>(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/CompatibilityUtils.java: -------------------------------------------------------------------------------- 1 | package openmods.utils; 2 | 3 | import javax.annotation.Nullable; 4 | import net.minecraft.tileentity.TileEntity; 5 | import net.minecraft.util.EnumFacing; 6 | import net.minecraftforge.fluids.capability.CapabilityFluidHandler; 7 | import net.minecraftforge.fluids.capability.IFluidHandler; 8 | 9 | public class CompatibilityUtils { 10 | 11 | @Nullable 12 | public static IFluidHandler getFluidHandler(TileEntity te, EnumFacing side) { 13 | if (te == null) return null; 14 | final IFluidHandler nativeCapability = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side); 15 | if (nativeCapability != null) return nativeCapability; 16 | 17 | return null; 18 | } 19 | 20 | public static boolean isFluidHandler(TileEntity te, EnumFacing side) { 21 | return te != null && (te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/DirUtils.java: -------------------------------------------------------------------------------- 1 | package openmods.utils; 2 | 3 | import java.util.Iterator; 4 | import net.minecraft.util.EnumFacing; 5 | import openmods.utils.ByteUtils.CountingBitIterator; 6 | 7 | public class DirUtils { 8 | 9 | private static class DirectionBitsetIterator extends CountingBitIterator { 10 | public DirectionBitsetIterator(int value) { 11 | super(value); 12 | } 13 | 14 | @Override 15 | protected EnumFacing convert(int bit) { 16 | return EnumFacing.VALUES[bit]; 17 | } 18 | } 19 | 20 | public static Iterator bitsToValidDirs(int value) { 21 | return new DirectionBitsetIterator(value & 0x3F); 22 | } 23 | 24 | public static Iterator bitsToAllDirs(int value) { 25 | return new DirectionBitsetIterator(value & 0x7F); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/EntityUtils.java: -------------------------------------------------------------------------------- 1 | package openmods.utils; 2 | 3 | import net.minecraft.entity.Entity; 4 | import net.minecraft.util.math.RayTraceResult; 5 | import net.minecraft.util.math.Vec3d; 6 | 7 | public class EntityUtils { 8 | 9 | public static Vec3d getPredictedPosition(Entity entity) { 10 | return entity.getPositionVector().addVector( 11 | entity.motionX, 12 | entity.motionY, 13 | entity.motionZ); 14 | } 15 | 16 | public static RayTraceResult raytraceEntity(Entity entity) { 17 | 18 | if (entity == null || entity.world == null) { return null; } 19 | 20 | return entity.world.rayTraceBlocks( 21 | entity.getPositionVector(), 22 | getPredictedPosition(entity), 23 | false, 24 | true, 25 | false); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/EnumUtils.java: -------------------------------------------------------------------------------- 1 | package openmods.utils; 2 | 3 | import gnu.trove.map.TIntObjectMap; 4 | import gnu.trove.map.hash.TIntObjectHashMap; 5 | 6 | public class EnumUtils { 7 | 8 | private static class EnumMappings> { 9 | private final TIntObjectMap idToValue = new TIntObjectHashMap<>(); 10 | 11 | public EnumMappings(Class enumCls) { 12 | 13 | for (T value : enumCls.getEnumConstants()) 14 | idToValue.put(value.ordinal(), value); 15 | } 16 | 17 | public T getValue(int id) { 18 | return idToValue.get(id); 19 | } 20 | 21 | } 22 | 23 | private static final CachedFactory>, EnumMappings> mappings = new CachedFactory>, EnumMappings>() { 24 | @Override 25 | @SuppressWarnings({ "rawtypes", "unchecked" }) 26 | protected EnumMappings create(Class> key) { 27 | return new EnumMappings(key); 28 | } 29 | }; 30 | 31 | public static > T fromOrdinal(Class cls, int ordinal) { 32 | @SuppressWarnings("unchecked") 33 | final EnumMappings mapping = (EnumMappings)mappings.getOrCreate(cls); 34 | return mapping.getValue(ordinal); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/ITester.java: -------------------------------------------------------------------------------- 1 | package openmods.utils; 2 | 3 | @FunctionalInterface 4 | public interface ITester { 5 | public enum Result { 6 | ACCEPT, 7 | REJECT, 8 | CONTINUE; 9 | } 10 | 11 | Result test(T o); 12 | } -------------------------------------------------------------------------------- /src/main/java/openmods/utils/LazyValue.java: -------------------------------------------------------------------------------- 1 | package openmods.utils; 2 | 3 | public abstract class LazyValue { 4 | 5 | private boolean initialized; 6 | 7 | private T value; 8 | 9 | protected abstract T initialize(); 10 | 11 | public T get() { 12 | if (!initialized) { 13 | value = initialize(); 14 | initialized = true; 15 | } 16 | 17 | return value; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/MCUtils.java: -------------------------------------------------------------------------------- 1 | package openmods.utils; 2 | 3 | import java.io.File; 4 | import openmods.OpenMods; 5 | 6 | public class MCUtils { 7 | public static String getLogFileName() { 8 | return OpenMods.proxy.getLogFileName(); 9 | } 10 | 11 | public static String getMinecraftDir() { 12 | return OpenMods.proxy.getMinecraftDir().getAbsolutePath(); 13 | } 14 | 15 | public static String getConfigDir() { 16 | return new File(OpenMods.proxy.getMinecraftDir(), "config").getAbsolutePath(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/PlayerUtils.java: -------------------------------------------------------------------------------- 1 | package openmods.utils; 2 | 3 | import net.minecraft.entity.player.EntityPlayer; 4 | import net.minecraft.nbt.NBTTagCompound; 5 | 6 | public class PlayerUtils { 7 | 8 | public static NBTTagCompound getModPlayerPersistTag(EntityPlayer player, String modName) { 9 | 10 | NBTTagCompound tag = player.getEntityData(); 11 | 12 | NBTTagCompound persistTag = null; 13 | if (tag.hasKey(EntityPlayer.PERSISTED_NBT_TAG)) { 14 | persistTag = tag.getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG); 15 | } else { 16 | persistTag = new NBTTagCompound(); 17 | tag.setTag(EntityPlayer.PERSISTED_NBT_TAG, persistTag); 18 | } 19 | 20 | NBTTagCompound modTag = null; 21 | if (persistTag.hasKey(modName)) { 22 | modTag = persistTag.getCompoundTag(modName); 23 | } else { 24 | modTag = new NBTTagCompound(); 25 | persistTag.setTag(modName, modTag); 26 | } 27 | 28 | return modTag; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/RecipeUtils.java: -------------------------------------------------------------------------------- 1 | package openmods.utils; 2 | 3 | import javax.annotation.Nonnull; 4 | import net.minecraft.item.ItemStack; 5 | import net.minecraft.item.crafting.CraftingManager; 6 | import net.minecraft.item.crafting.IRecipe; 7 | import net.minecraft.item.crafting.Ingredient; 8 | import net.minecraft.util.NonNullList; 9 | 10 | public class RecipeUtils { 11 | 12 | public static IRecipe getFirstRecipeForItemStack(@Nonnull ItemStack resultingItem) { 13 | 14 | for (IRecipe recipe : CraftingManager.REGISTRY) { 15 | if (recipe == null) continue; 16 | 17 | ItemStack result = recipe.getRecipeOutput(); 18 | if (!result.isEmpty() && result.isItemEqual(resultingItem)) return recipe; 19 | 20 | } 21 | return null; 22 | } 23 | 24 | public static ItemStack[][] getFullRecipeInput(IRecipe recipe) { 25 | final NonNullList ingredients = recipe.getIngredients(); 26 | final int ingredientCount = ingredients.size(); 27 | final ItemStack[][] result = new ItemStack[ingredientCount][]; 28 | 29 | for (int i = 0; i < ingredientCount; i++) 30 | result[i] = ingredients.get(i).getMatchingStacks(); 31 | 32 | return result; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/RegistrationContextBase.java: -------------------------------------------------------------------------------- 1 | package openmods.utils; 2 | 3 | import com.google.common.base.Preconditions; 4 | import net.minecraftforge.fml.common.Loader; 5 | import net.minecraftforge.fml.common.ModContainer; 6 | import net.minecraftforge.registries.IForgeRegistry; 7 | import net.minecraftforge.registries.IForgeRegistryEntry; 8 | 9 | public class RegistrationContextBase> { 10 | 11 | protected final IForgeRegistry registry; 12 | 13 | protected final String domain; 14 | 15 | private static String getCurrentMod() { 16 | ModContainer mc = Loader.instance().activeModContainer(); 17 | Preconditions.checkState(mc != null, "This method can be only used during mod initialization"); 18 | String prefix = mc.getModId().toLowerCase(); 19 | return prefix; 20 | } 21 | 22 | public RegistrationContextBase(IForgeRegistry registry, String domain) { 23 | this.registry = registry; 24 | this.domain = domain; 25 | } 26 | 27 | public RegistrationContextBase(IForgeRegistry registry) { 28 | this(registry, getCurrentMod()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/SidedCommand.java: -------------------------------------------------------------------------------- 1 | package openmods.utils; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | import net.minecraft.command.ICommand; 6 | import net.minecraft.command.ICommandSender; 7 | import net.minecraft.server.MinecraftServer; 8 | 9 | public abstract class SidedCommand implements ICommand { 10 | 11 | protected final String name; 12 | protected final boolean restricted; 13 | 14 | public SidedCommand(String name, boolean restricted) { 15 | this.name = name; 16 | this.restricted = restricted; 17 | } 18 | 19 | @Override 20 | public int compareTo(ICommand o) { 21 | return name.compareTo(o.getName()); 22 | } 23 | 24 | @Override 25 | public String getName() { 26 | return name; 27 | } 28 | 29 | @Override 30 | public List getAliases() { 31 | return Collections.emptyList(); 32 | } 33 | 34 | @Override 35 | public boolean checkPermission(MinecraftServer server, ICommandSender sender) { 36 | return restricted? sender.canUseCommand(4, name) : true; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/SimpleUnlistedProperty.java: -------------------------------------------------------------------------------- 1 | package openmods.utils; 2 | 3 | import net.minecraftforge.common.property.IUnlistedProperty; 4 | 5 | public class SimpleUnlistedProperty implements IUnlistedProperty { 6 | 7 | private final Class type; 8 | private final String name; 9 | 10 | public SimpleUnlistedProperty(Class type, String name) { 11 | this.type = type; 12 | this.name = name; 13 | } 14 | 15 | @Override 16 | public String getName() { 17 | return name; 18 | } 19 | 20 | @Override 21 | public boolean isValid(T value) { 22 | return true; 23 | } 24 | 25 | @Override 26 | public Class getType() { 27 | return type; 28 | } 29 | 30 | @Override 31 | public String valueToString(T value) { 32 | return value.toString(); 33 | } 34 | 35 | public static IUnlistedProperty create(Class type, String name) { 36 | return new SimpleUnlistedProperty<>(type, name); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/SneakyThrower.java: -------------------------------------------------------------------------------- 1 | package openmods.utils; 2 | 3 | public class SneakyThrower { 4 | 5 | public static class DummyException extends RuntimeException { 6 | private static final long serialVersionUID = 2594806051360685738L; 7 | } 8 | 9 | public static class Thrower { 10 | @SuppressWarnings("unchecked") 11 | public T sneakyThrow(Throwable exception) throws T { 12 | throw (T)exception; 13 | } 14 | } 15 | 16 | private static final Thrower HELPER = new Thrower<>(); 17 | 18 | public static DummyException sneakyThrow(Throwable exception) { 19 | HELPER.sneakyThrow(exception); 20 | return null; 21 | } 22 | 23 | @SuppressWarnings("unused") 24 | public static void sneakyThrows(Class cls) throws T {} 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/StackUnderflowException.java: -------------------------------------------------------------------------------- 1 | package openmods.utils; 2 | 3 | public class StackUnderflowException extends RuntimeException { 4 | private static final long serialVersionUID = 360455673552034663L; 5 | 6 | public StackUnderflowException(String message) { 7 | super(message); 8 | } 9 | 10 | public StackUnderflowException(String format, Object... args) { 11 | super(String.format(format, args)); 12 | } 13 | 14 | public StackUnderflowException() { 15 | super("stack underflow"); 16 | } 17 | } -------------------------------------------------------------------------------- /src/main/java/openmods/utils/StackValidationException.java: -------------------------------------------------------------------------------- 1 | package openmods.utils; 2 | 3 | public class StackValidationException extends RuntimeException { 4 | private static final long serialVersionUID = -6473451138801686555L; 5 | 6 | public StackValidationException(String message) { 7 | super(message); 8 | } 9 | 10 | public StackValidationException(String format, Object... args) { 11 | super(String.format(format, args)); 12 | } 13 | } -------------------------------------------------------------------------------- /src/main/java/openmods/utils/StringUtils.java: -------------------------------------------------------------------------------- 1 | package openmods.utils; 2 | 3 | import java.util.Random; 4 | 5 | public class StringUtils { 6 | 7 | public static final String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 8 | public static Random rnd = new Random(); 9 | 10 | public static String randomString(int len) { 11 | StringBuilder sb = new StringBuilder(len); 12 | for (int i = 0; i < len; i++) 13 | sb.append(AB.charAt(rnd.nextInt(AB.length()))); 14 | return sb.toString(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/TranslationUtils.java: -------------------------------------------------------------------------------- 1 | package openmods.utils; 2 | 3 | import net.minecraft.util.text.translation.I18n; 4 | 5 | @SuppressWarnings("deprecation") // TODO find better solution 6 | public class TranslationUtils { 7 | 8 | public static String translateToLocal(String key) { 9 | return I18n.translateToLocal(key); 10 | } 11 | 12 | public static String translateToLocalFormatted(String key, Object... args) { 13 | return I18n.translateToLocalFormatted(key, args); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/Units.java: -------------------------------------------------------------------------------- 1 | package openmods.utils; 2 | 3 | public class Units { 4 | public static enum SpeedUnit { 5 | M_PER_TICK("m/tick", 1, "%.2f %s"), 6 | M_PER_S("m/s", 1.0 * 20.0, "%.2f %s"), // probably not working 7 | KM_PER_H("km/s", 3.6 * 20.0, "%.2f %s"), 8 | BROKEN("mph", 2.23694 * 20.0, "%.2f %s"); 9 | 10 | public final String name; 11 | public final double factor; 12 | public final String format; 13 | 14 | private SpeedUnit(String name, double factor, String format) { 15 | this.name = name; 16 | this.factor = factor; 17 | this.format = format; 18 | } 19 | 20 | public String format(double value) { 21 | return String.format(format, value * factor, name); 22 | } 23 | } 24 | 25 | public static enum DistanceUnit { 26 | M("m", 1, "%.0f %s"), 27 | KM("km", 0.001, "%.2f %s"), 28 | SILLY("miles", 0.000621371, "%.f %s"); 29 | 30 | public final String name; 31 | public final double factor; 32 | public final String format; 33 | 34 | private DistanceUnit(String name, double factor, String format) { 35 | this.name = name; 36 | this.factor = factor; 37 | this.format = format; 38 | } 39 | 40 | public String format(double value) { 41 | return String.format(format, value * factor, name); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/Variant.java: -------------------------------------------------------------------------------- 1 | package openmods.utils; 2 | 3 | import com.google.common.base.Preconditions; 4 | 5 | public class Variant { 6 | // TODO maybe capture type somehow? 7 | public abstract static class Selector { 8 | public abstract T cast(Object o); 9 | } 10 | 11 | public static Selector createSelector() { 12 | return new Selector() { 13 | @Override 14 | @SuppressWarnings("unchecked") 15 | public T cast(Object o) { 16 | return (T)o; 17 | } 18 | }; 19 | } 20 | 21 | private final Selector type; 22 | private final Object payload; 23 | 24 | public Variant(Selector type, T payload) { 25 | this.type = type; 26 | this.payload = payload; 27 | } 28 | 29 | public boolean is(Selector type) { 30 | return this.type == type; 31 | } 32 | 33 | public T get(Selector type) { 34 | Preconditions.checkArgument(this.type == type); 35 | return type.cast(payload); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/WorldUtils.java: -------------------------------------------------------------------------------- 1 | package openmods.utils; 2 | 3 | import com.google.common.base.Preconditions; 4 | import com.google.common.base.Predicate; 5 | import net.minecraft.entity.Entity; 6 | import net.minecraft.entity.player.EntityPlayer; 7 | import net.minecraft.tileentity.TileEntity; 8 | import net.minecraft.world.World; 9 | import net.minecraftforge.fml.relauncher.Side; 10 | import openmods.OpenMods; 11 | 12 | public class WorldUtils { 13 | 14 | public static final Predicate NON_PLAYER = entity -> !(entity instanceof EntityPlayer); 15 | 16 | public static World getWorld(Side side, int dimensionId) { 17 | final World result; 18 | if (side == Side.SERVER) { 19 | result = OpenMods.proxy.getServerWorld(dimensionId); 20 | } else { 21 | result = OpenMods.proxy.getClientWorld(); 22 | Preconditions.checkArgument(result.provider.getDimension() == dimensionId, "Invalid client dimension id %s", dimensionId); 23 | } 24 | 25 | Preconditions.checkNotNull(result, "Invalid world dimension %s", dimensionId); 26 | return result; 27 | } 28 | 29 | public static boolean isTileEntityValid(TileEntity te) { 30 | if (te.isInvalid()) return false; 31 | 32 | final World world = te.getWorld(); 33 | return (world != null)? world.isBlockLoaded(te.getPos()) : false; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/bitmap/IBitMap.java: -------------------------------------------------------------------------------- 1 | package openmods.utils.bitmap; 2 | 3 | public interface IBitMap extends IReadableBitMap, IWriteableBitMap {} -------------------------------------------------------------------------------- /src/main/java/openmods/utils/bitmap/IReadableBitMap.java: -------------------------------------------------------------------------------- 1 | package openmods.utils.bitmap; 2 | 3 | public interface IReadableBitMap { 4 | public boolean get(T value); 5 | } -------------------------------------------------------------------------------- /src/main/java/openmods/utils/bitmap/IRpcDirectionBitMap.java: -------------------------------------------------------------------------------- 1 | package openmods.utils.bitmap; 2 | 3 | import net.minecraft.util.EnumFacing; 4 | 5 | public interface IRpcDirectionBitMap { 6 | public void mark(EnumFacing value); 7 | 8 | public void clear(EnumFacing value); 9 | 10 | public abstract void set(EnumFacing key, boolean value); 11 | 12 | public void toggle(EnumFacing value); 13 | 14 | public abstract void clearAll(); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/bitmap/IRpcIntBitMap.java: -------------------------------------------------------------------------------- 1 | package openmods.utils.bitmap; 2 | 3 | public interface IRpcIntBitMap { 4 | public abstract void mark(Integer value); 5 | 6 | public abstract void clear(Integer value); 7 | 8 | public abstract void set(Integer key, boolean value); 9 | 10 | public abstract void toggle(Integer value); 11 | 12 | public abstract void clearAll(); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/bitmap/IWriteableBitMap.java: -------------------------------------------------------------------------------- 1 | package openmods.utils.bitmap; 2 | 3 | public interface IWriteableBitMap { 4 | 5 | public void mark(T value); 6 | 7 | public void clear(T value); 8 | 9 | public void set(T key, boolean value); 10 | 11 | public void toggle(T value); 12 | 13 | public void clearAll(); 14 | 15 | } -------------------------------------------------------------------------------- /src/main/java/openmods/utils/bitstream/InputBitStream.java: -------------------------------------------------------------------------------- 1 | package openmods.utils.bitstream; 2 | 3 | import java.io.IOException; 4 | import openmods.utils.io.IByteSource; 5 | 6 | public class InputBitStream extends InputBitStreamBase { 7 | 8 | private int byteCounter; 9 | 10 | private final IByteSource source; 11 | 12 | public InputBitStream(IByteSource source) { 13 | super(0x80); 14 | this.source = source; 15 | } 16 | 17 | @Override 18 | protected int nextByte() throws IOException { 19 | final int nextByte = source.nextByte(); 20 | byteCounter++; 21 | return nextByte; 22 | } 23 | 24 | @Override 25 | public int bytesRead() { 26 | return byteCounter; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/bitstream/InputBitStreamBase.java: -------------------------------------------------------------------------------- 1 | package openmods.utils.bitstream; 2 | 3 | import java.io.IOException; 4 | 5 | public abstract class InputBitStreamBase { 6 | 7 | private final int initialMask; 8 | 9 | private int mask; 10 | 11 | private int currentByte; 12 | 13 | public InputBitStreamBase(int initialMask) { 14 | this.initialMask = initialMask; 15 | } 16 | 17 | protected abstract int nextByte() throws IOException; 18 | 19 | public boolean readBit() throws IOException { 20 | if (mask == 0) { 21 | currentByte = nextByte(); 22 | mask = initialMask; 23 | } 24 | 25 | boolean bit = (currentByte & mask) != 0; 26 | mask >>= 1; 27 | 28 | return bit; 29 | } 30 | 31 | public abstract int bytesRead(); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/bitstream/OutputVarBitStream.java: -------------------------------------------------------------------------------- 1 | package openmods.utils.bitstream; 2 | 3 | import java.io.IOException; 4 | import openmods.utils.io.IByteSink; 5 | 6 | public class OutputVarBitStream extends OutputBitStream { 7 | 8 | public OutputVarBitStream(IByteSink sink) { 9 | super(sink, 7); 10 | } 11 | 12 | @Override 13 | protected void flushBuffer(int value, boolean isLastBit) throws IOException { 14 | flushBuffer(value | (isLastBit? 0x00 : 0x80)); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/io/FileLineReader.java: -------------------------------------------------------------------------------- 1 | package openmods.utils.io; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.FileReader; 5 | import java.io.IOException; 6 | 7 | public class FileLineReader { 8 | 9 | public static void readLineByLine(BufferedReader reader, ILineReadMethod callback) 10 | throws IOException { 11 | String line; 12 | while ((line = reader.readLine()) != null) { 13 | callback.read(line); 14 | } 15 | reader.close(); 16 | } 17 | 18 | public static void readLineByLine(String filename, ILineReadMethod callback) 19 | throws IOException { 20 | readLineByLine(new BufferedReader(new FileReader(filename)), callback); 21 | } 22 | } -------------------------------------------------------------------------------- /src/main/java/openmods/utils/io/IByteSink.java: -------------------------------------------------------------------------------- 1 | package openmods.utils.io; 2 | 3 | import java.io.IOException; 4 | 5 | @FunctionalInterface 6 | public interface IByteSink { 7 | public void acceptByte(int b) throws IOException; 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/io/IByteSource.java: -------------------------------------------------------------------------------- 1 | package openmods.utils.io; 2 | 3 | import java.io.EOFException; 4 | import java.io.IOException; 5 | 6 | @FunctionalInterface 7 | public interface IByteSource { 8 | public int nextByte() throws IOException, EOFException; 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/io/ILineReadMethod.java: -------------------------------------------------------------------------------- 1 | package openmods.utils.io; 2 | 3 | public interface ILineReadMethod { 4 | public void read(String line); 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/io/INBTSerializer.java: -------------------------------------------------------------------------------- 1 | package openmods.utils.io; 2 | 3 | public interface INBTSerializer extends INbtReader, INbtWriter, INbtChecker {} -------------------------------------------------------------------------------- /src/main/java/openmods/utils/io/INbtChecker.java: -------------------------------------------------------------------------------- 1 | package openmods.utils.io; 2 | 3 | import net.minecraft.nbt.NBTBase; 4 | 5 | public interface INbtChecker { 6 | public boolean checkTagType(NBTBase tag); 7 | } -------------------------------------------------------------------------------- /src/main/java/openmods/utils/io/INbtReader.java: -------------------------------------------------------------------------------- 1 | package openmods.utils.io; 2 | 3 | import net.minecraft.nbt.NBTTagCompound; 4 | 5 | public interface INbtReader { 6 | public T readFromNBT(NBTTagCompound tag, String name); 7 | } -------------------------------------------------------------------------------- /src/main/java/openmods/utils/io/INbtWriter.java: -------------------------------------------------------------------------------- 1 | package openmods.utils.io; 2 | 3 | import net.minecraft.nbt.NBTTagCompound; 4 | 5 | public interface INbtWriter { 6 | public void writeToNBT(T o, NBTTagCompound tag, String name); 7 | } -------------------------------------------------------------------------------- /src/main/java/openmods/utils/io/ISerializer.java: -------------------------------------------------------------------------------- 1 | package openmods.utils.io; 2 | 3 | public interface ISerializer extends IStreamSerializer, INBTSerializer { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/io/IStreamReader.java: -------------------------------------------------------------------------------- 1 | package openmods.utils.io; 2 | 3 | import java.io.IOException; 4 | import net.minecraft.network.PacketBuffer; 5 | 6 | public interface IStreamReader { 7 | public T readFromStream(PacketBuffer input) throws IOException; 8 | } -------------------------------------------------------------------------------- /src/main/java/openmods/utils/io/IStreamSerializer.java: -------------------------------------------------------------------------------- 1 | package openmods.utils.io; 2 | 3 | public interface IStreamSerializer extends IStreamReader, IStreamWriter {} -------------------------------------------------------------------------------- /src/main/java/openmods/utils/io/IStreamWriter.java: -------------------------------------------------------------------------------- 1 | package openmods.utils.io; 2 | 3 | import java.io.IOException; 4 | import net.minecraft.network.PacketBuffer; 5 | 6 | public interface IStreamWriter { 7 | public void writeToStream(T o, PacketBuffer output) throws IOException; 8 | } -------------------------------------------------------------------------------- /src/main/java/openmods/utils/io/IStringSerializer.java: -------------------------------------------------------------------------------- 1 | package openmods.utils.io; 2 | 3 | public interface IStringSerializer { 4 | public T readFromString(String s); 5 | // toString not needed! 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/io/InputBitStream.java: -------------------------------------------------------------------------------- 1 | package openmods.utils.io; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.DataInput; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | 8 | public abstract class InputBitStream { 9 | 10 | protected abstract int nextByte() throws IOException; 11 | 12 | private int byteCounter; 13 | 14 | private int mask; 15 | 16 | private int currentByte; 17 | 18 | public boolean readBit() throws IOException { 19 | if (mask == 0) { 20 | currentByte = nextByte(); 21 | byteCounter++; 22 | mask = 0x80; 23 | } 24 | 25 | boolean bit = (currentByte & mask) != 0; 26 | mask >>= 1; 27 | 28 | return bit; 29 | } 30 | 31 | public int bytesRead() { 32 | return byteCounter; 33 | } 34 | 35 | public static InputBitStream create(final DataInput input) { 36 | return new InputBitStream() { 37 | @Override 38 | protected int nextByte() throws IOException { 39 | return input.readByte(); 40 | } 41 | }; 42 | } 43 | 44 | public static InputBitStream create(final InputStream input) { 45 | return new InputBitStream() { 46 | @Override 47 | protected int nextByte() throws IOException { 48 | return input.read(); 49 | } 50 | }; 51 | } 52 | 53 | public static InputBitStream create(byte[] bytes) { 54 | return create(new ByteArrayInputStream(bytes)); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/io/StreamUtils.java: -------------------------------------------------------------------------------- 1 | package openmods.utils.io; 2 | 3 | import java.io.DataInput; 4 | import java.io.EOFException; 5 | import java.io.IOException; 6 | import net.minecraft.network.PacketBuffer; 7 | 8 | public class StreamUtils { 9 | 10 | public static class EndOfStreamException extends RuntimeException { 11 | private static final long serialVersionUID = -3617549679310092671L; 12 | } 13 | 14 | public static int bitsToBytes(int bits) { 15 | return (bits + 7) / 8; 16 | } 17 | 18 | public static byte[] readBytes(PacketBuffer stream, int count) { 19 | byte[] buffer = new byte[count]; 20 | stream.readBytes(buffer); 21 | return buffer; 22 | } 23 | 24 | public static byte[] readBytes(DataInput stream, int count) throws IOException { 25 | byte[] buffer = new byte[count]; 26 | try { 27 | stream.readFully(buffer); 28 | } catch (EOFException e) { 29 | throw new EndOfStreamException(); 30 | } 31 | 32 | return buffer; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/openmods/utils/io/StringConversionException.java: -------------------------------------------------------------------------------- 1 | package openmods.utils.io; 2 | 3 | import java.util.Arrays; 4 | 5 | public class StringConversionException extends IllegalArgumentException { 6 | private static final long serialVersionUID = -3492890240785282110L; 7 | 8 | public final String value; 9 | public final String type; 10 | 11 | private static String createCause(String type, String value) { 12 | return String.format("String '%s' couldn't be converted to type %s", value, type); 13 | } 14 | 15 | private static String createCause(String type, String value, String... values) { 16 | return String.format("String '%s' couldn't be converted to type %s, allowed values: %s", value, type, Arrays.toString(values)); 17 | } 18 | 19 | public StringConversionException(String type, String value) { 20 | super(createCause(type, value)); 21 | this.value = value; 22 | this.type = type; 23 | } 24 | 25 | public StringConversionException(String type, String value, String... values) { 26 | super(createCause(type, value, values)); 27 | this.value = value; 28 | this.type = type; 29 | } 30 | 31 | public StringConversionException(String type, String value, Throwable cause) { 32 | super(createCause(type, value), cause); 33 | this.value = value; 34 | this.type = type; 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /src/main/java/openmods/words/Alternative.java: -------------------------------------------------------------------------------- 1 | package openmods.words; 2 | 3 | import com.google.common.collect.ImmutableList; 4 | import java.math.BigInteger; 5 | import java.util.List; 6 | import java.util.Map; 7 | import java.util.Random; 8 | 9 | public class Alternative implements IGenerator { 10 | 11 | private final List alts; 12 | 13 | public Alternative(IGenerator... alts) { 14 | this.alts = ImmutableList.copyOf(alts); 15 | } 16 | 17 | @Override 18 | public String generate(Random random, Map params) { 19 | if (alts.isEmpty()) return ""; 20 | int choice = random.nextInt(alts.size()); 21 | return alts.get(choice).generate(random, params); 22 | } 23 | 24 | @Override 25 | public BigInteger count() { 26 | BigInteger result = BigInteger.ZERO; 27 | for (IGenerator alt : alts) 28 | result = result.add(alt.count()); 29 | return result; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/openmods/words/IGenerator.java: -------------------------------------------------------------------------------- 1 | package openmods.words; 2 | 3 | import java.math.BigInteger; 4 | import java.util.Map; 5 | import java.util.Random; 6 | 7 | public interface IGenerator { 8 | public String generate(Random random, Map params); 9 | 10 | public BigInteger count(); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/openmods/words/Optional.java: -------------------------------------------------------------------------------- 1 | package openmods.words; 2 | 3 | import java.math.BigInteger; 4 | import java.util.Map; 5 | import java.util.Random; 6 | 7 | public class Optional implements IGenerator { 8 | 9 | private final IGenerator part; 10 | private final float probability; 11 | 12 | public Optional(IGenerator part, float probability) { 13 | this.part = part; 14 | this.probability = probability; 15 | } 16 | 17 | @Override 18 | public String generate(Random random, Map params) { 19 | return (random.nextFloat() < probability)? part.generate(random, params) : ""; 20 | } 21 | 22 | @Override 23 | public BigInteger count() { 24 | return part.count().add(BigInteger.ONE); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/openmods/words/Range.java: -------------------------------------------------------------------------------- 1 | package openmods.words; 2 | 3 | import java.math.BigInteger; 4 | import java.util.Map; 5 | import java.util.Random; 6 | 7 | public class Range implements IGenerator { 8 | 9 | private final int start; 10 | private final int range; 11 | 12 | public Range(int start, int end) { 13 | this.start = start; 14 | this.range = end - start; 15 | } 16 | 17 | @Override 18 | public String generate(Random random, Map params) { 19 | return Integer.toString(start + random.nextInt(range)); 20 | } 21 | 22 | @Override 23 | public BigInteger count() { 24 | return BigInteger.valueOf(range); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/openmods/words/Substitution.java: -------------------------------------------------------------------------------- 1 | package openmods.words; 2 | 3 | import com.google.common.base.MoreObjects; 4 | import java.math.BigInteger; 5 | import java.util.Map; 6 | import java.util.Random; 7 | 8 | public class Substitution implements IGenerator { 9 | 10 | private final String key; 11 | private final String defaultValue; 12 | 13 | public Substitution(String key, String defaultValue) { 14 | this.key = key; 15 | this.defaultValue = defaultValue; 16 | } 17 | 18 | @Override 19 | public String generate(Random random, Map params) { 20 | return MoreObjects.firstNonNull(params.get(key), defaultValue); 21 | } 22 | 23 | @Override 24 | public BigInteger count() { 25 | return BigInteger.ONE; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/openmods/words/Terminal.java: -------------------------------------------------------------------------------- 1 | package openmods.words; 2 | 3 | import java.math.BigInteger; 4 | import java.util.Map; 5 | import java.util.Random; 6 | 7 | public class Terminal implements IGenerator { 8 | 9 | private final String value; 10 | 11 | public Terminal(String value) { 12 | this.value = value; 13 | } 14 | 15 | @Override 16 | public String generate(Random random, Map params) { 17 | return value; 18 | } 19 | 20 | @Override 21 | public BigInteger count() { 22 | return BigInteger.ONE; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/openmods/words/Transformer.java: -------------------------------------------------------------------------------- 1 | package openmods.words; 2 | 3 | import java.math.BigInteger; 4 | import java.util.Map; 5 | import java.util.Random; 6 | 7 | public abstract class Transformer implements IGenerator { 8 | 9 | protected final IGenerator root; 10 | 11 | public Transformer(IGenerator root) { 12 | this.root = root; 13 | } 14 | 15 | protected abstract String transform(String input); 16 | 17 | @Override 18 | public String generate(Random random, Map params) { 19 | String result = root.generate(random, params); 20 | return transform(result); 21 | } 22 | 23 | @Override 24 | public BigInteger count() { 25 | return root.count(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/openmods/world/IStructureGenProvider.java: -------------------------------------------------------------------------------- 1 | package openmods.world; 2 | 3 | import java.util.Set; 4 | import net.minecraft.world.gen.IChunkGenerator; 5 | 6 | public interface IStructureGenProvider { 7 | public Class getGeneratorCls(); 8 | 9 | public Set listStructureNames(T provider); 10 | } -------------------------------------------------------------------------------- /src/main/resources/assets/openmods/models/block/cube_all_tinted.json: -------------------------------------------------------------------------------- 1 | { 2 | "parent": "openmods:block/cube_tinted", 3 | "textures": { 4 | "particle": "#all", 5 | "down": "#all", 6 | "up": "#all", 7 | "north": "#all", 8 | "east": "#all", 9 | "south": "#all", 10 | "west": "#all" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/resources/assets/openmods/models/block/cube_tinted.json: -------------------------------------------------------------------------------- 1 | { 2 | "elements": [ 3 | { "from": [ 0, 0, 0 ], 4 | "to": [ 16, 16, 16 ], 5 | "faces": { 6 | "down": { "texture": "#down", "cullface": "down", "tintindex": 0}, 7 | "up": { "texture": "#up", "cullface": "up", "tintindex": 0 }, 8 | "north": { "texture": "#north", "cullface": "north", "tintindex": 0 }, 9 | "south": { "texture": "#south", "cullface": "south", "tintindex": 0 }, 10 | "west": { "texture": "#west", "cullface": "west", "tintindex": 0 }, 11 | "east": { "texture": "#east", "cullface": "east", "tintindex": 0 } 12 | } 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /src/main/resources/assets/openmods/models/block/cube_top_tinted.json: -------------------------------------------------------------------------------- 1 | { 2 | "parent": "openmods:block/cube_tinted", 3 | "textures": { 4 | "particle": "#side", 5 | "down": "#side", 6 | "up": "#top", 7 | "north": "#side", 8 | "east": "#side", 9 | "south": "#side", 10 | "west": "#side" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/resources/assets/openmods/recipes/_factories.json: -------------------------------------------------------------------------------- 1 | { 2 | "conditions": { 3 | "enchantment_exists": "openmods.recipe.EnchantingRecipe$Condition" 4 | }, 5 | "recipes": { 6 | "enchanting": "openmods.recipe.EnchantingRecipe$Factory" 7 | } 8 | } -------------------------------------------------------------------------------- /src/main/resources/assets/openmods/sounds.json: -------------------------------------------------------------------------------- 1 | { 2 | "pageturn": { 3 | "category": "master", 4 | "sounds": [ 5 | "openmods:pageturn" 6 | ] 7 | } 8 | } -------------------------------------------------------------------------------- /src/main/resources/assets/openmods/sounds/pageturn.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenMods/OpenModsLib/239bb8ad9421837cecebe77479b5acfd1583ceda/src/main/resources/assets/openmods/sounds/pageturn.ogg -------------------------------------------------------------------------------- /src/main/resources/assets/openmods/textures/gui/book.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenMods/OpenModsLib/239bb8ad9421837cecebe77479b5acfd1583ceda/src/main/resources/assets/openmods/textures/gui/book.png -------------------------------------------------------------------------------- /src/main/resources/assets/openmods/textures/gui/components.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenMods/OpenModsLib/239bb8ad9421837cecebe77479b5acfd1583ceda/src/main/resources/assets/openmods/textures/gui/components.png -------------------------------------------------------------------------------- /src/main/resources/mcmod.info: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "modid" : "openmods", 4 | "name" : "OpenModsLib", 5 | "version" : "${version}", 6 | "mcversion": "${mc_version}", 7 | "url" : "https://openmods.info/", 8 | "credits" : "", 9 | "authorList": [ 10 | "Mikee", 11 | "NeverCast", 12 | "boq", 13 | "Lyqyd" 14 | ], 15 | "description": "Boring stuff for all that silly Open* mods", 16 | "logoFile" : "", 17 | "updateUrl" : "", 18 | "parent" : "", 19 | "screenshots": [ 20 | ] 21 | }] 22 | -------------------------------------------------------------------------------- /src/main/resources/pack.mcmeta: -------------------------------------------------------------------------------- 1 | { 2 | "pack":{ 3 | "pack_format": 3, 4 | "description": "OpenModsLib" 5 | } 6 | } -------------------------------------------------------------------------------- /src/test/java/openmods/geometry/HalfAxisTest.java: -------------------------------------------------------------------------------- 1 | package openmods.geometry; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | 6 | public class HalfAxisTest { 7 | 8 | // just a sanity check 9 | @Test 10 | public void testCross() { 11 | for (HalfAxis a : HalfAxis.values()) 12 | for (HalfAxis b : HalfAxis.values()) { 13 | final HalfAxis pp = HalfAxis.cross(a, b); 14 | final HalfAxis pn = HalfAxis.cross(b, a); 15 | 16 | if (a == b || a == b.negate()) { 17 | Assert.assertNull(pp); 18 | Assert.assertNull(pn); 19 | } else { 20 | Assert.assertEquals(pp, pn.negate()); 21 | 22 | final int x = a.y * b.z - a.z * b.y; 23 | final int y = a.z * b.x - a.x * b.z; 24 | final int z = a.x * b.y - a.y * b.x; 25 | 26 | Assert.assertEquals(pp.x, x); 27 | Assert.assertEquals(pp.y, y); 28 | Assert.assertEquals(pp.z, z); 29 | } 30 | } 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/openmods/geometry/LocalDirectionsTest.java: -------------------------------------------------------------------------------- 1 | package openmods.geometry; 2 | 3 | import net.minecraft.util.EnumFacing; 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | 7 | public class LocalDirectionsTest { 8 | 9 | @Test 10 | public void testForNorthAndUp() { 11 | LocalDirections dirs = LocalDirections.fromFrontAndTop(EnumFacing.NORTH, EnumFacing.UP); 12 | Assert.assertEquals(dirs.front, EnumFacing.NORTH); 13 | Assert.assertEquals(dirs.back, EnumFacing.SOUTH); 14 | 15 | Assert.assertEquals(dirs.top, EnumFacing.UP); 16 | Assert.assertEquals(dirs.bottom, EnumFacing.DOWN); 17 | 18 | Assert.assertEquals(dirs.right, EnumFacing.EAST); 19 | Assert.assertEquals(dirs.left, EnumFacing.WEST); 20 | } 21 | 22 | @Test 23 | public void testForUpAndNorth() { 24 | LocalDirections dirs = LocalDirections.fromFrontAndTop(EnumFacing.UP, EnumFacing.NORTH); 25 | Assert.assertEquals(dirs.front, EnumFacing.UP); 26 | Assert.assertEquals(dirs.back, EnumFacing.DOWN); 27 | 28 | Assert.assertEquals(dirs.top, EnumFacing.NORTH); 29 | Assert.assertEquals(dirs.bottom, EnumFacing.SOUTH); 30 | 31 | Assert.assertEquals(dirs.right, EnumFacing.WEST); 32 | Assert.assertEquals(dirs.left, EnumFacing.EAST); 33 | } 34 | 35 | } 36 | --------------------------------------------------------------------------------